Class XmlNamespaceConfiguration

java.lang.Object
com.persequor.xml.XmlNamespaceConfiguration

public class XmlNamespaceConfiguration extends Object
The XmlNamespaceConfiguration is used to map xml namespaces prefixes, in here called aliases, to full xml namespaces. If you wish to add an alias you can call XmlNamespaceConfiguration.getInstance().register("alias", "namespace", null); It is important that this is only done once at application startup or the like. The default mappings are: psqr -> urn:psqr:extension:xsd saga -> urn:saga:extension:xsd epcis -> urn:epcglobal:epcis:xsd:1 (unqualified) epcismd -> urn:epcglobal:epcis-masterdata:xsd:1 (unqualified) epcisq -> urn:epcglobal:epcis-query:xsd:1 (unqualified) sbdh -> http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader
  • Field Details

  • Method Details

    • reset

      public static void reset()
      This method resets xml namespace configuration to SAGA defaults
    • getInstance

      public static XmlNamespaceConfiguration getInstance()
      Returns:
      the active xml configuration instance
    • addUnqualified

      public XmlNamespaceConfiguration addUnqualified(String prefix, String namespace)
      Add or replace unqualified namespace mapping. For unqualified namespaces only the top most tag in the namespace has an xml prefix, like so: <my:tag> <childTag> <grandChild>value</grandChild> </childTag> </my:tag>
      Parameters:
      prefix - prefix used for accessing this namespace in xpaths and other data queries in SAGA
      namespace - namespace value in the xml document, like urn:epcglobal:epcis:xsd:1
      Returns:
      a reference to this
    • add

      public XmlNamespaceConfiguration add(String prefix, String namespace)
      Add or replace qualified namespace mapping. For qualified namespaces all tags under the top most one in this namespace, should also have the alias set. Like so: <my:tag> <my:childTag> <my:grandChild>value</my:grandChild> </my:childTag> </my:tag>
      Parameters:
      prefix - prefix used for accessing this namespace in xpaths and other data queries in SAGA
      namespace - namespace value in the xml document, like urn:epcglobal:epcis:xsd:1
      Returns:
      a reference to this
    • getNamespaceContext

      public NamespaceContext getNamespaceContext()
      Returns:
      a javax namespace context configured by this class
    • setNamespace

      public void setNamespace(Document document)
      Register namespaces in this configuration into this document
      Parameters:
      document - The document to enrich
    • getNamespaceForPrefix

      public Namespace getNamespaceForPrefix(Namespace namespace)
      Parameters:
      namespace - A namespace which may only have alias or full name set
      Returns:
      A namespace with both alias and full name set, according to this configuration
    • getNamespaceConfiguration

      public Optional<XmlNamespaceConfigurationElement> getNamespaceConfiguration(Node node, String namespaceURI)
      Find a configuration for node and namespaceUri
      Parameters:
      node - The node
      namespaceURI - The namespace uri
      Returns:
      an optional configuration element
    • getElements