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.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.UnicodeProperties;
022    import com.liferay.portal.model.Group;
023    import com.liferay.portal.model.LayoutSet;
024    import com.liferay.portal.service.GroupLocalServiceUtil;
025    import com.liferay.portal.service.LayoutSetLocalServiceUtil;
026    
027    import java.io.IOException;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Ryan Park
032     */
033    public class LayoutSetPrototypeImpl extends LayoutSetPrototypeBaseImpl {
034    
035            public LayoutSetPrototypeImpl() {
036            }
037    
038            @Override
039            public Group getGroup() throws PortalException, SystemException {
040                    return GroupLocalServiceUtil.getLayoutSetPrototypeGroup(
041                            getCompanyId(), getLayoutSetPrototypeId());
042            }
043    
044            @Override
045            public long getGroupId() throws PortalException, SystemException {
046                    Group group = getGroup();
047    
048                    return group.getGroupId();
049            }
050    
051            @Override
052            public LayoutSet getLayoutSet() throws PortalException, SystemException {
053                    return LayoutSetLocalServiceUtil.getLayoutSet(
054                            getGroup().getGroupId(), true);
055            }
056    
057            @Override
058            public UnicodeProperties getSettingsProperties() {
059                    if (_settingsProperties == null) {
060                            _settingsProperties = new UnicodeProperties(true);
061    
062                            try {
063                                    _settingsProperties.load(super.getSettings());
064                            }
065                            catch (IOException ioe) {
066                                    _log.error(ioe, ioe);
067                            }
068                    }
069    
070                    return _settingsProperties;
071            }
072    
073            @Override
074            public String getSettingsProperty(String key) {
075                    UnicodeProperties settingsProperties = getSettingsProperties();
076    
077                    return settingsProperties.getProperty(key);
078            }
079    
080            @Override
081            public void setSettings(String settings) {
082                    _settingsProperties = null;
083    
084                    super.setSettings(settings);
085            }
086    
087            @Override
088            public void setSettingsProperties(UnicodeProperties settingsProperties) {
089                    _settingsProperties = settingsProperties;
090    
091                    super.setSettings(settingsProperties.toString());
092            }
093    
094            private static Log _log = LogFactoryUtil.getLog(
095                    LayoutSetPrototypeImpl.class);
096    
097            private UnicodeProperties _settingsProperties;
098    
099    }