com.liferay.portal.template.BaseTemplateManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-impl Show documentation
Show all versions of portal-impl Show documentation
Contains implementation for the portal services.
/**
* Copyright (c) 2000-2013 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.TemplateManager;
import com.liferay.portal.kernel.template.TemplateResource;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Map;
/**
* @author Raymond Augé
*/
public abstract class BaseTemplateManager implements TemplateManager {
@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) {
TemplateControlContext templateControlContext =
templateContextHelper.getTemplateControlContext();
AccessControlContext accessControlContext =
templateControlContext.getAccessControlContext();
ClassLoader classLoader = templateControlContext.getClassLoader();
if (accessControlContext == null) {
Map helperUtilities =
templateContextHelper.getHelperUtilities(
classLoader, restricted);
return doGetTemplate(
templateResource, errorTemplateResource, restricted,
helperUtilities, false);
}
Map helperUtilities = AccessController.doPrivileged(
new DoGetHelperUtilitiesPrivilegedAction(
templateContextHelper, classLoader, restricted),
accessControlContext);
Template template = AccessController.doPrivileged(
new DoGetTemplatePrivilegedAction(
templateResource, errorTemplateResource, restricted,
helperUtilities));
return new PrivilegedTemplateWrapper(accessControlContext, template);
}
public void setTemplateContextHelper(
TemplateContextHelper templateContextHelper) {
this.templateContextHelper = templateContextHelper;
}
protected abstract Template doGetTemplate(
TemplateResource templateResource,
TemplateResource errorTemplateResource, boolean restricted,
Map helperUtilities, boolean privileged);
protected TemplateContextHelper templateContextHelper;
private class DoGetHelperUtilitiesPrivilegedAction
implements PrivilegedAction