org.oclc.da.gdfr.registryprototype.pvt.dbxml
Class XPathEvaluator

java.lang.Object
  extended by org.oclc.da.gdfr.registryprototype.pvt.dbxml.XPathEvaluator

public class XPathEvaluator
extends java.lang.Object


Constructor Summary
XPathEvaluator(java.lang.String xml)
           
 
Method Summary
 java.lang.String addComplexValueToContent(java.lang.String content, java.lang.String path, java.lang.String value)
          Appends a new complex value to the node at the given path
 void addNamespaces(java.lang.String xml)
          Adds any new namespaces found in the given xml to this objects properties
 java.lang.String addSimpleValueToContent(java.lang.String content, java.lang.String path, java.lang.String value)
          Appends a simple value to the given XML
 java.lang.String addTextValueToContent(java.lang.String content, java.lang.String path, java.lang.String value)
          Adds/Updates a text node with the given value at the given path
 com.sleepycat.dbxml.XmlQueryContext createQueryContext(com.sleepycat.dbxml.XmlQueryContext qContext)
          Puts all known namespace prefix/uri pairs into an XmlQueryContext Object
 java.lang.String[] findValueInContent(java.lang.String content, java.lang.String path)
          Finds a value in an Xml String and returns it
 java.lang.String getNamespaceFromPrefix(java.lang.String prefix)
          Returns the namespace URI for the given Prefix
 java.lang.String removeValueFromContent(java.lang.String content, java.lang.String path, boolean removeElem)
          Removes a text value from the given content
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathEvaluator

public XPathEvaluator(java.lang.String xml)
Method Detail

addNamespaces

public void addNamespaces(java.lang.String xml)
Adds any new namespaces found in the given xml to this objects properties

Parameters:
xml -

addComplexValueToContent

public java.lang.String addComplexValueToContent(java.lang.String content,
                                                 java.lang.String path,
                                                 java.lang.String value)
Appends a new complex value to the node at the given path

Parameters:
content - The original XML document
path - The XPath to follow
value - The new value to add.
Returns:
String representing the new XML with value added at path
Throws:
RegistryException

addSimpleValueToContent

public java.lang.String addSimpleValueToContent(java.lang.String content,
                                                java.lang.String path,
                                                java.lang.String value)
Appends a simple value to the given XML

Parameters:
content - The XML to add to. Note, this MUST contain the node that is addressed by the XPath provided
path - The XPath to reach the element
value - The value to assign. This should NOT contain the element that is directly referred to by the XPath
Returns:
The updated XML

addTextValueToContent

public java.lang.String addTextValueToContent(java.lang.String content,
                                              java.lang.String path,
                                              java.lang.String value)
Adds/Updates a text node with the given value at the given path

Parameters:
content - String representing the XML document
path - The XPath leading to the simple element containing the text node
value - The text value to add

createQueryContext

public com.sleepycat.dbxml.XmlQueryContext createQueryContext(com.sleepycat.dbxml.XmlQueryContext qContext)
Puts all known namespace prefix/uri pairs into an XmlQueryContext Object

Parameters:
qContext -
Returns:
XmlQueryContext poplulated with all known namespace prefix/uri pairs

findValueInContent

public java.lang.String[] findValueInContent(java.lang.String content,
                                             java.lang.String path)
Finds a value in an Xml String and returns it

Parameters:
content - The Xml String to look at
path - The XPath expression to the location of the value
Returns:
The value found by the given path in the given content
Throws:
javax.xml.xpath.XPathExpressionException - If the XPath is invalid

getNamespaceFromPrefix

public java.lang.String getNamespaceFromPrefix(java.lang.String prefix)
Returns the namespace URI for the given Prefix

Parameters:
prefix -
Returns:

removeValueFromContent

public java.lang.String removeValueFromContent(java.lang.String content,
                                               java.lang.String path,
                                               boolean removeElem)
Removes a text value from the given content

Parameters:
content - The XML document to use
path - The XPath to reach the text to remove
removeElem - If true, element and contents are removed. If false, only contents are erased.
Returns:
The XML document with specified text element removed


Copyright © 2008 OCLC Online Computer Library Center, Inc.. All Rights Reserved.