You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by il...@apache.org on 2011/03/02 10:29:26 UTC

svn commit: r1076154 - in /cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component: LogAsXMLTransformer.java LogTransformer.java

Author: ilgrosso
Date: Wed Mar  2 09:29:25 2011
New Revision: 1076154

URL: http://svn.apache.org/viewvc?rev=1076154&view=rev
Log:
Patching Log*Transformer for letting ^Ctegration tests succeed

Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogTransformer.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java?rev=1076154&r1=1076153&r2=1076154&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java Wed Mar  2 09:29:25 2011
@@ -50,29 +50,33 @@ public final class LogAsXMLTransformer e
      */
     private static final Log LOG = LogFactory.getLog(LogAsXMLTransformer.class);
 
-    private final XMLSerializer xmlSerializer = XMLSerializer.createXMLSerializer();
-    
-    private OutputStream outputStream;
+    private final transient XMLSerializer xmlSerializer =
+            XMLSerializer.createXMLSerializer();
+
+    private transient OutputStream outputStream;
 
     public LogAsXMLTransformer() {
         this(null);
     }
 
-    public LogAsXMLTransformer(File logFile) {
+    public LogAsXMLTransformer(final File logFile) {
+        super();
+
         if (logFile == null) {
             this.init(System.out);
         } else {
             try {
                 this.init(new FileOutputStream(logFile));
             } catch (FileNotFoundException e) {
-                throw new SetupException("Impossible to create an XML log file '"
+                throw new SetupException(
+                        "Impossible to create an XML log file '"
                         + logFile
-                        + "'");
+                        + "'", e);
             }
         }
     }
 
-    private void init(OutputStream outputStream) {
+    private void init(final OutputStream outputStream) {
         this.xmlSerializer.setup(new HashMap<String, Object>());
         this.xmlSerializer.setOutputStream(outputStream);
         this.xmlSerializer.setIndent(true);
@@ -80,12 +84,14 @@ public final class LogAsXMLTransformer e
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> configuration) {
+    public void setConfiguration(
+            final Map<String, ? extends Object> configuration) {
+
         this.setup((Map<String, Object>) configuration);
     }
 
     @Override
-    public void setup(Map<String, Object> parameters) {
+    public void setup(final Map<String, Object> parameters) {
         if (parameters == null || !parameters.containsKey(LOG_FILE)) {
             return;
         }
@@ -110,7 +116,11 @@ public final class LogAsXMLTransformer e
         this.xmlSerializer.finish();
         if (this.outputStream != null) {
             try {
-                this.outputStream.close();
+                if (System.out.equals(this.outputStream)) {
+                    this.outputStream.flush();
+                } else {
+                    this.outputStream.close();
+                }
             } catch (IOException e) {
                 LOG.debug("Impossible to close the log writer", e);
             }
@@ -118,116 +128,148 @@ public final class LogAsXMLTransformer e
     }
 
     @Override
-    public void characters(char[] ch, int start, int length)
+    public void characters(final char[] ch, final int start, final int length)
             throws SAXException {
+
         this.xmlSerializer.characters(ch, start, length);
         super.characters(ch, start, length);
     }
 
     @Override
-    public void comment(char[] ch, int start, int length) throws SAXException {
+    public void comment(final char[] ch, final int start, final int length)
+            throws SAXException {
+
         this.xmlSerializer.comment(ch, start, length);
         super.comment(ch, start, length);
     }
 
     @Override
-    public void endCDATA() throws SAXException {
+    public void endCDATA()
+            throws SAXException {
+
         this.xmlSerializer.endCDATA();
         super.endCDATA();
     }
 
     @Override
-    public void endDocument() throws SAXException {
+    public void endDocument()
+            throws SAXException {
+
         this.xmlSerializer.endDocument();
         super.endDocument();
     }
 
     @Override
-    public void endDTD() throws SAXException {
+    public void endDTD()
+            throws SAXException {
+
         this.xmlSerializer.endDTD();
         super.endDTD();
     }
 
     @Override
-    public void endElement(String uri, String localName, String name)
+    public void endElement(final String uri, final String localName,
+            final String name)
             throws SAXException {
+
         this.xmlSerializer.endElement(uri, localName, name);
         super.endElement(uri, localName, name);
     }
 
     @Override
-    public void endEntity(String name) throws SAXException {
+    public void endEntity(final String name)
+            throws SAXException {
+
         this.xmlSerializer.endEntity(name);
         super.endEntity(name);
     }
 
     @Override
-    public void endPrefixMapping(String prefix) throws SAXException {
+    public void endPrefixMapping(final String prefix)
+            throws SAXException {
+
         this.xmlSerializer.endPrefixMapping(prefix);
         super.endPrefixMapping(prefix);
     }
 
     @Override
-    public void ignorableWhitespace(char[] ch, int start, int length)
+    public void ignorableWhitespace(final char[] ch,
+            final int start, final int length)
             throws SAXException {
+
         this.xmlSerializer.ignorableWhitespace(ch, start, length);
         super.ignorableWhitespace(ch, start, length);
     }
 
     @Override
-    public void processingInstruction(String target, String data)
+    public void processingInstruction(final String target, final String data)
             throws SAXException {
+
         this.xmlSerializer.processingInstruction(target, data);
         super.processingInstruction(target, data);
     }
 
     @Override
-    public void setDocumentLocator(Locator locator) {
+    public void setDocumentLocator(final Locator locator) {
+
         this.xmlSerializer.setDocumentLocator(locator);
         super.setDocumentLocator(locator);
     }
 
     @Override
-    public void skippedEntity(String name) throws SAXException {
+    public void skippedEntity(final String name)
+            throws SAXException {
+
         this.xmlSerializer.skippedEntity(name);
         super.skippedEntity(name);
     }
 
     @Override
-    public void startCDATA() throws SAXException {
+    public void startCDATA()
+            throws SAXException {
+
         this.xmlSerializer.startCDATA();
         super.startCDATA();
     }
 
     @Override
-    public void startDocument() throws SAXException {
+    public void startDocument()
+            throws SAXException {
+
         this.xmlSerializer.startDocument();
         super.startDocument();
     }
 
     @Override
-    public void startDTD(String name, String publicId, String systemId)
+    public void startDTD(final String name, final String publicId,
+            final String systemId)
             throws SAXException {
+
         this.xmlSerializer.startDTD(name, publicId, systemId);
         super.startDTD(name, publicId, systemId);
     }
 
     @Override
-    public void startElement(String uri, String localName, String name,
-            Attributes atts) throws SAXException {
+    public void startElement(final String uri, final String localName,
+            final String name, final Attributes atts)
+            throws SAXException {
+
         this.xmlSerializer.startElement(uri, localName, name, atts);
         super.startElement(uri, localName, name, atts);
     }
 
     @Override
-    public void startEntity(String name) throws SAXException {
+    public void startEntity(final String name)
+            throws SAXException {
+
         this.xmlSerializer.startEntity(name);
         super.startEntity(name);
     }
 
     @Override
-    public void startPrefixMapping(String prefix, String uri)
+    public void startPrefixMapping(final String prefix, final String uri)
             throws SAXException {
+
         this.xmlSerializer.startPrefixMapping(prefix, uri);
         super.startPrefixMapping(prefix, uri);
     }

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogTransformer.java?rev=1076154&r1=1076153&r2=1076154&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogTransformer.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogTransformer.java Wed Mar  2 09:29:25 2011
@@ -42,9 +42,11 @@ import org.xml.sax.SAXException;
  */
 public final class LogTransformer extends AbstractSAXTransformer {
 
-    private static final SimpleDateFormat ISO_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
+    private static final SimpleDateFormat ISO_FORMAT = new SimpleDateFormat(
+            "yyyy-MM-dd'T'hh:mm:ss");
 
-    private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n");
+    private static final String LINE_SEPARATOR = System.getProperty(
+            "line.separator", "\n");
 
     private static final String LOG_FILE = "logfile";
 
@@ -75,15 +77,20 @@ public final class LogTransformer extend
         this.dateFormat = ISO_FORMAT;
     }
 
-    public LogTransformer(File logFile, boolean append) throws IOException {
+    public LogTransformer(File logFile, boolean append)
+            throws IOException {
         this(logFile, append, ISO_FORMAT);
     }
 
-    public LogTransformer(File logFile, boolean append, String datePattern) throws IOException {
+    public LogTransformer(File logFile, boolean append, String datePattern)
+            throws IOException {
         this(logFile, append, new SimpleDateFormat(datePattern));
     }
 
-    public LogTransformer(File logFile, boolean append, SimpleDateFormat dateFormat) throws IOException {
+    public LogTransformer(File logFile, boolean append,
+            SimpleDateFormat dateFormat)
+            throws IOException {
+
         this.logWriter = new FileWriter(logFile, append);
         this.dateFormat = dateFormat;
     }
@@ -121,7 +128,8 @@ public final class LogTransformer extend
 
         Object datePatternString = parameters.get(DATE_PATTERN);
         if (datePatternString != null) {
-            this.dateFormat = new SimpleDateFormat(String.valueOf(datePatternString));
+            this.dateFormat = new SimpleDateFormat(String.valueOf(
+                    datePatternString));
         }
     }
 
@@ -129,7 +137,11 @@ public final class LogTransformer extend
     public void finish() {
         if (this.logWriter != null) {
             try {
-                this.logWriter.close();
+                if (System.out.equals(this.logWriter)) {
+                    this.logWriter.flush();
+                } else {
+                    this.logWriter.close();
+                }
             } catch (IOException e) {
                 this.log.debug("Impossible to close the log writer", e);
             }
@@ -144,25 +156,29 @@ public final class LogTransformer extend
     }
 
     @Override
-    public void comment(char[] ch, int start, int length) throws SAXException {
+    public void comment(char[] ch, int start, int length)
+            throws SAXException {
         this.log("comment", new String(ch, start, length));
         super.comment(ch, start, length);
     }
 
     @Override
-    public void endCDATA() throws SAXException {
+    public void endCDATA()
+            throws SAXException {
         this.log("endCDATA", null);
         super.endCDATA();
     }
 
     @Override
-    public void endDocument() throws SAXException {
+    public void endDocument()
+            throws SAXException {
         this.log("endDocument", null);
         super.endDocument();
     }
 
     @Override
-    public void endDTD() throws SAXException {
+    public void endDTD()
+            throws SAXException {
         this.log("endDTD", null);
         super.endDTD();
     }
@@ -180,19 +196,22 @@ public final class LogTransformer extend
     }
 
     @Override
-    public void endEntity(String name) throws SAXException {
+    public void endEntity(String name)
+            throws SAXException {
         this.log("endEntity", "name=" + name);
         super.endEntity(name);
     }
 
     @Override
-    public void endPrefixMapping(String prefix) throws SAXException {
+    public void endPrefixMapping(String prefix)
+            throws SAXException {
         this.log("endPrefixMapping", "prefix=" + prefix);
         super.endPrefixMapping(prefix);
     }
 
     @Override
-    public SAXBuffer endSAXRecording() throws SAXException {
+    public SAXBuffer endSAXRecording()
+            throws SAXException {
         this.log("endSAXRecording", null);
         return super.endSAXRecording();
     }
@@ -200,7 +219,7 @@ public final class LogTransformer extend
     @Override
     public void ignorableWhitespace(char[] ch, int start, int length)
             throws SAXException {
-        this.log("ignorableWhitespace", new String(ch,start,length));
+        this.log("ignorableWhitespace", new String(ch, start, length));
         super.ignorableWhitespace(ch, start, length);
     }
 
@@ -224,19 +243,22 @@ public final class LogTransformer extend
     }
 
     @Override
-    public void skippedEntity(String name) throws SAXException {
+    public void skippedEntity(String name)
+            throws SAXException {
         this.log("skippedEntity", "name=" + name);
         super.skippedEntity(name);
     }
 
     @Override
-    public void startCDATA() throws SAXException {
+    public void startCDATA()
+            throws SAXException {
         this.log("startCDATA", null);
         super.startCDATA();
     }
 
     @Override
-    public void startDocument() throws SAXException {
+    public void startDocument()
+            throws SAXException {
         this.log("startDocument", null);
         super.startDocument();
     }
@@ -255,7 +277,8 @@ public final class LogTransformer extend
 
     @Override
     public void startElement(String uri, String localName, String name,
-            Attributes atts) throws SAXException {
+            Attributes atts)
+            throws SAXException {
         this.log("startElement", "uri="
                 + uri
                 + ", localName="
@@ -264,23 +287,24 @@ public final class LogTransformer extend
                 + name);
         for (int i = 0; i < atts.getLength(); i++) {
             this.log("            ", (i + 1)
-                 + ". uri="
-                 + atts.getURI(i)
-                 + ", local="
-                 + atts.getLocalName(i)
-                 + ", qname="
-                 + atts.getQName(i)
-                 + ", type="
-                 + atts.getType(i)
-                 + ", value="
-                 + atts.getValue(i));
+                    + ". uri="
+                    + atts.getURI(i)
+                    + ", local="
+                    + atts.getLocalName(i)
+                    + ", qname="
+                    + atts.getQName(i)
+                    + ", type="
+                    + atts.getType(i)
+                    + ", value="
+                    + atts.getValue(i));
         }
         super.startElement(uri, localName, name, atts);
     }
 
     @Override
-    public void startEntity(String name) throws SAXException {
-        this.log ("startEntity", "name=" + name);
+    public void startEntity(String name)
+            throws SAXException {
+        this.log("startEntity", "name=" + name);
         super.startEntity(name);
     }
 
@@ -295,8 +319,9 @@ public final class LogTransformer extend
     }
 
     @Override
-    public void startSAXRecording() throws SAXException {
-        this.log ("startSAXRecording", null);
+    public void startSAXRecording()
+            throws SAXException {
+        this.log("startSAXRecording", null);
         super.startSAXRecording();
     }