You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/04/12 20:59:03 UTC

svn commit: r528091 - in /logging/log4j/trunk/src/java/org/apache/log4j: helpers/UtilLoggingLevel.java spi/Decoder.java varia/ListModelAppender.java xml/UtilLoggingEntityResolver.java xml/UtilLoggingXMLDecoder.java xml/XMLDecoder.java

Author: carnold
Date: Thu Apr 12 11:59:02 2007
New Revision: 528091

URL: http://svn.apache.org/viewvc?view=rev&rev=528091
Log:
Bug 42092: Checkstyle fixes in o.a.l.xml and others

Modified:
    logging/log4j/trunk/src/java/org/apache/log4j/helpers/UtilLoggingLevel.java
    logging/log4j/trunk/src/java/org/apache/log4j/spi/Decoder.java
    logging/log4j/trunk/src/java/org/apache/log4j/varia/ListModelAppender.java
    logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
    logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java
    logging/log4j/trunk/src/java/org/apache/log4j/xml/XMLDecoder.java

Modified: logging/log4j/trunk/src/java/org/apache/log4j/helpers/UtilLoggingLevel.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/helpers/UtilLoggingLevel.java?view=diff&rev=528091&r1=528090&r2=528091
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/helpers/UtilLoggingLevel.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/helpers/UtilLoggingLevel.java Thu Apr 12 11:59:02 2007
@@ -26,6 +26,8 @@
  * An extension of the Level class that provides support for java.util.logging
  * Levels.
  *
+ * @since 1.3
+ *
  * @author Scott Deboy (sdeboy@apache.org)
  */
 

Modified: logging/log4j/trunk/src/java/org/apache/log4j/spi/Decoder.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/spi/Decoder.java?view=diff&rev=528091&r1=528090&r2=528091
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/spi/Decoder.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/spi/Decoder.java Thu Apr 12 11:59:02 2007
@@ -27,17 +27,38 @@
 
 
 /**
- *  Allow LoggingEvents to be reconstructed from a different format 
+ *  Allow LoggingEvents to be reconstructed from a different format
  * (usually XML).
  *
- *  @author Scott Deboy <sd...@apache.org>
+ *  @author Scott Deboy (sdeboy@apache.org)
+ *  @since 1.3
  */
 public interface Decoder {
+    /**
+     * Decode events from document.
+     * @param document document to decode.
+     * @return list of LoggingEvent instances.
+     */
   Vector decodeEvents(String document);
 
+    /**
+     * Decode event from string.
+     * @param event string representation of event
+     * @return event
+     */
   LoggingEvent decode(String event);
 
+    /**
+     * Decode event from document retreived from URL.
+     * @param url url of document
+     * @return list of LoggingEvent instances.
+     * @throws IOException if IO error resolving document.
+     */
   Vector decode(URL url) throws IOException;
 
+    /**
+     * Sets additional properties.
+     * @param additionalProperties map of additional properties.
+     */
   void setAdditionalProperties(Map additionalProperties);
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/varia/ListModelAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/varia/ListModelAppender.java?view=diff&rev=528091&r1=528090&r2=528091
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/varia/ListModelAppender.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/varia/ListModelAppender.java Thu Apr 12 11:59:02 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,10 +28,15 @@
  * A very basic appender that takes the events and stores them in to a
  * ListModel for late retrieval.
  *
- * @author Paul Smith <ps...@apache.org>
+ * @since 1.3
+ *
+ * @author Paul Smith (psmith@apache.org)
  *
  */
 public final class ListModelAppender extends AppenderSkeleton {
+    /**
+     * Default list model.
+     */
   private final DefaultListModel model = new DefaultListModel();
 
   /**
@@ -43,38 +48,31 @@
   /**
    * Returns a reference to the ListModel that contains all the LoggingEvents
    * that have been appended to this class.
-   * 
+   *
    * @return the list model
    */
-  public final ListModel getModel() {
+  public ListModel getModel() {
     return model;
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
-   */
-  protected void append(LoggingEvent event) {
+    /** {@inheritDoc} */
+  protected void append(final LoggingEvent event) {
     model.addElement(event);
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.log4j.Appender#close()
-   */
+    /** {@inheritDoc} */
   public void close() {
     clearModel();
   }
 
   /**
-   * Removes all the Events from the model
+   * Removes all the Events from the model.
    */
   public void clearModel() {
     model.clear();
   }
 
-    /**
-     * Gets whether appender requires a layout.
-     * @return false
-     */
+    /** {@inheritDoc} */
   public boolean requiresLayout() {
       return false;
   }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java?view=diff&rev=528091&r1=528090&r2=528091
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingEntityResolver.java Thu Apr 12 11:59:02 2007
@@ -26,17 +26,27 @@
 
 /**
  * An {@link EntityResolver} specifically designed to return
- * <code>java 1.4's logging dtd, logger.dtd</code> which is embedded within the log4j jar
- * file.  Based on EntityResolver.
+ * <code>java 1.4's logging dtd, logger.dtd</code>
+ * which is embedded within the log4j jar file.  Based on EntityResolver.
+ *
+ * @since 1.3
  *
  * @author Paul Austin
- * @author Scott Deboy <sd...@apache.org>
+ * @author Scott Deboy (sdeboy@apache.org)
  */
-public class UtilLoggingEntityResolver implements EntityResolver {
-  
-  
-  
-  public InputSource resolveEntity(String publicId, String systemId) {
+public final class UtilLoggingEntityResolver implements EntityResolver {
+
+    /**
+     * Create new instance.
+     */
+    public UtilLoggingEntityResolver() {
+        super();
+    }
+
+
+    /** {@inheritDoc} */
+  public InputSource resolveEntity(final String publicId,
+                                   final String systemId) {
     if (systemId.endsWith("logger.dtd")) {
       Class clazz = getClass();
       InputStream in =

Modified: logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java?view=diff&rev=528091&r1=528090&r2=528091
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java Thu Apr 12 11:59:02 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,32 +49,62 @@
 
 
 /**
- * Decodes JDK 1.4's java.util.logging package events delivered via XML (using the logger.dtd).
+ * Decodes JDK 1.4's java.util.logging package events
+ * delivered via XML (using the logger.dtd).
  *
- * @author Scott Deboy <sd...@apache.org>
- * @author Paul Smith <ps...@apache.org>
+ * @author Scott Deboy (sdeboy@apache.org)
+ * @author Paul Smith (psmith@apache.org)
+ * @since 1.3
  *
  */
 public class UtilLoggingXMLDecoder implements Decoder {
   //NOTE: xml section is only handed on first delivery of events
   //on this first delivery of events, there is no end tag for the log element
+  /**
+   * Document prolog.
+   */
   private static final String BEGIN_PART =
-    "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><!DOCTYPE log SYSTEM \"logger.dtd\"><log>";
-  private static final String END_PART= "</log>";
-  private DocumentBuilderFactory dbf;
+    "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+    + "<!DOCTYPE log SYSTEM \"logger.dtd\"><log>";
+    /**
+     * Document close.
+     */
+  private static final String END_PART = "</log>";
+    /**
+     * Document builder.
+     */
   private DocumentBuilder docBuilder;
+    /**
+     * Additional properties.
+     */
   private Map additionalProperties = new HashMap();
+    /**
+     * Partial event.
+     */
   private String partialEvent;
-  private static final String RECORD_END="</record>";
+    /**
+     * Record end.
+     */
+  private static final String RECORD_END = "</record>";
+    /**
+     * Owner.
+     */
   private Component owner = null;
 
-  public UtilLoggingXMLDecoder(Component owner) {
+    /**
+     * Create new instance.
+     * @param o owner
+     */
+  public UtilLoggingXMLDecoder(final Component o) {
       this();
-      this.owner = owner;
+      this.owner = o;
   }
-  
+
+    /**
+     * Create new instance.
+     */
   public UtilLoggingXMLDecoder() {
-    dbf = DocumentBuilderFactory.newInstance();
+    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setValidating(false);
 
     try {
@@ -91,19 +121,19 @@
    * automatically added to each LoggingEvent as it is decoded.
    *
    * This is useful, say, to include the source file name of the Logging events
-   * @param additionalProperties
+   * @param properties additional properties
    */
-  public void setAdditionalProperties(Map additionalProperties) {
-    this.additionalProperties.putAll(additionalProperties);
+  public void setAdditionalProperties(final Map properties) {
+    this.additionalProperties.putAll(properties);
   }
 
   /**
    * Converts the LoggingEvent data in XML string format into an actual
    * XML Document class instance.
-   * @param data
-   * @return dom document
+   * @param data XML fragment
+   * @return  XML document
    */
-  private Document parse(String data) {
+  private Document parse(final String data) {
     if (docBuilder == null || data == null) {
       return null;
     }
@@ -144,15 +174,18 @@
   }
 
   /**
-   * Decodes a File into a Vector of LoggingEvents
+   * Decodes a File into a Vector of LoggingEvents.
    * @param url the url of a file containing events to decode
    * @return Vector of LoggingEvents
-   * @throws IOException
+   * @throws IOException if IO error during processing.
    */
-  public Vector decode(URL url) throws IOException {
+  public Vector decode(final URL url) throws IOException {
     LineNumberReader reader = null;
     if (owner != null) {
-        reader = new LineNumberReader(new InputStreamReader(new ProgressMonitorInputStream(owner, "Loading " + url , url.openStream())));
+        reader = new LineNumberReader(
+                new InputStreamReader(
+                        new ProgressMonitorInputStream(owner,
+                                "Loading " + url , url.openStream())));
     } else {
         reader = new LineNumberReader(new InputStreamReader(url.openStream()));
     }
@@ -162,7 +195,7 @@
     try {
         while ((line = reader.readLine()) != null) {
             StringBuffer buffer = new StringBuffer(line);
-            for (int i = 0;i<100;i++) {
+            for (int i = 0; i < 100; i++) {
                 buffer.append(reader.readLine());
             }
             v.addAll(decodeEvents(buffer.toString()));
@@ -181,57 +214,63 @@
   }
 
   /**
-   * Decodes a String representing a number of events into a Vector of LoggingEvents
+   * Decodes a String representing a number of events into a
+   * Vector of LoggingEvents.
    * @param document to decode events from
    * @return Vector of LoggingEvents
    */
-  public Vector decodeEvents(String document) {
-  	
-    if (document != null) {
+  public Vector decodeEvents(final String document) {
 
-      if (document.equals("")) {
-        return null;
-      }
+      if (document != null) {
 
-	  	String newDoc=null;
-	  	String newPartialEvent=null;
-	  	//separate the string into the last portion ending with </record> (which will
-	  	//be processed) and the partial event which will be combined and processed in the next section
-	
-		//if the document does not contain a record end, append it to the partial event string
-		if (document.lastIndexOf(RECORD_END) == -1) {
-			partialEvent = partialEvent + document;
-			return null;
-		}
-	
-	  	if (document.lastIndexOf(RECORD_END) + RECORD_END.length() < document.length()) {
-	      	newDoc = document.substring(0, document.lastIndexOf(RECORD_END) + RECORD_END.length());
-			newPartialEvent = document.substring(document.lastIndexOf(RECORD_END) + RECORD_END.length());
-	 	} else {
-	  		newDoc = document;
-	  	}
-		if (partialEvent != null) {
-			newDoc=partialEvent + newDoc;
-		}	      		
-	  	partialEvent=newPartialEvent;
-	  	
-	    Document doc = parse(newDoc);
-	    if (doc == null) {
-	      return null;
-	    }
-	    return decodeEvents(doc);
-	  }
-    return null;
+          if (document.equals("")) {
+              return null;
+          }
+
+          String newDoc;
+          String newPartialEvent = null;
+          //separate the string into the last portion ending with </record>
+          // (which willbe processed) and the partial event which
+          // will be combined and processed in the next section
+
+          //if the document does not contain a record end,
+          // append it to the partial event string
+          if (document.lastIndexOf(RECORD_END) == -1) {
+              partialEvent = partialEvent + document;
+              return null;
+          }
+
+          if (document.lastIndexOf(RECORD_END) + RECORD_END.length()
+                  < document.length()) {
+              newDoc = document.substring(0,
+                      document.lastIndexOf(RECORD_END) + RECORD_END.length());
+              newPartialEvent = document.substring(
+                      document.lastIndexOf(RECORD_END) + RECORD_END.length());
+          } else {
+              newDoc = document;
+          }
+          if (partialEvent != null) {
+              newDoc = partialEvent + newDoc;
+          }
+          partialEvent = newPartialEvent;
+
+          Document doc = parse(newDoc);
+          if (doc == null) {
+              return null;
+          }
+          return decodeEvents(doc);
+      }
+      return null;
   }
 
-  /**
-   * Converts the string data into an XML Document, and then soaks out the
-   * relevant bits to form a new LoggingEvent instance which can be used
-   * by any Log4j element locally.
-   * @param data
-   * @return a single LoggingEvent
-   */
-  public LoggingEvent decode(String data) {
+    /**
+      * Converts the string data into an XML Document, and then soaks out the
+      * relevant bits to form a new LoggingEvent instance which can be used
+      * by any Log4j element locally.
+      * @param data XML fragment
+      * @return a single LoggingEvent or null
+      */
+  public LoggingEvent decode(final String data) {
     Document document = parse(data);
 
     if (document == null) {
@@ -248,11 +287,11 @@
   }
 
   /**
-   * Given a Document, converts the XML into a Vector of LoggingEvents
-   * @param document
+   * Given a Document, converts the XML into a Vector of LoggingEvents.
+   * @param document XML document
    * @return vector of logging events
    */
-  private Vector decodeEvents(Document document) {
+  private Vector decodeEvents(final Document document) {
     Vector events = new Vector();
 
     NodeList eventList = document.getElementsByTagName("record");
@@ -358,14 +397,17 @@
           while (i.hasNext()) {
             Map.Entry e = (Map.Entry) i.next();
             if (!(properties.containsKey(e.getKey()))) {
-            	properties.put(e.getKey(), e.getValue());
+                properties.put(e.getKey(), e.getValue());
             }
           }
         }
       }
 
       LocationInfo info = null;
-      if ((fileName != null) || (className != null) || (methodName != null) || (lineNumber != null)) {
+      if ((fileName != null)
+              || (className != null)
+              || (methodName != null)
+              || (lineNumber != null)) {
           info = new LocationInfo(fileName, className, methodName, lineNumber);
       } else {
         info = LocationInfo.NA_LOCATION_INFO;
@@ -374,7 +416,7 @@
       if (exception == null) {
           exception = new String[]{""};
       }
-      
+
       LoggingEvent loggingEvent = new LoggingEvent();
       loggingEvent.setLogger(logger);
       loggingEvent.setTimeStamp(timeStamp);
@@ -385,26 +427,19 @@
       loggingEvent.setThrowableInformation(new ThrowableInformation(exception));
       loggingEvent.setLocationInformation(info);
       loggingEvent.setProperties(properties);
-      
+
       events.add(loggingEvent);
 
-      logger = null;
-      timeStamp = 0L;
-      level = null;
-      threadName = null;
-      message = null;
-      ndc = null;
-      exception = null;
-      className = null;
-      methodName = null;
-      fileName = null;
-      lineNumber = null;
-      properties = null;
     }
     return events;
   }
 
-  private String getCData(Node n) {
+    /**
+     * Get contents of CDATASection.
+     * @param n CDATASection
+     * @return text content of all text or CDATA children of node.
+     */
+  private String getCData(final Node n) {
     StringBuffer buf = new StringBuffer();
     NodeList nl = n.getChildNodes();
 

Modified: logging/log4j/trunk/src/java/org/apache/log4j/xml/XMLDecoder.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/xml/XMLDecoder.java?view=diff&rev=528091&r1=528090&r2=528091
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/xml/XMLDecoder.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/xml/XMLDecoder.java Thu Apr 12 11:59:02 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -50,33 +50,68 @@
  * Decodes Logging Events in XML formated into elements that are used by
  * Chainsaw.
  *
- * This decoder can process a collection of log4j:event nodes ONLY 
+ * This decoder can process a collection of log4j:event nodes ONLY
  * (no XML declaration nor eventSet node)
- * 
+ *
  * NOTE:  Only a single LoggingEvent is returned from the decode method
  * even though the DTD supports multiple events nested in an eventSet.
  *
- * @author Scott Deboy <sd...@apache.org>
- * @author Paul Smith <ps...@apache.org>
+ * @since 1.3
+ *
+ * @author Scott Deboy (sdeboy@apache.org)
+ * @author Paul Smith (psmith@apache.org)
  *
  */
 public class XMLDecoder implements Decoder {
+    /**
+     * Document prolog.
+     */
   private static final String BEGINPART =
-    "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><!DOCTYPE log4j:eventSet SYSTEM \"log4j.dtd\"><log4j:eventSet version=\"1.2\" xmlns:log4j=\"http://jakarta.apache.org/log4j/\">";
+    "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+    + "<!DOCTYPE log4j:eventSet SYSTEM \"log4j.dtd\">"
+    + "<log4j:eventSet version=\"1.2\" "
+    + "xmlns:log4j=\"http://jakarta.apache.org/log4j/\">";
+    /**
+     * Document close.
+     */
   private static final String ENDPART = "</log4j:eventSet>";
+    /**
+     * Record end.
+     */
   private static final String RECORD_END = "</log4j:event>";
-  private DocumentBuilderFactory dbf;
+
+    /**
+     * Document builder.
+     */
   private DocumentBuilder docBuilder;
+    /**
+     * Additional properties.
+     */
   private Map additionalProperties = new HashMap();
+    /**
+     * Partial event.
+     */
   private String partialEvent;
+    /**
+     * Owner.
+     */
   private Component owner = null;
 
-  public XMLDecoder(Component owner) {
+    /**
+     * Create new instance.
+     * @param o owner
+     */
+  public XMLDecoder(final Component o) {
       this();
-      this.owner = owner;
+      this.owner = o;
   }
-  public XMLDecoder() {
-    dbf = DocumentBuilderFactory.newInstance();
+
+    /**
+     * Create new instance.
+     */
+   public XMLDecoder() {
+    super();
+    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     dbf.setValidating(false);
 
     try {
@@ -93,19 +128,19 @@
    * automatically added to each LoggingEvent as it is decoded.
    *
    * This is useful, say, to include the source file name of the Logging events
-   * @param additionalProperties
+   * @param properties additional properties
    */
-  public void setAdditionalProperties(Map additionalProperties) {
-    this.additionalProperties = additionalProperties;
+  public void setAdditionalProperties(final Map properties) {
+    this.additionalProperties = properties;
   }
 
   /**
    * Converts the LoggingEvent data in XML string format into an actual
    * XML Document class instance.
-   * @param data
+   * @param data XML fragment
    * @return dom document
    */
-  private Document parse(String data) {
+  private Document parse(final String data) {
     if (docBuilder == null || data == null) {
       return null;
     }
@@ -140,32 +175,35 @@
   }
 
   /**
-   * Decodes a File into a Vector of LoggingEvents
+   * Decodes a File into a Vector of LoggingEvents.
    * @param url the url of a file containing events to decode
    * @return Vector of LoggingEvents
-   * @throws IOException
+   * @throws IOException if IO error during processing.
    */
-  public Vector decode(URL url) throws IOException {
-    LineNumberReader reader = null;
+  public Vector decode(final URL url) throws IOException {
+    LineNumberReader reader;
     if (owner != null) {
-      reader = new LineNumberReader(new InputStreamReader(new ProgressMonitorInputStream(owner, "Loading " + url , url.openStream())));
+      reader = new LineNumberReader(new InputStreamReader(
+              new ProgressMonitorInputStream(owner,
+                      "Loading " + url , url.openStream())));
     } else {
       reader = new LineNumberReader(new InputStreamReader(url.openStream()));
     }
 
     Vector v = new Vector();
 
-    String line = null;
-	Vector events = null;
+    String line;
+    Vector events;
     try {
         while ((line = reader.readLine()) != null) {
             StringBuffer buffer = new StringBuffer(line);
-            for (int i = 0;i<1000;i++) {
+            for (int i = 0; i < 1000; i++) {
                 buffer.append(reader.readLine()).append("\n");
             }
-			events = decodeEvents(buffer.toString());
-            if (events != null)
-            	v.addAll(events);
+            events = decodeEvents(buffer.toString());
+            if (events != null) {
+                v.addAll(events);
+            }
         }
     } finally {
       partialEvent = null;
@@ -180,37 +218,49 @@
     return v;
   }
 
-  public Vector decodeEvents(String document) {
+    /**
+     * Decodes a String representing a number of events into a
+     * Vector of LoggingEvents.
+     * @param document to decode events from
+     * @return Vector of LoggingEvents
+     */
+  public Vector decodeEvents(final String document) {
     if (document != null) {
       if (document.trim().equals("")) {
         return null;
       }
-	  	String newDoc=null;
-	  	String newPartialEvent=null;
-	  	//separate the string into the last portion ending with </log4j:event> (which will
-	  	//be processed) and the partial event which will be combined and processed in the next section
-	
-		//if the document does not contain a record end, append it to the partial event string
-	  	if (document.lastIndexOf(RECORD_END) == -1) {
-			partialEvent = partialEvent + document;
-	  		return null;
-	  	}
-	
-	  	if (document.lastIndexOf(RECORD_END) + RECORD_END.length() < document.length()) {
-	      	newDoc = document.substring(0, document.lastIndexOf(RECORD_END) + RECORD_END.length());
-			newPartialEvent = document.substring(document.lastIndexOf(RECORD_END) + RECORD_END.length());
-	 	} else {
-	  		newDoc = document;
-	  	}
-		if (partialEvent != null) {
-			newDoc=partialEvent + newDoc;
-		}	      		
-	  	partialEvent=newPartialEvent;
-	    Document doc = parse(newDoc);
-	    if (doc == null) {
-	      return null;
-	    }
-	    return decodeEvents(doc);
+        String newDoc = null;
+        String newPartialEvent = null;
+        //separate the string into the last portion ending with
+        // </log4j:event> (which will be processed) and the
+        // partial event which will be combined and
+        // processed in the next section
+
+        //if the document does not contain a record end,
+        // append it to the partial event string
+        if (document.lastIndexOf(RECORD_END) == -1) {
+            partialEvent = partialEvent + document;
+            return null;
+        }
+
+        if (document.lastIndexOf(RECORD_END)
+                + RECORD_END.length() < document.length()) {
+            newDoc = document.substring(0,
+                    document.lastIndexOf(RECORD_END) + RECORD_END.length());
+            newPartialEvent = document.substring(
+                    document.lastIndexOf(RECORD_END) + RECORD_END.length());
+        } else {
+            newDoc = document;
+        }
+        if (partialEvent != null) {
+            newDoc = partialEvent + newDoc;
+        }
+        partialEvent = newPartialEvent;
+        Document doc = parse(newDoc);
+        if (doc == null) {
+            return null;
+        }
+        return decodeEvents(doc);
     }
     return null;
   }
@@ -219,10 +269,10 @@
    * Converts the string data into an XML Document, and then soaks out the
    * relevant bits to form a new LoggingEvent instance which can be used
    * by any Log4j element locally.
-   * @param data
+   * @param data XML fragment
    * @return a single LoggingEvent
    */
-  public LoggingEvent decode(String data) {
+  public LoggingEvent decode(final String data) {
     Document document = parse(data);
 
     if (document == null) {
@@ -239,17 +289,17 @@
   }
 
   /**
-   * Given a Document, converts the XML into a Vector of LoggingEvents
-   * @param document
+   * Given a Document, converts the XML into a Vector of LoggingEvents.
+   * @param document XML document
    * @return Vector of LoggingEvents
    */
-  private Vector decodeEvents(Document document) {
+  private Vector decodeEvents(final Document document) {
     Vector events = new Vector();
 
-    Logger logger = null;
-    long timeStamp = 0L;
-    String level = null;
-    String threadName = null;
+    Logger logger;
+    long timeStamp;
+    String level;
+    String threadName;
     Object message = null;
     String ndc = null;
     String[] exception = null;
@@ -266,18 +316,18 @@
 
     for (int eventIndex = 0; eventIndex < eventList.getLength();
         eventIndex++) {
-      Node eventNode = eventList.item(eventIndex);
-      //ignore carriage returns in xml 
-	  if(eventNode.getNodeType() != Node.ELEMENT_NODE) {
-	  	continue;
-	  }
-      logger =
-        Logger.getLogger(
-          eventNode.getAttributes().getNamedItem("logger").getNodeValue());
+        Node eventNode = eventList.item(eventIndex);
+      //ignore carriage returns in xml
+        if (eventNode.getNodeType() != Node.ELEMENT_NODE) {
+            continue;
+        }
+        logger =
+            Logger.getLogger(
+               eventNode.getAttributes().getNamedItem("logger").getNodeValue());
       timeStamp =
         Long.parseLong(
           eventNode.getAttributes().getNamedItem("timestamp").getNodeValue());
-      level =eventNode.getAttributes().getNamedItem("level").getNodeValue();
+      level = eventNode.getAttributes().getNamedItem("level").getNodeValue();
       threadName =
         eventNode.getAttributes().getNamedItem("thread").getNodeValue();
 
@@ -315,7 +365,9 @@
         }
 
         if (tagName.equalsIgnoreCase("log4j:throwable")) {
-          exception = new String[] { getCData(list.item(y)) };
+          exception = new String[] {
+                  getCData(list.item(y))
+          };
         }
 
         if (tagName.equalsIgnoreCase("log4j:locationinfo")) {
@@ -362,16 +414,19 @@
             while (i.hasNext()) {
               Map.Entry e = (Map.Entry) i.next();
               if (!(properties.containsKey(e.getKey()))) {
-              	properties.put(e.getKey(), e.getValue());
+                properties.put(e.getKey(), e.getValue());
               }
             }
           }
         }
       }
       Level levelImpl = Level.toLevel(level);
-      
-      LocationInfo info = null;
-      if ((fileName != null) || (className != null) || (methodName != null) || (lineNumber != null)) {
+
+      LocationInfo info;
+      if ((fileName != null)
+              || (className != null)
+              || (methodName != null)
+              || (lineNumber != null)) {
           info = new LocationInfo(fileName, className, methodName, lineNumber);
       } else {
         info = LocationInfo.NA_LOCATION_INFO;
@@ -379,7 +434,7 @@
       if (exception == null) {
           exception = new String[]{""};
       }
-      
+
       LoggingEvent loggingEvent = new LoggingEvent();
       loggingEvent.setLogger(logger);
       loggingEvent.setTimeStamp(timeStamp);
@@ -390,13 +445,9 @@
       loggingEvent.setThrowableInformation(new ThrowableInformation(exception));
       loggingEvent.setLocationInformation(info);
       loggingEvent.setProperties(properties);
-      
+
       events.add(loggingEvent);
-     
-      logger = null;
-      timeStamp = 0L;
-      level = null;
-      threadName = null;
+
       message = null;
       ndc = null;
       exception = null;
@@ -410,7 +461,12 @@
     return events;
   }
 
-  private String getCData(Node n) {
+    /**
+     * Get contents of CDATASection.
+     * @param n CDATASection
+     * @return text content of all text or CDATA children of node.
+     */
+  private String getCData(final Node n) {
     StringBuffer buf = new StringBuffer();
     NodeList nl = n.getChildNodes();
 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org