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.xsl;
016    
017    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
018    import com.liferay.portal.kernel.template.Template;
019    import com.liferay.portal.kernel.template.TemplateConstants;
020    import com.liferay.portal.kernel.template.TemplateContextType;
021    import com.liferay.portal.kernel.template.TemplateResource;
022    import com.liferay.portal.template.BaseTemplateManager;
023    import com.liferay.portal.template.RestrictedTemplate;
024    import com.liferay.portal.template.TemplateContextHelper;
025    
026    import java.util.Map;
027    
028    /**
029     * @author Tina Tian
030     */
031    @DoPrivileged
032    public class XSLManager extends BaseTemplateManager {
033    
034            public void destroy() {
035                    if (_templateContextHelper == null) {
036                            return;
037                    }
038    
039                    _templateContextHelper.removeAllHelperUtilities();
040    
041                    _templateContextHelper = null;
042            }
043    
044            public void destroy(ClassLoader classLoader) {
045                    _templateContextHelper.removeHelperUtilities(classLoader);
046            }
047    
048            public String getName() {
049                    return TemplateConstants.LANG_TYPE_XSL;
050            }
051    
052            public void init() {
053            }
054    
055            public void setTemplateContextHelper(
056                    TemplateContextHelper templateContextHelper) {
057    
058                    _templateContextHelper = templateContextHelper;
059            }
060    
061            @Override
062            protected Template doGetTemplate(
063                    TemplateResource templateResource,
064                    TemplateResource errorTemplateResource,
065                    TemplateContextType templateContextType,
066                    Map<String, Object> helperUtilities) {
067    
068                    Template template = null;
069    
070                    XSLTemplateResource xslTemplateResource =
071                            (XSLTemplateResource)templateResource;
072    
073                    if (templateContextType.equals(TemplateContextType.EMPTY)) {
074                            template = new XSLTemplate(
075                                    xslTemplateResource, errorTemplateResource, null,
076                                    _templateContextHelper);
077                    }
078                    else if (templateContextType.equals(TemplateContextType.RESTRICTED)) {
079                            template = new RestrictedTemplate(
080                                    new XSLTemplate(
081                                            xslTemplateResource, errorTemplateResource, helperUtilities,
082                                            _templateContextHelper),
083                                    _templateContextHelper.getRestrictedVariables());
084                    }
085                    else if (templateContextType.equals(TemplateContextType.STANDARD)) {
086                            template = new XSLTemplate(
087                                    xslTemplateResource, errorTemplateResource, helperUtilities,
088                                    _templateContextHelper);
089                    }
090    
091                    return template;
092            }
093    
094            @Override
095            protected TemplateContextHelper getTemplateContextHelper() {
096                    return _templateContextHelper;
097            }
098    
099            private TemplateContextHelper _templateContextHelper;
100    
101    }