Package com.logicaldoc.util.config
Class XMLBean
- java.lang.Object
-
- com.logicaldoc.util.config.XMLBean
-
- Direct Known Subclasses:
PluginDescriptorConfigurator
,WebConfigurator
public class XMLBean extends Object
Class for using xml-files.- Version:
- 1.0
- Author:
- Michael Scholz
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.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
getAllAttribute(org.jdom2.Element elem)
Returns a list of all attributes from an element.List
getAllChildren(String elemname)
Returns a list of all elements with the given element.List
getAllChildren(String elemname, String attribute, String value)
Returns a list of all children with the specific name and the specific attribute valueString
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>org.jdom2.Attribute
getAttribute(org.jdom2.Element elem, String attrib)
Returns an element attribute.String
getAttributeValue(org.jdom2.Element elem, String attrib)
Returns the value of an elementattribute.org.jdom2.Element
getChild(String elemname)
Returns a child element.org.jdom2.Element
getChild(String elemname, String attribute, String value)
This method finds a child by name and attribute.String
getChildText(String elemname, String childname, String attribute, String value)
This method returns the text of a child element characterized by elementname and attribute.List
getRootChild()
This method returns all direct children of the root element.org.jdom2.Element
getRootElement()
Returns the root element.String
getText(String elemname, String attrname, String attrvalue)
String
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
setText(org.jdom2.Element elem, String text)
boolean
writeXMLDoc()
This method saves the xml-file connected by XMLBean.
-
-
-
Constructor Detail
-
XMLBean
public XMLBean(String docPath)
Creates new XMLBean.- Parameters:
docPath
- Path of xml-file.
-
XMLBean
public XMLBean(URL docname)
Creates new XMLBean.- Parameters:
docname
- URL of xml-file.
-
XMLBean
public XMLBean(InputStream is)
Creates new XMLBean from an input stream; XMLBean is read-only!!!- Parameters:
is
- contents of the XML structure
-
-
Method Detail
-
findElement
public org.jdom2.Element findElement(String xpathExpression)
Finds an element using an XPATH expression- Parameters:
xpathExpression
- the expression to evaluate- Returns:
- the found element
-
findElement
public org.jdom2.Element findElement(String xpathExpression, Map<String,String> namespaces)
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
public org.jdom2.Element getChild(String elemname)
Returns a child element.- Parameters:
elemname
- Name of the child.- Returns:
- the child element
-
getChild
public org.jdom2.Element getChild(String elemname, String attribute, String value)
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
public String getText(org.jdom2.Element elem)
This returns the text between a begining and an ending tag.- Parameters:
elem
- Name of the element.- Returns:
- Text of the element.
-
getChildText
public String getChildText(String elemname, String childname, String attribute, String value)
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
public org.jdom2.Attribute getAttribute(org.jdom2.Element elem, String attrib)
Returns an element attribute.- Parameters:
elem
- Name of the element.attrib
- Name of the attribute.- Returns:
- Attribute
-
getAttributeValue
public String getAttributeValue(org.jdom2.Element elem, String attrib)
Returns the value of an elementattribute.- Parameters:
elem
- Name of the element.attrib
- Name of the attribute.- Returns:
- Value of the attribute.
-
setAttributeValue
public void setAttributeValue(org.jdom2.Element elem, String attrib, String value)
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
public void setText(org.jdom2.Element elem, String text)
-
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
public List getRootChild()
This method returns all direct children of the root element.- Returns:
- Childrenlist
-
getAllAttribute
public List getAllAttribute(org.jdom2.Element elem)
Returns a list of all attributes from an element.- Parameters:
elem
- Name of the element.- Returns:
- Attributelist
-
getAllChildren
public List getAllChildren(String elemname)
Returns a list of all elements with the given element.- Parameters:
elemname
- name of the element- Returns:
- list of the children elements
-
getAllChildren
public List getAllChildren(String elemname, String attribute, String value)
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
public boolean removeChild(String elemname)
Removes an element.- Parameters:
elemname
- Tag name of the element.- Returns:
- true if the deletion has been successful
-
-