diff --git a/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectAdmincentralButtonBundle.java b/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectAdmincentralButtonBundle.java new file mode 100644 index 0000000..d39b3f4 --- /dev/null +++ b/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectAdmincentralButtonBundle.java @@ -0,0 +1,74 @@ +/** + * This file Copyright (c) 2014 Magnolia International + * Ltd. (http://www.magnolia-cms.com). All rights reserved. + * + * + * This file is dual-licensed under both the Magnolia + * Network Agreement and the GNU General Public License. + * You may elect to use one or the other of these licenses. + * + * This file is distributed in the hope that it will be + * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. + * Redistribution, except as permitted by whichever of the GPL + * or MNA you select, is prohibited. + * + * 1. For the GPL license (GPL), you can redistribute and/or + * modify this file under the terms of the GNU General + * Public License, Version 3, as published by the Free Software + * Foundation. You should have received a copy of the GNU + * General Public License, Version 3 along with this program; + * if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * 2. For the Magnolia Network Agreement (MNA), this file + * and the accompanying materials are made available under the + * terms of the MNA which accompanies this distribution, and + * is available at http://www.magnolia-cms.com/mna.html + * + * Any modifications to this file must keep this entire header + * intact. + * + */ +package info.magnolia.module.cache.sitemesh.inject; + +import org.sitemesh.SiteMeshContext; +import org.sitemesh.content.ContentProperty; +import org.sitemesh.content.tagrules.TagRuleBundle; +import org.sitemesh.tagprocessor.State; +import org.sitemesh.tagprocessor.Tag; + +/** + * . + */ +public class InjectAdmincentralButtonBundle implements TagRuleBundle { + + private String injectionCode = "
"; + + private static final String BODY_TAG = "body"; + + @Override + public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) { + defaultState.addRule(BODY_TAG, new InjectRule(getInjectionCode(), Tag.Type.CLOSE)); + } + + @Override + public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) { + // No op. + } + + public String getInjectionCode() { + return injectionCode; + } + + public void setInjectionCode(String injectionCode) { + this.injectionCode = injectionCode; + } + +} diff --git a/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectRule.java b/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectRule.java new file mode 100644 index 0000000..4f98f21 --- /dev/null +++ b/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectRule.java @@ -0,0 +1,28 @@ +package info.magnolia.module.cache.sitemesh.inject; + +import java.io.IOException; + +import org.sitemesh.tagprocessor.BasicRule; +import org.sitemesh.tagprocessor.CustomTag; +import org.sitemesh.tagprocessor.Tag; +import org.sitemesh.tagprocessor.Tag.Type; + +/** + * . + */ +public class InjectRule extends BasicRule { + + private final String injectionCode; + private Type tagType; + + public InjectRule(String injectionCode, Type tagType) { + this.injectionCode = injectionCode; + this.tagType = tagType; + } + + @Override + public void process(Tag tag) throws IOException { + CustomTag customTag = new InjectionTag(tag, injectionCode, tagType); + customTag.writeTo(tagProcessorContext.currentBuffer()); + } +} diff --git a/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectionTag.java b/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectionTag.java new file mode 100644 index 0000000..4dbf07e --- /dev/null +++ b/src/main/java/info/magnolia/module/cache/sitemesh/inject/InjectionTag.java @@ -0,0 +1,49 @@ +package info.magnolia.module.cache.sitemesh.inject; + +import info.magnolia.cms.core.AggregationState; +import info.magnolia.context.MgnlContext; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; + +import org.apache.commons.lang3.StringUtils; +import org.sitemesh.tagprocessor.CustomTag; +import org.sitemesh.tagprocessor.Tag; + +/** + * . + */ +public class InjectionTag extends CustomTag { + + private String injectionCode; + private final String ADMINCENTRAL_URL_PARAMETER = "{$admincentralURL}"; + private Collection