001
014
015 package com.liferay.portlet.journal.search;
016
017 import com.liferay.portal.kernel.dao.search.DisplayTerms;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.StringBundler;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.util.StringUtil;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portal.util.WebKeys;
024
025 import javax.portlet.PortletRequest;
026
027
030 public class TemplateDisplayTerms extends DisplayTerms {
031
032 public static final String DESCRIPTION = "description";
033
034 public static final String GROUP_IDS = "groupIds";
035
036 public static final String NAME = "name";
037
038 public static final String STRUCTURE_ID = "structureId";
039
040 public static final String TEMPLATE_ID = "searchTemplateId";
041
042 public TemplateDisplayTerms(PortletRequest portletRequest) {
043 super(portletRequest);
044
045 description = ParamUtil.getString(portletRequest, DESCRIPTION);
046 groupIds = setGroupIds(portletRequest);
047 name = ParamUtil.getString(portletRequest, NAME);
048 structureId = ParamUtil.getString(portletRequest, STRUCTURE_ID);
049 templateId = ParamUtil.getString(portletRequest, TEMPLATE_ID);
050 }
051
052 public String getDescription() {
053 return description;
054 }
055
056 public long getGroupId() {
057 if (groupIds.length == 1) {
058 return groupIds[0];
059 }
060 else {
061 return 0;
062 }
063 }
064
065 public long[] getGroupIds() {
066 return groupIds;
067 }
068
069 public String getGroupIds(PortletRequest portletRequest) {
070 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
071 WebKeys.THEME_DISPLAY);
072
073 String strutsAction = ParamUtil.getString(
074 portletRequest, "struts_action");
075
076 long groupId = ParamUtil.getLong(portletRequest, "groupId");
077
078 StringBundler sb = new StringBundler();
079
080 if (groupId > 0) {
081 sb.append(groupId);
082 }
083 else {
084 sb.append(themeDisplay.getScopeGroupId());
085 }
086
087 if (strutsAction.equalsIgnoreCase("/journal/select_template")) {
088 sb.append(StringPool.COMMA);
089 sb.append(themeDisplay.getCompanyGroupId());
090 }
091
092 return sb.toString();
093 }
094
095 public String getName() {
096 return name;
097 }
098
099 public String getStructureId() {
100 return structureId;
101 }
102
103 public String getTemplateId() {
104 return templateId;
105 }
106
107 protected long[] setGroupIds(PortletRequest portletRequest) {
108 String groupIdsString = ParamUtil.getString(
109 portletRequest, GROUP_IDS, getGroupIds(portletRequest));
110
111 return StringUtil.split(groupIdsString, 0L);
112 }
113
114 protected String description;
115 protected long[] groupIds;
116 protected String name;
117 protected String structureId;
118 protected String templateId;
119
120 }