verinec.util
Class LocalSAXBuilder

java.lang.Object
  extended by org.jdom.input.SAXBuilder
      extended by verinec.util.LocalSAXBuilder

public class LocalSAXBuilder
extends SAXBuilder

A SAXBuilder using local copies of the Verinec schemas. The Builder is set to be validating against schemas and sets the parser to use all local .xsd files in /res/schemas/ within the classpath. Use only relative paths in xs:include statements, or you will still need network access.

Because of a bug in Java 1.4 and 1.5 see urlEncode, this does only work if the path to the jar contains only us-ascii characters (spaces are ok).

The Class is uses a Singleton design pattern to guarantee a single instance of the Builder. The use singleton is reasonable because finding all schemas takes a long time and the build methods are reentrant.

Version:
$Revision: 142 $
Author:
Dominik Jungo, David Buchmann

Field Summary
private static LocalSAXBuilder instance
           
private  Logger logger
           
private  boolean schemaLocal
           
 
Constructor Summary
private LocalSAXBuilder()
          This is a singleton, use instance()
 
Method Summary
private  String buildSchemaLocations()
          Collect the string for the schemaLocation attribute.
static LocalSAXBuilder instance()
          Creates an instance of LocalSAXBuilder if it does not exist or returns the existing one otherwise.
 boolean isNetworkNeeded()
          Tells if network is needed for schemas.
 String urlEncode(String s)
          Encode all spaces in the string with their character code.
 
Methods inherited from class org.jdom.input.SAXBuilder
build, build, build, build, build, build, build, build, configureContentHandler, configureParser, createContentHandler, createParser, getDriverClass, getDTDHandler, getEntityResolver, getErrorHandler, getExpandEntities, getFactory, getIgnoringElementContentWhitespace, getReuseParser, getValidation, getXMLFilter, setDTDHandler, setEntityResolver, setErrorHandler, setExpandEntities, setFactory, setFeature, setIgnoringElementContentWhitespace, setProperty, setReuseParser, setValidation, setXMLFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static LocalSAXBuilder instance

logger

private Logger logger

schemaLocal

private boolean schemaLocal
Constructor Detail

LocalSAXBuilder

private LocalSAXBuilder()
This is a singleton, use instance()

Method Detail

isNetworkNeeded

public boolean isNetworkNeeded()
Tells if network is needed for schemas. Otherwise, the builder found them in the classpath.

Returns:
true if the local schema locations were build, false otherwise

instance

public static LocalSAXBuilder instance()
Creates an instance of LocalSAXBuilder if it does not exist or returns the existing one otherwise.

Returns:
an instance of LocalSAXBuilder

buildSchemaLocations

private String buildSchemaLocations()
                             throws VerinecException
Collect the string for the schemaLocation attribute. It has the format {namespace uri}* Because of a bug in Java 1.4 and 1.5 see urlEncode, this does only work if the path to the jar contains no non-us-ascii characters.

Returns:
A schema location string appropriate for the xerces property.
Throws:
VerinecException - If we have a problem with the classpath.

urlEncode

public String urlEncode(String s)
Encode all spaces in the string with their character code. As long as this bug in Java is not fixed, the jars must be in a path with only us-ascii letters and numbers. If there are other characters in the path, the validation will require network access.

Parameters:
s - An URL
Returns:
The encoded URL. Currently just replaces space by %20.

Copyright © 2005 Verinec, DIUF