public class XmlConfigHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static org.infinispan.util.logging.Log |
log |
Constructor and Description |
---|
XmlConfigHelper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escapeBackslashes(java.lang.String value)
Escapes backslashes ('\') with additional backslashes in a given String, returning a new, escaped String.
|
static java.util.Properties |
extractProperties(org.w3c.dom.Element source) |
static java.lang.String |
getAttributeValue(org.w3c.dom.Element elem,
java.lang.String elementName,
java.lang.String attributeName)
Retrieves the value of a given attribute for the first encountered instance of a tag in an element.
|
static org.w3c.dom.Element |
getDocumentRoot(java.io.InputStream is)
Returns the root element of a given input stream
|
static java.lang.String |
getElementContent(org.w3c.dom.Element element,
boolean trim)
Reads the contents of the element passed in.
|
static org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Element element)
Gets the first child element of an element
|
static org.w3c.dom.Element |
getSubElement(org.w3c.dom.Element element,
java.lang.String subElementName)
Returns a named sub-element of the current element passed in.
|
static java.lang.String |
getTagContents(org.w3c.dom.Element elem,
java.lang.String value,
java.lang.String elementName,
java.lang.String attributeName)
Returns the contents of a specific node of given element name, provided a certain attribute exists and is set to
value.
|
static boolean |
readBooleanAttribute(org.w3c.dom.Element elem,
java.lang.String elementName,
java.lang.String attributeName,
boolean defaultValue)
Retrieves the boolean value of a given attribute for the first encountered instance of elementName
|
static boolean |
readBooleanContents(org.w3c.dom.Element element,
java.lang.String elementName)
Similar to
readStringContents(org.w3c.dom.Element,String) except that it returns a boolean. |
static boolean |
readBooleanContents(org.w3c.dom.Element element,
java.lang.String elementName,
boolean defaultValue)
Similar to
readStringContents(org.w3c.dom.Element,String) except that it returns a boolean. |
static java.util.Properties |
readPropertiesContents(org.w3c.dom.Element element) |
static java.util.Properties |
readPropertiesContents(org.w3c.dom.Element element,
java.lang.String elementName)
Reads the contents of a named sub element within a given element, and attempts to parse the contents as a Java
properties file.
|
static java.lang.String |
readStringContents(org.w3c.dom.Element element,
java.lang.String elementName)
Reads the contents of the first occurrence of elementName under the given element, trimming results of whitespace.
|
static java.util.Map<java.lang.Object,java.lang.Object> |
setValues(java.lang.Object target,
java.util.Map<?,?> attribs,
boolean isXmlAttribs,
boolean failOnMissingSetter) |
static void |
showUnrecognizedAttributes(java.util.Map<java.lang.Object,java.lang.Object> attribs) |
static org.w3c.dom.Element |
stringToElement(java.lang.String xml)
Converts a String representing an XML snippet into an
Element . |
static java.lang.String |
toString(org.w3c.dom.Element e) |
public static java.lang.String getTagContents(org.w3c.dom.Element elem, java.lang.String value, java.lang.String elementName, java.lang.String attributeName)
Element
which represents the following XML snippet:
<ItemQuantity Colour="Red">100</ItemQuantity> <ItemQuantity Colour="Blue">30</ItemQuantity> <ItemQuantity Colour="Black">10</ItemQuantity>The following results could be expected:getTagContents(element, "Red", "ItemQuantity", "Colour"); // 100 getTagContents(element, "Black", "ItemQuantity", "Colour"); // 10 getTagContents(element, "Blah", "ItemQuantity", "Colour"); // null getTagContents(element, "Red", "Blah", "Colour"); // null getTagContents(element, "Black", "ItemQuantity", "Blah"); // nullNone of the parameters should be null - otherwise the method may throw a NullPointerException.
elem
- - element to search through.value
- - expected value to match againstelementName
- - element nameattributeName
- - attribute name of the element that would contain the expected value.public static java.lang.String getAttributeValue(org.w3c.dom.Element elem, java.lang.String elementName, java.lang.String attributeName)
Element
which represents the following XML snippet:
<ItemQuantity Colour="Red">100</ItemQuantity> <ItemQuantity Colour="Blue">30</ItemQuantity> <ItemQuantity Colour="Black">10</ItemQuantity>The following results could be expected:getAttributeValue(element, "ItemQuantity", "Colour"); // "Red" getTagContents(element, "Blah", "Colour"); // null getTagContents(element, "ItemQuantity", "Blah"); // nullNone of the parameters should be null - otherwise the method may throw a NullPointerException.
elem
- - element to search through.elementName
- - element nameattributeName
- - attribute name of the element that would contain the expected value.public static org.w3c.dom.Element getSubElement(org.w3c.dom.Element element, java.lang.String subElementName)
element
- - element to search through.subElementName
- - the name of a sub element to look forpublic static java.lang.String getElementContent(org.w3c.dom.Element element, boolean trim)
element
- - element to search through.trim
- - if true, whitespace is trimmed before returningpublic static java.lang.String readStringContents(org.w3c.dom.Element element, java.lang.String elementName)
element
- - element to search through.elementName
- - name of the element to find within the element passed inpublic static java.lang.String escapeBackslashes(java.lang.String value)
value
- String to escape. Cannot be null.public static java.util.Properties readPropertiesContents(org.w3c.dom.Element element, java.lang.String elementName)
Element
which represents the following XML snippet:
<props> my.attrib.1 = blah my.attrib.2 = blahblah </props>The following results could be expected:Properties p = readPropertiesContents(element, "props"); p.getProperty("my.attrib.1"); // blah p.getProperty("my.attrib.2"); // blahblahNone of the parameters should be null - otherwise the method may throw a NullPointerException.
element
- - element to search through.elementName
- - name of the element to find within the element passed inProperties
object, never null.java.io.IOException
- if unable to parse the contents of the elementpublic static java.util.Properties readPropertiesContents(org.w3c.dom.Element element)
public static boolean readBooleanContents(org.w3c.dom.Element element, java.lang.String elementName)
readStringContents(org.w3c.dom.Element,String)
except that it returns a boolean.element
- - element to search through.elementName
- - name of the element to find within the element passed inpublic static boolean readBooleanContents(org.w3c.dom.Element element, java.lang.String elementName, boolean defaultValue)
readStringContents(org.w3c.dom.Element,String)
except that it returns a boolean.element
- - element to search through.elementName
- - name of the element to find within the element passed indefaultValue
- - value to return if the element is not found or cannot be parsed.public static org.w3c.dom.Element stringToElement(java.lang.String xml) throws java.lang.Exception
Element
.xml
- snippet as a stringjava.lang.Exception
- if unable to parse the String or if it doesn't contain valid XML.public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element element)
element
- the parentpublic static org.w3c.dom.Element getDocumentRoot(java.io.InputStream is)
is
- stream to parsepublic static boolean readBooleanAttribute(org.w3c.dom.Element elem, java.lang.String elementName, java.lang.String attributeName, boolean defaultValue)
elem
- - element to searchelementName
- - name of element to findattributeName
- - name of attribute to retrieve the value ofdefaultValue
- - default value to return if not foundpublic static java.util.Map<java.lang.Object,java.lang.Object> setValues(java.lang.Object target, java.util.Map<?,?> attribs, boolean isXmlAttribs, boolean failOnMissingSetter)
public static void showUnrecognizedAttributes(java.util.Map<java.lang.Object,java.lang.Object> attribs)
public static java.util.Properties extractProperties(org.w3c.dom.Element source)
public static java.lang.String toString(org.w3c.dom.Element e)