public final class CmsXmlUtils
extends java.lang.Object
限定符和类型 | 方法和说明 |
---|---|
static java.lang.String |
createXpath(java.lang.String path,
int index)
Translates a simple lookup path to the simplified Xpath format used for
the internal bookmarks.
|
static java.lang.String |
createXpathElement(java.lang.String path,
int index)
Appends the provided index parameter in square brackets to the given name,
like
path[index] . |
static java.lang.String |
createXpathElementCheck(java.lang.String path,
int index)
Ensures that a provided simplified Xpath has the format
title[1] . |
static java.lang.String |
getFirstXpathElement(java.lang.String path)
Returns the first Xpath element from the provided path,
without the index value.
|
static java.lang.String |
getLastXpathElement(java.lang.String path)
Returns the last Xpath element from the provided path,
without the index value.
|
static java.lang.String |
getXpathIndex(java.lang.String path)
Returns the last Xpath index from the given path.
|
static int |
getXpathIndexInt(java.lang.String path)
Returns the last Xpath index from the given path as integer.
|
static boolean |
isDeepXpath(java.lang.String path)
Returns
true if the given path is a Xpath with
at last 2 elements. |
static java.io.OutputStream |
marshal(org.dom4j.Document document,
java.io.OutputStream out,
java.lang.String encoding)
Marshals (writes) an XML document into an output stream using XML pretty-print formatting.
|
static java.lang.String |
marshal(org.dom4j.Document document,
java.lang.String encoding)
Marshals (writes) an XML document to a String using XML pretty-print formatting.
|
static java.lang.String |
marshal(org.dom4j.Node node,
java.lang.String encoding)
Marshals (writes) an XML node into an output stream using XML pretty-print formatting.
|
static java.lang.String |
removeFirstXpathElement(java.lang.String path)
Removes the first Xpath element from the path.
|
static java.lang.String |
removeLastComplexXpathElement(java.lang.String path)
Removes the last complex Xpath element from the path.
|
static java.lang.String |
removeLastXpathElement(java.lang.String path)
Removes the last Xpath element from the path.
|
static java.lang.String |
removeXpath(java.lang.String path)
Removes all Xpath index information from the given input path.
|
static java.lang.String |
removeXpathIndex(java.lang.String path)
Removes the last Xpath index from the given path.
|
static java.lang.String |
simplifyXpath(java.lang.String path)
Simplifies an Xpath by removing a leading and a trailing slash from the given path.
|
static org.dom4j.Document |
unmarshalHelper(byte[] xmlData,
org.xml.sax.EntityResolver resolver)
Helper to unmarshal (read) xml contents from a byte array into a document.
|
static org.dom4j.Document |
unmarshalHelper(byte[] xmlData,
org.xml.sax.EntityResolver resolver,
boolean validate)
Helper to unmarshal (read) xml contents from a byte array into a document.
|
static org.dom4j.Document |
unmarshalHelper(org.xml.sax.InputSource source,
org.xml.sax.EntityResolver resolver)
Helper to unmarshal (read) xml contents from an input source into a document.
|
static org.dom4j.Document |
unmarshalHelper(org.xml.sax.InputSource source,
org.xml.sax.EntityResolver resolver,
boolean validate)
Helper to unmarshal (read) xml contents from an input source into a document.
|
static org.dom4j.Document |
unmarshalHelper(java.lang.String xmlData,
org.xml.sax.EntityResolver resolver)
Helper to unmarshal (read) xml contents from a String into a document.
|
public static java.lang.String createXpath(java.lang.String path, int index)
Examples:
title
becomes title[1]
title[1]
is left untouched
title/subtitle
becomes title[1]/subtitle[1]
title/subtitle[1]
becomes title[1]/subtitle[1]
Note: If the name already has the format title[1]
then provided index parameter
is ignored.
path
- the path to get the simplified Xpath forindex
- the index to append (if required)public static java.lang.String createXpathElement(java.lang.String path, int index)
path[index]
.This method is used if it's clear that some path does not have a square bracket already appended.
path
- the path append the index toindex
- the index to appendpublic static java.lang.String createXpathElementCheck(java.lang.String path, int index)
title[1]
.This method is used if it's uncertain if some path does have a square bracket already appended or not.
Note: If the name already has the format title[1]
, then provided index parameter
is ignored.
path
- the path to get the simplified Xpath forindex
- the index to append (if required)public static java.lang.String getFirstXpathElement(java.lang.String path)
Examples:
title
is left untouched
title[1]
becomes title
title/subtitle
becomes title
title[1]/subtitle[1]
becomes title
path
- the path to get the first Xpath element frompublic static java.lang.String getLastXpathElement(java.lang.String path)
Examples:
title
is left untouched
title[1]
becomes title
title/subtitle
becomes subtitle
title[1]/subtitle[1]
becomes subtitle
path
- the path to get the last Xpath element frompublic static java.lang.String getXpathIndex(java.lang.String path)
Examples:
title
returns the empty String
title[1]
returns [1]
title/subtitle
returns them empty String
title[1]/subtitle[1]
returns [1]
path
- the path to extract the Xpath index frompublic static int getXpathIndexInt(java.lang.String path)
Examples:
title
returns 1
title[1]
returns 1
title/subtitle
returns 1
title[1]/subtitle[2]
returns 2
path
- the path to extract the Xpath index frompublic static boolean isDeepXpath(java.lang.String path)
true
if the given path is a Xpath with
at last 2 elements.
Examples:
title
returns false
title[1]
returns false
title/subtitle
returns true
title[1]/subtitle[1]
returns true
path
- the path to checkpublic static java.io.OutputStream marshal(org.dom4j.Document document, java.io.OutputStream out, java.lang.String encoding) throws java.lang.Exception
document
- the XML document to marshalout
- the output stream to write toencoding
- the encoding to usejava.lang.Exception
- if something goes wrongpublic static java.lang.String marshal(org.dom4j.Document document, java.lang.String encoding) throws java.lang.Exception
document
- the XML document to marshalencoding
- the encoding to usejava.lang.Exception
- if something goes wrongpublic static java.lang.String marshal(org.dom4j.Node node, java.lang.String encoding) throws java.lang.Exception
node
- the XML node to marshalencoding
- the encoding to usejava.lang.Exception
- if something goes wrongpublic static java.lang.String removeFirstXpathElement(java.lang.String path)
If the provided path does not contain a "/" character, it is returned unchanged.
Examples:
title
is left untouched
title[1]
is left untouched
title/subtitle
becomes subtitle
title[1]/subtitle[1]
becomes subtitle[1]
path
- the Xpath to remove the first element frompublic static java.lang.String removeLastComplexXpathElement(java.lang.String path)
The same as removeLastXpathElement(String)
both it works with more complex xpaths.
Example:
system/backup[@date='23/10/2003']/resource[path='/a/b/c']
becomes system/backup[@date='23/10/2003']
path
- the Xpath to remove the last element frompublic static java.lang.String removeLastXpathElement(java.lang.String path)
If the provided path does not contain a "/" character, it is returned unchanged.
Examples:
title
is left untouched
title[1]
is left untouched
title/subtitle
becomes title
title[1]/subtitle[1]
becomes title[1]
path
- the Xpath to remove the last element frompublic static java.lang.String removeXpath(java.lang.String path)
Examples:
title
is left untouched
title[1]
becomes title
title/subtitle
is left untouched
title[1]/subtitle[1]
becomes title/subtitle
path
- the path to remove the Xpath index information frompublic static java.lang.String removeXpathIndex(java.lang.String path)
Examples:
title
is left untouched
title[1]
becomes title
title/subtitle
is left untouched
title[1]/subtitle[1]
becomes title[1]/subtitle
path
- the path to remove the Xpath index frompublic static java.lang.String simplifyXpath(java.lang.String path)
Examples:
title/
becomes title
/title[1]/
becomes title[1]
/title/subtitle/
becomes title/subtitle
/title/subtitle[1]/
becomes title/subtitle[1]
path
- the path to processpublic static org.dom4j.Document unmarshalHelper(byte[] xmlData, org.xml.sax.EntityResolver resolver) throws java.lang.Exception
Using this method ensures that the OpenCms XML entity resolver is used.
xmlData
- the XML data in a byte arrayresolver
- the XML entity resolver to usejava.lang.Exception
- if something goes wrongunmarshalHelper(InputSource, EntityResolver)
public static org.dom4j.Document unmarshalHelper(byte[] xmlData, org.xml.sax.EntityResolver resolver, boolean validate) throws java.lang.Exception
Using this method ensures that the OpenCms XML entity resolver is used.
xmlData
- the XML data in a byte arrayresolver
- the XML entity resolver to usevalidate
- if the reader should try to validate the xml codejava.lang.Exception
- if something goes wrongunmarshalHelper(InputSource, EntityResolver)
public static org.dom4j.Document unmarshalHelper(org.xml.sax.InputSource source, org.xml.sax.EntityResolver resolver) throws java.lang.Exception
Using this method ensures that the OpenCms XML entity resolver is used.
Important: The encoding provided will NOT be used during unmarshalling, the XML parser will do this on the base of the information in the source String. The encoding is used for initializing the created instance of the document, which means it will be used when marshalling the document again later.
source
- the XML input source to useresolver
- the XML entity resolver to usejava.lang.Exception
- if something goes wrongpublic static org.dom4j.Document unmarshalHelper(org.xml.sax.InputSource source, org.xml.sax.EntityResolver resolver, boolean validate) throws java.lang.Exception
Using this method ensures that the OpenCms XML entity resolver is used.
Important: The encoding provided will NOT be used during unmarshalling, the XML parser will do this on the base of the information in the source String. The encoding is used for initializing the created instance of the document, which means it will be used when marshalling the document again later.
source
- the XML input source to useresolver
- the XML entity resolver to usevalidate
- if the reader should try to validate the xml codejava.lang.Exception
- if something goes wrongpublic static org.dom4j.Document unmarshalHelper(java.lang.String xmlData, org.xml.sax.EntityResolver resolver) throws java.lang.Exception
Using this method ensures that the OpenCms XML entitiy resolver is used.
xmlData
- the xml data in a Stringresolver
- the XML entity resolver to usejava.lang.Exception
- if something goes wrongunmarshalHelper(InputSource, EntityResolver)