Class EzlibLoader.XmlParser

java.lang.Object
com.saicone.ezlib.EzlibLoader.XmlParser
Enclosing class:
EzlibLoader

public static class EzlibLoader.XmlParser extends Object
The XML parser to handle documents.
  • Constructor Details

    • XmlParser

      public XmlParser()
      Constructs an XML parser with default parameters.
    • XmlParser

      public XmlParser(DocumentBuilder docBuilder, Transformer transformer)
      Constructs an XML parser with provided parameters.
      Parameters:
      docBuilder - the document builder to use.
      transformer - the element transformer to use.
    • XmlParser

      public XmlParser(Supplier<DocumentBuilder> docBuilder, Supplier<Transformer> transformer)
      Constructs an XML parser with provided parameters.
      Parameters:
      docBuilder - the document builder supplier to use.
      transformer - the element transformer supplier to use.
  • Method Details

    • fromUrl

      public Document fromUrl(String url) throws IOException, SAXException
      Get document from URL.
      Parameters:
      url - the URL to connect.
      Returns:
      a parsed document from URL or null.
      Throws:
      IOException - if an I/O exception occurs.
      SAXException - if any parse errors occur.
    • fromFile

      public Document fromFile(File file) throws IOException, SAXException
      Get document from file.
      Parameters:
      file - the file to parse.
      Returns:
      the provided file as document or null.
      Throws:
      IOException - if an I/O exception occurs.
      SAXException - if any parse errors occur.
    • getDocBuilder

      public DocumentBuilder getDocBuilder()
      Get document builder used to parse documents.
      Returns:
      a document builder.
    • getTransformer

      public Transformer getTransformer()
      Get transformed used on this instance.
      Returns:
      a transformer.
    • getNode

      public Node getNode(Element element, String... path)
      Get node from element at provided path.
      Parameters:
      element - the element to see.
      path - the key path.
      Returns:
      a node from provided path or null.
    • getElement

      public Element getElement(Element element, String... path)
      Get element inside element at provided path.
      Parameters:
      element - the element to see.
      path - the key path.
      Returns:
      a element from provided path or null.
    • getElements

      public List<Element> getElements(Element element, String tag, String... path)
      Get element list from provided element path by tag name.
      Parameters:
      element - the element to see.
      tag - the tag name to match elements.
      path - the key path.
      Returns:
      a list containing all the found nodes.
    • getTextContent

      public String getTextContent(Element document, Element element, String... path)
      Get text content from element path.
      Parameters:
      document - the full document if the text content have any node variable to parse.
      element - the element to see.
      path - the key path.
      Returns:
      a parsed string representing the found text from node at path or null.
    • getTextContentOrDefault

      public String getTextContentOrDefault(Element document, Element element, String def, String... path)
      Get text content from element path or use default value if node don't exists.
      Parameters:
      document - the full document if the text content have any node variable to parse.
      element - the element to see.
      def - the default text.
      path - the key path.
      Returns:
      a parsed string representing the found text from node at path or null.
    • toString

      public String toString(Element element)