org.gjt.sp.util
Class XMLUtilities

java.lang.Object
  extended by org.gjt.sp.util.XMLUtilities

public class XMLUtilities
extends java.lang.Object

XML utility methods that only depend on the JDK.

Since:
4.3pre6

Method Summary
static java.lang.String charsToEntities(java.lang.String str, boolean xml11)
          Converts <, >, & in the string to their HTML entity equivalents.
static org.xml.sax.InputSource findEntity(java.lang.String systemId, java.lang.String test, java.lang.Class where)
          Tries to find the given systemId in the context of the given class.
static boolean parseXML(java.io.InputStream in, org.xml.sax.helpers.DefaultHandler handler)
          Convenience method for parsing an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

charsToEntities

public static java.lang.String charsToEntities(java.lang.String str,
                                               boolean xml11)
Converts <, >, & in the string to their HTML entity equivalents.

If xml11 is true, then character entities are used to convert illegal XML characters (mainly ASCII control characters).

Parameters:
str - The string
xml11 - Whether to allow XML 1.1 constructs.

parseXML

public static boolean parseXML(java.io.InputStream in,
                               org.xml.sax.helpers.DefaultHandler handler)
                        throws java.io.IOException
Convenience method for parsing an XML file. This method will wrap the resource in an InputSource and set the source's systemId to "jedit.jar" (so the source should be able to handle any external entities by itself).

SAX Errors are caught and are not propagated to the caller; instead, an error message is printed to jEdit's activity log. So, if you need custom error handling, do not use this method.

The given stream is closed before the method returns, regardless whether there were errors or not.

Returns:
true if any error occured during parsing, false if success.
Throws:
java.io.IOException

findEntity

public static org.xml.sax.InputSource findEntity(java.lang.String systemId,
                                                 java.lang.String test,
                                                 java.lang.Class where)
Tries to find the given systemId in the context of the given class. If the given systemId ends with the given test string, then try to load a resource using the Class's getResourceAsStream() method using the test string as the resource.

This is used a lot internally while parsing XML files used by jEdit, but anyone is free to use the method if it sounds usable.