de.smartics.xml.encoding
Class XmlDescriptorDetector

Package class diagram package XmlDescriptorDetector
java.lang.Object
  extended by de.smartics.xml.encoding.XmlDescriptorDetector

public class XmlDescriptorDetector
     
     
extends Object

Detects the descriptor of an XML document.

The implementation requires a parser implementing org.xml.sax.ext.Locator2. This is provided by the Xerces from version 2.0.2 on (please refer to Xerces SAX FAQ for details).

This library does not force a special Xerces version to be used. Maven users may want to add the following dependency to their POM:

 
   
   

POM Dependency

<dependency>
  <groupId>xerces</groupId>
  <artifactId>xercesImpl</artifactId>
  <version>2.10.0</version>
</dependency>

Note:

Most implementations only provide the version and encoding information if a stream is passed instead of a input source.


Constructor Summary
XmlDescriptorDetector()
          Convenience constructor with no delegate that stops parsing after document start event has been detected.
XmlDescriptorDetector(XmlParsingHandler delegate)
           Default constructor.
 
Method Summary
protected  XMLReader createParser()
          Creates and configures a parser instance.
 XmlParsingHandler getDelegate()
          Returns the delegate to fetch additional information from the stream.
 XmlDescriptor readDescriptor(InputSource input)
          Reads the XML descriptor of the file provided by the input source.
 XmlDescriptor readDescriptor(InputStream input)
          Reads the XML descriptor of the file provided by the input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlDescriptorDetector

public XmlDescriptorDetector()
Convenience constructor with no delegate that stops parsing after document start event has been detected.


XmlDescriptorDetector

public XmlDescriptorDetector(XmlParsingHandler delegate)

Default constructor.

Please consider to throw an {@link AbortException in your content handler delegate to abort the parsing as soon as all information is collected.}

Parameters:
delegate - the delegate to fetch additional information from the stream.
Method Detail

getDelegate

public XmlParsingHandler getDelegate()
Returns the delegate to fetch additional information from the stream.

Returns:
the delegate to fetch additional information from the stream.

createParser

protected XMLReader createParser()
                          throws SAXException,
                                 SAXNotRecognizedException,
                                 SAXNotSupportedException
Creates and configures a parser instance.

Returns:
the new parser instance.
Throws:
SAXException - on any problem creating the parser.
SAXNotRecognizedException - on any problem configuring the parser.
SAXNotSupportedException - on any problem configuring the parser.

readDescriptor

public XmlDescriptor readDescriptor(InputStream input)
                             throws SAXException,
                                    IOException
Reads the XML descriptor of the file provided by the input stream.

This will only detect XML version and encoding.

Note:

Most implementations only provide the version and encoding information if a stream is passed instead of a input source.

Parameters:
input - the XML document whose descriptor is to be read.
Returns:
the descriptor of the document. Never null.
Throws:
SAXException - on any problem reading the XML document.
IOException - on any problem reading from the input source.

readDescriptor

public XmlDescriptor readDescriptor(InputSource input)
                             throws SAXException,
                                    IOException
Reads the XML descriptor of the file provided by the input source.

As soon as all relevant information is read, the paring is aborted.

Note:

Most implementations read the public and system ID from the input source as defaults and return them if no such information can be determined from the input.

Parameters:
input - the XML document whose descriptor is to be read.
Returns:
the descriptor of the document. Never null.
Throws:
SAXException - on any problem reading the XML document.
IOException - on any problem reading from the input source.


Copyright © 2010-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.