Class XmlHelper

java.lang.Object
org.n52.svalbard.util.XmlHelper

public final class XmlHelper extends Object
XML utility class TODO add javadoc to public methods.
Since:
1.0.0
  • Method Details

    • parseHttpPostBodyWithParameter

      public static String parseHttpPostBodyWithParameter(Map<String,String[]> parameterMap) throws DecodingException
      Parses the HTTP-Post body with a parameter
      Parameters:
      parameterMap - Parameter map
      Returns:
      Value of the parameter
      Throws:
      DecodingException - * If the parameter is not supported by this SOS.
    • parseXmlString

      public static org.apache.xmlbeans.XmlObject parseXmlString(String xmlString) throws DecodingException
      Throws:
      DecodingException
    • getNodeFromNodeList

      public static Node getNodeFromNodeList(NodeList nodeList)
      Get element Node from NodeList.
      Parameters:
      nodeList - NodeList.
      Returns:
      Element Node
    • validateDocument

      public static <X extends org.apache.xmlbeans.XmlObject, T extends Throwable> X validateDocument(X doc, Function<Throwable,T> supplier) throws T
      checks whether the XMLDocument is valid
      Parameters:
      doc - the document which should be checked
      Throws:
      T - * if the Document is not valid
    • validateDocument

      public static boolean validateDocument(org.apache.xmlbeans.XmlObject doc) throws DecodingException
      Parameters:
      doc - the XML document to validate.
      Returns:
      true if the given xml document is valid, else an exception is thrown.
      Throws:
      DecodingException - thrown if the given xml document is invalid.
    • loadXmlDocumentFromFile

      public static org.apache.xmlbeans.XmlObject loadXmlDocumentFromFile(File file) throws OwsExceptionReport
      Loads a XML document from File.
      Parameters:
      file - File
      Returns:
      XML document
      Throws:
      OwsExceptionReport - If an error occurs
    • makeGmlIdsUnique

      public static void makeGmlIdsUnique(Node node)
      Recurse through a node and its children and make all gml:ids unique
      Parameters:
      node - The root node
    • makeGmlIdsUnique

      public static void makeGmlIdsUnique(Node node, Map<String,Integer> foundIds)
      Recurse through a node and its children and make all gml:ids unique
      Parameters:
      node - The node to examine
      foundIds - the already found ids
    • updateGmlIDs

      public static void updateGmlIDs(Node node, String gmlID, String oldGmlID)
    • getNamespace

      public static String getNamespace(org.apache.xmlbeans.XmlObject doc)
    • substituteElement

      public static org.apache.xmlbeans.XmlObject substituteElement(org.apache.xmlbeans.XmlObject elementToSubstitute, org.apache.xmlbeans.XmlObject substitutionElement)
    • substituteElement

      public static org.apache.xmlbeans.XmlObject substituteElement(org.apache.xmlbeans.XmlObject elementToSubstitute, org.apache.xmlbeans.SchemaType schemaType, QName name)
    • getPrefixForNamespace

      public static String getPrefixForNamespace(org.apache.xmlbeans.XmlObject element, String namespace)
    • getLocalName

      public static String getLocalName(org.apache.xmlbeans.XmlObject element)
    • append

      public static void append(org.apache.xmlbeans.XmlObject parent, org.apache.xmlbeans.XmlObject childDoc)
      Utility method to append the contents of the child docment to the end of the parent XmlObject. This is useful when dealing with elements without generated methods (like elements with xs:any)
      Parameters:
      parent - Parent to append contents to
      childDoc - Xml document containing contents to be appended
    • removeNamespaces

      public static void removeNamespaces(org.apache.xmlbeans.XmlObject x)
      Remove namespace declarations from an xml fragment (useful for moving all declarations to a document root
      Parameters:
      x - The fragment to localize
    • removeElement

      public static boolean removeElement(org.apache.xmlbeans.XmlObject element)
      Remove the element from XML document
      Parameters:
      element - Element to remove
      Returns:
      true, if element is removed
    • fixNamespaceForXsiType

      public static void fixNamespaceForXsiType(org.apache.xmlbeans.XmlObject object, QName value)
    • fixNamespaceForXsiType

      public static void fixNamespaceForXsiType(org.apache.xmlbeans.XmlObject content, Map<?,?> namespaces)
    • getNamespaces

      public static Map<?,?> getNamespaces(org.apache.xmlbeans.XmlObject xmlObject)
    • getXPathPrefix

      public static String getXPathPrefix(String prefix, String namespace)
      Parameters:
      prefix - The prefix
      namespace - The namespace
      Returns:
      The path