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