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
  • Constructor Details

    • 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 Details

    • 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 evaluate
      namespaces - 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.
    • getText

      public String getText(String elemname, String attrname, String attrvalue)
    • 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 element
      attribute - Name of the attribute which must root element have
      value - Value of the attribute
      separator1 - string used as first separator
      separator2 - 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<org.jdom2.Element> getRootChild()
      This method returns all direct children of the root element.
      Returns:
      Childrenlist
    • getAllAttribute

      public List<org.jdom2.Attribute> 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<org.jdom2.Element> 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<org.jdom2.Element> 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 element
      attribute - name of the attribute
      value - 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