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