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.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            public Object get(String key) {
039                    return _template.get(key);
040            }
041    
042            public void prepare(HttpServletRequest request) {
043                    _template.prepare(request);
044            }
045    
046            public boolean processTemplate(Writer writer) throws TemplateException {
047                    return _template.processTemplate(writer);
048            }
049    
050            public void put(String key, Object value) {
051                    if (_restrictedVariables.contains(key)) {
052                            return;
053                    }
054    
055                    _template.put(key, value);
056            }
057    
058            private Set<String> _restrictedVariables;
059            private Template _template;
060    
061    }