001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.LayoutFriendlyURLException;
018    import com.liferay.portal.NoSuchGroupException;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    import com.liferay.portal.kernel.util.CharPool;
024    import com.liferay.portal.kernel.util.HttpUtil;
025    import com.liferay.portal.kernel.util.ListUtil;
026    import com.liferay.portal.kernel.util.LocaleUtil;
027    import com.liferay.portal.kernel.util.StringPool;
028    import com.liferay.portal.kernel.util.StringUtil;
029    import com.liferay.portal.kernel.util.UnicodeProperties;
030    import com.liferay.portal.kernel.util.Validator;
031    import com.liferay.portal.model.ColorScheme;
032    import com.liferay.portal.model.Group;
033    import com.liferay.portal.model.Layout;
034    import com.liferay.portal.model.LayoutConstants;
035    import com.liferay.portal.model.LayoutSet;
036    import com.liferay.portal.model.LayoutType;
037    import com.liferay.portal.model.LayoutTypePortlet;
038    import com.liferay.portal.model.LayoutTypePortletConstants;
039    import com.liferay.portal.model.Theme;
040    import com.liferay.portal.security.permission.ActionKeys;
041    import com.liferay.portal.security.permission.PermissionChecker;
042    import com.liferay.portal.service.GroupLocalServiceUtil;
043    import com.liferay.portal.service.LayoutLocalServiceUtil;
044    import com.liferay.portal.service.LayoutSetLocalServiceUtil;
045    import com.liferay.portal.service.ThemeLocalServiceUtil;
046    import com.liferay.portal.service.permission.LayoutPermissionUtil;
047    import com.liferay.portal.theme.ThemeDisplay;
048    import com.liferay.portal.util.CookieKeys;
049    import com.liferay.portal.util.LayoutClone;
050    import com.liferay.portal.util.LayoutCloneFactory;
051    import com.liferay.portal.util.PortalUtil;
052    import com.liferay.portal.util.PropsValues;
053    import com.liferay.portal.util.WebKeys;
054    import com.liferay.portlet.PortletURLImpl;
055    
056    import java.io.IOException;
057    
058    import java.util.ArrayList;
059    import java.util.Iterator;
060    import java.util.List;
061    import java.util.Locale;
062    
063    import javax.portlet.PortletException;
064    import javax.portlet.PortletMode;
065    import javax.portlet.PortletRequest;
066    import javax.portlet.WindowState;
067    
068    import javax.servlet.http.HttpServletRequest;
069    
070    /**
071     * @author Brian Wing Shun Chan
072     */
073    public class LayoutImpl extends LayoutBaseImpl {
074    
075            public static boolean hasFriendlyURLKeyword(String friendlyURL) {
076                    String keyword = _getFriendlyURLKeyword(friendlyURL);
077    
078                    if (Validator.isNotNull(keyword)) {
079                            return true;
080                    }
081    
082                    return false;
083            }
084    
085            public static int validateFriendlyURL(String friendlyURL) {
086                    return validateFriendlyURL(friendlyURL, true);
087            }
088    
089            public static int validateFriendlyURL(
090                    String friendlyURL, boolean checkMaxLength) {
091    
092                    if (friendlyURL.length() < 2) {
093                            return LayoutFriendlyURLException.TOO_SHORT;
094                    }
095    
096                    if (checkMaxLength &&
097                            (friendlyURL.length() > LayoutConstants.FRIENDLY_URL_MAX_LENGTH)) {
098    
099                            return LayoutFriendlyURLException.TOO_LONG;
100                    }
101    
102                    if (!friendlyURL.startsWith(StringPool.SLASH)) {
103                            return LayoutFriendlyURLException.DOES_NOT_START_WITH_SLASH;
104                    }
105    
106                    if (friendlyURL.endsWith(StringPool.SLASH)) {
107                            return LayoutFriendlyURLException.ENDS_WITH_SLASH;
108                    }
109    
110                    if (friendlyURL.contains(StringPool.DOUBLE_SLASH)) {
111                            return LayoutFriendlyURLException.ADJACENT_SLASHES;
112                    }
113    
114                    for (char c : friendlyURL.toCharArray()) {
115                            if (!Validator.isChar(c) && !Validator.isDigit(c) &&
116                                    (c != CharPool.DASH) && (c != CharPool.PERCENT) &&
117                                    (c != CharPool.PERIOD) && (c != CharPool.PLUS) &&
118                                    (c != CharPool.SLASH) && (c != CharPool.STAR) &&
119                                    (c != CharPool.UNDERLINE)) {
120    
121                                    return LayoutFriendlyURLException.INVALID_CHARACTERS;
122                            }
123                    }
124    
125                    return -1;
126            }
127    
128            public static void validateFriendlyURLKeyword(String friendlyURL)
129                    throws LayoutFriendlyURLException {
130    
131                    String keyword = _getFriendlyURLKeyword(friendlyURL);
132    
133                    if (Validator.isNotNull(keyword)) {
134                            LayoutFriendlyURLException lfurle =
135                                    new LayoutFriendlyURLException(
136                                            LayoutFriendlyURLException.KEYWORD_CONFLICT);
137    
138                            lfurle.setKeywordConflict(keyword);
139    
140                            throw lfurle;
141                    }
142            }
143    
144            public LayoutImpl() {
145            }
146    
147            @Override
148            public List<Layout> getAllChildren() throws SystemException {
149                    List<Layout> layouts = new ArrayList<Layout>();
150    
151                    Iterator<Layout> itr = getChildren().iterator();
152    
153                    while (itr.hasNext()) {
154                            Layout layout = itr.next();
155    
156                            layouts.add(layout);
157                            layouts.addAll(layout.getAllChildren());
158                    }
159    
160                    return layouts;
161            }
162    
163            @Override
164            public long getAncestorLayoutId() throws PortalException, SystemException {
165                    long layoutId = 0;
166    
167                    Layout layout = this;
168    
169                    while (true) {
170                            if (!layout.isRootLayout()) {
171                                    layout = LayoutLocalServiceUtil.getLayout(
172                                            layout.getGroupId(), layout.isPrivateLayout(),
173                                            layout.getParentLayoutId());
174                            }
175                            else {
176                                    layoutId = layout.getLayoutId();
177    
178                                    break;
179                            }
180                    }
181    
182                    return layoutId;
183            }
184    
185            @Override
186            public long getAncestorPlid() throws PortalException, SystemException {
187                    long plid = 0;
188    
189                    Layout layout = this;
190    
191                    while (true) {
192                            if (!layout.isRootLayout()) {
193                                    layout = LayoutLocalServiceUtil.getLayout(
194                                            layout.getGroupId(), layout.isPrivateLayout(),
195                                            layout.getParentLayoutId());
196                            }
197                            else {
198                                    plid = layout.getPlid();
199    
200                                    break;
201                            }
202                    }
203    
204                    return plid;
205            }
206    
207            @Override
208            public List<Layout> getAncestors() throws PortalException, SystemException {
209                    List<Layout> layouts = new ArrayList<Layout>();
210    
211                    Layout layout = this;
212    
213                    while (true) {
214                            if (!layout.isRootLayout()) {
215                                    layout = LayoutLocalServiceUtil.getLayout(
216                                            layout.getGroupId(), layout.isPrivateLayout(),
217                                            layout.getParentLayoutId());
218    
219                                    layouts.add(layout);
220                            }
221                            else {
222                                    break;
223                            }
224                    }
225    
226                    return layouts;
227            }
228    
229            @Override
230            public List<Layout> getChildren() throws SystemException {
231                    return LayoutLocalServiceUtil.getLayouts(
232                            getGroupId(), isPrivateLayout(), getLayoutId());
233            }
234    
235            @Override
236            public List<Layout> getChildren(PermissionChecker permissionChecker)
237                    throws PortalException, SystemException {
238    
239                    List<Layout> layouts = ListUtil.copy(getChildren());
240    
241                    Iterator<Layout> itr = layouts.iterator();
242    
243                    while (itr.hasNext()) {
244                            Layout layout = itr.next();
245    
246                            if (layout.isHidden() ||
247                                    !LayoutPermissionUtil.contains(
248                                            permissionChecker, layout, ActionKeys.VIEW)) {
249    
250                                    itr.remove();
251                            }
252                    }
253    
254                    return layouts;
255            }
256    
257            @Override
258            public ColorScheme getColorScheme()
259                    throws PortalException, SystemException {
260    
261                    if (isInheritLookAndFeel()) {
262                            return getLayoutSet().getColorScheme();
263                    }
264                    else {
265                            return ThemeLocalServiceUtil.getColorScheme(
266                                    getCompanyId(), getTheme().getThemeId(), getColorSchemeId(),
267                                    false);
268                    }
269            }
270    
271            @Override
272            public String getCssText() throws PortalException, SystemException {
273                    if (isInheritLookAndFeel()) {
274                            return getLayoutSet().getCss();
275                    }
276                    else {
277                            return getCss();
278                    }
279            }
280    
281            @Override
282            public Group getGroup() throws PortalException, SystemException {
283                    return GroupLocalServiceUtil.getGroup(getGroupId());
284            }
285    
286            @Override
287            public String getHTMLTitle(Locale locale) {
288                    String localeLanguageId = LocaleUtil.toLanguageId(locale);
289    
290                    return getHTMLTitle(localeLanguageId);
291            }
292    
293            @Override
294            public String getHTMLTitle(String localeLanguageId) {
295                    String htmlTitle = getTitle(localeLanguageId);
296    
297                    if (Validator.isNull(htmlTitle)) {
298                            htmlTitle = getName(localeLanguageId);
299                    }
300    
301                    return htmlTitle;
302            }
303    
304            @Override
305            public LayoutSet getLayoutSet() throws PortalException, SystemException {
306                    if (_layoutSet == null) {
307                            _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
308                                    getGroupId(), isPrivateLayout());
309                    }
310    
311                    return _layoutSet;
312            }
313    
314            @Override
315            public LayoutType getLayoutType() {
316                    if (_layoutType == null) {
317                            _layoutType = new LayoutTypePortletImpl(this);
318                    }
319    
320                    return _layoutType;
321            }
322    
323            @Override
324            public long getParentPlid() throws PortalException, SystemException {
325                    if (getParentLayoutId() == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
326                            return 0;
327                    }
328    
329                    Layout layout = LayoutLocalServiceUtil.getLayout(
330                            getGroupId(), isPrivateLayout(), getParentLayoutId());
331    
332                    return layout.getPlid();
333            }
334    
335            @Override
336            public String getRegularURL(HttpServletRequest request)
337                    throws PortalException, SystemException {
338    
339                    return _getURL(request, false, false);
340            }
341    
342            @Override
343            public String getResetLayoutURL(HttpServletRequest request)
344                    throws PortalException, SystemException {
345    
346                    return _getURL(request, true, true);
347            }
348    
349            @Override
350            public String getResetMaxStateURL(HttpServletRequest request)
351                    throws PortalException, SystemException {
352    
353                    return _getURL(request, true, false);
354            }
355    
356            @Override
357            public Group getScopeGroup() throws PortalException, SystemException {
358                    Group group = null;
359    
360                    try {
361                            group = GroupLocalServiceUtil.getLayoutGroup(
362                                    getCompanyId(), getPlid());
363                    }
364                    catch (NoSuchGroupException nsge) {
365                    }
366    
367                    return group;
368            }
369    
370            @Override
371            public String getTarget() {
372                    return PortalUtil.getLayoutTarget(this);
373            }
374    
375            @Override
376            public Theme getTheme() throws PortalException, SystemException {
377                    if (isInheritLookAndFeel()) {
378                            return getLayoutSet().getTheme();
379                    }
380                    else {
381                            return ThemeLocalServiceUtil.getTheme(
382                                    getCompanyId(), getThemeId(), false);
383                    }
384            }
385    
386            @Override
387            public String getThemeSetting(String key, String device) {
388                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
389    
390                    String value = typeSettingsProperties.getProperty(
391                            ThemeSettingImpl.namespaceProperty(device, key));
392    
393                    if (value != null) {
394                            return value;
395                    }
396    
397                    if (!isInheritLookAndFeel()) {
398                            try {
399                                    Theme theme = _getTheme(device);
400    
401                                    return theme.getSetting(key);
402                            }
403                            catch (Exception e) {
404                            }
405                    }
406    
407                    try {
408                            LayoutSet layoutSet = getLayoutSet();
409    
410                            value = layoutSet.getThemeSetting(key, device);
411                    }
412                    catch (Exception e) {
413                    }
414    
415                    return value;
416            }
417    
418            @Override
419            public String getTypeSettings() {
420                    if (_typeSettingsProperties == null) {
421                            return super.getTypeSettings();
422                    }
423                    else {
424                            return _typeSettingsProperties.toString();
425                    }
426            }
427    
428            @Override
429            public UnicodeProperties getTypeSettingsProperties() {
430                    if (_typeSettingsProperties == null) {
431                            _typeSettingsProperties = new UnicodeProperties(true);
432    
433                            _typeSettingsProperties.fastLoad(super.getTypeSettings());
434                    }
435    
436                    return _typeSettingsProperties;
437            }
438    
439            @Override
440            public String getTypeSettingsProperty(String key) {
441                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
442    
443                    return typeSettingsProperties.getProperty(key);
444            }
445    
446            @Override
447            public String getTypeSettingsProperty(String key, String defaultValue) {
448                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
449    
450                    return typeSettingsProperties.getProperty(key, defaultValue);
451            }
452    
453            @Override
454            public ColorScheme getWapColorScheme()
455                    throws PortalException, SystemException {
456    
457                    if (isInheritLookAndFeel()) {
458                            return getLayoutSet().getWapColorScheme();
459                    }
460                    else {
461                            return ThemeLocalServiceUtil.getColorScheme(
462                                    getCompanyId(), getWapTheme().getThemeId(),
463                                    getWapColorSchemeId(), true);
464                    }
465            }
466    
467            @Override
468            public Theme getWapTheme() throws PortalException, SystemException {
469                    if (isInheritWapLookAndFeel()) {
470                            return getLayoutSet().getWapTheme();
471                    }
472                    else {
473                            return ThemeLocalServiceUtil.getTheme(
474                                    getCompanyId(), getWapThemeId(), true);
475                    }
476            }
477    
478            @Override
479            public boolean hasAncestor(long layoutId)
480                    throws PortalException, SystemException {
481    
482                    long parentLayoutId = getParentLayoutId();
483    
484                    while (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
485                            if (parentLayoutId == layoutId) {
486                                    return true;
487                            }
488                            else {
489                                    Layout parentLayout = LayoutLocalServiceUtil.getLayout(
490                                            getGroupId(), isPrivateLayout(), parentLayoutId);
491    
492                                    parentLayoutId = parentLayout.getParentLayoutId();
493                            }
494                    }
495    
496                    return false;
497            }
498    
499            @Override
500            public boolean hasChildren() throws SystemException {
501                    return LayoutLocalServiceUtil.hasLayouts(
502                            getGroupId(), isPrivateLayout(), getLayoutId());
503            }
504    
505            @Override
506            public boolean hasScopeGroup() throws PortalException, SystemException {
507                    Group group = getScopeGroup();
508    
509                    if (group != null) {
510                            return true;
511                    }
512                    else {
513                            return false;
514                    }
515            }
516    
517            @Override
518            public boolean isChildSelected(boolean selectable, Layout layout)
519                    throws PortalException, SystemException {
520    
521                    if (selectable) {
522                            long plid = getPlid();
523    
524                            List<Layout> ancestors = layout.getAncestors();
525    
526                            for (Layout curLayout : ancestors) {
527                                    if (plid == curLayout.getPlid()) {
528                                            return true;
529                                    }
530                            }
531                    }
532    
533                    return false;
534            }
535    
536            @Override
537            public boolean isContentDisplayPage() {
538                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
539    
540                    String defaultAssetPublisherPortletId =
541                            typeSettingsProperties.getProperty(
542                                    LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);
543    
544                    if (Validator.isNotNull(defaultAssetPublisherPortletId)) {
545                            return true;
546                    }
547                    else {
548                            return false;
549                    }
550            }
551    
552            @Override
553            public boolean isFirstChild() {
554                    if (getPriority() == 0) {
555                            return true;
556                    }
557                    else {
558                            return false;
559                    }
560            }
561    
562            @Override
563            public boolean isFirstParent() {
564                    if (isFirstChild() && isRootLayout()) {
565                            return true;
566                    }
567                    else {
568                            return false;
569                    }
570            }
571    
572            @Override
573            public boolean isInheritLookAndFeel() {
574                    if (Validator.isNull(getThemeId()) ||
575                            Validator.isNull(getColorSchemeId())) {
576    
577                            return true;
578                    }
579                    else {
580                            return false;
581                    }
582            }
583    
584            @Override
585            public boolean isInheritWapLookAndFeel() {
586                    if (Validator.isNull(getWapThemeId()) ||
587                            Validator.isNull(getWapColorSchemeId())) {
588    
589                            return true;
590                    }
591                    else {
592                            return false;
593                    }
594            }
595    
596            @Override
597            public boolean isLayoutPrototypeLinkActive() {
598                    if (isLayoutPrototypeLinkEnabled() &&
599                            Validator.isNotNull(getLayoutPrototypeUuid())) {
600    
601                            return true;
602                    }
603    
604                    return false;
605            }
606    
607            @Override
608            public boolean isPublicLayout() {
609                    return !isPrivateLayout();
610            }
611    
612            @Override
613            public boolean isRootLayout() {
614                    if (getParentLayoutId() == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
615                            return true;
616                    }
617                    else {
618                            return false;
619                    }
620            }
621    
622            @Override
623            public boolean isSelected(
624                    boolean selectable, Layout layout, long ancestorPlid) {
625    
626                    if (selectable) {
627                            long plid = getPlid();
628    
629                            if ((plid == layout.getPlid()) || (plid == ancestorPlid)) {
630                                    return true;
631                            }
632                    }
633    
634                    return false;
635            }
636    
637            @Override
638            public boolean isTypeArticle() {
639                    if (getType().equals(LayoutConstants.TYPE_ARTICLE)) {
640                            return true;
641                    }
642                    else {
643                            return false;
644                    }
645            }
646    
647            @Override
648            public boolean isTypeControlPanel() {
649                    if (getType().equals(LayoutConstants.TYPE_CONTROL_PANEL)) {
650                            return true;
651                    }
652                    else {
653                            return false;
654                    }
655            }
656    
657            @Override
658            public boolean isTypeEmbedded() {
659                    if (getType().equals(LayoutConstants.TYPE_EMBEDDED)) {
660                            return true;
661                    }
662                    else {
663                            return false;
664                    }
665            }
666    
667            @Override
668            public boolean isTypeLinkToLayout() {
669                    if (getType().equals(LayoutConstants.TYPE_LINK_TO_LAYOUT)) {
670                            return true;
671                    }
672                    else {
673                            return false;
674                    }
675            }
676    
677            @Override
678            public boolean isTypePanel() {
679                    if (getType().equals(LayoutConstants.TYPE_PANEL)) {
680                            return true;
681                    }
682                    else {
683                            return false;
684                    }
685            }
686    
687            @Override
688            public boolean isTypePortlet() {
689                    if (getType().equals(LayoutConstants.TYPE_PORTLET)) {
690                            return true;
691                    }
692                    else {
693                            return false;
694                    }
695            }
696    
697            @Override
698            public boolean isTypeURL() {
699                    if (getType().equals(LayoutConstants.TYPE_URL)) {
700                            return true;
701                    }
702                    else {
703                            return false;
704                    }
705            }
706    
707            @Override
708            public void setGroupId(long groupId) {
709                    super.setGroupId(groupId);
710    
711                    _layoutSet = null;
712            }
713    
714            @Override
715            public void setLayoutSet(LayoutSet layoutSet) {
716                    _layoutSet = layoutSet;
717            }
718    
719            @Override
720            public void setPrivateLayout(boolean privateLayout) {
721                    super.setPrivateLayout(privateLayout);
722    
723                    _layoutSet = null;
724            }
725    
726            @Override
727            public void setTypeSettings(String typeSettings) {
728                    _typeSettingsProperties = null;
729    
730                    super.setTypeSettings(typeSettings);
731            }
732    
733            @Override
734            public void setTypeSettingsProperties(
735                    UnicodeProperties typeSettingsProperties) {
736    
737                    _typeSettingsProperties = typeSettingsProperties;
738    
739                    super.setTypeSettings(_typeSettingsProperties.toString());
740            }
741    
742            private static String _getFriendlyURLKeyword(String friendlyURL) {
743                    friendlyURL = friendlyURL.toLowerCase();
744    
745                    for (String keyword : _friendlyURLKeywords) {
746                            if (friendlyURL.startsWith(keyword)) {
747                                    return keyword;
748                            }
749    
750                            if (keyword.equals(friendlyURL + StringPool.SLASH)) {
751                                    return friendlyURL;
752                            }
753                    }
754    
755                    return null;
756            }
757    
758            private static void _initFriendlyURLKeywords() {
759                    _friendlyURLKeywords =
760                            new String[PropsValues.LAYOUT_FRIENDLY_URL_KEYWORDS.length];
761    
762                    for (int i = 0; i < PropsValues.LAYOUT_FRIENDLY_URL_KEYWORDS.length;
763                                    i++) {
764    
765                            String keyword = PropsValues.LAYOUT_FRIENDLY_URL_KEYWORDS[i];
766    
767                            keyword = StringPool.SLASH + keyword;
768    
769                            if (!keyword.contains(StringPool.PERIOD)) {
770                                    if (keyword.endsWith(StringPool.STAR)) {
771                                            keyword = keyword.substring(0, keyword.length() - 1);
772                                    }
773                                    else {
774                                            keyword = keyword + StringPool.SLASH;
775                                    }
776                            }
777    
778                            _friendlyURLKeywords[i] = keyword.toLowerCase();
779                    }
780            }
781    
782            private LayoutTypePortlet _getLayoutTypePortletClone(
783                            HttpServletRequest request)
784                    throws IOException {
785    
786                    LayoutTypePortlet layoutTypePortlet = null;
787    
788                    LayoutClone layoutClone = LayoutCloneFactory.getInstance();
789    
790                    if (layoutClone != null) {
791                            String typeSettings = layoutClone.get(request, getPlid());
792    
793                            if (typeSettings != null) {
794                                    UnicodeProperties typeSettingsProperties =
795                                            new UnicodeProperties(true);
796    
797                                    typeSettingsProperties.load(typeSettings);
798    
799                                    String stateMax = typeSettingsProperties.getProperty(
800                                            LayoutTypePortletConstants.STATE_MAX);
801                                    String stateMin = typeSettingsProperties.getProperty(
802                                            LayoutTypePortletConstants.STATE_MIN);
803    
804                                    Layout layout = (Layout)this.clone();
805    
806                                    layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
807    
808                                    layoutTypePortlet.setStateMax(stateMax);
809                                    layoutTypePortlet.setStateMin(stateMin);
810                            }
811                    }
812    
813                    if (layoutTypePortlet == null) {
814                            layoutTypePortlet = (LayoutTypePortlet)getLayoutType();
815                    }
816    
817                    return layoutTypePortlet;
818            }
819    
820            private Theme _getTheme(String device)
821                    throws PortalException, SystemException {
822    
823                    if (device.equals("regular")) {
824                            return getTheme();
825                    }
826                    else {
827                            return getWapTheme();
828                    }
829            }
830    
831            private String _getURL(
832                            HttpServletRequest request, boolean resetMaxState,
833                            boolean resetRenderParameters)
834                    throws PortalException, SystemException {
835    
836                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
837                            WebKeys.THEME_DISPLAY);
838    
839                    if (resetMaxState) {
840                            Layout layout = themeDisplay.getLayout();
841    
842                            LayoutTypePortlet layoutTypePortlet = null;
843    
844                            if (layout.equals(this)) {
845                                    layoutTypePortlet = themeDisplay.getLayoutTypePortlet();
846                            }
847                            else {
848                                    try {
849                                            layoutTypePortlet = _getLayoutTypePortletClone(request);
850                                    }
851                                    catch (IOException ioe) {
852                                            _log.error("Unable to clone layout settings", ioe);
853    
854                                            layoutTypePortlet = (LayoutTypePortlet)getLayoutType();
855                                    }
856                            }
857    
858                            if (layoutTypePortlet.hasStateMax()) {
859                                    String portletId = StringUtil.split(
860                                            layoutTypePortlet.getStateMax())[0];
861    
862                                    PortletURLImpl portletURLImpl = new PortletURLImpl(
863                                            request, portletId, getPlid(), PortletRequest.ACTION_PHASE);
864    
865                                    try {
866                                            portletURLImpl.setWindowState(WindowState.NORMAL);
867                                            portletURLImpl.setPortletMode(PortletMode.VIEW);
868                                    }
869                                    catch (PortletException pe) {
870                                            throw new SystemException(pe);
871                                    }
872    
873                                    portletURLImpl.setAnchor(false);
874    
875                                    if (PropsValues.LAYOUT_DEFAULT_P_L_RESET &&
876                                            !resetRenderParameters) {
877    
878                                            portletURLImpl.setParameter("p_l_reset", "0");
879                                    }
880                                    else if (!PropsValues.LAYOUT_DEFAULT_P_L_RESET &&
881                                                     resetRenderParameters) {
882    
883                                            portletURLImpl.setParameter("p_l_reset", "1");
884                                    }
885    
886                                    return portletURLImpl.toString();
887                            }
888                    }
889    
890                    String portalURL = PortalUtil.getPortalURL(request);
891    
892                    String url = PortalUtil.getLayoutURL(this, themeDisplay);
893    
894                    if (!CookieKeys.hasSessionId(request) &&
895                            (url.startsWith(portalURL) || url.startsWith(StringPool.SLASH))) {
896    
897                            url = PortalUtil.getURLWithSessionId(
898                                    url, request.getSession().getId());
899                    }
900    
901                    if (!resetMaxState) {
902                            return url;
903                    }
904    
905                    if (PropsValues.LAYOUT_DEFAULT_P_L_RESET && !resetRenderParameters) {
906                            url = HttpUtil.addParameter(url, "p_l_reset", 0);
907                    }
908                    else if (!PropsValues.LAYOUT_DEFAULT_P_L_RESET &&
909                                     resetRenderParameters) {
910    
911                            url = HttpUtil.addParameter(url, "p_l_reset", 1);
912                    }
913    
914                    return url;
915            }
916    
917            private static Log _log = LogFactoryUtil.getLog(LayoutImpl.class);
918    
919            private static String[] _friendlyURLKeywords;
920    
921            private LayoutSet _layoutSet;
922            private LayoutType _layoutType;
923            private UnicodeProperties _typeSettingsProperties;
924    
925            static {
926                    _initFriendlyURLKeywords();
927            }
928    
929    }