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
081 public static String assemblePortletId(String portletId, long userId) {
082 return assemblePortletId(portletId, userId, null);
083 }
084
085
095 public static String assemblePortletId(
096 String portletId, long userId, String instanceId) {
097
098 String rootPortletId = getRootPortletId(portletId);
099
100 StringBundler sb = new StringBundler(5);
101
102 sb.append(rootPortletId);
103
104 if (userId <= 0) {
105 userId = getUserId(portletId);
106 }
107
108 if (userId > 0) {
109 sb.append(USER_SEPARATOR);
110 sb.append(userId);
111 }
112
113 if (Validator.isNull(instanceId)) {
114 instanceId = getInstanceId(portletId);
115 }
116
117 if (Validator.isNotNull(instanceId)) {
118 sb.append(INSTANCE_SEPARATOR);
119 sb.append(instanceId);
120 }
121
122 return sb.toString();
123 }
124
125
134 public static String assemblePortletId(
135 String portletId, String instanceId) {
136
137 return assemblePortletId(portletId, 0, instanceId);
138 }
139
140
146 public static String getInstanceId(String portletId) {
147 int pos = portletId.indexOf(INSTANCE_SEPARATOR);
148
149 if (pos == -1) {
150 return null;
151 }
152
153 return portletId.substring(pos + INSTANCE_SEPARATOR.length());
154 }
155
156
162 public static String getRootPortletId(String portletId) {
163 int x = portletId.indexOf(USER_SEPARATOR);
164 int y = portletId.indexOf(INSTANCE_SEPARATOR);
165
166 if ((x == -1) && (y == -1)) {
167 return portletId;
168 }
169 else if (x != -1) {
170 return portletId.substring(0, x);
171 }
172
173 return portletId.substring(0, y);
174 }
175
176
183 public static long getUserId(String portletId) {
184 int x = portletId.indexOf(USER_SEPARATOR);
185 int y = portletId.indexOf(INSTANCE_SEPARATOR);
186
187 if (x == -1) {
188 return 0;
189 }
190
191 if (y != -1) {
192 return GetterUtil.getLong(
193 portletId.substring(x + USER_SEPARATOR.length(), y));
194 }
195
196 return GetterUtil.getLong(
197 portletId.substring(x + USER_SEPARATOR.length()));
198 }
199
200 public static boolean hasIdenticalRootPortletId(
201 String portletId1, String portletId2) {
202
203 String rootPortletId1 = getRootPortletId(portletId1);
204 String rootPortletId2 = getRootPortletId(portletId2);
205
206 return rootPortletId1.equals(rootPortletId2);
207 }
208
209
216 public static boolean hasInstanceId(String portletId) {
217 return portletId.contains(INSTANCE_SEPARATOR);
218 }
219
220
227 public static boolean hasUserId(String portletId) {
228 return portletId.contains(USER_SEPARATOR);
229 }
230
231 }