|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webmethods.rtl.util.xml.XMLUtil
public class XMLUtil
XMLUtil provides convience functions XML Functions (DOM & XPath) Right now it uses xalan and xerces... this may change, but the api shouldn't
Nested Class Summary | |
---|---|
static class |
XMLUtil.NodeListIterator
NodeIterator which iterates over a dom NodeList. |
static class |
XMLUtil.SingleNodeIterator
Node iterator which iterates over a single node. |
Field Summary | |
---|---|
static String |
ATTR_BEG_QUERY
|
static String |
ATTR_END_QUERY
|
static String |
ATTR_MID_QUERY
|
static String |
CLOSE_TAG
|
protected static String |
DOCUMENT_DECL
|
static String |
END_TAG
|
static long |
LONG_ERROR_VALUE
Error result of various long functions |
static String |
MSG_NULL_DOCUMENT
Empty string corresponding to the NULL document |
static String |
OPEN_TAG
|
static String |
SERIALIZER_ENCODING
Default serializer encoding -> UTF-8 |
static String |
SERIALIZER_MIME_TYPE
Default serializer's MIME type -> text/xml |
static String[] |
SERIALIZER_NON_ESCAPING_ELEMENTS
|
static int |
XML_DUMP_ALL
|
Constructor Summary | |
---|---|
XMLUtil()
|
Method Summary | |
---|---|
protected static void |
_dumpXML(Node node,
Writer out,
int depth,
int totalDepth)
output to a stream |
protected static Document |
_loadDocument(InputSource inputSource)
loads an xml document from the xslt input source |
static Node |
createElement(Node parent,
String name)
Creates new element and appends it to passed parent |
static Node |
createElement(Node parent,
String name,
String value)
Creates new element with passed name and text value, and appends it to passed parent |
static void |
dumpXML(Node node,
Writer out,
int depth)
Outputs a Node to a stream |
static Element |
duplicateElement(Element parent,
Element src)
Duplicates src Element as a regular Element,
and adds it to the parent Element. |
static String |
encodeToQName(String s)
ASCII-only encoder |
static void |
ensureChildElement(Node parent,
String childName,
Object childValue)
|
static void |
excludeElement(Node nodeExclude)
|
static void |
excludeElements(Document document,
String xpathToExclude)
|
static void |
flushXSLCache()
Flushes cache for all xsl templates |
static void |
flushXSLCache(Source source)
Flushes cache for a particular xsl template |
static String |
getAllText(Node node)
Gets all the text for the given node, including any child nodes |
static String |
getAttributeDef(Element element,
String attrName,
String defaultValue)
Gets the attribute value with the given attribute name from the given element. |
static String |
getAttributeEx(Element element,
String attribute)
Helper function to get an attribute. |
static long |
getAttrLong(Element element,
String attrName)
Return attribute value for the given DOM element as long. |
static boolean |
getBooleanByXPath(Node aNode,
String xPath,
boolean defValue)
Gets the boolean value for the node text of the first node that matches the given xpath criteria |
static DocumentBuilderFactory |
getBuilderFactory()
Returns reference to the DocumentBuilderFactory. |
static EntityResolver |
getEntityResolver()
Returns reference to the EntityResolver. |
static ErrorHandler |
getErrorHandler()
Returns reference to the sax ErrorHandler. |
static Map |
getMapFromElement(Element element)
Constructs a Map from element its attributes and its child elements. |
static Map |
getMapFromElementAttributes(Element element)
Constructs a Map from the attributes on the given element. |
static Map |
getMapFromXMLAttributes(String xmlStream)
|
static String |
getNodeText(Node node)
Get the text value for the given node. |
static String |
getNodeTextByXPath(Node aNode,
String xPath)
Gets the node text for the first node that matches the given xpath criteria |
static List |
getNodeTexts(NodeList nodeList)
Gets a list of all the node texts for the nodes in the given NodeList |
static String |
getSafeAttribute(Element element,
String attribute)
Helper function to get an attribute or return an empty string if the attribute doesn't exist |
static Source |
getSAXSource(Reader inputReader)
|
static void |
init()
Initializes XML utilities. |
void |
init(IComponentData data,
String phase)
Called automatically by the portal runtime to initialize the XMLUtil. |
static boolean |
isEmpty(NodeList nodeList)
Verifies whether specified node list is empty or null |
static Document |
loadDocument(String xmlFile)
loads an xml document by the supplied file name |
static Document |
loadDocumentFromInputStream(InputStream inputStream)
loads an xml document by the suplied input stream |
static Document |
loadDocumentFromReader(Reader reader)
loads an xml document by the suplied java.io.Reader |
static Document |
loadDocumentFromXML(String xml)
loads an xml document by the suplied xml |
static void |
mergeNodeInDocument(String srcFilePath,
String targetFilePath,
String xpathQuery)
Lookup the node with the given xpath query in the source and target documents and merge the contents of the source node into the target node. |
static void |
mergeNodeInDocument(String srcFilePath,
String targetFilePath,
String srcXpathQuery,
String targetXpathQuery)
Lookup the node with the given xpath query in the source and target documents and merge the contents of the source node into the target node. |
static Node |
mergeNodes(Node srcNode,
Node targetNode)
Merge the contents of the srcNode into the targetNode replacing any duplicate nodes in the targetElement |
static Document |
newDocument()
Creates and returns a new DOM document |
static Document |
newDocument(Node cloneNode)
Creates and returns a new DOM document that is a clone of the given node. |
static DocumentBuilder |
newDocumentBuilder()
Creates and returns document builder |
static String |
normalize(String s)
Normalizes the given string. |
static boolean |
notEmpty(NodeList nodeList)
Checks that specified node list is not empty |
static void |
removeChild(Element parent,
String childName)
|
static void |
removeElement(Element element)
Remove element from document |
static void |
replaceNode(Node srcNode,
Node targetNode)
Replaces the targetNode with the srcNode |
static void |
replaceNodeInDocument(String srcFilePath,
String targetFilePath,
String xpathQuery)
Lookup the node with the given xpath query in the source and target documents and merge the contents of the source node into the target node. |
static Element |
selectElement(Node node,
String xpath)
returns a node from the suplied node that meets the xpath criteria. |
static org.w3c.dom.traversal.NodeIterator |
selectNodeIterator(Node node,
String xpath)
returns a node iterator from the suplied node that meets the xpath criteria. |
static NodeList |
selectNodeList(Node node,
String xpath)
returns a node list from the suplied node that meets the xpath criteria. |
static Node |
selectSingleNode(Node node,
String xpath)
returns a node from the suplied node that meets the xpath criteria. |
static void |
setNodeText(Node node,
String text)
Sets the text value for the given node. |
void |
shutdown()
Called automatically by the portal runtime when the VM is closing down. |
protected static Attr[] |
sortAttributes(NamedNodeMap attrs)
Returns a sorted list of attributes. |
static String |
toString(Document document)
Serializes document and returns its content as a string |
static String |
toString(Node node)
Serializes document node and returns its content as a string |
static String |
toString(Node node,
boolean minimizeXMLSize)
Serializes document node and returns its content as a string |
static String |
toString(Node node,
int depth)
Writes a node to text up to the given depth |
static void |
transformXSLtoDoc(Source source,
Reader xslreader,
Node out)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static void |
transformXSLtoDoc(Source source,
Reader xslreader,
Node out,
HashMap params)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static void |
transformXSLtoDoc(Source source,
String location,
Node out)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static void |
transformXSLtoDoc(Source source,
String location,
Node out,
HashMap params)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static String |
transformXSLtoStr(Source source,
Reader xslreader)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static String |
transformXSLtoStr(Source source,
Reader xslreader,
HashMap params)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static String |
transformXSLtoStr(Source source,
String location)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static String |
transformXSLtoStr(Source source,
String location,
HashMap params)
Helper function that transforms input XML Node using specified XSLT stylesheet and returns result as a String |
static String |
wrapTextWithTag(String text,
String tag)
wraps a text with the tag for example: |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ATTR_BEG_QUERY
public static final String ATTR_MID_QUERY
public static final String ATTR_END_QUERY
public static final String MSG_NULL_DOCUMENT
public static final String SERIALIZER_ENCODING
public static final String SERIALIZER_MIME_TYPE
public static final int XML_DUMP_ALL
XMLUtil.dumpXML(org.w3c.dom.Node, java.io.Writer, int)
,
Constant Field Valuespublic static final String[] SERIALIZER_NON_ESCAPING_ELEMENTS
public static final long LONG_ERROR_VALUE
public static final String OPEN_TAG
public static final String CLOSE_TAG
public static final String END_TAG
protected static final String DOCUMENT_DECL
Constructor Detail |
---|
public XMLUtil()
Method Detail |
---|
public void init(IComponentData data, String phase) throws InitializationException
data
- the IComponentData
contains the configuration data for the data manager.phase
- the name of the startup phase that is currently executing
com.webmethods.portal.system.init.InitializationException
InitializationException
IInitializable
public void shutdown()
IInitializable
public static void init() throws RtlException
RtlException
public static DocumentBuilderFactory getBuilderFactory()
public static EntityResolver getEntityResolver()
public static ErrorHandler getErrorHandler()
public static DocumentBuilder newDocumentBuilder()
public static Document newDocument()
public static Document newDocument(Node cloneNode)
cloneNode
- the node to use as the content of the new Document
public static Node createElement(Node parent, String name)
parent
- owner Node. May be either regular node, or document itselfname
- name of the element to createpublic static Node createElement(Node parent, String name, String value)
parent
- owner Node. May be either regular node, or document itselfname
- name of the element to createvalue
- text value of created elementpublic static Document loadDocument(String xmlFile)
xmlFile
- is the name of the file.public static Document loadDocumentFromInputStream(InputStream inputStream)
inputStream
- is an open inputStream to an xml document.public static Document loadDocumentFromReader(Reader reader)
reader
- is an open Reader to an xml document.public static Document loadDocumentFromXML(String xml)
xml
- is a string with valid XMLprotected static Document _loadDocument(InputSource inputSource)
inputSource
- is the xslt input sourcepublic static Node selectSingleNode(Node node, String xpath)
node
- is the tree starting point.xpath
- is a valid xpath statement.public static Element selectElement(Node node, String xpath)
node
- is the tree starting point.xpath
- is a valid xpath statement.public static NodeList selectNodeList(Node node, String xpath)
node
- is the tree starting point.xpath
- is a valid xpath statement.public static org.w3c.dom.traversal.NodeIterator selectNodeIterator(Node node, String xpath)
node
- is the tree starting point.xpath
- is a valid xpath statement.public static Source getSAXSource(Reader inputReader) throws RtlException
RtlException
public static Map getMapFromXMLAttributes(String xmlStream) throws RtlException
RtlException
public static Map getMapFromElementAttributes(Element element)
Map
from the attributes on the given element. namespaces
are ignored.
element
- the element to get the attributes from
public static Map getMapFromElement(Element element)
Map
from element its attributes and its child elements. Child elements are
constructed into nested Map instances, while attributes are passed as simple types
element
-
public static Element duplicateElement(Element parent, Element src)
src
Element as a regular Element,
and adds it to the parent
Element.
parent
- Element that will be made the parent of the new Element.src
- Element the source element (the element to be duplicated).public static String wrapTextWithTag(String text, String tag)
public static String getNodeText(Node node)
node
- the node to examine
public static void setNodeText(Node node, String text)
node
- the node to examinetext
- the text value of the nodepublic static long getAttrLong(Element element, String attrName)
element
- Document element to useattrName
- Attribute name to retrievepublic static String getAttributeDef(Element element, String attrName, String defaultValue)
element
- the element to get the attribute value fromattrName
- the attribute name to retrievedefaultValue
- the value to return if the attribute could not be found
public static String getAllText(Node node)
public static String getNodeTextByXPath(Node aNode, String xPath)
aNode
- is the tree starting point.xPath
- is a valid xpath statement.public static boolean getBooleanByXPath(Node aNode, String xPath, boolean defValue)
aNode
- is the tree starting point.xPath
- is a valid xpath statement.defValue
- the value to use if the node text is not a boolean stringpublic static List getNodeTexts(NodeList nodeList)
nodeList
- the nodelist to get the node texts forpublic static String getSafeAttribute(Element element, String attribute)
element
- the object to get the attribute fromattribute
- the attribute name to retrieve
public static String getAttributeEx(Element element, String attribute)
element
- the object to get the attribute fromattribute
- the attribute name to retrieve
public static String transformXSLtoStr(Source source, Reader xslreader) throws TransformerException
source
- input Node to be transformedxslreader
- reader to read XSLT from
TransformerException
public static String transformXSLtoStr(Source source, Reader xslreader, HashMap params) throws TransformerException
source
- input Node to be transformedxslreader
- reader to read XSLT fromparams
- to be added to the processor
TransformerException
public static String transformXSLtoStr(Source source, String location) throws TransformerException
source
- input Node to be transformedlocation
- is a full qualified path to XSLT file. Note, that passing XSLT as file
location, rather than as stream, allows XSLT stylesheet caching.
TransformerException
public static String transformXSLtoStr(Source source, String location, HashMap params) throws TransformerException
source
- input Node to be transformedlocation
- is a full qualified path to XSLT file. Note, that passing XSLT as file
location, rather than as stream, allows XSLT stylesheet caching.params
- to be added to the processor
TransformerException
public static void transformXSLtoDoc(Source source, Reader xslreader, Node out) throws TransformerException
source
- input Node to be transformedxslreader
- reader to read XSLT fromout
- output Node
TransformerException
public static void transformXSLtoDoc(Source source, Reader xslreader, Node out, HashMap params) throws TransformerException
source
- input Node to be transformedxslreader
- reader to read XSLT fromout
- output Nodeparams
- to be added to the processor
TransformerException
public static void transformXSLtoDoc(Source source, String location, Node out) throws TransformerException
source
- input Node to be transformedlocation
- is a full qualified path to XSLT file. Note, that passing XSLT as file
location, rather than as stream, allows XSLT stylesheet caching.out
- output Node
TransformerException
public static void transformXSLtoDoc(Source source, String location, Node out, HashMap params) throws TransformerException
source
- input Node to be transformedlocation
- is a full qualified path to XSLT file. Note, that passing XSLT as file
location, rather than as stream, allows XSLT stylesheet caching.out
- output Nodeparams
- to be added to the processor
TransformerException
public static void flushXSLCache(Source source)
source
- public static void flushXSLCache()
public static String toString(Node node, int depth)
node
- depth
-
XMLUtil.toString(org.w3c.dom.Node, int)
,
XMLUtil.dumpXML(org.w3c.dom.Node, java.io.Writer, int)
public static void dumpXML(Node node, Writer out, int depth) throws IOException
IOException
protected static void _dumpXML(Node node, Writer out, int depth, int totalDepth) throws IOException
IOException
protected static Attr[] sortAttributes(NamedNodeMap attrs)
public static String normalize(String s)
public static String toString(Node node)
public static String toString(Node node, boolean minimizeXMLSize)
node
- the xml DOM nodeminimizeXMLSize
- if true then omit comments, identing, etc to minimize overall xml sizepublic static String toString(Document document)
public static String encodeToQName(String s)
s
- the string the ecode
public static void ensureChildElement(Node parent, String childName, Object childValue)
public static void removeChild(Element parent, String childName)
public static void excludeElements(Document document, String xpathToExclude)
public static void excludeElement(Node nodeExclude)
nodeExclude
- public static void removeElement(Element element)
element
- public static void mergeNodeInDocument(String srcFilePath, String targetFilePath, String srcXpathQuery, String targetXpathQuery) throws IOException
srcFilePath
- targetFilePath
- srcXpathQuery
- the xpath query to get the node in the src documenttargetXpathQuery
- the xpath query to get the node in the target document
IOException
public static void mergeNodeInDocument(String srcFilePath, String targetFilePath, String xpathQuery) throws IOException
srcFilePath
- targetFilePath
- xpathQuery
- the xpath query to get the node in both the src and target documents
IOException
public static Node mergeNodes(Node srcNode, Node targetNode)
srcNode
- targetNode
-
public static void replaceNodeInDocument(String srcFilePath, String targetFilePath, String xpathQuery) throws IOException
srcFilePath
- targetFilePath
- xpathQuery
-
IOException
public static void replaceNode(Node srcNode, Node targetNode)
srcNode
- targetNode
- public static boolean isEmpty(NodeList nodeList)
null
nodeList
- Node list to check
public static boolean notEmpty(NodeList nodeList)
nodeList
- Node list to verify
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |