001
014
015 package com.liferay.portal.util;
016
017 import com.liferay.portal.NoSuchCompanyException;
018 import com.liferay.portal.NoSuchImageException;
019 import com.liferay.portal.NoSuchLayoutException;
020 import com.liferay.portal.NoSuchResourceException;
021 import com.liferay.portal.NoSuchUserException;
022 import com.liferay.portal.cluster.ClusterInvokeThreadLocal;
023 import com.liferay.portal.dao.orm.common.SQLTransformer;
024 import com.liferay.portal.kernel.bean.BeanPropertiesUtil;
025 import com.liferay.portal.kernel.cluster.ClusterExecutorUtil;
026 import com.liferay.portal.kernel.cluster.ClusterRequest;
027 import com.liferay.portal.kernel.dao.db.DB;
028 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
029 import com.liferay.portal.kernel.exception.PortalException;
030 import com.liferay.portal.kernel.exception.SystemException;
031 import com.liferay.portal.kernel.io.unsync.UnsyncStringWriter;
032 import com.liferay.portal.kernel.language.LanguageUtil;
033 import com.liferay.portal.kernel.log.Log;
034 import com.liferay.portal.kernel.log.LogFactoryUtil;
035 import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
036 import com.liferay.portal.kernel.portlet.FriendlyURLMapperThreadLocal;
037 import com.liferay.portal.kernel.portlet.LiferayPortletConfig;
038 import com.liferay.portal.kernel.portlet.LiferayPortletContext;
039 import com.liferay.portal.kernel.portlet.LiferayPortletMode;
040 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
041 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
042 import com.liferay.portal.kernel.portlet.LiferayWindowState;
043 import com.liferay.portal.kernel.portlet.PortletBag;
044 import com.liferay.portal.kernel.portlet.PortletBagPool;
045 import com.liferay.portal.kernel.portlet.RestrictPortletServletRequest;
046 import com.liferay.portal.kernel.security.pacl.DoPrivileged;
047 import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
048 import com.liferay.portal.kernel.servlet.DirectRequestDispatcherFactoryUtil;
049 import com.liferay.portal.kernel.servlet.DynamicServletRequest;
050 import com.liferay.portal.kernel.servlet.FileTimestampUtil;
051 import com.liferay.portal.kernel.servlet.HttpHeaders;
052 import com.liferay.portal.kernel.servlet.HttpMethods;
053 import com.liferay.portal.kernel.servlet.NonSerializableObjectRequestWrapper;
054 import com.liferay.portal.kernel.servlet.PersistentHttpServletRequestWrapper;
055 import com.liferay.portal.kernel.servlet.PipingServletResponse;
056 import com.liferay.portal.kernel.servlet.PortalSessionThreadLocal;
057 import com.liferay.portal.kernel.servlet.SessionErrors;
058 import com.liferay.portal.kernel.servlet.StringServletResponse;
059 import com.liferay.portal.kernel.servlet.taglib.ui.BreadcrumbEntry;
060 import com.liferay.portal.kernel.upload.UploadPortletRequest;
061 import com.liferay.portal.kernel.upload.UploadServletRequest;
062 import com.liferay.portal.kernel.util.ArrayUtil;
063 import com.liferay.portal.kernel.util.Base64;
064 import com.liferay.portal.kernel.util.CalendarFactoryUtil;
065 import com.liferay.portal.kernel.util.CharPool;
066 import com.liferay.portal.kernel.util.ContentTypes;
067 import com.liferay.portal.kernel.util.ContextPathUtil;
068 import com.liferay.portal.kernel.util.DeterminateKeyGenerator;
069 import com.liferay.portal.kernel.util.GetterUtil;
070 import com.liferay.portal.kernel.util.HtmlUtil;
071 import com.liferay.portal.kernel.util.Http;
072 import com.liferay.portal.kernel.util.HttpUtil;
073 import com.liferay.portal.kernel.util.InheritableMap;
074 import com.liferay.portal.kernel.util.JavaConstants;
075 import com.liferay.portal.kernel.util.ListUtil;
076 import com.liferay.portal.kernel.util.LocaleUtil;
077 import com.liferay.portal.kernel.util.MethodHandler;
078 import com.liferay.portal.kernel.util.MethodKey;
079 import com.liferay.portal.kernel.util.ParamUtil;
080 import com.liferay.portal.kernel.util.PropsKeys;
081 import com.liferay.portal.kernel.util.ReleaseInfo;
082 import com.liferay.portal.kernel.util.ServerDetector;
083 import com.liferay.portal.kernel.util.SetUtil;
084 import com.liferay.portal.kernel.util.StringBundler;
085 import com.liferay.portal.kernel.util.StringComparator;
086 import com.liferay.portal.kernel.util.StringPool;
087 import com.liferay.portal.kernel.util.StringUtil;
088 import com.liferay.portal.kernel.util.Time;
089 import com.liferay.portal.kernel.util.UnicodeProperties;
090 import com.liferay.portal.kernel.util.UniqueList;
091 import com.liferay.portal.kernel.util.Validator;
092 import com.liferay.portal.kernel.xml.QName;
093 import com.liferay.portal.model.AuditedModel;
094 import com.liferay.portal.model.BaseModel;
095 import com.liferay.portal.model.ClassName;
096 import com.liferay.portal.model.ColorScheme;
097 import com.liferay.portal.model.Company;
098 import com.liferay.portal.model.Group;
099 import com.liferay.portal.model.GroupConstants;
100 import com.liferay.portal.model.Layout;
101 import com.liferay.portal.model.LayoutConstants;
102 import com.liferay.portal.model.LayoutSet;
103 import com.liferay.portal.model.LayoutType;
104 import com.liferay.portal.model.LayoutTypePortlet;
105 import com.liferay.portal.model.LayoutTypePortletConstants;
106 import com.liferay.portal.model.Organization;
107 import com.liferay.portal.model.Portlet;
108 import com.liferay.portal.model.PublicRenderParameter;
109 import com.liferay.portal.model.Resource;
110 import com.liferay.portal.model.ResourceCode;
111 import com.liferay.portal.model.ResourceConstants;
112 import com.liferay.portal.model.ResourcePermission;
113 import com.liferay.portal.model.Role;
114 import com.liferay.portal.model.RoleConstants;
115 import com.liferay.portal.model.Theme;
116 import com.liferay.portal.model.Ticket;
117 import com.liferay.portal.model.TicketConstants;
118 import com.liferay.portal.model.User;
119 import com.liferay.portal.model.UserGroup;
120 import com.liferay.portal.model.VirtualLayoutConstants;
121 import com.liferay.portal.model.impl.LayoutTypePortletImpl;
122 import com.liferay.portal.model.impl.VirtualLayout;
123 import com.liferay.portal.plugin.PluginPackageUtil;
124 import com.liferay.portal.security.auth.AuthException;
125 import com.liferay.portal.security.auth.AuthTokenUtil;
126 import com.liferay.portal.security.auth.CompanyThreadLocal;
127 import com.liferay.portal.security.auth.PrincipalException;
128 import com.liferay.portal.security.lang.DoPrivilegedUtil;
129 import com.liferay.portal.security.permission.ActionKeys;
130 import com.liferay.portal.security.permission.PermissionChecker;
131 import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
132 import com.liferay.portal.security.permission.ResourceActionsUtil;
133 import com.liferay.portal.service.ClassNameLocalServiceUtil;
134 import com.liferay.portal.service.CompanyLocalServiceUtil;
135 import com.liferay.portal.service.GroupLocalServiceUtil;
136 import com.liferay.portal.service.GroupServiceUtil;
137 import com.liferay.portal.service.LayoutLocalServiceUtil;
138 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
139 import com.liferay.portal.service.PortletLocalServiceUtil;
140 import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
141 import com.liferay.portal.service.ResourceCodeLocalServiceUtil;
142 import com.liferay.portal.service.ResourceLocalServiceUtil;
143 import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
144 import com.liferay.portal.service.TicketLocalServiceUtil;
145 import com.liferay.portal.service.UserLocalServiceUtil;
146 import com.liferay.portal.service.UserServiceUtil;
147 import com.liferay.portal.service.permission.GroupPermissionUtil;
148 import com.liferay.portal.service.permission.LayoutPermissionUtil;
149 import com.liferay.portal.service.permission.LayoutPrototypePermissionUtil;
150 import com.liferay.portal.service.permission.LayoutSetPrototypePermissionUtil;
151 import com.liferay.portal.service.permission.OrganizationPermissionUtil;
152 import com.liferay.portal.service.permission.PortletPermissionUtil;
153 import com.liferay.portal.service.permission.UserPermissionUtil;
154 import com.liferay.portal.servlet.filters.i18n.I18nFilter;
155 import com.liferay.portal.servlet.filters.secure.NonceUtil;
156 import com.liferay.portal.struts.StrutsUtil;
157 import com.liferay.portal.theme.PortletDisplay;
158 import com.liferay.portal.theme.ThemeDisplay;
159 import com.liferay.portal.upload.UploadPortletRequestImpl;
160 import com.liferay.portal.upload.UploadServletRequestImpl;
161 import com.liferay.portal.util.comparator.PortletControlPanelWeightComparator;
162 import com.liferay.portal.webserver.WebServerServlet;
163 import com.liferay.portlet.ActionResponseImpl;
164 import com.liferay.portlet.ControlPanelEntry;
165 import com.liferay.portlet.DefaultControlPanelEntryFactory;
166 import com.liferay.portlet.PortletConfigFactoryUtil;
167 import com.liferay.portlet.PortletPreferencesFactoryUtil;
168 import com.liferay.portlet.PortletPreferencesImpl;
169 import com.liferay.portlet.PortletPreferencesThreadLocal;
170 import com.liferay.portlet.PortletPreferencesWrapper;
171 import com.liferay.portlet.PortletQNameUtil;
172 import com.liferay.portlet.PortletRequestImpl;
173 import com.liferay.portlet.PortletResponseImpl;
174 import com.liferay.portlet.PortletURLFactoryUtil;
175 import com.liferay.portlet.PortletURLImpl;
176 import com.liferay.portlet.RenderRequestImpl;
177 import com.liferay.portlet.RenderResponseImpl;
178 import com.liferay.portlet.StateAwareResponseImpl;
179 import com.liferay.portlet.UserAttributes;
180 import com.liferay.portlet.admin.util.OmniadminUtil;
181 import com.liferay.portlet.asset.model.AssetTag;
182 import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
183 import com.liferay.portlet.blogs.model.BlogsEntry;
184 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
185 import com.liferay.portlet.calendar.model.CalEvent;
186 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
187 import com.liferay.portlet.expando.ValueDataException;
188 import com.liferay.portlet.expando.model.ExpandoBridge;
189 import com.liferay.portlet.expando.model.ExpandoColumnConstants;
190 import com.liferay.portlet.journal.asset.JournalArticleAssetRendererFactory;
191 import com.liferay.portlet.journal.model.JournalArticle;
192 import com.liferay.portlet.journal.model.JournalArticleConstants;
193 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
194 import com.liferay.portlet.login.util.LoginUtil;
195 import com.liferay.portlet.messageboards.model.MBMessage;
196 import com.liferay.portlet.messageboards.model.MBThread;
197 import com.liferay.portlet.social.model.SocialRelationConstants;
198 import com.liferay.portlet.social.util.FacebookUtil;
199 import com.liferay.portlet.wiki.model.WikiPage;
200 import com.liferay.util.Encryptor;
201 import com.liferay.util.JS;
202 import com.liferay.util.PwdGenerator;
203
204 import java.io.IOException;
205 import java.io.Serializable;
206
207 import java.lang.reflect.Method;
208
209 import java.net.InetAddress;
210 import java.net.UnknownHostException;
211
212 import java.util.ArrayList;
213 import java.util.Arrays;
214 import java.util.Calendar;
215 import java.util.Collection;
216 import java.util.Collections;
217 import java.util.Date;
218 import java.util.Enumeration;
219 import java.util.HashMap;
220 import java.util.HashSet;
221 import java.util.Iterator;
222 import java.util.List;
223 import java.util.Locale;
224 import java.util.Map;
225 import java.util.Properties;
226 import java.util.ResourceBundle;
227 import java.util.Set;
228 import java.util.TimeZone;
229 import java.util.TreeSet;
230 import java.util.concurrent.ConcurrentHashMap;
231 import java.util.concurrent.atomic.AtomicInteger;
232 import java.util.regex.Matcher;
233 import java.util.regex.Pattern;
234
235 import javax.portlet.ActionRequest;
236 import javax.portlet.ActionResponse;
237 import javax.portlet.PortletConfig;
238 import javax.portlet.PortletMode;
239 import javax.portlet.PortletPreferences;
240 import javax.portlet.PortletRequest;
241 import javax.portlet.PortletResponse;
242 import javax.portlet.PortletURL;
243 import javax.portlet.PreferencesValidator;
244 import javax.portlet.RenderRequest;
245 import javax.portlet.RenderResponse;
246 import javax.portlet.ValidatorException;
247 import javax.portlet.WindowState;
248
249 import javax.servlet.RequestDispatcher;
250 import javax.servlet.ServletContext;
251 import javax.servlet.ServletException;
252 import javax.servlet.http.HttpServletRequest;
253 import javax.servlet.http.HttpServletRequestWrapper;
254 import javax.servlet.http.HttpServletResponse;
255 import javax.servlet.http.HttpSession;
256 import javax.servlet.jsp.PageContext;
257
258 import org.apache.struts.Globals;
259
260
270 @DoPrivileged
271 public class PortalImpl implements Portal {
272
273 public PortalImpl() {
274
275
276
277 _computerName = System.getProperty("env.COMPUTERNAME");
278
279 if (Validator.isNull(_computerName)) {
280 _computerName = System.getProperty("env.HOST");
281 }
282
283 if (Validator.isNull(_computerName)) {
284 _computerName = System.getProperty("env.HOSTNAME");
285 }
286
287 if (Validator.isNull(_computerName)) {
288 try {
289 _computerName = InetAddress.getLocalHost().getHostName();
290 }
291 catch (UnknownHostException uhe) {
292 }
293 }
294
295 try {
296 _computerAddress = InetAddress.getByName(
297 _computerName).getHostAddress();
298 }
299 catch (UnknownHostException uhe) {
300 }
301
302 if (Validator.isNull(_computerAddress)) {
303 try {
304 _computerAddress = InetAddress.getLocalHost().getHostAddress();
305 }
306 catch (UnknownHostException uhe) {
307 }
308 }
309
310
311
312 _pathProxy = PropsValues.PORTAL_PROXY_PATH;
313
314 _pathContext = ContextPathUtil.getContextPath(PropsValues.PORTAL_CTX);
315 _pathContext = _pathProxy.concat(_pathContext);
316
317 _pathFriendlyURLPrivateGroup =
318 _pathContext + _PRIVATE_GROUP_SERVLET_MAPPING;
319 _pathFriendlyURLPrivateUser =
320 _pathContext + _PRIVATE_USER_SERVLET_MAPPING;
321 _pathFriendlyURLPublic = _pathContext + _PUBLIC_GROUP_SERVLET_MAPPING;
322 _pathImage = _pathContext + PATH_IMAGE;
323 _pathMain = _pathContext + PATH_MAIN;
324
325
326
327 String[] customSystemGroups = PropsUtil.getArray(
328 PropsKeys.SYSTEM_GROUPS);
329
330 if ((customSystemGroups == null) || (customSystemGroups.length == 0)) {
331 _allSystemGroups = GroupConstants.SYSTEM_GROUPS;
332 }
333 else {
334 _allSystemGroups = ArrayUtil.append(
335 GroupConstants.SYSTEM_GROUPS, customSystemGroups);
336 }
337
338 _sortedSystemGroups = new String[_allSystemGroups.length];
339
340 System.arraycopy(
341 _allSystemGroups, 0, _sortedSystemGroups, 0,
342 _allSystemGroups.length);
343
344 Arrays.sort(_sortedSystemGroups, new StringComparator());
345
346
347
348 String[] customSystemRoles = PropsUtil.getArray(PropsKeys.SYSTEM_ROLES);
349
350 if ((customSystemRoles == null) || (customSystemRoles.length == 0)) {
351 _allSystemRoles = RoleConstants.SYSTEM_ROLES;
352 }
353 else {
354 _allSystemRoles = ArrayUtil.append(
355 RoleConstants.SYSTEM_ROLES, customSystemRoles);
356 }
357
358 _sortedSystemRoles = new String[_allSystemRoles.length];
359
360 System.arraycopy(
361 _allSystemRoles, 0, _sortedSystemRoles, 0, _allSystemRoles.length);
362
363 Arrays.sort(_sortedSystemRoles, new StringComparator());
364
365
366
367 String[] customSystemOrganizationRoles = PropsUtil.getArray(
368 PropsKeys.SYSTEM_ORGANIZATION_ROLES);
369
370 if ((customSystemOrganizationRoles == null) ||
371 (customSystemOrganizationRoles.length == 0)) {
372
373 _allSystemOrganizationRoles =
374 RoleConstants.SYSTEM_ORGANIZATION_ROLES;
375 }
376 else {
377 _allSystemOrganizationRoles = ArrayUtil.append(
378 RoleConstants.SYSTEM_ORGANIZATION_ROLES,
379 customSystemOrganizationRoles);
380 }
381
382 _sortedSystemOrganizationRoles =
383 new String[_allSystemOrganizationRoles.length];
384
385 System.arraycopy(
386 _allSystemOrganizationRoles, 0, _sortedSystemOrganizationRoles, 0,
387 _allSystemOrganizationRoles.length);
388
389 Arrays.sort(_sortedSystemOrganizationRoles, new StringComparator());
390
391
392
393 String[] customSystemSiteRoles = PropsUtil.getArray(
394 PropsKeys.SYSTEM_SITE_ROLES);
395
396 if ((customSystemSiteRoles == null) ||
397 (customSystemSiteRoles.length == 0)) {
398
399 _allSystemSiteRoles = RoleConstants.SYSTEM_SITE_ROLES;
400 }
401 else {
402 _allSystemSiteRoles = ArrayUtil.append(
403 RoleConstants.SYSTEM_SITE_ROLES, customSystemSiteRoles);
404 }
405
406 _sortedSystemSiteRoles = new String[_allSystemSiteRoles.length];
407
408 System.arraycopy(
409 _allSystemSiteRoles, 0, _sortedSystemSiteRoles, 0,
410 _allSystemSiteRoles.length);
411
412 Arrays.sort(_sortedSystemSiteRoles, new StringComparator());
413
414
415
416 _authTokenIgnoreActions = SetUtil.fromArray(
417 PropsValues.AUTH_TOKEN_IGNORE_ACTIONS);
418 _authTokenIgnorePortlets = SetUtil.fromArray(
419 PropsValues.AUTH_TOKEN_IGNORE_PORTLETS);
420
421
422
423 resetPortletAddDefaultResourceCheckWhitelist();
424 resetPortletAddDefaultResourceCheckWhitelistActions();
425
426
427
428 _reservedParams = new HashSet<String>();
429
430
431
432 _reservedParams.add("p_auth");
433 _reservedParams.add("p_auth_secret");
434
435
436
437 _reservedParams.add("p_l_id");
438 _reservedParams.add("p_l_reset");
439
440
441
442 _reservedParams.add("p_p_auth");
443 _reservedParams.add("p_p_id");
444 _reservedParams.add("p_p_i_id");
445 _reservedParams.add("p_p_lifecycle");
446 _reservedParams.add("p_p_url_type");
447 _reservedParams.add("p_p_state");
448 _reservedParams.add("p_p_state_rcv");
449 _reservedParams.add("p_p_mode");
450 _reservedParams.add("p_p_resource_id");
451 _reservedParams.add("p_p_cacheability");
452 _reservedParams.add("p_p_width");
453 _reservedParams.add("p_p_col_id");
454 _reservedParams.add("p_p_col_pos");
455 _reservedParams.add("p_p_col_count");
456 _reservedParams.add("p_p_static");
457 _reservedParams.add("p_p_isolated");
458
459
460
461 _reservedParams.add("p_t_lifecycle");
462
463
464
465 _reservedParams.add("p_v_l_s_g_id");
466
467
468
469 _reservedParams.add("p_f_id");
470
471
472
473 _reservedParams.add("p_j_a_id");
474
475
476
477 _reservedParams.add("saveLastPath");
478 _reservedParams.add("scroll");
479 }
480
481 @Override
482 public void addPageDescription(
483 String description, HttpServletRequest request) {
484
485 String requestDescription = (String)request.getAttribute(
486 WebKeys.PAGE_DESCRIPTION);
487
488 if (requestDescription != null) {
489 description = requestDescription + StringPool.SPACE + description;
490 }
491
492 request.setAttribute(WebKeys.PAGE_DESCRIPTION, description);
493 }
494
495 @Override
496 public void addPageKeywords(String keywords, HttpServletRequest request) {
497 List<String> requestKeywords = (List<String>)request.getAttribute(
498 WebKeys.PAGE_KEYWORDS);
499
500 if (requestKeywords == null) {
501 requestKeywords = new UniqueList<String>();
502 }
503
504 String[] keywordsArray = StringUtil.split(keywords);
505
506 for (String keyword : keywordsArray) {
507 if (!requestKeywords.contains(keyword.toLowerCase())) {
508 requestKeywords.add(keyword.toLowerCase());
509 }
510 }
511
512 request.setAttribute(WebKeys.PAGE_KEYWORDS, requestKeywords);
513 }
514
515 @Override
516 public void addPageSubtitle(String subtitle, HttpServletRequest request) {
517 String requestSubtitle = (String)request.getAttribute(
518 WebKeys.PAGE_SUBTITLE);
519
520 if (requestSubtitle != null) {
521 subtitle = requestSubtitle + StringPool.SPACE + subtitle;
522 }
523
524 request.setAttribute(WebKeys.PAGE_SUBTITLE, subtitle);
525 }
526
527 @Override
528 public void addPageTitle(String title, HttpServletRequest request) {
529 String requestTitle = (String)request.getAttribute(WebKeys.PAGE_TITLE);
530
531 if (requestTitle != null) {
532 title = requestTitle + StringPool.SPACE + title;
533 }
534
535 request.setAttribute(WebKeys.PAGE_TITLE, title);
536 }
537
538 @Override
539 public void addPortalPortEventListener(
540 PortalPortEventListener portalPortEventListener) {
541
542 if (!_portalPortEventListeners.contains(portalPortEventListener)) {
543 _portalPortEventListeners.add(portalPortEventListener);
544 }
545 }
546
547 @Override
548 public void addPortletBreadcrumbEntry(
549 HttpServletRequest request, String title, String url) {
550
551 addPortletBreadcrumbEntry(request, title, url, null);
552 }
553
554 @Override
555 public void addPortletBreadcrumbEntry(
556 HttpServletRequest request, String title, String url,
557 Map<String, Object> data) {
558
559 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
560 WebKeys.THEME_DISPLAY);
561
562 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
563
564 String name = WebKeys.PORTLET_BREADCRUMBS;
565
566 if (Validator.isNotNull(portletDisplay.getId()) &&
567 !portletDisplay.isFocused()) {
568
569 name += StringPool.UNDERLINE + portletDisplay.getId();
570 }
571
572 List<BreadcrumbEntry> breadcrumbEntries =
573 (List<BreadcrumbEntry>)request.getAttribute(name);
574
575 if (breadcrumbEntries == null) {
576 breadcrumbEntries = new ArrayList<BreadcrumbEntry>();
577
578 request.setAttribute(name, breadcrumbEntries);
579 }
580
581 BreadcrumbEntry breadcrumbEntry = new BreadcrumbEntry();
582
583 breadcrumbEntry.setData(data);
584 breadcrumbEntry.setTitle(title);
585 breadcrumbEntry.setURL(url);
586
587 breadcrumbEntries.add(breadcrumbEntry);
588 }
589
590 @Override
591 public void addPortletDefaultResource(
592 HttpServletRequest request, Portlet portlet)
593 throws PortalException, SystemException {
594
595 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
596 WebKeys.THEME_DISPLAY);
597
598 Layout layout = themeDisplay.getLayout();
599
600 long groupId = 0;
601
602 if (layout.isTypeControlPanel()) {
603 groupId = themeDisplay.getScopeGroupId();
604 }
605 else {
606 groupId = getScopeGroupId(layout, portlet.getPortletId());
607 }
608
609 addDefaultResource(
610 themeDisplay.getCompanyId(), groupId, layout, portlet, true);
611 addDefaultResource(
612 themeDisplay.getCompanyId(), groupId, layout, portlet, false);
613 }
614
615 @Override
616 public void addPortletDefaultResource(
617 long companyId, Layout layout, Portlet portlet)
618 throws PortalException, SystemException {
619
620 addDefaultResource(companyId, layout, portlet, true);
621 addDefaultResource(companyId, layout, portlet, false);
622 }
623
624 @Override
625 public String addPreservedParameters(
626 ThemeDisplay themeDisplay, Layout layout, String url,
627 boolean doAsUser) {
628
629 if (doAsUser) {
630 if (Validator.isNotNull(themeDisplay.getDoAsUserId())) {
631 url = HttpUtil.addParameter(
632 url, "doAsUserId", themeDisplay.getDoAsUserId());
633 }
634
635 if (Validator.isNotNull(themeDisplay.getDoAsUserLanguageId())) {
636 url = HttpUtil.addParameter(
637 url, "doAsUserLanguageId",
638 themeDisplay.getDoAsUserLanguageId());
639 }
640 }
641
642 if (layout.isTypeControlPanel()) {
643 if (themeDisplay.getDoAsGroupId() > 0) {
644 url = HttpUtil.addParameter(
645 url, "doAsGroupId", themeDisplay.getDoAsGroupId());
646 }
647
648 if (themeDisplay.getRefererPlid() != LayoutConstants.DEFAULT_PLID) {
649 url = HttpUtil.addParameter(
650 url, "refererPlid", themeDisplay.getRefererPlid());
651 }
652
653 if (Validator.isNotNull(themeDisplay.getControlPanelCategory())) {
654 url = HttpUtil.addParameter(
655 url, "controlPanelCategory",
656 themeDisplay.getControlPanelCategory());
657 }
658 }
659
660 return url;
661 }
662
663 @Override
664 public String addPreservedParameters(
665 ThemeDisplay themeDisplay, String url) {
666
667 return addPreservedParameters(
668 themeDisplay, themeDisplay.getLayout(), url, true);
669 }
670
671 @Override
672 public void clearRequestParameters(RenderRequest renderRequest) {
673 RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
674
675 if (renderRequestImpl.isTriggeredByActionURL()) {
676 Map<String, String[]> renderParameters =
677 renderRequestImpl.getRenderParameters();
678
679 renderParameters.clear();
680 }
681 }
682
683 @Override
684 public void copyRequestParameters(
685 ActionRequest actionRequest, ActionResponse actionResponse) {
686
687 if (actionResponse instanceof StateAwareResponseImpl) {
688 StateAwareResponseImpl stateAwareResponseImpl =
689 (StateAwareResponseImpl)actionResponse;
690
691 if (stateAwareResponseImpl.getRedirectLocation() != null) {
692 if (_log.isDebugEnabled()) {
693 _log.debug(
694 "Cannot copy parameters on a redirected " +
695 "StateAwareResponseImpl");
696 }
697
698 return;
699 }
700 }
701
702 ActionResponseImpl actionResponseImpl =
703 (ActionResponseImpl)actionResponse;
704
705 Map<String, String[]> renderParameters =
706 actionResponseImpl.getRenderParameterMap();
707
708 actionResponse.setRenderParameter("p_p_lifecycle", "1");
709
710 Enumeration<String> enu = actionRequest.getParameterNames();
711
712 while (enu.hasMoreElements()) {
713 String param = enu.nextElement();
714 String[] values = actionRequest.getParameterValues(param);
715
716 if (renderParameters.get(
717 actionResponseImpl.getNamespace() + param) == null) {
718
719 actionResponse.setRenderParameter(param, values);
720 }
721 }
722 }
723
724 @Override
725 public String escapeRedirect(String url) {
726 if (Validator.isNull(url) || !HttpUtil.hasDomain(url)) {
727 return url;
728 }
729
730 String domain = HttpUtil.getDomain(url);
731
732 int pos = domain.indexOf(CharPool.COLON);
733
734 if (pos != -1) {
735 domain = domain.substring(0, pos);
736 }
737
738 try {
739 Company company = CompanyLocalServiceUtil.fetchCompanyByVirtualHost(
740 domain);
741
742 if (company != null) {
743 return url;
744 }
745 }
746 catch (Exception e) {
747 }
748
749 try {
750 LayoutSet layoutSet = LayoutSetLocalServiceUtil.fetchLayoutSet(
751 domain);
752
753 if (layoutSet != null) {
754 return url;
755 }
756 }
757 catch (Exception e) {
758 }
759
760 try {
761 String securityMode = PropsValues.REDIRECT_URL_SECURITY_MODE;
762
763 if (securityMode.equals("domain")) {
764 String[] allowedDomains =
765 PropsValues.REDIRECT_URL_DOMAINS_ALLOWED;
766
767 if ((allowedDomains.length > 0) &&
768 !ArrayUtil.contains(allowedDomains, domain)) {
769
770 if (_log.isDebugEnabled()) {
771 _log.debug("Redirect URL " + url + " is not allowed");
772 }
773
774 url = null;
775 }
776 }
777 else if (securityMode.equals("ip")) {
778 String[] allowedIps = PropsValues.REDIRECT_URL_IPS_ALLOWED;
779
780 InetAddress inetAddress = InetAddress.getByName(domain);
781
782 if ((allowedIps.length > 0) &&
783 !ArrayUtil.contains(
784 allowedIps, inetAddress.getHostAddress())) {
785
786 String serverIp = getComputerAddress();
787
788 if (!serverIp.equals(inetAddress.getHostAddress()) ||
789 !ArrayUtil.contains(allowedIps, "SERVER_IP")) {
790
791 if (_log.isDebugEnabled()) {
792 _log.debug(
793 "Redirect URL " + url + " is not allowed");
794 }
795
796 url = null;
797 }
798 }
799 }
800 }
801 catch (UnknownHostException uhe) {
802 if (_log.isDebugEnabled()) {
803 _log.debug("Unable to determine IP for redirect URL " + url);
804 }
805
806 url = null;
807 }
808
809 return url;
810 }
811
812 @Override
813 public String generateRandomKey(HttpServletRequest request, String input) {
814 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
815 WebKeys.THEME_DISPLAY);
816
817 if (themeDisplay.isAjax() || themeDisplay.isIsolated() ||
818 themeDisplay.isLifecycleResource() ||
819 themeDisplay.isStateExclusive()) {
820
821 return PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
822 }
823 else {
824 return DeterminateKeyGenerator.generate(input);
825 }
826 }
827
828 @Override
829 public String getActualURL(
830 long groupId, boolean privateLayout, String mainPath,
831 String friendlyURL, Map<String, String[]> params,
832 Map<String, Object> requestContext)
833 throws PortalException, SystemException {
834
835 String actualURL = null;
836
837 if (friendlyURL != null) {
838 if (friendlyURL.startsWith(
839 JournalArticleConstants.CANONICAL_URL_SEPARATOR)) {
840
841 try {
842 actualURL = getJournalArticleActualURL(
843 groupId, privateLayout, mainPath, friendlyURL, params,
844 requestContext);
845 }
846 catch (Exception e) {
847 throw new NoSuchLayoutException(e);
848 }
849 }
850 else if (friendlyURL.startsWith(
851 VirtualLayoutConstants.CANONICAL_URL_SEPARATOR)) {
852
853 try {
854 actualURL = getVirtualLayoutActualURL(
855 groupId, privateLayout, mainPath, friendlyURL, params,
856 requestContext);
857 }
858 catch (Exception e) {
859 throw new NoSuchLayoutException(e);
860 }
861 }
862 }
863
864 if (actualURL == null) {
865 actualURL = getLayoutActualURL(
866 groupId, privateLayout, mainPath, friendlyURL, params,
867 requestContext);
868 }
869
870 return actualURL;
871 }
872
873 @Override
874 public Locale[] getAlternateLocales(HttpServletRequest request)
875 throws PortalException, SystemException {
876
877 Locale[] availableLocales = LanguageUtil.getAvailableLocales();
878
879 long mainJournalArticleId = ParamUtil.getLong(request, "p_j_a_id");
880
881 if (mainJournalArticleId <= 0) {
882 return availableLocales;
883 }
884
885 JournalArticle mainJournalArticle =
886 JournalArticleLocalServiceUtil.getJournalArticle(
887 mainJournalArticleId);
888
889 if (mainJournalArticle == null) {
890 return availableLocales;
891 }
892
893 String[] articleLocales = mainJournalArticle.getAvailableLocales();
894
895 if (articleLocales.length > 1) {
896 Locale[] alternateLocales = new Locale[
897 availableLocales.length - articleLocales.length];
898
899 int i = 0;
900
901 for (Locale locale : availableLocales) {
902 if (!ArrayUtil.contains(
903 articleLocales, LocaleUtil.toLanguageId(locale))) {
904
905 alternateLocales[i] = locale;
906
907 i++;
908 }
909 }
910
911 return alternateLocales;
912 }
913
914 return availableLocales;
915 }
916
917
920 @Override
921 public String getAlternateURL(
922 HttpServletRequest request, String canonicalURL, Locale locale) {
923
924 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
925 WebKeys.THEME_DISPLAY);
926
927 return getAlternateURL(canonicalURL, themeDisplay, locale);
928 }
929
930 @Override
931 public String getAlternateURL(
932 String canonicalURL, ThemeDisplay themeDisplay, Locale locale) {
933
934 LayoutSet layoutSet = themeDisplay.getLayoutSet();
935
936 String virtualHost = null;
937
938 if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
939 virtualHost = layoutSet.getVirtualHostname();
940 }
941 else {
942 Company company = themeDisplay.getCompany();
943
944 virtualHost = company.getVirtualHostname();
945 }
946
947 String i18nPath = buildI18NPath(locale);
948
949 if (Validator.isNull(virtualHost)) {
950 return canonicalURL.replaceFirst(
951 _PUBLIC_GROUP_SERVLET_MAPPING,
952 i18nPath.concat(_PUBLIC_GROUP_SERVLET_MAPPING));
953 }
954
955
956
957 int pos = canonicalURL.indexOf(virtualHost);
958
959 if (pos > 0) {
960 pos = canonicalURL.indexOf(
961 CharPool.SLASH, pos + virtualHost.length());
962
963 if (Validator.isNotNull(_pathContext)) {
964 pos = canonicalURL.indexOf(
965 CharPool.SLASH, pos + _pathContext.length());
966 }
967
968 if ((pos > 0) && (pos < canonicalURL.length())) {
969 return canonicalURL.substring(0, pos).concat(
970 i18nPath).concat(canonicalURL.substring(pos));
971 }
972 }
973
974 return canonicalURL.concat(i18nPath);
975 }
976
977 @Override
978 public Set<String> getAuthTokenIgnoreActions() {
979 return _authTokenIgnoreActions;
980 }
981
982 @Override
983 public Set<String> getAuthTokenIgnorePortlets() {
984 return _authTokenIgnorePortlets;
985 }
986
987 @Override
988 public BaseModel<?> getBaseModel(Resource resource)
989 throws PortalException, SystemException {
990
991 ResourceCode resourceCode =
992 ResourceCodeLocalServiceUtil.getResourceCode(resource.getCodeId());
993
994 String modelName = resourceCode.getName();
995 String primKey = resource.getPrimKey();
996
997 return getBaseModel(modelName, primKey);
998 }
999
1000 @Override
1001 public BaseModel<?> getBaseModel(ResourcePermission resourcePermission)
1002 throws PortalException, SystemException {
1003
1004 String modelName = resourcePermission.getName();
1005 String primKey = resourcePermission.getPrimKey();
1006
1007 return getBaseModel(modelName, primKey);
1008 }
1009
1010 @Override
1011 public BaseModel<?> getBaseModel(String modelName, String primKey)
1012 throws PortalException, SystemException {
1013
1014 if (!modelName.contains(".model.")) {
1015 return null;
1016 }
1017
1018 String[] parts = StringUtil.split(modelName, CharPool.PERIOD);
1019
1020 if ((parts.length <= 2) || !parts[parts.length - 2].equals("model")) {
1021 return null;
1022 }
1023
1024 parts[parts.length - 2] = "service";
1025
1026 String serviceName =
1027 StringUtil.merge(parts, StringPool.PERIOD) + "LocalServiceUtil";
1028 String methodName = "get" + parts[parts.length - 1];
1029
1030 Method method = null;
1031
1032 try {
1033 Class<?> serviceUtil = Class.forName(serviceName);
1034
1035 if (Validator.isNumber(primKey)) {
1036 method = serviceUtil.getMethod(
1037 methodName, new Class[] {Long.TYPE});
1038
1039 return (BaseModel<?>)method.invoke(null, new Long(primKey));
1040 }
1041 else {
1042 method = serviceUtil.getMethod(
1043 methodName, new Class[] {String.class});
1044
1045 return (BaseModel<?>)method.invoke(null, primKey);
1046 }
1047 }
1048 catch (Exception e) {
1049 Throwable cause = e.getCause();
1050
1051 if (cause instanceof PortalException) {
1052 throw (PortalException)cause;
1053 }
1054 else if (cause instanceof SystemException) {
1055 throw (SystemException)cause;
1056 }
1057 else {
1058 throw new SystemException(cause);
1059 }
1060 }
1061 }
1062
1063 @Override
1064 public long getBasicAuthUserId(HttpServletRequest request)
1065 throws PortalException, SystemException {
1066
1067 long companyId = PortalInstances.getCompanyId(request);
1068
1069 return getBasicAuthUserId(request, companyId);
1070 }
1071
1072 @Override
1073 public long getBasicAuthUserId(HttpServletRequest request, long companyId)
1074 throws PortalException, SystemException {
1075
1076 long userId = 0;
1077
1078 String authorizationHeader = request.getHeader(
1079 HttpHeaders.AUTHORIZATION);
1080
1081 if (Validator.isNull(authorizationHeader)) {
1082 return userId;
1083 }
1084
1085 String[] authorizationArray = authorizationHeader.split("\\s+");
1086
1087 String authorization = authorizationArray[0];
1088 String credentials = new String(Base64.decode(authorizationArray[1]));
1089
1090 if (!authorization.equalsIgnoreCase(HttpServletRequest.BASIC_AUTH)) {
1091 return userId;
1092 }
1093
1094 String[] loginAndPassword = StringUtil.split(
1095 credentials, CharPool.COLON);
1096
1097 String login = HttpUtil.decodeURL(loginAndPassword[0].trim());
1098
1099 String password = null;
1100
1101 if (loginAndPassword.length > 1) {
1102 password = loginAndPassword[1].trim();
1103 }
1104
1105
1106
1107 if (login.endsWith("@uid")) {
1108 int pos = login.indexOf("@uid");
1109
1110 login = login.substring(0, pos);
1111 }
1112 else if (login.endsWith("@sn")) {
1113 int pos = login.indexOf("@sn");
1114
1115 login = login.substring(0, pos);
1116 }
1117
1118 try {
1119 userId = LoginUtil.getAuthenticatedUserId(
1120 request, login, password, null);
1121 }
1122 catch (AuthException ae) {
1123 }
1124
1125 return userId;
1126 }
1127
1128
1131 @Override
1132 public String getCanonicalURL(String completeURL, ThemeDisplay themeDisplay)
1133 throws PortalException, SystemException {
1134
1135 Layout layout = themeDisplay.getLayout();
1136
1137 return getCanonicalURL(completeURL, themeDisplay, layout);
1138 }
1139
1140 @Override
1141 public String getCanonicalURL(
1142 String completeURL, ThemeDisplay themeDisplay, Layout layout)
1143 throws PortalException, SystemException {
1144
1145 return getCanonicalURL(completeURL, themeDisplay, layout, false);
1146 }
1147
1148 @Override
1149 public String getCanonicalURL(
1150 String completeURL, ThemeDisplay themeDisplay, Layout layout,
1151 boolean forceLayoutFriendlyURL)
1152 throws PortalException, SystemException {
1153
1154 String groupFriendlyURL = StringPool.BLANK;
1155 String parametersURL = StringPool.BLANK;
1156
1157 if (Validator.isNotNull(completeURL)) {
1158 completeURL = removeRedirectParameter(completeURL);
1159
1160 int pos = completeURL.indexOf(Portal.FRIENDLY_URL_SEPARATOR);
1161
1162 if (pos == -1) {
1163 pos = completeURL.indexOf(StringPool.QUESTION);
1164 }
1165
1166 groupFriendlyURL = completeURL;
1167
1168 if (pos != -1) {
1169 groupFriendlyURL = completeURL.substring(0, pos);
1170 parametersURL = completeURL.substring(pos);
1171 }
1172 }
1173
1174 if (layout == null) {
1175 layout = themeDisplay.getLayout();
1176 }
1177
1178 String layoutFriendlyURL = StringPool.BLANK;
1179
1180 if ((groupFriendlyURL.contains(layout.getFriendlyURL()) ||
1181 groupFriendlyURL.contains(
1182 StringPool.SLASH + layout.getLayoutId())) &&
1183 (!layout.isFirstParent() || Validator.isNotNull(parametersURL))) {
1184
1185 layoutFriendlyURL = layout.getFriendlyURL();
1186 }
1187 else if (forceLayoutFriendlyURL) {
1188 layoutFriendlyURL = layout.getFriendlyURL();
1189 }
1190
1191 Group group = layout.getGroup();
1192
1193 groupFriendlyURL = getGroupFriendlyURL(
1194 group, layout.isPrivateLayout(), themeDisplay, true);
1195
1196 return groupFriendlyURL.concat(layoutFriendlyURL).concat(parametersURL);
1197 }
1198
1199
1202 @Override
1203 public String getCDNHost() {
1204 long companyId = CompanyThreadLocal.getCompanyId();
1205
1206 return getCDNHostHttp(companyId);
1207 }
1208
1209 @Override
1210 public String getCDNHost(boolean secure) {
1211 long companyId = CompanyThreadLocal.getCompanyId();
1212
1213 if (secure) {
1214 return getCDNHostHttps(companyId);
1215 }
1216 else {
1217 return getCDNHostHttp(companyId);
1218 }
1219 }
1220
1221 @Override
1222 public String getCDNHost(HttpServletRequest request)
1223 throws PortalException, SystemException {
1224
1225 boolean cdnEnabled = ParamUtil.getBoolean(request, "cdn_enabled", true);
1226
1227 if (!cdnEnabled) {
1228 return StringPool.BLANK;
1229 }
1230
1231 String cdnHost = null;
1232
1233 Company company = getCompany(request);
1234
1235 if (request.isSecure()) {
1236 cdnHost = getCDNHostHttps(company.getCompanyId());
1237 }
1238 else {
1239 cdnHost = getCDNHostHttp(company.getCompanyId());
1240 }
1241
1242 if (Validator.isUrl(cdnHost)) {
1243 return cdnHost;
1244 }
1245
1246 return StringPool.BLANK;
1247 }
1248
1249 @Override
1250 public String getCDNHostHttp(long companyId) {
1251 String cdnHostHttp = _cdnHostHttpMap.get(companyId);
1252
1253 if (cdnHostHttp != null) {
1254 return cdnHostHttp;
1255 }
1256
1257 try {
1258 cdnHostHttp = PrefsPropsUtil.getString(
1259 companyId, PropsKeys.CDN_HOST_HTTP, PropsValues.CDN_HOST_HTTP);
1260 }
1261 catch (Exception e) {
1262 }
1263
1264 if ((cdnHostHttp == null) || cdnHostHttp.startsWith("${") ||
1265 !Validator.isUrl(cdnHostHttp)) {
1266
1267 cdnHostHttp = StringPool.BLANK;
1268 }
1269
1270 _cdnHostHttpMap.put(companyId, cdnHostHttp);
1271
1272 return cdnHostHttp;
1273 }
1274
1275 @Override
1276 public String getCDNHostHttps(long companyId) {
1277 String cdnHostHttps = _cdnHostHttpsMap.get(companyId);
1278
1279 if (cdnHostHttps != null) {
1280 return cdnHostHttps;
1281 }
1282
1283 try {
1284 cdnHostHttps = PrefsPropsUtil.getString(
1285 companyId, PropsKeys.CDN_HOST_HTTPS,
1286 PropsValues.CDN_HOST_HTTPS);
1287 }
1288 catch (SystemException se) {
1289 }
1290
1291 if ((cdnHostHttps == null) || cdnHostHttps.startsWith("${") ||
1292 !Validator.isUrl(cdnHostHttps)) {
1293
1294 cdnHostHttps = StringPool.BLANK;
1295 }
1296
1297 _cdnHostHttpsMap.put(companyId, cdnHostHttps);
1298
1299 return cdnHostHttps;
1300 }
1301
1302 @Override
1303 public String getClassName(long classNameId) {
1304 try {
1305 ClassName className = ClassNameLocalServiceUtil.getClassName(
1306 classNameId);
1307
1308 return className.getValue();
1309 }
1310 catch (Exception e) {
1311 throw new RuntimeException(
1312 "Unable to get class name from id " + classNameId);
1313 }
1314 }
1315
1316 @Override
1317 public long getClassNameId(Class<?> clazz) {
1318 return ClassNameLocalServiceUtil.getClassNameId(clazz);
1319 }
1320
1321 @Override
1322 public long getClassNameId(String value) {
1323 return ClassNameLocalServiceUtil.getClassNameId(value);
1324 }
1325
1326 @Override
1327 public String getClassNamePortletId(String className) {
1328 String portletId = StringPool.BLANK;
1329
1330 if (className.startsWith("com.liferay.portlet.blogs")) {
1331 portletId = PortletKeys.BLOGS;
1332 }
1333 else if (className.startsWith("com.liferay.portlet.bookmarks")) {
1334 portletId = PortletKeys.BOOKMARKS;
1335 }
1336 else if (className.startsWith("com.liferay.portlet.calendar")) {
1337 portletId = PortletKeys.CALENDAR;
1338 }
1339 else if (className.startsWith("com.liferay.portlet.documentlibrary")) {
1340 portletId = PortletKeys.DOCUMENT_LIBRARY;
1341 }
1342 else if (className.startsWith("com.liferay.portlet.imagegallery")) {
1343 portletId = PortletKeys.MEDIA_GALLERY_DISPLAY;
1344 }
1345 else if (className.startsWith("com.liferay.portlet.journal")) {
1346 portletId = PortletKeys.JOURNAL;
1347 }
1348 else if (className.startsWith("com.liferay.portlet.messageboards")) {
1349 portletId = PortletKeys.MESSAGE_BOARDS;
1350 }
1351 else if (className.startsWith("com.liferay.portlet.wiki")) {
1352 portletId = PortletKeys.WIKI;
1353 }
1354
1355 return portletId;
1356 }
1357
1358 @Override
1359 public Company getCompany(HttpServletRequest request)
1360 throws PortalException, SystemException {
1361
1362 long companyId = getCompanyId(request);
1363
1364 if (companyId <= 0) {
1365 return null;
1366 }
1367
1368 Company company = (Company)request.getAttribute(WebKeys.COMPANY);
1369
1370 if (company == null) {
1371
1372
1373
1374 try {
1375 company = CompanyLocalServiceUtil.getCompanyById(companyId);
1376 }
1377 catch (NoSuchCompanyException nsce) {
1378 company = CompanyLocalServiceUtil.getCompanyById(
1379 PortalInstances.getDefaultCompanyId());
1380 }
1381
1382 request.setAttribute(WebKeys.COMPANY, company);
1383 }
1384
1385 return company;
1386 }
1387
1388 @Override
1389 public Company getCompany(PortletRequest portletRequest)
1390 throws PortalException, SystemException {
1391
1392 return getCompany(getHttpServletRequest(portletRequest));
1393 }
1394
1395 @Override
1396 public long getCompanyId(HttpServletRequest request) {
1397 return PortalInstances.getCompanyId(request);
1398 }
1399
1400 @Override
1401 public long getCompanyId(PortletRequest portletRequest) {
1402 return getCompanyId(getHttpServletRequest(portletRequest));
1403 }
1404
1405 @Override
1406 public long[] getCompanyIds() {
1407 return PortalInstances.getCompanyIds();
1408 }
1409
1410 @Override
1411 public String getComputerAddress() {
1412 return _computerAddress;
1413 }
1414
1415 @Override
1416 public String getComputerName() {
1417 return _computerName;
1418 }
1419
1420 @Override
1421 public String getControlPanelCategory(
1422 String portletId, ThemeDisplay themeDisplay)
1423 throws SystemException {
1424
1425 for (String category : PortletCategoryKeys.ALL) {
1426 List<Portlet> portlets = getControlPanelPortlets(
1427 category, themeDisplay);
1428
1429 for (Portlet portlet : portlets) {
1430 if (portlet.getPortletId().equals(portletId)) {
1431 return category;
1432 }
1433 }
1434 }
1435
1436 return StringPool.BLANK;
1437 }
1438
1439 @Override
1440 public String getControlPanelFullURL(
1441 long scopeGroupId, String ppid, Map<String, String[]> params)
1442 throws PortalException, SystemException {
1443
1444 StringBundler sb = new StringBundler(6);
1445
1446 Group group = GroupLocalServiceUtil.getGroup(scopeGroupId);
1447
1448 Company company = CompanyLocalServiceUtil.getCompany(
1449 group.getCompanyId());
1450
1451 sb.append(
1452 getPortalURL(
1453 company.getVirtualHostname(), getPortalPort(false), false));
1454 sb.append(getPathFriendlyURLPrivateGroup());
1455 sb.append(GroupConstants.CONTROL_PANEL_FRIENDLY_URL);
1456 sb.append(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL);
1457
1458 if (params != null) {
1459 params = new HashMap<String, String[]>(params);
1460 }
1461 else {
1462 params = new HashMap<String, String[]>();
1463 }
1464
1465 params.put("p_p_id", new String[] {ppid});
1466 params.put("p_p_lifecycle", new String[] {"0"});
1467 params.put(
1468 "p_p_state", new String[] {WindowState.MAXIMIZED.toString()});
1469 params.put("p_p_mode", new String[] {PortletMode.VIEW.toString()});
1470
1471 sb.append(HttpUtil.parameterMapToString(params, true));
1472
1473 return sb.toString();
1474 }
1475
1476 @Override
1477 public Set<Portlet> getControlPanelPortlets(long companyId, String category)
1478 throws SystemException {
1479
1480 Set<Portlet> portletsSet = new TreeSet<Portlet>(
1481 new PortletControlPanelWeightComparator());
1482
1483 List<Portlet> portletsList = PortletLocalServiceUtil.getPortlets(
1484 companyId);
1485
1486 for (Portlet portlet : portletsList) {
1487 if (category.equals(portlet.getControlPanelEntryCategory())) {
1488 portletsSet.add(portlet);
1489 }
1490 }
1491
1492 return portletsSet;
1493 }
1494
1495 @Override
1496 public List<Portlet> getControlPanelPortlets(
1497 String category, ThemeDisplay themeDisplay)
1498 throws SystemException {
1499
1500 Set<Portlet> portlets = getControlPanelPortlets(
1501 themeDisplay.getCompanyId(), category);
1502
1503 return filterControlPanelPortlets(portlets, category, themeDisplay);
1504 }
1505
1506 @Override
1507 public String getCreateAccountURL(
1508 HttpServletRequest request, ThemeDisplay themeDisplay)
1509 throws Exception {
1510
1511 if (Validator.isNull(PropsValues.COMPANY_SECURITY_STRANGERS_URL)) {
1512 PortletURL createAccountURL = PortletURLFactoryUtil.create(
1513 request, PortletKeys.LOGIN, themeDisplay.getPlid(),
1514 PortletRequest.RENDER_PHASE);
1515
1516 createAccountURL.setWindowState(WindowState.MAXIMIZED);
1517 createAccountURL.setPortletMode(PortletMode.VIEW);
1518
1519 createAccountURL.setParameter("saveLastPath", "0");
1520 createAccountURL.setParameter(
1521 "struts_action", "/login/create_account");
1522
1523 if (!PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS) {
1524 return createAccountURL.toString();
1525 }
1526
1527 String portalURL = PortalUtil.getPortalURL(request);
1528 String portalURLSecure = PortalUtil.getPortalURL(request, true);
1529
1530 return StringUtil.replaceFirst(
1531 createAccountURL.toString(), portalURL, portalURLSecure);
1532 }
1533
1534 try {
1535 Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(
1536 themeDisplay.getScopeGroupId(), false,
1537 PropsValues.COMPANY_SECURITY_STRANGERS_URL);
1538
1539 return getLayoutURL(layout, themeDisplay);
1540 }
1541 catch (NoSuchLayoutException nsle) {
1542 }
1543
1544 return StringPool.BLANK;
1545 }
1546
1547 @Override
1548 public String getCurrentCompleteURL(HttpServletRequest request) {
1549 String currentCompleteURL = (String)request.getAttribute(
1550 WebKeys.CURRENT_COMPLETE_URL);
1551
1552 if (currentCompleteURL == null) {
1553 currentCompleteURL = HttpUtil.getCompleteURL(request);
1554
1555 request.setAttribute(
1556 WebKeys.CURRENT_COMPLETE_URL, currentCompleteURL);
1557 }
1558
1559 return currentCompleteURL;
1560 }
1561
1562 @Override
1563 public String getCurrentURL(HttpServletRequest request) {
1564 String currentURL = (String)request.getAttribute(WebKeys.CURRENT_URL);
1565
1566 if (currentURL != null) {
1567 return currentURL;
1568 }
1569
1570 currentURL = ParamUtil.getString(request, "currentURL");
1571
1572 if (Validator.isNull(currentURL)) {
1573 currentURL = HttpUtil.getCompleteURL(request);
1574
1575 if (Validator.isNotNull(currentURL) &&
1576 !currentURL.contains(_J_SECURITY_CHECK)) {
1577
1578 currentURL = currentURL.substring(
1579 currentURL.indexOf(Http.PROTOCOL_DELIMITER) +
1580 Http.PROTOCOL_DELIMITER.length());
1581
1582 currentURL = currentURL.substring(
1583 currentURL.indexOf(CharPool.SLASH));
1584 }
1585
1586 if (Validator.isNotNull(currentURL) &&
1587 FacebookUtil.isFacebook(currentURL)) {
1588
1589 String[] facebookData = FacebookUtil.getFacebookData(request);
1590
1591 if (facebookData != null) {
1592 currentURL =
1593 FacebookUtil.FACEBOOK_APPS_URL + facebookData[0] +
1594 facebookData[2];
1595 }
1596 }
1597 }
1598
1599 if (Validator.isNull(currentURL)) {
1600 currentURL = getPathMain();
1601 }
1602
1603 request.setAttribute(WebKeys.CURRENT_URL, currentURL);
1604
1605 return currentURL;
1606 }
1607
1608 @Override
1609 public String getCurrentURL(PortletRequest portletRequest) {
1610 return (String)portletRequest.getAttribute(WebKeys.CURRENT_URL);
1611 }
1612
1613 @Override
1614 public String getCustomSQLFunctionIsNotNull() {
1615 return PropsValues.CUSTOM_SQL_FUNCTION_ISNOTNULL;
1616 }
1617
1618 @Override
1619 public String getCustomSQLFunctionIsNull() {
1620 return PropsValues.CUSTOM_SQL_FUNCTION_ISNULL;
1621 }
1622
1623 @Override
1624 public Date getDate(int month, int day, int year) {
1625 try {
1626 return getDate(
1627 month, day, year, (Class<? extends PortalException>)null);
1628 }
1629 catch (PortalException pe) {
1630 throw new RuntimeException();
1631 }
1632 }
1633
1634 @Override
1635 public Date getDate(
1636 int month, int day, int year,
1637 Class<? extends PortalException> clazz)
1638 throws PortalException {
1639
1640 return getDate(month, day, year, null, clazz);
1641 }
1642
1643 @Override
1644 public Date getDate(
1645 int month, int day, int year, int hour, int min,
1646 Class<? extends PortalException> clazz)
1647 throws PortalException {
1648
1649 return getDate(month, day, year, hour, min, null, clazz);
1650 }
1651
1652
1655 @Override
1656 public Date getDate(
1657 int month, int day, int year, int hour, int min, PortalException pe)
1658 throws PortalException {
1659
1660 return getDate(month, day, year, hour, min, null, pe);
1661 }
1662
1663 @Override
1664 public Date getDate(
1665 int month, int day, int year, int hour, int min, TimeZone timeZone,
1666 Class<? extends PortalException> clazz)
1667 throws PortalException {
1668
1669 if (!Validator.isGregorianDate(month, day, year)) {
1670 if (clazz != null) {
1671 try {
1672 throw clazz.newInstance();
1673 }
1674 catch (Exception e) {
1675 throw new PortalException(e);
1676 }
1677 }
1678 else {
1679 return null;
1680 }
1681 }
1682 else {
1683 Calendar cal = null;
1684
1685 if (timeZone == null) {
1686 cal = CalendarFactoryUtil.getCalendar();
1687 }
1688 else {
1689 cal = CalendarFactoryUtil.getCalendar(timeZone);
1690 }
1691
1692 if ((hour == -1) || (min == -1)) {
1693 cal.set(year, month, day, 0, 0, 0);
1694 }
1695 else {
1696 cal.set(year, month, day, hour, min, 0);
1697 }
1698
1699 cal.set(Calendar.MILLISECOND, 0);
1700
1701 Date date = cal.getTime();
1702
1703
1708
1709 return date;
1710 }
1711 }
1712
1713
1716 @Override
1717 public Date getDate(
1718 int month, int day, int year, int hour, int min, TimeZone timeZone,
1719 PortalException pe)
1720 throws PortalException {
1721
1722 if (!Validator.isGregorianDate(month, day, year)) {
1723 if (pe != null) {
1724 throw pe;
1725 }
1726 else {
1727 return null;
1728 }
1729 }
1730 else {
1731 Calendar cal = null;
1732
1733 if (timeZone == null) {
1734 cal = CalendarFactoryUtil.getCalendar();
1735 }
1736 else {
1737 cal = CalendarFactoryUtil.getCalendar(timeZone);
1738 }
1739
1740 if ((hour == -1) || (min == -1)) {
1741 cal.set(year, month, day, 0, 0, 0);
1742 }
1743 else {
1744 cal.set(year, month, day, hour, min, 0);
1745 }
1746
1747 cal.set(Calendar.MILLISECOND, 0);
1748
1749 Date date = cal.getTime();
1750
1751
1756
1757 return date;
1758 }
1759 }
1760
1761
1764 @Override
1765 public Date getDate(int month, int day, int year, PortalException pe)
1766 throws PortalException {
1767
1768 return getDate(month, day, year, null, pe);
1769 }
1770
1771 @Override
1772 public Date getDate(
1773 int month, int day, int year, TimeZone timeZone,
1774 Class<? extends PortalException> clazz)
1775 throws PortalException {
1776
1777 return getDate(month, day, year, -1, -1, timeZone, clazz);
1778 }
1779
1780
1783 @Override
1784 public Date getDate(
1785 int month, int day, int year, TimeZone timeZone, PortalException pe)
1786 throws PortalException {
1787
1788 return getDate(month, day, year, -1, -1, timeZone, pe);
1789 }
1790
1791 @Override
1792 public long getDefaultCompanyId() {
1793 return PortalInstances.getDefaultCompanyId();
1794 }
1795
1796 @Override
1797 public long getDigestAuthUserId(HttpServletRequest request)
1798 throws PortalException, SystemException {
1799
1800 long userId = 0;
1801
1802 String authorizationHeader = request.getHeader(
1803 HttpHeaders.AUTHORIZATION);
1804
1805 if (Validator.isNull(authorizationHeader) ||
1806 !authorizationHeader.startsWith("Digest ")) {
1807
1808 return userId;
1809 }
1810
1811 authorizationHeader = authorizationHeader.substring("Digest ".length());
1812 authorizationHeader = StringUtil.replace(
1813 authorizationHeader, CharPool.COMMA, CharPool.NEW_LINE);
1814
1815 UnicodeProperties authorizationProperties = new UnicodeProperties();
1816
1817 authorizationProperties.fastLoad(authorizationHeader);
1818
1819 String username = StringUtil.unquote(
1820 authorizationProperties.getProperty("username"));
1821 String realm = StringUtil.unquote(
1822 authorizationProperties.getProperty("realm"));
1823 String nonce = StringUtil.unquote(
1824 authorizationProperties.getProperty("nonce"));
1825 String uri = StringUtil.unquote(
1826 authorizationProperties.getProperty("uri"));
1827 String response = StringUtil.unquote(
1828 authorizationProperties.getProperty("response"));
1829
1830 if (Validator.isNull(username) || Validator.isNull(realm) ||
1831 Validator.isNull(nonce) || Validator.isNull(uri) ||
1832 Validator.isNull(response)) {
1833
1834 return userId;
1835 }
1836
1837 if (!realm.equals(PORTAL_REALM) ||
1838 !uri.equals(request.getRequestURI())) {
1839
1840 return userId;
1841 }
1842
1843 if (!NonceUtil.verify(nonce)) {
1844 return userId;
1845 }
1846
1847 long companyId = PortalInstances.getCompanyId(request);
1848
1849 userId = UserLocalServiceUtil.authenticateForDigest(
1850 companyId, username, realm, nonce, request.getMethod(), uri,
1851 response);
1852
1853 return userId;
1854 }
1855
1856 @Override
1857 public String getEmailFromAddress(
1858 PortletPreferences preferences, long companyId, String defaultValue)
1859 throws SystemException {
1860
1861 if (Validator.isNull(defaultValue)) {
1862 defaultValue = PrefsPropsUtil.getString(
1863 companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
1864 }
1865
1866 return preferences.getValue("emailFromAddress", defaultValue);
1867 }
1868
1869 @Override
1870 public String getEmailFromName(
1871 PortletPreferences preferences, long companyId, String defaultValue)
1872 throws SystemException {
1873
1874 if (Validator.isNull(defaultValue)) {
1875 defaultValue = PrefsPropsUtil.getString(
1876 companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME);
1877 }
1878
1879 return preferences.getValue("emailFromName", defaultValue);
1880 }
1881
1882 @Override
1883 public Map<String, Serializable> getExpandoBridgeAttributes(
1884 ExpandoBridge expandoBridge, PortletRequest portletRequest)
1885 throws PortalException, SystemException {
1886
1887 Map<String, Serializable> attributes =
1888 new HashMap<String, Serializable>();
1889
1890 List<String> names = new ArrayList<String>();
1891
1892 Enumeration<String> enu = portletRequest.getParameterNames();
1893
1894 while (enu.hasMoreElements()) {
1895 String param = enu.nextElement();
1896
1897 if (param.contains("ExpandoAttributeName--")) {
1898 String name = ParamUtil.getString(portletRequest, param);
1899
1900 names.add(name);
1901 }
1902 }
1903
1904 for (String name : names) {
1905 int type = expandoBridge.getAttributeType(name);
1906
1907 UnicodeProperties properties = expandoBridge.getAttributeProperties(
1908 name);
1909
1910 String displayType = GetterUtil.getString(
1911 properties.getProperty(
1912 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE),
1913 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX);
1914
1915 Serializable value = getExpandoValue(
1916 portletRequest, "ExpandoAttribute--" + name + "--", type,
1917 displayType);
1918
1919 attributes.put(name, value);
1920 }
1921
1922 return attributes;
1923 }
1924
1925 @Override
1926 public Map<String, Serializable> getExpandoBridgeAttributes(
1927 ExpandoBridge expandoBridge,
1928 UploadPortletRequest uploadPortletRequest)
1929 throws PortalException, SystemException {
1930
1931 Map<String, Serializable> attributes =
1932 new HashMap<String, Serializable>();
1933
1934 List<String> names = new ArrayList<String>();
1935
1936 Enumeration<String> enu = uploadPortletRequest.getParameterNames();
1937
1938 while (enu.hasMoreElements()) {
1939 String param = enu.nextElement();
1940
1941 if (param.contains("ExpandoAttributeName--")) {
1942 String name = ParamUtil.getString(uploadPortletRequest, param);
1943
1944 names.add(name);
1945 }
1946 }
1947
1948 for (String name : names) {
1949 int type = expandoBridge.getAttributeType(name);
1950
1951 UnicodeProperties properties = expandoBridge.getAttributeProperties(
1952 name);
1953
1954 String displayType = GetterUtil.getString(
1955 properties.getProperty(
1956 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE),
1957 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX);
1958
1959 Serializable value = getExpandoValue(
1960 uploadPortletRequest, "ExpandoAttribute--" + name + "--", type,
1961 displayType);
1962
1963 attributes.put(name, value);
1964 }
1965
1966 return attributes;
1967 }
1968
1969 @Override
1970 public Serializable getExpandoValue(
1971 PortletRequest portletRequest, String name, int type,
1972 String displayType)
1973 throws PortalException, SystemException {
1974
1975 Serializable value = null;
1976
1977 if (type == ExpandoColumnConstants.BOOLEAN) {
1978 value = ParamUtil.getBoolean(portletRequest, name);
1979 }
1980 else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
1981 }
1982 else if (type == ExpandoColumnConstants.DATE) {
1983 int valueDateMonth = ParamUtil.getInteger(
1984 portletRequest, name + "Month");
1985 int valueDateDay = ParamUtil.getInteger(
1986 portletRequest, name + "Day");
1987 int valueDateYear = ParamUtil.getInteger(
1988 portletRequest, name + "Year");
1989 int valueDateHour = ParamUtil.getInteger(
1990 portletRequest, name + "Hour");
1991 int valueDateMinute = ParamUtil.getInteger(
1992 portletRequest, name + "Minute");
1993 int valueDateAmPm = ParamUtil.getInteger(
1994 portletRequest, name + "AmPm");
1995
1996 if (valueDateAmPm == Calendar.PM) {
1997 valueDateHour += 12;
1998 }
1999
2000 TimeZone timeZone = null;
2001
2002 User user = getUser(portletRequest);
2003
2004 if (user != null) {
2005 timeZone = user.getTimeZone();
2006 }
2007
2008 value = getDate(
2009 valueDateMonth, valueDateDay, valueDateYear, valueDateHour,
2010 valueDateMinute, timeZone, ValueDataException.class);
2011 }
2012 else if (type == ExpandoColumnConstants.DATE_ARRAY) {
2013 }
2014 else if (type == ExpandoColumnConstants.DOUBLE) {
2015 value = ParamUtil.getDouble(portletRequest, name);
2016 }
2017 else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
2018 String[] values = portletRequest.getParameterValues(name);
2019
2020 if (displayType.equals(
2021 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2022
2023 values = StringUtil.splitLines(values[0]);
2024 }
2025
2026 value = GetterUtil.getDoubleValues(values);
2027 }
2028 else if (type == ExpandoColumnConstants.FLOAT) {
2029 value = ParamUtil.getFloat(portletRequest, name);
2030 }
2031 else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
2032 String[] values = portletRequest.getParameterValues(name);
2033
2034 if (displayType.equals(
2035 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2036
2037 values = StringUtil.splitLines(values[0]);
2038 }
2039
2040 value = GetterUtil.getFloatValues(values);
2041 }
2042 else if (type == ExpandoColumnConstants.INTEGER) {
2043 value = ParamUtil.getInteger(portletRequest, name);
2044 }
2045 else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
2046 String[] values = portletRequest.getParameterValues(name);
2047
2048 if (displayType.equals(
2049 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2050
2051 values = StringUtil.splitLines(values[0]);
2052 }
2053
2054 value = GetterUtil.getIntegerValues(values);
2055 }
2056 else if (type == ExpandoColumnConstants.LONG) {
2057 value = ParamUtil.getLong(portletRequest, name);
2058 }
2059 else if (type == ExpandoColumnConstants.LONG_ARRAY) {
2060 String[] values = portletRequest.getParameterValues(name);
2061
2062 if (displayType.equals(
2063 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2064
2065 values = StringUtil.splitLines(values[0]);
2066 }
2067
2068 value = GetterUtil.getLongValues(values);
2069 }
2070 else if (type == ExpandoColumnConstants.NUMBER) {
2071 value = ParamUtil.getNumber(portletRequest, name);
2072 }
2073 else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
2074 String[] values = portletRequest.getParameterValues(name);
2075
2076 if (displayType.equals(
2077 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2078
2079 values = StringUtil.splitLines(values[0]);
2080 }
2081
2082 value = GetterUtil.getNumberValues(values);
2083 }
2084 else if (type == ExpandoColumnConstants.SHORT) {
2085 value = ParamUtil.getShort(portletRequest, name);
2086 }
2087 else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
2088 String[] values = portletRequest.getParameterValues(name);
2089
2090 if (displayType.equals(
2091 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2092
2093 values = StringUtil.splitLines(values[0]);
2094 }
2095
2096 value = GetterUtil.getShortValues(values);
2097 }
2098 else if (type == ExpandoColumnConstants.STRING_ARRAY) {
2099 value = portletRequest.getParameterValues(name);
2100 }
2101 else {
2102 value = ParamUtil.getString(portletRequest, name);
2103 }
2104
2105 return value;
2106 }
2107
2108 @Override
2109 public Serializable getExpandoValue(
2110 UploadPortletRequest uploadPortletRequest, String name, int type,
2111 String displayType)
2112 throws PortalException, SystemException {
2113
2114 Serializable value = null;
2115
2116 if (type == ExpandoColumnConstants.BOOLEAN) {
2117 value = ParamUtil.getBoolean(uploadPortletRequest, name);
2118 }
2119 else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
2120 }
2121 else if (type == ExpandoColumnConstants.DATE) {
2122 int valueDateMonth = ParamUtil.getInteger(
2123 uploadPortletRequest, name + "Month");
2124 int valueDateDay = ParamUtil.getInteger(
2125 uploadPortletRequest, name + "Day");
2126 int valueDateYear = ParamUtil.getInteger(
2127 uploadPortletRequest, name + "Year");
2128 int valueDateHour = ParamUtil.getInteger(
2129 uploadPortletRequest, name + "Hour");
2130 int valueDateMinute = ParamUtil.getInteger(
2131 uploadPortletRequest, name + "Minute");
2132 int valueDateAmPm = ParamUtil.getInteger(
2133 uploadPortletRequest, name + "AmPm");
2134
2135 if (valueDateAmPm == Calendar.PM) {
2136 valueDateHour += 12;
2137 }
2138
2139 TimeZone timeZone = null;
2140
2141 User user = getUser(uploadPortletRequest);
2142
2143 if (user != null) {
2144 timeZone = user.getTimeZone();
2145 }
2146
2147 value = getDate(
2148 valueDateMonth, valueDateDay, valueDateYear, valueDateHour,
2149 valueDateMinute, timeZone, ValueDataException.class);
2150 }
2151 else if (type == ExpandoColumnConstants.DATE_ARRAY) {
2152 }
2153 else if (type == ExpandoColumnConstants.DOUBLE) {
2154 value = ParamUtil.getDouble(uploadPortletRequest, name);
2155 }
2156 else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
2157 String[] values = uploadPortletRequest.getParameterValues(name);
2158
2159 if (displayType.equals(
2160 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2161
2162 values = StringUtil.splitLines(values[0]);
2163 }
2164
2165 value = GetterUtil.getDoubleValues(values);
2166 }
2167 else if (type == ExpandoColumnConstants.FLOAT) {
2168 value = ParamUtil.getFloat(uploadPortletRequest, name);
2169 }
2170 else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
2171 String[] values = uploadPortletRequest.getParameterValues(name);
2172
2173 if (displayType.equals(
2174 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2175
2176 values = StringUtil.splitLines(values[0]);
2177 }
2178
2179 value = GetterUtil.getFloatValues(values);
2180 }
2181 else if (type == ExpandoColumnConstants.INTEGER) {
2182 value = ParamUtil.getInteger(uploadPortletRequest, name);
2183 }
2184 else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
2185 String[] values = uploadPortletRequest.getParameterValues(name);
2186
2187 if (displayType.equals(
2188 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2189
2190 values = StringUtil.splitLines(values[0]);
2191 }
2192
2193 value = GetterUtil.getIntegerValues(values);
2194 }
2195 else if (type == ExpandoColumnConstants.LONG) {
2196 value = ParamUtil.getLong(uploadPortletRequest, name);
2197 }
2198 else if (type == ExpandoColumnConstants.LONG_ARRAY) {
2199 String[] values = uploadPortletRequest.getParameterValues(name);
2200
2201 if (displayType.equals(
2202 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2203
2204 values = StringUtil.splitLines(values[0]);
2205 }
2206
2207 value = GetterUtil.getLongValues(values);
2208 }
2209 else if (type == ExpandoColumnConstants.SHORT) {
2210 value = ParamUtil.getShort(uploadPortletRequest, name);
2211 }
2212 else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
2213 String[] values = uploadPortletRequest.getParameterValues(name);
2214
2215 if (displayType.equals(
2216 ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE_TEXT_BOX)) {
2217
2218 values = StringUtil.splitLines(values[0]);
2219 }
2220
2221 value = GetterUtil.getShortValues(values);
2222 }
2223 else if (type == ExpandoColumnConstants.STRING_ARRAY) {
2224 value = uploadPortletRequest.getParameterValues(name);
2225 }
2226 else {
2227 value = ParamUtil.getString(uploadPortletRequest, name);
2228 }
2229
2230 return value;
2231 }
2232
2233 @Override
2234 public String getFacebookURL(
2235 Portlet portlet, String facebookCanvasPageURL,
2236 ThemeDisplay themeDisplay)
2237 throws PortalException, SystemException {
2238
2239 String facebookURL = getServletURL(
2240 portlet, FacebookUtil.FACEBOOK_SERVLET_PATH + facebookCanvasPageURL,
2241 themeDisplay);
2242
2243 if (!facebookURL.endsWith(StringPool.SLASH)) {
2244 facebookURL += StringPool.SLASH;
2245 }
2246
2247 return facebookURL;
2248 }
2249
2250 @Override
2251 public String getFirstPageLayoutTypes(PageContext pageContext) {
2252 StringBundler sb = new StringBundler();
2253
2254 for (String type : PropsValues.LAYOUT_TYPES) {
2255 if (isLayoutFirstPageable(type)) {
2256 sb.append(
2257 LanguageUtil.get(pageContext, "layout.types." + type));
2258 sb.append(StringPool.COMMA);
2259 sb.append(StringPool.SPACE);
2260 }
2261 }
2262
2263 if (sb.index() >= 2) {
2264 sb.setIndex(sb.index() - 2);
2265 }
2266
2267 return sb.toString();
2268 }
2269
2270 @Override
2271 public String getGlobalLibDir() {
2272 return PropsValues.LIFERAY_LIB_GLOBAL_DIR;
2273 }
2274
2275 @Override
2276 public String getGoogleGadgetURL(Portlet portlet, ThemeDisplay themeDisplay)
2277 throws PortalException, SystemException {
2278
2279 return getServletURL(
2280 portlet, PropsValues.GOOGLE_GADGET_SERVLET_MAPPING, themeDisplay);
2281 }
2282
2283 @Override
2284 public String getGroupFriendlyURL(
2285 Group group, boolean privateLayoutSet, ThemeDisplay themeDisplay)
2286 throws PortalException, SystemException {
2287
2288 return getGroupFriendlyURL(
2289 group, privateLayoutSet, themeDisplay, false);
2290 }
2291
2292 @Override
2293 public String getGroupFriendlyURL(
2294 Group group, boolean privateLayoutSet, ThemeDisplay themeDisplay,
2295 Locale locale)
2296 throws PortalException, SystemException {
2297
2298 String i18nLanguageId = themeDisplay.getI18nLanguageId();
2299 String i18nPath = themeDisplay.getI18nPath();
2300
2301 try {
2302 setThemeDisplayI18n(themeDisplay, locale);
2303
2304 return getGroupFriendlyURL(group, privateLayoutSet, themeDisplay);
2305 }
2306 finally {
2307 resetThemeDisplayI18n(themeDisplay, i18nLanguageId, i18nPath);
2308 }
2309 }
2310
2311 @Override
2312 public String[] getGroupPermissions(HttpServletRequest request) {
2313 return request.getParameterValues("groupPermissions");
2314 }
2315
2316 @Override
2317 public String[] getGroupPermissions(
2318 HttpServletRequest request, String className) {
2319
2320 return request.getParameterValues("groupPermissions_" + className);
2321 }
2322
2323 @Override
2324 public String[] getGroupPermissions(PortletRequest portletRequest) {
2325 return portletRequest.getParameterValues("groupPermissions");
2326 }
2327
2328 @Override
2329 public String[] getGroupPermissions(
2330 PortletRequest portletRequest, String className) {
2331
2332 return portletRequest.getParameterValues(
2333 "groupPermissions_" + className);
2334 }
2335
2336 @Override
2337 public String[] getGuestPermissions(HttpServletRequest request) {
2338 return request.getParameterValues("guestPermissions");
2339 }
2340
2341 @Override
2342 public String[] getGuestPermissions(
2343 HttpServletRequest request, String className) {
2344
2345 return request.getParameterValues("guestPermissions_" + className);
2346 }
2347
2348 @Override
2349 public String[] getGuestPermissions(PortletRequest portletRequest) {
2350 return portletRequest.getParameterValues("guestPermissions");
2351 }
2352
2353 @Override
2354 public String[] getGuestPermissions(
2355 PortletRequest portletRequest, String className) {
2356
2357 return portletRequest.getParameterValues(
2358 "guestPermissions_" + className);
2359 }
2360
2361 @Override
2362 public String getHomeURL(HttpServletRequest request)
2363 throws PortalException, SystemException {
2364
2365 String portalURL = getPortalURL(request);
2366
2367 return portalURL + _pathContext + getRelativeHomeURL(request);
2368 }
2369
2370 @Override
2371 public String getHost(HttpServletRequest request) {
2372 request = getOriginalServletRequest(request);
2373
2374 String host = request.getHeader("Host");
2375
2376 if (host != null) {
2377 host = host.trim().toLowerCase();
2378
2379 int pos = host.indexOf(':');
2380
2381 if (pos >= 0) {
2382 host = host.substring(0, pos);
2383 }
2384 }
2385 else {
2386 host = null;
2387 }
2388
2389 return host;
2390 }
2391
2392 @Override
2393 public String getHost(PortletRequest portletRequest) {
2394 return getHost(getHttpServletRequest(portletRequest));
2395 }
2396
2397 @Override
2398 public HttpServletRequest getHttpServletRequest(
2399 PortletRequest portletRequest) {
2400
2401 PortletRequestImpl portletRequestImpl =
2402 PortletRequestImpl.getPortletRequestImpl(portletRequest);
2403
2404 return portletRequestImpl.getHttpServletRequest();
2405 }
2406
2407 @Override
2408 public HttpServletResponse getHttpServletResponse(
2409 PortletResponse portletResponse) {
2410
2411 PortletResponseImpl portletResponseImpl =
2412 PortletResponseImpl.getPortletResponseImpl(portletResponse);
2413
2414 return portletResponseImpl.getHttpServletResponse();
2415 }
2416
2417 @Override
2418 public String getJournalArticleActualURL(
2419 long groupId, boolean privateLayout, String mainPath,
2420 String friendlyURL, Map<String, String[]> params,
2421 Map<String, Object> requestContext)
2422 throws PortalException, SystemException {
2423
2424 String articleUrlTitle = friendlyURL.substring(
2425 JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());
2426
2427 JournalArticle journalArticle =
2428 JournalArticleLocalServiceUtil.getArticleByUrlTitle(
2429 groupId, articleUrlTitle);
2430
2431 Layout layout = LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
2432 journalArticle.getLayoutUuid(), groupId, privateLayout);
2433
2434 String layoutActualURL = getLayoutActualURL(layout, mainPath);
2435
2436 InheritableMap<String, String[]> actualParams =
2437 new InheritableMap<String, String[]>();
2438
2439 if (params != null) {
2440 actualParams.setParentMap(params);
2441 }
2442
2443 UnicodeProperties typeSettingsProperties =
2444 layout.getTypeSettingsProperties();
2445
2446 String defaultAssetPublisherPortletId = typeSettingsProperties.get(
2447 LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);
2448
2449 String currentDefaultAssetPublisherPortletId =
2450 defaultAssetPublisherPortletId;
2451
2452 if (Validator.isNull(defaultAssetPublisherPortletId)) {
2453 defaultAssetPublisherPortletId =
2454 PortletKeys.ASSET_PUBLISHER +
2455 LayoutTypePortletImpl.getFullInstanceSeparator();
2456 }
2457
2458 HttpServletRequest request = (HttpServletRequest)requestContext.get(
2459 "request");
2460
2461 if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
2462 String actualPortletAuthenticationToken = AuthTokenUtil.getToken(
2463 request, layout.getPlid(), defaultAssetPublisherPortletId);
2464
2465 actualParams.put(
2466 "p_p_auth", new String[] {actualPortletAuthenticationToken});
2467 }
2468
2469 actualParams.put(
2470 "p_p_id", new String[] {defaultAssetPublisherPortletId});
2471 actualParams.put("p_p_lifecycle", new String[] {"0"});
2472
2473 if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
2474 actualParams.put(
2475 "p_p_state", new String[] {WindowState.MAXIMIZED.toString()});
2476 }
2477
2478 actualParams.put("p_p_mode", new String[] {"view"});
2479 actualParams.put(
2480 "p_j_a_id", new String[] {String.valueOf(journalArticle.getId())});
2481
2482 String namespace = getPortletNamespace(defaultAssetPublisherPortletId);
2483
2484 actualParams.put(
2485 namespace + "struts_action",
2486 new String[] {"/asset_publisher/view_content"});
2487 actualParams.put(
2488 namespace + "type",
2489 new String[] {JournalArticleAssetRendererFactory.TYPE});
2490 actualParams.put(
2491 namespace + "urlTitle",
2492 new String[] {journalArticle.getUrlTitle()});
2493
2494 String queryString = HttpUtil.parameterMapToString(actualParams, false);
2495
2496 if (layoutActualURL.contains(StringPool.QUESTION)) {
2497 layoutActualURL =
2498 layoutActualURL + StringPool.AMPERSAND + queryString;
2499 }
2500 else {
2501 layoutActualURL =
2502 layoutActualURL + StringPool.QUESTION + queryString;
2503 }
2504
2505 Locale locale = getLocale(request);
2506
2507 addPageSubtitle(journalArticle.getTitle(locale), request);
2508 addPageDescription(journalArticle.getDescription(locale), request);
2509
2510 List<AssetTag> assetTags = AssetTagLocalServiceUtil.getTags(
2511 JournalArticle.class.getName(), journalArticle.getPrimaryKey());
2512
2513 if (!assetTags.isEmpty()) {
2514 addPageKeywords(
2515 ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
2516 }
2517
2518 return layoutActualURL;
2519 }
2520
2521 @Override
2522 public String getJsSafePortletId(String portletId) {
2523 return JS.getSafeName(portletId);
2524 }
2525
2526 @Override
2527 public String getLayoutActualURL(Layout layout) {
2528 return getLayoutActualURL(layout, getPathMain());
2529 }
2530
2531 @Override
2532 public String getLayoutActualURL(Layout layout, String mainPath) {
2533 Map<String, String> variables = new HashMap<String, String>();
2534
2535 variables.put("liferay:groupId", String.valueOf(layout.getGroupId()));
2536 variables.put("liferay:mainPath", mainPath);
2537 variables.put("liferay:plid", String.valueOf(layout.getPlid()));
2538
2539 if (layout instanceof VirtualLayout) {
2540 variables.put(
2541 "liferay:pvlsgid", String.valueOf(layout.getGroupId()));
2542 }
2543 else {
2544 variables.put("liferay:pvlsgid", "0");
2545 }
2546
2547 LayoutType layoutType = layout.getLayoutType();
2548
2549 UnicodeProperties typeSettingsProperties =
2550 layoutType.getTypeSettingsProperties();
2551
2552 variables.putAll(typeSettingsProperties);
2553
2554 LayoutSettings layoutSettings = LayoutSettings.getInstance(layout);
2555
2556 return layoutSettings.getURL(variables);
2557 }
2558
2559 @Override
2560 public String getLayoutActualURL(
2561 long groupId, boolean privateLayout, String mainPath,
2562 String friendlyURL)
2563 throws PortalException, SystemException {
2564
2565 return getLayoutActualURL(
2566 groupId, privateLayout, mainPath, friendlyURL, null, null);
2567 }
2568
2569 @Override
2570 public String getLayoutActualURL(
2571 long groupId, boolean privateLayout, String mainPath,
2572 String friendlyURL, Map<String, String[]> params,
2573 Map<String, Object> requestContext)
2574 throws PortalException, SystemException {
2575
2576 Layout layout = null;
2577 String queryString = StringPool.BLANK;
2578
2579 if (Validator.isNull(friendlyURL)) {
2580 layout = LayoutLocalServiceUtil.fetchFirstLayout(
2581 groupId, privateLayout,
2582 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
2583
2584 if (layout == null) {
2585 throw new NoSuchLayoutException(
2586 "{groupId=" + groupId + ",privateLayout=" + privateLayout +
2587 "} does not have any layouts");
2588 }
2589 }
2590 else {
2591 Object[] friendlyURLMapper = getPortletFriendlyURLMapper(
2592 groupId, privateLayout, friendlyURL, params, requestContext);
2593
2594 layout = (Layout)friendlyURLMapper[0];
2595 queryString = (String)friendlyURLMapper[1];
2596 }
2597
2598 String layoutActualURL = getLayoutActualURL(layout, mainPath);
2599
2600 if (Validator.isNotNull(queryString)) {
2601 layoutActualURL = layoutActualURL.concat(queryString);
2602 }
2603 else if (params.isEmpty()) {
2604 LayoutType layoutType = layout.getLayoutType();
2605
2606 UnicodeProperties typeSettingsProperties =
2607 layoutType.getTypeSettingsProperties();
2608
2609 queryString = typeSettingsProperties.getProperty("query-string");
2610
2611 if (Validator.isNotNull(queryString) &&
2612 layoutActualURL.contains(StringPool.QUESTION)) {
2613
2614 layoutActualURL = layoutActualURL.concat(
2615 StringPool.AMPERSAND).concat(queryString);
2616 }
2617 }
2618
2619 return layoutActualURL;
2620 }
2621
2622 @Override
2623 public String getLayoutEditPage(Layout layout) {
2624 LayoutSettings layoutSettings = LayoutSettings.getInstance(
2625 layout.getType());
2626
2627 return layoutSettings.getEditPage();
2628 }
2629
2630 @Override
2631 public String getLayoutEditPage(String type) {
2632 LayoutSettings layoutSettings = LayoutSettings.getInstance(type);
2633
2634 return layoutSettings.getEditPage();
2635 }
2636
2637 @Override
2638 public String getLayoutFriendlyURL(Layout layout, ThemeDisplay themeDisplay)
2639 throws PortalException, SystemException {
2640
2641 if (!isLayoutFriendliable(layout)) {
2642 return null;
2643 }
2644
2645 String groupFriendlyURL = getGroupFriendlyURL(
2646 layout.getGroup(), layout.isPrivateLayout(), themeDisplay);
2647
2648 return groupFriendlyURL.concat(layout.getFriendlyURL());
2649 }
2650
2651 @Override
2652 public String getLayoutFriendlyURL(
2653 Layout layout, ThemeDisplay themeDisplay, Locale locale)
2654 throws PortalException, SystemException {
2655
2656 String i18nLanguageId = themeDisplay.getI18nLanguageId();
2657 String i18nPath = themeDisplay.getI18nPath();
2658
2659 try {
2660 setThemeDisplayI18n(themeDisplay, locale);
2661
2662 return getLayoutFriendlyURL(layout, themeDisplay);
2663 }
2664 finally {
2665 resetThemeDisplayI18n(themeDisplay, i18nLanguageId, i18nPath);
2666 }
2667 }
2668
2669 @Override
2670 public String getLayoutFullURL(Layout layout, ThemeDisplay themeDisplay)
2671 throws PortalException, SystemException {
2672
2673 return getLayoutFullURL(layout, themeDisplay, true);
2674 }
2675
2676 @Override
2677 public String getLayoutFullURL(
2678 Layout layout, ThemeDisplay themeDisplay, boolean doAsUser)
2679 throws PortalException, SystemException {
2680
2681 String layoutURL = getLayoutURL(layout, themeDisplay, doAsUser);
2682 String portalURL = getPortalURL(layout, themeDisplay);
2683
2684 if (StringUtil.startsWith(layoutURL, portalURL)) {
2685 return layoutURL;
2686 }
2687 else {
2688 return portalURL + layoutURL;
2689 }
2690 }
2691
2692 @Override
2693 public String getLayoutFullURL(long groupId, String portletId)
2694 throws PortalException, SystemException {
2695
2696 return getLayoutFullURL(groupId, portletId, false);
2697 }
2698
2699 @Override
2700 public String getLayoutFullURL(
2701 long groupId, String portletId, boolean secure)
2702 throws PortalException, SystemException {
2703
2704 long plid = getPlidFromPortletId(groupId, portletId);
2705
2706 if (plid == LayoutConstants.DEFAULT_PLID) {
2707 return null;
2708 }
2709
2710 StringBundler sb = new StringBundler(4);
2711
2712 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
2713
2714 Group group = GroupLocalServiceUtil.getGroup(groupId);
2715
2716 if (group.isLayout()) {
2717 long parentGroupId = group.getParentGroupId();
2718
2719 if (parentGroupId > 0) {
2720 group = GroupLocalServiceUtil.getGroup(parentGroupId);
2721 }
2722 }
2723
2724 String virtualHostname = null;
2725
2726 LayoutSet layoutSet = layout.getLayoutSet();
2727
2728 if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
2729 virtualHostname = layoutSet.getVirtualHostname();
2730 }
2731 else {
2732 Company company = CompanyLocalServiceUtil.getCompany(
2733 layout.getCompanyId());
2734
2735 virtualHostname = company.getVirtualHostname();
2736 }
2737
2738 String portalURL = getPortalURL(
2739 virtualHostname, getPortalPort(secure), secure);
2740
2741 sb.append(portalURL);
2742
2743 if (layout.isPrivateLayout()) {
2744 if (group.isUser()) {
2745 sb.append(getPathFriendlyURLPrivateUser());
2746 }
2747 else {
2748 sb.append(getPathFriendlyURLPrivateGroup());
2749 }
2750 }
2751 else {
2752 sb.append(getPathFriendlyURLPublic());
2753 }
2754
2755 sb.append(group.getFriendlyURL());
2756 sb.append(layout.getFriendlyURL());
2757
2758 return sb.toString();
2759 }
2760
2761 @Override
2762 public String getLayoutFullURL(ThemeDisplay themeDisplay)
2763 throws PortalException, SystemException {
2764
2765 return getLayoutFullURL(themeDisplay.getLayout(), themeDisplay);
2766 }
2767
2768 @Override
2769 public String getLayoutSetFriendlyURL(
2770 LayoutSet layoutSet, ThemeDisplay themeDisplay)
2771 throws PortalException, SystemException {
2772
2773 String virtualHostname = layoutSet.getVirtualHostname();
2774
2775 if (Validator.isNull(virtualHostname) &&
2776 Validator.isNotNull(PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME) &&
2777 !layoutSet.isPrivateLayout()) {
2778
2779 try {
2780 Group group = GroupLocalServiceUtil.getGroup(
2781 themeDisplay.getCompanyId(),
2782 PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME);
2783
2784 if (layoutSet.getGroupId() == group.getGroupId()) {
2785 Company company = themeDisplay.getCompany();
2786
2787 virtualHostname = company.getVirtualHostname();
2788 }
2789 }
2790 catch (Exception e) {
2791 _log.error(e, e);
2792 }
2793 }
2794
2795 if (Validator.isNotNull(virtualHostname)) {
2796 String portalURL = getPortalURL(
2797 virtualHostname, themeDisplay.getServerPort(),
2798 themeDisplay.isSecure());
2799
2800
2801
2802
2803 long curLayoutSetId =
2804 themeDisplay.getLayout().getLayoutSet().getLayoutSetId();
2805
2806 if ((layoutSet.getLayoutSetId() != curLayoutSetId) ||
2807 portalURL.startsWith(themeDisplay.getURLPortal())) {
2808
2809 String layoutSetFriendlyURL = StringPool.BLANK;
2810
2811 if (themeDisplay.isI18n()) {
2812 layoutSetFriendlyURL = themeDisplay.getI18nPath();
2813 }
2814
2815 return portalURL + _pathContext + layoutSetFriendlyURL;
2816 }
2817 }
2818
2819 Group group = GroupLocalServiceUtil.getGroup(layoutSet.getGroupId());
2820
2821 String friendlyURL = null;
2822
2823 if (layoutSet.isPrivateLayout()) {
2824 if (group.isUser()) {
2825 friendlyURL = _PRIVATE_USER_SERVLET_MAPPING;
2826 }
2827 else {
2828 friendlyURL = _PRIVATE_GROUP_SERVLET_MAPPING;
2829 }
2830 }
2831 else {
2832 friendlyURL = _PUBLIC_GROUP_SERVLET_MAPPING;
2833 }
2834
2835 if (themeDisplay.isI18n()) {
2836 friendlyURL = themeDisplay.getI18nPath() + friendlyURL;
2837 }
2838
2839 return _pathContext + friendlyURL + group.getFriendlyURL();
2840 }
2841
2842 @Override
2843 public String getLayoutTarget(Layout layout) {
2844 UnicodeProperties typeSettingsProps =
2845 layout.getTypeSettingsProperties();
2846
2847 String target = typeSettingsProps.getProperty("target");
2848
2849 if (Validator.isNull(target)) {
2850 target = StringPool.BLANK;
2851 }
2852 else {
2853 target = "target=\"" + HtmlUtil.escapeAttribute(target) + "\"";
2854 }
2855
2856 return target;
2857 }
2858
2859 @Override
2860 public String getLayoutURL(Layout layout, ThemeDisplay themeDisplay)
2861 throws PortalException, SystemException {
2862
2863 return getLayoutURL(layout, themeDisplay, true);
2864 }
2865
2866 @Override
2867 public String getLayoutURL(
2868 Layout layout, ThemeDisplay themeDisplay, boolean doAsUser)
2869 throws PortalException, SystemException {
2870
2871 if (layout == null) {
2872 return themeDisplay.getPathMain() + PATH_PORTAL_LAYOUT;
2873 }
2874
2875 if (!layout.isTypeURL()) {
2876 String layoutFriendlyURL = getLayoutFriendlyURL(
2877 layout, themeDisplay);
2878
2879 if (Validator.isNotNull(layoutFriendlyURL)) {
2880 layoutFriendlyURL = addPreservedParameters(
2881 themeDisplay, layout, layoutFriendlyURL, doAsUser);
2882
2883 return layoutFriendlyURL;
2884 }
2885 }
2886
2887 String layoutURL = getLayoutActualURL(layout);
2888
2889 layoutURL = addPreservedParameters(
2890 themeDisplay, layout, layoutURL, doAsUser);
2891
2892 return layoutURL;
2893 }
2894
2895 @Override
2896 public String getLayoutURL(ThemeDisplay themeDisplay)
2897 throws PortalException, SystemException {
2898
2899 return getLayoutURL(themeDisplay.getLayout(), themeDisplay);
2900 }
2901
2902 @Override
2903 public String getLayoutViewPage(Layout layout) {
2904 LayoutSettings layoutSettings = LayoutSettings.getInstance(
2905 layout.getType());
2906
2907 return layoutSettings.getViewPage();
2908 }
2909
2910 @Override
2911 public String getLayoutViewPage(String type) {
2912 LayoutSettings layoutSettings = LayoutSettings.getInstance(type);
2913
2914 return layoutSettings.getViewPage();
2915 }
2916
2917 @Override
2918 public LiferayPortletRequest getLiferayPortletRequest(
2919 PortletRequest portletRequest) {
2920
2921 PortletRequestImpl portletRequestImpl =
2922 PortletRequestImpl.getPortletRequestImpl(portletRequest);
2923
2924 return DoPrivilegedUtil.wrapWhenActive(portletRequestImpl);
2925 }
2926
2927 @Override
2928 public LiferayPortletResponse getLiferayPortletResponse(
2929 PortletResponse portletResponse) {
2930
2931 PortletResponseImpl portletResponseImpl =
2932 PortletResponseImpl.getPortletResponseImpl(portletResponse);
2933
2934 return DoPrivilegedUtil.wrapWhenActive(portletResponseImpl);
2935 }
2936
2937 @Override
2938 public Locale getLocale(HttpServletRequest request) {
2939 return getLocale(request, null, false);
2940 }
2941
2942 @Override
2943 public Locale getLocale(
2944 HttpServletRequest request, HttpServletResponse response,
2945 boolean initialize) {
2946
2947 User user = null;
2948
2949 if (initialize) {
2950 try {
2951 user = initUser(request);
2952 }
2953 catch (NoSuchUserException nsue) {
2954 return null;
2955 }
2956 catch (Exception e) {
2957 }
2958 }
2959
2960 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
2961 WebKeys.THEME_DISPLAY);
2962
2963 if (themeDisplay != null) {
2964 return themeDisplay.getLocale();
2965 }
2966
2967 String i18nLanguageId = (String)request.getAttribute(
2968 WebKeys.I18N_LANGUAGE_ID);
2969
2970 if (Validator.isNotNull(i18nLanguageId)) {
2971 return LocaleUtil.fromLanguageId(i18nLanguageId);
2972 }
2973
2974 String doAsUserLanguageId = ParamUtil.getString(
2975 request, "doAsUserLanguageId");
2976
2977 if (Validator.isNotNull(doAsUserLanguageId)) {
2978 return LocaleUtil.fromLanguageId(doAsUserLanguageId);
2979 }
2980
2981 HttpSession session = request.getSession();
2982
2983 if (session.getAttribute(Globals.LOCALE_KEY) != null) {
2984 return (Locale)session.getAttribute(Globals.LOCALE_KEY);
2985 }
2986
2987
2988
2989 if (user == null) {
2990 try {
2991 user = getUser(request);
2992 }
2993 catch (Exception e) {
2994 }
2995 }
2996
2997 if ((user != null) && !user.isDefaultUser()) {
2998 Locale userLocale = getAvailableLocale(user.getLocale());
2999
3000 if (userLocale != null) {
3001 if (initialize) {
3002 setLocale(request, response, userLocale);
3003 }
3004
3005 return userLocale;
3006 }
3007 }
3008
3009
3010
3011 String languageId = CookieKeys.getCookie(
3012 request, CookieKeys.GUEST_LANGUAGE_ID, false);
3013
3014 if (Validator.isNotNull(languageId)) {
3015 Locale cookieLocale = getAvailableLocale(
3016 LocaleUtil.fromLanguageId(languageId));
3017
3018 if (cookieLocale != null) {
3019 if (initialize) {
3020 setLocale(request, response, cookieLocale);
3021 }
3022
3023 return cookieLocale;
3024 }
3025 }
3026
3027
3028
3029 if (PropsValues.LOCALE_DEFAULT_REQUEST) {
3030 Enumeration<Locale> locales = request.getLocales();
3031
3032 while (locales.hasMoreElements()) {
3033 Locale requestLocale = getAvailableLocale(
3034 locales.nextElement());
3035
3036 if (requestLocale != null) {
3037 if (initialize) {
3038 setLocale(request, response, requestLocale);
3039 }
3040
3041 return requestLocale;
3042 }
3043 }
3044 }
3045
3046
3047
3048 Company company = null;
3049
3050 try {
3051 company = getCompany(request);
3052 }
3053 catch (Exception e) {
3054 }
3055
3056 if (company == null) {
3057 return null;
3058 }
3059
3060 User defaultUser = null;
3061
3062 try {
3063 defaultUser = company.getDefaultUser();
3064 }
3065 catch (Exception e) {
3066 }
3067
3068 if (defaultUser == null) {
3069 return null;
3070 }
3071
3072 Locale defaultUserLocale = getAvailableLocale(defaultUser.getLocale());
3073
3074 if (defaultUserLocale == null) {
3075 return null;
3076 }
3077
3078 if (initialize) {
3079 setLocale(request, response, defaultUserLocale);
3080 }
3081
3082 return defaultUserLocale;
3083 }
3084
3085 @Override
3086 public Locale getLocale(RenderRequest renderRequest) {
3087 return getLocale(getHttpServletRequest(renderRequest));
3088 }
3089
3090 @Override
3091 public String getMailId(String mx, String popPortletPrefix, Object... ids) {
3092 StringBundler sb = new StringBundler(ids.length * 2 + 7);
3093
3094 sb.append(StringPool.LESS_THAN);
3095 sb.append(popPortletPrefix);
3096
3097 if (!popPortletPrefix.endsWith(StringPool.PERIOD)) {
3098 sb.append(StringPool.PERIOD);
3099 }
3100
3101 for (int i = 0; i < ids.length; i++) {
3102 Object id = ids[i];
3103
3104 if (i != 0) {
3105 sb.append(StringPool.PERIOD);
3106 }
3107
3108 sb.append(id);
3109 }
3110
3111 sb.append(StringPool.AT);
3112
3113 if (Validator.isNotNull(PropsValues.POP_SERVER_SUBDOMAIN)) {
3114 sb.append(PropsValues.POP_SERVER_SUBDOMAIN);
3115 sb.append(StringPool.PERIOD);
3116 }
3117
3118 sb.append(mx);
3119 sb.append(StringPool.GREATER_THAN);
3120
3121 return sb.toString();
3122 }
3123
3124 @Override
3125 public String getNetvibesURL(Portlet portlet, ThemeDisplay themeDisplay)
3126 throws PortalException, SystemException {
3127
3128 return getServletURL(
3129 portlet, PropsValues.NETVIBES_SERVLET_MAPPING, themeDisplay);
3130 }
3131
3132 @Override
3133 public String getNewPortletTitle(
3134 String portletTitle, String oldScopeName, String newScopeName) {
3135
3136 if (portletTitle.endsWith(" (" + oldScopeName + ")")) {
3137 int pos = portletTitle.lastIndexOf(" (" + oldScopeName + ")");
3138
3139 portletTitle = portletTitle.substring(0, pos);
3140 }
3141
3142 if (Validator.isNull(newScopeName)) {
3143 return portletTitle;
3144 }
3145
3146 StringBundler sb = new StringBundler(5);
3147
3148 sb.append(portletTitle);
3149 sb.append(StringPool.SPACE);
3150 sb.append(StringPool.OPEN_PARENTHESIS);
3151 sb.append(newScopeName);
3152 sb.append(StringPool.CLOSE_PARENTHESIS);
3153
3154 return sb.toString();
3155 }
3156
3157 @Override
3158 public HttpServletRequest getOriginalServletRequest(
3159 HttpServletRequest request) {
3160
3161 List<HttpServletRequestWrapper> persistentHttpServletRequestWrappers =
3162 new ArrayList<HttpServletRequestWrapper>();
3163
3164 HttpServletRequest originalRequest = request;
3165
3166 while (originalRequest.getClass().getName().startsWith(
3167 "com.liferay.")) {
3168
3169 if (originalRequest instanceof
3170 PersistentHttpServletRequestWrapper) {
3171
3172 persistentHttpServletRequestWrappers.add(
3173 (HttpServletRequestWrapper)originalRequest);
3174 }
3175
3176
3177
3178
3179 HttpServletRequestWrapper httpServletRequestWrapper =
3180 (HttpServletRequestWrapper)originalRequest;
3181
3182 originalRequest =
3183 (HttpServletRequest)httpServletRequestWrapper.getRequest();
3184 }
3185
3186 for (int i = persistentHttpServletRequestWrappers.size() - 1; i >= 0;
3187 i--) {
3188
3189 HttpServletRequestWrapper httpServletRequestWrapper =
3190 persistentHttpServletRequestWrappers.get(i);
3191
3192 httpServletRequestWrapper.setRequest(originalRequest);
3193
3194 originalRequest = httpServletRequestWrapper;
3195 }
3196
3197 return originalRequest;
3198 }
3199
3200 @Override
3201 public long getParentGroupId(long groupId)
3202 throws PortalException, SystemException {
3203
3204 if (groupId <= 0) {
3205 return 0;
3206 }
3207
3208 Group group = GroupLocalServiceUtil.getGroup(groupId);
3209
3210 long parentGroupId = groupId;
3211
3212 if (group.isLayout()) {
3213 parentGroupId = group.getParentGroupId();
3214 }
3215
3216 return parentGroupId;
3217 }
3218
3219 @Override
3220 public String getPathContext() {
3221 return _pathContext;
3222 }
3223
3224 @Override
3225 public String getPathFriendlyURLPrivateGroup() {
3226 return _pathFriendlyURLPrivateGroup;
3227 }
3228
3229 @Override
3230 public String getPathFriendlyURLPrivateUser() {
3231 return _pathFriendlyURLPrivateUser;
3232 }
3233
3234 @Override
3235 public String getPathFriendlyURLPublic() {
3236 return _pathFriendlyURLPublic;
3237 }
3238
3239 @Override
3240 public String getPathImage() {
3241 return _pathImage;
3242 }
3243
3244 @Override
3245 public String getPathMain() {
3246 return _pathMain;
3247 }
3248
3249 @Override
3250 public String getPathProxy() {
3251 return _pathProxy;
3252 }
3253
3254 @Override
3255 public long getPlidFromFriendlyURL(long companyId, String friendlyURL) {
3256 if (Validator.isNull(friendlyURL)) {
3257 return LayoutConstants.DEFAULT_PLID;
3258 }
3259
3260 String[] urlParts = friendlyURL.split("\\/", 4);
3261
3262 if ((friendlyURL.charAt(0) != CharPool.SLASH) &&
3263 (urlParts.length != 4)) {
3264
3265 return LayoutConstants.DEFAULT_PLID;
3266 }
3267
3268 boolean privateLayout = true;
3269
3270 String urlPrefix = StringPool.SLASH + urlParts[1];
3271
3272 if (_PUBLIC_GROUP_SERVLET_MAPPING.equals(urlPrefix)) {
3273 privateLayout = false;
3274 }
3275 else if (_PRIVATE_GROUP_SERVLET_MAPPING.equals(urlPrefix) ||
3276 _PRIVATE_USER_SERVLET_MAPPING.equals(urlPrefix)) {
3277
3278 privateLayout = true;
3279 }
3280 else {
3281 return LayoutConstants.DEFAULT_PLID;
3282 }
3283
3284 Group group = null;
3285
3286 try {
3287 group = GroupLocalServiceUtil.getFriendlyURLGroup(
3288 companyId, StringPool.SLASH + urlParts[2]);
3289 }
3290 catch (Exception e) {
3291 }
3292
3293 if (group == null) {
3294 return LayoutConstants.DEFAULT_PLID;
3295 }
3296
3297 Layout layout = null;
3298
3299 try {
3300 String layoutFriendlyURL = null;
3301
3302 if (urlParts.length == 4) {
3303 layoutFriendlyURL = StringPool.SLASH + urlParts[3];
3304
3305 layout = LayoutLocalServiceUtil.getFriendlyURLLayout(
3306 group.getGroupId(), privateLayout, layoutFriendlyURL);
3307 }
3308 else {
3309 List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
3310 group.getGroupId(), privateLayout,
3311 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, true, 0, 1);
3312
3313 if (!layouts.isEmpty()) {
3314 layout = layouts.get(0);
3315 }
3316 else {
3317 return LayoutConstants.DEFAULT_PLID;
3318 }
3319 }
3320
3321 return layout.getPlid();
3322 }
3323 catch (Exception e) {
3324 }
3325
3326 return LayoutConstants.DEFAULT_PLID;
3327 }
3328
3329 @Override
3330 public long getPlidFromPortletId(
3331 long groupId, boolean privateLayout, String portletId)
3332 throws PortalException, SystemException {
3333
3334 long plid = LayoutConstants.DEFAULT_PLID;
3335
3336 StringBundler sb = new StringBundler(5);
3337
3338 sb.append(groupId);
3339 sb.append(StringPool.SPACE);
3340 sb.append(privateLayout);
3341 sb.append(StringPool.SPACE);
3342 sb.append(portletId);
3343
3344 String key = sb.toString();
3345
3346 Long plidObj = _plidToPortletIdMap.get(key);
3347
3348 if (plidObj == null) {
3349 plid = doGetPlidFromPortletId(groupId, privateLayout, portletId);
3350
3351 if (plid != LayoutConstants.DEFAULT_PLID) {
3352 _plidToPortletIdMap.put(key, plid);
3353 }
3354 }
3355 else {
3356 plid = plidObj.longValue();
3357
3358 boolean validPlid = false;
3359
3360 try {
3361 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
3362
3363 LayoutTypePortlet layoutTypePortlet =
3364 (LayoutTypePortlet)layout.getLayoutType();
3365
3366 if (layoutTypePortlet.hasDefaultScopePortletId(
3367 groupId, portletId)) {
3368
3369 validPlid = true;
3370 }
3371 }
3372 catch (Exception e) {
3373 }
3374
3375 if (!validPlid) {
3376 _plidToPortletIdMap.remove(key);
3377
3378 plid = doGetPlidFromPortletId(
3379 groupId, privateLayout, portletId);
3380
3381 if (plid != LayoutConstants.DEFAULT_PLID) {
3382 _plidToPortletIdMap.put(key, plid);
3383 }
3384 }
3385 }
3386
3387 return plid;
3388 }
3389
3390 @Override
3391 public long getPlidFromPortletId(long groupId, String portletId)
3392 throws PortalException, SystemException {
3393
3394 long plid = getPlidFromPortletId(groupId, false, portletId);
3395
3396 if (plid == LayoutConstants.DEFAULT_PLID) {
3397 plid = getPlidFromPortletId(groupId, true, portletId);
3398 }
3399
3400 if (plid == LayoutConstants.DEFAULT_PLID) {
3401 if (_log.isDebugEnabled()) {
3402 _log.debug(
3403 "Portlet " + portletId +
3404 " does not exist on a page in group " + groupId);
3405 }
3406 }
3407
3408 return plid;
3409 }
3410
3411 @Override
3412 public String getPortalLibDir() {
3413 return PropsValues.LIFERAY_LIB_PORTAL_DIR;
3414 }
3415
3416
3419 @Override
3420 public int getPortalPort() {
3421 return _portalPort.get();
3422 }
3423
3424 @Override
3425 public int getPortalPort(boolean secure) {
3426 if (secure) {
3427 return _securePortalPort.get();
3428 }
3429 else {
3430 return _portalPort.get();
3431 }
3432 }
3433
3434 @Override
3435 public Properties getPortalProperties() {
3436 return PropsUtil.getProperties();
3437 }
3438
3439 @Override
3440 public String getPortalURL(HttpServletRequest request) {
3441 return getPortalURL(request, isSecure(request));
3442 }
3443
3444 @Override
3445 public String getPortalURL(HttpServletRequest request, boolean secure) {
3446 return getPortalURL(
3447 request.getServerName(), request.getServerPort(), secure);
3448 }
3449
3450 @Override
3451 public String getPortalURL(Layout layout, ThemeDisplay themeDisplay)
3452 throws PortalException, SystemException {
3453
3454 String serverName = themeDisplay.getServerName();
3455
3456 if (layout == null) {
3457 layout = themeDisplay.getLayout();
3458 }
3459
3460 if (layout != null) {
3461 LayoutSet layoutSet = layout.getLayoutSet();
3462
3463 String virtualHostname = layoutSet.getVirtualHostname();
3464
3465 String domain = HttpUtil.getDomain(themeDisplay.getURLPortal());
3466
3467 if (Validator.isNotNull(virtualHostname) &&
3468 domain.startsWith(virtualHostname)) {
3469
3470 serverName = virtualHostname;
3471 }
3472 }
3473
3474 return getPortalURL(
3475 serverName, themeDisplay.getServerPort(), themeDisplay.isSecure());
3476 }
3477
3478 @Override
3479 public String getPortalURL(PortletRequest portletRequest) {
3480 return getPortalURL(portletRequest, portletRequest.isSecure());
3481 }
3482
3483 @Override
3484 public String getPortalURL(PortletRequest portletRequest, boolean secure) {
3485 return getPortalURL(
3486 portletRequest.getServerName(), portletRequest.getServerPort(),
3487 secure);
3488 }
3489
3490 @Override
3491 public String getPortalURL(
3492 String serverName, int serverPort, boolean secure) {
3493
3494 StringBundler sb = new StringBundler();
3495
3496 boolean https =
3497 secure || Http.HTTPS.equals(PropsValues.WEB_SERVER_PROTOCOL);
3498
3499 if (https) {
3500 sb.append(Http.HTTPS_WITH_SLASH);
3501 }
3502 else {
3503 sb.append(Http.HTTP_WITH_SLASH);
3504 }
3505
3506 if (Validator.isNull(PropsValues.WEB_SERVER_HOST)) {
3507 sb.append(serverName);
3508 }
3509 else {
3510 sb.append(PropsValues.WEB_SERVER_HOST);
3511 }
3512
3513 if (!https) {
3514 if (PropsValues.WEB_SERVER_HTTP_PORT == -1) {
3515 if ((serverPort != Http.HTTP_PORT) &&
3516 (serverPort != Http.HTTPS_PORT)) {
3517
3518 sb.append(StringPool.COLON);
3519 sb.append(serverPort);
3520 }
3521 }
3522 else {
3523 if (PropsValues.WEB_SERVER_HTTP_PORT != Http.HTTP_PORT) {
3524 sb.append(StringPool.COLON);
3525 sb.append(PropsValues.WEB_SERVER_HTTP_PORT);
3526 }
3527 }
3528 }
3529 else {
3530 if (PropsValues.WEB_SERVER_HTTPS_PORT == -1) {
3531 if ((serverPort != Http.HTTP_PORT) &&
3532 (serverPort != Http.HTTPS_PORT)) {
3533
3534 sb.append(StringPool.COLON);
3535 sb.append(serverPort);
3536 }
3537 }
3538 else {
3539 if (PropsValues.WEB_SERVER_HTTPS_PORT != Http.HTTPS_PORT) {
3540 sb.append(StringPool.COLON);
3541 sb.append(PropsValues.WEB_SERVER_HTTPS_PORT);
3542 }
3543 }
3544 }
3545
3546 return sb.toString();
3547 }
3548
3549 @Override
3550 public String getPortalURL(ThemeDisplay themeDisplay)
3551 throws PortalException, SystemException {
3552
3553 return getPortalURL(null, themeDisplay);
3554 }
3555
3556 @Override
3557 public String getPortalWebDir() {
3558 return PropsValues.LIFERAY_WEB_PORTAL_DIR;
3559 }
3560
3561 @Override
3562 public Set<String> getPortletAddDefaultResourceCheckWhitelist() {
3563 return _portletAddDefaultResourceCheckWhitelist;
3564 }
3565
3566 @Override
3567 public Set<String> getPortletAddDefaultResourceCheckWhitelistActions() {
3568 return _portletAddDefaultResourceCheckWhitelistActions;
3569 }
3570
3571
3574 @Override
3575 public List<BreadcrumbEntry> getPortletBreadcrumbList(
3576 HttpServletRequest request) {
3577
3578 return getPortletBreadcrumbs(request);
3579 }
3580
3581 @Override
3582 public List<BreadcrumbEntry> getPortletBreadcrumbs(
3583 HttpServletRequest request) {
3584
3585 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
3586 WebKeys.THEME_DISPLAY);
3587
3588 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
3589
3590 String name = WebKeys.PORTLET_BREADCRUMBS;
3591
3592 String portletName = portletDisplay.getPortletName();
3593
3594 if (Validator.isNotNull(portletDisplay.getId()) &&
3595 !portletName.equals(PortletKeys.BREADCRUMB) &&
3596 !portletDisplay.isFocused()) {
3597
3598 name = name.concat(
3599 StringPool.UNDERLINE.concat(portletDisplay.getId()));
3600 }
3601
3602 return (List<BreadcrumbEntry>)request.getAttribute(name);
3603 }
3604
3605 @Override
3606 public String getPortletDescription(
3607 Portlet portlet, ServletContext servletContext, Locale locale) {
3608
3609 PortletConfig portletConfig = PortletConfigFactoryUtil.create(
3610 portlet, servletContext);
3611
3612 ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);
3613
3614 return resourceBundle.getString(
3615 JavaConstants.JAVAX_PORTLET_DESCRIPTION);
3616 }
3617
3618 @Override
3619 public String getPortletDescription(Portlet portlet, User user) {
3620 return getPortletDescription(portlet.getPortletId(), user);
3621 }
3622
3623 @Override
3624 public String getPortletDescription(String portletId, Locale locale) {
3625 return LanguageUtil.get(
3626 locale,
3627 JavaConstants.JAVAX_PORTLET_DESCRIPTION.concat(
3628 StringPool.PERIOD).concat(portletId));
3629 }
3630
3631 @Override
3632 public String getPortletDescription(String portletId, String languageId) {
3633 Locale locale = LocaleUtil.fromLanguageId(languageId);
3634
3635 return getPortletDescription(portletId, locale);
3636 }
3637
3638 @Override
3639 public String getPortletDescription(String portletId, User user) {
3640 return LanguageUtil.get(
3641 user.getLocale(),
3642 JavaConstants.JAVAX_PORTLET_DESCRIPTION.concat(
3643 StringPool.PERIOD).concat(portletId));
3644 }
3645
3646 public Object[] getPortletFriendlyURLMapper(
3647 long groupId, boolean privateLayout, String url,
3648 Map<String, String[]> params, Map<String, Object> requestContext)
3649 throws PortalException, SystemException {
3650
3651 boolean foundFriendlyURLMapper = false;
3652
3653 String friendlyURL = url;
3654 String queryString = StringPool.BLANK;
3655
3656 List<Portlet> portlets =
3657 PortletLocalServiceUtil.getFriendlyURLMapperPortlets();
3658
3659 Iterator<Portlet> itr = portlets.iterator();
3660
3661 while (itr.hasNext()) {
3662 Portlet portlet = itr.next();
3663
3664 FriendlyURLMapper friendlyURLMapper =
3665 portlet.getFriendlyURLMapperInstance();
3666
3667 if (url.endsWith(
3668 StringPool.SLASH + friendlyURLMapper.getMapping())) {
3669
3670 url += StringPool.SLASH;
3671 }
3672
3673 int pos = -1;
3674
3675 if (friendlyURLMapper.isCheckMappingWithPrefix()) {
3676 pos = url.indexOf(
3677 FRIENDLY_URL_SEPARATOR + friendlyURLMapper.getMapping() +
3678 StringPool.SLASH);
3679 }
3680 else {
3681 pos = url.indexOf(
3682 StringPool.SLASH + friendlyURLMapper.getMapping() +
3683 StringPool.SLASH);
3684 }
3685
3686 if (pos != -1) {
3687 foundFriendlyURLMapper = true;
3688
3689 friendlyURL = url.substring(0, pos);
3690
3691 InheritableMap<String, String[]> actualParams =
3692 new InheritableMap<String, String[]>();
3693
3694 if (params != null) {
3695 actualParams.setParentMap(params);
3696 }
3697
3698 Map<String, String> prpIdentifiers =
3699 new HashMap<String, String>();
3700
3701 Set<PublicRenderParameter> publicRenderParameters =
3702 portlet.getPublicRenderParameters();
3703
3704 for (PublicRenderParameter publicRenderParameter :
3705 publicRenderParameters) {
3706
3707 QName qName = publicRenderParameter.getQName();
3708
3709 String publicRenderParameterIdentifier =
3710 qName.getLocalPart();
3711 String publicRenderParameterName =
3712 PortletQNameUtil.getPublicRenderParameterName(qName);
3713
3714 prpIdentifiers.put(
3715 publicRenderParameterIdentifier,
3716 publicRenderParameterName);
3717 }
3718
3719 FriendlyURLMapperThreadLocal.setPRPIdentifiers(prpIdentifiers);
3720
3721 if (friendlyURLMapper.isCheckMappingWithPrefix()) {
3722 friendlyURLMapper.populateParams(
3723 url.substring(pos + 2), actualParams, requestContext);
3724 }
3725 else {
3726 friendlyURLMapper.populateParams(
3727 url.substring(pos), actualParams, requestContext);
3728 }
3729
3730 queryString =
3731 StringPool.AMPERSAND +
3732 HttpUtil.parameterMapToString(actualParams, false);
3733
3734 break;
3735 }
3736 }
3737
3738 if (!foundFriendlyURLMapper) {
3739 int x = url.indexOf(FRIENDLY_URL_SEPARATOR);
3740
3741 if (x != -1) {
3742 int y = url.indexOf(CharPool.SLASH, x + 3);
3743
3744 if (y == -1) {
3745 y = url.length();
3746 }
3747
3748 String ppid = url.substring(x + 3, y);
3749
3750 if (Validator.isNotNull(ppid)) {
3751 friendlyURL = url.substring(0, x);
3752
3753 Map<String, String[]> actualParams = null;
3754
3755 if (params != null) {
3756 actualParams = new HashMap<String, String[]>(params);
3757 }
3758 else {
3759 actualParams = new HashMap<String, String[]>();
3760 }
3761
3762 actualParams.put("p_p_id", new String[] {ppid});
3763 actualParams.put("p_p_lifecycle", new String[] {"0"});
3764 actualParams.put(
3765 "p_p_state",
3766 new String[] {WindowState.MAXIMIZED.toString()});
3767 actualParams.put(
3768 "p_p_mode", new String[] {PortletMode.VIEW.toString()});
3769
3770 queryString =
3771 StringPool.AMPERSAND +
3772 HttpUtil.parameterMapToString(actualParams, false);
3773 }
3774 }
3775 }
3776
3777 friendlyURL = StringUtil.replace(
3778 friendlyURL, StringPool.DOUBLE_SLASH, StringPool.SLASH);
3779
3780 if (friendlyURL.endsWith(StringPool.SLASH)) {
3781 friendlyURL = friendlyURL.substring(0, friendlyURL.length() - 1);
3782 }
3783
3784 Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(
3785 groupId, privateLayout, friendlyURL);
3786
3787 return new Object[] {layout, queryString};
3788 }
3789
3790 @Override
3791 public String getPortletId(HttpServletRequest request) {
3792 LiferayPortletConfig liferayPortletConfig =
3793 (LiferayPortletConfig)request.getAttribute(
3794 JavaConstants.JAVAX_PORTLET_CONFIG);
3795
3796 if (liferayPortletConfig != null) {
3797 return liferayPortletConfig.getPortletId();
3798 }
3799 else {
3800 return null;
3801 }
3802 }
3803
3804 @Override
3805 public String getPortletId(PortletRequest portletRequest) {
3806 LiferayPortletConfig liferayPortletConfig =
3807 (LiferayPortletConfig)portletRequest.getAttribute(
3808 JavaConstants.JAVAX_PORTLET_CONFIG);
3809
3810 if (liferayPortletConfig != null) {
3811 return liferayPortletConfig.getPortletId();
3812 }
3813 else {
3814 return null;
3815 }
3816 }
3817
3818 @Override
3819 public String getPortletLongTitle(Portlet portlet, Locale locale) {
3820 return getPortletLongTitle(portlet.getPortletId(), locale);
3821 }
3822
3823 @Override
3824 public String getPortletLongTitle(
3825 Portlet portlet, ServletContext servletContext, Locale locale) {
3826
3827 PortletConfig portletConfig = PortletConfigFactoryUtil.create(
3828 portlet, servletContext);
3829
3830 ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);
3831
3832 try {
3833 String portletLongTitle = resourceBundle.getString(
3834 JavaConstants.JAVAX_PORTLET_LONG_TITLE);
3835
3836 if (portletLongTitle.startsWith(
3837 JavaConstants.JAVAX_PORTLET_LONG_TITLE)) {
3838
3839 portletLongTitle = getPortletTitle(
3840 portlet, servletContext, locale);
3841 }
3842
3843 return portletLongTitle;
3844 }
3845 catch (Exception e) {
3846 return getPortletTitle(portlet, servletContext, locale);
3847 }
3848 }
3849
3850 @Override
3851 public String getPortletLongTitle(Portlet portlet, String languageId) {
3852 return getPortletLongTitle(portlet.getPortletId(), languageId);
3853 }
3854
3855 @Override
3856 public String getPortletLongTitle(Portlet portlet, User user) {
3857 return getPortletLongTitle(portlet.getPortletId(), user);
3858 }
3859
3860 @Override
3861 public String getPortletLongTitle(String portletId, Locale locale) {
3862 String portletLongTitle = LanguageUtil.get(
3863 locale,
3864 JavaConstants.JAVAX_PORTLET_LONG_TITLE.concat(
3865 StringPool.PERIOD).concat(portletId),
3866 StringPool.BLANK);
3867
3868 if (Validator.isNull(portletLongTitle)) {
3869 portletLongTitle = getPortletTitle(portletId, locale);
3870 }
3871
3872 return portletLongTitle;
3873 }
3874
3875 @Override
3876 public String getPortletLongTitle(String portletId, String languageId) {
3877 Locale locale = LocaleUtil.fromLanguageId(languageId);
3878
3879 return getPortletLongTitle(portletId, locale);
3880 }
3881
3882 @Override
3883 public String getPortletLongTitle(String portletId, User user) {
3884 return getPortletLongTitle(portletId, user.getLocale());
3885 }
3886
3887 @Override
3888 public String getPortletNamespace(String portletId) {
3889 return StringPool.UNDERLINE.concat(portletId).concat(
3890 StringPool.UNDERLINE);
3891 }
3892
3893 @Override
3894 public String getPortletTitle(Portlet portlet, Locale locale) {
3895 return getPortletTitle(portlet.getPortletId(), locale);
3896 }
3897
3898 @Override
3899 public String getPortletTitle(
3900 Portlet portlet, ServletContext servletContext, Locale locale) {
3901
3902 PortletConfig portletConfig = PortletConfigFactoryUtil.create(
3903 portlet, servletContext);
3904
3905 ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);
3906
3907 return resourceBundle.getString(JavaConstants.JAVAX_PORTLET_TITLE);
3908 }
3909
3910 @Override
3911 public String getPortletTitle(Portlet portlet, String languageId) {
3912 return getPortletTitle(portlet.getPortletId(), languageId);
3913 }
3914
3915 @Override
3916 public String getPortletTitle(Portlet portlet, User user) {
3917 return getPortletTitle(portlet.getPortletId(), user);
3918 }
3919
3920 @Override
3921 public String getPortletTitle(RenderResponse renderResponse) {
3922 PortletResponseImpl portletResponseImpl =
3923 PortletResponseImpl.getPortletResponseImpl(renderResponse);
3924
3925 return ((RenderResponseImpl)portletResponseImpl).getTitle();
3926 }
3927
3928 @Override
3929 public String getPortletTitle(String portletId, Locale locale) {
3930 return LanguageUtil.get(
3931 locale,
3932 JavaConstants.JAVAX_PORTLET_TITLE.concat(StringPool.PERIOD).concat(
3933 portletId));
3934 }
3935
3936 @Override
3937 public String getPortletTitle(String portletId, String languageId) {
3938 Locale locale = LocaleUtil.fromLanguageId(languageId);
3939
3940 return getPortletTitle(portletId, locale);
3941 }
3942
3943 @Override
3944 public String getPortletTitle(String portletId, User user) {
3945 return LanguageUtil.get(
3946 user.getLocale(),
3947 JavaConstants.JAVAX_PORTLET_TITLE.concat(StringPool.PERIOD).concat(
3948 portletId));
3949 }
3950
3951 @Override
3952 public String getPortletXmlFileName() throws SystemException {
3953 if (PrefsPropsUtil.getBoolean(
3954 PropsKeys.AUTO_DEPLOY_CUSTOM_PORTLET_XML,
3955 PropsValues.AUTO_DEPLOY_CUSTOM_PORTLET_XML)) {
3956
3957 return PORTLET_XML_FILE_NAME_CUSTOM;
3958 }
3959 else {
3960 return PORTLET_XML_FILE_NAME_STANDARD;
3961 }
3962 }
3963
3964 @Override
3965 public PortletPreferences getPreferences(HttpServletRequest request) {
3966 RenderRequest renderRequest = (RenderRequest)request.getAttribute(
3967 JavaConstants.JAVAX_PORTLET_REQUEST);
3968
3969 PortletPreferences portletPreferences = null;
3970
3971 if (renderRequest != null) {
3972 PortletPreferencesWrapper portletPreferencesWrapper =
3973 (PortletPreferencesWrapper)renderRequest.getPreferences();
3974
3975 portletPreferences =
3976 portletPreferencesWrapper.getPortletPreferencesImpl();
3977 }
3978
3979 return portletPreferences;
3980 }
3981
3982 @Override
3983 public PreferencesValidator getPreferencesValidator(Portlet portlet) {
3984 PortletBag portletBag = PortletBagPool.get(portlet.getRootPortletId());
3985
3986 return portletBag.getPreferencesValidatorInstance();
3987 }
3988
3989 @Override
3990 public String getRelativeHomeURL(HttpServletRequest request)
3991 throws PortalException, SystemException {
3992
3993 Company company = getCompany(request);
3994
3995 String homeURL = company.getHomeURL();
3996
3997 if (Validator.isNull(homeURL)) {
3998 homeURL = PropsValues.COMPANY_DEFAULT_HOME_URL;
3999 }
4000
4001 return homeURL;
4002 }
4003
4004 @Override
4005 public long getScopeGroupId(HttpServletRequest request)
4006 throws PortalException, SystemException {
4007
4008 String portletId = getPortletId(request);
4009
4010 return getScopeGroupId(request, portletId);
4011 }
4012
4013 @Override
4014 public long getScopeGroupId(HttpServletRequest request, String portletId)
4015 throws PortalException, SystemException {
4016
4017 return getScopeGroupId(request, portletId, false);
4018 }
4019
4020 @Override
4021 public long getScopeGroupId(
4022 HttpServletRequest request, String portletId,
4023 boolean checkStagingGroup)
4024 throws PortalException, SystemException {
4025
4026 Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
4027
4028 long scopeGroupId = 0;
4029
4030 if (layout != null) {
4031 Group group = layout.getGroup();
4032
4033 if (group.isControlPanel()) {
4034 long doAsGroupId = ParamUtil.getLong(request, "doAsGroupId");
4035
4036 Group doAsGroup = GroupLocalServiceUtil.fetchGroup(doAsGroupId);
4037
4038 if ((doAsGroupId <= 0) || (doAsGroup == null)) {
4039 doAsGroupId = getDefaultScopeGroupId(group.getCompanyId());
4040 }
4041
4042 if (doAsGroupId > 0) {
4043 scopeGroupId = doAsGroupId;
4044 }
4045
4046 group = GroupLocalServiceUtil.fetchGroup(scopeGroupId);
4047
4048 if ((group != null) && group.hasStagingGroup()) {
4049 try {
4050 Group stagingGroup = group.getStagingGroup();
4051
4052 scopeGroupId = stagingGroup.getGroupId();
4053 }
4054 catch (Exception e) {
4055 }
4056 }
4057 }
4058
4059 if ((portletId != null) &&
4060 (group.isStaged() || group.isStagingGroup())) {
4061
4062 Group liveGroup = group;
4063
4064 if (group.isStagingGroup()) {
4065 liveGroup = group.getLiveGroup();
4066 }
4067
4068 if (liveGroup.isStaged() &&
4069 !liveGroup.isStagedPortlet(portletId)) {
4070
4071 Layout liveGroupLayout =
4072 LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
4073 layout.getUuid(), liveGroup.getGroupId(),
4074 layout.isPrivateLayout());
4075
4076 if ((liveGroupLayout != null) &&
4077 liveGroupLayout.hasScopeGroup()) {
4078
4079 scopeGroupId = getScopeGroupId(
4080 liveGroupLayout, portletId);
4081 }
4082 else if (checkStagingGroup &&
4083 !liveGroup.isStagedRemotely()) {
4084
4085 Group stagingGroup = liveGroup.getStagingGroup();
4086
4087 scopeGroupId = stagingGroup.getGroupId();
4088 }
4089 else {
4090 scopeGroupId = liveGroup.getGroupId();
4091 }
4092 }
4093 }
4094 }
4095
4096 if (scopeGroupId <= 0) {
4097 scopeGroupId = getScopeGroupId(layout, portletId);
4098 }
4099
4100 return scopeGroupId;
4101 }
4102
4103 @Override
4104 public long getScopeGroupId(Layout layout) {
4105 if (layout == null) {
4106 return 0;
4107 }
4108 else {
4109 return layout.getGroupId();
4110 }
4111 }
4112
4113 @Override
4114 public long getScopeGroupId(Layout layout, String portletId) {
4115 if (layout == null) {
4116 return 0;
4117 }
4118
4119 if (Validator.isNull(portletId)) {
4120 return layout.getGroupId();
4121 }
4122
4123 boolean strict = PortletPreferencesThreadLocal.isStrict();
4124
4125 PortletPreferencesThreadLocal.setStrict(true);
4126
4127 try {
4128 PortletPreferences portletSetup =
4129 PortletPreferencesFactoryUtil.getLayoutPortletSetup(
4130 layout, portletId);
4131
4132 String scopeType = GetterUtil.getString(
4133 portletSetup.getValue("lfrScopeType", null));
4134
4135 if (Validator.isNull(scopeType)) {
4136 return layout.getGroupId();
4137 }
4138
4139 if (scopeType.equals("company")) {
4140 Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(
4141 layout.getCompanyId());
4142
4143 return companyGroup.getGroupId();
4144 }
4145 else {
4146 String scopeLayoutUuid = GetterUtil.getString(
4147 portletSetup.getValue("lfrScopeLayoutUuid", null));
4148
4149 Layout scopeLayout =
4150 LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
4151 scopeLayoutUuid, layout.getGroupId(),
4152 layout.isPrivateLayout());
4153
4154 Group scopeGroup = scopeLayout.getScopeGroup();
4155
4156 return scopeGroup.getGroupId();
4157 }
4158 }
4159 catch (Exception e) {
4160 return layout.getGroupId();
4161 }
4162 finally {
4163 PortletPreferencesThreadLocal.setStrict(strict);
4164 }
4165 }
4166
4167 @Override
4168 public long getScopeGroupId(long plid) {
4169 Layout layout = null;
4170
4171 try {
4172 layout = LayoutLocalServiceUtil.getLayout(plid);
4173 }
4174 catch (Exception e) {
4175 }
4176
4177 return getScopeGroupId(layout);
4178 }
4179
4180 @Override
4181 public long getScopeGroupId(PortletRequest portletRequest)
4182 throws PortalException, SystemException {
4183
4184 return getScopeGroupId(getHttpServletRequest(portletRequest));
4185 }
4186
4187 @Override
4188 public User getSelectedUser(HttpServletRequest request)
4189 throws PortalException, SystemException {
4190
4191 return getSelectedUser(request, true);
4192 }
4193
4194 @Override
4195 public User getSelectedUser(
4196 HttpServletRequest request, boolean checkPermission)
4197 throws PortalException, SystemException {
4198
4199 long userId = ParamUtil.getLong(request, "p_u_i_d");
4200
4201 User user = null;
4202
4203 try {
4204 if (checkPermission) {
4205 user = UserServiceUtil.getUserById(userId);
4206 }
4207 else {
4208 user = UserLocalServiceUtil.getUserById(userId);
4209 }
4210 }
4211 catch (NoSuchUserException nsue) {
4212 }
4213
4214 return user;
4215 }
4216
4217 @Override
4218 public User getSelectedUser(PortletRequest portletRequest)
4219 throws PortalException, SystemException {
4220
4221 return getSelectedUser(portletRequest, true);
4222 }
4223
4224 @Override
4225 public User getSelectedUser(
4226 PortletRequest portletRequest, boolean checkPermission)
4227 throws PortalException, SystemException {
4228
4229 return getSelectedUser(
4230 getHttpServletRequest(portletRequest), checkPermission);
4231 }
4232
4233 @Override
4234 public ServletContext getServletContext(
4235 Portlet portlet, ServletContext servletContext) {
4236
4237 PortletConfig portletConfig = PortletConfigFactoryUtil.create(
4238 portlet, servletContext);
4239
4240 LiferayPortletContext liferayPortletContext =
4241 (LiferayPortletContext)portletConfig.getPortletContext();
4242
4243 return liferayPortletContext.getServletContext();
4244 }
4245
4246 @Override
4247 public String getSiteLoginURL(ThemeDisplay themeDisplay)
4248 throws PortalException, SystemException {
4249
4250 if (Validator.isNull(PropsValues.AUTH_LOGIN_SITE_URL)) {
4251 return null;
4252 }
4253
4254 List<Layout> layouts = themeDisplay.getUnfilteredLayouts();
4255
4256 if (layouts == null) {
4257 return null;
4258 }
4259
4260 for (Layout layout : layouts) {
4261 String friendlyURL = layout.getFriendlyURL();
4262
4263 if (friendlyURL.equals(PropsValues.AUTH_LOGIN_SITE_URL)) {
4264 if (themeDisplay.getLayout() == null) {
4265 break;
4266 }
4267
4268 String layoutSetFriendlyURL = getLayoutSetFriendlyURL(
4269 layout.getLayoutSet(), themeDisplay);
4270
4271 return layoutSetFriendlyURL + PropsValues.AUTH_LOGIN_SITE_URL;
4272 }
4273 }
4274
4275 return null;
4276 }
4277
4278 @Override
4279 public String getStaticResourceURL(HttpServletRequest request, String uri) {
4280 return getStaticResourceURL(request, uri, null, 0);
4281 }
4282
4283 @Override
4284 public String getStaticResourceURL(
4285 HttpServletRequest request, String uri, long timestamp) {
4286
4287 return getStaticResourceURL(request, uri, null, timestamp);
4288 }
4289
4290 @Override
4291 public String getStaticResourceURL(
4292 HttpServletRequest request, String uri, String queryString) {
4293
4294 return getStaticResourceURL(request, uri, queryString, 0);
4295 }
4296
4297 @Override
4298 public String getStaticResourceURL(
4299 HttpServletRequest request, String uri, String queryString,
4300 long timestamp) {
4301
4302 if (uri.indexOf(CharPool.QUESTION) != -1) {
4303 return uri;
4304 }
4305
4306 if (uri.startsWith(StringPool.DOUBLE_SLASH)) {
4307 uri = uri.substring(1);
4308 }
4309
4310 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
4311 WebKeys.THEME_DISPLAY);
4312
4313 Theme theme = themeDisplay.getTheme();
4314 ColorScheme colorScheme = themeDisplay.getColorScheme();
4315
4316 Map<String, String[]> parameterMap = null;
4317
4318 if (Validator.isNotNull(queryString)) {
4319 parameterMap = HttpUtil.getParameterMap(queryString);
4320 }
4321
4322 StringBundler sb = new StringBundler();
4323
4324
4325
4326 sb.append(uri);
4327 sb.append(StringPool.QUESTION);
4328
4329
4330
4331 if ((parameterMap == null) || !parameterMap.containsKey("browserId")) {
4332 sb.append("&browserId=");
4333 sb.append(BrowserSnifferUtil.getBrowserId(request));
4334 }
4335
4336
4337
4338 if ((uri.endsWith(".css") || uri.endsWith(".jsp")) &&
4339 ((parameterMap == null) || !parameterMap.containsKey("themeId"))) {
4340
4341 sb.append("&themeId=");
4342 sb.append(theme.getThemeId());
4343 }
4344
4345 if (uri.endsWith(".jsp") &&
4346 ((parameterMap == null) ||
4347 !parameterMap.containsKey("colorSchemeId"))) {
4348
4349 sb.append("&colorSchemeId=");
4350 sb.append(colorScheme.getColorSchemeId());
4351 }
4352
4353
4354
4355 if ((parameterMap == null) ||
4356 !parameterMap.containsKey("minifierType")) {
4357
4358 String minifierType = StringPool.BLANK;
4359
4360 if (uri.endsWith(".css") || uri.endsWith("css.jsp") ||
4361 (uri.endsWith(".jsp") && uri.contains("/css/"))) {
4362
4363 if (themeDisplay.isThemeCssFastLoad()) {
4364 minifierType = "css";
4365 }
4366 }
4367 else if (themeDisplay.isThemeJsFastLoad()) {
4368 minifierType = "js";
4369 }
4370
4371 if (Validator.isNotNull(minifierType)) {
4372 sb.append("&minifierType=");
4373 sb.append(minifierType);
4374 }
4375 }
4376
4377
4378
4379 if (Validator.isNotNull(queryString)) {
4380 if (!queryString.startsWith(StringPool.AMPERSAND)) {
4381 sb.append(StringPool.AMPERSAND);
4382 }
4383
4384 sb.append(queryString);
4385 }
4386
4387
4388
4389 sb.append("&languageId=");
4390 sb.append(themeDisplay.getLanguageId());
4391
4392
4393
4394 sb.append("&b=");
4395 sb.append(ReleaseInfo.getBuildNumber());
4396
4397
4398
4399 if ((parameterMap == null) || !parameterMap.containsKey("t")) {
4400 if ((timestamp == 0) && uri.startsWith(StrutsUtil.TEXT_HTML_DIR)) {
4401 ServletContext servletContext =
4402 (ServletContext)request.getAttribute(WebKeys.CTX);
4403
4404 timestamp = FileTimestampUtil.getTimestamp(servletContext, uri);
4405 }
4406
4407 if (timestamp == 0) {
4408 timestamp = theme.getTimestamp();
4409 }
4410
4411 sb.append("&t=");
4412 sb.append(timestamp);
4413 }
4414
4415 String url = sb.toString();
4416
4417 url = StringUtil.replace(url, "?&", StringPool.QUESTION);
4418
4419 return url;
4420 }
4421
4422 @Override
4423 public String getStrutsAction(HttpServletRequest request) {
4424 String strutsAction = ParamUtil.getString(request, "struts_action");
4425
4426 if (Validator.isNotNull(strutsAction)) {
4427
4428
4429
4430
4431
4432 return StringPool.BLANK;
4433 }
4434
4435 return getPortletParam(request, "struts_action");
4436 }
4437
4438 @Override
4439 public String[] getSystemGroups() {
4440 return _allSystemGroups;
4441 }
4442
4443 @Override
4444 public String[] getSystemOrganizationRoles() {
4445 return _allSystemOrganizationRoles;
4446 }
4447
4448 @Override
4449 public String[] getSystemRoles() {
4450 return _allSystemRoles;
4451 }
4452
4453 @Override
4454 public String[] getSystemSiteRoles() {
4455 return _allSystemSiteRoles;
4456 }
4457
4458 @Override
4459 public String getUniqueElementId(
4460 HttpServletRequest request, String namespace, String elementId) {
4461
4462 String uniqueElementId = elementId;
4463
4464 Set<String> uniqueElementIds = (Set<String>)request.getAttribute(
4465 WebKeys.UNIQUE_ELEMENT_IDS);
4466
4467 if (uniqueElementIds == null) {
4468 uniqueElementIds = new HashSet<String>();
4469
4470 request.setAttribute(WebKeys.UNIQUE_ELEMENT_IDS, uniqueElementIds);
4471 }
4472 else {
4473 int i = 1;
4474
4475 while (uniqueElementIds.contains(
4476 namespace.concat(uniqueElementId))) {
4477
4478 if (Validator.isNull(elementId) ||
4479 elementId.endsWith(StringPool.UNDERLINE)) {
4480
4481 uniqueElementId = elementId.concat(String.valueOf(i));
4482 }
4483 else {
4484 uniqueElementId =
4485 elementId.concat(StringPool.UNDERLINE).concat(
4486 String.valueOf(i));
4487 }
4488
4489 i++;
4490 }
4491 }
4492
4493 uniqueElementIds.add(namespace.concat(uniqueElementId));
4494
4495 return uniqueElementId;
4496 }
4497
4498 @Override
4499 public String getUniqueElementId(
4500 PortletRequest request, String namespace, String elementId) {
4501
4502 return getUniqueElementId(
4503 getHttpServletRequest(request), namespace, elementId);
4504 }
4505
4506 @Override
4507 public UploadPortletRequest getUploadPortletRequest(
4508 PortletRequest portletRequest) {
4509
4510 PortletRequestImpl portletRequestImpl =
4511 PortletRequestImpl.getPortletRequestImpl(portletRequest);
4512
4513 DynamicServletRequest dynamicRequest =
4514 (DynamicServletRequest)portletRequestImpl.getHttpServletRequest();
4515
4516 HttpServletRequestWrapper requestWrapper =
4517 (HttpServletRequestWrapper)dynamicRequest.getRequest();
4518
4519 UploadServletRequest uploadServletRequest = getUploadServletRequest(
4520 requestWrapper);
4521
4522 return new UploadPortletRequestImpl(
4523 uploadServletRequest,
4524 getPortletNamespace(portletRequestImpl.getPortletName()));
4525 }
4526
4527 @Override
4528 public UploadServletRequest getUploadServletRequest(
4529 HttpServletRequest request) {
4530
4531 HttpServletRequestWrapper requestWrapper = null;
4532
4533 if (request instanceof HttpServletRequestWrapper) {
4534 requestWrapper = (HttpServletRequestWrapper)request;
4535 }
4536
4537 UploadServletRequest uploadServletRequest = null;
4538
4539 while (uploadServletRequest == null) {
4540
4541
4542
4543
4544 if (requestWrapper instanceof UploadServletRequest) {
4545 uploadServletRequest = (UploadServletRequest)requestWrapper;
4546 }
4547 else {
4548 HttpServletRequest parentRequest =
4549 (HttpServletRequest)requestWrapper.getRequest();
4550
4551 if (!(parentRequest instanceof HttpServletRequestWrapper)) {
4552
4553
4554
4555
4556 if (ServerDetector.isWebLogic()) {
4557 if (requestWrapper instanceof
4558 NonSerializableObjectRequestWrapper) {
4559
4560 parentRequest = requestWrapper;
4561 }
4562 else {
4563 parentRequest =
4564 new NonSerializableObjectRequestWrapper(
4565 parentRequest);
4566 }
4567 }
4568
4569 uploadServletRequest = new UploadServletRequestImpl(
4570 parentRequest);
4571
4572 break;
4573 }
4574 else {
4575 requestWrapper = (HttpServletRequestWrapper)parentRequest;
4576 }
4577 }
4578 }
4579
4580 return uploadServletRequest;
4581 }
4582
4583 @Override
4584 public Date getUptime() {
4585 return _upTime;
4586 }
4587
4588 @Override
4589 public String getURLWithSessionId(String url, String sessionId) {
4590 if (!PropsValues.SESSION_ENABLE_URL_WITH_SESSION_ID) {
4591 return url;
4592 }
4593
4594 if (Validator.isNull(url)) {
4595 return url;
4596 }
4597
4598
4599
4600 int x = url.indexOf(CharPool.SEMICOLON);
4601
4602 if (x != -1) {
4603 return url;
4604 }
4605
4606 x = url.indexOf(CharPool.QUESTION);
4607
4608 if (x != -1) {
4609 StringBundler sb = new StringBundler(4);
4610
4611 sb.append(url.substring(0, x));
4612 sb.append(_JSESSIONID);
4613 sb.append(sessionId);
4614 sb.append(url.substring(x));
4615
4616 return sb.toString();
4617 }
4618
4619
4620
4621
4622 x = url.indexOf(StringPool.DOUBLE_SLASH);
4623
4624 StringBundler sb = new StringBundler(4);
4625
4626 sb.append(url);
4627
4628 if (x != -1) {
4629 int y = url.lastIndexOf(CharPool.SLASH);
4630
4631 if ((x + 1) == y) {
4632 sb.append(StringPool.SLASH);
4633 }
4634 }
4635
4636 sb.append(_JSESSIONID);
4637 sb.append(sessionId);
4638
4639 return sb.toString();
4640 }
4641
4642 @Override
4643 public User getUser(HttpServletRequest request)
4644 throws PortalException, SystemException {
4645
4646 User user = (User)request.getAttribute(WebKeys.USER);
4647
4648 if (user != null) {
4649 return user;
4650 }
4651
4652 long userId = getUserId(request);
4653
4654 if (userId <= 0) {
4655
4656
4657
4658
4659
4660
4661 String remoteUser = request.getRemoteUser();
4662
4663 if (remoteUser == null) {
4664 return null;
4665 }
4666
4667 userId = GetterUtil.getLong(remoteUser);
4668 }
4669
4670 if (userId > 0) {
4671 user = UserLocalServiceUtil.getUserById(userId);
4672
4673 request.setAttribute(WebKeys.USER, user);
4674 }
4675
4676 return user;
4677 }
4678
4679 @Override
4680 public User getUser(PortletRequest portletRequest)
4681 throws PortalException, SystemException {
4682
4683 return getUser(getHttpServletRequest(portletRequest));
4684 }
4685
4686 @Override
4687 public String getUserEmailAddress(long userId) throws SystemException {
4688 try {
4689 User user = UserLocalServiceUtil.getUserById(userId);
4690
4691 return user.getEmailAddress();
4692 }
4693 catch (PortalException pe) {
4694 return StringPool.BLANK;
4695 }
4696 }
4697
4698 @Override
4699 public long getUserId(HttpServletRequest request) {
4700 Long userIdObj = (Long)request.getAttribute(WebKeys.USER_ID);
4701
4702 if (userIdObj != null) {
4703 return userIdObj.longValue();
4704 }
4705
4706 String path = GetterUtil.getString(request.getPathInfo());
4707 String strutsAction = getStrutsAction(request);
4708 String actionName = getPortletParam(request, "actionName");
4709
4710 boolean alwaysAllowDoAsUser = false;
4711
4712 if (path.equals("/portal/session_click") ||
4713 strutsAction.equals("/document_library/edit_file_entry") ||
4714 strutsAction.equals("/document_library_display/edit_file_entry") ||
4715 strutsAction.equals("/image_gallery_display/edit_file_entry") ||
4716 strutsAction.equals("/image_gallery_display/edit_image") ||
4717 strutsAction.equals("/wiki/edit_page_attachment") ||
4718 strutsAction.equals("/wiki_admin/edit_page_attachment") ||
4719 strutsAction.equals("/wiki_display/edit_page_attachment") ||
4720 actionName.equals("addFile")) {
4721
4722 try {
4723 alwaysAllowDoAsUser = isAlwaysAllowDoAsUser(request);
4724 }
4725 catch (Exception e) {
4726 _log.error(e, e);
4727 }
4728 }
4729
4730 if ((!PropsValues.PORTAL_JAAS_ENABLE &&
4731 PropsValues.PORTAL_IMPERSONATION_ENABLE) ||
4732 alwaysAllowDoAsUser) {
4733
4734 String doAsUserIdString = ParamUtil.getString(
4735 request, "doAsUserId");
4736
4737 try {
4738 long doAsUserId = getDoAsUserId(
4739 request, doAsUserIdString, alwaysAllowDoAsUser);
4740
4741 if (doAsUserId > 0) {
4742 if (_log.isDebugEnabled()) {
4743 _log.debug("Impersonating user " + doAsUserId);
4744 }
4745
4746 return doAsUserId;
4747 }
4748 }
4749 catch (Exception e) {
4750 _log.error("Unable to impersonate user " + doAsUserIdString, e);
4751 }
4752 }
4753
4754 HttpSession session = request.getSession();
4755
4756 userIdObj = (Long)session.getAttribute(WebKeys.USER_ID);
4757
4758 if (userIdObj != null) {
4759 request.setAttribute(WebKeys.USER_ID, userIdObj);
4760
4761 return userIdObj.longValue();
4762 }
4763 else {
4764 return 0;
4765 }
4766 }
4767
4768 @Override
4769 public long getUserId(PortletRequest portletRequest) {
4770 return getUserId(getHttpServletRequest(portletRequest));
4771 }
4772
4773 @Override
4774 public String getUserName(BaseModel<?> baseModel) {
4775 long userId = 0;
4776 String userName = StringPool.BLANK;
4777
4778 if (baseModel instanceof AuditedModel) {
4779 AuditedModel auditedModel = (AuditedModel)baseModel;
4780
4781 userId = auditedModel.getUserId();
4782 userName = auditedModel.getUserName();
4783 }
4784 else {
4785 userId = BeanPropertiesUtil.getLongSilent(baseModel, "userId");
4786 userName = BeanPropertiesUtil.getStringSilent(
4787 baseModel, "userName");
4788 }
4789
4790 if (userId == 0) {
4791 return StringPool.BLANK;
4792 }
4793
4794 if (baseModel.isEscapedModel()) {
4795 userName = HtmlUtil.unescape(userName);
4796 }
4797
4798 userName = getUserName(userId, userName);
4799
4800 if (baseModel.isEscapedModel()) {
4801 userName = HtmlUtil.escape(userName);
4802 }
4803
4804 return userName;
4805 }
4806
4807 @Override
4808 public String getUserName(long userId, String defaultUserName) {
4809 return getUserName(
4810 userId, defaultUserName, UserAttributes.USER_NAME_FULL);
4811 }
4812
4813 @Override
4814 public String getUserName(
4815 long userId, String defaultUserName, HttpServletRequest request) {
4816
4817 return getUserName(
4818 userId, defaultUserName, UserAttributes.USER_NAME_FULL, request);
4819 }
4820
4821 @Override
4822 public String getUserName(
4823 long userId, String defaultUserName, String userAttribute) {
4824
4825 return getUserName(userId, defaultUserName, userAttribute, null);
4826 }
4827
4828 @Override
4829 public String getUserName(
4830 long userId, String defaultUserName, String userAttribute,
4831 HttpServletRequest request) {
4832
4833 String userName = defaultUserName;
4834
4835 try {
4836 User user = UserLocalServiceUtil.getUserById(userId);
4837
4838 if (userAttribute.equals(UserAttributes.USER_NAME_FULL)) {
4839 userName = user.getFullName();
4840 }
4841 else {
4842 userName = user.getScreenName();
4843 }
4844
4845 if (request != null) {
4846 Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
4847
4848 PortletURL portletURL = new PortletURLImpl(
4849 request, PortletKeys.DIRECTORY, layout.getPlid(),
4850 PortletRequest.RENDER_PHASE);
4851
4852 portletURL.setWindowState(WindowState.MAXIMIZED);
4853 portletURL.setPortletMode(PortletMode.VIEW);
4854
4855 portletURL.setParameter(
4856 "struts_action", "/directory/view_user");
4857 portletURL.setParameter(
4858 "p_u_i_d", String.valueOf(user.getUserId()));
4859
4860 userName =
4861 "<a href=\"" + portletURL.toString() + "\">" +
4862 HtmlUtil.escape(userName) + "</a>";
4863 }
4864 }
4865 catch (Exception e) {
4866 }
4867
4868 return userName;
4869 }
4870
4871 @Override
4872 public String getUserPassword(HttpServletRequest request) {
4873 HttpSession session = request.getSession();
4874
4875 return getUserPassword(session);
4876 }
4877
4878 @Override
4879 public String getUserPassword(HttpSession session) {
4880 return (String)session.getAttribute(WebKeys.USER_PASSWORD);
4881 }
4882
4883 @Override
4884 public String getUserPassword(PortletRequest portletRequest) {
4885 return getUserPassword(getHttpServletRequest(portletRequest));
4886 }
4887
4888 @Override
4889 public String getUserValue(long userId, String param, String defaultValue)
4890 throws SystemException {
4891
4892 if (Validator.isNotNull(defaultValue)) {
4893 return defaultValue;
4894 }
4895 else {
4896 try {
4897 User user = UserLocalServiceUtil.getUserById(userId);
4898
4899 return BeanPropertiesUtil.getString(user, param, defaultValue);
4900 }
4901 catch (PortalException pe) {
4902 return StringPool.BLANK;
4903 }
4904 }
4905 }
4906
4907 @Override
4908 public long getValidUserId(long companyId, long userId)
4909 throws PortalException, SystemException {
4910
4911 try {
4912 User user = UserLocalServiceUtil.getUser(userId);
4913
4914 if (user.getCompanyId() == companyId) {
4915 return user.getUserId();
4916 }
4917 else {
4918 return userId;
4919 }
4920 }
4921 catch (NoSuchUserException nsue) {
4922 return UserLocalServiceUtil.getDefaultUserId(companyId);
4923 }
4924 }
4925
4926 @Override
4927 public String getVirtualLayoutActualURL(
4928 long groupId, boolean privateLayout, String mainPath,
4929 String friendlyURL, Map<String, String[]> params,
4930 Map<String, Object> requestContext)
4931 throws PortalException, SystemException {
4932
4933
4934
4935 String groupFriendlyURL = null;
4936
4937 int pos = friendlyURL.indexOf(CharPool.SLASH, 3);
4938
4939 if (pos != -1) {
4940 groupFriendlyURL = friendlyURL.substring(2, pos);
4941 }
4942
4943 if (Validator.isNull(groupFriendlyURL)) {
4944 return mainPath;
4945 }
4946
4947 HttpServletRequest request = (HttpServletRequest)requestContext.get(
4948 "request");
4949
4950 long companyId = PortalInstances.getCompanyId(request);
4951
4952 Group group = GroupLocalServiceUtil.fetchFriendlyURLGroup(
4953 companyId, groupFriendlyURL);
4954
4955 if (group == null) {
4956 return mainPath;
4957 }
4958
4959
4960
4961 String layoutFriendlyURL = null;
4962
4963 if ((pos != -1) && ((pos + 1) != friendlyURL.length())) {
4964 layoutFriendlyURL = friendlyURL.substring(pos);
4965 }
4966
4967 if (Validator.isNull(layoutFriendlyURL)) {
4968 return mainPath;
4969 }
4970
4971 String actualURL = getActualURL(
4972 group.getGroupId(), privateLayout, mainPath, layoutFriendlyURL,
4973 params, requestContext);
4974
4975 return HttpUtil.addParameter(
4976 HttpUtil.removeParameter(actualURL, "p_v_l_s_g_id"), "p_v_l_s_g_id",
4977 groupId);
4978 }
4979
4980 @Override
4981 public String getWidgetURL(Portlet portlet, ThemeDisplay themeDisplay)
4982 throws PortalException, SystemException {
4983
4984 return getServletURL(
4985 portlet, PropsValues.WIDGET_SERVLET_MAPPING, themeDisplay);
4986 }
4987
4988 @Override
4989 public void initCustomSQL() {
4990 _customSqlKeys = new String[] {
4991 "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.GROUP$]",
4992 "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.LAYOUT$]",
4993 "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.ORGANIZATION$]",
4994 "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.ROLE$]",
4995 "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USER$]",
4996 "[$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.USERGROUP$]",
4997 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BLOGS.MODEL.BLOGSENTRY$]",
4998 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.BOOKMARKS.MODEL." +
4999 "BOOKMARKSENTRY$]",
5000 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.CALENDAR.MODEL.CALEVENT$]",
5001 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.DOCUMENTLIBRARY.MODEL." +
5002 "DLFILEENTRY$]",
5003 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.MESSAGEBOARDS.MODEL." +
5004 "MBMESSAGE$]",
5005 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.MESSAGEBOARDS.MODEL." +
5006 "MBTHREAD$]",
5007 "[$CLASS_NAME_ID_COM.LIFERAY.PORTLET.WIKI.MODEL.WIKIPAGE$]",
5008 "[$RESOURCE_SCOPE_COMPANY$]", "[$RESOURCE_SCOPE_GROUP$]",
5009 "[$RESOURCE_SCOPE_GROUP_TEMPLATE$]",
5010 "[$RESOURCE_SCOPE_INDIVIDUAL$]",
5011 "[$SOCIAL_RELATION_TYPE_BI_COWORKER$]",
5012 "[$SOCIAL_RELATION_TYPE_BI_FRIEND$]",
5013 "[$SOCIAL_RELATION_TYPE_BI_ROMANTIC_PARTNER$]",
5014 "[$SOCIAL_RELATION_TYPE_BI_SIBLING$]",
5015 "[$SOCIAL_RELATION_TYPE_BI_SPOUSE$]",
5016 "[$SOCIAL_RELATION_TYPE_UNI_CHILD$]",
5017 "[$SOCIAL_RELATION_TYPE_UNI_ENEMY$]",
5018 "[$SOCIAL_RELATION_TYPE_UNI_FOLLOWER$]",
5019 "[$SOCIAL_RELATION_TYPE_UNI_PARENT$]",
5020 "[$SOCIAL_RELATION_TYPE_UNI_SUBORDINATE$]",
5021 "[$SOCIAL_RELATION_TYPE_UNI_SUPERVISOR$]", "[$FALSE$]", "[$TRUE$]"
5022 };
5023
5024 DB db = DBFactoryUtil.getDB();
5025
5026 Object[] customSqlValues = new Object[] {
5027 getClassNameId(Group.class), getClassNameId(Layout.class),
5028 getClassNameId(Organization.class), getClassNameId(Role.class),
5029 getClassNameId(User.class), getClassNameId(UserGroup.class),
5030 getClassNameId(BlogsEntry.class),
5031 getClassNameId(BookmarksEntry.class),
5032 getClassNameId(CalEvent.class), getClassNameId(DLFileEntry.class),
5033 getClassNameId(MBMessage.class), getClassNameId(MBThread.class),
5034 getClassNameId(WikiPage.class), ResourceConstants.SCOPE_COMPANY,
5035 ResourceConstants.SCOPE_GROUP,
5036 ResourceConstants.SCOPE_GROUP_TEMPLATE,
5037 ResourceConstants.SCOPE_INDIVIDUAL,
5038 SocialRelationConstants.TYPE_BI_COWORKER,
5039 SocialRelationConstants.TYPE_BI_FRIEND,
5040 SocialRelationConstants.TYPE_BI_ROMANTIC_PARTNER,
5041 SocialRelationConstants.TYPE_BI_SIBLING,
5042 SocialRelationConstants.TYPE_BI_SPOUSE,
5043 SocialRelationConstants.TYPE_UNI_CHILD,
5044 SocialRelationConstants.TYPE_UNI_ENEMY,
5045 SocialRelationConstants.TYPE_UNI_FOLLOWER,
5046 SocialRelationConstants.TYPE_UNI_PARENT,
5047 SocialRelationConstants.TYPE_UNI_SUBORDINATE,
5048 SocialRelationConstants.TYPE_UNI_SUPERVISOR, db.getTemplateFalse(),
5049 db.getTemplateTrue()
5050 };
5051
5052 _customSqlValues = ArrayUtil.toStringArray(customSqlValues);
5053 }
5054
5055 @Override
5056 public User initUser(HttpServletRequest request) throws Exception {
5057 User user = null;
5058
5059 try {
5060 user = getUser(request);
5061 }
5062 catch (NoSuchUserException nsue) {
5063 if (_log.isWarnEnabled()) {
5064 _log.warn(nsue.getMessage());
5065 }
5066
5067 long userId = getUserId(request);
5068
5069 if (userId > 0) {
5070 HttpSession session = request.getSession();
5071
5072 session.invalidate();
5073 }
5074
5075 throw nsue;
5076 }
5077
5078 if (user != null) {
5079 return user;
5080 }
5081
5082 Company company = getCompany(request);
5083
5084 return company.getDefaultUser();
5085 }
5086
5087 @Override
5088 public boolean isAllowAddPortletDefaultResource(
5089 HttpServletRequest request, Portlet portlet)
5090 throws PortalException, SystemException {
5091
5092 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
5093 WebKeys.THEME_DISPLAY);
5094
5095 Layout layout = themeDisplay.getLayout();
5096 LayoutTypePortlet layoutTypePortlet =
5097 themeDisplay.getLayoutTypePortlet();
5098
5099 String portletId = portlet.getPortletId();
5100
5101 Boolean renderPortletResource = (Boolean)request.getAttribute(
5102 WebKeys.RENDER_PORTLET_RESOURCE);
5103
5104 if (renderPortletResource != null) {
5105 boolean runtimePortlet = renderPortletResource.booleanValue();
5106
5107 if (runtimePortlet) {
5108 return true;
5109 }
5110 }
5111
5112 if (layout.isTypePanel() &&
5113 isPanelSelectedPortlet(themeDisplay, portletId)) {
5114
5115 return true;
5116 }
5117
5118 if (layout.isTypeControlPanel() &&
5119 isControlPanelPortlet(portletId, themeDisplay)) {
5120
5121 return true;
5122 }
5123
5124 if (layout.isTypePortlet()) {
5125 if (layoutTypePortlet.hasPortletId(portletId)) {
5126 return true;
5127 }
5128
5129 if (hasPortletDefaultResource(themeDisplay, layout, portlet)) {
5130 return true;
5131 }
5132 }
5133
5134 if (themeDisplay.isSignedIn() &&
5135 (portletId.equals(PortletKeys.LAYOUT_CONFIGURATION) ||
5136 portletId.equals(PortletKeys.LAYOUTS_ADMIN))) {
5137
5138 PermissionChecker permissionChecker =
5139 themeDisplay.getPermissionChecker();
5140
5141 Group group = layout.getGroup();
5142
5143 if (group.isSite()) {
5144 if (LayoutPermissionUtil.contains(
5145 permissionChecker, layout, ActionKeys.CUSTOMIZE) ||
5146 LayoutPermissionUtil.contains(
5147 permissionChecker, layout, ActionKeys.UPDATE)) {
5148
5149 return true;
5150 }
5151 }
5152
5153 if (group.isCompany()) {
5154 if (permissionChecker.isCompanyAdmin()) {
5155 return true;
5156 }
5157 }
5158 else if (group.isLayoutPrototype()) {
5159 long layoutPrototypeId = group.getClassPK();
5160
5161 if (LayoutPrototypePermissionUtil.contains(
5162 permissionChecker, layoutPrototypeId,
5163 ActionKeys.UPDATE)) {
5164
5165 return true;
5166 }
5167 }
5168 else if (group.isLayoutSetPrototype()) {
5169 long layoutSetPrototypeId = group.getClassPK();
5170
5171 if (LayoutSetPrototypePermissionUtil.contains(
5172 permissionChecker, layoutSetPrototypeId,
5173 ActionKeys.UPDATE)) {
5174
5175 return true;
5176 }
5177 }
5178 else if (group.isOrganization()) {
5179 long organizationId = group.getOrganizationId();
5180
5181 if (OrganizationPermissionUtil.contains(
5182 permissionChecker, organizationId, ActionKeys.UPDATE)) {
5183
5184 return true;
5185 }
5186 }
5187 else if (group.isUserGroup()) {
5188 long scopeGroupId = themeDisplay.getScopeGroupId();
5189
5190 if (GroupPermissionUtil.contains(
5191 permissionChecker, scopeGroupId, ActionKeys.UPDATE)) {
5192
5193 return true;
5194 }
5195 }
5196 else if (group.isUser()) {
5197 return true;
5198 }
5199 }
5200
5201 if (!portlet.isAddDefaultResource()) {
5202 return false;
5203 }
5204
5205 if (!PropsValues.PORTLET_ADD_DEFAULT_RESOURCE_CHECK_ENABLED) {
5206 return true;
5207 }
5208
5209 if (_portletAddDefaultResourceCheckWhitelist.contains(portletId)) {
5210 return true;
5211 }
5212
5213 String namespace = getPortletNamespace(portletId);
5214
5215 String strutsAction = ParamUtil.getString(
5216 request, namespace + "struts_action");
5217
5218 if (Validator.isNull(strutsAction)) {
5219 strutsAction = ParamUtil.getString(request, "struts_action");
5220 }
5221
5222 if (_portletAddDefaultResourceCheckWhitelistActions.contains(
5223 strutsAction)) {
5224
5225 return true;
5226 }
5227
5228 String requestPortletAuthenticationToken = ParamUtil.getString(
5229 request, "p_p_auth");
5230
5231 if (Validator.isNull(requestPortletAuthenticationToken)) {
5232 HttpServletRequest originalRequest = getOriginalServletRequest(
5233 request);
5234
5235 requestPortletAuthenticationToken = ParamUtil.getString(
5236 originalRequest, "p_p_auth");
5237 }
5238
5239 if (Validator.isNotNull(requestPortletAuthenticationToken)) {
5240 String actualPortletAuthenticationToken = AuthTokenUtil.getToken(
5241 request, layout.getPlid(), portletId);
5242
5243 if (requestPortletAuthenticationToken.equals(
5244 actualPortletAuthenticationToken)) {
5245
5246 return true;
5247 }
5248 }
5249
5250 return false;
5251 }
5252
5253 @Override
5254 public boolean isCDNDynamicResourcesEnabled(HttpServletRequest request)
5255 throws PortalException, SystemException {
5256
5257 Company company = getCompany(request);
5258
5259 return isCDNDynamicResourcesEnabled(company.getCompanyId());
5260 }
5261
5262 @Override
5263 public boolean isCDNDynamicResourcesEnabled(long companyId) {
5264 try {
5265 return PrefsPropsUtil.getBoolean(
5266 companyId, PropsKeys.CDN_DYNAMIC_RESOURCES_ENABLED,
5267 PropsValues.CDN_DYNAMIC_RESOURCES_ENABLED);
5268 }
5269 catch (SystemException se) {
5270 }
5271
5272 return PropsValues.CDN_DYNAMIC_RESOURCES_ENABLED;
5273 }
5274
5275
5278 @Override
5279 public boolean isCommunityAdmin(User user, long groupId) throws Exception {
5280 return isGroupAdmin(user, groupId);
5281 }
5282
5283
5286 @Override
5287 public boolean isCommunityOwner(User user, long groupId) throws Exception {
5288 return isGroupOwner(user, groupId);
5289 }
5290
5291 @Override
5292 public boolean isCompanyAdmin(User user) throws Exception {
5293 PermissionChecker permissionChecker =
5294 PermissionCheckerFactoryUtil.create(user);
5295
5296 return permissionChecker.isCompanyAdmin();
5297 }
5298
5299 @Override
5300 public boolean isCompanyControlPanelPortlet(
5301 String portletId, String category, ThemeDisplay themeDisplay)
5302 throws PortalException, SystemException {
5303
5304 PermissionChecker permissionChecker =
5305 themeDisplay.getPermissionChecker();
5306
5307 if (permissionChecker.isCompanyAdmin()) {
5308 return true;
5309 }
5310
5311 Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(
5312 themeDisplay.getCompanyId());
5313
5314 themeDisplay.setScopeGroupId(companyGroup.getGroupId());
5315
5316 return isControlPanelPortlet(portletId, category, themeDisplay);
5317 }
5318
5319 @Override
5320 public boolean isCompanyControlPanelPortlet(
5321 String portletId, ThemeDisplay themeDisplay)
5322 throws PortalException, SystemException {
5323
5324 PermissionChecker permissionChecker =
5325 themeDisplay.getPermissionChecker();
5326
5327 if (permissionChecker.isCompanyAdmin()) {
5328 return true;
5329 }
5330
5331 Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(
5332 themeDisplay.getCompanyId());
5333
5334 themeDisplay.setScopeGroupId(companyGroup.getGroupId());
5335
5336 return isControlPanelPortlet(portletId, themeDisplay);
5337 }
5338
5339 @Override
5340 public boolean isCompanyControlPanelVisible(ThemeDisplay themeDisplay)
5341 throws PortalException, SystemException {
5342
5343 PermissionChecker permissionChecker =
5344 themeDisplay.getPermissionChecker();
5345
5346 if (permissionChecker.isCompanyAdmin()) {
5347 return true;
5348 }
5349
5350 long scopeGroupId = themeDisplay.getScopeGroupId();
5351
5352 try {
5353 Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(
5354 themeDisplay.getCompanyId());
5355
5356 themeDisplay.setScopeGroupId(companyGroup.getGroupId());
5357
5358 List<Portlet> controlPanelPortlets = getControlPanelPortlets(
5359 PortletCategoryKeys.CONTENT, themeDisplay);
5360
5361 if (!controlPanelPortlets.isEmpty()) {
5362 return true;
5363 }
5364 else {
5365 return false;
5366 }
5367 }
5368 finally {
5369 themeDisplay.setScopeGroupId(scopeGroupId);
5370 }
5371 }
5372
5373 @Override
5374 public boolean isControlPanelPortlet(
5375 String portletId, String category, ThemeDisplay themeDisplay)
5376 throws SystemException {
5377
5378 List<Portlet> portlets = getControlPanelPortlets(
5379 category, themeDisplay);
5380
5381 for (Portlet portlet : portlets) {
5382 if (portlet.getPortletId().equals(portletId)) {
5383 return true;
5384 }
5385 }
5386
5387 return false;
5388 }
5389
5390 @Override
5391 public boolean isControlPanelPortlet(
5392 String portletId, ThemeDisplay themeDisplay)
5393 throws SystemException {
5394
5395 for (String category : PortletCategoryKeys.ALL) {
5396 if (isControlPanelPortlet(portletId, category, themeDisplay)) {
5397 return true;
5398 }
5399 }
5400
5401 return false;
5402 }
5403
5404 @Override
5405 public boolean isGroupAdmin(User user, long groupId) throws Exception {
5406 PermissionChecker permissionChecker =
5407 PermissionCheckerFactoryUtil.create(user);
5408
5409 return permissionChecker.isGroupAdmin(groupId);
5410 }
5411
5412 @Override
5413 public boolean isGroupFriendlyURL(
5414 String fullURL, String groupFriendlyURL, String layoutFriendlyURL) {
5415
5416 if (fullURL.endsWith(groupFriendlyURL) &&
5417 !fullURL.endsWith(groupFriendlyURL.concat(layoutFriendlyURL))) {
5418
5419 return true;
5420 }
5421
5422 return false;
5423 }
5424
5425 @Override
5426 public boolean isGroupOwner(User user, long groupId) throws Exception {
5427 PermissionChecker permissionChecker =
5428 PermissionCheckerFactoryUtil.create(user);
5429
5430 return permissionChecker.isGroupOwner(groupId);
5431 }
5432
5433 @Override
5434 public boolean isLayoutDescendant(Layout layout, long layoutId)
5435 throws PortalException, SystemException {
5436
5437 if (layout.getLayoutId() == layoutId) {
5438 return true;
5439 }
5440 else {
5441 for (Layout childLayout : layout.getChildren()) {
5442 if (isLayoutDescendant(childLayout, layoutId)) {
5443 return true;
5444 }
5445 }
5446
5447 return false;
5448 }
5449 }
5450
5451 @Override
5452 public boolean isLayoutFirstPageable(Layout layout) {
5453 LayoutSettings layoutSettings = LayoutSettings.getInstance(layout);
5454
5455 return layoutSettings.isFirstPageable();
5456 }
5457
5458 @Override
5459 public boolean isLayoutFirstPageable(String type) {
5460 LayoutSettings layoutSettings = LayoutSettings.getInstance(type);
5461
5462 return layoutSettings.isFirstPageable();
5463 }
5464
5465 @Override
5466 public boolean isLayoutFriendliable(Layout layout) {
5467 LayoutSettings layoutSettings = LayoutSettings.getInstance(layout);
5468
5469 return layoutSettings.isURLFriendliable();
5470 }
5471
5472 @Override
5473 public boolean isLayoutFriendliable(String type) {
5474 LayoutSettings layoutSettings = LayoutSettings.getInstance(type);
5475
5476 return layoutSettings.isURLFriendliable();
5477 }
5478
5479 @Override
5480 public boolean isLayoutParentable(Layout layout) {
5481 return isLayoutParentable(layout.getType());
5482 }
5483
5484 @Override
5485 public boolean isLayoutParentable(String type) {
5486 LayoutSettings layoutSettings = LayoutSettings.getInstance(type);
5487
5488 return layoutSettings.isParentable();
5489 }
5490
5491 @Override
5492 public boolean isLayoutSitemapable(Layout layout) {
5493 if (layout.isPrivateLayout()) {
5494 return false;
5495 }
5496
5497 LayoutSettings layoutSettings = LayoutSettings.getInstance(layout);
5498
5499 return layoutSettings.isSitemapable();
5500 }
5501
5502 @Override
5503 public boolean isMethodGet(PortletRequest portletRequest) {
5504 HttpServletRequest request = getHttpServletRequest(portletRequest);
5505
5506 String method = GetterUtil.getString(request.getMethod());
5507
5508 if (method.equalsIgnoreCase(HttpMethods.GET)) {
5509 return true;
5510 }
5511 else {
5512 return false;
5513 }
5514 }
5515
5516 @Override
5517 public boolean isMethodPost(PortletRequest portletRequest) {
5518 HttpServletRequest request = getHttpServletRequest(portletRequest);
5519
5520 String method = GetterUtil.getString(request.getMethod());
5521
5522 if (method.equalsIgnoreCase(HttpMethods.POST)) {
5523 return true;
5524 }
5525 else {
5526 return false;
5527 }
5528 }
5529
5530 @Override
5531 public boolean isMultipartRequest(HttpServletRequest request) {
5532 String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE);
5533
5534 if ((contentType != null) &&
5535 contentType.startsWith(ContentTypes.MULTIPART_FORM_DATA)) {
5536
5537 return true;
5538 }
5539 else {
5540 return false;
5541 }
5542 }
5543
5544 @Override
5545 public boolean isOmniadmin(long userId) {
5546 return OmniadminUtil.isOmniadmin(userId);
5547 }
5548
5549 @Override
5550 public boolean isReservedParameter(String name) {
5551 return _reservedParams.contains(name);
5552 }
5553
5554 @Override
5555 public boolean isSecure(HttpServletRequest request) {
5556 HttpSession session = request.getSession();
5557
5558 if (session == null) {
5559 return request.isSecure();
5560 }
5561
5562 Boolean httpsInitial = (Boolean)session.getAttribute(
5563 WebKeys.HTTPS_INITIAL);
5564
5565 boolean secure = false;
5566
5567 if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS &&
5568 !PropsValues.SESSION_ENABLE_PHISHING_PROTECTION &&
5569 (httpsInitial != null) && !httpsInitial.booleanValue()) {
5570
5571 secure = false;
5572 }
5573 else {
5574 secure = request.isSecure();
5575 }
5576
5577 return secure;
5578 }
5579
5580 @Override
5581 public boolean isSystemGroup(String groupName) {
5582 if (groupName == null) {
5583 return false;
5584 }
5585
5586 groupName = groupName.trim();
5587
5588 int pos = Arrays.binarySearch(
5589 _sortedSystemGroups, groupName, new StringComparator());
5590
5591 if (pos >= 0) {
5592 return true;
5593 }
5594 else {
5595 return false;
5596 }
5597 }
5598
5599 @Override
5600 public boolean isSystemRole(String roleName) {
5601 if (roleName == null) {
5602 return false;
5603 }
5604
5605 roleName = roleName.trim();
5606
5607 int pos = Arrays.binarySearch(
5608 _sortedSystemRoles, roleName, new StringComparator());
5609
5610 if (pos >= 0) {
5611 return true;
5612 }
5613 else {
5614 pos = Arrays.binarySearch(
5615 _sortedSystemSiteRoles, roleName, new StringComparator());
5616
5617 if (pos >= 0) {
5618 return true;
5619 }
5620 else {
5621 pos = Arrays.binarySearch(
5622 _sortedSystemOrganizationRoles, roleName,
5623 new StringComparator());
5624
5625 if (pos >= 0) {
5626 return true;
5627 }
5628 }
5629 }
5630
5631 return false;
5632 }
5633
5634 @Override
5635 public boolean isUpdateAvailable() throws SystemException {
5636 return PluginPackageUtil.isUpdateAvailable();
5637 }
5638
5639 @Override
5640 public boolean isValidResourceId(String resourceId) {
5641 if (Validator.isNull(resourceId)) {
5642 return true;
5643 }
5644
5645 Matcher matcher = _bannedResourceIdPattern.matcher(resourceId);
5646
5647 if (matcher.matches()) {
5648 return false;
5649 }
5650
5651 return true;
5652 }
5653
5654 @Override
5655 public void removePortalPortEventListener(
5656 PortalPortEventListener portalPortEventListener) {
5657
5658 _portalPortEventListeners.remove(portalPortEventListener);
5659 }
5660
5661 @Override
5662 public String renderPage(
5663 ServletContext servletContext, HttpServletRequest request,
5664 HttpServletResponse response, String path)
5665 throws IOException, ServletException {
5666
5667 RequestDispatcher requestDispatcher =
5668 servletContext.getRequestDispatcher(path);
5669
5670 StringServletResponse stringResponse = new StringServletResponse(
5671 response);
5672
5673 requestDispatcher.include(request, stringResponse);
5674
5675 return stringResponse.getString();
5676 }
5677
5678 @Override
5679 public String renderPortlet(
5680 ServletContext servletContext, HttpServletRequest request,
5681 HttpServletResponse response, Portlet portlet, String queryString,
5682 boolean writeOutput)
5683 throws IOException, ServletException {
5684
5685 return renderPortlet(
5686 servletContext, request, response, portlet, queryString, null, null,
5687 null, writeOutput);
5688 }
5689
5690 @Override
5691 public String renderPortlet(
5692 ServletContext servletContext, HttpServletRequest request,
5693 HttpServletResponse response, Portlet portlet, String queryString,
5694 String columnId, Integer columnPos, Integer columnCount,
5695 boolean writeOutput)
5696 throws IOException, ServletException {
5697
5698 return renderPortlet(
5699 servletContext, request, response, portlet, queryString, columnId,
5700 columnPos, columnCount, null, writeOutput);
5701 }
5702
5703 @Override
5704 public String renderPortlet(
5705 ServletContext servletContext, HttpServletRequest request,
5706 HttpServletResponse response, Portlet portlet, String queryString,
5707 String columnId, Integer columnPos, Integer columnCount,
5708 String path, boolean writeOutput)
5709 throws IOException, ServletException {
5710
5711 queryString = GetterUtil.getString(queryString);
5712 columnId = GetterUtil.getString(columnId);
5713
5714 if (columnPos == null) {
5715 columnPos = Integer.valueOf(0);
5716 }
5717
5718 if (columnCount == null) {
5719 columnCount = Integer.valueOf(0);
5720 }
5721
5722 Portlet renderPortlet = (Portlet)request.getAttribute(
5723 WebKeys.RENDER_PORTLET);
5724
5725 RestrictPortletServletRequest restrictPortletServletRequest =
5726 new RestrictPortletServletRequest(request);
5727
5728 request = restrictPortletServletRequest;
5729
5730 request.setAttribute(WebKeys.RENDER_PORTLET, portlet);
5731 request.setAttribute(WebKeys.RENDER_PORTLET_QUERY_STRING, queryString);
5732 request.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_ID, columnId);
5733 request.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_POS, columnPos);
5734 request.setAttribute(WebKeys.RENDER_PORTLET_COLUMN_COUNT, columnCount);
5735
5736 if (path == null) {
5737 path = "/html/portal/render_portlet.jsp";
5738 }
5739
5740 RequestDispatcher requestDispatcher =
5741 DirectRequestDispatcherFactoryUtil.getRequestDispatcher(
5742 servletContext, path);
5743
5744 UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();
5745
5746 PipingServletResponse pipingServletResponse = new PipingServletResponse(
5747 response, unsyncStringWriter);
5748
5749 requestDispatcher.include(request, pipingServletResponse);
5750
5751 request.setAttribute(WebKeys.RENDER_PORTLET, renderPortlet);
5752
5753 boolean showPortlet = true;
5754
5755 Boolean portletConfiguratorVisibility = (Boolean)request.getAttribute(
5756 WebKeys.PORTLET_CONFIGURATOR_VISIBILITY);
5757
5758 if (portletConfiguratorVisibility != null) {
5759 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
5760 WebKeys.THEME_DISPLAY);
5761
5762 try {
5763 Layout layout = themeDisplay.getLayout();
5764
5765 if (!layout.isTypeControlPanel() &&
5766 !LayoutPermissionUtil.contains(
5767 themeDisplay.getPermissionChecker(), layout,
5768 ActionKeys.UPDATE) &&
5769 !PortletPermissionUtil.contains(
5770 themeDisplay.getPermissionChecker(), layout,
5771 portlet.getPortletId(), ActionKeys.CONFIGURATION)) {
5772
5773 showPortlet = false;
5774 }
5775 }
5776 catch (Exception e) {
5777 throw new ServletException(e);
5778 }
5779
5780 request.removeAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY);
5781 }
5782
5783 restrictPortletServletRequest.mergeSharedAttributes();
5784
5785 if (showPortlet) {
5786 if (writeOutput) {
5787 response.setContentType(ContentTypes.TEXT_HTML_UTF8);
5788
5789 StringBundler sb = unsyncStringWriter.getStringBundler();
5790
5791 sb.writeTo(response.getWriter());
5792
5793 return StringPool.BLANK;
5794 }
5795 else {
5796 return unsyncStringWriter.toString();
5797 }
5798 }
5799 else {
5800 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
5801
5802 return StringPool.BLANK;
5803 }
5804 }
5805
5806 @Override
5807 public void resetCDNHosts() {
5808 _cdnHostHttpMap.clear();
5809 _cdnHostHttpsMap.clear();
5810
5811 if (!ClusterInvokeThreadLocal.isEnabled()) {
5812 return;
5813 }
5814
5815 ClusterRequest clusterRequest = ClusterRequest.createMulticastRequest(
5816 _resetCDNHostsMethodHandler, true);
5817
5818 try {
5819 ClusterExecutorUtil.execute(clusterRequest);
5820 }
5821 catch (Exception e) {
5822 _log.error("Unable to clear cluster wide CDN hosts", e);
5823 }
5824 }
5825
5826 @Override
5827 public Set<String> resetPortletAddDefaultResourceCheckWhitelist() {
5828 _portletAddDefaultResourceCheckWhitelist = SetUtil.fromArray(
5829 PropsValues.PORTLET_ADD_DEFAULT_RESOURCE_CHECK_WHITELIST);
5830
5831 _portletAddDefaultResourceCheckWhitelist = Collections.unmodifiableSet(
5832 _portletAddDefaultResourceCheckWhitelist);
5833
5834 return _portletAddDefaultResourceCheckWhitelist;
5835 }
5836
5837 @Override
5838 public Set<String> resetPortletAddDefaultResourceCheckWhitelistActions() {
5839 _portletAddDefaultResourceCheckWhitelistActions = SetUtil.fromArray(
5840 PropsValues.PORTLET_ADD_DEFAULT_RESOURCE_CHECK_WHITELIST_ACTIONS);
5841
5842 _portletAddDefaultResourceCheckWhitelistActions =
5843 Collections.unmodifiableSet(
5844 _portletAddDefaultResourceCheckWhitelistActions);
5845
5846 return _portletAddDefaultResourceCheckWhitelistActions;
5847 }
5848
5849 @Override
5850 public void sendError(
5851 Exception e, ActionRequest actionRequest,
5852 ActionResponse actionResponse)
5853 throws IOException {
5854
5855 sendError(0, e, actionRequest, actionResponse);
5856 }
5857
5858 @Override
5859 public void sendError(
5860 Exception e, HttpServletRequest request,
5861 HttpServletResponse response)
5862 throws IOException, ServletException {
5863
5864 sendError(0, e, request, response);
5865 }
5866
5867 @Override
5868 public void sendError(
5869 int status, Exception e, ActionRequest actionRequest,
5870 ActionResponse actionResponse)
5871 throws IOException {
5872
5873 StringBundler sb = new StringBundler(7);
5874
5875 sb.append(_pathMain);
5876 sb.append("/portal/status?status=");
5877 sb.append(status);
5878 sb.append("&exception=");
5879 sb.append(e.getClass().getName());
5880 sb.append("&previousURL=");
5881 sb.append(HttpUtil.encodeURL(getCurrentURL(actionRequest)));
5882
5883 actionResponse.sendRedirect(sb.toString());
5884 }
5885
5886 @Override
5887 public void sendError(
5888 int status, Exception e, HttpServletRequest request,
5889 HttpServletResponse response)
5890 throws IOException, ServletException {
5891
5892 if (_log.isDebugEnabled()) {
5893 String currentURL = (String)request.getAttribute(
5894 WebKeys.CURRENT_URL);
5895
5896 _log.debug(
5897 "Current URL " + currentURL + " generates exception: " +
5898 e.getMessage());
5899 }
5900
5901 if (e instanceof NoSuchImageException) {
5902 if (_logWebServerServlet.isWarnEnabled()) {
5903 _logWebServerServlet.warn(e, e);
5904 }
5905 }
5906 else if ((e instanceof PortalException) && _log.isDebugEnabled()) {
5907 if ((e instanceof NoSuchLayoutException) ||
5908 (e instanceof PrincipalException)) {
5909
5910 String msg = e.getMessage();
5911
5912 if (Validator.isNotNull(msg)) {
5913 _log.debug(msg);
5914 }
5915 }
5916 else {
5917 _log.debug(e, e);
5918 }
5919 }
5920 else if ((e instanceof SystemException) && _log.isWarnEnabled()) {
5921 _log.warn(e, e);
5922 }
5923
5924 if (response.isCommitted()) {
5925 return;
5926 }
5927
5928 if (status == 0) {
5929 if (e instanceof PrincipalException) {
5930 status = HttpServletResponse.SC_FORBIDDEN;
5931 }
5932 else {
5933 String name = e.getClass().getName();
5934
5935 name = name.substring(name.lastIndexOf(CharPool.PERIOD) + 1);
5936
5937 if (name.startsWith("NoSuch") && name.endsWith("Exception")) {
5938 status = HttpServletResponse.SC_NOT_FOUND;
5939 }
5940 }
5941
5942 if (status == 0) {
5943
5944
5945
5946 if (PropsValues.TCK_URL) {
5947 status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
5948 }
5949 else {
5950 status = HttpServletResponse.SC_BAD_REQUEST;
5951 }
5952 }
5953 }
5954
5955 HttpSession session = PortalSessionThreadLocal.getHttpSession();
5956
5957 if (session == null) {
5958 session = request.getSession();
5959 }
5960
5961 ServletContext servletContext = session.getServletContext();
5962
5963 String redirect = PATH_MAIN + "/portal/status";
5964
5965 if ((e instanceof NoSuchLayoutException) &&
5966 Validator.isNotNull(
5967 PropsValues.LAYOUT_FRIENDLY_URL_PAGE_NOT_FOUND)) {
5968
5969 response.setStatus(status);
5970
5971 redirect = PropsValues.LAYOUT_FRIENDLY_URL_PAGE_NOT_FOUND;
5972
5973 RequestDispatcher requestDispatcher =
5974 servletContext.getRequestDispatcher(redirect);
5975
5976 if (requestDispatcher != null) {
5977 requestDispatcher.forward(request, response);
5978 }
5979 }
5980 else if (PropsValues.LAYOUT_SHOW_HTTP_STATUS) {
5981 response.setStatus(status);
5982
5983 SessionErrors.add(session, e.getClass(), e);
5984
5985 RequestDispatcher requestDispatcher =
5986 servletContext.getRequestDispatcher(redirect);
5987
5988 if (requestDispatcher != null) {
5989 requestDispatcher.forward(request, response);
5990 }
5991 }
5992 else {
5993 if (e != null) {
5994 response.sendError(status, e.getMessage());
5995 }
5996 else {
5997 response.sendError(status);
5998 }
5999 }
6000 }
6001
6002 @Override
6003 public void setPageDescription(
6004 String description, HttpServletRequest request) {
6005
6006 request.setAttribute(WebKeys.PAGE_DESCRIPTION, description);
6007 }
6008
6009 @Override
6010 public void setPageKeywords(String keywords, HttpServletRequest request) {
6011 request.removeAttribute(WebKeys.PAGE_KEYWORDS);
6012
6013 addPageKeywords(keywords, request);
6014 }
6015
6016 @Override
6017 public void setPageSubtitle(String subtitle, HttpServletRequest request) {
6018 request.setAttribute(WebKeys.PAGE_SUBTITLE, subtitle);
6019 }
6020
6021 @Override
6022 public void setPageTitle(String title, HttpServletRequest request) {
6023 request.setAttribute(WebKeys.PAGE_TITLE, title);
6024 }
6025
6026 @Override
6027 public void setPortalPort(HttpServletRequest request) {
6028 if (request.isSecure()) {
6029 if (_securePortalPort.get() == -1) {
6030 int securePortalPort = request.getServerPort();
6031
6032 _securePortalPort.compareAndSet(-1, securePortalPort);
6033 }
6034 }
6035 else {
6036 if (_portalPort.get() == -1) {
6037 int portalPort = request.getServerPort();
6038
6039 if (_portalPort.compareAndSet(-1, portalPort)) {
6040 notifyPortalPortEventListeners(portalPort);
6041 }
6042 }
6043 }
6044 }
6045
6046 @Override
6047 public void storePreferences(PortletPreferences portletPreferences)
6048 throws IOException, ValidatorException {
6049
6050 PortletPreferencesWrapper portletPreferencesWrapper =
6051 (PortletPreferencesWrapper)portletPreferences;
6052
6053 PortletPreferencesImpl portletPreferencesImpl =
6054 portletPreferencesWrapper.getPortletPreferencesImpl();
6055
6056 portletPreferencesImpl.store();
6057 }
6058
6059 @Override
6060 public String[] stripURLAnchor(String url, String separator) {
6061 String anchor = StringPool.BLANK;
6062
6063 int pos = url.indexOf(separator);
6064
6065 if (pos != -1) {
6066 anchor = url.substring(pos);
6067 url = url.substring(0, pos);
6068 }
6069
6070 return new String[] {url, anchor};
6071 }
6072
6073 @Override
6074 public String transformCustomSQL(String sql) {
6075 if ((_customSqlKeys == null) || (_customSqlValues == null)) {
6076 initCustomSQL();
6077 }
6078
6079 return StringUtil.replace(sql, _customSqlKeys, _customSqlValues);
6080 }
6081
6082 @Override
6083 public String transformSQL(String sql) {
6084 return SQLTransformer.transform(sql);
6085 }
6086
6087 @Override
6088 public PortletMode updatePortletMode(
6089 String portletId, User user, Layout layout, PortletMode portletMode,
6090 HttpServletRequest request) {
6091
6092 LayoutTypePortlet layoutType =
6093 (LayoutTypePortlet)layout.getLayoutType();
6094
6095 if ((portletMode == null) || Validator.isNull(portletMode.toString())) {
6096 if (layoutType.hasModeAboutPortletId(portletId)) {
6097 return LiferayPortletMode.ABOUT;
6098 }
6099 else if (layoutType.hasModeConfigPortletId(portletId)) {
6100 return LiferayPortletMode.CONFIG;
6101 }
6102 else if (layoutType.hasModeEditPortletId(portletId)) {
6103 return PortletMode.EDIT;
6104 }
6105 else if (layoutType.hasModeEditDefaultsPortletId(portletId)) {
6106 return LiferayPortletMode.EDIT_DEFAULTS;
6107 }
6108 else if (layoutType.hasModeEditGuestPortletId(portletId)) {
6109 return LiferayPortletMode.EDIT_GUEST;
6110 }
6111 else if (layoutType.hasModeHelpPortletId(portletId)) {
6112 return PortletMode.HELP;
6113 }
6114 else if (layoutType.hasModePreviewPortletId(portletId)) {
6115 return LiferayPortletMode.PREVIEW;
6116 }
6117 else if (layoutType.hasModePrintPortletId(portletId)) {
6118 return LiferayPortletMode.PRINT;
6119 }
6120 else {
6121 return PortletMode.VIEW;
6122 }
6123 }
6124 else {
6125 boolean updateLayout = false;
6126
6127 if (portletMode.equals(LiferayPortletMode.ABOUT) &&
6128 !layoutType.hasModeAboutPortletId(portletId)) {
6129
6130 layoutType.addModeAboutPortletId(portletId);
6131
6132 updateLayout = true;
6133 }
6134 else if (portletMode.equals(LiferayPortletMode.CONFIG) &&
6135 !layoutType.hasModeConfigPortletId(portletId)) {
6136
6137 layoutType.addModeConfigPortletId(portletId);
6138
6139 updateLayout = true;
6140 }
6141 else if (portletMode.equals(PortletMode.EDIT) &&
6142 !layoutType.hasModeEditPortletId(portletId)) {
6143
6144 layoutType.addModeEditPortletId(portletId);
6145
6146 updateLayout = true;
6147 }
6148 else if (portletMode.equals(LiferayPortletMode.EDIT_DEFAULTS) &&
6149 !layoutType.hasModeEditDefaultsPortletId(portletId)) {
6150
6151 layoutType.addModeEditDefaultsPortletId(portletId);
6152
6153 updateLayout = true;
6154 }
6155 else if (portletMode.equals(LiferayPortletMode.EDIT_GUEST) &&
6156 !layoutType.hasModeEditGuestPortletId(portletId)) {
6157
6158 layoutType.addModeEditGuestPortletId(portletId);
6159
6160 updateLayout = true;
6161 }
6162 else if (portletMode.equals(PortletMode.HELP) &&
6163 !layoutType.hasModeHelpPortletId(portletId)) {
6164
6165 layoutType.addModeHelpPortletId(portletId);
6166
6167 updateLayout = true;
6168 }
6169 else if (portletMode.equals(LiferayPortletMode.PREVIEW) &&
6170 !layoutType.hasModePreviewPortletId(portletId)) {
6171
6172 layoutType.addModePreviewPortletId(portletId);
6173
6174 updateLayout = true;
6175 }
6176 else if (portletMode.equals(LiferayPortletMode.PRINT) &&
6177 !layoutType.hasModePrintPortletId(portletId)) {
6178
6179 layoutType.addModePrintPortletId(portletId);
6180
6181 updateLayout = true;
6182 }
6183 else if (portletMode.equals(PortletMode.VIEW) &&
6184 !layoutType.hasModeViewPortletId(portletId)) {
6185
6186 layoutType.removeModesPortletId(portletId);
6187
6188 updateLayout = true;
6189 }
6190
6191 if (updateLayout) {
6192 LayoutClone layoutClone = LayoutCloneFactory.getInstance();
6193
6194 if (layoutClone != null) {
6195 layoutClone.update(
6196 request, layout.getPlid(), layout.getTypeSettings());
6197 }
6198 }
6199
6200 return portletMode;
6201 }
6202 }
6203
6204 @Override
6205 public String updateRedirect(
6206 String redirect, String oldPath, String newPath) {
6207
6208 if (Validator.isNull(redirect) || (oldPath == null) ||
6209 oldPath.equals(newPath)) {
6210
6211 return redirect;
6212 }
6213
6214 String queryString = HttpUtil.getQueryString(redirect);
6215
6216 String redirectParam = HttpUtil.getParameter(
6217 redirect, "redirect", false);
6218
6219 if (Validator.isNotNull(redirectParam)) {
6220 String newRedirectParam = StringUtil.replace(
6221 redirectParam, HttpUtil.encodeURL(oldPath),
6222 HttpUtil.encodeURL(newPath));
6223
6224 queryString = StringUtil.replace(
6225 queryString, redirectParam, newRedirectParam);
6226 }
6227
6228 String redirectPath = HttpUtil.getPath(redirect);
6229
6230 int pos = redirect.indexOf(redirectPath);
6231
6232 String prefix = redirect.substring(0, pos);
6233
6234 pos = redirectPath.lastIndexOf(oldPath);
6235
6236 if (pos != -1) {
6237 prefix += redirectPath.substring(0, pos);
6238
6239 String suffix = redirectPath.substring(pos + oldPath.length());
6240
6241 redirect = prefix + newPath + suffix;
6242 }
6243 else {
6244 redirect = prefix + redirectPath;
6245 }
6246
6247 if (Validator.isNotNull(queryString)) {
6248 redirect += StringPool.QUESTION + queryString;
6249 }
6250
6251 return redirect;
6252 }
6253
6254 @Override
6255 public WindowState updateWindowState(
6256 String portletId, User user, Layout layout, WindowState windowState,
6257 HttpServletRequest request) {
6258
6259 LayoutTypePortlet layoutType =
6260 (LayoutTypePortlet)layout.getLayoutType();
6261
6262 if ((windowState == null) || Validator.isNull(windowState.toString())) {
6263 if (layoutType.hasStateMaxPortletId(portletId)) {
6264 windowState = WindowState.MAXIMIZED;
6265 }
6266 else if (layoutType.hasStateMinPortletId(portletId)) {
6267 windowState = WindowState.MINIMIZED;
6268 }
6269 else {
6270 windowState = WindowState.NORMAL;
6271 }
6272 }
6273 else {
6274 boolean updateLayout = false;
6275
6276 if (windowState.equals(WindowState.MAXIMIZED) &&
6277 !layoutType.hasStateMaxPortletId(portletId)) {
6278
6279 layoutType.addStateMaxPortletId(portletId);
6280
6281 if (PropsValues.LAYOUT_REMEMBER_MAXIMIZED_WINDOW_STATE) {
6282 updateLayout = true;
6283 }
6284 }
6285 else if (windowState.equals(WindowState.MINIMIZED) &&
6286 !layoutType.hasStateMinPortletId(portletId)) {
6287
6288 layoutType.addStateMinPortletId(portletId);
6289
6290 updateLayout = true;
6291 }
6292 else if (windowState.equals(WindowState.NORMAL) &&
6293 !layoutType.hasStateNormalPortletId(portletId)) {
6294
6295 layoutType.removeStatesPortletId(portletId);
6296
6297 updateLayout = true;
6298 }
6299
6300 if (portletId.equals(PortletKeys.LAYOUTS_ADMIN) ||
6301 portletId.equals(PortletKeys.PORTLET_CONFIGURATION)) {
6302
6303 updateLayout = false;
6304 }
6305
6306 if (updateLayout) {
6307 LayoutClone layoutClone = LayoutCloneFactory.getInstance();
6308
6309 if (layoutClone != null) {
6310 layoutClone.update(
6311 request, layout.getPlid(), layout.getTypeSettings());
6312 }
6313 }
6314 }
6315
6316 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
6317 WebKeys.THEME_DISPLAY);
6318
6319 themeDisplay.setStateExclusive(
6320 windowState.equals(LiferayWindowState.EXCLUSIVE));
6321 themeDisplay.setStateMaximized(
6322 windowState.equals(WindowState.MAXIMIZED));
6323 themeDisplay.setStatePopUp(
6324 windowState.equals(LiferayWindowState.POP_UP));
6325
6326 if (themeDisplay.isStateMaximized() &&
6327 themeDisplay.isShowAddContentIcon()) {
6328
6329 themeDisplay.setShowAddContentIcon(false);
6330 }
6331 else if (!themeDisplay.isStateMaximized() &&
6332 !themeDisplay.isShowAddContentIcon() &&
6333 themeDisplay.isShowAddContentIconPermission()) {
6334
6335 themeDisplay.setShowAddContentIcon(true);
6336 }
6337
6338 request.setAttribute(WebKeys.WINDOW_STATE, windowState);
6339
6340 return windowState;
6341 }
6342
6343 protected void addDefaultResource(
6344 long companyId, Layout layout, Portlet portlet,
6345 boolean portletActions)
6346 throws PortalException, SystemException {
6347
6348 long groupId = getScopeGroupId(layout, portlet.getPortletId());
6349
6350 addDefaultResource(companyId, groupId, layout, portlet, portletActions);
6351 }
6352
6353 protected void addDefaultResource(
6354 long companyId, long groupId, Layout layout, Portlet portlet,
6355 boolean portletActions)
6356 throws PortalException, SystemException {
6357
6358 String rootPortletId = portlet.getRootPortletId();
6359
6360 String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(
6361 layout.getPlid(), portlet.getPortletId());
6362
6363 String name = null;
6364 String primaryKey = null;
6365
6366 if (portletActions) {
6367 name = rootPortletId;
6368 primaryKey = portletPrimaryKey;
6369 }
6370 else {
6371 name = ResourceActionsUtil.getPortletBaseResource(rootPortletId);
6372 primaryKey = String.valueOf(groupId);
6373 }
6374
6375 if (Validator.isNull(name)) {
6376 return;
6377 }
6378
6379 try {
6380 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
6381 int count =
6382 ResourcePermissionLocalServiceUtil.
6383 getResourcePermissionsCount(
6384 companyId, name, ResourceConstants.SCOPE_INDIVIDUAL,
6385 primaryKey);
6386
6387 if (count == 0) {
6388 throw new NoSuchResourceException();
6389 }
6390 }
6391 else if (!portlet.isUndeployedPortlet()) {
6392 ResourceLocalServiceUtil.getResource(
6393 companyId, name, ResourceConstants.SCOPE_INDIVIDUAL,
6394 primaryKey);
6395 }
6396 }
6397 catch (NoSuchResourceException nsre) {
6398 boolean addGuestPermissions = true;
6399
6400 if (portletActions) {
6401 Group layoutGroup = layout.getGroup();
6402
6403 if (layout.isPrivateLayout() &&
6404 !layoutGroup.isLayoutPrototype()) {
6405
6406 addGuestPermissions = false;
6407 }
6408 }
6409
6410 ResourceLocalServiceUtil.addResources(
6411 companyId, groupId, 0, name, primaryKey, portletActions, true,
6412 addGuestPermissions);
6413 }
6414 }
6415
6416 protected String buildI18NPath(Locale locale) {
6417 String languageId = LocaleUtil.toLanguageId(locale);
6418
6419 if (Validator.isNull(languageId)) {
6420 return null;
6421 }
6422
6423 if (LanguageUtil.isDuplicateLanguageCode(locale.getLanguage())) {
6424 Locale priorityLocale = LanguageUtil.getLocale(
6425 locale.getLanguage());
6426
6427 if (locale.equals(priorityLocale)) {
6428 languageId = locale.getLanguage();
6429 }
6430 }
6431 else {
6432 languageId = locale.getLanguage();
6433 }
6434
6435 return StringPool.SLASH.concat(languageId);
6436 }
6437
6438 protected long doGetPlidFromPortletId(
6439 long groupId, boolean privateLayout, String portletId)
6440 throws PortalException, SystemException {
6441
6442 long scopeGroupId = groupId;
6443
6444 try {
6445 Group group = GroupLocalServiceUtil.getGroup(groupId);
6446
6447 if (group.isLayout()) {
6448 Layout scopeLayout = LayoutLocalServiceUtil.getLayout(
6449 group.getClassPK());
6450
6451 groupId = scopeLayout.getGroupId();
6452 }
6453 }
6454 catch (Exception e) {
6455 }
6456
6457 long plid = LayoutConstants.DEFAULT_PLID;
6458
6459 List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
6460 groupId, privateLayout, LayoutConstants.TYPE_PORTLET);
6461
6462 for (Layout layout : layouts) {
6463 LayoutTypePortlet layoutTypePortlet =
6464 (LayoutTypePortlet)layout.getLayoutType();
6465
6466 if (layoutTypePortlet.hasPortletId(portletId)) {
6467 if (getScopeGroupId(layout, portletId) == scopeGroupId) {
6468 plid = layout.getPlid();
6469
6470 break;
6471 }
6472 }
6473 }
6474
6475 return plid;
6476 }
6477
6478 protected List<Portlet> filterControlPanelPortlets(
6479 Set<Portlet> portlets, String category, ThemeDisplay themeDisplay) {
6480
6481 Group group = themeDisplay.getScopeGroup();
6482
6483 List<Portlet> filteredPortlets = new ArrayList<Portlet>();
6484
6485 if (category.equals(PortletCategoryKeys.CONTENT) && group.isLayout()) {
6486 for (Portlet portlet : portlets) {
6487 if (portlet.isScopeable()) {
6488 filteredPortlets.add(portlet);
6489 }
6490 }
6491 }
6492 else {
6493 filteredPortlets.addAll(portlets);
6494 }
6495
6496 Iterator<Portlet> itr = filteredPortlets.iterator();
6497
6498 while (itr.hasNext()) {
6499 Portlet portlet = itr.next();
6500
6501 try {
6502 ControlPanelEntry controlPanelEntry =
6503 portlet.getControlPanelEntryInstance();
6504
6505 if (controlPanelEntry == null) {
6506 controlPanelEntry =
6507 DefaultControlPanelEntryFactory.getInstance();
6508 }
6509
6510 if (!controlPanelEntry.isVisible(
6511 portlet, category, themeDisplay)) {
6512
6513 itr.remove();
6514 }
6515 }
6516 catch (Exception e) {
6517 _log.error(e, e);
6518
6519 itr.remove();
6520 }
6521 }
6522
6523 return filteredPortlets;
6524 }
6525
6526 protected Locale getAvailableLocale(Locale locale) {
6527 if (Validator.isNull(locale.getCountry())) {
6528
6529
6530
6531 locale = LanguageUtil.getLocale(locale.getLanguage());
6532 }
6533
6534 if (!LanguageUtil.isAvailableLocale(locale)) {
6535 return null;
6536 }
6537
6538 return locale;
6539 }
6540
6541 protected long getDefaultScopeGroupId(long companyId)
6542 throws PortalException, SystemException {
6543
6544 long doAsGroupId = 0;
6545
6546 Collection<Portlet> portlets = getControlPanelPortlets(
6547 companyId, PortletCategoryKeys.CONTENT);
6548
6549 List<Group> groups = GroupServiceUtil.getManageableSites(portlets, 1);
6550
6551 if (!groups.isEmpty()) {
6552 Group group = groups.get(0);
6553
6554 doAsGroupId = group.getGroupId();
6555 }
6556 else {
6557 Group guestGroup = GroupLocalServiceUtil.fetchGroup(
6558 companyId, GroupConstants.GUEST);
6559
6560 if (guestGroup != null) {
6561 doAsGroupId = guestGroup.getGroupId();
6562 }
6563 }
6564
6565 return doAsGroupId;
6566 }
6567
6568 protected long getDoAsUserId(
6569 HttpServletRequest request, String doAsUserIdString,
6570 boolean alwaysAllowDoAsUser)
6571 throws Exception {
6572
6573 if (Validator.isNull(doAsUserIdString)) {
6574 return 0;
6575 }
6576
6577 long doAsUserId = 0;
6578
6579 try {
6580 Company company = getCompany(request);
6581
6582 doAsUserId = GetterUtil.getLong(
6583 Encryptor.decrypt(company.getKeyObj(), doAsUserIdString));
6584 }
6585 catch (Exception e) {
6586 if (_log.isWarnEnabled()) {
6587 _log.warn(
6588 "Unable to impersonate " + doAsUserIdString +
6589 " because the string cannot be decrypted");
6590 }
6591
6592 return 0;
6593 }
6594
6595 if (_log.isDebugEnabled()) {
6596 if (alwaysAllowDoAsUser) {
6597 _log.debug(
6598 "doAsUserId path or Struts action is always allowed");
6599 }
6600 else {
6601 _log.debug(
6602 "doAsUserId path is Struts action not always allowed");
6603 }
6604 }
6605
6606 if (alwaysAllowDoAsUser) {
6607 request.setAttribute(WebKeys.USER_ID, new Long(doAsUserId));
6608
6609 return doAsUserId;
6610 }
6611
6612 HttpSession session = request.getSession();
6613
6614 Long realUserIdObj = (Long)session.getAttribute(WebKeys.USER_ID);
6615
6616 if (realUserIdObj == null) {
6617 return 0;
6618 }
6619
6620 User doAsUser = UserLocalServiceUtil.getUserById(doAsUserId);
6621
6622 long[] organizationIds = doAsUser.getOrganizationIds();
6623
6624 User realUser = UserLocalServiceUtil.getUserById(
6625 realUserIdObj.longValue());
6626
6627 PermissionChecker permissionChecker =
6628 PermissionCheckerFactoryUtil.create(realUser);
6629
6630 if (doAsUser.isDefaultUser() ||
6631 UserPermissionUtil.contains(
6632 permissionChecker, doAsUserId, organizationIds,
6633 ActionKeys.IMPERSONATE)) {
6634
6635 request.setAttribute(WebKeys.USER_ID, new Long(doAsUserId));
6636
6637 return doAsUserId;
6638 }
6639 else {
6640 _log.error(
6641 "User " + realUserIdObj + " does not have the permission " +
6642 "to impersonate " + doAsUserId);
6643
6644 return 0;
6645 }
6646 }
6647
6648 protected String getGroupFriendlyURL(
6649 Group group, boolean privateLayoutSet, ThemeDisplay themeDisplay,
6650 boolean canonicalURL)
6651 throws PortalException, SystemException {
6652
6653 LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
6654 group.getGroupId(), privateLayoutSet);
6655
6656 String portalURL = StringPool.BLANK;
6657
6658 if (canonicalURL || !themeDisplay.getServerName().equals(_LOCALHOST)) {
6659 String virtualHostname = layoutSet.getVirtualHostname();
6660
6661 if (Validator.isNull(virtualHostname) &&
6662 Validator.isNotNull(
6663 PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME) &&
6664 !layoutSet.isPrivateLayout()) {
6665
6666 try {
6667 Group defaultGroup = GroupLocalServiceUtil.getGroup(
6668 themeDisplay.getCompanyId(),
6669 PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME);
6670
6671 if (layoutSet.getGroupId() == defaultGroup.getGroupId()) {
6672 Company company = themeDisplay.getCompany();
6673
6674 virtualHostname = company.getVirtualHostname();
6675 }
6676 }
6677 catch (Exception e) {
6678 _log.error(e, e);
6679 }
6680 }
6681
6682 if (Validator.isNotNull(virtualHostname) &&
6683 (canonicalURL ||
6684 !virtualHostname.equalsIgnoreCase(_LOCALHOST))) {
6685
6686 virtualHostname = getPortalURL(
6687 virtualHostname, themeDisplay.getServerPort(),
6688 themeDisplay.isSecure());
6689
6690 String portalDomain = HttpUtil.getDomain(
6691 themeDisplay.getPortalURL());
6692
6693 if (canonicalURL || virtualHostname.contains(portalDomain)) {
6694 String path = StringPool.BLANK;
6695
6696 if (themeDisplay.isWidget()) {
6697 path = PropsValues.WIDGET_SERVLET_MAPPING;
6698 }
6699
6700 if (themeDisplay.isI18n() && !canonicalURL) {
6701 path = themeDisplay.getI18nPath();
6702 }
6703
6704 return virtualHostname.concat(_pathContext).concat(path);
6705 }
6706 }
6707 else {
6708 LayoutSet curLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
6709 themeDisplay.getParentGroupId(), privateLayoutSet);
6710
6711 if (canonicalURL ||
6712 ((layoutSet.getLayoutSetId() !=
6713 curLayoutSet.getLayoutSetId()) &&
6714 (group.getClassPK() != themeDisplay.getUserId()))) {
6715
6716 if (group.isControlPanel()) {
6717 virtualHostname = themeDisplay.getServerName();
6718
6719 if (Validator.isNull(virtualHostname) ||
6720 virtualHostname.equalsIgnoreCase(_LOCALHOST)) {
6721
6722 virtualHostname = curLayoutSet.getVirtualHostname();
6723 }
6724 }
6725
6726 if (Validator.isNull(virtualHostname) ||
6727 virtualHostname.equalsIgnoreCase(_LOCALHOST)) {
6728
6729 Company company = themeDisplay.getCompany();
6730
6731 virtualHostname = company.getVirtualHostname();
6732 }
6733
6734 if (canonicalURL ||
6735 !virtualHostname.equalsIgnoreCase(_LOCALHOST)) {
6736
6737 portalURL = getPortalURL(
6738 virtualHostname, themeDisplay.getServerPort(),
6739 themeDisplay.isSecure());
6740 }
6741 }
6742 }
6743 }
6744
6745 String friendlyURL = null;
6746
6747 if (privateLayoutSet) {
6748 if (group.isUser()) {
6749 friendlyURL = _PRIVATE_USER_SERVLET_MAPPING;
6750 }
6751 else {
6752 friendlyURL = _PRIVATE_GROUP_SERVLET_MAPPING;
6753 }
6754 }
6755 else {
6756 friendlyURL = _PUBLIC_GROUP_SERVLET_MAPPING;
6757 }
6758
6759 StringBundler sb = new StringBundler(6);
6760
6761 sb.append(portalURL);
6762 sb.append(_pathContext);
6763
6764 if (themeDisplay.isI18n() && !canonicalURL) {
6765 sb.append(themeDisplay.getI18nPath());
6766 }
6767
6768 if (themeDisplay.isWidget()) {
6769 sb.append(PropsValues.WIDGET_SERVLET_MAPPING);
6770 }
6771
6772 sb.append(friendlyURL);
6773 sb.append(group.getFriendlyURL());
6774
6775 return sb.toString();
6776 }
6777
6778 protected String getPortletParam(HttpServletRequest request, String name) {
6779 String portletId = ParamUtil.getString(request, "p_p_id");
6780
6781 if (Validator.isNull(portletId)) {
6782 return StringPool.BLANK;
6783 }
6784
6785 String value = null;
6786
6787 int valueCount = 0;
6788
6789 String keyName = StringPool.UNDERLINE.concat(name);
6790
6791 Map<String, String[]> parameterMap = request.getParameterMap();
6792
6793 for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
6794 String parameterName = entry.getKey();
6795
6796 int pos = parameterName.indexOf(keyName);
6797
6798 if (pos == -1) {
6799 continue;
6800 }
6801
6802 valueCount++;
6803
6804
6805
6806 if (valueCount > 1) {
6807 return StringPool.BLANK;
6808 }
6809
6810 String[] parameterValues = entry.getValue();
6811
6812 if ((parameterValues == null) || (parameterValues.length == 0) ||
6813 Validator.isNull(parameterValues[0])) {
6814
6815 continue;
6816 }
6817
6818
6819
6820 String portletId1 = parameterName.substring(1, pos);
6821
6822 if (portletId.equals(portletId1)) {
6823 value = parameterValues[0];
6824 }
6825 }
6826
6827 if (value == null) {
6828 value = StringPool.BLANK;
6829 }
6830
6831 return value;
6832 }
6833
6834 protected String getServletURL(
6835 Portlet portlet, String servletPath, ThemeDisplay themeDisplay)
6836 throws PortalException, SystemException {
6837
6838 Layout layout = themeDisplay.getLayout();
6839
6840 StringBundler sb = new StringBundler();
6841
6842 sb.append(themeDisplay.getPortalURL());
6843
6844 if (Validator.isNotNull(_pathContext)) {
6845 sb.append(_pathContext);
6846 }
6847
6848 if (themeDisplay.isI18n()) {
6849 sb.append(themeDisplay.getI18nPath());
6850 }
6851
6852 sb.append(servletPath);
6853
6854 Group group = layout.getGroup();
6855
6856 if (layout.isPrivateLayout()) {
6857 if (group.isUser()) {
6858 sb.append(_PRIVATE_USER_SERVLET_MAPPING);
6859 }
6860 else {
6861 sb.append(_PRIVATE_GROUP_SERVLET_MAPPING);
6862 }
6863 }
6864 else {
6865 sb.append(_PUBLIC_GROUP_SERVLET_MAPPING);
6866 }
6867
6868 sb.append(group.getFriendlyURL());
6869 sb.append(layout.getFriendlyURL());
6870
6871 sb.append(FRIENDLY_URL_SEPARATOR);
6872
6873 FriendlyURLMapper friendlyURLMapper =
6874 portlet.getFriendlyURLMapperInstance();
6875
6876 if ((friendlyURLMapper != null) && !portlet.isInstanceable()) {
6877 sb.append(friendlyURLMapper.getMapping());
6878 }
6879 else {
6880 sb.append(portlet.getPortletId());
6881 }
6882
6883 return sb.toString();
6884 }
6885
6886 protected boolean hasPortletDefaultResource(
6887 ThemeDisplay themeDisplay, Layout layout, Portlet portlet)
6888 throws PortalException, SystemException {
6889
6890 String primaryKey = PortletPermissionUtil.getPrimaryKey(
6891 layout.getPlid(), portlet.getPortletId());
6892
6893 try {
6894 List<com.liferay.portal.model.PortletPreferences>
6895 portletPreferencesList =
6896 PortletPreferencesLocalServiceUtil.getPortletPreferences(
6897 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
6898 portlet.getPortletId());
6899
6900 if (portletPreferencesList.isEmpty()) {
6901 return false;
6902 }
6903
6904 if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
6905 int count =
6906 ResourcePermissionLocalServiceUtil.
6907 getResourcePermissionsCount(
6908 themeDisplay.getCompanyId(),
6909 portlet.getRootPortletId(),
6910 ResourceConstants.SCOPE_INDIVIDUAL, primaryKey);
6911
6912 if (count == 0) {
6913 return false;
6914 }
6915 }
6916 else if (!portlet.isUndeployedPortlet()) {
6917 ResourceLocalServiceUtil.getResource(
6918 themeDisplay.getCompanyId(), portlet.getRootPortletId(),
6919 ResourceConstants.SCOPE_INDIVIDUAL, primaryKey);
6920 }
6921 }
6922 catch (NoSuchResourceException nsre) {
6923 return false;
6924 }
6925
6926 return true;
6927 }
6928
6929 protected boolean isAlwaysAllowDoAsUser(HttpServletRequest request)
6930 throws Exception {
6931
6932 String ticketKey = ParamUtil.getString(request, "ticketKey");
6933
6934 if (Validator.isNull(ticketKey)) {
6935 return false;
6936 }
6937
6938 Ticket ticket = TicketLocalServiceUtil.fetchTicket(ticketKey);
6939
6940 if ((ticket == null) ||
6941 (ticket.getType() != TicketConstants.TYPE_IMPERSONATE)) {
6942
6943 return false;
6944 }
6945
6946 String className = ticket.getClassName();
6947
6948 if (!className.equals(User.class.getName())) {
6949 return false;
6950 }
6951
6952 long doAsUserId = 0;
6953
6954 try {
6955 Company company = getCompany(request);
6956
6957 String doAsUserIdString = ParamUtil.getString(
6958 request, "doAsUserId");
6959
6960 if (Validator.isNotNull(doAsUserIdString)) {
6961 doAsUserId = GetterUtil.getLong(
6962 Encryptor.decrypt(company.getKeyObj(), doAsUserIdString));
6963 }
6964 }
6965 catch (Exception e) {
6966 return false;
6967 }
6968
6969 if (ticket.getClassPK() != doAsUserId) {
6970 return false;
6971 }
6972
6973 if (ticket.isExpired()) {
6974 TicketLocalServiceUtil.deleteTicket(ticket);
6975
6976 return false;
6977 }
6978
6979 Date expirationDate = new Date(
6980 System.currentTimeMillis() +
6981 PropsValues.SESSION_TIMEOUT * Time.MINUTE);
6982
6983 ticket.setExpirationDate(expirationDate);
6984
6985 TicketLocalServiceUtil.updateTicket(ticket, false);
6986
6987 return true;
6988 }
6989
6990 protected boolean isPanelSelectedPortlet(
6991 ThemeDisplay themeDisplay, String portletId) {
6992
6993 Layout layout = themeDisplay.getLayout();
6994
6995 String panelSelectedPortlets = layout.getTypeSettingsProperty(
6996 "panelSelectedPortlets");
6997
6998 if (Validator.isNotNull(panelSelectedPortlets)) {
6999 String[] panelSelectedPortletsArray = StringUtil.split(
7000 panelSelectedPortlets);
7001
7002 return ArrayUtil.contains(panelSelectedPortletsArray, portletId);
7003 }
7004
7005 return false;
7006 }
7007
7008 protected void notifyPortalPortEventListeners(int portalPort) {
7009 for (PortalPortEventListener portalPortEventListener :
7010 _portalPortEventListeners) {
7011
7012 portalPortEventListener.portalPortConfigured(portalPort);
7013 }
7014 }
7015
7016 protected String removeRedirectParameter(String url) {
7017 String queryString = HttpUtil.getQueryString(url);
7018
7019 Map<String, String[]> parameterMap = HttpUtil.getParameterMap(
7020 queryString);
7021
7022 for (String parameter : parameterMap.keySet()) {
7023 if (parameter.endsWith("redirect")) {
7024 url = HttpUtil.removeParameter(url, parameter);
7025 }
7026 }
7027
7028 return url;
7029 }
7030
7031 protected void resetThemeDisplayI18n(
7032 ThemeDisplay themeDisplay, String languageId, String path) {
7033
7034 themeDisplay.setI18nLanguageId(languageId);
7035 themeDisplay.setI18nPath(path);
7036 }
7037
7038 protected void setLocale(
7039 HttpServletRequest request, HttpServletResponse response,
7040 Locale locale) {
7041
7042 HttpSession session = request.getSession();
7043
7044 session.setAttribute(Globals.LOCALE_KEY, locale);
7045
7046 LanguageUtil.updateCookie(request, response, locale);
7047 }
7048
7049 protected void setThemeDisplayI18n(
7050 ThemeDisplay themeDisplay, Locale locale) {
7051
7052 String i18nLanguageId = null;
7053 String i18nPath = null;
7054
7055 if ((I18nFilter.getLanguageIds().contains(locale.toString()) &&
7056 ((PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 1) &&
7057 !locale.equals(LocaleUtil.getDefault()))) ||
7058 (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 2)) {
7059
7060 i18nLanguageId = locale.toString();
7061 i18nPath = buildI18NPath(locale);
7062 }
7063
7064 themeDisplay.setI18nLanguageId(i18nLanguageId);
7065 themeDisplay.setI18nPath(i18nPath);
7066 }
7067
7068 private static final String _J_SECURITY_CHECK = "j_security_check";
7069
7070 private static final String _JSESSIONID = ";jsessionid=";
7071
7072 private static final String _LOCALHOST = "localhost";
7073
7074 private static final String _PRIVATE_GROUP_SERVLET_MAPPING =
7075 PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING;
7076
7077 private static final String _PRIVATE_USER_SERVLET_MAPPING =
7078 PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;
7079
7080 private static final String _PUBLIC_GROUP_SERVLET_MAPPING =
7081 PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING;
7082
7083 private static Log _log = LogFactoryUtil.getLog(PortalImpl.class);
7084
7085 private static Log _logWebServerServlet = LogFactoryUtil.getLog(
7086 WebServerServlet.class);
7087
7088 private static Map<Long, String> _cdnHostHttpMap =
7089 new ConcurrentHashMap<Long, String>();
7090 private static Map<Long, String> _cdnHostHttpsMap =
7091 new ConcurrentHashMap<Long, String>();
7092 private static MethodHandler _resetCDNHostsMethodHandler =
7093 new MethodHandler(
7094 new MethodKey(PortalUtil.class.getName(), "resetCDNHosts"));
7095 private static Date _upTime = new Date();
7096
7097 private String[] _allSystemGroups;
7098 private String[] _allSystemOrganizationRoles;
7099 private String[] _allSystemRoles;
7100 private String[] _allSystemSiteRoles;
7101 private Set<String> _authTokenIgnoreActions;
7102 private Set<String> _authTokenIgnorePortlets;
7103 private Pattern _bannedResourceIdPattern = Pattern.compile(
7104 PropsValues.PORTLET_RESOURCE_ID_BANNED_PATHS_REGEXP,
7105 Pattern.CASE_INSENSITIVE);
7106 private String _computerAddress;
7107 private String _computerName;
7108 private String[] _customSqlKeys;
7109 private String[] _customSqlValues;
7110 private String _pathContext;
7111 private String _pathFriendlyURLPrivateGroup;
7112 private String _pathFriendlyURLPrivateUser;
7113 private String _pathFriendlyURLPublic;
7114 private String _pathImage;
7115 private String _pathMain;
7116 private String _pathProxy;
7117 private Map<String, Long> _plidToPortletIdMap =
7118 new ConcurrentHashMap<String, Long>();
7119 private final AtomicInteger _portalPort = new AtomicInteger(-1);
7120 private List<PortalPortEventListener> _portalPortEventListeners =
7121 new ArrayList<PortalPortEventListener>();
7122 private Set<String> _portletAddDefaultResourceCheckWhitelist;
7123 private Set<String> _portletAddDefaultResourceCheckWhitelistActions;
7124 private Set<String> _reservedParams;
7125 private final AtomicInteger _securePortalPort = new AtomicInteger(-1);
7126 private String[] _sortedSystemGroups;
7127 private String[] _sortedSystemOrganizationRoles;
7128 private String[] _sortedSystemRoles;
7129 private String[] _sortedSystemSiteRoles;
7130
7131 }