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 = "
Go to Admin Central
"; + + 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 tagTypes; + + public InjectionTag(Tag tag, String injectionCode, Tag.Type... tagTypes) { + super(tag); + this.tagTypes = Arrays.asList(tagTypes); + this.injectionCode = injectionCode; + } + + @Override + public void writeTo(Appendable out) throws IOException { + if (!tagTypes.contains(this.getType())) { + return; + } + String processedInjectionCode = this.processCodeBeforeInjection(injectionCode); + out.append(processedInjectionCode); + super.writeTo(out); + } + + private String processCodeBeforeInjection(String code) { + if (StringUtils.contains(code, ADMINCENTRAL_URL_PARAMETER)) { + AggregationState aggregationState = MgnlContext.getAggregationState(); + String url = StringUtils.substringBeforeLast(aggregationState.getOriginalURL(), aggregationState.getOriginalURI()); + url += "/.magnolia/admincentral"; + code = StringUtils.replace(code, ADMINCENTRAL_URL_PARAMETER, url); + } + return code; + } + +} diff --git a/src/main/java/info/magnolia/module/cache/sitemesh/inject/config.server.filters.sitemesh.decoratedFilter.contentProcessor.tagRuleBundlesWrapper.injectAdmincentralButton.xml b/src/main/java/info/magnolia/module/cache/sitemesh/inject/config.server.filters.sitemesh.decoratedFilter.contentProcessor.tagRuleBundlesWrapper.injectAdmincentralButton.xml new file mode 100644 index 0000000..f5b13c2 --- /dev/null +++ b/src/main/java/info/magnolia/module/cache/sitemesh/inject/config.server.filters.sitemesh.decoratedFilter.contentProcessor.tagRuleBundlesWrapper.injectAdmincentralButton.xml @@ -0,0 +1,39 @@ + + + + mgnl:contentNode + + + 63727bff-d5bc-4e8b-9cd7-402880a56dd4 + + + info.magnolia.module.cache.sitemesh.inject.InjectAdmincentralButtonBundle + + + <div id="mgnlAdmincentralButtonArea" style="position: absolute !important; z-index: 900 !important; top: 0pt !important; left: 0pt !important; padding: 5px 3px 0 3px !important; height: 20px !important;"><a class="mgnlAdmincentralButton" href="{$admincentralURL}" style="height: 19px !important; padding: 1px 10px !important; border-top: 1px solid #9dc114 !important; border-left: 1px solid #9dc114 !important; border-bottom: 1px solid #284f04 !important; border-right: 1px solid #284f04 !important; color: #f0f2e6 !important; background-color: #538d0b !important; font-family: Verdana, sans-serif !important; font-size: 11px !important; text-decoration: none !important;">Go to Admin Central</a>;<script> if (document.referrer.indexOf(".magnolia") > -1) { document.getElementById("mgnlAdmincentralButtonArea").style.display = "none"; } </script></div> + + + admin + + + false + + + 2014-08-18T09:38:28.425+02:00 + + + superuser + + + 2014-08-18T09:38:28.426+02:00 + + + superuser + + + 2014-08-18T09:55:37.984+02:00 + + + superuser + +