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.layoutconfiguration.util.velocity;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.UnicodeProperties;
020    import com.liferay.portal.model.CustomizedPages;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portlet.sites.util.SitesUtil;
023    import com.liferay.taglib.aui.InputTag;
024    
025    import java.io.Writer;
026    
027    import javax.servlet.ServletRequest;
028    import javax.servlet.jsp.PageContext;
029    import javax.servlet.jsp.tagext.Tag;
030    
031    /**
032     * @author Raymond Aug??
033     */
034    public class CustomizationSettingsProcessor implements ColumnProcessor {
035    
036            public CustomizationSettingsProcessor(PageContext pageContext) {
037                    _pageContext = pageContext;
038                    _writer = pageContext.getOut();
039    
040                    ServletRequest servletRequest = pageContext.getRequest();
041    
042                    Layout selLayout = (Layout)servletRequest.getAttribute(
043                            "edit_pages.jsp-selLayout");
044    
045                    _layoutTypeSettings = selLayout.getTypeSettingsProperties();
046    
047                    _customizationEnabled = true;
048    
049                    if (!SitesUtil.isLayoutUpdateable(selLayout)) {
050                            _customizationEnabled = false;
051                    }
052    
053                    if (selLayout.isLayoutPrototypeLinkActive()) {
054                            _customizationEnabled = false;
055                    }
056            }
057    
058            @Override
059            public String processColumn(String columnId) throws Exception {
060                    return processColumn(columnId, StringPool.BLANK);
061            }
062    
063            @Override
064            public String processColumn(String columnId, String classNames)
065                    throws Exception {
066    
067                    String customizableKey = CustomizedPages.namespaceColumnId(columnId);
068    
069                    boolean customizable = false;
070    
071                    if (_customizationEnabled) {
072                            customizable = GetterUtil.getBoolean(
073                                    _layoutTypeSettings.getProperty(
074                                            customizableKey, String.valueOf(false)));
075                    }
076    
077                    _writer.append("<div class=\"");
078                    _writer.append(classNames);
079                    _writer.append("\">");
080    
081                    _writer.append("<h1>");
082                    _writer.append(columnId);
083                    _writer.append("</h1>");
084    
085                    InputTag inputTag = new InputTag();
086    
087                    inputTag.setDisabled(!_customizationEnabled);
088                    inputTag.setLabel("customizable");
089                    inputTag.setName(
090                            "TypeSettingsProperties--".concat(customizableKey).concat("--"));
091                    inputTag.setPageContext(_pageContext);
092                    inputTag.setType("checkbox");
093                    inputTag.setValue(customizable);
094    
095                    int result = inputTag.doStartTag();
096    
097                    if (result == Tag.EVAL_BODY_INCLUDE) {
098                            inputTag.doEndTag();
099                    }
100    
101                    _writer.append("</div>");
102    
103                    return StringPool.BLANK;
104            }
105    
106            @Override
107            public String processMax() throws Exception {
108                    return StringPool.BLANK;
109            }
110    
111            /**
112             * @deprecated As of 6.2.0, replaced by {@link #processMax()}
113             */
114            @Override
115            public String processMax(String classNames) throws Exception {
116                    return processMax();
117            }
118    
119            @Override
120            public String processPortlet(String portletId) throws Exception {
121                    _writer.append("<div class=\"portlet\">");
122                    _writer.append(portletId);
123                    _writer.append("</div>");
124    
125                    return StringPool.BLANK;
126            }
127    
128            private boolean _customizationEnabled;
129            private UnicodeProperties _layoutTypeSettings;
130            private PageContext _pageContext;
131            private Writer _writer;
132    
133    }