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