001
014
015 package com.liferay.portal.model;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.StringBundler;
019 import com.liferay.portal.kernel.util.Validator;
020
021
024 public class PortletConstants {
025
026
029 public static final String DEFAULT_PREFERENCES = "<portlet-preferences />";
030
031
034 public static final String FACEBOOK_INTEGRATION_FBML = "fbml";
035
036
039 public static final String FACEBOOK_INTEGRATION_IFRAME = "iframe";
040
041
044 public static final String INSTANCE_SEPARATOR = "_INSTANCE_";
045
046
049 public static final String LAYOUT_SEPARATOR = "_LAYOUT_";
050
051
054 public static final String USER_PRINCIPAL_STRATEGY_SCREEN_NAME =
055 "screenName";
056
057
060 public static final String USER_PRINCIPAL_STRATEGY_USER_ID = "userId";
061
062
065 public static final String USER_SEPARATOR = "_USER_";
066
067
070 public static final String WAR_SEPARATOR = "_WAR_";
071
072
082 public static String assemblePortletId(String portletId, long userId) {
083 return assemblePortletId(portletId, userId, null);
084 }
085
086
097 public static String assemblePortletId(
098 String portletId, long userId, String instanceId) {
099
100 String rootPortletId = getRootPortletId(portletId);
101
102 StringBundler sb = new StringBundler(5);
103
104 sb.append(rootPortletId);
105
106 if (userId <= 0) {
107 userId = getUserId(portletId);
108 }
109
110 if (userId > 0) {
111 sb.append(USER_SEPARATOR);
112 sb.append(userId);
113 }
114
115 if (Validator.isNull(instanceId)) {
116 instanceId = getInstanceId(portletId);
117 }
118
119 if (Validator.isNotNull(instanceId)) {
120 sb.append(INSTANCE_SEPARATOR);
121 sb.append(instanceId);
122 }
123
124 return sb.toString();
125 }
126
127
137 public static String assemblePortletId(
138 String portletId, String instanceId) {
139
140 return assemblePortletId(portletId, 0, instanceId);
141 }
142
143
149 public static String getInstanceId(String portletId) {
150 int pos = portletId.indexOf(INSTANCE_SEPARATOR);
151
152 if (pos == -1) {
153 return null;
154 }
155
156 return portletId.substring(pos + INSTANCE_SEPARATOR.length());
157 }
158
159
165 public static String getRootPortletId(String portletId) {
166 int x = portletId.indexOf(USER_SEPARATOR);
167 int y = portletId.indexOf(INSTANCE_SEPARATOR);
168
169 if ((x == -1) && (y == -1)) {
170 return portletId;
171 }
172 else if (x != -1) {
173 return portletId.substring(0, x);
174 }
175
176 return portletId.substring(0, y);
177 }
178
179
186 public static long getUserId(String portletId) {
187 int x = portletId.indexOf(USER_SEPARATOR);
188 int y = portletId.indexOf(INSTANCE_SEPARATOR);
189
190 if (x == -1) {
191 return 0;
192 }
193
194 if (y != -1) {
195 return GetterUtil.getLong(
196 portletId.substring(x + USER_SEPARATOR.length(), y));
197 }
198
199 return GetterUtil.getLong(
200 portletId.substring(x + USER_SEPARATOR.length()));
201 }
202
203 public static boolean hasIdenticalRootPortletId(
204 String portletId1, String portletId2) {
205
206 String rootPortletId1 = getRootPortletId(portletId1);
207 String rootPortletId2 = getRootPortletId(portletId2);
208
209 return rootPortletId1.equals(rootPortletId2);
210 }
211
212
219 public static boolean hasInstanceId(String portletId) {
220 return portletId.contains(INSTANCE_SEPARATOR);
221 }
222
223
230 public static boolean hasUserId(String portletId) {
231 return portletId.contains(USER_SEPARATOR);
232 }
233
234 }