Package org.n52.svalbard.util
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXmlHelper.LaxValidationCaseInterface for providing exceptional cases in XML validation (e.g.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappend(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.static voidfixNamespaceForXsiType(org.apache.xmlbeans.XmlObject content, Map<?,?> namespaces)static voidfixNamespaceForXsiType(org.apache.xmlbeans.XmlObject object, QName value)static StringgetLocalName(org.apache.xmlbeans.XmlObject element)static StringgetNamespace(org.apache.xmlbeans.XmlObject doc)static Map<?,?>getNamespaces(org.apache.xmlbeans.XmlObject xmlObject)static NodegetNodeFromNodeList(NodeList nodeList)Get element Node from NodeList.static StringgetPrefixForNamespace(org.apache.xmlbeans.XmlObject element, String namespace)static StringgetXPathPrefix(String prefix, String namespace)static org.apache.xmlbeans.XmlObjectloadXmlDocumentFromFile(File file)Loads a XML document from File.static voidmakeGmlIdsUnique(Node node)Recurse through a node and its children and make all gml:ids uniquestatic voidmakeGmlIdsUnique(Node node, Map<String,Integer> foundIds)Recurse through a node and its children and make all gml:ids uniquestatic StringparseHttpPostBodyWithParameter(Map<String,String[]> parameterMap)Parses the HTTP-Post body with a parameterstatic org.apache.xmlbeans.XmlObjectparseXmlString(String xmlString)static booleanremoveElement(org.apache.xmlbeans.XmlObject element)Remove the element from XML documentstatic voidremoveNamespaces(org.apache.xmlbeans.XmlObject x)Remove namespace declarations from an xml fragment (useful for moving all declarations to a document rootstatic org.apache.xmlbeans.XmlObjectsubstituteElement(org.apache.xmlbeans.XmlObject elementToSubstitute, org.apache.xmlbeans.SchemaType schemaType, QName name)static org.apache.xmlbeans.XmlObjectsubstituteElement(org.apache.xmlbeans.XmlObject elementToSubstitute, org.apache.xmlbeans.XmlObject substitutionElement)static voidupdateGmlIDs(Node node, String gmlID, String oldGmlID)static booleanvalidateDocument(org.apache.xmlbeans.XmlObject doc)static <X extends org.apache.xmlbeans.XmlObject,T extends Throwable>
XvalidateDocument(X doc, Function<Throwable,T> supplier)checks whether the XMLDocument is valid
-
-
-
Method Detail
-
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 extends Throwable
checks whether the XMLDocument is valid- Parameters:
doc- the document which should be checked- Throws:
T- * if the Document is not validT extends Throwable
-
validateDocument
public static boolean validateDocument(org.apache.xmlbeans.XmlObject doc) throws DecodingException- Parameters:
doc- the XML document to validate.- Returns:
trueif 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 examinefoundIds- the already found ids
-
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 tochildDoc- 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)
-
-