Skip to content

Commit 40ab663

Browse files
committed
[bugfix] Defaults should be omit-xml-declaration=no omit-original-xml-declaration=true
1 parent 0a287d0 commit 40ab663

File tree

13 files changed

+64
-89
lines changed

13 files changed

+64
-89
lines changed

exist-core/src/main/java/org/exist/http/RESTServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class RESTServer {
129129

130130
static {
131131
defaultOutputKeysProperties.setProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "no");
132-
defaultOutputKeysProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
132+
defaultOutputKeysProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
133133
defaultOutputKeysProperties.setProperty(OutputKeys.INDENT, "yes");
134134
defaultOutputKeysProperties.setProperty(OutputKeys.MEDIA_TYPE,
135135
MimeType.XML_TYPE.getName());
@@ -365,7 +365,7 @@ public void doGet(final DBBroker broker, final Txn transaction, final HttpServle
365365
outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, option);
366366
} else {
367367
// set omit-xml-declaration by configuration
368-
final String omitXmlDeclaration = broker.getConfiguration().getProperty(Serializer.PROPERTY_OMIT_XML_DECLARATION, "no");
368+
final String omitXmlDeclaration = broker.getConfiguration().getProperty(Serializer.PROPERTY_OMIT_XML_DECLARATION, "yes");
369369
outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration);
370370
}
371371
if ((option = getParameter(request, Omit_Original_Xml_Declaration)) != null) {

exist-core/src/main/java/org/exist/util/serializer/AbstractSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public abstract class AbstractSerializer {
6363

6464
static {
6565
defaultProperties.setProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "no");
66-
defaultProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
66+
defaultProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
6767
defaultProperties.setProperty(EXistOutputKeys.XDM_SERIALIZATION, "no");
6868
}
6969

exist-core/src/main/java/org/exist/util/serializer/MicroXmlWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package org.exist.util.serializer;
2323

2424
import org.exist.dom.QName;
25+
import org.exist.storage.serializers.EXistOutputKeys;
2526

2627
import javax.xml.XMLConstants;
2728
import javax.xml.transform.OutputKeys;
@@ -168,7 +169,8 @@ public void characters(final char[] ch, final int start, final int len) throws T
168169

169170
@Override
170171
public void setOutputProperties(final Properties properties) {
172+
properties.setProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "yes");
171173
properties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
172-
super.setOutputProperties(properties); //To change body of overridden methods use File | Settings | File Templates.
174+
super.setOutputProperties(properties);
173175
}
174176
}

exist-core/src/main/java/org/exist/util/serializer/XMLWriter.java

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class XMLWriter implements SerializerWriter {
4949
protected final static Properties defaultProperties = new Properties();
5050
static {
5151
defaultProperties.setProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "no");
52-
defaultProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
52+
defaultProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
5353
defaultProperties.setProperty(EXistOutputKeys.XDM_SERIALIZATION, "no");
5454
}
5555

@@ -536,42 +536,44 @@ protected void writeDeclaration() throws TransformerException {
536536
}
537537
declarationWritten = true;
538538

539-
final String omitXmlDecl = outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
540-
if ("no".equals(omitXmlDecl)) {
539+
final String omitOriginalXmlDecl = outputProperties.getProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "yes");
540+
if (originalXmlDecl != null && "no".equals(omitOriginalXmlDecl)) {
541+
// get the fields of the persisted xml declaration, but overridden with any properties from the serialization properties
542+
final String version = outputProperties.getProperty(OutputKeys.VERSION, (originalXmlDecl.version != null ? originalXmlDecl.version : DEFAULT_XML_VERSION));
543+
final String encoding = outputProperties.getProperty(OutputKeys.ENCODING, (originalXmlDecl.encoding != null ? originalXmlDecl.encoding : DEFAULT_XML_ENCODING));
544+
@Nullable final String standalone = outputProperties.getProperty(OutputKeys.STANDALONE, originalXmlDecl.standalone);
541545

542-
final String version;
543-
final String encoding;
544-
@Nullable final String standalone;
546+
writeDeclaration(version, encoding, standalone);
545547

546-
final String omitOriginalXmlDecl = outputProperties.getProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "yes");
547-
if (originalXmlDecl != null && "no".equals(omitOriginalXmlDecl)) {
548-
// get the fields of the persisted xml declaration, but overridden with any properties from the serialization properties
549-
version = outputProperties.getProperty(OutputKeys.VERSION, (originalXmlDecl.version != null ? originalXmlDecl.version : DEFAULT_XML_VERSION));
550-
encoding = outputProperties.getProperty(OutputKeys.ENCODING, (originalXmlDecl.encoding != null ? originalXmlDecl.encoding : DEFAULT_XML_ENCODING));
551-
standalone = outputProperties.getProperty(OutputKeys.STANDALONE, originalXmlDecl.standalone);
548+
return;
549+
}
552550

553-
} else {
554-
// get the fields of the declaration from the serialization properties
555-
version = outputProperties.getProperty(OutputKeys.VERSION, DEFAULT_XML_VERSION);
556-
encoding = outputProperties.getProperty(OutputKeys.ENCODING, DEFAULT_XML_ENCODING);
557-
standalone = outputProperties.getProperty(OutputKeys.STANDALONE);
558-
}
551+
final String omitXmlDecl = outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
552+
if ("no".equals(omitXmlDecl)) {
553+
// get the fields of the declaration from the serialization properties
554+
final String version = outputProperties.getProperty(OutputKeys.VERSION, DEFAULT_XML_VERSION);
555+
final String encoding = outputProperties.getProperty(OutputKeys.ENCODING, DEFAULT_XML_ENCODING);
556+
@Nullable final String standalone = outputProperties.getProperty(OutputKeys.STANDALONE);
559557

560-
try {
561-
writer.write("<?xml version=\"");
562-
writer.write(version);
563-
writer.write("\" encoding=\"");
564-
writer.write(encoding);
558+
writeDeclaration(version, encoding, standalone);
559+
}
560+
}
561+
562+
private void writeDeclaration(final String version, final String encoding, @Nullable final String standalone) throws TransformerException {
563+
try {
564+
writer.write("<?xml version=\"");
565+
writer.write(version);
566+
writer.write("\" encoding=\"");
567+
writer.write(encoding);
568+
writer.write('"');
569+
if(standalone != null) {
570+
writer.write(" standalone=\"");
571+
writer.write(standalone);
565572
writer.write('"');
566-
if(standalone != null) {
567-
writer.write(" standalone=\"");
568-
writer.write(standalone);
569-
writer.write('"');
570-
}
571-
writer.write("?>\n");
572-
} catch(final IOException ioe) {
573-
throw new TransformerException(ioe.getMessage(), ioe);
574573
}
574+
writer.write("?>\n");
575+
} catch(final IOException ioe) {
576+
throw new TransformerException(ioe.getMessage(), ioe);
575577
}
576578
}
577579

exist-core/src/main/java/org/exist/xmldb/LocalCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class LocalCollection extends AbstractLocal implements EXistCollection {
9494
defaultProperties.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes");
9595
defaultProperties.setProperty(EXistOutputKeys.PROCESS_XSL_PI, "no");
9696
defaultProperties.setProperty(NORMALIZE_HTML, "no");
97-
defaultProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
97+
defaultProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
9898
defaultProperties.setProperty(EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION, "no");
9999
defaultProperties.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, "yes");
100100
}

exist-core/src/main/java/org/exist/xmlrpc/RpcConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ private String getDocumentAsString(final XmldbURI docUri, final Map<String, Obje
664664

665665
private void serialize(final DBBroker broker, final Properties properties, final ConsumerE<Serializer, SAXException> toSaxFunction, final Writer writer) throws SAXException, IOException {
666666
if (!properties.containsKey(OutputKeys.OMIT_XML_DECLARATION)) {
667-
final String omitXmlDeclaration = broker.getConfiguration().getProperty(Serializer.OMIT_XML_DECLARATION_ATTRIBUTE, "no");
667+
final String omitXmlDeclaration = broker.getConfiguration().getProperty(Serializer.OMIT_XML_DECLARATION_ATTRIBUTE, "yes");
668668
properties.setProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration);
669669
}
670670

exist-core/src/test/java/org/exist/http/RESTServiceTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private static String getResourceUri() {
234234
}
235235

236236
private static String getResourceWithDocTypeUri() {
237-
return getServerUri() + TEST_DOCTYPE_COLLECTION_URI.append(TEST_XML_DOC_WITH_DOCTYPE_URI) + "?_omit-xml-declaration=yes";
237+
return getServerUri() + TEST_DOCTYPE_COLLECTION_URI.append(TEST_XML_DOC_WITH_DOCTYPE_URI);
238238
}
239239

240240
private static String getResourceWithXmlDeclUri() {
@@ -757,7 +757,7 @@ public void requestGetParameterFromModule() throws IOException {
757757

758758
/* execute the stored xquery a few times */
759759
for (int i = 0; i < 5; i++) {
760-
final HttpURLConnection connect = getConnection(getCollectionUri() + "/requestparameter.xql?doc=somedoc" + i + "&_omit-xml-declaration=yes");
760+
final HttpURLConnection connect = getConnection(getCollectionUri() + "/requestparameter.xql?doc=somedoc" + i);
761761
try {
762762
connect.setRequestProperty("Authorization", "Basic " + credentials);
763763
connect.setRequestMethod("GET");
@@ -831,7 +831,7 @@ public void execGuestQueryWithNoAuth() throws IOException {
831831
chmod(XmldbURI.ROOT_COLLECTION + "/test/auth.xq", "rwxrw-r-x");
832832

833833
// call the auth.xq
834-
final String uri = getCollectionUri() + "/auth.xq?_omit-xml-declaration=yes";
834+
final String uri = getCollectionUri() + "/auth.xq";
835835
final HttpURLConnection connect = getConnection(uri);
836836
try {
837837
connect.setRequestMethod("GET");
@@ -876,7 +876,7 @@ public void execQueryWithBasicAuth() throws IOException {
876876
chmod(XmldbURI.ROOT_COLLECTION + "/test/auth.xq", "rwxrw-r--");
877877

878878
// call the auth.xq
879-
final String uri = getCollectionUri() + "/auth.xq?_omit-xml-declaration=yes";
879+
final String uri = getCollectionUri() + "/auth.xq";
880880
final HttpURLConnection connect = getConnection(uri);
881881
try {
882882
connect.setRequestProperty("Authorization", "Basic " + credentials);
@@ -922,7 +922,7 @@ public void execQueryWithBasicAuthCaseInsensitive() throws IOException {
922922
chmod(XmldbURI.ROOT_COLLECTION + "/test/auth.xq", "rwxrw-r--");
923923

924924
// call the auth.xq
925-
final String uri = getCollectionUri() + "/auth.xq?_omit-xml-declaration=yes";
925+
final String uri = getCollectionUri() + "/auth.xq";
926926
final HttpURLConnection connect = getConnection(uri);
927927
try {
928928
connect.setRequestProperty("Authorization", "bAsiC " + credentials); // NOTE(AR): Intentional use of 'bAsiC' to test case-insensitive scheme matching
@@ -968,7 +968,7 @@ public void execSetUidQueryWithNoAuth() throws IOException {
968968
chmod(XmldbURI.ROOT_COLLECTION + "/test/auth.xq", "rwsr--r-x");
969969

970970
// call the auth.xq
971-
final String uri = getCollectionUri() + "/auth.xq?_omit-xml-declaration=yes";
971+
final String uri = getCollectionUri() + "/auth.xq";
972972
final HttpURLConnection connect = getConnection(uri);
973973
try {
974974
connect.setRequestMethod("GET");
@@ -1019,7 +1019,7 @@ public void execSetUidQueryWithBasicAuth() throws IOException {
10191019
chmod(XmldbURI.ROOT_COLLECTION + "/test/auth.xq", "rwsr--r-x");
10201020

10211021
// call the auth.xq
1022-
final String uri = getCollectionUri() + "/auth.xq?_omit-xml-declaration=yes";
1022+
final String uri = getCollectionUri() + "/auth.xq";
10231023
final HttpURLConnection connect = getConnection(uri);
10241024
try {
10251025
connect.setRequestMethod("GET");
@@ -1088,7 +1088,7 @@ public void execSetUidQueryWithBearerAuth() throws IOException {
10881088
chmod(XmldbURI.ROOT_COLLECTION + "/test/auth.xq", "rwsr--r-x");
10891089

10901090
// call the auth.xq
1091-
final String uri = getCollectionUri() + "/auth.xq?_omit-xml-declaration=yes";
1091+
final String uri = getCollectionUri() + "/auth.xq";
10921092
final HttpURLConnection connect = getConnection(uri);
10931093
try {
10941094
connect.setRequestMethod("GET");
@@ -1136,7 +1136,7 @@ public void execSetUidQueryWithBearerAuth() throws IOException {
11361136
// all the tests with EncodedPath in function declaration aim to test rest server ability to handle special characters
11371137
@Test
11381138
public void doGetEncodedPath() throws IOException {
1139-
String DOC_URI = getServerUri() + XmldbURI.ROOT_COLLECTION + "/AéB/AéB.xml?_omit-xml-declaration=yes";
1139+
String DOC_URI = getServerUri() + XmldbURI.ROOT_COLLECTION + "/AéB/AéB.xml";
11401140
final HttpURLConnection connect = getConnection(DOC_URI);
11411141
try {
11421142
connect.setRequestMethod("GET");
@@ -1177,7 +1177,7 @@ public void doHeadEncodedPath() throws IOException {
11771177

11781178
@Test
11791179
public void doPutEncodedPath() throws IOException {
1180-
String DOC_URI = getServerUri() + XmldbURI.ROOT_COLLECTION + "/AéB/AéB.xml?_omit-xml-declaration=yes";
1180+
String DOC_URI = getServerUri() + XmldbURI.ROOT_COLLECTION + "/AéB/AéB.xml";
11811181
final HttpURLConnection connect = getConnection(DOC_URI);
11821182
final HttpURLConnection getConnect = getConnection(DOC_URI);
11831183
String data = "<foobar/>";
@@ -1305,7 +1305,7 @@ public void getDocTypeDefault() throws IOException {
13051305

13061306
@Test
13071307
public void getDocTypeNo() throws IOException {
1308-
final HttpURLConnection connect = getConnection(getResourceWithDocTypeUri() + "&_output-doctype=no");
1308+
final HttpURLConnection connect = getConnection(getResourceWithDocTypeUri() + "?_output-doctype=no");
13091309
try {
13101310
connect.setRequestMethod("GET");
13111311
connect.connect();
@@ -1330,7 +1330,7 @@ public void getDocTypeNo() throws IOException {
13301330

13311331
@Test
13321332
public void getDocTypeYes() throws IOException {
1333-
final HttpURLConnection connect = getConnection(getResourceWithDocTypeUri() + "&_output-doctype=yes");
1333+
final HttpURLConnection connect = getConnection(getResourceWithDocTypeUri() + "?_output-doctype=yes");
13341334
try {
13351335
connect.setRequestMethod("GET");
13361336
connect.connect();
@@ -1429,7 +1429,7 @@ public void getXmlDeclDefault() throws IOException {
14291429

14301430
@Test
14311431
public void getXmlDeclNo() throws IOException {
1432-
final HttpURLConnection connect = getConnection(getResourceWithXmlDeclUri() + "?_omit-xml-declaration=no&_omit-original-xml-declaration=no");
1432+
final HttpURLConnection connect = getConnection(getResourceWithXmlDeclUri() + "?_omit-original-xml-declaration=no");
14331433
try {
14341434
connect.setRequestMethod("GET");
14351435
connect.connect();
@@ -1455,7 +1455,7 @@ public void getXmlDeclNo() throws IOException {
14551455

14561456
@Test
14571457
public void getXmlDeclYes() throws IOException {
1458-
final HttpURLConnection connect = getConnection(getResourceWithXmlDeclUri() + "?_omit-xml-declaration=yes&_omit-original-xml-declaration=yes");
1458+
final HttpURLConnection connect = getConnection(getResourceWithXmlDeclUri() + "?_omit-original-xml-declaration=yes");
14591459
try {
14601460
connect.setRequestMethod("GET");
14611461
connect.connect();
@@ -1516,7 +1516,7 @@ private void doPut(final String data, final String path, final int responseCode)
15161516

15171517
private void doStoredQuery(final boolean cacheHeader, final boolean wrap) throws IOException {
15181518

1519-
String uri = getCollectionUri() + "/test.xq?p=Hello&&_omit-xml-declaration=yes";
1519+
String uri = getCollectionUri() + "/test.xq?p=Hello";
15201520
if(wrap) {
15211521
uri += "&_wrap=yes";
15221522
}

0 commit comments

Comments
 (0)