/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.template; import com.liferay.portal.kernel.security.pacl.NotPrivileged; import com.liferay.portal.kernel.template.Template; import com.liferay.portal.kernel.template.TemplateResource; import java.security.AccessControlContext; import java.security.AccessController; import java.util.List; import java.util.Map; /** * @author Leonardo Barros */ public abstract class BaseSingleTemplateManager extends BaseTemplateManager { @NotPrivileged @Override public Template getTemplate( List<TemplateResource> templateResources, boolean restricted) { return getTemplate(templateResources, null, restricted); } @NotPrivileged @Override public Template getTemplate( List<TemplateResource> templateResources, TemplateResource errorTemplateResource, boolean restricted) { throw new UnsupportedOperationException( "Template type does not support multi templates"); } @NotPrivileged @Override public Template getTemplate( TemplateResource templateResource, boolean restricted) { return getTemplate(templateResource, null, restricted); } @NotPrivileged @Override public Template getTemplate( TemplateResource templateResource, TemplateResource errorTemplateResource, boolean restricted) { AccessControlContext accessControlContext = getAccessControlContext(); if (accessControlContext == null) { return doGetTemplate( templateResource, errorTemplateResource, restricted, getHelperUtilities(restricted), false); } Map<String, Object> helperUtilities = AccessController.doPrivileged( new DoGetHelperUtilitiesPrivilegedAction( templateContextHelper, getTemplateControlContextClassLoader(), restricted), accessControlContext); Template template = AccessController.doPrivileged( new DoGetSingleTemplatePrivilegedAction( templateResource, errorTemplateResource, restricted, helperUtilities)); return new PrivilegedTemplateWrapper(accessControlContext, template); } protected abstract Template doGetTemplate( TemplateResource templateResource, TemplateResource errorTemplateResource, boolean restricted, Map<String, Object> helperUtilities, boolean privileged); protected class DoGetSingleTemplatePrivilegedAction extends DoGetAbstractTemplatePrivilegedAction { public DoGetSingleTemplatePrivilegedAction( TemplateResource templateResource, TemplateResource errorTemplateResource, boolean restricted, Map<String, Object> helperUtilities) { super(errorTemplateResource, restricted, helperUtilities); _templateResource = templateResource; } @Override public Template run() { return doGetTemplate( _templateResource, errorTemplateResource, restricted, helperUtilities, true); } private final TemplateResource _templateResource; } }