Class PrefixResolver

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.lang.String>, java.util.Map<java.lang.String,​java.lang.String>, NamespaceMap

    class PrefixResolver
    extends java.util.LinkedHashMap<java.lang.String,​java.lang.String>
    implements NamespaceMap
    The PrefixResolver object will store the namespaces for an element. Each namespace added to this map can be added with a prefix. A prefix is added only if the associated reference has not been added to a parent element. If a parent element has the associated reference, then the parents prefix is the one that will be returned when requested from this map.
    See Also:
    OutputElement
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private OutputNode source
      Represents the actual XML element this is associated with.
    • Constructor Summary

      Constructors 
      Constructor Description
      PrefixResolver​(OutputNode source)
      Constructor for the PrefixResolver object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getPrefix()
      This is the prefix that is associated with the source element.
      java.lang.String getPrefix​(java.lang.String reference)
      This acquires the prefix for the specified namespace reference.
      java.lang.String getReference​(java.lang.String prefix)
      This acquires the namespace reference for the specified prefix.
      java.util.Iterator<java.lang.String> iterator()
      This returns an iterator for the namespace of all the nodes in this NamespaceMap.
      private java.lang.String resolvePrefix​(java.lang.String reference)
      This method will resolve the prefix or the specified reference by searching the parent nodes in order.
      private java.lang.String resolveReference​(java.lang.String prefix)
      This method will resolve the reference or the specified prefix by searching the parent nodes in order.
      java.lang.String setReference​(java.lang.String reference)
      This is used to add the namespace reference to the namespace map.
      java.lang.String setReference​(java.lang.String reference, java.lang.String prefix)
      This is used to add the namespace reference to the namespace map.
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
    • Field Detail

      • source

        private final OutputNode source
        Represents the actual XML element this is associated with.
    • Constructor Detail

      • PrefixResolver

        public PrefixResolver​(OutputNode source)
        Constructor for the PrefixResolver object. This is used to create a resolver for namespace prefixes using the hierarchy of elements. Resolving the prefix in this way avoids having to redeclare the same namespace with another prefix in a child element if it has already been declared.
        Parameters:
        source - this is the XML element this is associated to
    • Method Detail

      • getPrefix

        public java.lang.String getPrefix()
        This is the prefix that is associated with the source element. If the source element does not contain a namespace reference then this will return its parents namespace. This ensures that if a namespace has been declared its child elements will inherit its prefix.
        Specified by:
        getPrefix in interface NamespaceMap
        Returns:
        this returns the prefix that is currently in scope
      • setReference

        public java.lang.String setReference​(java.lang.String reference)
        This is used to add the namespace reference to the namespace map. If the namespace has been added to a parent node then this will not add the reference. The prefix added to the map will be the default namespace, which is an empty prefix.
        Specified by:
        setReference in interface NamespaceMap
        Parameters:
        reference - this is the reference to be added
        Returns:
        this returns the prefix that has been replaced
      • setReference

        public java.lang.String setReference​(java.lang.String reference,
                                             java.lang.String prefix)
        This is used to add the namespace reference to the namespace map. If the namespace has been added to a parent node then this will not add the reference.
        Specified by:
        setReference in interface NamespaceMap
        Parameters:
        reference - this is the reference to be added
        prefix - this is the prefix to be added to the reference
        Returns:
        this returns the prefix that has been replaced
      • getPrefix

        public java.lang.String getPrefix​(java.lang.String reference)
        This acquires the prefix for the specified namespace reference. If the namespace reference has been set on this node with a given prefix then that prefix is returned, however if it has not been set this will search the parent elements to find the prefix that is in scope for the specified reference.
        Specified by:
        getPrefix in interface NamespaceMap
        Parameters:
        reference - the reference to find a matching prefix for
        Returns:
        this will return the prefix that is is scope
      • getReference

        public java.lang.String getReference​(java.lang.String prefix)
        This acquires the namespace reference for the specified prefix. If the provided prefix has been set on this node with a given reference then that reference is returned, however if it has not been set this will search the parent elements to find the reference that is in scope for the specified reference.
        Specified by:
        getReference in interface NamespaceMap
        Parameters:
        prefix - the prefix to find a matching reference for
        Returns:
        this will return the reference that is is scope
      • resolveReference

        private java.lang.String resolveReference​(java.lang.String prefix)
        This method will resolve the reference or the specified prefix by searching the parent nodes in order. This allows the prefix that is currently in scope for the reference to be acquired.
        Parameters:
        prefix - the prefix to find a matching reference for
        Returns:
        this will return the reference that is is scope
      • resolvePrefix

        private java.lang.String resolvePrefix​(java.lang.String reference)
        This method will resolve the prefix or the specified reference by searching the parent nodes in order. This allows the prefix that is currently in scope for the reference to be acquired.
        Parameters:
        reference - the reference to find a matching prefix for
        Returns:
        this will return the prefix that is is scope
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        This returns an iterator for the namespace of all the nodes in this NamespaceMap. This allows the namespaces to be iterated within a for each loop in order to extract the prefix values associated with the map.
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Specified by:
        iterator in interface NamespaceMap
        Returns:
        this returns the namespaces contained in this map