/**
* 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.soy.internal;
import com.liferay.portal.kernel.cache.PortalCache;
import com.liferay.portal.kernel.cache.SingleVMPool;
import com.liferay.portal.kernel.template.Template;
import com.liferay.portal.kernel.template.TemplateConstants;
import com.liferay.portal.kernel.template.TemplateManager;
import com.liferay.portal.kernel.template.TemplateResource;
import com.liferay.portal.template.BaseMultiTemplateManager;
import com.liferay.portal.template.RestrictedTemplate;
import com.liferay.portal.template.TemplateContextHelper;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Bruno Basto
*/
@Component(
immediate = true,
property = {"language.type=" + TemplateConstants.LANG_TYPE_SOY},
service = TemplateManager.class
)
public class SoyManager extends BaseMultiTemplateManager {
@Override
public void destroy() {
templateContextHelper.removeAllHelperUtilities();
templateContextHelper = null;
}
@Override
public void destroy(ClassLoader classLoader) {
templateContextHelper.removeHelperUtilities(classLoader);
}
@Override
public String getName() {
return TemplateConstants.LANG_TYPE_SOY;
}
@Override
public void init() {
}
@Reference(unbind = "-")
public void setSingleVMPool(SingleVMPool singleVMPool) {
_portalCache =
(PortalCache<HashSet<TemplateResource>, SoyTofuCacheBag>)
singleVMPool.getPortalCache(SoyTemplate.class.getName());
}
@Override
@Reference(service = SoyTemplateContextHelper.class, unbind = "-")
public void setTemplateContextHelper(
TemplateContextHelper templateContextHelper) {
super.setTemplateContextHelper(templateContextHelper);
}
@Override
protected Template doGetTemplate(
List<TemplateResource> templateResources,
TemplateResource errorTemplateResource, boolean restricted,
Map<String, Object> helperUtilities, boolean privileged) {
Template template = new SoyTemplate(
templateResources, errorTemplateResource, helperUtilities,
(SoyTemplateContextHelper)templateContextHelper, privileged,
_portalCache);
if (restricted) {
template = new RestrictedTemplate(
template, templateContextHelper.getRestrictedVariables());
}
return template;
}
private PortalCache<HashSet<TemplateResource>, SoyTofuCacheBag>
_portalCache;
}