You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2004/02/10 23:15:49 UTC

cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases StoreTests.java

daveremy    2004/02/10 14:15:48

  Modified:    v1/bin   validate
               v1/src/common/org/apache/xmlbeans/impl/common
                        PrefixResolver.java
               v1/src/xmlpublic/org/apache/xmlbeans XmlCursor.java
               v1/src/xmlstore/org/apache/xmlbeans/impl/store Cursor.java
                        Root.java Splay.java Type.java
               v1/test/src/drt/drtcases StoreTests.java
               v2/bin   validate
               v2/src/common/org/apache/xmlbeans/impl/common
                        PrefixResolver.java
               v2/src/xmlpublic/org/apache/xmlbeans XmlCursor.java
               v2/src/xmlstore/org/apache/xmlbeans/impl/store Cursor.java
                        Root.java Splay.java Type.java
               v2/test/src/drt/drtcases StoreTests.java
  Log:
  CR135193: fix strange case where default namespace was not copied to an
  XmlObject from a XMLInputStream.
  
  Submitted by:	Kevin Krouse
  Reviewed by:	ericvas
  
  Revision  Changes    Path
  1.3       +1 -1      xml-xmlbeans/v1/bin/validate
  
  Index: validate
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/bin/validate,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- validate	23 Jan 2004 23:54:17 -0000	1.2
  +++ validate	10 Feb 2004 22:15:48 -0000	1.3
  @@ -9,7 +9,7 @@
   
   case "`uname`" in
       CYGWIN*)
  -        cp=`cygpath -w -p $cp`
  +        CP=`cygpath -w -p $CP`
           ;;
   esac
   
  
  
  
  1.3       +2 -1      xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/PrefixResolver.java
  
  Index: PrefixResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/PrefixResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PrefixResolver.java	24 Sep 2003 23:31:05 -0000	1.2
  +++ PrefixResolver.java	10 Feb 2004 22:15:48 -0000	1.3
  @@ -65,7 +65,8 @@
        * string return result.
        * 
        * If the prefix is null or "", then the default namespace is being
  -     * requested.
  +     * requested.  To conform with the XML spec, the default namespace will
  +     * return the no-namespace ("") if it is not mapped.
        */
       String getNamespaceForPrefix(String prefix);
   }
  
  
  
  1.3       +3 -1      xml-xmlbeans/v1/src/xmlpublic/org/apache/xmlbeans/XmlCursor.java
  
  Index: XmlCursor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlpublic/org/apache/xmlbeans/XmlCursor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XmlCursor.java	24 Sep 2003 23:31:13 -0000	1.2
  +++ XmlCursor.java	10 Feb 2004 22:15:48 -0000	1.3
  @@ -472,7 +472,9 @@
        * context must be at a START or STARTDOC. Namespace prefix mappings
        * are queried for the mappings defined at the current container first,
        * then parents are queried. The prefix can be "" or null to indicate
  -     * a search for the default namespace.<br/><br/>.
  +     * a search for the default namespace.  To conform with the
  +     * XML spec, the default namespace will return the no-namespace ("")
  +     * if it is not mapped.<br/><br/>
        * 
        * Note that this queries the current state of the document. When the 
        * document is persisted, the saving mechanism may synthesize namespaces 
  
  
  
  1.4       +1 -1      xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Cursor.java
  
  Index: Cursor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Cursor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Cursor.java	30 Sep 2003 23:18:15 -0000	1.3
  +++ Cursor.java	10 Feb 2004 22:15:48 -0000	1.4
  @@ -2071,7 +2071,7 @@
               if (getPos() > 0 || !s.isContainer())
                   throw new IllegalStateException( "Not on a container" );
       
  -            return s.namespaceForPrefix( prefix );
  +            return s.namespaceForPrefix( prefix, true );
           }
       }
   
  
  
  
  1.7       +2 -2      xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Root.java
  
  Index: Root.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Root.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Root.java	18 Nov 2003 19:19:04 -0000	1.6
  +++ Root.java	10 Feb 2004 22:15:48 -0000	1.7
  @@ -1379,7 +1379,7 @@
                           String namespace =
                               (String) _additionalNamespaces.get( prefix );
   
  -                        if (s.namespaceForPrefix( prefix ) == null)
  +                        if (s.namespaceForPrefix( prefix, false ) == null)
                           {
                               _root.insertSingleSplaySansSplayInLeftOnlyTree(
                                   new Xmlns( new QName( namespace, prefix ) ),
  @@ -1397,7 +1397,7 @@
               // loading.  When finished loading, bump it.
   
               _root.invalidateVersion();
  -
  +            
               assert _root.isLeftOnly();
           }
   
  
  
  
  1.4       +14 -5     xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Splay.java
  
  Index: Splay.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Splay.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Splay.java	21 Oct 2003 21:53:05 -0000	1.3
  +++ Splay.java	10 Feb 2004 22:15:48 -0000	1.4
  @@ -2415,7 +2415,7 @@
               localname = value;
           }
   
  -        String uri = namespaceForPrefix( prefix );
  +        String uri = namespaceForPrefix( prefix, true );
   
           if (uri == null)
               return null; // no prefix definition found - that's illegal
  @@ -2676,13 +2676,20 @@
        * with a return value of null, which indicates an illegal
        * state, where there is no mapping for the given prefix.
        * <p>
  +     * If the the default namespace is not explicitly mapped in the xml,
  +     * the xml spec says that it should be mapped to the no-namespace.
  +     * When the 'defaultAlwaysMapped' parameter is true, the default namepsace
  +     * will return the no-namespace even if it is not explicity
  +     * mapped, otherwise the default namespace will return null.
  +     * <p>
        * This function intercepts the built-in prefixes "xml" and
        * "xmlns" and returns their well-known namespace URIs.
        *
        * @param prefix The prefix to look up.
  +     * @param mapDefault If true, return the no-namespace for the default namespace if not set.
        * @return The mapped namespace URI ("" if no-namespace), or null if no mapping.
        */
  -    final String namespaceForPrefix ( String prefix )
  +    final String namespaceForPrefix ( String prefix, boolean defaultAlwaysMapped )
       {
           // null same as "", means look up the default namespace
           if (prefix == null)
  @@ -2706,9 +2713,11 @@
               }
           }
   
  -        // no xmlns decl?  no problem for the default namespace
  -        if (prefix.length() == 0)
  -            return "";
  +        // CR135193: if defaultAlwaysMapped, return no-namespace when no default namespace is found
  +        // otherwise, return null to indicate no default namespace was found.
  +        if (defaultAlwaysMapped && prefix.length() == 0) {
  +                return "";
  +        }
   
           // no namespace defn found: return null
           return null;
  
  
  
  1.3       +1 -1      xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlstore/org/apache/xmlbeans/impl/store/Type.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Type.java	24 Sep 2003 23:31:16 -0000	1.2
  +++ Type.java	10 Feb 2004 22:15:48 -0000	1.3
  @@ -711,7 +711,7 @@
           if (s.isAttr())
               s = s.getContainer();
           
  -        return s.namespaceForPrefix( prefix );
  +        return s.namespaceForPrefix( prefix, true );
       }
   
       public TypeStoreUser insert_element_user ( QName name, int i )
  
  
  
  1.3       +61 -0     xml-xmlbeans/v1/test/src/drt/drtcases/StoreTests.java
  
  Index: StoreTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/test/src/drt/drtcases/StoreTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StoreTests.java	24 Sep 2003 23:31:17 -0000	1.2
  +++ StoreTests.java	10 Feb 2004 22:15:48 -0000	1.3
  @@ -2587,4 +2587,65 @@
   
           Assert.assertTrue( x1.xmlText().equals( x2.xmlText() ) );
       }
  +
  +    public void testAdditionalNamespaces()
  +        throws Exception
  +    {
  +        String xml = "<a xmlns:a='aNS'><a:b/></a>";
  +
  +        Map map = new java.util.LinkedHashMap();
  +        map.put("b", "bNS");
  +        map.put("c", "cNS");
  +        map.put("a", "not-aNS");
  +
  +        XmlOptions options = new XmlOptions();
  +        options.setLoadAdditionalNamespaces(map);
  +
  +        XmlObject x = XmlObject.Factory.parse(xml, options);
  +
  +        // 'a' prefix namespace is not remapped
  +        String expect = "<a xmlns:c=\"cNS\" xmlns:b=\"bNS\" xmlns:a=\"aNS\"><a:b/></a>";
  +        Assert.assertEquals( expect, x.xmlText() );
  +
  +        xml = "<a xmlns='aNS'><b/></a>";
  +
  +        map = new java.util.LinkedHashMap();
  +        map.put("b", "bNS");
  +        map.put("c", "cNS");
  +        map.put("", "not-aNS");
  +
  +        options = new XmlOptions();
  +        options.setLoadAdditionalNamespaces(map);
  +
  +        x = XmlObject.Factory.parse(xml, options);
  +
  +        // default namespace is not remapped
  +        expect = "<a xmlns:c=\"cNS\" xmlns:b=\"bNS\" xmlns=\"aNS\"><b/></a>";
  +        Assert.assertEquals( expect, x.xmlText() );
  +
  +    }
  +
  +    public void testCR135193()
  +        throws Exception
  +    {
  +        String xml = "<a xmlns='aNS' xmlns:b='bNS'><b><c/></b></a>";
  +
  +        XmlObject x = XmlObject.Factory.parse(xml);
  +
  +        // get an XMLInputStream and move to XMLEvent.START_ELEMENT for 'b'
  +        XmlCursor c = x.newCursor();
  +        XMLInputStream xis = c.newXMLInputStream();
  +        c.dispose();
  +        while (xis.hasNext() && xis.next().getType() != XMLEvent.START_ELEMENT) {
  +        }
  +
  +        // reparse from 'b' element using an sub-XMLInputStream
  +        XMLInputStream xis1 = xis.getSubStream();
  +        XmlObject x1 = XmlObject.Factory.parse(xis1);
  +
  +        // CR135193: namespaces including default are set on the 'b' child
  +        String expect = "<b xmlns=\"aNS\" xmlns:b=\"bNS\"><c/></b>";
  +        Assert.assertEquals( expect, x1.xmlText() );
  +    }
  +
   }
  
  
  
  1.3       +1 -1      xml-xmlbeans/v2/bin/validate
  
  Index: validate
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/bin/validate,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- validate	24 Jan 2004 01:01:48 -0000	1.2
  +++ validate	10 Feb 2004 22:15:48 -0000	1.3
  @@ -9,7 +9,7 @@
   
   case "`uname`" in
       CYGWIN*)
  -        cp=`cygpath -w -p $cp`
  +        CP=`cygpath -w -p $CP`
           ;;
   esac
   
  
  
  
  1.2       +2 -1      xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/PrefixResolver.java
  
  Index: PrefixResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/PrefixResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrefixResolver.java	26 Sep 2003 21:23:26 -0000	1.1
  +++ PrefixResolver.java	10 Feb 2004 22:15:48 -0000	1.2
  @@ -65,7 +65,8 @@
        * string return result.
        * 
        * If the prefix is null or "", then the default namespace is being
  -     * requested.
  +     * requested.  To conform with the XML spec, the default namespace will
  +     * return the no-namespace ("") if it is not mapped.
        */
       String getNamespaceForPrefix(String prefix);
   }
  
  
  
  1.2       +3 -1      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlCursor.java
  
  Index: XmlCursor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlCursor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlCursor.java	26 Sep 2003 21:23:34 -0000	1.1
  +++ XmlCursor.java	10 Feb 2004 22:15:48 -0000	1.2
  @@ -472,7 +472,9 @@
        * context must be at a START or STARTDOC. Namespace prefix mappings
        * are queried for the mappings defined at the current container first,
        * then parents are queried. The prefix can be "" or null to indicate
  -     * a search for the default namespace.<br/><br/>.
  +     * a search for the default namespace.  To conform with the
  +     * XML spec, the default namespace will return the no-namespace ("")
  +     * if it is not mapped.<br/><br/>
        * 
        * Note that this queries the current state of the document. When the 
        * document is persisted, the saving mechanism may synthesize namespaces 
  
  
  
  1.6       +1 -1      xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Cursor.java
  
  Index: Cursor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Cursor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Cursor.java	4 Nov 2003 23:25:43 -0000	1.5
  +++ Cursor.java	10 Feb 2004 22:15:48 -0000	1.6
  @@ -2081,7 +2081,7 @@
               if (getPos() > 0 || !s.isContainer())
                   throw new IllegalStateException( "Not on a container" );
   
  -            return s.namespaceForPrefix( prefix );
  +            return s.namespaceForPrefix( prefix, true );
           }
       }
   
  
  
  
  1.6       +1 -1      xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Root.java
  
  Index: Root.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Root.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Root.java	26 Jan 2004 18:48:10 -0000	1.5
  +++ Root.java	10 Feb 2004 22:15:48 -0000	1.6
  @@ -1398,7 +1398,7 @@
                           String namespace =
                               (String) _additionalNamespaces.get( prefix );
   
  -                        if (s.namespaceForPrefix( prefix ) == null)
  +                        if (s.namespaceForPrefix( prefix, false ) == null)
                           {
                               _root.insertSingleSplaySansSplayInLeftOnlyTree(
                                   new Xmlns( new QName( namespace, prefix ) ),
  
  
  
  1.3       +14 -5     xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Splay.java
  
  Index: Splay.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Splay.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Splay.java	27 Oct 2003 19:17:21 -0000	1.2
  +++ Splay.java	10 Feb 2004 22:15:48 -0000	1.3
  @@ -2415,7 +2415,7 @@
               localname = value;
           }
   
  -        String uri = namespaceForPrefix( prefix );
  +        String uri = namespaceForPrefix( prefix, true );
   
           if (uri == null)
               return null; // no prefix definition found - that's illegal
  @@ -2676,13 +2676,20 @@
        * with a return value of null, which indicates an illegal
        * state, where there is no mapping for the given prefix.
        * <p>
  +     * If the the default namespace is not explicitly mapped in the xml,
  +     * the xml spec says that it should be mapped to the no-namespace.
  +     * When the 'defaultAlwaysMapped' parameter is true, the default namepsace
  +     * will return the no-namespace even if it is not explicity
  +     * mapped, otherwise the default namespace will return null.
  +     * <p>
        * This function intercepts the built-in prefixes "xml" and
        * "xmlns" and returns their well-known namespace URIs.
        *
        * @param prefix The prefix to look up.
  +     * @param mapDefault If true, return the no-namespace for the default namespace if not set.
        * @return The mapped namespace URI ("" if no-namespace), or null if no mapping.
        */
  -    final String namespaceForPrefix ( String prefix )
  +    final String namespaceForPrefix ( String prefix, boolean defaultAlwaysMapped )
       {
           // null same as "", means look up the default namespace
           if (prefix == null)
  @@ -2706,9 +2713,11 @@
               }
           }
   
  -        // no xmlns decl?  no problem for the default namespace
  -        if (prefix.length() == 0)
  -            return "";
  +        // CR135193: if defaultAlwaysMapped, return no-namespace when no default namespace is found
  +        // otherwise, return null to indicate no default namespace was found.
  +        if (defaultAlwaysMapped && prefix.length() == 0) {
  +                return "";
  +        }
   
           // no namespace defn found: return null
           return null;
  
  
  
  1.2       +1 -1      xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Type.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Type.java	26 Sep 2003 21:23:37 -0000	1.1
  +++ Type.java	10 Feb 2004 22:15:48 -0000	1.2
  @@ -711,7 +711,7 @@
           if (s.isAttr())
               s = s.getContainer();
           
  -        return s.namespaceForPrefix( prefix );
  +        return s.namespaceForPrefix( prefix, true );
       }
   
       public TypeStoreUser insert_element_user ( QName name, int i )
  
  
  
  1.3       +61 -0     xml-xmlbeans/v2/test/src/drt/drtcases/StoreTests.java
  
  Index: StoreTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/StoreTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StoreTests.java	7 Oct 2003 04:08:03 -0000	1.2
  +++ StoreTests.java	10 Feb 2004 22:15:48 -0000	1.3
  @@ -2620,4 +2620,65 @@
   
           Assert.assertTrue( x1.xmlText().equals( x2.xmlText() ) );
       }
  +
  +    public void testAdditionalNamespaces()
  +        throws Exception
  +    {
  +        String xml = "<a xmlns:a='aNS'><a:b/></a>";
  +
  +        Map map = new java.util.LinkedHashMap();
  +        map.put("b", "bNS");
  +        map.put("c", "cNS");
  +        map.put("a", "not-aNS");
  +
  +        XmlOptions options = new XmlOptions();
  +        options.setLoadAdditionalNamespaces(map);
  +
  +        XmlObject x = XmlObject.Factory.parse(xml, options);
  +
  +        // 'a' prefix namespace is not remapped
  +        String expect = "<a xmlns:c=\"cNS\" xmlns:b=\"bNS\" xmlns:a=\"aNS\"><a:b/></a>";
  +        Assert.assertEquals( expect, x.xmlText() );
  +
  +        xml = "<a xmlns='aNS'><b/></a>";
  +
  +        map = new java.util.LinkedHashMap();
  +        map.put("b", "bNS");
  +        map.put("c", "cNS");
  +        map.put("", "not-aNS");
  +
  +        options = new XmlOptions();
  +        options.setLoadAdditionalNamespaces(map);
  +
  +        x = XmlObject.Factory.parse(xml, options);
  +
  +        // default namespace is not remapped
  +        expect = "<a xmlns:c=\"cNS\" xmlns:b=\"bNS\" xmlns=\"aNS\"><b/></a>";
  +        Assert.assertEquals( expect, x.xmlText() );
  +
  +    }
  +
  +    public void testCR135193()
  +        throws Exception
  +    {
  +        String xml = "<a xmlns='aNS' xmlns:b='bNS'><b><c/></b></a>";
  +
  +        XmlObject x = XmlObject.Factory.parse(xml);
  +
  +        // get an XMLInputStream and move to XMLEvent.START_ELEMENT for 'b'
  +        XmlCursor c = x.newCursor();
  +        XMLInputStream xis = c.newXMLInputStream();
  +        c.dispose();
  +        while (xis.hasNext() && xis.next().getType() != XMLEvent.START_ELEMENT) {
  +        }
  +
  +        // reparse from 'b' element using an sub-XMLInputStream
  +        XMLInputStream xis1 = xis.getSubStream();
  +        XmlObject x1 = XmlObject.Factory.parse(xis1);
  +
  +        // CR135193: namespaces including default are set on the 'b' child
  +        String expect = "<b xmlns=\"aNS\" xmlns:b=\"bNS\"><c/></b>";
  +        Assert.assertEquals( expect, x1.xmlText() );
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org