xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eric...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/erictest EricTest.java
Date Fri, 05 Mar 2004 01:17:05 GMT
ericvas     2004/03/04 17:17:05

  Modified:    v2/src/newstore2/org/apache/xmlbeans/impl/newstore2
                        Cursor.java Saver.java
               v2/test/src/erictest EricTest.java
  Log:
  More XmlCursor ops
  
  Revision  Changes    Path
  1.6       +71 -33    xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Cursor.java
  
  Index: Cursor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Cursor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Cursor.java	4 Mar 2004 23:56:21 -0000	1.5
  +++ Cursor.java	5 Mar 2004 01:17:05 -0000	1.6
  @@ -152,10 +152,10 @@
           throw new IllegalArgumentException( msg );
       }
   
  -    static void insert ( Cur thisStuff, Cur there )
  +    private void insert ( Cur thisStuff )
       {
           assert isValid( thisStuff );
  -        assert isValid( there );
  +        assert isValid();
   
           int thisKind = thisStuff.kind();
   
  @@ -165,29 +165,44 @@
           if (thisKind == ROOT)
               complain( "Can't move/copy/insert a whole document." );
   
  -        int thereKind = there.kind();
  +        int k = _cur.kind();
   
  -        if (thereKind == ROOT)
  +        if (k == ROOT)
               complain( "Can't insert before the start of the document." );
   
  -        if (thereKind == ATTR && thisKind != TEXT)
  +        if (k == ATTR && thisKind != TEXT)
               complain( "Can only insert attributes before other attributes." );
   
           if (thisKind == ATTR)
           {
  -            there.push();
  -            there.prev();
  -            int prevKind = there.kind();
  -            there.pop();
  +            _cur.push();
  +            _cur.prev();
  +            int pk = _cur.kind();
  +            _cur.pop();
   
  -            if (prevKind != -ELEM || prevKind != -ROOT || prevKind != -ATTR)
  -                complain( "Can only insert attributes before other attributes." );
  +            if (pk != ELEM && pk != ROOT && pk != -ATTR)
  +            {
  +                complain(
  +                    "Can only insert attributes before other attributes or after containers."
);
  +            }
           }
   
           if (thisKind == TEXT)
  -            thisStuff.moveChars( there, -1 );
  +            thisStuff.moveChars( _cur, -1 );
           else
  -            thisStuff.moveNode( there );
  +            thisStuff.moveNode( _cur );
  +    }
  +    
  +    private void insertWithValue ( Cur thisStuff, String text )
  +    {
  +        if (text != null && text.length() > 0)
  +        {
  +            thisStuff.next();
  +            thisStuff.insertChars( text, 0, text.length() );
  +            thisStuff.toParent();
  +        }
  +
  +        insert( thisStuff );
       }
       
       //
  @@ -906,14 +921,7 @@
   
           c.createElement( name );
   
  -        if (text != null && text.length() > 0)
  -        {
  -            c.next();
  -            c.insertChars( text, 0, text.length() );
  -            c.toParent();
  -        }
  -
  -        insert( c, _cur );
  +        insertWithValue( c, text );
   
           c.release();
       }
  @@ -924,47 +932,77 @@
       
       public void _insertAttribute ( String localName )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        _insertAttributeWithValue( localName, null );
       }
       
       public void _insertAttribute ( String localName, String uri )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        _insertAttributeWithValue( localName, uri, null );
       }
       
       public void _insertAttribute ( QName name )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        _insertAttributeWithValue( name, null );
       }
       
  -    public void _insertAttributeWithValue ( String Name, String value )
  +    public void _insertAttributeWithValue ( String localName, String value )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        _insertAttributeWithValue( localName, null, value );
       }
       
  -    public void _insertAttributeWithValue ( String name, String uri, String value )
  +    public void _insertAttributeWithValue ( String localName, String uri, String value
)
       {
  -        throw new RuntimeException( "Not implemented" );
  +        _insertAttributeWithValue( _locale.makeQName( uri, localName ), value );
       }
       
  -    public void _insertAttributeWithValue ( QName name, String value )
  +    public void _insertAttributeWithValue ( QName name, String text )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        Cur c = _locale.tempCur();
  +
  +        c.createAttr( name );
  +
  +        insertWithValue( c, text );
  +        
  +        c.release();
       }
  +
  +    //
  +    //
  +    //
       
       public void _insertNamespace ( String prefix, String namespace )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        if (prefix == null)
  +            prefix = "";
  +
  +        QName name =
  +            prefix.length() == 0
  +                ? _locale.makeQName( _locale._xmlnsUri, "xmlns", "" )
  +                : _locale.makeQName( _locale._xmlnsUri, "xmlns", prefix );
  +
  +        _insertAttributeWithValue( name, namespace );
       }
       
       public void _insertComment ( String text )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        Cur c = _locale.tempCur();
  +
  +        c.createComment();
  +        
  +        insertWithValue( c, text );
  +        
  +        c.release();
       }
       
       public void _insertProcInst ( String target, String text )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        Cur c = _locale.tempCur();
  +
  +        c.createProcinst( target );
  +
  +        insertWithValue( c, text );
  +        
  +        c.release();
       }
   
       //
  
  
  
  1.11      +2 -0      xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Saver.java
  
  Index: Saver.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Saver.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Saver.java	3 Mar 2004 22:56:38 -0000	1.10
  +++ Saver.java	5 Mar 2004 01:17:05 -0000	1.11
  @@ -1011,6 +1011,8 @@
                       _in = (_in + cch) % _buf.length;
                   }
               }
  +            else
  +                preEmit( 0 );
           }
           
           private void emitValue ( SaveCur c )
  
  
  
  1.30      +4 -7      xml-xmlbeans/v2/test/src/erictest/EricTest.java
  
  Index: EricTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/erictest/EricTest.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- EricTest.java	4 Mar 2004 23:56:21 -0000	1.29
  +++ EricTest.java	5 Mar 2004 01:17:05 -0000	1.30
  @@ -111,13 +111,10 @@
           c.toNextToken();
   
           c.beginElement( "foo" );
  -        c.beginElement( "bar" );
  -        c.beginElement( "baz" );
  -
  -        c.toNextToken();
  -        c.toNextToken();
  -        
  -        c.beginElement( "bar2" );
  +        c.insertAttributeWithValue( "a1", "<>><<" );
  +        c.insertComment( "comment" );
  +        c.insertProcInst( "target", "value" );
  +        c.insertElementWithText( "gag", "text" );
   
           c.toStartDoc();
   
  
  
  

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


Mime
View raw message