You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/08/28 20:49:50 UTC

svn commit: r1881284 [8/18] - in /xmlbeans/trunk/src: main/java/org/apache/xmlbeans/ main/java/org/apache/xmlbeans/impl/common/ main/java/org/apache/xmlbeans/impl/schema/ main/java/org/apache/xmlbeans/impl/store/ main/java/org/apache/xmlbeans/impl/tool...

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java?rev=1881284&r1=1881283&r2=1881284&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java Fri Aug 28 20:49:50 2020
@@ -145,8 +145,9 @@ final class Cur {
     boolean isContainerOrFinish() {
         assert isPositioned();
 
-        if (_pos != 0 && _pos != END_POS)
+        if (_pos != 0 && _pos != END_POS) {
             return false;
+        }
 
         int kind = _xobj.kind();
         return kind == ELEM || kind == -ELEM || kind == ROOT || kind == -ROOT;
@@ -248,36 +249,60 @@ final class Cur {
     static Xobj createDomDocumentRootXobj(Locale l, boolean fragment) {
         Xobj xo;
 
-        if (l._saaj == null)
-            if (fragment)
+        if (l._saaj == null) {
+            if (fragment) {
                 xo = new DocumentFragXobj(l);
-            else
+            } else {
                 xo = new DocumentXobj(l);
-        else
+            }
+        } else {
             xo = new SoapPartDocXobj(l);
+        }
 
-        if (l._ownerDoc == null)
+        if (l._ownerDoc == null) {
             l._ownerDoc = xo.getDom();
+        }
 
         return xo;
     }
 
     static Xobj createElementXobj(Locale l, QName name, QName parentName) {
-        if (l._saaj == null)
+        if (l._saaj == null) {
             return new ElementXobj(l, name);
+        }
 
         Class c = l._saaj.identifyElement(name, parentName);
 
-        if (c == SOAPElement.class) return new SoapElementXobj(l, name);
-        if (c == SOAPBody.class) return new SoapBodyXobj(l, name);
-        if (c == SOAPBodyElement.class) return new SoapBodyElementXobj(l, name);
-        if (c == SOAPEnvelope.class) return new SoapEnvelopeXobj(l, name);
-        if (c == SOAPHeader.class) return new SoapHeaderXobj(l, name);
-        if (c == SOAPHeaderElement.class) return new SoapHeaderElementXobj(l, name);
-        if (c == SOAPFaultElement.class) return new SoapFaultElementXobj(l, name);
-        if (c == Detail.class) return new DetailXobj(l, name);
-        if (c == DetailEntry.class) return new DetailEntryXobj(l, name);
-        if (c == SOAPFault.class) return new SoapFaultXobj(l, name);
+        if (c == SOAPElement.class) {
+            return new SoapElementXobj(l, name);
+        }
+        if (c == SOAPBody.class) {
+            return new SoapBodyXobj(l, name);
+        }
+        if (c == SOAPBodyElement.class) {
+            return new SoapBodyElementXobj(l, name);
+        }
+        if (c == SOAPEnvelope.class) {
+            return new SoapEnvelopeXobj(l, name);
+        }
+        if (c == SOAPHeader.class) {
+            return new SoapHeaderXobj(l, name);
+        }
+        if (c == SOAPHeaderElement.class) {
+            return new SoapHeaderElementXobj(l, name);
+        }
+        if (c == SOAPFaultElement.class) {
+            return new SoapFaultElementXobj(l, name);
+        }
+        if (c == Detail.class) {
+            return new DetailXobj(l, name);
+        }
+        if (c == DetailEntry.class) {
+            return new DetailEntryXobj(l, name);
+        }
+        if (c == SOAPFault.class) {
+            return new SoapFaultXobj(l, name);
+        }
 
         throw new IllegalStateException("Unknown SAAJ element class: " + c);
     }
@@ -337,8 +362,9 @@ final class Cur {
 
         // If in differnet locales, then can't comapre
 
-        if (_locale != that._locale)
+        if (_locale != that._locale) {
             return 2;
+        }
 
         // No need to denormalize, but I want positions which I can compare (no END_POS)
 
@@ -391,12 +417,12 @@ final class Cur {
 
         while (dThis > dThat) {
             dThis--;
-            assert(xThis != null);
+            assert (xThis != null);
             xThis = xThis._parent;
         }
         while (dThat > dThis) {
             dThat--;
-            assert(xThat != null);
+            assert (xThat != null);
             xThat = xThat._parent;
         }
 
@@ -614,8 +640,9 @@ final class Cur {
                 next[i] = before;
                 prev[before] = i;
 
-                if (head == before)
+                if (head == before) {
                     head = i;
+                }
             } else {
                 prev[i] = prev[head];
                 assert next[i] == NULL;
@@ -864,8 +891,9 @@ final class Cur {
     boolean hasParent() {
         assert isPositioned();
 
-        if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter()))
+        if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter())) {
             return true;
+        }
 
         assert _pos == 0 || _xobj._parent != null;
 
@@ -875,13 +903,15 @@ final class Cur {
     Xobj getParentNoRoot() {
         assert isPositioned();
 
-        if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter()))
+        if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter())) {
             return _xobj;
+        }
 
         assert _pos == 0 || _xobj._parent != null;
 
-        if (_xobj._parent != null)
+        if (_xobj._parent != null) {
             return _xobj._parent;
+        }
 
         return null;
     }
@@ -889,16 +919,19 @@ final class Cur {
     Xobj getParent(boolean raw) {
         assert isPositioned();
 
-        if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter()))
+        if (_pos == END_POS || (_pos >= 1 && _pos < _xobj.posAfter())) {
             return _xobj;
+        }
 
         assert _pos == 0 || _xobj._parent != null;
 
-        if (_xobj._parent != null)
+        if (_xobj._parent != null) {
             return _xobj._parent;
+        }
 
-        if (raw || _xobj.isRoot())
+        if (raw || _xobj.isRoot()) {
             return null;
+        }
 
         Cur r = _locale.tempCur();
 
@@ -916,8 +949,9 @@ final class Cur {
     boolean toParent(boolean raw) {
         Xobj parent = getParent(raw);
 
-        if (parent == null)
+        if (parent == null) {
             return false;
+        }
 
         moveTo(parent);
 
@@ -967,8 +1001,9 @@ final class Cur {
     boolean toFirstChild() {
         assert isNode();
 
-        if (!_xobj.hasChildren())
+        if (!_xobj.hasChildren()) {
             return false;
+        }
 
         for (Xobj x = _xobj._firstChild; ; x = x._nextSibling) {
             if (!x.isAttr()) {
@@ -981,8 +1016,9 @@ final class Cur {
     protected boolean toLastChild() {
         assert isNode();
 
-        if (!_xobj.hasChildren())
+        if (!_xobj.hasChildren()) {
             return false;
+        }
 
         moveTo(_xobj._lastChild);
 
@@ -1015,8 +1051,9 @@ final class Cur {
             prefixForNamespace(
                 ns, qname.getPrefix().length() > 0 ? qname.getPrefix() : null, true);
 
-        if (prefix.length() > 0)
+        if (prefix.length() > 0) {
             value = prefix + ":" + value;
+        }
 
         setValue(value);
     }
@@ -1042,10 +1079,11 @@ final class Cur {
 
         if (toNextAttr()) {
             while (isAttr()) {
-                if (getName().equals(attrName))
+                if (getName().equals(attrName)) {
                     moveNode(null);
-                else if (!toNextAttr())
+                } else if (!toNextAttr()) {
                     break;
+                }
             }
         }
 
@@ -1103,8 +1141,9 @@ final class Cur {
 
         Xobj a = _xobj.getAttr(name);
 
-        if (a == null)
+        if (a == null) {
             return false;
+        }
 
         moveTo(a);
 
@@ -1133,7 +1172,9 @@ final class Cur {
         }
 
         //noinspection StatementWithEmptyBody
-        while (toNextAttr()) ;
+        while (toNextAttr()) {
+            ;
+        }
 
         return true;
     }
@@ -1198,16 +1239,19 @@ final class Cur {
     boolean skip() {
         assert isNode();
 
-        if (_xobj.isRoot())
+        if (_xobj.isRoot()) {
             return false;
+        }
 
         if (_xobj.isAttr()) {
-            if (_xobj._nextSibling == null || !_xobj._nextSibling.isAttr())
+            if (_xobj._nextSibling == null || !_xobj._nextSibling.isAttr()) {
                 return false;
+            }
 
             moveTo(_xobj._nextSibling, 0);
-        } else
+        } else {
             moveTo(getNormal(_xobj, _xobj.posAfter()), _posTemp);
+        }
 
         return true;
     }
@@ -1408,13 +1452,15 @@ final class Cur {
 
         int cchLeft = cchLeft();
 
-        if (cch < 0 || cch > cchLeft)
+        if (cch < 0 || cch > cchLeft) {
             cch = cchLeft;
+        }
 
         // Dang, I love this stmt :-)
 
-        if (cch != 0)
+        if (cch != 0) {
             moveTo(getNormal(getDenormal(), _posTemp - cch), _posTemp);
+        }
 
         return cch;
     }
@@ -1424,8 +1470,9 @@ final class Cur {
 
         int cchRight = cchRight();
 
-        if (cchRight == 0)
+        if (cchRight == 0) {
             return 0;
+        }
 
         if (cch < 0 || cch >= cchRight) {
             // Use next to not skip over children
@@ -1447,13 +1494,15 @@ final class Cur {
 
         assert !x.isRoot() || (p > 0 && p < x.posAfter());
 
-        if (p >= x.posAfter())
+        if (p >= x.posAfter()) {
             x._charNodesAfter = nodes;
-        else
+        } else {
             x._charNodesValue = nodes;
+        }
 
-        for (; nodes != null; nodes = nodes._next)
+        for (; nodes != null; nodes = nodes._next) {
             nodes.setDom((Dom) x);
+        }
 
         // No Need to notify text change or alter version, text nodes are
         // not part of the infoset
@@ -1554,8 +1603,9 @@ final class Cur {
     }
 
     void insertString(String s) {
-        if (s != null)
+        if (s != null) {
             insertChars(s, 0, s.length());
+        }
     }
 
     void insertChars(Object src, int off, int cch) {
@@ -1564,8 +1614,9 @@ final class Cur {
 
         // Check for nothing to insert
 
-        if (cch <= 0)
+        if (cch <= 0) {
             return;
+        }
 
         _locale.notifyChange();
 
@@ -1575,8 +1626,9 @@ final class Cur {
         // insert in the value of the parent.  In the latter case, because the parent has a child,
         // it cannot be vacant.
 
-        if (_pos == END_POS)
+        if (_pos == END_POS) {
             _xobj.ensureOccupancy();
+        }
 
         // Get the denormailized Xobj and pos.  This is the Xobj which will actually receive
         // the new chars.  Note that a denormalized position can never be <= 0.
@@ -1609,8 +1661,9 @@ final class Cur {
         assert cchMove <= 0 || cchMove <= cchRight();
         assert to == null || (to.isPositioned() && !to.isRoot());
 
-        if (cchMove < 0)
+        if (cchMove < 0) {
             cchMove = cchRight();
+        }
 
         // If we're instructed to move 0 characters, then return the null triple.
 
@@ -1689,10 +1742,11 @@ final class Cur {
         //
         //if ( _xobj != null )
         {
-            if (to == null)
+            if (to == null) {
                 _xobj.removeCharsHelper(_pos, cchMove, null, NO_POS, false, true);
-            else
+            } else {
                 _xobj.removeCharsHelper(_pos, cchMove, to._xobj, to._pos, false, true);
+            }
         }
 
         // Need to update the position of this cursor even though it did not move anywhere.  This
@@ -1771,8 +1825,9 @@ final class Cur {
             // a vacant node, I get it occupied.  I do not need to worry about the source being
             // vacant.
 
-            if (to._pos == END_POS)
+            if (to._pos == END_POS) {
                 to._xobj.ensureOccupancy();
+            }
 
             // See if the destination is on the edge of the node to be moved (a no-op).  It is
             // illegal to call this fcn when to is contained within the node to be moved.  Note
@@ -1804,14 +1859,16 @@ final class Cur {
         // Node is going away.  Invalidate the parent (the text around the node is merging).
         // Also, this node may be an attribute -- invalidate special attrs ...
 
-        if (x.isAttr())
+        if (x.isAttr()) {
             x.invalidateSpecialAttr(to == null ? null : to.getParentRaw());
-        else {
-            if (x._parent != null)
+        } else {
+            if (x._parent != null) {
                 x._parent.invalidateUser();
+            }
 
-            if (to != null && to.hasParent())
+            if (to != null && to.hasParent()) {
                 to.getParent().invalidateUser();
+            }
         }
 
         // If there is any text after x, I move it to be before x.  This frees me to extract x
@@ -1870,16 +1927,18 @@ final class Cur {
                 to.pop();
             }
 
-            if (append)
+            if (append) {
                 here.appendXobj(x);
-            else
+            } else {
                 here.insertXobj(x);
+            }
 
             // The only text I need to move is that to the right of "to".  Even considering all
             // the cases where an attribute is involed!
 
-            if (cchRight > 0)
+            if (cchRight > 0) {
                 transferChars(to._xobj, to._pos, x, x.posAfter(), cchRight);
+            }
 
             to.moveTo(x);
         }
@@ -1962,8 +2021,9 @@ final class Cur {
 
             // TODO - shuffle interior curs?
 
-            if (isAtLeftEdge)
+            if (isAtLeftEdge) {
                 return;
+            }
 
             // Now, after dealing with the edge condition, I can assert that to is not inside x
 
@@ -1990,8 +2050,9 @@ final class Cur {
             c.moveChars(to, -1);
             c.release();
 
-            if (to != null)
+            if (to != null) {
                 to.nextChars(valueMovedCch = c._cchSrc);
+            }
         }
 
         // Now, walk all the contents, invalidating special attrs, reportioning cursors,
@@ -2015,13 +2076,15 @@ final class Cur {
                 y.invalidateSpecialAttr(to == null ? null : to.getParent());
             }
 
-            for (Cur c; (c = y._embedded) != null; )
+            for (Cur c; (c = y._embedded) != null; ) {
                 c.moveTo(x, END_POS);
+            }
 
             y.disconnectUser();
 
-            if (to != null)
+            if (to != null) {
                 y._locale = to._locale;
+            }
 
             sawBookmark = sawBookmark || y._bookmarks != null;
         }
@@ -2046,8 +2109,9 @@ final class Cur {
         // invalidation needed.  If I've move text to "to" already, no need to invalidate
         // again.
 
-        if (!lastToMove.isAttr())
+        if (!lastToMove.isAttr()) {
             x.invalidateUser();
+        }
 
         x._locale._versionAll++;
         x._locale._versionSansText++;
@@ -2093,8 +2157,9 @@ final class Cur {
             if (firstToMove.isAttr()) {
                 Xobj lastNewAttr = firstToMove;
 
-                while (lastNewAttr._nextSibling != null && lastNewAttr._nextSibling.isAttr())
+                while (lastNewAttr._nextSibling != null && lastNewAttr._nextSibling.isAttr()) {
                     lastNewAttr = lastNewAttr._nextSibling;
+                }
 
                 // Get to's parnet now before I potentially move him with the next transfer
 
@@ -2112,7 +2177,7 @@ final class Cur {
                         cch = y._cchValue;
                     } else {
                         y = y.lastAttr();
-                        assert(y != null);
+                        assert (y != null);
                         p = y.posAfter();
                         cch = y._cchAfter;
                     }
@@ -2139,8 +2204,9 @@ final class Cur {
 
         // If I consed up a to, release it here
 
-        if (surragateTo != null)
+        if (surragateTo != null) {
             surragateTo.release();
+        }
     }
 
     protected final Bookmark setBookmark(Object key, Object value) {
@@ -2154,9 +2220,11 @@ final class Cur {
         assert isNormal();
         assert key != null;
 
-        for (Bookmark b = _xobj._bookmarks; b != null; b = b._next)
-            if (b._pos == _pos && b._key == key)
+        for (Bookmark b = _xobj._bookmarks; b != null; b = b._next) {
+            if (b._pos == _pos && b._key == key) {
                 return b._value;
+            }
+        }
 
         return null;
     }
@@ -2170,9 +2238,11 @@ final class Cur {
         int d = -1;
 
         if (isText()) {
-            for (Bookmark b = _xobj._bookmarks; b != null; b = b._next)
-                if (b._key == key && inChars(b, cch, false))
+            for (Bookmark b = _xobj._bookmarks; b != null; b = b._next) {
+                if (b._key == key && inChars(b, cch, false)) {
                     d = (d == -1 || b._pos - _pos < d) ? b._pos - _pos : d;
+                }
+            }
         }
 
         return d;
@@ -2644,17 +2714,15 @@ final class Cur {
             _lastXobj = _frontier;
             _lastPos = 0;
 
-            if (options.hasOption(XmlOptions.LOAD_REPLACE_DOCUMENT_ELEMENT)) {
-                _replaceDocElem = (QName) options.get(XmlOptions.LOAD_REPLACE_DOCUMENT_ELEMENT);
-                _discardDocElem = true;
-            }
+            _replaceDocElem = options.getLoadReplaceDocumentElement();
+            _discardDocElem = options.hasOption(XmlOptions.LOAD_REPLACE_DOCUMENT_ELEMENT);
 
-            _stripWhitespace = options.hasOption(XmlOptions.LOAD_STRIP_WHITESPACE);
-            _stripComments = options.hasOption(XmlOptions.LOAD_STRIP_COMMENTS);
-            _stripProcinsts = options.hasOption(XmlOptions.LOAD_STRIP_PROCINSTS);
+            _stripWhitespace = options.isSetLoadStripWhitespace();
+            _stripComments = options.isLoadStripComments();
+            _stripProcinsts = options.isLoadStripProcinsts();
 
-            _substituteNamespaces = (Map) options.get(XmlOptions.LOAD_SUBSTITUTE_NAMESPACES);
-            _additionalNamespaces = (Map) options.get(XmlOptions.LOAD_ADDITIONAL_NAMESPACES);
+            _substituteNamespaces = options.getLoadSubstituteNamespaces();
+            _additionalNamespaces = options.getLoadAdditionalNamespaces();
 
             _locale._versionAll++;
             _locale._versionSansText++;
@@ -2857,8 +2925,9 @@ final class Cur {
         }
 
         protected void comment(String comment) {
-            if (!_stripComments)
+            if (!_stripComments) {
                 comment(comment, 0, comment.length());
+            }
             _stripLeft = true;
         }
 
@@ -2915,9 +2984,9 @@ final class Cur {
         }
 
         protected void bookmarkLastNonAttr(XmlBookmark bm) {
-            if (_lastPos > 0 || !_lastXobj.isAttr())
+            if (_lastPos > 0 || !_lastXobj.isAttr()) {
                 _lastXobj.setBookmark(_lastPos, bm.getKey(), bm);
-            else {
+            } else {
                 assert _lastXobj._parent != null;
 
                 _lastXobj._parent.setBookmark(0, bm.getKey(), bm);
@@ -2955,8 +3024,9 @@ final class Cur {
         protected Cur finish() {
             flushText();
 
-            if (_after)
+            if (_after) {
                 _frontier = _frontier._parent;
+            }
 
             assert _frontier != null && _frontier._parent == null && _frontier.isRoot();
 
@@ -2978,7 +3048,9 @@ final class Cur {
                     // does not appear to have been the contents of the removed element.
 
                     //noinspection StatementWithEmptyBody
-                    while (c.toParent()) ;
+                    while (c.toParent()) {
+                        ;
+                    }
 
                     c.next();
 
@@ -3237,29 +3309,34 @@ final class Cur {
     }
 
     private static void dumpXobj(PrintStream o, Xobj xo, int level, Object ref) {
-        if (xo == null)
+        if (xo == null) {
             return;
+        }
 
-        if (xo == ref)
+        if (xo == ref) {
             o.print("* ");
-        else
+        } else {
             o.print("  ");
+        }
 
-        for (int i = 0; i < level; i++)
+        for (int i = 0; i < level; i++) {
             o.print("  ");
+        }
 
         o.print(kindName(xo.kind()));
 
         if (xo._name != null) {
             o.print(" ");
 
-            if (xo._name.getPrefix().length() > 0)
+            if (xo._name.getPrefix().length() > 0) {
                 o.print(xo._name.getPrefix() + ":");
+            }
 
             o.print(xo._name.getLocalPart());
 
-            if (xo._name.getNamespaceURI().length() > 0)
+            if (xo._name.getNamespaceURI().length() > 0) {
                 o.print("@" + xo._name.getNamespaceURI());
+            }
         }
 
         if (xo._srcValue != null || xo._charNodesValue != null) {
@@ -3269,11 +3346,13 @@ final class Cur {
             o.print(" )");
         }
 
-        if (xo._user != null)
+        if (xo._user != null) {
             o.print(" (USER)");
+        }
 
-        if (xo.isVacant())
+        if (xo.isVacant()) {
             o.print(" (VACANT)");
+        }
 
         if (xo._srcAfter != null || xo._charNodesAfter != null) {
             o.print(" After( ");
@@ -3294,8 +3373,9 @@ final class Cur {
 
             i = className.lastIndexOf('$');
 
-            if (i > 0)
+            if (i > 0) {
                 className = className.substring(i + 1);
+            }
         }
 
         o.print(" (");
@@ -3304,8 +3384,9 @@ final class Cur {
 
         o.println();
 
-        for (xo = xo._firstChild; xo != null; xo = xo._nextSibling)
+        for (xo = xo._firstChild; xo != null; xo = xo._nextSibling) {
             dumpXobj(o, xo, level + 1, ref);
+        }
     }
 
     void setId(String id) {

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cursor.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cursor.java?rev=1881284&r1=1881283&r2=1881284&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cursor.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cursor.java Fri Aug 28 20:49:50 2020
@@ -68,8 +68,9 @@ public final class Cursor implements Xml
             if (c.toParentRaw()) {
                 int pk = c.kind();
 
-                if (pk == COMMENT || pk == PROCINST || pk == ATTR)
+                if (pk == COMMENT || pk == PROCINST || pk == ATTR) {
                     return false;
+                }
             }
 
             c.pop();
@@ -95,35 +96,43 @@ public final class Cursor implements Xml
     }
 
     static void validateLocalName(QName name) {
-        if (name == null)
+        if (name == null) {
             throw new IllegalArgumentException("QName is null");
+        }
 
         validateLocalName(name.getLocalPart());
     }
 
     static void validateLocalName(String name) {
-        if (name == null)
+        if (name == null) {
             throw new IllegalArgumentException("Name is null");
+        }
 
-        if (name.length() == 0)
+        if (name.length() == 0) {
             throw new IllegalArgumentException("Name is empty");
+        }
 
-        if (!XMLChar.isValidNCName(name))
+        if (!XMLChar.isValidNCName(name)) {
             throw new IllegalArgumentException("Name is not valid");
+        }
     }
 
     static void validatePrefix(String name) {
-        if (name == null)
+        if (name == null) {
             throw new IllegalArgumentException("Prefix is null");
+        }
 
-        if (name.length() == 0)
+        if (name.length() == 0) {
             throw new IllegalArgumentException("Prefix is empty");
+        }
 
-        if (Locale.beginsWithXml(name))
+        if (Locale.beginsWithXml(name)) {
             throw new IllegalArgumentException("Prefix begins with 'xml'");
+        }
 
-        if (!XMLChar.isValidNCName(name))
+        if (!XMLChar.isValidNCName(name)) {
             throw new IllegalArgumentException("Prefix is not valid");
+        }
     }
 
     private static void complain(String msg) {
@@ -133,16 +142,19 @@ public final class Cursor implements Xml
     private void checkInsertionValidity(Cur that) {
         int thatKind = that.kind();
 
-        if (thatKind < 0)
+        if (thatKind < 0) {
             complain("Can't move/copy/insert an end token.");
+        }
 
-        if (thatKind == ROOT)
+        if (thatKind == ROOT) {
             complain("Can't move/copy/insert a whole document.");
+        }
 
         int thisKind = _cur.kind();
 
-        if (thisKind == ROOT)
+        if (thisKind == ROOT) {
             complain("Can't insert before the start of the document.");
+        }
 
         if (thatKind == ATTR) {
             _cur.push();
@@ -155,8 +167,9 @@ public final class Cursor implements Xml
             }
         }
 
-        if (thisKind == ATTR && thatKind != ATTR)
+        if (thisKind == ATTR && thatKind != ATTR) {
             complain("Can only insert attributes before other attributes or after containers.");
+        }
     }
 
     private void insertNode(Cur that, String text) {
@@ -205,7 +218,7 @@ public final class Cursor implements Xml
 
                 if (_cur.isXmlns()) {
                     return
-                            _cur._locale.makeQNameNoCheck(_cur.getXmlnsUri(), _cur.getXmlnsPrefix());
+                        _cur._locale.makeQNameNoCheck(_cur.getXmlnsUri(), _cur.getXmlnsPrefix());
                 }
 
                 // Fall thru
@@ -219,33 +232,34 @@ public final class Cursor implements Xml
     }
 
     public void _setName(QName name) {
-        if (name == null)
+        if (name == null) {
             throw new IllegalArgumentException("Name is null");
+        }
 
         switch (_cur.kind()) {
             case ELEM:
-            case ATTR:
-                {
-                    validateLocalName(name.getLocalPart());
-                    break;
-                }
-
-            case PROCINST:
-                {
-                    validatePrefix(name.getLocalPart());
+            case ATTR: {
+                validateLocalName(name.getLocalPart());
+                break;
+            }
 
-                    if (name.getNamespaceURI().length() > 0)
-                        throw new IllegalArgumentException("Procinst name must have no URI");
+            case PROCINST: {
+                validatePrefix(name.getLocalPart());
 
-                    if (name.getPrefix().length() > 0)
-                        throw new IllegalArgumentException("Procinst name must have no prefix");
+                if (name.getNamespaceURI().length() > 0) {
+                    throw new IllegalArgumentException("Procinst name must have no URI");
+                }
 
-                    break;
+                if (name.getPrefix().length() > 0) {
+                    throw new IllegalArgumentException("Procinst name must have no prefix");
                 }
 
-            default :
+                break;
+            }
+
+            default:
                 throw
-                        new IllegalStateException("Can set name on element, atrtribute and procinst only");
+                    new IllegalStateException("Can set name on element, atrtribute and procinst only");
         }
 
         _cur.setName(name);
@@ -272,7 +286,7 @@ public final class Cursor implements Xml
             case PROCINST:
                 return TokenType.PROCINST;
 
-            default :
+            default:
                 throw new IllegalStateException();
         }
     }
@@ -354,38 +368,36 @@ public final class Cursor implements Xml
 
         switch (_cur.kind()) {
             case ROOT:
-            case ELEM:
-                {
-                    if (!_cur.toFirstAttr())
-                        _cur.next();
-
-                    break;
+            case ELEM: {
+                if (!_cur.toFirstAttr()) {
+                    _cur.next();
                 }
 
-            case ATTR:
-                {
-                    if (!_cur.toNextSibling()) {
-                        _cur.toParent();
-                        _cur.next();
-                    }
+                break;
+            }
 
-                    break;
+            case ATTR: {
+                if (!_cur.toNextSibling()) {
+                    _cur.toParent();
+                    _cur.next();
                 }
 
-            case COMMENT:
-            case PROCINST:
-                {
-                    _cur.skip();
-                    break;
-                }
+                break;
+            }
 
-            default :
-                {
-                    if (!_cur.next())
-                        return TokenType.NONE;
+            case COMMENT:
+            case PROCINST: {
+                _cur.skip();
+                break;
+            }
 
-                    break;
+            default: {
+                if (!_cur.next()) {
+                    return TokenType.NONE;
                 }
+
+                break;
+            }
         }
 
         return _currentTokenType();
@@ -545,13 +557,14 @@ public final class Cursor implements Xml
     }
 
     public void _save(ContentHandler ch, LexicalHandler lh, XmlOptions options)
-            throws SAXException {
+        throws SAXException {
         new Saver.SaxSaver(_cur, options, ch, lh);
     }
 
     public void _save(File file, XmlOptions options) throws IOException {
-        if (file == null)
+        if (file == null) {
             throw new IllegalArgumentException("Null file specified");
+        }
 
         try (OutputStream os = new FileOutputStream(file)) {
             _save(os, options);
@@ -559,33 +572,31 @@ public final class Cursor implements Xml
     }
 
     public void _save(OutputStream os, XmlOptions options) throws IOException {
-        if (os == null)
+        if (os == null) {
             throw new IllegalArgumentException("Null OutputStream specified");
+        }
 
-        InputStream is = _newInputStream(options);
-
-        try {
+        try (InputStream is = _newInputStream(options)) {
             byte[] bytes = new byte[8192];
 
-            for (; ;) {
+            for (; ; ) {
                 int n = is.read(bytes);
 
-                if (n < 0)
+                if (n < 0) {
                     break;
+                }
 
                 os.write(bytes, 0, n);
             }
-        } finally {
-            is.close();
         }
     }
 
     public void _save(Writer w, XmlOptions options) throws IOException {
-        if (w == null)
+        if (w == null) {
             throw new IllegalArgumentException("Null Writer specified");
+        }
 
-        if (options != null && options.hasOption( XmlOptions.SAVE_OPTIMIZE_FOR_SPEED ))
-        {
+        if (options != null && options.isSaveOptimizeForSpeed()) {
             Saver.OptimizedForSpeedSaver.save(_cur, w); //ignore all other options
             return;
         }
@@ -593,7 +604,7 @@ public final class Cursor implements Xml
         try (Reader r = _newReader(options)) {
             char[] chars = new char[8192];
 
-            for (;;) {
+            for (; ; ) {
                 int n = r.read(chars);
 
                 if (n < 0) {
@@ -610,8 +621,9 @@ public final class Cursor implements Xml
     }
 
     private boolean isDomFragment() {
-        if (!isStartdoc())
+        if (!isStartdoc()) {
             return true;
+        }
 
         boolean seenElement = false;
 
@@ -619,18 +631,21 @@ public final class Cursor implements Xml
         int token = c.toNextToken().intValue();
 
         try {
-            LOOP: for (; ;) {
+            LOOP:
+            for (; ; ) {
                 switch (token) {
                     case TokenType.INT_START:
-                        if (seenElement)
+                        if (seenElement) {
                             return true;
+                        }
                         seenElement = true;
                         token = c.toEndToken().intValue();
                         break;
 
                     case TokenType.INT_TEXT:
-                        if (!Locale.isWhiteSpace(c.getChars()))
+                        if (!Locale.isWhiteSpace(c.getChars())) {
                             return true;
+                        }
                         token = c.toNextToken().intValue();
                         break;
 
@@ -663,9 +678,9 @@ public final class Cursor implements Xml
     public Node _newDomNode(XmlOptions options) {
         // Must ignore inner options for compat with v1.
 
-        if (XmlOptions.hasOption(options, XmlOptions.SAVE_INNER)) {
+        if (options != null && options.isSaveInner()) {
             options = new XmlOptions(options);
-            options.remove(XmlOptions.SAVE_INNER);
+            options.setSaveInner(false);
         }
 
         return new DomSaver(_cur, isDomFragment(), options).saveDom();
@@ -691,8 +706,9 @@ public final class Cursor implements Xml
         // Force any path to get exausted, cursor may be disposed, but still be on the notification
         // list.
 
-        if (_cur != null)
+        if (_cur != null) {
             _getSelectionCount();
+        }
     }
 
     public void setNextChangeListener(ChangeListener listener) {
@@ -734,12 +750,14 @@ public final class Cursor implements Xml
     }
 
     public boolean _toSelection(int i) {
-        if (i < 0)
+        if (i < 0) {
             return false;
+        }
 
         while (i >= _cur.selectionCount()) {
-            if (_pathEngine == null)
+            if (_pathEngine == null) {
                 return false;
+            }
 
             if (!_pathEngine.next(_cur)) {
                 _pathEngine.release();
@@ -779,15 +797,17 @@ public final class Cursor implements Xml
     }
 
     public String _namespaceForPrefix(String prefix) {
-        if (!_cur.isContainer())
+        if (!_cur.isContainer()) {
             throw new IllegalStateException("Not on a container");
+        }
 
         return _cur.namespaceForPrefix(prefix, true);
     }
 
     public String _prefixForNamespace(String ns) {
-        if (ns == null || ns.length() == 0)
+        if (ns == null || ns.length() == 0) {
             throw new IllegalArgumentException("Must specify a namespace");
+        }
 
 // Note: I loosen this requirement in v2, can call this from anywhere
 //        if (!_cur.isContainer())
@@ -796,12 +816,14 @@ public final class Cursor implements Xml
         return _cur.prefixForNamespace(ns, null, true);
     }
 
-    public void _getAllNamespaces(Map addToThis) {
-        if (!_cur.isContainer())
+    public void _getAllNamespaces(Map<String,String> addToThis) {
+        if (!_cur.isContainer()) {
             throw new IllegalStateException("Not on a container");
+        }
 
-        if (addToThis != null)
+        if (addToThis != null) {
             Locale.getAllNamespaces(_cur, addToThis);
+        }
     }
 
     public XmlObject _getObject() {
@@ -820,7 +842,7 @@ public final class Cursor implements Xml
 
     public boolean _hasNextToken() {
         //return _cur.kind() != -ROOT;
-        return _cur._pos!=Cur.END_POS || _cur._xobj.kind()!=ROOT;
+        return _cur._pos != Cur.END_POS || _cur._xobj.kind() != ROOT;
     }
 
     public boolean _hasPrevToken() {
@@ -828,8 +850,9 @@ public final class Cursor implements Xml
     }
 
     public TokenType _toFirstContentToken() {
-        if (!_cur.isContainer())
+        if (!_cur.isContainer()) {
             return TokenType.NONE;
+        }
 
         _cur.next();
 
@@ -837,8 +860,9 @@ public final class Cursor implements Xml
     }
 
     public TokenType _toEndToken() {
-        if (!_cur.isContainer())
+        if (!_cur.isContainer()) {
             return TokenType.NONE;
+        }
 
         _cur.toEnd();
 
@@ -953,8 +977,9 @@ public final class Cursor implements Xml
     }
 
     public String _getAttributeText(QName attrName) {
-        if (attrName == null)
+        if (attrName == null) {
             throw new IllegalArgumentException("Attr name is null");
+        }
 
         if (!_cur.isContainer()) {
             return null;
@@ -1167,7 +1192,7 @@ public final class Cursor implements Xml
 
     public XmlCursor _execQuery(String query, XmlOptions options) {
         checkThisCursor();
-        return Query.cursorExecQuery(_cur,query,options);
+        return Query.cursorExecQuery(_cur, query, options);
     }
 
 
@@ -1196,7 +1221,7 @@ public final class Cursor implements Xml
 
         _cur.push();
 
-        for (; ;) {
+        for (; ; ) {
             // Move a minimal amount.  If at text, move to a potential bookmark in the text.
 
             if ((cch = _cur.cchRight()) > 1) {
@@ -1222,14 +1247,15 @@ public final class Cursor implements Xml
     }
 
     public XmlBookmark _toPrevBookmark(Object key) {
-        if (key == null)
+        if (key == null) {
             return null;
+        }
 
         int cch;
 
         _cur.push();
 
-        for (; ;) {
+        for (; ; ) {
             // Move a minimal amount.  If at text, move to a potential bookmark in the text.
 
             if ((cch = _cur.cchLeft()) > 1) {
@@ -1316,10 +1342,11 @@ public final class Cursor implements Xml
 
         assert _cur.isText() || _cur.isNode();
 
-        if (_cur.isText())
+        if (_cur.isText()) {
             _cur.moveChars(null, -1);
-        else
+        } else {
             _cur.moveNode(null);
+        }
 
         return true;
     }
@@ -1482,11 +1509,13 @@ public final class Cursor implements Xml
     public int _moveChars(int cch, Cursor to) {
         int cchRight = _cur.cchRight();
 
-        if (cchRight <= 0 || cch == 0)
+        if (cchRight <= 0 || cch == 0) {
             return 0;
+        }
 
-        if (cch < 0 || cch > cchRight)
+        if (cch < 0 || cch > cchRight) {
             cch = cchRight;
+        }
 
         to.checkInsertionValidity(_cur);
 
@@ -1500,11 +1529,13 @@ public final class Cursor implements Xml
     public int _copyChars(int cch, Cursor to) {
         int cchRight = _cur.cchRight();
 
-        if (cchRight <= 0 || cch == 0)
+        if (cchRight <= 0 || cch == 0) {
             return 0;
+        }
 
-        if (cch < 0 || cch > cchRight)
+        if (cch < 0 || cch > cchRight) {
             cch = cchRight;
+        }
 
         to.checkInsertionValidity(_cur);
 
@@ -1521,7 +1552,7 @@ public final class Cursor implements Xml
         if (l > 0) {
             if (_cur.isRoot() || _cur.isAttr()) {
                 throw
-                        new IllegalStateException("Can't insert before the document or an attribute.");
+                    new IllegalStateException("Can't insert before the document or an attribute.");
             }
 
             _cur.insertChars(text, 0, l);
@@ -1641,8 +1672,9 @@ public final class Cursor implements Xml
     public void _insertProcInst(String target, String text) {
         validateLocalName(target);
 
-        if (Locale.beginsWithXml(target) && target.length() == 3)
+        if (Locale.beginsWithXml(target) && target.length() == 3) {
             throw new IllegalArgumentException("Target is 'xml'");
+        }
 
         Cur c = _cur._locale.tempCur();
 
@@ -1666,23 +1698,27 @@ public final class Cursor implements Xml
     //
 
     private void checkThisCursor() {
-        if (_cur == null)
+        if (_cur == null) {
             throw new IllegalStateException("This cursor has been disposed");
+        }
     }
 
     private Cursor checkCursors(XmlCursor xOther) {
         checkThisCursor();
 
-        if (xOther == null)
+        if (xOther == null) {
             throw new IllegalArgumentException("Other cursor is <null>");
+        }
 
-        if (!(xOther instanceof Cursor))
+        if (!(xOther instanceof Cursor)) {
             throw new IllegalArgumentException("Incompatible cursors: " + xOther);
+        }
 
         Cursor other = (Cursor) xOther;
 
-        if (other._cur == null)
+        if (other._cur == null) {
             throw new IllegalStateException("Other cursor has been disposed");
+        }
 
         return other;
     }
@@ -1709,9 +1745,9 @@ public final class Cursor implements Xml
         }
 
         if (locale.noSync()) {
-            if (otherLocale.noSync())
+            if (otherLocale.noSync()) {
                 return twoLocaleOp(other, op, arg);
-            else {
+            } else {
                 synchronized (otherLocale) {
                     return twoLocaleOp(other, op, arg);
                 }
@@ -1739,8 +1775,9 @@ public final class Cursor implements Xml
         } catch (InterruptedException e) {
             throw new RuntimeException(e.getMessage(), e);
         } finally {
-            if (acquired)
+            if (acquired) {
                 GlobalLock.release();
+            }
         }
     }
 
@@ -1765,7 +1802,7 @@ public final class Cursor implements Xml
                 case COPY_CHARS:
                     return _copyChars(arg, other);
 
-                default :
+                default:
                     throw new RuntimeException("Unknown operation: " + op);
             }
         } finally {
@@ -1863,12 +1900,14 @@ public final class Cursor implements Xml
             } finally {
                 l.exit();
             }
-        } else synchronized (l) {
-            l.enter();
-            try {
-                return new Cursor(x, p);
-            } finally {
-                l.exit();
+        } else {
+            synchronized (l) {
+                l.enter();
+                try {
+                    return new Cursor(x, p);
+                } finally {
+                    l.exit();
+                }
             }
         }
     }
@@ -1901,7 +1940,7 @@ public final class Cursor implements Xml
     }
 
     public XMLStreamReader newXMLStreamReader() {
-        return syncWrap((Supplier<XMLStreamReader>)this::_newXMLStreamReader);
+        return syncWrap((Supplier<XMLStreamReader>) this::_newXMLStreamReader);
     }
 
     public XMLStreamReader newXMLStreamReader(XmlOptions options) {
@@ -1912,23 +1951,23 @@ public final class Cursor implements Xml
      * @deprecated XMLInputStream was deprecated by XMLStreamReader from STaX - jsr173 API.
      */
     public XMLInputStream newXMLInputStream() {
-        return syncWrap((Supplier<XMLInputStream>)this::_newXMLInputStream);
+        return syncWrap((Supplier<XMLInputStream>) this::_newXMLInputStream);
     }
 
     public String xmlText() {
-        return syncWrap((Supplier<String>)this::_xmlText);
+        return syncWrap((Supplier<String>) this::_xmlText);
     }
 
     public InputStream newInputStream() {
-        return syncWrap((Supplier<InputStream>)this::_newInputStream);
+        return syncWrap((Supplier<InputStream>) this::_newInputStream);
     }
 
     public Reader newReader() {
-        return syncWrap((Supplier<Reader>)this::_newReader);
+        return syncWrap((Supplier<Reader>) this::_newReader);
     }
 
     public Node newDomNode() {
-        return syncWrap((Supplier<Node>)this::_newDomNode);
+        return syncWrap((Supplier<Node>) this::_newDomNode);
     }
 
     public Node getDomNode() {
@@ -2058,7 +2097,7 @@ public final class Cursor implements Xml
         return syncWrap(() -> _prefixForNamespace(namespaceURI));
     }
 
-    public void getAllNamespaces(Map addToThis) {
+    public void getAllNamespaces(Map<String,String> addToThis) {
         syncWrap(() -> _getAllNamespaces(addToThis));
     }
 
@@ -2166,7 +2205,7 @@ public final class Cursor implements Xml
 
         Xobj parent = _cur.getParentNoRoot();
 
-        if (parent==null) {
+        if (parent == null) {
             _cur._locale.enter();
             try {
                 parent = _cur.getParent();
@@ -2259,7 +2298,7 @@ public final class Cursor implements Xml
     }
 
     public String getTextValue() {
-        return syncWrap((Supplier<String>)this::_getTextValue);
+        return syncWrap((Supplier<String>) this::_getTextValue);
     }
 
     public int getTextValue(char[] chars, int offset, int cch) {
@@ -2275,7 +2314,7 @@ public final class Cursor implements Xml
     }
 
     public String getChars() {
-        return syncWrap((Supplier<String>)this::_getChars);
+        return syncWrap((Supplier<String>) this::_getChars);
     }
 
     public int getChars(char[] chars, int offset, int cch) {

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DomSaver.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DomSaver.java?rev=1881284&r1=1881283&r2=1881284&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DomSaver.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DomSaver.java Fri Aug 28 20:49:50 2020
@@ -22,7 +22,7 @@ import org.apache.xmlbeans.XmlOptions;
 import org.w3c.dom.Node;
 
 import javax.xml.namespace.QName;
-import java.util.ArrayList;
+import java.util.List;
 
 final class DomSaver extends Saver {
     private Cur _nodeCur;
@@ -79,7 +79,8 @@ final class DomSaver extends Saver {
         }
     }
 
-    protected boolean emitElement(SaveCur c, ArrayList attrNames, ArrayList attrValues) {
+    @Override
+    protected boolean emitElement(SaveCur c, List<QName> attrNames, List<String> attrValues) {
         // If there was text or comments before the frag element, I will loose them -- oh well
         // Also, I will lose any attributes and namesapces on the fragment -- DOM can
         // have attrs in fragments



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