xmlBlaster 2.1.0 API

org.xmlBlaster.util
Class XmlNotPortable

java.lang.Object
  extended by org.xmlBlaster.util.XmlNotPortable

public class XmlNotPortable
extends java.lang.Object

XmlNotPortable holds static methods for parser dependent code. Currently JDK 1.2 until JDK 1.5 are explicitly covered.

For JDK 1.5 we use only DOM Level 3 compliant coding, so any such parser should do the job.

For JDK <= 1.4 we need the crimson parser.

The current xml code is tested with Sun JDK 1.2 - JDK 1.6 IBM JDK 1.4 and jrockit JDK 5.

Author:
Marcel Ruff

Field Summary
private static java.lang.Class clazz_QName
           
private static java.lang.Class clazz_XPath
           
private static java.lang.Class clazz_XPathFactory
           
static java.lang.String ENCODING
          xmlBlaster uses generally UTF-8
private static java.lang.Object field_NODESET
           
private static java.lang.Object instance_XPathFactory
           
static int JVM_VERSION
          We only distinguish: 13 for all JDK <= 1.3 14 for JDK 1.4 15 for all JDK >= 1.5
private static java.util.logging.Logger log
           
private static java.lang.String ME
           
private static java.lang.reflect.Method method_newXPath
           
private static java.lang.Class[] paramCls_StringDocument
           
private static int version
           
 
Constructor Summary
XmlNotPortable()
           
 
Method Summary
static java.lang.String escape(java.lang.String str)
          Encapsulate the given string with CDATA, escapes "]]>" tokens in str.
static int getJvmXmlVersionToUse()
          Checks for forcing crimson even for JDK 15
static java.util.Enumeration getNodeSetFromXPath(java.lang.String expression, org.w3c.dom.Document document)
          Do XPath query on DOM
static org.w3c.dom.traversal.TreeWalker getTreeWalker(org.w3c.dom.Document document, org.w3c.dom.Node node)
          Access a XML DOM node tree walker.
static void main(java.lang.String[] args)
           
static org.w3c.dom.Node mergeNode(org.w3c.dom.Document document, org.w3c.dom.Node node)
          Merging a node into another document.
static int protectionNeeded(java.lang.String value)
          If value contains XML harmful characters it needs to be wrapped by CDATA or encoded to Base64.
private static java.io.ByteArrayOutputStream write(java.io.ByteArrayOutputStream out, org.w3c.dom.Node node, java.lang.String offset)
           
static java.io.ByteArrayOutputStream write(org.w3c.dom.Node node)
          Dumo the DOM nodes to a XML string.
static java.io.ByteArrayOutputStream writeNode(org.w3c.dom.Node node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private static final java.lang.String ME
See Also:
Constant Field Values

log

private static java.util.logging.Logger log

method_newXPath

private static java.lang.reflect.Method method_newXPath

paramCls_StringDocument

private static java.lang.Class[] paramCls_StringDocument

clazz_XPathFactory

private static java.lang.Class clazz_XPathFactory

clazz_XPath

private static java.lang.Class clazz_XPath

clazz_QName

private static java.lang.Class clazz_QName

instance_XPathFactory

private static java.lang.Object instance_XPathFactory

field_NODESET

private static java.lang.Object field_NODESET

JVM_VERSION

public static int JVM_VERSION
We only distinguish: 13 for all JDK <= 1.3 14 for JDK 1.4 15 for all JDK >= 1.5


version

private static int version

ENCODING

public static java.lang.String ENCODING
xmlBlaster uses generally UTF-8

Constructor Detail

XmlNotPortable

public XmlNotPortable()
Method Detail

getJvmXmlVersionToUse

public static int getJvmXmlVersionToUse()
Checks for forcing crimson even for JDK 15

Returns:
13, 14 or 15

getNodeSetFromXPath

public static java.util.Enumeration getNodeSetFromXPath(java.lang.String expression,
                                                        org.w3c.dom.Document document)
                                                 throws XmlBlasterException
Do XPath query on DOM

Throws:
XmlBlasterException

write

private static final java.io.ByteArrayOutputStream write(java.io.ByteArrayOutputStream out,
                                                         org.w3c.dom.Node node,
                                                         java.lang.String offset)
                                                  throws java.io.IOException
Throws:
java.io.IOException

writeNode

public static final java.io.ByteArrayOutputStream writeNode(org.w3c.dom.Node node)
                                                     throws java.io.IOException
Throws:
java.io.IOException

write

public static final java.io.ByteArrayOutputStream write(org.w3c.dom.Node node)
                                                 throws java.io.IOException
Dumo the DOM nodes to a XML string. (DOM) Level 1 and DOM Level 2 (The org.w3c.dom API is DOM Level 2 API) specifications do not have a standard method for loading and saving an XML document. Instead, we use vendor (crimson) specific code for input to and output from DOM parsers, which is a disadvantage when portability is a requirement.

Throws:
java.io.IOException

mergeNode

public static final org.w3c.dom.Node mergeNode(org.w3c.dom.Document document,
                                               org.w3c.dom.Node node)
Merging a node into another document.

The caller must synchronize if necessary

Implementation details:

  1. adoptNode(): Node org.w3c.dom.Document.adoptNode(Node source) throws DOMException merges the nodes since JDK 1.5 / DOM Level 3
  2. importNode(): Node org.w3c.dom.Document.importNode(Node importedNode, boolean deep) throws DOMException takes a clone, since JDK 1.4 / DOM Level 2
  3. changeNodeOwner(): Specific for crimson xml parser which was default in JDK 1.4 (not portable)

Parameters:
the - destination document
the - node to merge into the DOM tree, it is invalid after this call
Returns:
The node added or null

getTreeWalker

public static final org.w3c.dom.traversal.TreeWalker getTreeWalker(org.w3c.dom.Document document,
                                                                   org.w3c.dom.Node node)
Access a XML DOM node tree walker. Caution: Works only with JDK 1.5 or higher

Parameters:
document - The DOM document
node - The root node to walk, if null the document's top node is chosen
Throws:
java.lang.IllegalArgumentException - for JDK <= 1.4

escape

public static java.lang.String escape(java.lang.String str)
Encapsulate the given string with CDATA, escapes "]]>" tokens in str. Please use for dumps only as it can't handle internally used ]]> (no Base64 encoding is done)


protectionNeeded

public static int protectionNeeded(java.lang.String value)
If value contains XML harmful characters it needs to be wrapped by CDATA or encoded to Base64.

Parameters:
value - The string to verify
Returns:
0 No protection necessary 1 Protection with CDATA is needed 2 Protection with Base64 is needed

main

public static void main(java.lang.String[] args)

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.