[XMLBEANS-548] support adding standalone flag to xml declaration
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1869600 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/store/org/apache/xmlbeans/impl/store/Saver.java b/src/store/org/apache/xmlbeans/impl/store/Saver.java
index 2f289b2..49f7498 100755
--- a/src/store/org/apache/xmlbeans/impl/store/Saver.java
+++ b/src/store/org/apache/xmlbeans/impl/store/Saver.java
@@ -913,7 +913,7 @@
Boolean standalone = null;
if (props != null && props.get(XmlDocumentProperties.STANDALONE) != null)
- standalone = Boolean.valueOf("yes".equals(props.get(XmlDocumentProperties.STANDALONE)));
+ standalone = props.getStandalone();
emit("<?xml version=\"");
emit(version);
diff --git a/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java b/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
index f61fad5..7de0aba 100644
--- a/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
+++ b/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
@@ -79,7 +79,10 @@
/**
* Returns the standalone property
*/
- public boolean getStandalone ( ) { return get( STANDALONE ) != null; }
+ public boolean getStandalone ( ) {
+ Object flag = get( STANDALONE );
+ return flag != null && flag.toString().equalsIgnoreCase("true");
+ }
/**
* Sets the DOCTYPE name use in the <!DOCTYPE> declaration.
diff --git a/test/src/misc/checkin/XmlDocumentPropertiesTest.java b/test/src/misc/checkin/XmlDocumentPropertiesTest.java
new file mode 100644
index 0000000..1aa370c
--- /dev/null
+++ b/test/src/misc/checkin/XmlDocumentPropertiesTest.java
@@ -0,0 +1,54 @@
+/* Copyright 2019 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package misc.checkin;
+
+import java.util.HashMap;
+
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlDocumentProperties;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class XmlDocumentPropertiesTest {
+
+ @Test
+ public void testSetStandalone() {
+ XmlDocumentProperties props = new XmlDocumentProperties() {
+ HashMap<Object, Object> props = new HashMap<>();
+ @Override
+ public Object put ( Object key, Object value ) {
+ return props.put(key, value);
+ }
+
+ @Override
+ public Object get ( Object key ) {
+ return props.get(key);
+ }
+
+ @Override
+ public Object remove ( Object key ) {
+ return props.remove(key);
+ }
+ };
+ assertFalse(props.getStandalone());
+ props.setStandalone(true);
+ assertTrue(props.getStandalone());
+ props.setStandalone(false);
+ assertFalse(props.getStandalone());
+ }
+
+}