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