1
14
15 package com.liferay.portal.editor.fckeditor.command;
16
17 import com.liferay.portal.NoSuchGroupException;
18 import com.liferay.portal.kernel.util.GetterUtil;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.model.Group;
21 import com.liferay.portal.model.Layout;
22 import com.liferay.portal.service.GroupLocalServiceUtil;
23 import com.liferay.portal.service.LayoutLocalServiceUtil;
24 import com.liferay.portal.theme.ThemeDisplay;
25
26 import java.util.StringTokenizer;
27
28 import javax.servlet.http.HttpServletRequest;
29
30
36 public class CommandArgument {
37
38 public CommandArgument(
39 String command, String type, String currentFolder, String newFolder,
40 ThemeDisplay themeDisplay, HttpServletRequest request) {
41
42 _command = command;
43 _type = type;
44 _currentFolder = currentFolder;
45 _newFolder = newFolder;
46 _themeDisplay = themeDisplay;
47 _request = request;
48 }
49
50 public String getCommand() {
51 return _command;
52 }
53
54 public String getType() {
55 return _type;
56 }
57
58 public String getCurrentFolder() {
59 return _currentFolder;
60 }
61
62 public String getNewFolder() {
63 return _newFolder;
64 }
65
66 public ThemeDisplay getThemeDisplay() {
67 return _themeDisplay;
68 }
69
70 public HttpServletRequest getHttpServletRequest() {
71 return _request;
72 }
73
74 public long getCompanyId() {
75 return _themeDisplay.getCompanyId();
76 }
77
78 public Group getCurrentGroup() throws Exception {
79 String currentGroupName = getCurrentGroupName();
80
81 int pos = currentGroupName.indexOf(" - ");
82
83 if (pos > 0) {
84 long groupId = GetterUtil.getLong(
85 currentGroupName.substring(0, pos));
86
87 Group group = GroupLocalServiceUtil.getGroup(groupId);
88
89 if (group.getCompanyId() == getCompanyId()) {
90 return group;
91 }
92 }
93
94 throw new NoSuchGroupException();
95 }
96
97 public String getCurrentGroupName() {
98 if (_currentFolder.equals("/")) {
99 return StringPool.BLANK;
100 }
101 else {
102 StringTokenizer st = new StringTokenizer(_currentFolder, "/");
103
104 return st.nextToken();
105 }
106 }
107
108 public long getUserId() {
109 return _themeDisplay.getUserId();
110 }
111
112 public long getPlid() throws Exception {
113 long plid = _themeDisplay.getPlid();
114
115 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
116
117 Group group = getCurrentGroup();
118
119 if (layout.getGroupId() != group.getGroupId()) {
120 plid = LayoutLocalServiceUtil.getDefaultPlid(group.getGroupId());
121 }
122
123 return plid;
124 }
125
126 private String _command;
127 private String _type;
128 private String _currentFolder;
129 private String _newFolder;
130 private ThemeDisplay _themeDisplay;
131 private HttpServletRequest _request;
132
133 }