Class Writer

  • All Implemented Interfaces:
    org.apache.xerces.xni.parser.XMLComponent, org.apache.xerces.xni.parser.XMLDocumentFilter, org.apache.xerces.xni.parser.XMLDocumentSource, org.apache.xerces.xni.XMLDocumentHandler, HTMLComponent

    public class Writer
    extends DefaultFilter
    An HTML writer written as a filter. Besides serializing the HTML event stream, the writer also passes the document events to the next stage in the pipeline. This allows applications to insert writer filters between other custom filters for debugging purposes.

    Since an HTML document may have specified its encoding using the <META> tag and http-equiv/content attributes, the writer will automatically change any character set specified in this tag to match the encoding of the output stream. Therefore, the character encoding name used to construct the writer should be an official IANA encoding name and not a Java encoding name.

    Note: The modified character set in the <META> tag is not propagated to the next stage in the pipeline. The changed value is only output to the stream; the original value is sent to the next stage in the pipeline.

    Version:
    $Id: Writer.java,v 1.7 2005/02/14 04:01:33 andyc Exp $
    Author:
    Andy Clark
    • Constructor Summary

      Constructors 
      Constructor Description
      Writer()
      Constructs a writer filter that prints to standard out.
      Writer​(java.io.OutputStream outputStream, java.lang.String encoding)
      Constructs a writer filter using the specified output stream and encoding.
      Writer​(java.io.Writer writer, java.lang.String encoding)
      Constructs a writer filter using the specified Java writer and encoding.
    • Field Detail

      • NOTIFY_CHAR_REFS

        public static final java.lang.String NOTIFY_CHAR_REFS
        Notify character entity references.
        See Also:
        Constant Field Values
      • NOTIFY_HTML_BUILTIN_REFS

        public static final java.lang.String NOTIFY_HTML_BUILTIN_REFS
        Notify built-in entity references.
        See Also:
        Constant Field Values
      • AUGMENTATIONS

        protected static final java.lang.String AUGMENTATIONS
        Augmentations feature identifier.
        See Also:
        Constant Field Values
      • FILTERS

        protected static final java.lang.String FILTERS
        Filters property identifier.
        See Also:
        Constant Field Values
      • fEncoding

        protected java.lang.String fEncoding
        The encoding.
      • fPrinter

        protected java.io.PrintWriter fPrinter
        The print writer used for serializing the document with the appropriate character encoding.
      • fSeenRootElement

        protected boolean fSeenRootElement
        Seen root element.
      • fSeenHttpEquiv

        protected boolean fSeenHttpEquiv
        Seen http-equiv directive.
      • fElementDepth

        protected int fElementDepth
        Element depth.
      • fNormalize

        protected boolean fNormalize
        Normalize character content.
      • fPrintChars

        protected boolean fPrintChars
        Print characters.
    • Constructor Detail

      • Writer

        public Writer()
        Constructs a writer filter that prints to standard out.
      • Writer

        public Writer​(java.io.OutputStream outputStream,
                      java.lang.String encoding)
               throws java.io.UnsupportedEncodingException
        Constructs a writer filter using the specified output stream and encoding.
        Parameters:
        outputStream - The output stream to write to.
        encoding - The encoding to be used for the output. The encoding name should be an official IANA encoding name.
        Throws:
        java.io.UnsupportedEncodingException
      • Writer

        public Writer​(java.io.Writer writer,
                      java.lang.String encoding)
        Constructs a writer filter using the specified Java writer and encoding.
        Parameters:
        writer - The Java writer to write to.
        encoding - The encoding to be used for the output. The encoding name should be an official IANA encoding name.
    • Method Detail

      • startDocument

        public void startDocument​(org.apache.xerces.xni.XMLLocator locator,
                                  java.lang.String encoding,
                                  org.apache.xerces.xni.NamespaceContext nscontext,
                                  org.apache.xerces.xni.Augmentations augs)
                           throws org.apache.xerces.xni.XNIException
        Start document.
        Specified by:
        startDocument in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        startDocument in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • startDocument

        public void startDocument​(org.apache.xerces.xni.XMLLocator locator,
                                  java.lang.String encoding,
                                  org.apache.xerces.xni.Augmentations augs)
                           throws org.apache.xerces.xni.XNIException
        Start document.
        Overrides:
        startDocument in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • comment

        public void comment​(org.apache.xerces.xni.XMLString text,
                            org.apache.xerces.xni.Augmentations augs)
                     throws org.apache.xerces.xni.XNIException
        Comment.
        Specified by:
        comment in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        comment in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • startElement

        public void startElement​(org.apache.xerces.xni.QName element,
                                 org.apache.xerces.xni.XMLAttributes attributes,
                                 org.apache.xerces.xni.Augmentations augs)
                          throws org.apache.xerces.xni.XNIException
        Start element.
        Specified by:
        startElement in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        startElement in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • emptyElement

        public void emptyElement​(org.apache.xerces.xni.QName element,
                                 org.apache.xerces.xni.XMLAttributes attributes,
                                 org.apache.xerces.xni.Augmentations augs)
                          throws org.apache.xerces.xni.XNIException
        Empty element.
        Specified by:
        emptyElement in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        emptyElement in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • characters

        public void characters​(org.apache.xerces.xni.XMLString text,
                               org.apache.xerces.xni.Augmentations augs)
                        throws org.apache.xerces.xni.XNIException
        Characters.
        Specified by:
        characters in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        characters in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • endElement

        public void endElement​(org.apache.xerces.xni.QName element,
                               org.apache.xerces.xni.Augmentations augs)
                        throws org.apache.xerces.xni.XNIException
        End element.
        Specified by:
        endElement in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        endElement in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • startGeneralEntity

        public void startGeneralEntity​(java.lang.String name,
                                       org.apache.xerces.xni.XMLResourceIdentifier id,
                                       java.lang.String encoding,
                                       org.apache.xerces.xni.Augmentations augs)
                                throws org.apache.xerces.xni.XNIException
        Start general entity.
        Specified by:
        startGeneralEntity in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        startGeneralEntity in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • endGeneralEntity

        public void endGeneralEntity​(java.lang.String name,
                                     org.apache.xerces.xni.Augmentations augs)
                              throws org.apache.xerces.xni.XNIException
        End general entity.
        Specified by:
        endGeneralEntity in interface org.apache.xerces.xni.XMLDocumentHandler
        Overrides:
        endGeneralEntity in class DefaultFilter
        Throws:
        org.apache.xerces.xni.XNIException
      • printAttributeValue

        protected void printAttributeValue​(java.lang.String text)
        Print attribute value.
      • printCharacters

        protected void printCharacters​(org.apache.xerces.xni.XMLString text,
                                       boolean normalize)
        Print characters.
      • printStartElement

        protected void printStartElement​(org.apache.xerces.xni.QName element,
                                         org.apache.xerces.xni.XMLAttributes attributes)
        Print start element.
      • printEndElement

        protected void printEndElement​(org.apache.xerces.xni.QName element)
        Print end element.
      • printEntity

        protected void printEntity​(java.lang.String name)
        Print entity.
      • main

        public static void main​(java.lang.String[] argv)
                         throws java.lang.Exception
        Main.
        Throws:
        java.lang.Exception