You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by er...@apache.org on 2004/09/13 20:37:16 UTC
cvs commit: xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2 Cursor.java
ericvas 2004/09/13 11:37:16
Modified: v2/src/newstore2/org/apache/xmlbeans/impl/newstore2
Cursor.java
Log:
make getDomNode behave like v1 wrt fragments
Revision Changes Path
1.26 +88 -26 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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Cursor.java 16 Aug 2004 15:58:25 -0000 1.25
+++ Cursor.java 13 Sep 2004 18:37:16 -0000 1.26
@@ -583,9 +583,66 @@
return (Node) _cur.getDom();
}
+ private boolean isDomFragment ( )
+ {
+ if (! isStartdoc())
+ return true;
+
+ boolean seenElement = false;
+
+ XmlCursor c = newCursor();
+ int token = c.toNextToken().intValue();
+
+ try
+ {
+ LOOP: for ( ; ; )
+ {
+ SWITCH: switch ( token )
+ {
+ case TokenType.INT_START:
+ if (seenElement)
+ return true;
+ seenElement = true;
+ token = c.toEndToken().intValue();
+ break SWITCH;
+
+ case TokenType.INT_TEXT:
+ if (!Locale.isWhiteSpace( c.getChars() ))
+ return true;
+ token = c.toNextToken().intValue();
+ break SWITCH;
+
+ case TokenType.INT_NONE:
+ case TokenType.INT_ENDDOC:
+ break LOOP;
+
+ case TokenType.INT_ATTR:
+ case TokenType.INT_NAMESPACE:
+ return true;
+
+ case TokenType.INT_END:
+ case TokenType.INT_COMMENT:
+ case TokenType.INT_PROCINST:
+ token = c.toNextToken().intValue();
+ break SWITCH;
+
+ case TokenType.INT_STARTDOC:
+ assert false;
+ break LOOP;
+ }
+ }
+ }
+ finally
+ {
+ c.dispose();
+ }
+
+ return !seenElement;
+ }
+
private static final class DomSaver extends Saver
{
- DomSaver ( Cur c, XmlOptions options )
+ DomSaver ( Cur c, boolean isFrag, XmlOptions options )
{
super( c, options );
@@ -594,6 +651,7 @@
_stl = c._locale._schemaTypeLoader;
_options = options;
+ _isFrag = isFrag;
}
Node saveDom ( )
@@ -606,9 +664,13 @@
{
_nodeCur = l.getCur(); // Not weak or temp
+ // Build the tree
+
while ( process() )
;
+ // Set the type
+
while ( !_nodeCur.isRoot() )
_nodeCur.toParent();
@@ -636,34 +698,29 @@
// have attrs in fragments
if (Locale.isFragmentQName( c.getName() ))
+ _nodeCur.moveTo( null, Cur.NO_POS );
+
+ ensureDoc();
+
+ _nodeCur.createElement( getQualifiedName( c, c.getName() ) );
+ _nodeCur.next();
+
+ for ( iterateMappings() ; hasMapping() ; nextMapping() )
{
- _nodeCur.createDomDocFragRoot();
+ _nodeCur.createAttr( _nodeCur._locale.createXmlns( mappingPrefix() ) );
_nodeCur.next();
+ _nodeCur.insertString( mappingUri() );
+ _nodeCur.toParent();
+ _nodeCur.skipWithAttrs();
}
- else
- {
- ensureDoc();
- _nodeCur.createElement( getQualifiedName( c, c.getName() ) );
+ for ( int i = 0 ; i < attrNames.size() ; i ++ )
+ {
+ _nodeCur.createAttr( getQualifiedName( c, (QName) attrNames.get( i ) ) );
_nodeCur.next();
-
- for ( iterateMappings() ; hasMapping() ; nextMapping() )
- {
- _nodeCur.createAttr( _nodeCur._locale.createXmlns( mappingPrefix() ) );
- _nodeCur.next();
- _nodeCur.insertString( mappingUri() );
- _nodeCur.toParent();
- _nodeCur.skipWithAttrs();
- }
-
- for ( int i = 0 ; i < attrNames.size() ; i ++ )
- {
- _nodeCur.createAttr( getQualifiedName( c, (QName) attrNames.get( i ) ) );
- _nodeCur.next();
- _nodeCur.insertString( (String) attrValues.get( i ) );
- _nodeCur.toParent();
- _nodeCur.skipWithAttrs();
- }
+ _nodeCur.insertString( (String) attrValues.get( i ) );
+ _nodeCur.toParent();
+ _nodeCur.skipWithAttrs();
}
return false;
@@ -740,7 +797,11 @@
{
if (!_nodeCur.isPositioned())
{
- _nodeCur.createDomDocumentRoot();
+ if (_isFrag)
+ _nodeCur.createDomDocFragRoot();
+ else
+ _nodeCur.createDomDocumentRoot();
+
_nodeCur.next();
}
}
@@ -749,6 +810,7 @@
private SchemaType _type;
private SchemaTypeLoader _stl;
private XmlOptions _options;
+ private boolean _isFrag;
}
public Node _newDomNode ( XmlOptions options )
@@ -761,7 +823,7 @@
options.remove( XmlOptions.SAVE_INNER );
}
- return new DomSaver( _cur, options ).saveDom();
+ return new DomSaver( _cur, isDomFragment(), options ).saveDom();
}
public boolean _toCursor ( Cursor other )
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org