@@ -120,7 +120,6 @@ public class RESTServer {
120
120
121
121
static {
122
122
defaultProperties .setProperty (OutputKeys .INDENT , "yes" );
123
- defaultProperties .setProperty (OutputKeys .ENCODING , UTF_8 .name ());
124
123
defaultProperties .setProperty (OutputKeys .MEDIA_TYPE , MimeType .XML_TYPE .getName ());
125
124
defaultProperties .setProperty (EXistOutputKeys .EXPAND_XINCLUDES , "yes" );
126
125
defaultProperties .setProperty (EXistOutputKeys .HIGHLIGHT_MATCHES , "elements" );
@@ -129,8 +128,9 @@ public class RESTServer {
129
128
public final static Properties defaultOutputKeysProperties = new Properties ();
130
129
131
130
static {
131
+ defaultOutputKeysProperties .setProperty (EXistOutputKeys .OMIT_ORIGINAL_XML_DECLARATION , "no" );
132
+ defaultOutputKeysProperties .setProperty (OutputKeys .OMIT_XML_DECLARATION , "no" );
132
133
defaultOutputKeysProperties .setProperty (OutputKeys .INDENT , "yes" );
133
- defaultOutputKeysProperties .setProperty (OutputKeys .ENCODING , UTF_8 .name ());
134
134
defaultOutputKeysProperties .setProperty (OutputKeys .MEDIA_TYPE ,
135
135
MimeType .XML_TYPE .getName ());
136
136
}
@@ -141,6 +141,9 @@ public class RESTServer {
141
141
+ "h1 { color: #C0C0C0; }" + ".path {" + " padding-bottom: 10px;"
142
142
+ "}" + ".high { " + " color: #666699; " + " font-weight: bold;"
143
143
+ "}" + "</style>" + "</head>" + "<body>" + "<h1>XQuery Error</h1>" ;
144
+
145
+ private static final String DEFAULT_ENCODING = UTF_8 .name ();
146
+
144
147
private final String formEncoding ; // TODO: we may be able to remove this
145
148
// eventually, in favour of
146
149
// HttpServletRequestWrapper being setup in
@@ -315,7 +318,7 @@ public void doGet(final DBBroker broker, final Txn transaction, final HttpServle
315
318
}
316
319
} catch (final SAXException e ) {
317
320
final XPathException x = new XPathException (variables != null ? variables .getExpression () : null , e .toString ());
318
- writeXPathException (response , HttpServletResponse .SC_BAD_REQUEST , UTF_8 . name () , query , path , x );
321
+ writeXPathException (response , HttpServletResponse .SC_BAD_REQUEST , DEFAULT_ENCODING , query , path , x );
319
322
}
320
323
321
324
if ((option = getParameter (request , HowMany )) != null ) {
@@ -381,7 +384,7 @@ public void doGet(final DBBroker broker, final Txn transaction, final HttpServle
381
384
if ((encoding = getParameter (request , Encoding )) != null ) {
382
385
outputProperties .setProperty (OutputKeys .ENCODING , encoding );
383
386
} else {
384
- encoding = UTF_8 . name () ;
387
+ encoding = DEFAULT_ENCODING ;
385
388
}
386
389
387
390
final String mimeType = outputProperties .getProperty (OutputKeys .MEDIA_TYPE );
@@ -567,7 +570,7 @@ public void doHead(final DBBroker broker, final Txn transaction, final HttpServl
567
570
if ((encoding = getParameter (request , Encoding )) != null ) {
568
571
outputProperties .setProperty (OutputKeys .ENCODING , encoding );
569
572
} else {
570
- encoding = UTF_8 . name () ;
573
+ encoding = DEFAULT_ENCODING ;
571
574
}
572
575
573
576
try (final LockedDocument lockedDocument = broker .getXMLResource (pathUri , LockMode .READ_LOCK )) {
@@ -638,7 +641,7 @@ public void doPost(final DBBroker broker, final Txn transaction, final HttpServl
638
641
LockedDocument lockedDocument = null ;
639
642
DocumentImpl resource = null ;
640
643
641
- final String encoding = outputProperties . getProperty ( OutputKeys . ENCODING );
644
+ final String encoding = getEncoding ( outputProperties );
642
645
String mimeType = outputProperties .getProperty (OutputKeys .MEDIA_TYPE );
643
646
try {
644
647
// check if path leads to an XQuery resource.
@@ -1244,7 +1247,7 @@ private boolean checkForXQueryTarget(final DBBroker broker, final Txn transactio
1244
1247
executeXQuery (broker , transaction , resource , request , response ,
1245
1248
outputProperties , servletPath .toString (), pathInfo );
1246
1249
} catch (final XPathException e ) {
1247
- writeXPathExceptionHtml (response , HttpServletResponse .SC_BAD_REQUEST , UTF_8 . name () , null , path .toString (), e );
1250
+ writeXPathExceptionHtml (response , HttpServletResponse .SC_BAD_REQUEST , DEFAULT_ENCODING , null , path .toString (), e );
1248
1251
} finally {
1249
1252
lockedDocument .close ();
1250
1253
}
@@ -1255,7 +1258,7 @@ private String getRequestContent(final HttpServletRequest request) throws IOExce
1255
1258
1256
1259
String encoding = request .getCharacterEncoding ();
1257
1260
if (encoding == null ) {
1258
- encoding = UTF_8 . name () ;
1261
+ encoding = DEFAULT_ENCODING ;
1259
1262
}
1260
1263
1261
1264
final InputStream is = request .getInputStream ();
@@ -2119,6 +2122,10 @@ protected void writeResults(final HttpServletResponse response, final DBBroker b
2119
2122
2120
2123
}
2121
2124
2125
+ private static String getEncoding (final Properties outputProperties ) {
2126
+ return outputProperties .getProperty (OutputKeys .ENCODING , DEFAULT_ENCODING );
2127
+ }
2128
+
2122
2129
private void writeResultXML (final HttpServletResponse response ,
2123
2130
final DBBroker broker , final Sequence results , final int howmany ,
2124
2131
final int start , final boolean typed , final Properties outputProperties ,
@@ -2129,7 +2136,7 @@ private void writeResultXML(final HttpServletResponse response,
2129
2136
try {
2130
2137
2131
2138
// set output headers
2132
- final String encoding = outputProperties . getProperty ( OutputKeys . ENCODING );
2139
+ final String encoding = getEncoding ( outputProperties );
2133
2140
if (!response .containsHeader ("Content-Type" )) {
2134
2141
String mimeType = outputProperties .getProperty (OutputKeys .MEDIA_TYPE );
2135
2142
if (mimeType != null ) {
@@ -2189,7 +2196,7 @@ private void writeResultJSON(final HttpServletResponse response,
2189
2196
outputProperties .setProperty (Serializer .GENERATE_DOC_EVENTS , "false" );
2190
2197
try {
2191
2198
serializer .setProperties (outputProperties );
2192
- try (Writer writer = new OutputStreamWriter (response .getOutputStream (), outputProperties . getProperty ( OutputKeys . ENCODING ))) {
2199
+ try (Writer writer = new OutputStreamWriter (response .getOutputStream (), getEncoding ( outputProperties ))) {
2193
2200
final JSONObject root = new JSONObject ();
2194
2201
root .addObject (new JSONSimpleProperty ("start" , Integer .toString (start ), true ));
2195
2202
root .addObject (new JSONSimpleProperty ("count" , Integer .toString (howmany ), true ));
0 commit comments