001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.UnicodeProperties;
022    import com.liferay.portal.model.ColorScheme;
023    import com.liferay.portal.model.Group;
024    import com.liferay.portal.model.LayoutSet;
025    import com.liferay.portal.model.Theme;
026    import com.liferay.portal.service.GroupLocalServiceUtil;
027    import com.liferay.portal.service.ThemeLocalServiceUtil;
028    
029    import java.io.IOException;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     * @author Jorge Ferrer
034     */
035    public class LayoutSetImpl extends LayoutSetModelImpl implements LayoutSet {
036    
037            public LayoutSetImpl() {
038            }
039    
040            public Theme getTheme() throws SystemException {
041                    return ThemeLocalServiceUtil.getTheme(
042                            getCompanyId(), getThemeId(), false);
043            }
044    
045            public ColorScheme getColorScheme() throws SystemException {
046                    return ThemeLocalServiceUtil.getColorScheme(
047                            getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false);
048            }
049    
050            public Group getGroup() throws PortalException, SystemException {
051                    return GroupLocalServiceUtil.getGroup(getGroupId());
052            }
053    
054            public String getSettings() {
055                    if (_settingsProperties == null) {
056                            return super.getSettings();
057                    }
058                    else {
059                            return _settingsProperties.toString();
060                    }
061            }
062    
063            public UnicodeProperties getSettingsProperties() {
064                    if (_settingsProperties == null) {
065                            _settingsProperties = new UnicodeProperties(true);
066    
067                            try {
068                                    _settingsProperties.load(super.getSettings());
069                            }
070                            catch (IOException ioe) {
071                                    _log.error(ioe, ioe);
072                            }
073                    }
074    
075                    return _settingsProperties;
076            }
077    
078            public String getSettingsProperty(String key) {
079                    UnicodeProperties settingsProperties = getSettingsProperties();
080    
081                    return settingsProperties.getProperty(key);
082            }
083    
084            public Theme getWapTheme() throws SystemException {
085                    return ThemeLocalServiceUtil.getTheme(
086                            getCompanyId(), getWapThemeId(), true);
087            }
088    
089            public ColorScheme getWapColorScheme() throws SystemException {
090                    return ThemeLocalServiceUtil.getColorScheme(
091                            getCompanyId(), getWapTheme().getThemeId(), getWapColorSchemeId(),
092                            true);
093            }
094    
095            public void setSettings(String settings) {
096                    _settingsProperties = null;
097    
098                    super.setSettings(settings);
099            }
100    
101            public void setSettingsProperties(UnicodeProperties settingsProperties) {
102                    _settingsProperties = settingsProperties;
103    
104                    super.setSettings(_settingsProperties.toString());
105            }
106    
107            private static Log _log = LogFactoryUtil.getLog(LayoutSetImpl.class);
108    
109            private UnicodeProperties _settingsProperties;
110    
111    }