org.weborganic.berlioz.xml
Class XMLCopy

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.weborganic.berlioz.xml.XMLCopy
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler

public final class XMLCopy
extends DefaultHandler
implements ContentHandler, LexicalHandler

Copy the parsed XML to the specified XML writer.

This class also implements the LexicalHandler interface, so that comments can be copied if the XMLReader reader supports the property.

Since:
Berlioz 0.7
Version:
Berlioz 0.9.9 - 8 October 2012
Author:
Christophe Lauret

Constructor Summary
XMLCopy(XMLWriter xml)
          Creates a new XMLExtractor wrapping the specified XML writer.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void comment(char[] ch, int start, int length)
          Copy the comment to the output.
static boolean copyTo(File file, XMLWriter xml)
          Copy the specified File to the given XML Writer.
static boolean copyTo(Reader reader, XMLWriter xml)
          Copy the specified File to the given XML Writer.
 void endCDATA()
          Does nothing.
 void endDTD()
          Does nothing.
 void endElement(String uri, String localName, String qName)
           
 void endEntity(String name)
          Does nothing.
 void processingInstruction(String target, String data)
           
 void startCDATA()
          Does nothing.
 void startDTD(String name, String publicId, String systemId)
          Does nothing.
 void startElement(String uri, String localName, String qName, Attributes atts)
           
 void startEntity(String name)
          Does nothing.
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, resolveEntity, setDocumentLocator, skippedEntity, startDocument, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, endPrefixMapping, ignorableWhitespace, setDocumentLocator, skippedEntity, startDocument
 

Constructor Detail

XMLCopy

public XMLCopy(XMLWriter xml)
Creates a new XMLExtractor wrapping the specified XML writer.

Parameters:
xml - The XML writer to use.
Method Detail

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class DefaultHandler
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class DefaultHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Copy the comment to the output.

Specified by:
comment in interface LexicalHandler
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
Does nothing.

Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Does nothing.

Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Does nothing.

Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException

endDTD

public void endDTD()
            throws SAXException
Does nothing.

Specified by:
endDTD in interface LexicalHandler
Throws:
SAXException

startEntity

public void startEntity(String name)
                 throws SAXException
Does nothing.

Specified by:
startEntity in interface LexicalHandler
Throws:
SAXException

endEntity

public void endEntity(String name)
               throws SAXException
Does nothing.

Specified by:
endEntity in interface LexicalHandler
Throws:
SAXException

copyTo

public static boolean copyTo(File file,
                             XMLWriter xml)
                      throws IOException
Copy the specified File to the given XML Writer.

Any error is reported as XML on the XML writer.

This method does not perform any caching, caching is better handled externally by generators.

Parameters:
file - The file.
xml - The XML writer.
Returns:
true if the copy was done successfully; false otherwise.
Throws:
IOException - should an error occur when writing the XML.

copyTo

public static boolean copyTo(Reader reader,
                             XMLWriter xml)
                      throws IOException
Copy the specified File to the given XML Writer.

Any error is reported as XML on the XML writer. This method does not perform any caching or validation.

Parameters:
reader - The reader over the XML to read.
xml - The XML writer.
Returns:
true if the copy was done successfully; false otherwise.
Throws:
IOException - should an error occur when writing the XML.