Permalink
Browse files

combined Filter and service and used addInstance method for configura…

…tion
  • Loading branch information...
1 parent bc3026d commit 5c34ec3e4698dff8e429c75ae4abe20632bd201d @robink committed Jan 24, 2010
@@ -1,6 +1,5 @@
package com.spreadthesource.tapestry.ganalytics.services;
-import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
@@ -9,15 +8,13 @@
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.services.ClientInfrastructure;
import org.apache.tapestry5.services.Environment;
-import org.apache.tapestry5.services.MarkupRenderer;
import org.apache.tapestry5.services.MarkupRendererFilter;
import com.spreadthesource.tapestry.ganalytics.GAnalyticsConstants;
-import com.spreadthesource.tapestry.ganalytics.services.impl.GAnalyticsScriptsInjectorImpl;
public class GAnalyticsModule {
public static void bind(ServiceBinder binder) {
- binder.bind(GAnalyticsScriptsInjector.class, GAnalyticsScriptsInjectorImpl.class);
+ binder.bind(GAnalyticsScriptsInjector.class, GAnalyticsScriptsInjector.class);
}
public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration) {
@@ -29,15 +26,7 @@ public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter>
final ClientInfrastructure clientInfrastructure) {
if (productionMode) {
- MarkupRendererFilter injectGAnalyticsScript = new MarkupRendererFilter() {
- public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
- renderer.renderMarkup(writer);
-
- scriptInjector.addScript(writer.getDocument());
- }
- };
-
- configuration.add("GAnalyticsScript", injectGAnalyticsScript, "after:RenderSupport");
+ configuration.addInstance("GAnalyticsScript", GAnalyticsScriptsInjector.class, "after:RenderSupport");
}
}
@@ -1,9 +1,57 @@
package com.spreadthesource.tapestry.ganalytics.services;
+import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.dom.Document;
+import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
+import org.apache.tapestry5.services.MarkupRenderer;
+import org.apache.tapestry5.services.MarkupRendererFilter;
-public interface GAnalyticsScriptsInjector {
+import com.spreadthesource.tapestry.ganalytics.GAnalyticsConstants;
+import com.spreadthesource.tapestry.ganalytics.GAnalyticsScriptsMessages;
+import com.spreadthesource.tapestry.ganalytics.services.GAnalyticsScriptsInjector;
- public void addScript(Document document);
+public class GAnalyticsScriptsInjector implements MarkupRendererFilter {
+
+ private final static Messages SCRIPTS = MessagesImpl.forClass(GAnalyticsScriptsMessages.class);
+
+ private final String key;
+
+ public GAnalyticsScriptsInjector(@Inject @Symbol(GAnalyticsConstants.GANALYTICS_KEY) String key) {
+ this.key = key;
+ }
+
+ private void addScript(Document document) {
+ if (key != null && !key.trim().equals("")) {
+ Element root = document.getRootElement();
+
+ if (root == null)
+ return;
+
+ Element body = root.find("body");
+
+ if (body == null) {
+ body = root.element("body");
+ }
+
+ Element e = body.element("script", "type", "text/javascript");
+
+ e.raw(SCRIPTS.get("scriptOne"));
+
+ e = body.element("script", "type", "text/javascript");
+
+ e.raw(SCRIPTS.format("scriptTwo", key));
+
+ }
+ }
+
+ public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
+ renderer.renderMarkup(writer);
+
+ this.addScript(writer.getDocument());
+ }
}
@@ -1,48 +0,0 @@
-package com.spreadthesource.tapestry.ganalytics.services.impl;
-
-import org.apache.tapestry5.dom.Document;
-import org.apache.tapestry5.dom.Element;
-import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
-
-import com.spreadthesource.tapestry.ganalytics.GAnalyticsConstants;
-import com.spreadthesource.tapestry.ganalytics.GAnalyticsScriptsMessages;
-import com.spreadthesource.tapestry.ganalytics.services.GAnalyticsScriptsInjector;
-
-public class GAnalyticsScriptsInjectorImpl implements GAnalyticsScriptsInjector {
-
- private final static Messages SCRIPTS = MessagesImpl.forClass(GAnalyticsScriptsMessages.class);
-
- private final String key;
-
- public GAnalyticsScriptsInjectorImpl(@Inject @Symbol(GAnalyticsConstants.GANALYTICS_KEY) String key) {
- this.key = key;
- }
-
- public void addScript(Document document) {
- if (key != null && !key.trim().equals("")) {
- Element root = document.getRootElement();
-
- if (root == null)
- return;
-
- Element body = root.find("body");
-
- if (body == null) {
- body = root.element("body");
- }
-
- Element e = body.element("script", "type", "text/javascript");
-
- e.raw(SCRIPTS.get("scriptOne"));
-
- e = body.element("script", "type", "text/javascript");
-
- e.raw(SCRIPTS.format("scriptTwo", key));
-
- }
- }
-
-}

0 comments on commit 5c34ec3

Please sign in to comment.