Class ChangeNamespacePrefixProcessor

  • All Implemented Interfaces:
    NodeProcessor

    public class ChangeNamespacePrefixProcessor
    extends java.lang.Object
    implements NodeProcessor

    NodeProcessor which alters the namespace prefix for all relevant Nodes within an XML document Node. It alters namespace prefixes in the following logical places:

    Schema Namespace Definition
    xmlns:oldPrefix="http://some/namespace" is altered to xmlns:newPrefix="http://some/namespace"
    Elements Namespace Prefix
    <oldPrefix:someElement ... > is altered to <newPrefix:someElement ... >
    Element Reference
    <xs:element ref="oldPrefix:aRequiredElementInTheOldPrefixNamespace"/> is altered to <xs:element ref="newPrefix:aRequiredElementInTheOldPrefixNamespace"/>
    Type Attribute
    <xs:element type="oldPrefix:something"/> is altered to <xs:element type="newPrefix:something"/>
    Type Extension
    <xs:extension base="oldPrefix:something"/> is altered to <xs:extension base="newPrefix:something"/>
    Since:
    1.4
    • Constructor Summary

      Constructors 
      Constructor Description
      ChangeNamespacePrefixProcessor​(java.lang.String oldPrefix, java.lang.String newPrefix)
      Creates a new ChangeNamespacePrefixProcessor providing the oldPrefix which should be replaced by the newPrefix.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(org.w3c.dom.Node aNode)
      Defines if this visitor should process the provided node.
      private boolean isElementReference​(org.w3c.dom.Attr attribute)
      Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form <xs:element ref="oldPrefix:anElementInTheOldPrefixNamespace"/>
      private boolean isExtension​(org.w3c.dom.Attr attribute)
      Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form
      private boolean isNamespaceDefinition​(org.w3c.dom.Attr attribute)
      Discovers if the provided attribute is the oldPrefix namespace definition, i.e.
      private boolean isTypeAttributeWithPrefix​(org.w3c.dom.Attr attribute)
      Discovers if the provided attribute is a type attribute using the oldPrefix namespace, on the form <xs:element type="oldPrefix:anElementInTheOldPrefixNamespace"/>
      void process​(org.w3c.dom.Node aNode)
      Processes the provided DOM Node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EXTENSION_ELEMENT_NAME

        private static final java.lang.String EXTENSION_ELEMENT_NAME
        See Also:
        Constant Field Values
      • EXTENSION_BASE_ATTRIBUTE_NAME

        private static final java.lang.String EXTENSION_BASE_ATTRIBUTE_NAME
        See Also:
        Constant Field Values
      • REFERENCE_ATTRIBUTE_NAME

        private static final java.lang.String REFERENCE_ATTRIBUTE_NAME
        See Also:
        Constant Field Values
      • TYPE_ATTRIBUTE_NAME

        private static final java.lang.String TYPE_ATTRIBUTE_NAME
        See Also:
        Constant Field Values
      • oldPrefix

        private java.lang.String oldPrefix
      • newPrefix

        private java.lang.String newPrefix
    • Constructor Detail

      • ChangeNamespacePrefixProcessor

        public ChangeNamespacePrefixProcessor​(java.lang.String oldPrefix,
                                              java.lang.String newPrefix)
        Creates a new ChangeNamespacePrefixProcessor providing the oldPrefix which should be replaced by the newPrefix.
        Parameters:
        oldPrefix - The old/current namespace prefix
        newPrefix - The new/substituted namespace prefix
    • Method Detail

      • accept

        public boolean accept​(org.w3c.dom.Node aNode)
        Defines if this visitor should process the provided node.
        Specified by:
        accept in interface NodeProcessor
        Parameters:
        aNode - The DOM node to process.
        Returns:
        true if the provided Node should be processed by this NodeProcessor.
      • process

        public void process​(org.w3c.dom.Node aNode)
        Processes the provided DOM Node.
        Specified by:
        process in interface NodeProcessor
        Parameters:
        aNode - The DOM Node to process.
      • isNamespaceDefinition

        private boolean isNamespaceDefinition​(org.w3c.dom.Attr attribute)
        Discovers if the provided attribute is the oldPrefix namespace definition, i.e. if the given attribute is the xmlns:[oldPrefix] within the schema Element.
        Parameters:
        attribute - the attribute to test.
        Returns:
        true if the provided attribute is the oldPrefix namespace definition, i.e. if the given attribute is the xmlns:[oldPrefix] within the schema Element.
      • isElementReference

        private boolean isElementReference​(org.w3c.dom.Attr attribute)
        Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form <xs:element ref="oldPrefix:anElementInTheOldPrefixNamespace"/>
        Parameters:
        attribute - the attribute to test.
        Returns:
        true if the provided attribute is named "ref" and starts with [oldPrefix]:, in which case it is a reference to the oldPrefix namespace.
      • isTypeAttributeWithPrefix

        private boolean isTypeAttributeWithPrefix​(org.w3c.dom.Attr attribute)
        Discovers if the provided attribute is a type attribute using the oldPrefix namespace, on the form <xs:element type="oldPrefix:anElementInTheOldPrefixNamespace"/>
        Parameters:
        attribute - the attribute to test.
        Returns:
        true if the provided attribute is named "type" and starts with [oldPrefix]:, in which case it is a type in the oldPrefix namespace.
      • isExtension

        private boolean isExtension​(org.w3c.dom.Attr attribute)
        Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form

             <xs:extension base="[oldPrefix]:importItem">
         
        Parameters:
        attribute - the attribute to test.
        Returns:
        true if the provided attribute is named "extension" and starts with [oldPrefix]:, in which case it is a reference to the oldPrefix namespace.