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, 12 Mar 2004 00:15:34 GMT
ericvas     2004/03/11 16:15:34

  Modified:    v2/src/newstore2/org/apache/xmlbeans/impl/newstore2
                        Saver.java
               v2/test/src/erictest EricTest.java
  Log:
  pretty printing
  
  Revision  Changes    Path
  1.14      +58 -34    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Saver.java	11 Mar 2004 20:52:03 -0000	1.13
  +++ Saver.java	12 Mar 2004 00:15:34 -0000	1.14
  @@ -283,7 +283,7 @@
   
               assert k != ATTR;
               
  -            if (k == ELEM)
  +            if (k != TEXT)
                   start.toEnd();
               
               start.next();
  @@ -2091,67 +2091,86 @@
           
           boolean toFirstAttr   ( ) { assert _txt == null; return _cur.toFirstAttr(); }
           boolean toNextAttr    ( ) { assert _txt == null; return _cur.toNextAttr(); }
  -        String  getAttrValue  ( ) { throw new RuntimeException( "Not impl" ); }
  +        String  getAttrValue  ( ) { assert _txt == null; return _cur.getAttrValue(); }
           
           void toEnd ( ) { assert _txt == null; _cur.toEnd(); }
           
           boolean next ( )
           {
  +            int k = kind();
  +            
               if (_txt != null)
               {
                   assert _txt.length() > 0;
                   assert !_cur.isText();
                   _txt = null;
  -                
  -                return true;
  +                k = kind();
               }
  +            else
  +            {
  +                int prevKind = k;
   
  -            int kind = kind();
  -
  -            if (!_cur.next())
  -                return false;
  -
  -            _sb.delete( 0, _sb.length() );
  +                if (!_cur.next())
  +                    return false;
   
  -            assert _txt == null;
  +                _sb.delete( 0, _sb.length() );
   
  -//            if (
  -//
  -//            if (kind == ELEM || kind == COMMENT || kind == PROCINST)
  -//            {
  -//                
  -//            }
  +                assert _txt == null;
   
  +                if (_cur.isText())
  +                {
  +                    CharUtil.getString( _sb, _cur.getChars(), _cur._offSrc, _cur._cchSrc
);
  +                    _cur.next();
  +                    trim( _sb );
  +                }
   
  +                k = kind();
   
  -                        
  +                boolean isLeaf =
  +                    prevKind == COMMENT || prevKind == PROCINST ||
  +                        (prevKind == ELEM && k == -ELEM);
   
  -            if (kind == ELEM || kind == COMMENT || kind == PROCINST)
  -            {
  -                if (_cur.isText())
  +                if (_sb.length() > 0 && !isLeaf)
                   {
  -                    Object src = _cur.getChars();
  -                    CharUtil.getString( _sb, _cur._offSrc, _cur._cchSrc );
  -                    _cur.next();
  +                    _sb.insert( 0, _newLine );
  +                    spaces( _sb, _newLine.length(), _prettyOffset + _prettyIndent * _depth
);
                   }
   
  -                trim( _sb );
  +                if (prevKind != ROOT && !isLeaf)
  +                {
  +                    _sb.append( _newLine );
  +                    int d = k < 0 ? _depth - 1 : _depth;
  +                    spaces( _sb, _sb.length(), _prettyOffset + _prettyIndent * d );
  +                }
                   
                   if (_sb.length() > 0)
  +                {
                       _txt = _sb.toString();
  -
  -                
  -            }
  -            else if (kind < 0 && kind != -ATTR)
  -            {
  +                    k = kind();
  +                }
               }
   
  +            if (k == ELEM)
  +                _depth++;
  +            else if (k == -ELEM)
  +                _depth--;
  +
               return true;
           }
           
  -        void push ( ) { _cur.push(); _stack.add( _txt ); }
  +        void push ( )
  +        {
  +            _cur.push();
  +            _stack.add( _txt );
  +            _stack.add( new Integer( _depth ) );
  +        }
           
  -        void pop ( ) { _cur.pop(); _txt = (String) _stack.remove( _stack.size() - 1 );
}
  +        void pop ( )
  +        {
  +            _cur.pop();
  +            _depth = ((Integer) _stack.remove( _stack.size() - 1 )).intValue();
  +            _txt = (String) _stack.remove( _stack.size() - 1 );
  +        }
           
           Object getChars ( )
           {
  @@ -2173,7 +2192,7 @@
           final static void spaces ( StringBuffer sb, int offset, int count )
           {
               while ( count-- > 0 )
  -                sb.insert( offset, ' ' );
  +                sb.insert( offset, '.' );
           }
   
           final static void trim ( StringBuffer sb )
  @@ -2200,6 +2219,8 @@
   
           private String       _txt;
           private StringBuffer _sb;
  +
  +        private int          _depth;
           
           private ArrayList    _stack;
       }
  @@ -2233,5 +2254,8 @@
       private HashMap   _prefixMap;
       private String    _initialDefaultUri;
   
  -    protected String _newLine;
  +    static String _newLine =
  +        System.getProperty( "line.separator" ) == null
  +            ? "\n"
  +            : System.getProperty( "line.separator" );
   }
  
  
  
  1.34      +27 -23    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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- EricTest.java	11 Mar 2004 20:53:40 -0000	1.33
  +++ EricTest.java	12 Mar 2004 00:15:34 -0000	1.34
  @@ -106,33 +106,37 @@
   {
       public static void main ( String[] args ) throws Exception
       {
  -        XmlOptions innerOptions = new XmlOptions();
  -        innerOptions.setSaveInner();
  +//        XmlOptions innerOptions = new XmlOptions();
  +//        innerOptions.setSaveInner();
           
           XmlOptions prettyOptions = new XmlOptions();
  -        innerOptions.setSavePrettyPrint();
  +        prettyOptions.setSavePrettyPrint();
   
  -        XmlOptions synthOptions = new XmlOptions();
  -        synthOptions.setSaveSyntheticDocumentElement( new QName( "synth" ) );
  +//        XmlOptions synthOptions = new XmlOptions();
  +//        synthOptions.setSaveSyntheticDocumentElement( new QName( "synth" ) );
           
  -        XmlObject x = XmlObject.Factory.parse( "<a x='y'><b>33<c>11</c>22</a>"
);
  -        XmlCursor cx = x.newCursor();
  -        cx.toFirstChild();
  -        cx.save( System.out, prettyOptions );
  -        
  -        XmlCursor c = Public2.newStore();
  -
  -        c.toNextToken();
  -
  -        c.beginElement( "foo" );
  -        c.insertNamespace( "ns1", "ns1.com" );
  -        c.insertAttributeWithValue( "x", "y" );
  -        c.insertElementWithText( "bar", "text" );
  -        c.insertElementWithText( "bar2", "text" );
  -
  -        c.toStartDoc();
  -        Public2.dump( c );
  +//        XmlObject x = XmlObject.Factory.parse( "<a x='y'><b>33<c>11</c>22</b></a>"
);
  +//        XmlCursor cx = x.newCursor();
  +//        cx.save( System.out, prettyOptions );
  +
  +        Document doc = Public2.parse( new FileInputStream( new File( "c:\\ee.xml" ) ),
null );
  +        
  +        System.out.println( Public2.save( doc, prettyOptions ) );
  +        
  +//        XmlCursor c = Public2.newStore();
  +//
  +//        c.toNextToken();
  +//
  +//        c.beginElement( "foo" );
  +//        c.insertNamespace( "ns1", "ns1.com" );
  +//        c.insertAttributeWithValue( "x", "y" );
  +//        c.insertElementWithText( "bar", "text" );
  +//        c.insertElementWithText( "bar2", "text" );
  +//
  +//        c.toStartDoc();
  +//        Public2.dump( c );
   
  +/*
           c.toStartDoc();
           System.out.println( "Rename document: " + c.xmlText( synthOptions ) );
           
  @@ -202,7 +206,7 @@
           
           // 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