org.crosswire.common.xml
Class XMLUtil

java.lang.Object
  extended by org.crosswire.common.xml.XMLUtil

public final class XMLUtil
extends Object

Utilities for working with SAX XML parsing.

Author:
Joe Walker [joe at eireneh dot com]
See Also:
for license details. The copyright to this program is held by it's authors.

Field Summary
protected static Logger log
          The log stream
private static Pattern validCharacterEntityPattern
           
 
Constructor Summary
private XMLUtil()
          Prevent Instansiation
 
Method Summary
static String cleanAllEntities(String broken)
          A parse has failed so we can try to kill the broken entities and then have another go.
static String cleanAllTags(String broken)
          XML parse failed, so we can try getting rid of all the tags and having another go.
static void debugSAXAttributes(Attributes attrs)
          Show the attributes of an element as debug
static String escape(String s)
          Normalizes the given string
static org.jdom.Document getDocument(String subject)
          Get and load an XML file from the classpath and a few other places into a JDOM Document object.
private static String guessEntity(String brokenEntity)
          Attempt to guess what the entity should have been and fix it, or remove it if there are no obvious replacements.
static String writeToString(SAXEventProvider provider)
          Serialize a SAXEventProvider into an XML String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final Logger log
The log stream


validCharacterEntityPattern

private static Pattern validCharacterEntityPattern
Constructor Detail

XMLUtil

private XMLUtil()
Prevent Instansiation

Method Detail

getDocument

public static org.jdom.Document getDocument(String subject)
                                     throws org.jdom.JDOMException,
                                            IOException
Get and load an XML file from the classpath and a few other places into a JDOM Document object.

Parameters:
subject - The name of the desired resource (without any extension)
Returns:
The requested resource
Throws:
IOException - if there is a problem reading the file
org.jdom.JDOMException - If the resource is not valid XML

writeToString

public static String writeToString(SAXEventProvider provider)
                            throws SAXException
Serialize a SAXEventProvider into an XML String

Parameters:
provider - The source of SAX events
Returns:
a serialized string
Throws:
SAXException

debugSAXAttributes

public static void debugSAXAttributes(Attributes attrs)
Show the attributes of an element as debug


escape

public static String escape(String s)
Normalizes the given string


cleanAllEntities

public static String cleanAllEntities(String broken)
A parse has failed so we can try to kill the broken entities and then have another go.


guessEntity

private static String guessEntity(String brokenEntity)
Attempt to guess what the entity should have been and fix it, or remove it if there are no obvious replacements.


cleanAllTags

public static String cleanAllTags(String broken)
XML parse failed, so we can try getting rid of all the tags and having another go. We define a tag to start at a < and end at the end of the next word (where a word is what comes in between spaces) that does not contain an = sign, or at a >, whichever is earlier.


Copyright ยจ 2003-2005