You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by kk...@apache.org on 2004/11/30 01:02:03 UTC

cvs commit: xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2 Cursor.java Locale.java Saver.java

kkrouse     2004/11/29 16:02:03

  Modified:    v2/src/newstore2/org/apache/xmlbeans/impl/newstore2
                        Cursor.java Locale.java Saver.java
  Log:
  Jira72: Document properties are lost
  
  Revision  Changes    Path
  1.33      +10 -0     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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Cursor.java	22 Oct 2004 18:22:09 -0000	1.32
  +++ Cursor.java	30 Nov 2004 00:02:03 -0000	1.33
  @@ -769,6 +769,16 @@
               emitTextValue( c );
               _nodeCur.skip();
           }
  +        
  +        protected void emitDocType ( String docTypeName, String publicId, String systemId )
  +        {
  +            ensureDoc();
  +
  +            XmlDocumentProperties props = Locale.getDocProps( _nodeCur, true );
  +            props.setDoctypeName(docTypeName);
  +            props.setDoctypePublicId(publicId);
  +            props.setDoctypeSystemId(systemId);
  +        }
   
           private QName getQualifiedName ( SaveCur c, QName name )
           {
  
  
  
  1.35      +1 -1      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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- Locale.java	27 Nov 2004 19:00:45 -0000	1.34
  +++ Locale.java	30 Nov 2004 00:02:03 -0000	1.35
  @@ -1379,7 +1379,7 @@
   
           DocProps props = (DocProps) c.getBookmark( DocProps.class );
   
  -        if (props == null)
  +        if (props == null && ensure)
               c.setBookmark( DocProps.class, props = new DocProps() );
   
           c.pop();
  
  
  
  1.33      +104 -13   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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Saver.java	13 Oct 2004 20:50:58 -0000	1.32
  +++ Saver.java	30 Nov 2004 00:02:03 -0000	1.33
  @@ -59,6 +59,7 @@
       protected abstract void emitText       ( SaveCur c );
       protected abstract void emitComment    ( SaveCur c );
       protected abstract void emitProcinst   ( SaveCur c );
  +    protected abstract void emitDocType    ( String docTypeName, String publicId, String systemId );
   
       protected void syntheticNamespace ( String prefix, String uri, boolean considerDefault ) { }
   
  @@ -281,7 +282,7 @@
           
           switch ( _cur.kind() )
           {
  -            case   ROOT     : {                                       break; }
  +            case   ROOT     : { processRoot();                        break; }
               case   ELEM     : { processElement();                     break; }
               case - ELEM     : { processFinish ();                     break; }
               case   TEXT     : { emitText      ( _cur );               break; }
  @@ -310,19 +311,45 @@
           emitFinish( _cur );
           popMappings();
       }
  -    
  +
  +    private final void processRoot ( )
  +    {
  +        assert _cur.isRoot();
  +
  +        XmlDocumentProperties props = _cur.getDocProps();
  +        String systemId = null;
  +        String docTypeName = null;
  +        if (props != null)
  +        {
  +            systemId = props.getDoctypeSystemId();
  +            docTypeName = props.getDoctypeName();
  +        }
  +
  +        if (systemId != null || docTypeName != null)
  +        {
  +            if (docTypeName == null)
  +            {
  +                _cur.push();
  +                while (!_cur.isElem() && _cur.next())
  +                    ;
  +                if (_cur.isElem())
  +                    docTypeName = _cur.getName().getLocalPart();
  +                _cur.pop();
  +            }
  +
  +            String publicId = props.getDoctypePublicId();
  +
  +            if (docTypeName != null)
  +                emitDocType( docTypeName, publicId, systemId );
  +        }
  +    }
  +
       private final void processElement ( )
       {
           assert _cur.isElem() && _cur.getName() != null;
   
           QName name = _cur.getName();
   
  -        // TODO - check for doctype to save out here
  -        // TODO - check for doctype to save out here
  -        // TODO - check for doctype to save out here
  -
  -        ;
  -
           // Add a new entry to the frontier.  If this element has a name
           // which has no namespace, then we must make sure that pushing
           // the mappings causes the default namespace to be empty
  @@ -814,6 +841,8 @@
           protected void emitText      ( SaveCur c ) { }
           protected void emitComment   ( SaveCur c ) { }
           protected void emitProcinst  ( SaveCur c ) { }
  +        protected void emitDocType   ( String docTypeName, String publicId, String systemId ) { }
  +
       }
   
       //
  @@ -972,6 +1001,48 @@
               emit( "?>" );
           }
   
  +        private void emitLiteral ( String literal )
  +        {
  +            // TODO: systemId production http://www.w3.org/TR/REC-xml/#NT-SystemLiteral
  +            // TODO: publicId production http://www.w3.org/TR/REC-xml/#NT-PubidLiteral
  +            if (literal.indexOf( "\"" ) < 0)
  +            {
  +                emit( "\"" );
  +                emit( literal );
  +                emit( "\"" );
  +            }
  +            else
  +            {
  +                emit( "'" );
  +                emit( literal );
  +                emit( "'" );
  +            }
  +        }
  +
  +        protected void emitDocType ( String docTypeName, String publicId, String systemId )
  +        {
  +            assert docTypeName != null;
  +
  +            emit( "<DOCTYPE " );
  +            emit( docTypeName );
  +
  +            if (publicId == null && systemId != null)
  +            {
  +                emit( " SYSTEM " );
  +                emitLiteral( systemId );
  +            }
  +            else if (publicId != null)
  +            {
  +                emit( " PUBLIC " );
  +                emitLiteral( publicId );
  +                emit( " " );
  +                emitLiteral( systemId );
  +            }
  +
  +            emit( ">" );
  +            emit( _newLine );
  +        }
  +
           //
           //
           //
  @@ -2127,10 +2198,21 @@
               }
           }
   
  -        // TODO - need to emit doc type !!!!!
  -        // TODO - need to emit doc type !!!!!
  -        // TODO - need to emit doc type !!!!!
  -        // TODO - need to emit doc type !!!!!
  +        protected void emitDocType ( String docTypeName, String publicId, String systemId )
  +        {
  +            if (_lexicalHandler != null)
  +            {
  +                try
  +                {
  +                    _lexicalHandler.startDTD( docTypeName, publicId, systemId );
  +                    _lexicalHandler.endDTD();
  +                }
  +                catch ( SAXException e )
  +                {
  +                    throw new SaverSAXException( e );
  +                }
  +            }
  +        }
   
           private ContentHandler _contentHandler;
           private LexicalHandler _lexicalHandler;
  @@ -2183,6 +2265,7 @@
   
           abstract Object getChars ( );
           abstract List  getAncestorNamespaces ( );
  +        abstract XmlDocumentProperties getDocProps ( );
   
           int _offSrc;
           int _cchSrc;
  @@ -2238,6 +2321,8 @@
               return o;
           }
   
  +        XmlDocumentProperties getDocProps ( ) { return Locale.getDocProps(_cur, false); }
  +
           private Cur _cur;
       }
   
  @@ -2305,6 +2390,8 @@
               return o;
           }
           
  +        XmlDocumentProperties getDocProps ( ) { return _cur.getDocProps(); }
  +
           private SaveCur _cur;
       }
   
  @@ -2611,6 +2698,8 @@
               _state = _stateStack [ --_stateStackSize ];
           }
           
  +        XmlDocumentProperties getDocProps ( ) { return Locale.getDocProps(_cur, false); }
  +
           //
           //
           //
  @@ -2790,6 +2879,8 @@
               return o;
           }
           
  +        XmlDocumentProperties getDocProps ( ) { return _cur.getDocProps(); }
  +
           final static void spaces ( StringBuffer sb, int offset, int count )
           {
               while ( count-- > 0 )
  @@ -2850,7 +2941,7 @@
       private HashMap   _prefixMap;
       private String    _initialDefaultUri;
   
  -    static String _newLine =
  +    static final String _newLine =
           System.getProperty( "line.separator" ) == null
               ? "\n"
               : System.getProperty( "line.separator" );
  
  
  

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