cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject svn commit: r1639295 - in /cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main: java/org/apache/cocoon/stringtemplate/ resources/META-INF/cocoon/spring/
Date Thu, 13 Nov 2014 10:36:23 GMT
Author: andreas
Date: Thu Nov 13 10:36:22 2014
New Revision: 1639295

URL: http://svn.apache.org/r1639295
Log:
Log stringtemplate messages to slf4j instead of stdout.

Added:
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/LogErrorListener.java
Modified:
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/STRenderer.java
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/resources/META-INF/cocoon/spring/cocoon-stringtemplate-sitemap-components.xml

Added: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/LogErrorListener.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/LogErrorListener.java?rev=1639295&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/LogErrorListener.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/LogErrorListener.java
Thu Nov 13 10:36:22 2014
@@ -0,0 +1,32 @@
+package org.apache.cocoon.stringtemplate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.stringtemplate.v4.STErrorListener;
+import org.stringtemplate.v4.misc.STMessage;
+
+public class LogErrorListener implements STErrorListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(LogErrorListener.class);
+
+    @Override
+    public void IOError(STMessage msg) {
+        LOG.error("IO error: " + msg);
+    }
+
+    @Override
+    public void compileTimeError(STMessage msg) {
+        LOG.error("Compile time error: " + msg);
+    }
+
+    @Override
+    public void internalError(STMessage msg) {
+        LOG.error("Internal error: " + msg);
+    }
+
+    @Override
+    public void runTimeError(STMessage msg) {
+        LOG.error("Runtime error: " + msg);
+    }
+
+}

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/STRenderer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/STRenderer.java?rev=1639295&r1=1639294&r2=1639295&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/STRenderer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/STRenderer.java
Thu Nov 13 10:36:22 2014
@@ -18,13 +18,19 @@ package org.apache.cocoon.stringtemplate
 
 import java.io.IOException;
 import java.io.PrintStream;
+import java.io.StringWriter;
+import java.util.Locale;
 import java.util.Map;
+
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.stringtemplate.v4.AutoIndentWriter;
 import org.stringtemplate.v4.ST;
+import org.stringtemplate.v4.STErrorListener;
+import org.stringtemplate.v4.STWriter;
 
 public final class STRenderer {
 
@@ -36,10 +42,13 @@ public final class STRenderer {
     private static final STRenderer SINGLETON;
 
     static {
-        SINGLETON = new STRenderer();
+        SINGLETON = new STRenderer(new LogErrorListener());
     }
 
-    private STRenderer() {
+    private STErrorListener errorListener;
+
+    private STRenderer(STErrorListener errorListener) {
+        this.errorListener = errorListener;
         // Empty private constructor for singleton classes
     }
 
@@ -76,6 +85,10 @@ public final class STRenderer {
             }
         }
 
-        return stringTemplate.render();
+        StringWriter out = new StringWriter();
+        STWriter wr = new AutoIndentWriter(out);
+        wr.setLineWidth(STWriter.NO_WRAP);
+        stringTemplate.write(wr, Locale.getDefault(), this.errorListener);
+        return out.toString();
     }
 }

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/resources/META-INF/cocoon/spring/cocoon-stringtemplate-sitemap-components.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/resources/META-INF/cocoon/spring/cocoon-stringtemplate-sitemap-components.xml?rev=1639295&r1=1639294&r2=1639295&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/resources/META-INF/cocoon/spring/cocoon-stringtemplate-sitemap-components.xml
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/resources/META-INF/cocoon/spring/cocoon-stringtemplate-sitemap-components.xml
Thu Nov 13 10:36:22 2014
@@ -28,5 +28,5 @@
     <bean name="reader:string-template" class="org.apache.cocoon.stringtemplate.StringTemplateReader"
scope="prototype" />
 
     <bean name="transformer:string-template" class="org.apache.cocoon.stringtemplate.StringTemplateTransformer"
scope="prototype" />
-
+    
 </beans>



Mime
View raw message