|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.util.XmlUtil
public class XmlUtil
This class provides a set of static methods which perform various utility operations for XML.
Field Summary | |
---|---|
static String |
REVISION
|
static String |
XML_HEADER
|
Method Summary | |
---|---|
static void |
addLangElement(org.jdom.Element parentElt,
String eltName,
Map<String,String> langMap)
Constructs a sub element base on the given language map. |
static String |
extractText(String str)
Extract the text of the given XML/HTML string. |
static String |
extractText(String str,
boolean collapseBlank)
Extract the text of the given XML/HTML string. |
static HashMap<String,String> |
getAttributesAsMap(org.jdom.Element elt)
Return a map of attribute (key, value) from the attributes of the JDom Element |
static boolean |
getBoolean(Object node,
String xpathExpression,
boolean def)
Gives a boolean representation of the first node wich if the result of the XPath expression into the given node in parameter. |
static org.jdom.input.SAXBuilder |
getBuilder()
Get a SAXBuilder |
static Date |
getDate(Object node,
String xpathExpression,
Date def)
Gives a Date representation of the first node wich if the result of the XPath expression into the given node in parameter. |
static org.jdom.Document |
getDocument(File file)
Returns the JDOM document for the given file. |
static org.jdom.Document |
getDocument(InputStream in)
Returns the JDOM document for the given input stream. |
static org.jdom.Document |
getDocument(Reader reader)
Returns the JDOM document for the given reader. |
static org.jdom.Document |
getDocument(String text)
Returns a JDOM document for the given text. |
static org.jdom.Element |
getFirstChild(org.jdom.Element parent,
String childName)
Returns the first child of the given parent with the given name. |
static org.jdom.Element |
getLangChild(org.jdom.Element elt,
String childName,
String lang,
String defaultLang)
Returns the first child of elt if possible which uses lang or
defaultLang as value
for its xml:lang attribute. |
static List<org.jdom.Element> |
getLangChildren(org.jdom.Element elt,
String childName,
String lang)
Returns all the children of elt which use lang as value
for their xml:lang attribute. |
static Map<String,String> |
getLangChildrenMap(org.jdom.Element elt,
String childName)
Returns the map of the children of elt with their xml:lang as key. |
static String |
getLangChildText(org.jdom.Element elt,
String childName,
String lang)
Returns the text of the first child of elt which uses lang as value
for its xml:lang attribute. |
static String |
getLangChildText(org.jdom.Element elt,
String childName,
String lang,
String defaultLang)
Returns the text of the first child of elt which uses lang or
defaultLang as value for its xml:lang attribute. |
static long |
getLong(Object node,
String xpathExpression,
long def)
Gives a long representation of the first node wich if the result of the XPath expression into the given node in parameter. |
static List<?> |
getNodeList(org.jdom.Document doc,
String xpathExpression)
Provide XPath feature : returns the list of Nodes in the xml in first argument, with the xPathExpression in second argument. |
static List<?> |
getNodeList(org.jdom.Element element,
String xpathExpression)
Provide XPath feature : returns the list of Nodes in the xml in first argument, with the xPathExpression in second argument. |
static List<?> |
getNodeList(String xmlString,
String xpathExpression)
Provide XPath feature : returns the list of Nodes in the xml in first argument, with the xPathExpression in second argument. |
static Object |
getSingleNode(Object doc,
String xpathExpression)
Provide XPath feature : returns the first of the Nodes in the xml in first argument, with the xPathExpression in second argument. |
static Object |
getSingleNode(String xmlString,
String xpathExpression)
Provide XPath feature : returns the first of the Nodes in the xml in first argument, with the xPathExpression in second argument. |
static String |
getString(Object node,
String xpathExpression)
Return the most pertinent String for the result of the XPath query in the body content of the given resource. |
static String |
getStringNode(Object node)
Return the most pertinent String representation for this node. |
static String |
getTextValue(Element parentElement,
String tagName)
Returns the text value of the given tag of the given DOM element |
static String |
getTextValue(Element parentElement,
String tagName,
String defaultValue)
Returns the text value of the given tag of the given DOM element or the default value. |
static String |
getXmlString(org.jdom.Element elt)
Returns a String representation of the given element. |
static int |
lastIndexOfElement(org.jdom.Element parentElt,
String eltName)
Returns the position of the latest element with the given name in the parent's childrens or -1 if there is no elements. |
static String |
normalize(String str)
Normalizes the String for XML. |
static void |
removeEmptyElement(org.jdom.Element element)
Remove element if it is no longer a node. |
static org.jdom.Element |
searchChild(org.jdom.Element elt,
String tagName,
String attName,
String attValue)
Returns the first child having a given attribute value. |
static List<org.jdom.Element> |
searchChildren(org.jdom.Element elt,
String tagName,
String attName,
String attValue)
Returns all the children having the given attribute value. |
static org.jdom.Element |
searchElement(org.jdom.Document document,
String tagName,
String attName,
String attValue)
Returns the first element having a given attribute value |
static String |
searchValue(org.jdom.Element element,
String tagName,
String attName)
Returns the first element having a given attribute name |
static void |
updateAttribute(org.jdom.Element elt,
String attr,
String value)
Updates a given attribute value on a given element. |
static void |
updateElements(org.jdom.Element parent,
String childName,
String attName,
Set<String> attrSet)
Update all children attribute value, with the given name, under a given parent Element. |
static void |
updateLangElement(org.jdom.Element parentElt,
String eltName,
Map<String,String> langMap)
Constructs a sub element base on the given language map. |
static void |
write(org.jdom.Document doc,
File file)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
public static final String XML_HEADER
Method Detail |
---|
public static String normalize(String str)
<
,
>
, &
, \
,
"
, \r
, \n
.
All char < 0x20 are ignored except \t, \r, \n
str
- the string to normalize
public static org.jdom.Element searchChild(org.jdom.Element elt, String tagName, String attName, String attValue)
elt
- the element to start the search.tagName
- the elements to be searched for.attName
- the attributes to be searched for.attValue
- the value to be searched for.
public static List<org.jdom.Element> searchChildren(org.jdom.Element elt, String tagName, String attName, String attValue)
elt
- the element to start the search.tagName
- the elements to be searched for.attName
- the attributes to be searched for.attValue
- the value to be searched for.
public static org.jdom.Element searchElement(org.jdom.Document document, String tagName, String attName, String attValue)
document
- the document to start the search.tagName
- the elements to be searched for.attName
- the attributes to be searched for.attValue
- the value to be searched for.
public static String searchValue(org.jdom.Element element, String tagName, String attName)
element
- the element to search on.tagName
- the elements of this document to be searched.attName
- the attributes of this element to be searched.
public static HashMap<String,String> getAttributesAsMap(org.jdom.Element elt)
elt
- the Element to get the attribute
public static org.jdom.input.SAXBuilder getBuilder()
public static org.jdom.Document getDocument(File file) throws org.jdom.JDOMException, IOException
file
- the file.
org.jdom.JDOMException
IOException
public static org.jdom.Document getDocument(InputStream in) throws org.jdom.JDOMException, IOException
in
- the input stream.
org.jdom.JDOMException
IOException
public static org.jdom.Document getDocument(Reader reader) throws org.jdom.JDOMException, IOException
reader
- the reader.
org.jdom.JDOMException
IOException
public static org.jdom.Document getDocument(String text) throws org.jdom.JDOMException, IOException
text
- the text.
org.jdom.JDOMException
IOException
public static void write(org.jdom.Document doc, File file) throws IOException
IOException
public static String getXmlString(org.jdom.Element elt)
elt
- the element
public static org.jdom.Element getLangChild(org.jdom.Element elt, String childName, String lang, String defaultLang)
elt
if possible which uses lang
or
defaultLang
as value
for its xml:lang
attribute.
elt
- the ElementchildName
- the name of the childlang
- the languagedefaultLang
- the default language
elt
which uses lang
as value
for its xml:lang
attribute.public static String getLangChildText(org.jdom.Element elt, String childName, String lang)
elt
which uses lang
as value
for its xml:lang
attribute.
elt
- the ElementchildName
- the name of the childlang
- the language
elt
which uses lang
as value
for its xml:lang
attribute.getLangChildText(Element, String, String, String)
public static String getLangChildText(org.jdom.Element elt, String childName, String lang, String defaultLang)
elt
which uses lang
or
defaultLang
as value for its xml:lang
attribute.
elt
- the ElementchildName
- the name of the childlang
- the languagedefaultLang
- the default language
elt
which uses lang
or defaultLang
as value
for its xml:lang
attribute.public static List<org.jdom.Element> getLangChildren(org.jdom.Element elt, String childName, String lang)
elt
which use lang
as value
for their xml:lang
attribute.
elt
- the ElementchildName
- the name of the childlang
- the language
elt
which uses lang
as value
for its xml:lang
attribute.public static Map<String,String> getLangChildrenMap(org.jdom.Element elt, String childName)
elt
with their xml:lang
as key.
elt
- the ElementchildName
- the name of the child
lang
, elt
}.public static int lastIndexOfElement(org.jdom.Element parentElt, String eltName)
parentElt
- the parent elementeltName
- the name of the sub element
public static void addLangElement(org.jdom.Element parentElt, String eltName, Map<String,String> langMap)
parentElt
- the parent elementeltName
- the name of the sub elementlangMap
- the language mappublic static void updateLangElement(org.jdom.Element parentElt, String eltName, Map<String,String> langMap)
parentElt
- the parent elementeltName
- the name of the sub elementlangMap
- the language mappublic static void updateAttribute(org.jdom.Element elt, String attr, String value)
elt
- the XML Elementattr
- String represents tha attribute namevalue
- the attribute value to setpublic static void updateElements(org.jdom.Element parent, String childName, String attName, Set<String> attrSet)
parent
- the parent ElementchildName
- the children name elementattName
- the children attribute name to work withattrSet
- the set of new values.public static void removeEmptyElement(org.jdom.Element element)
element
- the element to work withpublic static org.jdom.Element getFirstChild(org.jdom.Element parent, String childName)
parent
- the Parent ElementchildName
- the name of the child to look for or create.
public static String getTextValue(Element parentElement, String tagName)
parentElement
- the parenttagName
- the name of the tag to get the text value
public static String getTextValue(Element parentElement, String tagName, String defaultValue)
parentElement
- the parenttagName
- the name of the tag to get the text valuedefaultValue
- the defaultValue
public static String extractText(String str)
str
- the XML/HTML string .
public static String extractText(String str, boolean collapseBlank)
str
- the XML/HTML string .collapseBlank
- if true, series of blanks chars are collapsed in one blank.
public static List<?> getNodeList(String xmlString, String xpathExpression) throws org.jdom.JDOMException
xmlString
- the full XML in a single StringxpathExpression
- the XPath expression
org.jdom.JDOMException
- if the XPath expression is invalid or its evaluation on the specified context failed.public static List<?> getNodeList(org.jdom.Document doc, String xpathExpression) throws org.jdom.JDOMException
doc
- the XML documentxpathExpression
- the XPath expression
org.jdom.JDOMException
- if the XPath expression is invalid or its evaluation on the specified context failed.public static List<?> getNodeList(org.jdom.Element element, String xpathExpression) throws org.jdom.JDOMException
element
- an XML nodexpathExpression
- the XPath expression
org.jdom.JDOMException
- if the XPath expression is invalid or its evaluation on the specified context failed.public static Object getSingleNode(String xmlString, String xpathExpression) throws org.jdom.JDOMException
xmlString
- the XML documentxpathExpression
- the XPath expression
org.jdom.JDOMException
- if the XPath expression is invalid or its evaluation on the specified context failed.public static Object getSingleNode(Object doc, String xpathExpression) throws org.jdom.JDOMException
doc
- the XML documentxpathExpression
- the XPath expression
org.jdom.JDOMException
- if the XPath expression is invalid or its evaluation on the specified context failed.public static String getString(Object node, String xpathExpression)
node
- xpathExpression
- an xpath expression to dig into the node
public static String getStringNode(Object node)
node
- the given resource get by a rest request
public static boolean getBoolean(Object node, String xpathExpression, boolean def)
node
- the node we dig intoxpathExpression
- the XPath expressiondef
- the default value
public static Date getDate(Object node, String xpathExpression, Date def)
node
- the node we dig intoxpathExpression
- the XPath expressiondef
- the default value
public static long getLong(Object node, String xpathExpression, long def)
node
- the node we dig intoxpathExpression
- the XPath expressiondef
- the default value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |