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 Thu, 11 Mar 2004 19:50:29 GMT
ericvas     2004/03/11 11:50:29

  Modified:    v2/src/newstore2/org/apache/xmlbeans/impl/newstore2 Cur.java
                        Cursor.java Jsr173.java Locale.java Saver.java
               v2/test/src/erictest EricTest.java
  Log:
  New saver
  
  Revision  Changes    Path
  1.16      +29 -35    xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Cur.java
  
  Index: Cur.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Cur.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Cur.java	4 Mar 2004 23:56:21 -0000	1.15
  +++ Cur.java	11 Mar 2004 19:50:29 -0000	1.16
  @@ -1628,20 +1628,12 @@
   
           boolean isXmlns ( )
           {
  -            if (!isAttr())
  -                return false;
  -
  -            String prefix = _name.getPrefix();
  -
  -            if (prefix.equals( "xmlns" ))
  -                return true;
  -
  -            return prefix.length() == 0 && _name.getLocalPart().equals( "xmlns" );
  +            return isAttr() ? Locale.isXmlns( _name ) : false;
           }
   
           String getXmlnsPrefix ( )
           {
  -            return _name.getPrefix().equals( "xmlns" ) ? _name.getLocalPart() : "";
  +            return Locale.xmlnsPrefix( _name );
           }
   
           String getXmlnsUri ( )
  @@ -1669,7 +1661,7 @@
           }
   
           public void dump ( PrintStream o, Object ref ) { Cur.dump( o, (Xobj) this, ref ); }
  -        public void dump ( PrintStream o ) { Cur.dump( o, (Xobj) this ); }
  +        public void dump ( PrintStream o ) { Cur.dump( o, this, this ); }
           public void dump ( ) { dump( System.out ); }
   
           //
  @@ -2406,7 +2398,7 @@
   
       void dump ( )
       {
  -        dump( System.out );
  +        dump( System.out, _xobj, this );
       }
   
       void dump ( PrintStream o )
  @@ -2417,23 +2409,41 @@
               return;
           }
   
  -        dump( o, _xobj );
  +        dump( o, _xobj, this );
       }
   
  -    private static void dumpCur ( PrintStream o, String prefix, Cur c )
  +    public static void dump ( PrintStream o, Xobj xo, Object ref )
  +    {
  +        if (ref == null)
  +            ref = xo;
  +        
  +        while ( xo._parent != null )
  +            xo = xo._parent;
  +
  +        dumpXobj( o, xo, 0, ref );
  +        
  +        o.println();
  +    }
  +    
  +    private static void dumpCur ( PrintStream o, String prefix, Cur c, Object ref )
       {
  -        o.print( " " + prefix + "cur[" + c._pos + "]" );
  +        o.print( " " );
  +        
  +        if (ref == c)
  +            o.print( "*:" );
  +        
  +        o.print( prefix + "cur[" + c._pos + "]" );
       }
       
  -    private static void dumpCurs ( PrintStream o, Xobj xo )
  +    private static void dumpCurs ( PrintStream o, Xobj xo, Object ref )
       {
           for ( Cur c = xo._embedded ; c != null ; c = c._next )
  -            dumpCur( o, "*", c );
  +            dumpCur( o, "E:", c, ref );
           
           for ( Cur c = xo._locale._unembedded ; c != null ; c = c._next )
           {
               if (c._xobj == xo)
  -                dumpCur( o, "", c );
  +                dumpCur( o, "U:", c, ref );
           }
       }
       
  @@ -2496,7 +2506,7 @@
               o.print( " )" );
           }
   
  -        dumpCurs( o, xo );
  +        dumpCurs( o, xo, ref );
   
           String className = xo.getClass().getName();
           
  @@ -2520,22 +2530,6 @@
   
           for ( xo = xo._firstChild ; xo != null ; xo = xo._nextSibling )
               dumpXobj( o, xo, level + 1, ref );
  -    }
  -    
  -    public static void dump ( PrintStream o, Xobj xo, Object ref )
  -    {
  -        dumpXobj( o, xo, 0, ref );
  -        o.println();
  -    }
  -    
  -    public static void dump ( PrintStream o, Xobj xo )
  -    {
  -        Xobj ref = xo;
  -        
  -        while ( xo._parent != null )
  -            xo = xo._parent;
  -
  -        dump( o, xo, (Object) ref );
       }
       
       //
  
  
  
  1.7       +43 -122   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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Cursor.java	5 Mar 2004 01:17:05 -0000	1.6
  +++ Cursor.java	11 Mar 2004 19:50:29 -0000	1.7
  @@ -152,11 +152,19 @@
           throw new IllegalArgumentException( msg );
       }
   
  -    private void insert ( Cur thisStuff )
  +    private void insertNode ( Cur thisStuff, String text )
       {
  +        assert thisStuff.kind() != TEXT && thisStuff.kind() > 0;
           assert isValid( thisStuff );
           assert isValid();
   
  +        if (text != null && text.length() > 0)
  +        {
  +            thisStuff.next();
  +            thisStuff.insertChars( text, 0, text.length() );
  +            thisStuff.toParent();
  +        }
  +
           int thisKind = thisStuff.kind();
   
           if (thisKind < 0)
  @@ -170,9 +178,6 @@
           if (k == ROOT)
               complain( "Can't insert before the start of the document." );
   
  -        if (k == ATTR && thisKind != TEXT)
  -            complain( "Can only insert attributes before other attributes." );
  -
           if (thisKind == ATTR)
           {
               _cur.push();
  @@ -187,22 +192,7 @@
               }
           }
   
  -        if (thisKind == TEXT)
  -            thisStuff.moveChars( _cur, -1 );
  -        else
  -            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 );
  +        thisStuff.moveNode( _cur );
       }
       
       //
  @@ -234,6 +224,19 @@
           }
       }
   
  +    public boolean _isStartdoc   ( ){ return _currentTokenType().isStartdoc();  }
  +    public boolean _isEnddoc     ( ){ return _currentTokenType().isEnddoc();    }
  +    public boolean _isStart      ( ){ return _currentTokenType().isStart();     }
  +    public boolean _isEnd        ( ){ return _currentTokenType().isEnd();       }
  +    public boolean _isText       ( ){ return _currentTokenType().isText();      }
  +    public boolean _isAttr       ( ){ return _currentTokenType().isAttr();      }
  +    public boolean _isNamespace  ( ){ return _currentTokenType().isNamespace(); }
  +    public boolean _isComment    ( ){ return _currentTokenType().isComment();   }
  +    public boolean _isProcinst   ( ){ return _currentTokenType().isProcinst();  }
  +    public boolean _isContainer  ( ){ return _currentTokenType().isContainer(); }
  +    public boolean _isFinish     ( ){ return _currentTokenType().isFinish();    }
  +    public boolean _isAnyAttr    ( ){ return _currentTokenType().isAnyAttr();   }
  +    
       public TokenType _toNextToken ( )
       {
           assert isValid();
  @@ -316,67 +319,6 @@
           return _locale;
       }
       
  -    public boolean _isStartdoc ( )
  -    {
  -        // TODO - can make these faster .... perhaps even inline?
  -        return _currentTokenType().isStartdoc();
  -    }
  -
  -    public boolean _isEnddoc ( )
  -    {
  -        return _currentTokenType().isEnddoc();
  -    }
  -
  -    public boolean _isStart ( )
  -    {
  -        return _currentTokenType().isStart();
  -    }
  -
  -    public boolean _isEnd ( )
  -    {
  -        return _currentTokenType().isEnd();
  -    }
  -
  -    public boolean _isText ( )
  -    {
  -        return _currentTokenType().isText();
  -    }
  -
  -    public boolean _isAttr ( )
  -    {
  -        return _currentTokenType().isAttr();
  -    }
  -
  -    public boolean _isNamespace ( )
  -    {
  -        return _currentTokenType().isNamespace();
  -    }
  -
  -    public boolean _isComment ( )
  -    {
  -        return _currentTokenType().isComment();
  -    }
  -
  -    public boolean _isProcinst ( )
  -    {
  -        return _currentTokenType().isProcinst();
  -    }
  -
  -    public boolean _isContainer ( )
  -    {
  -        return _currentTokenType().isContainer();
  -    }
  -
  -    public boolean _isFinish ( )
  -    {
  -        return _currentTokenType().isFinish();
  -    }
  -
  -    public boolean _isAnyAttr ( )
  -    {
  -        return _currentTokenType().isAnyAttr();
  -    }
  -
       public boolean _toFirstChild ( )
       {
           throw new RuntimeException( "Not implemented" );
  @@ -897,19 +839,25 @@
       
       public void _insertChars ( String text )
       {
  -        throw new RuntimeException( "Not implemented" );
  +        if (text != null && text.length() > 0)
  +        {
  +            if (_cur.isRoot() || _cur.isAttr())
  +                complain( "Can't insert before the document or an attribute." );
  +
  +            _cur.insertChars( text, 0, text.length() );
  +        }
       }
   
       //
       // Inserting elements
       //
       
  -    public void _insertElement         ( String localName                          ) { _insertElementWithText( localName, null, null ); }
  -    public void _insertElement         ( String localName, String uri              ) { _insertElementWithText( localName, uri, null ); }
  -    public void _insertElement         ( QName  name                               ) { _insertElementWithText( name, null ); }
       public void _beginElement          ( String localName                          ) { _insertElementWithText( localName, null, null ); _toPrevToken(); }
       public void _beginElement          ( String localName, String uri              ) { _insertElementWithText( localName, uri ); _toPrevToken(); }
       public void _beginElement          ( QName  name                               ) { _insertElementWithText( name, null ); _toPrevToken(); }
  +    public void _insertElement         ( String localName                          ) { _insertElementWithText( localName, null, null ); }
  +    public void _insertElement         ( String localName, String uri              ) { _insertElementWithText( localName, uri, null ); }
  +    public void _insertElement         ( QName  name                               ) { _insertElementWithText( name, null ); }
       public void _insertElementWithText ( String localName, String text             ) { _insertElementWithText( localName, null, text ); }
       public void _insertElementWithText ( String localName, String uri, String text ) { _insertElementWithText( _locale.makeQName( uri, localName ), text ); }
       
  @@ -921,7 +869,7 @@
   
           c.createElement( name );
   
  -        insertWithValue( c, text );
  +        insertNode( c, text );
   
           c.release();
       }
  @@ -930,30 +878,11 @@
       //
       //
       
  -    public void _insertAttribute ( String localName )
  -    {
  -        _insertAttributeWithValue( localName, null );
  -    }
  -    
  -    public void _insertAttribute ( String localName, String uri )
  -    {
  -        _insertAttributeWithValue( localName, uri, null );
  -    }
  -    
  -    public void _insertAttribute ( QName name )
  -    {
  -        _insertAttributeWithValue( name, null );
  -    }
  -    
  -    public void _insertAttributeWithValue ( String localName, String value )
  -    {
  -        _insertAttributeWithValue( localName, null, value );
  -    }
  -    
  -    public void _insertAttributeWithValue ( String localName, String uri, String value )
  -    {
  -        _insertAttributeWithValue( _locale.makeQName( uri, localName ), value );
  -    }
  +    public void _insertAttribute          ( String localName )                           { _insertAttributeWithValue( localName, null ); }
  +    public void _insertAttribute          ( String localName, String uri )               { _insertAttributeWithValue( localName, uri, null ); }
  +    public void _insertAttribute          ( QName name )                                 { _insertAttributeWithValue( name, null ); }
  +    public void _insertAttributeWithValue ( String localName, String value )             { _insertAttributeWithValue( localName, null, value ); }
  +    public void _insertAttributeWithValue ( String localName, String uri, String value ) { _insertAttributeWithValue( _locale.makeQName( uri, localName ), value ); }
       
       public void _insertAttributeWithValue ( QName name, String text )
       {
  @@ -961,7 +890,7 @@
   
           c.createAttr( name );
   
  -        insertWithValue( c, text );
  +        insertNode( c, text );
           
           c.release();
       }
  @@ -972,15 +901,7 @@
       
       public void _insertNamespace ( String prefix, String namespace )
       {
  -        if (prefix == null)
  -            prefix = "";
  -
  -        QName name =
  -            prefix.length() == 0
  -                ? _locale.makeQName( _locale._xmlnsUri, "xmlns", "" )
  -                : _locale.makeQName( _locale._xmlnsUri, "xmlns", prefix );
  -
  -        _insertAttributeWithValue( name, namespace );
  +        _insertAttributeWithValue( _locale.createXmlns( prefix ), namespace );
       }
       
       public void _insertComment ( String text )
  @@ -989,7 +910,7 @@
   
           c.createComment();
           
  -        insertWithValue( c, text );
  +        insertNode( c, text );
           
           c.release();
       }
  @@ -1000,7 +921,7 @@
   
           c.createProcinst( target );
   
  -        insertWithValue( c, text );
  +        insertNode( c, text );
           
           c.release();
       }
  
  
  
  1.5       +0 -4      xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Jsr173.java
  
  Index: Jsr173.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Jsr173.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Jsr173.java	3 Mar 2004 22:56:38 -0000	1.4
  +++ Jsr173.java	11 Mar 2004 19:50:29 -0000	1.5
  @@ -60,10 +60,6 @@
       //
       //
       //
  -
  -    //
  -    //
  -    //
       
       private static final class XMLStreamReaderForNode extends XMLStreamReaderBase
       {
  
  
  
  1.9       +58 -5     xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Locale.java
  
  Index: Locale.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Locale.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Locale.java	3 Mar 2004 22:56:38 -0000	1.8
  +++ Locale.java	11 Mar 2004 19:50:29 -0000	1.9
  @@ -65,11 +65,16 @@
   
   final class Locale implements DOMImplementation, SaajCallback
   {
  -    public static final String _xsi         = "http://www.w3.org/2001/XMLSchema-instance";
  -    public static final String _schema      = "http://www.w3.org/2001/XMLSchema";
  -    public static final String _openFragUri = "http://www.openuri.org/fragment";
  -    public static final String _xml1998Uri  = "http://www.w3.org/XML/1998/namespace";
  -    public static final String _xmlnsUri    = "http://www.w3.org/2000/xmlns/";
  +    static final String _xsi         = "http://www.w3.org/2001/XMLSchema-instance";
  +    static final String _schema      = "http://www.w3.org/2001/XMLSchema";
  +    static final String _openFragUri = "http://www.openuri.org/fragment";
  +    static final String _xml1998Uri  = "http://www.w3.org/XML/1998/namespace";
  +    static final String _xmlnsUri    = "http://www.w3.org/2000/xmlns/";
  +    
  +    static final QName _xsiNil          = new QName( _xsi, "nil" );
  +    static final QName _xsiType         = new QName( _xsi, "type" );
  +    static final QName _openuriFragment = new QName( _openFragUri, "fragment" );
  +    static final QName _xmlFragment     = new QName( "xml-fragment" );
       
       Locale ( )
       {
  @@ -308,6 +313,28 @@
           }
       }
   
  +    static final boolean isWhiteSpace ( String s )
  +    {
  +        int l = s.length();
  +
  +        while ( l-- > 0)
  +            if (!isWhiteSpace( s.charAt( l )))
  +                  return false;
  +
  +        return true;
  +    }
  +
  +    static final boolean isWhiteSpace ( StringBuffer sb )
  +    {
  +        int l = sb.length();
  +
  +        while ( l-- > 0)
  +            if (!isWhiteSpace( sb.charAt( l )))
  +                  return false;
  +
  +        return true;
  +    }
  +
       static boolean beginsWithXml ( String name )
       {
           if (name.length() < 3)
  @@ -323,6 +350,32 @@
           }
   
           return false;
  +    }
  +
  +    static boolean isXmlns ( QName name )
  +    {
  +        String prefix = name.getPrefix();
  +
  +        if (prefix.equals( "xmlns" ))
  +            return true;
  +
  +        return prefix.length() == 0 && name.getLocalPart().equals( "xmlns" );
  +    }
  +
  +    QName createXmlns ( String prefix )
  +    {
  +        if (prefix == null)
  +            prefix = "";
  +        
  +        return
  +            prefix.length() == 0
  +                ? makeQName( _xmlnsUri, "xmlns", "" )
  +                : makeQName( _xmlnsUri, prefix, "xmlns" );
  +    }
  +    
  +    static String xmlnsPrefix ( QName name )
  +    {
  +        return name.getPrefix().equals( "xmlns" ) ? name.getLocalPart() : "";
       }
   
       //
  
  
  
  1.12      +593 -326  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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Saver.java	5 Mar 2004 01:17:05 -0000	1.11
  +++ Saver.java	11 Mar 2004 19:50:29 -0000	1.12
  @@ -43,7 +43,9 @@
       static final int PROCINST = Cur.PROCINST;
       static final int TEXT     = Cur.TEXT;
   
  -    protected abstract void emitContainer ( SaveCur c, QName name );
  +    protected abstract boolean emitContainer (
  +        SaveCur c, QName name, ArrayList attrNames, ArrayList attrValues );
  +    
       protected abstract void emitFinish    ( SaveCur c, QName name );
       protected abstract void emitText      ( SaveCur c );
       protected abstract void emitComment   ( SaveCur c );
  @@ -51,26 +53,21 @@
   
       protected void syntheticNamespace ( String prefix, String uri, boolean considerDefault ) { }
   
  -    Saver ( Cur c, boolean wantFragTest, XmlOptions options )
  +    Saver ( Cur c, XmlOptions options )
       {
           options = XmlOptions.maskNull( options );
   
           _locale = c._locale;
           _version = _locale.version();
   
  -        _wantFragTest = wantFragTest;
  -
  -        _cur = new NormalSaveCur( c.weakCur( this ) );
  -        
  -        if (options.hasOption( XmlOptions.SAVE_PRETTY_PRINT ))
  -            _cur = new PrettySaveCur( _cur, options );
  -        
  -        _preProcess = true;
  +        _cur = createSaveCur( c, options  );
   
           _namespaceStack = new ArrayList();
           _uriMap = new HashMap();
           _prefixMap = new HashMap();
  -        _firstPush = true;
  +
  +        _attrNames = new ArrayList();
  +        _attrValues = new ArrayList ();
   
           _newLine = System.getProperty( "line.separator" );
   
  @@ -125,27 +122,180 @@
               _filterProcinst =
                   (String) options.get( XmlOptions.SAVE_FILTER_PROCINST );
           }
  +    }
  +
  +    private SaveCur createSaveCur ( Cur c, XmlOptions options )
  +    {
  +        QName synthName = (QName) options.get( XmlOptions.SAVE_SYNTHETIC_DOCUMENT_ELEMENT );
  +
  +        QName fragName = synthName;
  +
  +        if (fragName == null)
  +        {
  +            fragName = 
  +                options.hasOption( XmlOptions.SAVE_USE_OPEN_FRAGMENT )
  +                    ? Locale._openuriFragment
  +                    : Locale._xmlFragment;
  +        }
  +
  +        boolean saveInner = 
  +            options.hasOption( XmlOptions.SAVE_INNER ) &&
  +                !options.hasOption( XmlOptions.SAVE_OUTER );
  +
  +        Cur start = c.tempCur();
  +        Cur end   = c.tempCur();
  +
  +        SaveCur cur = null;
  +
  +        int k = c.kind();
  +
  +        switch ( k )
  +        {
  +        case ROOT :
  +        {
  +            positionToInner( c, start, end );
  +
  +            if (isFragment( start, end ))
  +            {
  +                positionToInner( c, start, end );
  +                cur = new FragSaveCur( start, end, fragName );
  +            }
  +            else if (synthName != null)
  +            {
  +                positionToInner( c, start, end );
  +                cur = new FragSaveCur( start, end, synthName );
  +            }
  +            else
  +                cur = new DocSaveCur( c );
  +
  +            break;
  +        }
           
  -        // TODO - _synthElem
  -        // TODO - _fragment
  -        // TODO - _inner
  +        case ELEM :
  +        {
  +            if (saveInner)
  +            {
  +                positionToInner( c, start, end );
  +                boolean isFrag = isFragment( start, end );
  +                cur = new FragSaveCur( start, end, isFragment( start, end ) ? fragName : synthName);
  +            }
  +            else if (synthName != null)
  +            {
  +                positionToInner( c, start, end );
  +                cur = new FragSaveCur( start, end, synthName );
  +            }
  +            else
  +            {
  +                start.moveToCur( c );
  +                end.moveToCur( c );
  +                end.toEnd();
  +                end.next();
  +
  +                cur = new FragSaveCur( start, end, null );
  +            }
  +
  +            break;
  +        }
  +        }
  +
  +        if (cur == null)
  +        {
  +            assert k < 0 || k == ATTR || k == COMMENT || k == PROCINST || k == TEXT;
  +
  +            if (k < 0)
  +            {
  +                start.moveToCur( c );
  +                end.moveToCur( c );
  +            }
  +            else if (k == TEXT)
  +            {
  +                start.moveToCur( c );
  +                end.moveToCur( c );
  +                end.next();
  +            }
  +            else if (saveInner)
  +            {
  +                start.moveToCur( c );
  +                start.next();
  +                
  +                end.moveToCur( c );
  +                end.toEnd();
  +            }
  +            else if (k == ATTR)
  +            {
  +                start.moveToCur( c );
  +                end.moveToCur( c );
  +            }
  +            else
  +            {
  +                start.moveToCur( c );
  +                end.moveToCur( c );
  +                end.toEnd();
  +                end.next();
  +            }
  +
  +            cur = new FragSaveCur( start, end, fragName );
  +        }
  +
  +        if (options.hasOption( XmlOptions.SAVE_PRETTY_PRINT ))
  +            cur = new PrettySaveCur( cur, options );
  +
  +        start.release();
  +        end.release();
  +
  +        return cur;
       }
   
  -    protected boolean needsFrag ( )
  +    private void positionToInner ( Cur c, Cur start, Cur end )
       {
  -        return _needsFrag;
  +        assert c.isContainer();
  +
  +        start.moveToCur( c );
  +
  +        if (!start.toFirstAttr())
  +            start.next();
  +
  +        end.moveToCur( c );
  +        end.toEnd();
       }
   
  -    protected boolean saveNamespacesFirst ( )
  +    private static boolean isFragment ( Cur start, Cur end )
       {
  -        return _saveNamespacesFirst;
  +        assert !end.isAttr();
  +
  +        int numDocElems = 0;
  +        
  +        while ( ! start.isSamePos( end ) )
  +        {
  +            int k = start.kind();
  +
  +            if (k == ATTR)
  +                break;
  +            
  +            if (k == TEXT && !Locale.isWhiteSpace( start.getString( -1 )))
  +                break;
  +
  +            if (k == ELEM && ++numDocElems > 1)
  +                break;
  +
  +            // Move to next token
  +
  +            assert k != ATTR;
  +            
  +            if (k == ELEM)
  +                start.toEnd();
  +            
  +            start.next();
  +        }
  +        
  +        return !start.isSamePos( end );
       }
   
  -    protected void skipContainer ( )
  +    protected boolean saveNamespacesFirst ( )
       {
  -        _skipContainer = true;
  +        return _saveNamespacesFirst;
       }
  -    
  +
       private final void checkVersion ( )
       {
           if (_version != _locale.version())
  @@ -158,27 +308,6 @@
           
           checkVersion();
   
  -        if (_preProcess)
  -        {
  -            assert _cur != null;
  -
  -            _preProcess = false;
  -
  -            //
  -            // 
  -            //
  -
  -            if (_cur.isFinish())
  -            {
  -                _done = true;
  -                processTextFragment( _cur );
  -            }
  -            else
  -            {
  -                assert _cur.isContainer();
  -            }
  -        }
  -
           if (_postPop)
           {
               popMappings();
  @@ -187,31 +316,24 @@
   
           if (_postProcess)
           {
  -            if (_cur.atEndOfTop())
  +            int k = _cur.kind();
  +            
  +            if (k == -ROOT)
                   _done = true;
               else
               {
  -                switch ( _cur.kind() )
  +                switch ( k )
                   {
                   case ROOT :
                   case ELEM :
                   {
                       if (_skipContainer)
                       {
  +                        assert _cur.isElem();
                           _cur.toEnd();
  -                        
  -                        if (_cur.atEndOfTop())
  -                            _done = true;
  -                        else
  -                            _cur.next();
                       }
  -                    else
  -                    {
  -                        _cur.next();
   
  -                        while ( _cur.isAttr() )
  -                            _cur.next();
  -                    }
  +                    _cur.next();
                       
                       break;
                   }
  @@ -249,15 +371,13 @@
   
           checkVersion();
   
  -        _skipContainer = false;
  -
           switch ( _cur.kind() )
           {
  -            case   ROOT : case   ELEM : { processContainer();               break; }
  -            case - ROOT : case - ELEM : { processFinish(); _postPop = true; break; }
  -            case TEXT                 : { emitText( _cur );                 break; }
  -            case COMMENT              : { emitComment( _cur );              break; }
  -            case PROCINST             : { processProcinst();                break; }
  +            case   ROOT : case   ELEM : { _skipContainer = processContainer(); break; }
  +            case - ROOT : case - ELEM : { processFinish(); _postPop = true;    break; }
  +            case TEXT                 : { emitText( _cur );                    break; }
  +            case COMMENT              : { emitComment( _cur );                 break; }
  +            case PROCINST             : { processProcinst();                   break; }
   
               default : throw new RuntimeException( "Unexpected kind" );
           }
  @@ -267,12 +387,12 @@
           return true;
       }
   
  -    private final void processContainer ( )
  +    private final boolean processContainer ( )
       {
           assert _cur.isContainer();
           assert !_cur.isRoot() || _cur.getName() == null;
  -        
  -        QName name = _synthElem != null && _cur.atTop() ? _synthElem : _cur.getName();
  +
  +        QName name = _cur.getName();
   
           String nameUri = name == null ? null : name.getNamespaceURI();
           
  @@ -302,43 +422,47 @@
           if (name != null)
               ensureMapping( nameUri, null, !ensureDefaultEmpty, false );
   
  -        _cur.clearSelection();
  +        //
  +        //
  +        //
  +
  +        _attrNames.clear();
  +        _attrValues.clear();
  +
           _cur.push();
   
  +        attrs:
           for ( boolean A = _cur.toFirstAttr() ; A ; A = _cur.toNextAttr() )
           {
               if (_cur.isNormalAttr())
               {
                   QName attrName = _cur.getName();
  -                
  -                _cur.addAttrToSelection();
  -                _cur.push();
   
  -                ensureMapping( attrName.getNamespaceURI(), null, false, true );
  -
  -                for ( boolean P = _cur.toPrevAttr() ; P ; P = _cur.toPrevAttr() )
  +                _attrNames.add( attrName );
  +                               
  +                for ( int i = _attrNames.size() - 2 ; i >= 0 ; i-- )
                   {
  -                    if (_cur.getName().equals( attrName ))
  +                    if (_attrNames.get( i ).equals( attrName ))
                       {
  -                        _cur.removeSelection( _cur.selectionCount() - 1 );
  -                        break;
  +                        _attrNames.remove( _attrNames.size() - 1 );
  +                        continue attrs;
                       }
                   }
  +
  +                _attrValues.add( _cur.getAttrValue() );
                   
  -                _cur.pop();
  +                ensureMapping( attrName.getNamespaceURI(), null, false, true );
               }
           }
           
           _cur.pop();
   
  -        // todo - do _wantFragTest thingy here ...
  -        
           // If I am doing aggressive namespaces and we're emitting a
           // container which can contain content, add the namespaces
           // we've computed.  Basically, I'm making sure the pre-computed
           // namespaces are mapped on the first container which has a name.
   
  -        if (_preComputedNamespaces != null && (name != null || _needsFrag))
  +        if (_preComputedNamespaces != null && name != null)
           {
               for ( Iterator i = _preComputedNamespaces.keySet().iterator() ; i.hasNext() ; )
               {
  @@ -353,14 +477,12 @@
               _preComputedNamespaces = null;
           }
   
  -        emitContainer( _cur, name );
  +        return emitContainer( _cur, name, _attrNames, _attrValues );
       }
   
       private final void processFinish ( )
       {
  -        QName name = _synthElem != null && _cur.atEndOfTop() ? _synthElem : _cur.getName();
  -        
  -        // todo - do _wantFragTest thingy here ...
  +        QName name = _cur.getName();
           
           emitFinish( _cur, name );
           
  @@ -369,15 +491,10 @@
       
       private final void processProcinst ( )
       {
  -        if (_filterProcinst == null || !_cur.getLocal().equals( _filterProcinst ))
  +        if (_filterProcinst == null || !_cur.getName().getLocalPart().equals( _filterProcinst ))
               emitProcinst( _cur );
       }
   
  -    private void processTextFragment( SaveCur c )
  -    {
  -        throw new RuntimeException( "Not impl" );
  -    }
  -    
       //
       // Layout of namespace stack:
       //
  @@ -441,40 +558,32 @@
   
           c.push();
   
  -        for ( boolean C = true ; C ; C = c.toParentRaw() )
  +        namespaces:
  +        for ( boolean A = c.toFirstAttr() ; A ; A = c.toNextAttr() )
           {
  -            c.push();
  -            
  -            namespaces:
  -            for ( boolean A = c.toFirstAttr() ; A ; A = c.toNextAttr() )
  +            if (c.isXmlns())
               {
  -                if (c.isXmlns())
  -                {
  -                    String prefix = c.getXmlnsPrefix();
  -                    String uri = c.getXmlnsUri();
  -                    
  -                    if (ensureDefaultEmpty && prefix.length() == 0 && uri.length() > 0)
  -                        continue;
  -                    
  -                    // Make sure the prefix is not already mapped in this frame
  -
  -                    for ( iterateMappings() ; hasMapping() ; nextMapping() )
  -                        if (mappingPrefix().equals( prefix ))
  -                            continue namespaces;
  +                String prefix = c.getXmlnsPrefix();
  +                String uri = c.getXmlnsUri();
   
  -                    addMapping( prefix, uri );
  -                }
  +                if (!ensureDefaultEmpty || prefix.length() > 0 || uri.length() == 0)
  +                    addNewFrameMapping( prefix, uri );
               }
  -            
  -            c.pop();
  -
  -            // Push all ancestors the first time
  -            
  -            if (!_firstPush)
  -                break;
           }
   
           c.pop();
  +
  +        if (c.isRoot() && _cur._ancestorNamespaces != null)
  +        {
  +            for ( int i = 0 ; i < _cur._ancestorNamespaces.size() ; i += 2 )
  +            {
  +                String prefix = (String) _cur._ancestorNamespaces.get( i );
  +                String uri    = (String) _cur._ancestorNamespaces.get( i + 1 );
  +                
  +                if (!ensureDefaultEmpty || prefix.length() > 0 || uri.length() == 0)
  +                    addNewFrameMapping( prefix, uri );
  +            }
  +        }
           
           if (ensureDefaultEmpty)
           {
  @@ -486,10 +595,19 @@
               if (defaultUri.length() > 0)
                   addMapping( "", "" );
           }
  +    }
   
  -        _firstPush = false;
  +    private final void addNewFrameMapping ( String prefix, String uri )
  +    {
  +        // Make sure the prefix is not already mapped in this frame
  +
  +        for ( iterateMappings() ; hasMapping() ; nextMapping() )
  +            if (mappingPrefix().equals( prefix ))
  +                return;;
  +
  +        addMapping( prefix, uri );
       }
  -    
  +
       private final void addMapping ( String prefix, String uri )
       {
           assert uri != null;
  @@ -714,7 +832,7 @@
           
           SynthNamespaceSaver ( Cur c, XmlOptions options )
           {
  -            super( c, false, options );
  +            super( c, options );
           }
           
           protected void syntheticNamespace (
  @@ -723,7 +841,9 @@
               _synthNamespaces.put( uri, considerCreatingDefault ? "useDefault" : null );
           }
           
  -        protected void emitContainer ( SaveCur c, QName name ) { }
  +        protected boolean emitContainer (
  +            SaveCur c, QName name, ArrayList attrNames, ArrayList attrValues ) { return false; }
  +        
           protected void emitFinish    ( SaveCur c, QName name ) { }
           protected void emitText      ( SaveCur c ) { }
           protected void emitComment   ( SaveCur c ) { }
  @@ -738,7 +858,7 @@
       {
           TextSaver ( Cur c, XmlOptions options, String encoding )
           {
  -            super( c, true, options );
  +            super( c, options );
   
               if (encoding != null)
               {
  @@ -755,28 +875,21 @@
               }
           }
           
  -        protected void emitContainer ( SaveCur c, QName name )
  +        protected boolean emitContainer (
  +            SaveCur c, QName name, ArrayList attrNames, ArrayList attrValues )
           {
  +            boolean skipElem = false;
  +            
               if (c.isElem())
               {
  -                emitContainerHelper( c, name, null, false );
  +                emitContainerHelper( name, false, attrNames, attrValues );
   
                   assert c.isContainer();
   
  -                if (!c.hasChildren())
  +                if (!c.hasChildren() && !c.hasText())
                   {
  -                    if (c.hasText())
  -                    {
  -                        emit( '>' );
  -                        emitValue( c );
  -                        entitizeContent();
  -                        emit( "</" );
  -                        emitName( name );
  -                    }
  -                    else
  -                        emit( '/' );
  -                    
  -                    skipContainer();
  +                    emit( '/' );
  +                    skipElem = true;
                   }
                   
                   emit( '>' );
  @@ -786,8 +899,10 @@
                   assert c.isRoot();
   
                   if (name != null)
  -                    emitContainerHelper( c, name, null, true );
  +                    emitContainerHelper( name, true, attrNames, attrValues );
               }
  +
  +            return skipElem;
           }
           
           protected void emitFinish ( SaveCur c, QName name )
  @@ -837,27 +952,18 @@
               }
           }
                                        
  -        private void emitAttrHelper ( SaveCur a )
  +        private void emitAttrHelper ( QName attrName, String attrValue )
           {
  -            assert a.isNormalAttr();
  -            
               emit( ' ' );
  -            emitName( a.getName() );
  +            emitName( attrName );
               emit( "=\"" );
  -
  -            a.push();
  -            a.next();
  -            
  -            emit( a );
  -
  -            a.pop();
  -
  +            emit( attrValue );
               entitizeAttrValue();
  -
               emit( '"' );
           }
   
  -        private void emitContainerHelper ( SaveCur saveAttrs, QName name, SaveCur extraAttr, boolean close )
  +        private void emitContainerHelper (
  +            QName name, boolean close, ArrayList attrNames, ArrayList attrValues )
           {
               assert name != null;
   
  @@ -867,21 +973,8 @@
               if (saveNamespacesFirst())
                   emitNamespacesHelper();
   
  -            if (saveAttrs != null)
  -            {
  -                saveAttrs.push();
  -                
  -                for ( int i = 0 ; i < saveAttrs.selectionCount() ; i++ )
  -                {
  -                    saveAttrs.moveToSelection( i );
  -                    emitAttrHelper( saveAttrs );
  -                }
  -                
  -                saveAttrs.pop();
  -            }
  -
  -            if (extraAttr != null)
  -                emitAttrHelper( extraAttr);
  +            for ( int i = 0 ; i < attrNames.size() ; i++ )
  +                emitAttrHelper( (QName) attrNames.get( i ), (String) attrValues.get( i ) );
   
               if (!saveNamespacesFirst())
                   emitNamespacesHelper();
  @@ -916,7 +1009,7 @@
               emit( "<?" );
               
               // TODO - encoding issues here?
  -            emit( c.getLocal() );
  +            emit( c.getName().getLocalPart() );
   
               if (c.hasText())
               {
  @@ -1017,7 +1110,7 @@
           
           private void emitValue ( SaveCur c )
           {
  -            assert !c.isText() && c.kind() > 0 && !c.hasChildren();
  +            assert !c.isText() && !c.isAttr() && c.kind() > 0 && !c.hasChildren();
   
               c.push();
               c.next();
  @@ -1565,16 +1658,12 @@
           boolean isFinish     ( ) { return Cur.kindIsFinish( kind() ); }
           boolean isContainer  ( ) { return Cur.kindIsContainer( kind() ); }
           boolean isNormalAttr ( ) { return kind() == ATTR && !isXmlns(); }
  -        
  -        abstract boolean atTop ( );
  -        abstract boolean atEndOfTop ( );
  -        
  +
           abstract void release ( );
           
           abstract int kind ( );
           
           abstract QName  getName ( );
  -        abstract String getLocal ( );
           abstract String getXmlnsPrefix ( );
           abstract String getXmlnsUri ( );
           
  @@ -1585,162 +1674,370 @@
           
           abstract boolean toFirstAttr ( );
           abstract boolean toNextAttr ( );
  -        abstract boolean toPrevAttr ( );
  -        abstract boolean toParentRaw ( );
  -        abstract void    toEnd ( );
  +        abstract String  getAttrValue ( );
           
  -        abstract boolean next ( );
  +        abstract boolean next  ( );
  +        abstract void    toEnd ( );
   
           abstract void push ( );
           abstract void pop ( );
  -        abstract void clearSelection ( );
  -        abstract void addAttrToSelection ( );
  -        abstract void removeSelection ( int i );
  -        abstract int  selectionCount ( );
  -        abstract void moveToSelection ( int i );
   
           abstract Object getChars ( );
   
  +        ArrayList _ancestorNamespaces;
  +
           int _offSrc;
           int _cchSrc;
       }
       
  -    private static final class NormalSaveCur extends SaveCur
  +    // TODO - saving a fragment need to take namesapces from root and
  +    // reflect them on the document element
  +    
  +    private static final class DocSaveCur extends SaveCur
       {
  -        NormalSaveCur ( Cur c )
  +        DocSaveCur ( Cur c )
           {
  -            _cur = c;
  -
  -            if (c.isContainer())
  -                _top = c.weakCur( c );
  +            assert c.isRoot();
  +            _cur = c.weakCur( this );
           }
   
           void release ( )
           {
               _cur.release();
               _cur = null;
  -
  -            if (_top != null)
  -            {
  -                _top.release();
  -                _top = null;
  -            }
           }
           
           int kind ( ) { return _cur.kind(); }
           
  -        QName getName ( ) { return _cur.getName(); }
  -        String getLocal ( ) { return _cur.getLocal(); }
  +        QName  getName        ( ) { return _cur.getName(); }
           String getXmlnsPrefix ( ) { return _cur.getXmlnsPrefix(); }
           String getXmlnsUri    ( ) { return _cur.getXmlnsUri(); }
           
  -        boolean isXmlns      ( ) { return _cur.isXmlns();     }
  +        boolean isXmlns       ( ) { return _cur.isXmlns();     }
           
  -        boolean hasChildren  ( ) { return _cur.hasChildren(); }
  -        boolean hasText      ( ) { return _cur.hasText();     }
  +        boolean hasChildren   ( ) { return _cur.hasChildren(); }
  +        boolean hasText       ( ) { return _cur.hasText();     }
           
  -        boolean atTop      ( ) { assert _top != null; return _cur.isSamePos( _top ); }
  -        boolean atEndOfTop ( ) { assert _top != null; return _cur.isAtEndOf( _top ); }
  +        boolean toFirstAttr   ( ) { return _cur.toFirstAttr(); }
  +        boolean toNextAttr    ( ) { return _cur.toNextAttr();  }
  +        String  getAttrValue  ( ) { assert _cur.isAttr(); return _cur.getValueString(); }
           
  -        boolean toFirstAttr ( ) { return _cur.toFirstAttr(); }
  -        boolean toNextAttr  ( ) { return _cur.toNextAttr();  }
  -        boolean toPrevAttr  ( ) { return _cur.toPrevAttr();  }
  -        boolean toParentRaw ( ) { return _cur.toParentRaw(); }
  +        void    toEnd         ( ) { _cur.toEnd();              }
  +        boolean next          ( ) { return _cur.next();        }
           
  -        void toEnd ( ) { _cur.toEnd(); }
  +        void push ( )         { _cur.push(); }
  +        void pop  ( )         { _cur.pop(); }
  +
           
  -        boolean next ( ) { return _cur.next(); }
  +        Object getChars ( )
  +        {
  +            Object o = _cur.getChars( -1 );
  +            
  +            _offSrc = _cur._offSrc;
  +            _cchSrc = _cur._cchSrc;
  +
  +            return o;
  +        }
           
  -        void push ( )            { _cur.push(); }
  -        void pop ( )             { _cur.pop(); }
  -        void clearSelection ( )  { _cur.clearSelection(); }
  -        void addAttrToSelection ( )  { assert _cur.isAttr(); _cur.addToSelection(); }
  -        int  selectionCount ( )  { return _cur.selectionCount(); }
  +        private Cur _cur;
  +    }
  +
  +    private static final class FragSaveCur extends SaveCur
  +    {
  +        FragSaveCur ( Cur start, Cur end, QName synthElem )
  +        {
  +            _saveAttr = start.isAttr() && start.isSamePos( end );
  +
  +            _cur = start.weakCur( this );
  +            _end = end.weakCur( this );
  +
  +            _elem = synthElem;
  +            
  +            _state = ROOT_START;
  +            
  +            _stateStack = new int [ 8 ];
  +
  +            start.push();
  +            computeAncestorNamespaces( start );
  +            start.pop();
  +        }
  +
  +        private void computeAncestorNamespaces ( Cur c )
  +        {
  +            _ancestorNamespaces = new ArrayList();
  +            
  +            while ( c.toParentRaw() )
  +            {
  +                if (c.toFirstAttr())
  +                {
  +                    do
  +                    {
  +                        if (c.isXmlns())
  +                        {
  +                            _ancestorNamespaces.add( c.getXmlnsPrefix() );
  +                            _ancestorNamespaces.add( c.getXmlnsUri() );
  +                        }
  +                    }
  +                    while ( c.toNextAttr() );
  +                    
  +                    c.toParent();
  +                }
  +            }
  +        }
  +        
  +        //
  +        //
  +        //
           
  -        void moveToSelection ( int i ) { _cur.moveToSelection( i ); }
  -        void removeSelection ( int i ) { _cur.removeSelection( i ); }
  +        void release ( )
  +        {
  +            _cur.release();
  +            _cur = null;
   
  +            _end.release();
  +            _end = null;
  +        }
  +
  +        int kind ( )
  +        {
  +            switch ( _state )
  +            {
  +            case ROOT_START : return  ROOT;
  +            case ELEM_START : return  ELEM;
  +            case ELEM_END   : return -ELEM;
  +            case ROOT_END   : return -ROOT;
  +            }
  +            
  +            assert _state == CUR;
  +            
  +            return _cur.kind();
  +        }
  +        
  +        QName getName ( )
  +        {
  +            switch ( _state )
  +            {
  +            case ROOT_START :
  +            case ROOT_END   : return null;
  +            case ELEM_START : 
  +            case ELEM_END   : return _elem;
  +            }
  +            
  +            assert _state == CUR;
  +
  +            return _cur.getName();
  +        }
  +        
  +        String getXmlnsPrefix ( )
  +        {
  +            assert _state == CUR && _cur.isAttr();
  +            return _cur.getXmlnsPrefix();
  +        }
  +        
  +        String getXmlnsUri ( )
  +        {
  +            assert _state == CUR && _cur.isAttr();
  +            return _cur.getXmlnsUri();
  +        }
  +        
  +        boolean isXmlns ( )
  +        {
  +            assert _state == CUR && _cur.isAttr();
  +            return _cur.isXmlns();
  +        }
  +        
  +        boolean hasChildren ( )
  +        {
  +            boolean hasChildren = false;
  +            
  +            if (isContainer())
  +            {
  +                push();
  +                next();
  +
  +                if (!isText() && !isFinish())
  +                    hasChildren = true;
  +                
  +                pop();
  +            }
  +
  +            return hasChildren;
  +        }
  +        
  +        boolean hasText ( )
  +        {
  +            boolean hasText = false;
  +            
  +            if (isContainer())
  +            {
  +                push();
  +                next();
  +
  +                if (isText())
  +                    hasText = true;
  +                
  +                pop();
  +            }
  +
  +            return hasText;
  +        }
  +        
           Object getChars ( )
           {
  -            Object o = _cur.getChars( -1 );
  +            assert _state == CUR && _cur.isText();
  +
  +            Object src = _cur.getChars( -1 );
               
               _offSrc = _cur._offSrc;
               _cchSrc = _cur._cchSrc;
   
  -            return o;
  +            return src;
           }
           
  +        boolean next ( )
  +        {
  +            switch ( _state )
  +            {
  +            case ROOT_START :
  +            {
  +                _state = _elem == null ? CUR : ELEM_START;
  +                return true;
  +            }
  +
  +            case ELEM_START :
  +            {
  +                if (_saveAttr)
  +                    _state = ELEM_END;
  +                else
  +                {
  +                    if (_cur.isAttr())
  +                    {
  +                        _cur.toParent();
  +                        _cur.next();
  +                    }
  +
  +                    if (_cur.isSamePos( _end ))
  +                        _state = ELEM_END;
  +                    else
  +                        _state = CUR;
  +                }
  +
  +                return true;
  +            }
  +
  +            case CUR :
  +            {
  +                assert !_cur.isAttr();
  +
  +                _cur.next();
  +
  +                if (_cur.isSamePos( _end ))
  +                    _state = _elem == null ? ROOT_END : ELEM_END;
  +
  +                return true;
  +            }
  +            
  +            case ELEM_END :
  +            {
  +                _state = ROOT_END;
  +                return true;
  +            }
  +            }
  +
  +            assert _state == ROOT_END;
  +            
  +            return false;
  +        }
  +        
  +        void toEnd ( )
  +        {
  +            switch ( _state )
  +            {
  +            case ROOT_START : _state = ROOT_END; return;
  +            case ELEM_START : _state = ELEM_END; return;
  +            case ROOT_END   :
  +            case ELEM_END   : return;
  +            }
  +
  +            assert _state == CUR && !_cur.isAttr() && !_cur.isText();
  +
  +            _cur.toEnd();
  +        }
  +        
  +        boolean toFirstAttr ( )
  +        {
  +            switch ( _state )
  +            {
  +            case ROOT_END   :
  +            case ELEM_END   : 
  +            case ROOT_START : return false;
  +            case CUR        : return _cur.toFirstAttr();
  +            }
  +            
  +            assert _state == ELEM_START;
  +
  +            if (!_cur.isAttr())
  +                return false;
  +            
  +            _state = CUR;
  +                
  +            return true;
  +        }
  +        
  +        boolean toNextAttr ( )
  +        {
  +            assert _state == CUR;
  +            return !_saveAttr && _cur.toNextAttr();
  +        }
  +        
  +        String getAttrValue ( )
  +        {
  +            assert _state == CUR && _cur.isAttr();
  +            return _cur.getValueString();
  +        }
  +
  +        void push ( )
  +        {
  +            if (_stateStackSize == _stateStack.length)
  +            {
  +                int[] newStateStack = new int [ _stateStackSize * 2 ];
  +                System.arraycopy( _stateStack, 0, newStateStack, 0, _stateStackSize );
  +                _stateStack = newStateStack;
  +            }
  +
  +            _stateStack [ _stateStackSize++ ] = _state;
  +            _cur.push();
  +        }
  +
  +        void pop ()
  +        {
  +            _cur.pop();
  +            _state = _stateStack [ --_stateStackSize ];
  +        }
  +        
  +        //
  +        //
  +        //
  +
           private Cur _cur;
  -        private Cur _top;
  +        private Cur _end;
  +
  +        private QName _elem;
  +
  +        private boolean _saveAttr;
  +        
  +        private static final int ROOT_START = 1;
  +        private static final int ELEM_START = 2;
  +        private static final int ROOT_END   = 3;
  +        private static final int ELEM_END   = 4;
  +        private static final int CUR        = 5;
  +        
  +        private int _state;
  +
  +        private int[] _stateStack;
  +        private int   _stateStackSize;
       }
       
  -//    private static final class FragmentSaveCur extends SaveCur
  -//    {
  -//        NormalSaveCur ( SaveCur c )
  -//        {
  -//            assert !c.isRoot();
  -//            
  -//            _cur = c;
  -//        }
  -//
  -//        void release ( )
  -//        {
  -//            _cur.release();
  -//            _cur = null;
  -//
  -//            if (_top != null)
  -//            {
  -//                _top.release();
  -//                _top = null;
  -//            }
  -//        }
  -//        
  -//        int kind ( ) { return _cur.kind(); }
  -//        
  -//        QName getName ( ) { return _cur.getName(); }
  -//        String getLocal ( ) { return _cur.getLocal(); }
  -//        String getXmlnsPrefix ( ) { return _cur.getXmlnsPrefix(); }
  -//        String getXmlnsUri    ( ) { return _cur.getXmlnsUri(); }
  -//        
  -//        boolean isXmlns      ( ) { return _cur.isXmlns();     }
  -//        
  -//        boolean hasChildren  ( ) { return _cur.hasChildren(); }
  -//        boolean hasText      ( ) { return _cur.hasText();     }
  -//        
  -//        boolean atTop      ( ) { assert _top != null; return _cur.isSamePos( _top ); }
  -//        boolean atEndOfTop ( ) { assert _top != null; return _cur.isAtEndOf( _top ); }
  -//        
  -//        boolean toFirstAttr ( ) { return _cur.toFirstAttr(); }
  -//        boolean toNextAttr  ( ) { return _cur.toNextAttr();  }
  -//        boolean toPrevAttr  ( ) { return _cur.toPrevAttr();  }
  -//        boolean toParentRaw ( ) { return _cur.toParentRaw(); }
  -//        
  -//        void toEnd ( ) { _cur.toEnd(); }
  -//        
  -//        boolean next ( ) { return _cur.next(); }
  -//        
  -//        void push ( )            { _cur.push(); }
  -//        void pop ( )             { _cur.pop(); }
  -//        void clearSelection ( )  { _cur.clearSelection(); }
  -//        void addAttrToSelection ( )  { assert _cur.isAttr(); _cur.addToSelection(); }
  -//        int  selectionCount ( )  { return _cur.selectionCount(); }
  -//        
  -//        void moveToSelection ( int i ) { _cur.moveToSelection( i ); }
  -//        void removeSelection ( int i ) { _cur.removeSelection( i ); }
  -//
  -//        Object getChars ( )
  -//        {
  -//            Object o = _cur.getChars( -1 );
  -//            
  -//            _offSrc = _cur._offSrc;
  -//            _cchSrc = _cur._cchSrc;
  -//
  -//            return o;
  -//        }
  -//        
  -//        private SaveCur _cur;
  -//    }
  -
       private static final class PrettySaveCur extends SaveCur
       {
           PrettySaveCur ( SaveCur c, XmlOptions options )
  @@ -1771,32 +2068,18 @@
           
           int kind ( ) { return _txt == null ? _cur.kind() : TEXT; }
           
  -        QName  getName ( )        { assert _txt == null; return _cur.getName(); }
  -        String getLocal ( )       { assert _txt == null; return _cur.getLocal(); }
  +        QName  getName        ( ) { assert _txt == null; return _cur.getName(); }
           String getXmlnsPrefix ( ) { assert _txt == null; return _cur.getXmlnsPrefix(); }
           String getXmlnsUri    ( ) { assert _txt == null; return _cur.getXmlnsUri(); }
           
  -        boolean isRoot       ( ) { return _txt == null ? _cur.isRoot()       : false; }
  -        boolean isElem       ( ) { return _txt == null ? _cur.isElem()       : false; }
  -        boolean isAttr       ( ) { return _txt == null ? _cur.isAttr()       : false; }
  -        boolean isText       ( ) { return _txt == null ? _cur.isText()       : true;  }
  -        boolean isComment    ( ) { return _txt == null ? _cur.isComment()    : false; }
  -        boolean isProcinst   ( ) { return _txt == null ? _cur.isProcinst()   : false; }
  -        boolean isFinish     ( ) { return _txt == null ? _cur.isFinish()     : false; }
  -        boolean isContainer  ( ) { return _txt == null ? _cur.isContainer()  : false; }
  -        boolean isNormalAttr ( ) { return _txt == null ? _cur.isNormalAttr() : false; }
  -        boolean isXmlns      ( ) { return _txt == null ? _cur.isXmlns()      : false; }
  -        
  -        boolean hasChildren  ( ) { return _txt == null ? _cur.hasChildren() : false; }
  -        boolean hasText      ( ) { return _txt == null ? _cur.hasText()     : false; }
  -        
  -        boolean atTop      ( ) { return _txt == null ? _cur.atTop() : false;      }
  -        boolean atEndOfTop ( ) { return _txt == null ? _cur.atEndOfTop() : false; }
  -        
  -        boolean toFirstAttr ( ) { assert _txt == null; return _cur.toFirstAttr(); }
  -        boolean toNextAttr  ( ) { assert _txt == null; return _cur.toNextAttr(); }
  -        boolean toPrevAttr  ( ) { assert _txt == null; return _cur.toPrevAttr(); }
  -        boolean toParentRaw ( ) { return _cur.toParentRaw(); }
  +        boolean isXmlns       ( ) { return _txt == null ? _cur.isXmlns()      : false; }
  +        
  +        boolean hasChildren   ( ) { return _txt == null ? _cur.hasChildren() : false; }
  +        boolean hasText       ( ) { return _txt == null ? _cur.hasText()     : false; }
  +        
  +        boolean toFirstAttr   ( ) { assert _txt == null; return _cur.toFirstAttr(); }
  +        boolean toNextAttr    ( ) { assert _txt == null; return _cur.toNextAttr(); }
  +        String  getAttrValue  ( ) { throw new RuntimeException( "Not impl" ); }
           
           void toEnd ( ) { assert _txt == null; _cur.toEnd(); }
           
  @@ -1820,8 +2103,6 @@
   
               if (kind == ROOT || kind == ELEM)
               {
  -                _sb.append( "[after container]" );
  -                
                   if (_cur.isText())
                   {
                       Object src = _cur.getChars();
  @@ -1846,18 +2127,6 @@
           
           void pop ( ) { _cur.pop(); _txt = (String) _stack.remove( _stack.size() - 1 ); }
           
  -        void clearSelection ( )  { _cur.clearSelection(); }
  -        int  selectionCount ( )  { return _cur.selectionCount(); }
  -        
  -        void addAttrToSelection ( )
  -        {
  -            assert _cur.isAttr() && _txt == null;
  -            _cur.addAttrToSelection();
  -        }
  -        
  -        void moveToSelection ( int i ) { _cur.moveToSelection( i ); assert isAttr(); }
  -        void removeSelection ( int i ) { _cur.removeSelection( i ); }
  -        
           Object getChars ( )
           {
               if (_txt != null)
  @@ -1912,24 +2181,22 @@
       
       private SaveCur _cur;
   
  -    private boolean _preProcess;
       private boolean _postProcess;
       private boolean _postPop;
       private boolean _done;
       private boolean _skipContainer;
  -    private boolean _needsFrag;
   
  -    private QName   _synthElem;
       private Map     _suggestedPrefixes;
       private boolean _useDefaultNamespace;
       private HashMap _preComputedNamespaces;
  -    private boolean _wantFragTest;
       private boolean _saveNamespacesFirst;
       private String  _filterProcinst;
   
  +    private ArrayList _attrNames;
  +    private ArrayList _attrValues;
  +
       private ArrayList _namespaceStack;
       private int       _currentMapping;
  -    private boolean   _firstPush;
       private HashMap   _uriMap;
       private HashMap   _prefixMap;
       private String    _initialDefaultUri;
  
  
  
  1.31      +85 -5     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.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- EricTest.java	5 Mar 2004 01:17:05 -0000	1.30
  +++ EricTest.java	11 Mar 2004 19:50:29 -0000	1.31
  @@ -106,19 +106,99 @@
   {
       public static void main ( String[] args ) throws Exception
       {
  +        XmlOptions innerOptions = new XmlOptions();
  +        innerOptions.setSaveInner();
  +        
  +        XmlOptions synthOptions = new XmlOptions();
  +        synthOptions.setSaveSyntheticDocumentElement( new QName( "synth" ) );
  +        
  +        XmlObject x = XmlObject.Factory.parse( "<a x='y'/>" );
  +        XmlCursor cx = x.newCursor();
  +        cx.toFirstChild();
  +        cx.save( System.out, innerOptions );
  +        
           XmlCursor c = Public2.newStore();
   
           c.toNextToken();
   
           c.beginElement( "foo" );
  -        c.insertAttributeWithValue( "a1", "<>><<" );
  -        c.insertComment( "comment" );
  -        c.insertProcInst( "target", "value" );
  -        c.insertElementWithText( "gag", "text" );
  +        c.insertNamespace( "ns1", "ns1.com" );
  +        c.insertAttributeWithValue( "x", "y" );
  +        c.insertElementWithText( "bar", "text" );
  +        c.insertElementWithText( "bar2", "text" );
   
           c.toStartDoc();
  +        Public2.dump( c );
   
  -        System.out.println( c.xmlText() );
  +        c.toStartDoc();
  +        System.out.println( "Rename document: " + c.xmlText( synthOptions ) );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        System.out.println( "Rename doc elem: " + c.xmlText( synthOptions ) );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        System.out.println( "Inner Doc Elem: " + c.xmlText( innerOptions ) );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        System.out.println( "Doc Elem: " + c.xmlText() );
  +        
  +        c.toStartDoc();
  +        System.out.println( "Whole doc: " + c.xmlText() );
  +
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Namespace: " + c.xmlText() );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Attr: " + c.xmlText() );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Nested elem: " + c.xmlText() );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Text: " + c.xmlText() );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Nothing: " + c.xmlText() );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Rename attr: " + c.xmlText( synthOptions ) );
  +        
  +        c.toStartDoc();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        c.toNextToken();
  +        System.out.println( "Rename Text: " + c.xmlText( synthOptions ) );
  +        
  +        // TODO - set saving of inner of elem with attrs, does the old
  +        // saver save out the attributes or just hte content?
   
   
   //        Document doc = Public2.parse( "<a/>" );
  
  
  

---------------------------------------------------------------------
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