|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tangosol.util.Base
com.tangosol.run.xml.XmlHelper
public abstract class XmlHelper
This abstract class contains XML manipulation methods.
Nested Class Summary | |
---|---|
static interface |
XmlHelper.ParameterResolver
An interface that describes a callback to resolve a substitutable parameter value. |
Constructor Summary | |
---|---|
XmlHelper()
|
Method Summary | |
---|---|
static void |
addElements(XmlElement xml,
Iterator iter)
Add the elements from the iterator to the passed XML. |
static Object |
convert(Object o,
int nType)
Convert the passed Object to the specified type. |
static String |
decodeAttribute(String sValue)
Decode an attribute value that was quoted. |
static String |
decodeContent(String sValue)
Decode an element's content value. |
static String |
decodeUri(String sUri)
Decode a System Identifier as per the XML 1.0 Specification 2nd ed section 4.2.2. |
static String |
encodeAttribute(String sValue,
char chQuote)
Encode an attribute value so that it can be quoted and made part of a valid and well formed XML document. |
static String |
encodeContent(String sValue,
boolean fPreferBlockEscape)
Encode an element's content value so that it can be made part of a valid and well formed XML document. |
static String |
encodeUri(String sUri)
Encode a System Identifier as per the XML 1.0 Specification second edition, section 4.2.2. |
static XmlElement |
ensureElement(XmlElement xml,
String sPath)
Ensure that a child element exists. |
static void |
ensureNamespace(XmlElement xml,
String sPrefix,
String sUri)
Ensure the existence of the Namespace declaration attribute in a context of the specified XmlElement. |
static boolean |
equalsElement(XmlElement xml1,
XmlElement xml2)
Compare one XML element with another XML element for equality. |
static boolean |
equalsValue(XmlValue val1,
XmlValue val2)
Compare one XML value with another XML value for equality. |
static XmlElement |
findElement(XmlElement xml,
String sPath)
Find a child element of the specified element with the specified '/'-delimited path. |
static XmlElement |
findElement(XmlElement xml,
String sPath,
Object oValue)
Find a child element of the specified element with the specified '/'-delimited path and the specified value. |
static String |
getAbsolutePath(XmlElement xml)
Get the '/'-delimited path of the passed element starting from the root element. |
static XmlValue |
getAttribute(XmlElement xml,
String sLocal,
String sUri)
Get an attribute of the specified XmlElement that matches to the specified local name and the specified Namespace URI. |
static XmlElement |
getElement(XmlElement xml,
String sName)
Get a child element for the specified element. |
static XmlElement |
getElement(XmlElement xml,
String sLocal,
String sUri)
Get a child element of the specified XmlElement that matches to the specified local name and the specified Namespace URI. |
static Iterator |
getElements(XmlElement xml,
String sLocal,
String sUri)
Get an iterator of child elements of the specified XmlElement that match to the specified local name and the specified Namespace URI. |
static String |
getNamespacePrefix(XmlElement xml,
String sUri)
Retrieve the Namespace prefix for a given URI in a context of the specified XmlElement. |
static String |
getNamespaceUri(XmlElement xml,
String sPrefix)
Retrieve the Namespace URI for a given prefix in a context of the specified XmlElement. |
static String |
getUniversalName(String sLocal,
String sPrefix)
Return a universal XML element name. |
static int |
hashElement(XmlElement xml)
Provide a hash value for the XML element and all of its contained information. |
static int |
hashValue(XmlValue val)
Provide a hash value for the XML value. |
static boolean |
isCommentValid(String sComment)
Validate the passed comment. |
static boolean |
isElementMatch(XmlElement xml,
String sLocal,
String sUri)
Check whether or not an element matches to the specified local name and Namespace URI. |
static boolean |
isEmpty(XmlElement xml)
Check whether or not this element or any of its children elements have any content such as values or attributes. |
static boolean |
isEncodingValid(String sEncoding)
Validate the passed encoding. |
static boolean |
isNameMatch(XmlElement xml,
String sName,
String sLocal,
String sUri)
Check whether or not a universal (composite) name matches to the specified local name and Namespace URI. |
static boolean |
isNameValid(String sName)
Validate the passed name. |
static boolean |
isPublicIdentifierValid(String sName)
Validate the passed public identifier. |
static boolean |
isSystemIdentifierValid(String sName)
Validate the passed system identifier. |
static boolean |
isWhitespace(char ch)
Test if the specified character is XML whitespace. |
static XmlDocument |
loadXml(Class clz)
Load XML from a file for a class. |
static XmlDocument |
loadXml(Class clz,
String sCharset)
Load XML from a file for a class using a given charset. |
static XmlDocument |
loadXml(Class clz,
String sName,
String sCharset)
Load XML from a file that is collocated with the specified class with a given charset. |
static XmlDocument |
loadXml(InputStream stream)
Load XML from a stream. |
static XmlDocument |
loadXml(InputStream stream,
String sCharset)
Load XML from a stream using the specified charset. |
static XmlDocument |
loadXml(String sXml)
Load XML from a string. |
static void |
loadXml(String sXml,
XmlDocument xmlRoot)
Load XML from a String into the specified XmlElement. |
static void |
overrideElement(XmlElement xmlBase,
XmlElement xmlOverride)
Override the values of the specified base element with values from the specified override element. |
static Object[] |
parseInitParams(XmlElement xmlParams)
Parse the specified "init-params" element of the following structure: |
static Object[] |
parseInitParams(XmlElement xmlParams,
XmlHelper.ParameterResolver resolver)
Parse the specified "init-params" element of the following structure: |
static void |
purgeChildrenNamespace(XmlElement xml)
For the children elements of the specified XmlElement purge the repetetive Namespace declarations. |
static void |
purgeNamespace(XmlElement xml)
For the specified XmlElement purge the Namespace declarations that are declared somewhere up the xml tree. |
static String |
quote(String s)
XML quote the passed string. |
static int |
removeElement(XmlElement xml,
String sName)
Remove all immediate child elements with the given name |
static boolean |
replaceElement(XmlElement xmlParent,
XmlElement xmlReplace)
Replace a child element with the same name as the specified element. |
static void |
replaceSystemProperties(XmlElement xml,
String sPropertyAttribute)
Replace the values of the XmlElement and all its children that contain the specified attribute with the values returned by the System.getProperty() call. |
static String |
toString(XmlSerializable xml)
Return the XML of an XmlSerializable object as a String. |
static void |
transformInitParams(XmlElement xmlParent,
XmlElement xmlParams)
Transform the specified "init-params" element of the following structure: |
static String |
trim(String s)
Trim XML whitespace. |
static String |
trimb(String s)
Trim trailing XML whitespace. |
static String |
trimf(String s)
Trim leading XML whitespace. |
Constructor Detail |
---|
public XmlHelper()
Method Detail |
---|
public static XmlDocument loadXml(Class clz)
clz
- the class for which to load the XML
public static XmlDocument loadXml(Class clz, String sCharset)
clz
- the class for which to load the XMLsCharset
- the charset name; pass null to use the default charset
public static XmlDocument loadXml(Class clz, String sName, String sCharset)
clz
- the class for which to load the XMLsName
- the XML file name (including extension if any)
that exists in the package from which the class
was loadedsCharset
- the charset name; pass null to use the default charset
public static XmlDocument loadXml(InputStream stream)
stream
- the InputStream object
public static XmlDocument loadXml(InputStream stream, String sCharset)
stream
- the InputStream objectsCharset
- the charset name
public static XmlDocument loadXml(String sXml)
sXml
- the string containing an XML
public static void loadXml(String sXml, XmlDocument xmlRoot)
sXml
- the string containing an XMLxmlRoot
- the root XmlElement to parse the string intopublic static boolean isEncodingValid(String sEncoding)
sEncoding
- the document encoding
public static boolean isSystemIdentifierValid(String sName)
sName
- the system identifier of the XML document
public static boolean isPublicIdentifierValid(String sName)
sName
- the public identifier of the XML document
public static boolean isCommentValid(String sComment)
sComment
- the XML comment
public static boolean isNameValid(String sName)
sName
- the XML name to validate
public static boolean isWhitespace(char ch)
ch
- a character
public static String trim(String s)
s
- the original String
public static String trimf(String s)
s
- the original String
public static String trimb(String s)
s
- the original String
public static String encodeAttribute(String sValue, char chQuote)
sValue
- the attribute value to encodechQuote
- the character that will be used to quote the attribute
public static String decodeAttribute(String sValue)
sValue
- the attribute value to decode
public static String encodeContent(String sValue, boolean fPreferBlockEscape)
sValue
- the content value to encodefPreferBlockEscape
- pass true to use the CDATA escape if two
conditions are met: that escaping is required, and that the
value does not contain the string "]]>"
public static String decodeContent(String sValue)
sValue
- the content value to decode
public static String encodeUri(String sUri)
sUri
- the URI to encode
public static String decodeUri(String sUri)
sUri
- the URI to decode
public static String quote(String s)
s
- the string to quote
public static String getAbsolutePath(XmlElement xml)
xml
- an XML element
public static boolean isEmpty(XmlElement xml)
xml
- an XmlElement
public static XmlElement getElement(XmlElement xml, String sName)
xml
- an XML elementsName
- the name of the desired child element
public static XmlElement findElement(XmlElement xml, String sPath)
xml
- an XML elementsPath
- the path to follow to find the desired XML element
public static XmlElement findElement(XmlElement xml, String sPath, Object oValue)
xml
- an XML elementsPath
- the path to follow to find the desired XML elementoValue
- the value to match
public static XmlElement ensureElement(XmlElement xml, String sPath)
xml
- and XmlElementsPath
- element path
IllegalArgumentException
- if the name is null or if any part
of the path is not a legal XML tag name
UnsupportedOperationException
- if any element in the path
is immutable or otherwise can not add a child elementfindElement(XmlElement, String)
public static void addElements(XmlElement xml, Iterator iter)
xml
- an XmlElement object to add toiter
- an Iterator of zero or more XmlElement objects to addpublic static int removeElement(XmlElement xml, String sName)
xml
- an XmlElementsName
- child element name
UnsupportedOperationException
- if the element is immutable
or otherwise cannot remove a child elementpublic static boolean replaceElement(XmlElement xmlParent, XmlElement xmlReplace)
xmlParent
- parent XmlElementxmlReplace
- element to replace with
UnsupportedOperationException
- if the parent element is immutable
or otherwise cannot remove a child elementpublic static void overrideElement(XmlElement xmlBase, XmlElement xmlOverride)
The values are only overriden if there is an exact match between the element paths and attribute values. Empty override values are ignored. Override elements that do not match any of the base elements are just copied over. No ambiguity is allowed.
For example, if the base element has more then one child with the same name and attributes then the override is not allowed.
xmlBase
- base XmlElementxmlOverride
- override XmlElement
UnsupportedOperationException
- if the base element is immutable
or there is ambiguity between the override and base elementspublic static void replaceSystemProperties(XmlElement xml, String sPropertyAttribute)
This method iterates the specified XmlElement tree and for each element that contains the attribute with the specified name replaces its value with the value of the corresponding system property (if exists).
xml
- the XmlElement to processsPropertyAttribute
- the name of the attribute that supplies the
corresponding system property namepublic static String getNamespaceUri(XmlElement xml, String sPrefix)
xml
- the XmlElementsPrefix
- the Namespace prefix
public static String getNamespacePrefix(XmlElement xml, String sUri)
xml
- the XmlElementsUri
- the Namespace URI
public static void ensureNamespace(XmlElement xml, String sPrefix, String sUri)
xml
- the XmlElementsPrefix
- the Namespace prefixsUri
- the Namespace URIpublic static String getUniversalName(String sLocal, String sPrefix)
sLocal
- the local XML element namesPrefix
- the Namespace prefix
public static boolean isNameMatch(XmlElement xml, String sName, String sLocal, String sUri)
xml
- the (context) XmlElementsName
- the universal namesLocal
- the local xml namesUri
- the Namespace URI
public static boolean isElementMatch(XmlElement xml, String sLocal, String sUri)
xml
- the XmlElementsLocal
- the local xml namesUri
- the Namespace URI
public static XmlElement getElement(XmlElement xml, String sLocal, String sUri)
xml
- the parent XmlElementsLocal
- the local xml namesUri
- the Namespace URI
public static XmlValue getAttribute(XmlElement xml, String sLocal, String sUri)
xml
- the XmlElementsLocal
- the local attribute namesUri
- the Namespace URI
public static Iterator getElements(XmlElement xml, String sLocal, String sUri)
xml
- the parent XmlElementsLocal
- the local xml namesUri
- the Namespace URI
public static void purgeNamespace(XmlElement xml)
xml
- the XmlElementpublic static void purgeChildrenNamespace(XmlElement xml)
xml
- the XmlElementpublic static Object[] parseInitParams(XmlElement xmlParams)
[!ELEMENT init-params (init-param*)] [!ELEMENT init-param ((param-name | param-type), param-value, description?)]into an object array.
For the purpose of this method only the parameters that have the "param-type" element specified are processed. The following types are supported:
xmlParams
- the "init-params" XmlElement to parse
public static Object[] parseInitParams(XmlElement xmlParams, XmlHelper.ParameterResolver resolver)
[!ELEMENT init-params (init-param*)] [!ELEMENT init-param ((param-name | param-type), param-value, description?)]into an object array.
For the purpose of this method only the parameters that have the "param-type" element specified are processed. The following types are supported:
xmlParams
- the "init-params" XmlElement to parseresolver
- an optional ParameterResolver
public static void transformInitParams(XmlElement xmlParent, XmlElement xmlParams)
[!ELEMENT init-params (init-param*)] [!ELEMENT init-param ((param-name | param-type), param-value, description?)]into an XML element composed of the corrsponding names. For example, the the "init-params" element of the following structure:
<init-param> <param-name>NameOne</param-name> <param-value>ValueOne</param-value> </init-param> <init-param> <param-name>NameTwo</param-name> <param-value>ValueTwo</param-value> </init-param>will transform into
<NameOne>ValueOne</NameOne> <NameTwo>ValueTwo</NameTwo>For the purpose of this method only the parameters that have the "param-name" element specified are processed.
xmlParent
- the XML element to insert the transformed elements intoxmlParams
- the "init-params" XmlElement to parsepublic static int hashElement(XmlElement xml)
xml
- the XML element
public static int hashValue(XmlValue val)
val
- the XML value
public static boolean equalsElement(XmlElement xml1, XmlElement xml2)
xml1
- a non-null XmlElement objectxml2
- a non-null XmlElement object
public static boolean equalsValue(XmlValue val1, XmlValue val2)
val1
- a non-null XmlValue objectval2
- a non-null XmlValue object
public static String toString(XmlSerializable xml)
xml
- an object that can serialize itself into XML
public static Object convert(Object o, int nType)
o
- the object value or nullnType
- the enumerated type to convert to
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |