001    /**
002     * Copyright (c) 2000-2012 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            public Group getGroup() throws PortalException, SystemException {
039                    return GroupLocalServiceUtil.getLayoutSetPrototypeGroup(
040                            getCompanyId(), getLayoutSetPrototypeId());
041            }
042    
043            public LayoutSet getLayoutSet() throws PortalException, SystemException {
044                    return LayoutSetLocalServiceUtil.getLayoutSet(
045                            getGroup().getGroupId(), true);
046            }
047    
048            public UnicodeProperties getSettingsProperties() {
049                    if (_settingsProperties == null) {
050                            _settingsProperties = new UnicodeProperties(true);
051    
052                            try {
053                                    _settingsProperties.load(super.getSettings());
054                            }
055                            catch (IOException ioe) {
056                                    _log.error(ioe, ioe);
057                            }
058                    }
059    
060                    return _settingsProperties;
061            }
062    
063            public String getSettingsProperty(String key) {
064                    UnicodeProperties settingsProperties = getSettingsProperties();
065    
066                    return settingsProperties.getProperty(key);
067            }
068    
069            @Override
070            public void setSettings(String settings) {
071                    _settingsProperties = null;
072    
073                    super.setSettings(settings);
074            }
075    
076            public void setSettingsProperties(UnicodeProperties settingsProperties) {
077                    _settingsProperties = settingsProperties;
078    
079                    super.setSettings(settingsProperties.toString());
080            }
081    
082            private static Log _log = LogFactoryUtil.getLog(
083                    LayoutSetPrototypeImpl.class);
084    
085            private UnicodeProperties _settingsProperties;
086    
087    }