org.openspml.v2.util.xml
Class XmlParser

java.lang.Object
  extended byorg.openspml.v2.util.xml.XmlParser
All Implemented Interfaces:
org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XmlParser
extends java.lang.Object
implements org.xml.sax.ErrorHandler, org.xml.sax.EntityResolver

A wrapper around the Xerces parser that provides a simpler interface, and maintains a pool of parser objects for better performance.

This implements the Xerces ErrorHandler interface so we can intercept parser errors and mutate them.

This is a slimmed down version of the XmlParser from the 1.0 toolkit. We do NOT do any validating.


Field Summary
static java.lang.String code_id
           
 
Method Summary
 void error(org.xml.sax.SAXParseException ex)
          Parser error callback handler

We get here for things like DTD syntax errors, and DTD validation errors.

 void fatalError(org.xml.sax.SAXParseException ex)
          Parser fatal error callback handler.
static org.w3c.dom.Document parse(java.lang.String xml)
          Parses a string with or without validation and returns the Document.
 org.xml.sax.InputSource resolveEntity(java.lang.String pubid, java.lang.String sysid)
          Attempt to resolve an entity reference to an absolute file path in the user.dir.
static void setLogFailuresFile(java.io.File file)
          Use this to turn on the logging of failures to the named file.
 void warning(org.xml.sax.SAXParseException ex)
          Parser warning callback handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values
Method Detail

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String pubid,
                                             java.lang.String sysid)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException
Attempt to resolve an entity reference to an absolute file path in the user.dir. We're not validating, so it doesn't matter yet.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Throws:
org.xml.sax.SAXException
java.io.IOException

warning

public void warning(org.xml.sax.SAXParseException ex)
Parser warning callback handler.

What should we do with warnings, collection them, barf to the console? Might want a flag that treats warnings as errors.

Specified by:
warning in interface org.xml.sax.ErrorHandler

error

public void error(org.xml.sax.SAXParseException ex)
           throws org.xml.sax.SAXParseException
Parser error callback handler

We get here for things like DTD syntax errors, and DTD validation errors.

Specified by:
error in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXParseException

fatalError

public void fatalError(org.xml.sax.SAXParseException ex)
                throws org.xml.sax.SAXException
Parser fatal error callback handler.

Convert this one to a Spml2Exception so we can capture the full message text in one place. We get here for things like DTD location failure.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

parse

public static org.w3c.dom.Document parse(java.lang.String xml)
                                  throws Spml2Exception
Parses a string with or without validation and returns the Document.

Throws:
Spml2Exception

setLogFailuresFile

public static void setLogFailuresFile(java.io.File file)
Use this to turn on the logging of failures to the named file. Set it to null to turn it off.

Parameters:
file -


Copyright © Sun Microsystems, Inc. All Rights Reserved.