/* * Copyright (c) 2014 Thomas Kratz * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Dieses Programm ist Freie Software: Sie können es unter den Bedingungen der GNU General Public License, wie von der Free Software Foundation, Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren veröffentlichten Version, weiterverbreiten und/oder modifizieren. Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. Siehe die GNU General Public License für weitere Details. Sie sollten eine Kopie der GNU General Public License zusammen mit diesem Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>. */ package de.eiswind.magnolia.thymeleaf.processor; import info.magnolia.module.blossom.template.BlossomTemplateDefinition; import info.magnolia.objectfactory.Components; import info.magnolia.rendering.context.RenderingContext; import info.magnolia.rendering.engine.RenderingEngine; import info.magnolia.rendering.template.AreaDefinition; import info.magnolia.templating.elements.AreaElement; import org.thymeleaf.context.ITemplateContext; import org.thymeleaf.engine.AttributeName; import org.thymeleaf.exceptions.TemplateProcessingException; import org.thymeleaf.model.IProcessableElementTag; import org.thymeleaf.processor.element.IElementTagStructureHandler; import org.thymeleaf.templatemode.TemplateMode; /** * the area processor. */ public class CmsAreaElementProcessor extends AbstractCmsElementProcessor<AreaElement> { /** * the area attribute name. */ public static final String ATTR_NAME = "area"; /** * create an instance. */ public CmsAreaElementProcessor(String prefix) { super(TemplateMode.HTML, prefix, null, false, ATTR_NAME, true); } /** * {@inheritDoc} */ protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler structureHandler) { final RenderingEngine renderingEngine = Components.getComponent(RenderingEngine.class); final RenderingContext renderingContext = renderingEngine.getRenderingContext(); AreaDefinition areaDef = null; BlossomTemplateDefinition templateDefinition; try { templateDefinition = (BlossomTemplateDefinition) renderingContext.getRenderableDefinition(); if (templateDefinition.getAreas().containsKey(attributeValue)) { areaDef = templateDefinition.getAreas().get(attributeValue); } } catch (ClassCastException x) { throw new TemplateProcessingException("Only Blossom, templates supported", x); } if (areaDef == null) { throw new TemplateProcessingException("Area not found:" + attributeValue); } AreaElement areaElement = createElement(renderingContext); areaElement.setName(areaDef.getName()); processElement(context, tag, structureHandler, areaElement); } }