001
014
015 package com.liferay.portal.editor.fckeditor.command;
016
017 import com.liferay.portal.NoSuchGroupException;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.model.Group;
021 import com.liferay.portal.model.Layout;
022 import com.liferay.portal.service.GroupLocalServiceUtil;
023 import com.liferay.portal.service.LayoutLocalServiceUtil;
024 import com.liferay.portal.theme.ThemeDisplay;
025
026 import java.util.StringTokenizer;
027
028 import javax.servlet.http.HttpServletRequest;
029
030
034 public class CommandArgument {
035
036 public CommandArgument(
037 String command, String type, String currentFolder, String newFolder,
038 ThemeDisplay themeDisplay, HttpServletRequest request) {
039
040 _command = command;
041 _type = type;
042 _currentFolder = currentFolder;
043 _newFolder = newFolder;
044 _themeDisplay = themeDisplay;
045 _request = request;
046 }
047
048 public String getCommand() {
049 return _command;
050 }
051
052 public String getType() {
053 return _type;
054 }
055
056 public String getCurrentFolder() {
057 return _currentFolder;
058 }
059
060 public String getNewFolder() {
061 return _newFolder;
062 }
063
064 public ThemeDisplay getThemeDisplay() {
065 return _themeDisplay;
066 }
067
068 public HttpServletRequest getHttpServletRequest() {
069 return _request;
070 }
071
072 public long getCompanyId() {
073 return _themeDisplay.getCompanyId();
074 }
075
076 public Group getCurrentGroup() throws Exception {
077 String currentGroupName = getCurrentGroupName();
078
079 int pos = currentGroupName.indexOf(" - ");
080
081 if (pos > 0) {
082 long groupId = GetterUtil.getLong(
083 currentGroupName.substring(0, pos));
084
085 Group group = GroupLocalServiceUtil.getGroup(groupId);
086
087 if (group.getCompanyId() == getCompanyId()) {
088 return group;
089 }
090 }
091
092 throw new NoSuchGroupException();
093 }
094
095 public String getCurrentGroupName() {
096 if (_currentFolder.equals("/")) {
097 return StringPool.BLANK;
098 }
099 else {
100 StringTokenizer st = new StringTokenizer(_currentFolder, "/");
101
102 return st.nextToken();
103 }
104 }
105
106 public long getUserId() {
107 return _themeDisplay.getUserId();
108 }
109
110 public long getPlid() throws Exception {
111 long plid = _themeDisplay.getPlid();
112
113 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
114
115 Group group = getCurrentGroup();
116
117 if (layout.getGroupId() != group.getGroupId()) {
118 plid = LayoutLocalServiceUtil.getDefaultPlid(group.getGroupId());
119 }
120
121 return plid;
122 }
123
124 private String _command;
125 private String _type;
126 private String _currentFolder;
127 private String _newFolder;
128 private ThemeDisplay _themeDisplay;
129 private HttpServletRequest _request;
130
131 }