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