Class XMLDecoder

  • All Implemented Interfaces:
    Decoder

    public class XMLDecoder
    extends java.lang.Object
    implements Decoder
    Decodes Logging Events in XML formated into elements that are used by Chainsaw. 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. NOTE: This class has been created on the assumption that all XML log files are encoded in UTF-8. There is no current support for any other encoding format at this time.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map additionalProperties
      Additional properties.
      private static java.lang.String BEGINPART
      Document prolog.
      private javax.xml.parsers.DocumentBuilder docBuilder
      Document builder.
      private static java.lang.String ENCODING  
      private static java.lang.String ENDPART
      Document close.
      private java.awt.Component owner
      Owner.
      private java.lang.String partialEvent
      Partial event.
      private static java.lang.String RECORD_END
      Record end.
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLDecoder()
      Create new instance.
      XMLDecoder​(java.awt.Component o)
      Create new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.log4j.spi.LoggingEvent decode​(java.lang.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.
      java.util.Vector decode​(java.net.URL url)
      Decodes a File into a Vector of LoggingEvents.
      java.util.Vector decodeEvents​(java.lang.String document)
      Decodes a String representing a number of events into a Vector of LoggingEvents.
      private java.util.Vector decodeEvents​(org.w3c.dom.Document document)
      Given a Document, converts the XML into a Vector of LoggingEvents.
      private java.lang.String getCData​(org.w3c.dom.Node n)
      Get contents of CDATASection.
      private org.w3c.dom.Document parse​(java.lang.String data)
      Converts the LoggingEvent data in XML string format into an actual XML Document class instance.
      void setAdditionalProperties​(java.util.Map properties)
      Sets an additionalProperty map, where each Key/Value pair is automatically added to each LoggingEvent as it is decoded.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BEGINPART

        private static final java.lang.String BEGINPART
        Document prolog.
        See Also:
        Constant Field Values
      • RECORD_END

        private static final java.lang.String RECORD_END
        Record end.
        See Also:
        Constant Field Values
      • docBuilder

        private javax.xml.parsers.DocumentBuilder docBuilder
        Document builder.
      • additionalProperties

        private java.util.Map additionalProperties
        Additional properties.
      • partialEvent

        private java.lang.String partialEvent
        Partial event.
      • owner

        private java.awt.Component owner
        Owner.
    • Constructor Detail

      • XMLDecoder

        public XMLDecoder​(java.awt.Component o)
        Create new instance.
        Parameters:
        o - owner
      • XMLDecoder

        public XMLDecoder()
        Create new instance.
    • Method Detail

      • setAdditionalProperties

        public void setAdditionalProperties​(java.util.Map properties)
        Sets an additionalProperty map, where each Key/Value pair is automatically added to each LoggingEvent as it is decoded. This is useful, say, to include the source file name of the Logging events
        Specified by:
        setAdditionalProperties in interface Decoder
        Parameters:
        properties - additional properties
      • parse

        private org.w3c.dom.Document parse​(java.lang.String data)
        Converts the LoggingEvent data in XML string format into an actual XML Document class instance.
        Parameters:
        data - XML fragment
        Returns:
        dom document
      • decode

        public java.util.Vector decode​(java.net.URL url)
                                throws java.io.IOException
        Decodes a File into a Vector of LoggingEvents.
        Specified by:
        decode in interface Decoder
        Parameters:
        url - the url of a file containing events to decode
        Returns:
        Vector of LoggingEvents
        Throws:
        java.io.IOException - if IO error during processing.
      • decodeEvents

        public java.util.Vector decodeEvents​(java.lang.String document)
        Decodes a String representing a number of events into a Vector of LoggingEvents.
        Specified by:
        decodeEvents in interface Decoder
        Parameters:
        document - to decode events from
        Returns:
        Vector of LoggingEvents
      • decode

        public org.apache.log4j.spi.LoggingEvent decode​(java.lang.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.
        Specified by:
        decode in interface Decoder
        Parameters:
        data - XML fragment
        Returns:
        a single LoggingEvent or null
      • decodeEvents

        private java.util.Vector decodeEvents​(org.w3c.dom.Document document)
        Given a Document, converts the XML into a Vector of LoggingEvents.
        Parameters:
        document - XML document
        Returns:
        Vector of LoggingEvents
      • getCData

        private java.lang.String getCData​(org.w3c.dom.Node n)
        Get contents of CDATASection.
        Parameters:
        n - CDATASection
        Returns:
        text content of all text or CDATA children of node.