|
Oracle® Coherence Java API Reference Release 3.7.1.0 E22843-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.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, java.util.Iterator iter) Add the elements from the iterator to the passed XML. |
static java.lang.Object |
convert(java.lang.Object o, int nType) Convert the passed Object to the specified type. |
static java.lang.Object |
createInstance(XmlElement xml, java.lang.ClassLoader loader, XmlHelper.ParameterResolver resolver) Create an instance of the class configured using an XmlElement of the following structure: <! |
static java.lang.Object |
createInstance(XmlElement xml, java.lang.ClassLoader loader, XmlHelper.ParameterResolver resolver, java.lang.Class clzAssignable) Create an instance of the class configured using an XmlElement of the following structure: <! |
static java.lang.String |
decodeAttribute(java.lang.String sValue) Decode an attribute value that was quoted. |
static java.lang.String |
decodeContent(java.lang.String sValue) Decode an element's content value. |
static java.lang.String |
decodeUri(java.lang.String sUri) Decode a System Identifier as per the XML 1.0 Specification 2nd ed section 4.2.2. |
static java.lang.String |
encodeAttribute(java.lang.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 java.lang.String |
encodeContent(java.lang.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 XmlElement |
encodeInitParams(XmlElement xmlParent, XmlElement xmlConfig) Encode the supplied xmlConfig XmlElement as a series of init-param elements. |
static java.lang.String |
encodeUri(java.lang.String sUri) Encode a System Identifier as per the XML 1.0 Specification second edition, section 4.2.2. |
static XmlElement |
ensureElement(XmlElement xml, java.lang.String sPath) Ensure that a child element exists. |
static void |
ensureNamespace(XmlElement xml, java.lang.String sPrefix, java.lang.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, java.lang.String sPath) Find a child element of the specified element with the specified '/'-delimited path. |
static XmlElement |
findElement(XmlElement xml, java.lang.String sPath, java.lang.Object oValue) Find a child element of the specified element with the specified '/'-delimited path and the specified value. |
static java.lang.String |
getAbsolutePath(XmlElement xml) Get the '/'-delimited path of the passed element starting from the root element. |
static XmlValue |
getAttribute(XmlElement xml, java.lang.String sLocal, java.lang.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, java.lang.String sName) Get a child element for the specified element. |
static XmlElement |
getElement(XmlElement xml, java.lang.String sLocal, java.lang.String sUri) Get a child element of the specified XmlElement that matches to the specified local name and the specified Namespace URI. |
static java.util.Iterator |
getElements(XmlElement xml, java.lang.String sLocal, java.lang.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 java.lang.String |
getNamespacePrefix(XmlElement xml, java.lang.String sUri) Retrieve the Namespace prefix for a given URI in a context of the specified XmlElement. |
static java.lang.String |
getNamespaceUri(XmlElement xml, java.lang.String sPrefix) Retrieve the Namespace URI for a given prefix in a context of the specified XmlElement. |
static java.util.List |
getSchemaLocations(XmlElement xml, java.lang.String sPrefix) Retrieve a listing of schema locations (schemaLocation/noNamespaceSchemaLocation) URL's referenced in XmlElement and all of its children. |
static java.lang.String |
getUniversalName(java.lang.String sLocal, java.lang.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(java.lang.String sComment) Validate the passed comment. |
static boolean |
isElementMatch(XmlElement xml, java.lang.String sLocal, java.lang.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(java.lang.String sEncoding) Validate the passed encoding. |
static boolean |
isInstanceConfigEmpty(XmlElement xmlClass) Check whether or not the specified configuration defines an instance of a class. |
static boolean |
isNameMatch(XmlElement xml, java.lang.String sName, java.lang.String sLocal, java.lang.String sUri) Check whether or not a universal (composite) name matches to the specified local name and Namespace URI. |
static boolean |
isNameValid(java.lang.String sName) Validate the passed name. |
static boolean |
isPublicIdentifierValid(java.lang.String sName) Validate the passed public identifier. |
static boolean |
isSystemIdentifierValid(java.lang.String sName) Validate the passed system identifier. |
static boolean |
isWhitespace(char ch) Test if the specified character is XML whitespace. |
static XmlDocument |
loadFileOrResource(java.lang.String sName, java.lang.String sDescr) Load the configuration from a file or resource. |
static XmlDocument |
loadFileOrResource(java.lang.String sName, java.lang.String sDescr, java.lang.ClassLoader loader) Load the configuration from a file or resource. |
static XmlDocument |
loadResource(java.lang.String sName, java.lang.String sDescr) Load the configuration from a resource. |
static XmlDocument |
loadResource(java.lang.String sName, java.lang.String sDescr, java.lang.ClassLoader loader) Load the configuration from resource. |
protected static XmlDocument |
loadResourceInternal(java.lang.String sName, java.lang.String sDescr, java.lang.ClassLoader loader, boolean fFile) Load the configuration from a file or resource. |
static XmlDocument |
loadXml(java.lang.Class clz) Load XML from a file for a class. |
static XmlDocument |
loadXml(java.lang.Class clz, java.lang.String sCharset) Load XML from a file for a class using a given charset. |
static XmlDocument |
loadXml(java.lang.Class clz, java.lang.String sName, java.lang.String sCharset) Load XML from a file that is collocated with the specified class with a given charset. |
static XmlDocument |
loadXml(java.io.InputStream stream) Load XML from a stream. |
static XmlDocument |
loadXml(java.io.InputStream stream, java.lang.String sCharset) Load XML from a stream using the specified charset. |
static XmlDocument |
loadXml(java.lang.String sXml) Load XML from a string. |
static void |
loadXml(java.lang.String sXml, XmlDocument xmlRoot) Load XML from a String into the specified XmlElement. |
static XmlDocument |
loadXml(java.net.URL url) Load the XML from the specified url using the default character set. |
static XmlDocument |
loadXml(java.net.URL url, java.lang.String sCharset) Load the XML from the specified url using the specified character set. |
static void |
overrideElement(XmlElement xmlBase, XmlElement xmlOverride) Override the values of the specified base element with values from the specified override element. |
static void |
overrideElement(XmlElement xmlBase, XmlElement xmlOverride, java.lang.String sIdAttrName) Override the values of the specified base element with values from the specified override element. |
static java.lang.Object[] |
parseInitParams(XmlElement xmlParams) Parse the specified "init-params" element of the following structure: <! |
static java.lang.Object[] |
parseInitParams(XmlElement xmlParams, XmlHelper.ParameterResolver resolver) Parse the specified "init-params" element of the following structure: <! |
static long |
parseTime(XmlElement xml, java.lang.String sName, long cDefault) Parse the String value of the child XmlElement with the given name as a time in milliseconds. |
static void |
purgeChildrenNamespace(XmlElement xml) For the children elements of the specified XmlElement purge the repetitive Namespace declarations. |
static void |
purgeNamespace(XmlElement xml) For the specified XmlElement purge the Namespace declarations that are declared somewhere up the xml tree. |
static java.lang.String |
quote(java.lang.String s) XML quote the passed string. |
static int |
removeElement(XmlElement xml, java.lang.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, java.lang.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 java.lang.String |
toString(XmlSerializable xml) Return the XML of an XmlSerializable object as a String. |
static XmlElement |
transformInitParams(XmlElement xmlParent, XmlElement xmlParams) Transform the specified "init-params" element of the following structure: <! |
static java.lang.String |
trim(java.lang.String s) Trim XML whitespace. |
static java.lang.String |
trimb(java.lang.String s) Trim trailing XML whitespace. |
static java.lang.String |
trimf(java.lang.String s) Trim leading XML whitespace. |
Constructor Detail |
---|
public XmlHelper()
Method Detail |
---|
public static XmlDocument loadXml(java.lang.Class clz)
clz
- the class for which to load the XMLpublic static XmlDocument loadXml(java.lang.Class clz, java.lang.String sCharset)
clz
- the class for which to load the XMLsCharset
- the charset name; pass null to use the default charsetpublic static XmlDocument loadXml(java.lang.Class clz, java.lang.String sName, java.lang.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 charsetpublic static XmlDocument loadXml(java.io.InputStream stream)
stream
- the InputStream objectpublic static XmlDocument loadXml(java.io.InputStream stream, java.lang.String sCharset)
stream
- the InputStream objectsCharset
- the charset namepublic static XmlDocument loadXml(java.net.URL url)
url
- the url from which to load the XMLpublic static XmlDocument loadXml(java.net.URL url, java.lang.String sCharset)
url
- the url from which to load the XMLsCharset
- the charset namepublic static XmlDocument loadXml(java.lang.String sXml)
sXml
- the string containing an XMLpublic static void loadXml(java.lang.String sXml, XmlDocument xmlRoot)
sXml
- the string containing an XMLxmlRoot
- the root XmlElement to parse the string intopublic static XmlDocument loadResource(java.lang.String sName, java.lang.String sDescr)
sName
- the name of the resourcesDescr
- a description of the resource being loaded (e.g. "cache configuration"). The description is only used in logging and error messages related to loading the resourcepublic static XmlDocument loadResource(java.lang.String sName, java.lang.String sDescr, java.lang.ClassLoader loader)
sName
- the name of the resourcesDescr
- a description of the resource being loaded (e.g. "cache configuration"). The description is only used in logging and error messages related to loading the resourceloader
- (optional) ClassLoader that should be used to load the configuration resourcepublic static XmlDocument loadFileOrResource(java.lang.String sName, java.lang.String sDescr)
sName
- the name of the file or resourcesDescr
- a description of the resource being loaded (e.g. "cache configuration"). The description is only used in logging and error messages related to loading the resourcepublic static XmlDocument loadFileOrResource(java.lang.String sName, java.lang.String sDescr, java.lang.ClassLoader loader)
sName
- the name of the file or resourcesDescr
- a description of the resource being loaded (e.g. "cache configuration"). The description is only used in logging and error messages related to loading the resourceloader
- (optional) ClassLoader that should be used to load the configuration resourceprotected static XmlDocument loadResourceInternal(java.lang.String sName, java.lang.String sDescr, java.lang.ClassLoader loader, boolean fFile)
Note: The default character set is used to load configurations provided in files; otherwise the character set "ISO-8859-1" is used.
sName
- the name of the file or resourcesDescr
- a description of the resource being loaded (e.g. "cache configuration"). The description is only used in logging and error messages related to loading the resourceloader
- (optional) ClassLoader that should be used to load the configuration resourcefFile
- true iff the specified name could refer to a filepublic static boolean isEncodingValid(java.lang.String sEncoding)
sEncoding
- the document encodingpublic static boolean isSystemIdentifierValid(java.lang.String sName)
sName
- the system identifier of the XML documentpublic static boolean isPublicIdentifierValid(java.lang.String sName)
sName
- the public identifier of the XML documentpublic static boolean isCommentValid(java.lang.String sComment)
sComment
- the XML commentpublic static boolean isNameValid(java.lang.String sName)
sName
- the XML name to validatepublic static boolean isWhitespace(char ch)
ch
- a characterpublic static java.lang.String trim(java.lang.String s)
s
- the original Stringpublic static java.lang.String trimf(java.lang.String s)
s
- the original Stringpublic static java.lang.String trimb(java.lang.String s)
s
- the original Stringpublic static java.lang.String encodeAttribute(java.lang.String sValue, char chQuote)
sValue
- the attribute value to encodechQuote
- the character that will be used to quote the attributepublic static java.lang.String decodeAttribute(java.lang.String sValue)
sValue
- the attribute value to decodepublic static java.lang.String encodeContent(java.lang.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 java.lang.String decodeContent(java.lang.String sValue)
sValue
- the content value to decodepublic static java.lang.String encodeUri(java.lang.String sUri)
sUri
- the URI to encodepublic static java.lang.String decodeUri(java.lang.String sUri)
sUri
- the URI to decodepublic static java.lang.String quote(java.lang.String s)
s
- the string to quotepublic static java.lang.String getAbsolutePath(XmlElement xml)
xml
- an XML elementpublic static boolean isEmpty(XmlElement xml)
xml
- an XmlElementpublic static XmlElement getElement(XmlElement xml, java.lang.String sName)
xml
- an XML elementsName
- the name of the desired child elementpublic static XmlElement findElement(XmlElement xml, java.lang.String sPath)
xml
- an XML elementsPath
- the path to follow to find the desired XML elementpublic static XmlElement findElement(XmlElement xml, java.lang.String sPath, java.lang.Object oValue)
xml
- an XML elementsPath
- the path to follow to find the desired XML elementoValue
- the value to matchpublic static XmlElement ensureElement(XmlElement xml, java.lang.String sPath)
xml
- and XmlElementsPath
- element pathjava.lang.IllegalArgumentException
- if the name is null or if any part of the path is not a legal XML tag namejava.lang.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, java.util.Iterator iter)
xml
- an XmlElement object to add toiter
- an Iterator of zero or more XmlElement objects to addpublic static int removeElement(XmlElement xml, java.lang.String sName)
xml
- an XmlElementsName
- child element namejava.lang.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 withjava.lang.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 overridden if there is an exact match between the element paths and all 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 XmlElementjava.lang.UnsupportedOperationException
- if the base element is immutable or there is ambiguity between the override and base elementspublic static void overrideElement(XmlElement xmlBase, XmlElement xmlOverride, java.lang.String sIdAttrName)
The values are only overridden if there is an exact match between the element paths and an attribute value for the specified attribute name. 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 the specified attribute's value then the override is not allowed.
xmlBase
- base XmlElementxmlOverride
- override XmlElementsIdAttrName
- attribute name that serves as an identifier allowing to match elements with the same name; if not specified all attributes have to match for an overridejava.lang.UnsupportedOperationException
- if the base element is immutable or there is ambiguity between the override and base elementspublic static void replaceSystemProperties(XmlElement xml, java.lang.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 java.util.List getSchemaLocations(XmlElement xml, java.lang.String sPrefix)
xml
- the XmlElement to processsPrefix
- prefix of schema instancespublic static java.lang.String getNamespaceUri(XmlElement xml, java.lang.String sPrefix)
xml
- the XmlElementsPrefix
- the Namespace prefixpublic static java.lang.String getNamespacePrefix(XmlElement xml, java.lang.String sUri)
xml
- the XmlElementsUri
- the Namespace URIpublic static void ensureNamespace(XmlElement xml, java.lang.String sPrefix, java.lang.String sUri)
xml
- the XmlElementsPrefix
- the Namespace prefixsUri
- the Namespace URIpublic static java.lang.String getUniversalName(java.lang.String sLocal, java.lang.String sPrefix)
sLocal
- the local XML element namesPrefix
- the Namespace prefixpublic static boolean isNameMatch(XmlElement xml, java.lang.String sName, java.lang.String sLocal, java.lang.String sUri)
xml
- the (context) XmlElementsName
- the universal namesLocal
- the local xml namesUri
- the Namespace URIpublic static boolean isElementMatch(XmlElement xml, java.lang.String sLocal, java.lang.String sUri)
xml
- the XmlElementsLocal
- the local xml namesUri
- the Namespace URIpublic static XmlElement getElement(XmlElement xml, java.lang.String sLocal, java.lang.String sUri)
xml
- the parent XmlElementsLocal
- the local xml namesUri
- the Namespace URIpublic static XmlValue getAttribute(XmlElement xml, java.lang.String sLocal, java.lang.String sUri)
xml
- the XmlElementsLocal
- the local attribute namesUri
- the Namespace URIpublic static java.util.Iterator getElements(XmlElement xml, java.lang.String sLocal, java.lang.String sUri)
xml
- the parent XmlElementsLocal
- the local xml namesUri
- the Namespace URIpublic static void purgeNamespace(XmlElement xml)
xml
- the XmlElementpublic static void purgeChildrenNamespace(XmlElement xml)
xml
- the XmlElementpublic static java.lang.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 parsepublic static long parseTime(XmlElement xml, java.lang.String sName, long cDefault)
xml
- the parent XmlElementsName
- the name of the child XmlElementcDefault
- the default valuepublic static java.lang.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
- a ParameterResolver to resolve "{macro}" values (optional)public static XmlElement 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 corresponding 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 XmlElement encodeInitParams(XmlElement xmlParent, XmlElement xmlConfig)
xmlParent
- the element in which to add the init-param elementsxmlConfig
- the element to encode frompublic static boolean isInstanceConfigEmpty(XmlElement xmlClass)
createInstance()
method.xmlClass
- the XML element that contains the instantiation infopublic static java.lang.Object createInstance(XmlElement xml, java.lang.ClassLoader loader, XmlHelper.ParameterResolver resolver)
<!ELEMENT ... (class-name | (class-factory-name, method-name), init-params?> <!ELEMENT init-params (init-param*)> <!ELEMENT init-param ((param-name | param-type), param-value, description?)>As of Coherence 3.6 the supplied element may specify all of the above elements within an <instance> element.
xml
- the XML element that contains the instantiation infoloader
- a ClassLoader that should be used to load necessary classes (optional)resolver
- a ParameterResolver to resolve "{macro}" values (optional)public static java.lang.Object createInstance(XmlElement xml, java.lang.ClassLoader loader, XmlHelper.ParameterResolver resolver, java.lang.Class clzAssignable)
<!ELEMENT ... (class-name | (class-factory-name, method-name), init-params?> <!ELEMENT init-params (init-param*)> <!ELEMENT init-param ((param-name | param-type), param-value, description?)>As of Coherence 3.6 the supplied element may also be of the following format:
<!ELEMENT instance>where the "instance" format is the same as above.
xml
- the XML element that contains the instantiation infoloader
- a ClassLoader that should be used to load necessary classes (optional)resolver
- a ParameterResolver to resolve "{macro}" values (optional)clzAssignable
- if non-null, this method will validate that the Class is assignable from the loaded Classpublic static int hashElement(XmlElement xml)
xml
- the XML elementpublic static int hashValue(XmlValue val)
val
- the XML valuepublic static boolean equalsElement(XmlElement xml1, XmlElement xml2)
xml1
- a non-null XmlElement objectxml2
- a non-null XmlElement objectpublic static boolean equalsValue(XmlValue val1, XmlValue val2)
val1
- a non-null XmlValue objectval2
- a non-null XmlValue objectpublic static java.lang.String toString(XmlSerializable xml)
xml
- an object that can serialize itself into XMLpublic static java.lang.Object convert(java.lang.Object o, int nType)
o
- the object value or nullnType
- the enumerated type to convert to
|
Oracle® Coherence Java API Reference Release 3.7.1.0 E22843-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |