Class XmlTools

java.lang.Object
io.goobi.viewer.controller.XmlTools

public final class XmlTools extends Object
XML utilities.
  • Method Details

    • getSAXBuilder

      public static org.jdom2.input.SAXBuilder getSAXBuilder()
    • readXmlFile

      public static org.jdom2.Document readXmlFile(String filePath) throws IOException, org.jdom2.JDOMException

      readXmlFile.

      Parameters:
      filePath - a String object.
      Returns:
      a Document object.
      Throws:
      FileNotFoundException - if any.
      IOException - if any.
      org.jdom2.JDOMException - if any.
    • readXmlFile

      public static org.jdom2.Document readXmlFile(URL url) throws IOException, org.jdom2.JDOMException
      Reads an XML document from the given URL and returns a JDOM2 document. Works with XML files within JARs.
      Parameters:
      url - a URL object.
      Returns:
      a Document object.
      Throws:
      FileNotFoundException - if any.
      IOException - if any.
      org.jdom2.JDOMException - if any.
    • readXmlFile

      public static org.jdom2.Document readXmlFile(Path path) throws IOException, org.jdom2.JDOMException

      readXmlFile.

      Parameters:
      path - a Path object.
      Returns:
      a Document object.
      Throws:
      FileNotFoundException - if any.
      IOException - if any.
      org.jdom2.JDOMException - if any.
    • writeXmlFile

      public static File writeXmlFile(org.jdom2.Document doc, String filePath) throws IOException

      writeXmlFile.

      Parameters:
      doc - a Document object.
      filePath - a String object.
      Returns:
      a File object.
      Throws:
      FileNotFoundException - if any.
      IOException - if any.
    • getDocumentFromString

      public static org.jdom2.Document getDocumentFromString(String string, String encoding) throws org.jdom2.JDOMException, IOException
      Create a JDOM document from an XML string.
      Parameters:
      string - a String object.
      encoding - a String object.
      Returns:
      a Document object.
      Throws:
      org.jdom2.JDOMException - if any.
      IOException - if any.
    • getStringFromElement

      public static String getStringFromElement(Object element, String encoding)

      getStringFromElement.

      Parameters:
      element - a Object object.
      encoding - a String object.
      Returns:
      a String object.
    • evaluateToElements

      public static List<org.jdom2.Element> evaluateToElements(String expr, org.jdom2.Element element, List<org.jdom2.Namespace> namespaces)
      Evaluates the given XPath expression to a list of elements.
      Parameters:
      expr - XPath expression to evaluate.
      element - a Element object.
      namespaces - a List object.
      Returns:
      ArrayList or null
    • evaluateToFirstElement

      public static Optional<org.jdom2.Element> evaluateToFirstElement(String expr, org.jdom2.Element element, List<org.jdom2.Namespace> namespaces)
    • evaluate

      public static List<Object> evaluate(String expr, Object parent, org.jdom2.filter.Filter filter, List<org.jdom2.Namespace> namespaces)
      XPath evaluation with a given return type filter.
      Parameters:
      expr - XPath expression to evaluate.
      parent - If not null, the expression is evaluated relative to this element.
      filter - Return type filter.
      namespaces - a List object.
      Returns:
      a List object.
    • evaluateAttributeString

      public static List<String> evaluateAttributeString(String expr, Object parent, List<org.jdom2.Namespace> namespaces)
    • evaluateString

      public static List<String> evaluateString(String expr, Object parent, List<org.jdom2.Namespace> namespaces)
    • evaluateToFirstAttributeString

      public static Optional<String> evaluateToFirstAttributeString(String expr, Object parent, List<org.jdom2.Namespace> namespaces)
    • evaluateToFirstString

      public static Optional<String> evaluateToFirstString(String expr, Object parent, List<org.jdom2.Namespace> namespaces)
    • determineFileFormat

      public static String determineFileFormat(String xml, String encoding) throws org.jdom2.JDOMException, IOException

      determineFileFormat.

      Parameters:
      xml - a String object.
      encoding - a String object.
      Returns:
      a String object.
      Throws:
      org.jdom2.JDOMException - if any.
      IOException - if any.
    • determineFileFormat

      public static String determineFileFormat(org.jdom2.Document doc)
      Determines the format of the given XML file by checking for namespaces.
      Parameters:
      doc - a Document object.
      Returns:
      a String object.
    • checkXMLWellformed

      public static List<XMLError> checkXMLWellformed(String xml) throws ParserConfigurationException, SAXException, IOException
      Parameters:
      xml -
      Returns:
      List
      Throws:
      ParserConfigurationException
      SAXException
      IOException