Package com.logicaldoc.util.config
Class XMLBean
java.lang.Object
com.logicaldoc.util.config.XMLBean
- Direct Known Subclasses:
PluginDescriptorConfigurator
,WebConfigurator
Class for using xml-files.
- Version:
- 1.0
- Author:
- Michael Scholz
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.jdom2.Element
findElement
(String xpathExpression) Finds an element using an XPATH expressionorg.jdom2.Element
findElement
(String xpathExpression, Map<String, String> namespaces) Finds an element using an XPATH expressionList
<org.jdom2.Attribute> getAllAttribute
(org.jdom2.Element elem) Returns a list of all attributes from an element.List
<org.jdom2.Element> getAllChildren
(String elemname) Returns a list of all elements with the given element.List
<org.jdom2.Element> getAllChildren
(String elemname, String attribute, String value) Returns a list of all children with the specific name and the specific attribute valuegetAllChildText
(String elemname, String attribute, String value, String separator1, String separator2) This method returns the text of all children in the format childname<separator1>childtext<separator2>org.jdom2.Attribute
getAttribute
(org.jdom2.Element elem, String attrib) Returns an element attribute.getAttributeValue
(org.jdom2.Element elem, String attrib) Returns the value of an elementattribute.org.jdom2.Element
Returns a child element.org.jdom2.Element
This method finds a child by name and attribute.getChildText
(String elemname, String childname, String attribute, String value) This method returns the text of a child element characterized by elementname and attribute.List
<org.jdom2.Element> This method returns all direct children of the root element.org.jdom2.Element
Returns the root element.getText
(org.jdom2.Element elem) This returns the text between a begining and an ending tag.boolean
removeChild
(String elemname) Removes an element.void
setAttributeValue
(org.jdom2.Element elem, String attrib, String value) This method set the value of an elementattribute.void
boolean
This method saves the xml-file connected by XMLBean.
-
Constructor Details
-
XMLBean
Creates new XMLBean.- Parameters:
docPath
- Path of xml-file.
-
XMLBean
Creates new XMLBean.- Parameters:
docname
- URL of xml-file.
-
XMLBean
Creates new XMLBean from an input stream; XMLBean is read-only!!!- Parameters:
is
- contents of the XML structure
-
-
Method Details
-
findElement
Finds an element using an XPATH expression- Parameters:
xpathExpression
- the expression to evaluate- Returns:
- the found element
-
findElement
Finds an element using an XPATH expression- Parameters:
xpathExpression
- the expression to evaluatenamespaces
- map of namespaces as declared into the XML document- Returns:
- the found element
-
getRootElement
public org.jdom2.Element getRootElement()Returns the root element.- Returns:
- the root element
-
getChild
Returns a child element.- Parameters:
elemname
- Name of the child.- Returns:
- the child element
-
getChild
This method finds a child by name and attribute.- Parameters:
elemname
- Name of the child.attribute
- Name of the child attribute.value
- Value of the attribute.- Returns:
- Child
-
getText
This returns the text between a begining and an ending tag.- Parameters:
elem
- Name of the element.- Returns:
- Text of the element.
-
getText
-
getChildText
This method returns the text of a child element characterized by elementname and attribute.- Parameters:
elemname
- Name of the element.childname
- Name of the child.attribute
- Name of the attribute which must element have.value
- Value of the attribute.- Returns:
- Text of the child.
-
getAllChildText
public String getAllChildText(String elemname, String attribute, String value, String separator1, String separator2) This method returns the text of all children in the format childname<separator1>childtext<separator2>- Parameters:
elemname
- Name of the root elementattribute
- Name of the attribute which must root element havevalue
- Value of the attributeseparator1
- string used as first separatorseparator2
- string used as second separator- Returns:
- the children's text
-
getAttribute
Returns an element attribute.- Parameters:
elem
- Name of the element.attrib
- Name of the attribute.- Returns:
- Attribute
-
getAttributeValue
Returns the value of an elementattribute.- Parameters:
elem
- Name of the element.attrib
- Name of the attribute.- Returns:
- Value of the attribute.
-
setAttributeValue
This method set the value of an elementattribute.- Parameters:
elem
- Name of the element.attrib
- Attribute of the element.value
- New value of the attribute.
-
setText
-
writeXMLDoc
public boolean writeXMLDoc()This method saves the xml-file connected by XMLBean. NOTE: only call this on an XMLBean _NOT_ created from an InputStream!- Returns:
- true if the file has been completely written
-
getRootChild
This method returns all direct children of the root element.- Returns:
- Childrenlist
-
getAllAttribute
Returns a list of all attributes from an element.- Parameters:
elem
- Name of the element.- Returns:
- Attributelist
-
getAllChildren
Returns a list of all elements with the given element.- Parameters:
elemname
- name of the element- Returns:
- list of the children elements
-
getAllChildren
Returns a list of all children with the specific name and the specific attribute value- Parameters:
elemname
- name of the elementattribute
- name of the attributevalue
- value of the attribute- Returns:
- the list of children
-
removeChild
Removes an element.- Parameters:
elemname
- Tag name of the element.- Returns:
- true if the deletion has been successful
-