Uploaded image for project: 'Santuario'
  1. Santuario
  2. SANTUARIO-534

DOMNamespaceContext does not implement the NamespaceContext contract correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • Java 2.1.5
    • Java 2.2.0
    • Java
    • None

    Description

      DOMNamespaceContext implements NamespaceContext, but it does not obey the contract defined by NamespaceContext. In addition, it is needlessly stateful, which hampers flexibility and reuse.

      1. getPrefixes(String namespaceURI) must return all prefixes for a given namespace URI (a corner case), however, the implementation returns all prefixes, ignoring the namespace URI. Luckily, this method is not used in practice by the framework, so since it's broken anyway and not used it's better to throw UnsupportedOperationException.
      2. It does not correctly treat constants such as XMLConstants.XMLNS_ATTRIBUTE correctly, as explained in the Javadoc of NamespaceContext.getPrefix(String namespaceURI) and getNamespaceURI(String prefix).
      3. It needlessly builds up a map, and rolls its own implementation of detecting "xmlns" attributes, rather than relying on the Node API for that.

      Solution

      Implement the class as an adapter, adapting the Node API to the NamespaceContext API.
      Leverage methods such as Node.lookupPrefix.
      Beware of the differences in both APIs: Node generally uses null to denote "the default value", while NamespaceContext uses "" (the empty string) for that.

      Attachments

        1. SANTUARIO-534.patch
          14 kB
          Peter De Maeyer

        Issue Links

          Activity

            People

              coheigea Colm O hEigeartaigh
              peterdm Peter De Maeyer
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: