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.template;
016    
017    import com.liferay.portal.kernel.template.Template;
018    import com.liferay.portal.kernel.template.TemplateException;
019    
020    import java.io.Writer;
021    
022    import java.util.Set;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Tina Tian
028     */
029    public class RestrictedTemplate implements Template {
030    
031            public RestrictedTemplate(
032                    Template template, Set<String> restrictedVariables) {
033    
034                    _template = template;
035                    _restrictedVariables = restrictedVariables;
036            }
037    
038            @Override
039            public Object get(String key) {
040                    return _template.get(key);
041            }
042    
043            @Override
044            public String[] getKeys() {
045                    return _template.getKeys();
046            }
047    
048            @Override
049            public void prepare(HttpServletRequest request) {
050                    _template.prepare(request);
051            }
052    
053            @Override
054            public void processTemplate(Writer writer) throws TemplateException {
055                    _template.processTemplate(writer);
056            }
057    
058            @Override
059            public void put(String key, Object value) {
060                    if (_restrictedVariables.contains(key)) {
061                            return;
062                    }
063    
064                    _template.put(key, value);
065            }
066    
067            private Set<String> _restrictedVariables;
068            private Template _template;
069    
070    }