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.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.LocaleUtil;
020    import com.liferay.portal.kernel.util.UnicodeProperties;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.model.ColorScheme;
023    import com.liferay.portal.model.LayoutBranch;
024    import com.liferay.portal.model.LayoutRevision;
025    import com.liferay.portal.model.LayoutSet;
026    import com.liferay.portal.model.Theme;
027    import com.liferay.portal.service.LayoutBranchLocalServiceUtil;
028    import com.liferay.portal.service.LayoutRevisionLocalServiceUtil;
029    import com.liferay.portal.service.LayoutSetLocalServiceUtil;
030    import com.liferay.portal.service.ThemeLocalServiceUtil;
031    
032    import java.util.List;
033    import java.util.Locale;
034    
035    /**
036     * @author Brian Wing Shun Chan
037     */
038    public class LayoutRevisionImpl extends LayoutRevisionBaseImpl {
039    
040            public LayoutRevisionImpl() {
041            }
042    
043            @Override
044            public List<LayoutRevision> getChildren() throws SystemException {
045                    return LayoutRevisionLocalServiceUtil.getChildLayoutRevisions(
046                            getLayoutSetBranchId(), getLayoutRevisionId(), getPlid());
047            }
048    
049            @Override
050            public ColorScheme getColorScheme()
051                    throws PortalException, SystemException {
052    
053                    if (isInheritLookAndFeel()) {
054                            return getLayoutSet().getColorScheme();
055                    }
056                    else {
057                            return ThemeLocalServiceUtil.getColorScheme(
058                                    getCompanyId(), getTheme().getThemeId(), getColorSchemeId(),
059                                    false);
060                    }
061            }
062    
063            @Override
064            public String getCssText() throws PortalException, SystemException {
065                    if (isInheritLookAndFeel()) {
066                            return getLayoutSet().getCss();
067                    }
068                    else {
069                            return getCss();
070                    }
071            }
072    
073            @Override
074            public String getHTMLTitle(Locale locale) {
075                    String localeLanguageId = LocaleUtil.toLanguageId(locale);
076    
077                    return getHTMLTitle(localeLanguageId);
078            }
079    
080            @Override
081            public String getHTMLTitle(String localeLanguageId) {
082                    String htmlTitle = getTitle(localeLanguageId);
083    
084                    if (Validator.isNull(htmlTitle)) {
085                            htmlTitle = getName(localeLanguageId);
086                    }
087    
088                    return htmlTitle;
089            }
090    
091            @Override
092            public LayoutBranch getLayoutBranch()
093                    throws PortalException, SystemException {
094    
095                    return LayoutBranchLocalServiceUtil.getLayoutBranch(
096                            getLayoutBranchId());
097            }
098    
099            @Override
100            public LayoutSet getLayoutSet() throws PortalException, SystemException {
101                    return LayoutSetLocalServiceUtil.getLayoutSet(
102                            getGroupId(), isPrivateLayout());
103            }
104    
105            @Override
106            public Theme getTheme() throws PortalException, SystemException {
107                    if (isInheritLookAndFeel()) {
108                            return getLayoutSet().getTheme();
109                    }
110                    else {
111                            return ThemeLocalServiceUtil.getTheme(
112                                    getCompanyId(), getThemeId(), false);
113                    }
114            }
115    
116            @Override
117            public String getTypeSettings() {
118                    if (_typeSettingsProperties == null) {
119                            return super.getTypeSettings();
120                    }
121                    else {
122                            return _typeSettingsProperties.toString();
123                    }
124            }
125    
126            @Override
127            public UnicodeProperties getTypeSettingsProperties() {
128                    if (_typeSettingsProperties == null) {
129                            _typeSettingsProperties = new UnicodeProperties(true);
130    
131                            _typeSettingsProperties.fastLoad(super.getTypeSettings());
132                    }
133    
134                    return _typeSettingsProperties;
135            }
136    
137            @Override
138            public ColorScheme getWapColorScheme()
139                    throws PortalException, SystemException {
140    
141                    if (isInheritLookAndFeel()) {
142                            return getLayoutSet().getWapColorScheme();
143                    }
144                    else {
145                            return ThemeLocalServiceUtil.getColorScheme(
146                                    getCompanyId(), getWapTheme().getThemeId(),
147                                    getWapColorSchemeId(), true);
148                    }
149            }
150    
151            @Override
152            public Theme getWapTheme() throws PortalException, SystemException {
153                    if (isInheritWapLookAndFeel()) {
154                            return getLayoutSet().getWapTheme();
155                    }
156                    else {
157                            return ThemeLocalServiceUtil.getTheme(
158                                    getCompanyId(), getWapThemeId(), true);
159                    }
160            }
161    
162            @Override
163            public boolean hasChildren() throws SystemException {
164                    if (!getChildren().isEmpty()) {
165                            return true;
166                    }
167    
168                    return false;
169            }
170    
171            @Override
172            public boolean isInheritLookAndFeel() {
173                    if (Validator.isNull(getThemeId()) ||
174                            Validator.isNull(getColorSchemeId())) {
175    
176                            return true;
177                    }
178                    else {
179                            return false;
180                    }
181            }
182    
183            @Override
184            public boolean isInheritWapLookAndFeel() {
185                    if (Validator.isNull(getWapThemeId()) ||
186                            Validator.isNull(getWapColorSchemeId())) {
187    
188                            return true;
189                    }
190                    else {
191                            return false;
192                    }
193            }
194    
195            @Override
196            public void setTypeSettings(String typeSettings) {
197                    _typeSettingsProperties = null;
198    
199                    super.setTypeSettings(typeSettings);
200            }
201    
202            @Override
203            public void setTypeSettingsProperties(
204                    UnicodeProperties typeSettingsProperties) {
205    
206                    _typeSettingsProperties = typeSettingsProperties;
207    
208                    super.setTypeSettings(_typeSettingsProperties.toString());
209            }
210    
211            private UnicodeProperties _typeSettingsProperties;
212    
213    }