wxtutils
Class domer

java.lang.Object
  extended bywxtutils.domer

public class domer
extends java.lang.Object

domer has only static methods and serve as a library for utilities that load, save, validates and transform DOMs makeDomFromString makeDomFromUri makeTransformedDomFromUri saveDom saveTransformedDom stringFromDom stringFromTransformedDom ValidateString


Constructor Summary
domer()
          Creates a new instance of domer
 
Method Summary
static javax.xml.parsers.DocumentBuilder makeDocBuilder()
          Make a documentbuilder
static org.w3c.dom.Document makeDomFromString(java.lang.String S)
          Establish a Dom from a string
static org.w3c.dom.Document makeDomFromUri(java.net.URI theUri)
          Establish a Dom from a XML-file
static org.w3c.dom.Document makeTransformedDomFromString(java.lang.String theString, java.net.URI transUri, java.util.HashMap parameters, java.util.HashMap options)
          Establish a Dom from a transformed XML-file
static org.w3c.dom.Document makeTransformedDomFromUri(java.net.URI theUri, java.net.URI transUri, java.util.HashMap parameters, java.util.HashMap options)
          Establish a Dom from a transformed XML-file
static org.w3c.dom.DocumentFragment produceDocFragmentFromString(java.lang.String theText, java.lang.String enc)
          Try to establish a documentfragment from a string
static org.w3c.dom.Document produceDocFromString(java.lang.String theText, java.lang.String enc)
          Try to establish a document from a string
protected static java.util.Properties propsFromDoc(org.w3c.dom.Document doc, java.lang.String fileExtension, java.lang.String encoding)
          Prepare a a set of transformer output options from whatever information we can extract from the document, the targets filextension and the encoding
protected static java.util.Properties propsFromOptions(java.util.HashMap options)
          Prepare a a set of transformer output options from buildoptions
static void saveDom(org.w3c.dom.Document doc, java.net.URI theUri, java.lang.String encoding)
          Saves a dom tree to file with an identity transformation Throws a general exception
static void saveTransformedDom(org.w3c.dom.Document doc, java.net.URI theUri, java.net.URI transUri, java.util.HashMap parameters, java.util.HashMap options)
          Saves a dom tree to file after a transformation Throws a general exception
static java.lang.String serializeDomToString(org.w3c.dom.Document doc, java.lang.String encoding)
          Saves a dom tree to string using serializing
static void serializeDomToUri(org.w3c.dom.Document doc, java.net.URI theUri, java.lang.String encoding)
          Saves a dom tree to file using serializing
static java.lang.String stringFromDom(org.w3c.dom.Document doc, java.net.URI theUri, java.lang.String encoding)
          Saves a dom tree to a string with an identity transformation Throws a general exception
static java.lang.String stringFromTransformedDom(org.w3c.dom.Document doc, java.net.URI theUri, java.net.URI transUri, java.util.HashMap parameters, java.util.HashMap options)
          Saves a dom tree to a string after a transformation Throws a general exception
static boolean ValidateString(java.lang.String theText, java.net.URI theSchema, validationErrorHandler errors)
          Validate a stringrepresentation of a Document against a schema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

domer

public domer()
Creates a new instance of domer

Method Detail

serializeDomToUri

public static void serializeDomToUri(org.w3c.dom.Document doc,
                                     java.net.URI theUri,
                                     java.lang.String encoding)
                              throws java.lang.Exception
Saves a dom tree to file using serializing

Parameters:
doc - The document
theUri - Where it goes
encoding - The encoding we want
Throws:
java.lang.Exception - when save is not acomplished

serializeDomToString

public static java.lang.String serializeDomToString(org.w3c.dom.Document doc,
                                                    java.lang.String encoding)
                                             throws java.lang.Exception
Saves a dom tree to string using serializing

Parameters:
doc - The document
encoding - The encoding we want
Returns:
The string containing the XML-file serialized
Throws:
java.lang.Exception - when save is not complished

ValidateString

public static boolean ValidateString(java.lang.String theText,
                                     java.net.URI theSchema,
                                     validationErrorHandler errors)
Validate a stringrepresentation of a Document against a schema

Parameters:
errors - An errorhandler
theText - The Text we will validate
theSchema - The schema we want to validate against
Returns:
true if ok , false otherwise

stringFromDom

public static java.lang.String stringFromDom(org.w3c.dom.Document doc,
                                             java.net.URI theUri,
                                             java.lang.String encoding)
                                      throws java.lang.Exception
Saves a dom tree to a string with an identity transformation Throws a general exception

Parameters:
doc - The document(DOM)
theUri - Where it goes
encoding - The encoding we want, set elsewhere
Returns:
The DOM serialized to a string
Throws:
java.lang.Exception - when save is not accomplished

produceDocFromString

public static org.w3c.dom.Document produceDocFromString(java.lang.String theText,
                                                        java.lang.String enc)
                                                 throws java.lang.Exception
Try to establish a document from a string

Parameters:
theText - The text we will attempt to interpret as XML
enc - The encoding we want, defaults to UTF-8
Returns:
A document if succeeded, null otherwise
Throws:
java.lang.Exception - when parsing fails

produceDocFragmentFromString

public static org.w3c.dom.DocumentFragment produceDocFragmentFromString(java.lang.String theText,
                                                                        java.lang.String enc)
                                                                 throws java.lang.Exception
Try to establish a documentfragment from a string

Parameters:
theText - The text we will attempt to interpret as XML
enc - The encoding we want, defaults to UTF-8
Returns:
A documenfragment if succeeded, null otherwise
Throws:
java.lang.Exception - when the String can not be parsed

stringFromTransformedDom

public static java.lang.String stringFromTransformedDom(org.w3c.dom.Document doc,
                                                        java.net.URI theUri,
                                                        java.net.URI transUri,
                                                        java.util.HashMap parameters,
                                                        java.util.HashMap options)
                                                 throws java.lang.Exception
Saves a dom tree to a string after a transformation Throws a general exception

Parameters:
doc - The document(DOM)
theUri - Where it goes
transUri - The URI for the transformation
parameters - The parameters that will be set for the transformation
options - The options that will be set for the transformation
Returns:
a string with the serialized DOM
Throws:
java.lang.Exception - when save is not accomplished

saveDom

public static void saveDom(org.w3c.dom.Document doc,
                           java.net.URI theUri,
                           java.lang.String encoding)
                    throws java.lang.Exception
Saves a dom tree to file with an identity transformation Throws a general exception

Parameters:
doc - The document(DOM)
theUri - Where it goes
encoding - The encoding we want, set elsewhere
Throws:
java.lang.Exception - when save is not accomplished

saveTransformedDom

public static void saveTransformedDom(org.w3c.dom.Document doc,
                                      java.net.URI theUri,
                                      java.net.URI transUri,
                                      java.util.HashMap parameters,
                                      java.util.HashMap options)
                               throws java.lang.Exception
Saves a dom tree to file after a transformation Throws a general exception

Parameters:
doc - The document(DOM)
theUri - Where it goes
transUri - The URI for the transformation
parameters - The parameters that will be set for the transformation
options - The options that will be set for the transformation
Throws:
java.lang.Exception - when save is not accomplished

makeDomFromUri

public static org.w3c.dom.Document makeDomFromUri(java.net.URI theUri)
                                           throws java.lang.Exception
Establish a Dom from a XML-file

Parameters:
theUri - Where the XML-file is located
Returns:
A DOM
Throws:
java.lang.Exception - when no DOM is established

makeDomFromString

public static org.w3c.dom.Document makeDomFromString(java.lang.String S)
                                              throws java.lang.Exception
Establish a Dom from a string

Parameters:
S - the string that should be parsed
Returns:
the document, DOM
Throws:
java.lang.Exception - when no DOM is established

makeTransformedDomFromString

public static org.w3c.dom.Document makeTransformedDomFromString(java.lang.String theString,
                                                                java.net.URI transUri,
                                                                java.util.HashMap parameters,
                                                                java.util.HashMap options)
                                                         throws java.lang.Exception
Establish a Dom from a transformed XML-file

Parameters:
theString - the XML-file as a string
transUri - Where we find the transformation
parameters - The parameters that will be applied in the transformation
options - The options that will be applied to output from the transformation
Returns:
a Document
Throws:
java.lang.Exception - when no DOM is established

makeTransformedDomFromUri

public static org.w3c.dom.Document makeTransformedDomFromUri(java.net.URI theUri,
                                                             java.net.URI transUri,
                                                             java.util.HashMap parameters,
                                                             java.util.HashMap options)
                                                      throws java.lang.Exception
Establish a Dom from a transformed XML-file

Parameters:
theUri - Where the XML-file is located
transUri - Where we find the transformation
parameters - The parameters that will be applied in the transformation
options - The options that will be applied to output from the transformation
Returns:
a Document
Throws:
java.lang.Exception - when no DOM is established

makeDocBuilder

public static javax.xml.parsers.DocumentBuilder makeDocBuilder()
                                                        throws javax.xml.parsers.ParserConfigurationException,
                                                               javax.xml.parsers.FactoryConfigurationError
Make a documentbuilder

Returns:
a documentbuilder
Throws:
javax.xml.parsers.ParserConfigurationException - when bad parser configuration
javax.xml.parsers.FactoryConfigurationError - when bad factory configuration

propsFromOptions

protected static java.util.Properties propsFromOptions(java.util.HashMap options)
Prepare a a set of transformer output options from buildoptions

Parameters:
options - The options
Returns:
a set of options

propsFromDoc

protected static java.util.Properties propsFromDoc(org.w3c.dom.Document doc,
                                                   java.lang.String fileExtension,
                                                   java.lang.String encoding)
Prepare a a set of transformer output options from whatever information we can extract from the document, the targets filextension and the encoding

Parameters:
doc - The DOM we want to serialize
fileExtension - The extension of the file we will write to
encoding - The encoding we want
Returns:
a set of options