@@ -166,6 +166,13 @@ public class RESTServiceTest {
166
166
" <header>{request:get-header('Authorization')}</header>\n " +
167
167
"</authorization>\n " ;
168
168
169
+ private static final String XML_WITH_DOCTYPE =
170
+ "<!DOCTYPE bookmap PUBLIC \" -//OASIS//DTD DITA BookMap//EN\" \" bookmap.dtd\" >\n " +
171
+ "<bookmap id=\" bookmap-1\" />" ;
172
+
173
+ private static final XmldbURI TEST_DOCTYPE_COLLECTION_URI = XmldbURI .ROOT_COLLECTION_URI .append ("rest-test-doctype" );
174
+ private static final XmldbURI TEST_XML_DOC_WITH_DOCTYPE_URI = XmldbURI .create ("test-with-doctype.xml" );
175
+
169
176
private static String credentials ;
170
177
private static String badCredentials ;
171
178
@@ -189,6 +196,10 @@ private static String getResourceUri() {
189
196
return getServerUri () + XmldbURI .ROOT_COLLECTION + "/test/test.xml" ;
190
197
}
191
198
199
+ private static String getResourceWithDocTypeUri () {
200
+ return getServerUri () + TEST_DOCTYPE_COLLECTION_URI .append (TEST_XML_DOC_WITH_DOCTYPE_URI );
201
+ }
202
+
192
203
/* About path components of URIs:
193
204
194
205
** reserved characters # http://tools.ietf.org/html/rfc3986#section-2.2
@@ -266,6 +277,11 @@ public static void setup() throws PermissionDeniedException, IOException, Trigge
266
277
broker .saveCollection (transaction , col );
267
278
}
268
279
280
+ try (final Collection col = broker .getOrCreateCollection (transaction , TEST_DOCTYPE_COLLECTION_URI )) {
281
+ broker .storeDocument (transaction , TEST_XML_DOC_WITH_DOCTYPE_URI , new StringInputSource (XML_WITH_DOCTYPE ), MimeType .XML_TYPE , col );
282
+ broker .saveCollection (transaction , col );
283
+ }
284
+
269
285
transaction .commit ();
270
286
} catch (EXistException | SAXException | LockException e ) {
271
287
throw new RuntimeException (e );
@@ -1206,6 +1222,86 @@ public void doDeleteEncodedPath() throws IOException {
1206
1222
}
1207
1223
}
1208
1224
1225
+ /**
1226
+ * By default there should be NO doctype serialized.
1227
+ */
1228
+ @ Test
1229
+ public void getDocTypeDefault () throws IOException {
1230
+ final HttpURLConnection connect = getConnection (getResourceWithDocTypeUri ());
1231
+ try {
1232
+ connect .setRequestMethod ("GET" );
1233
+ connect .connect ();
1234
+
1235
+ final int r = connect .getResponseCode ();
1236
+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
1237
+ String contentType = connect .getContentType ();
1238
+ final int semicolon = contentType .indexOf (';' );
1239
+ if (semicolon > 0 ) {
1240
+ contentType = contentType .substring (0 , semicolon ).trim ();
1241
+ }
1242
+ assertEquals ("Server returned content type " + contentType , "application/xml" , contentType );
1243
+
1244
+ final String response = readResponse (connect .getInputStream ());
1245
+
1246
+ assertEquals ("<bookmap id=\" bookmap-1\" />\r \n " , response );
1247
+
1248
+ } finally {
1249
+ connect .disconnect ();
1250
+ }
1251
+ }
1252
+
1253
+ @ Test
1254
+ public void getDocTypeNo () throws IOException {
1255
+ final HttpURLConnection connect = getConnection (getResourceWithDocTypeUri () + "?_output-doctype=no" );
1256
+ try {
1257
+ connect .setRequestMethod ("GET" );
1258
+ connect .connect ();
1259
+
1260
+ final int r = connect .getResponseCode ();
1261
+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
1262
+ String contentType = connect .getContentType ();
1263
+ final int semicolon = contentType .indexOf (';' );
1264
+ if (semicolon > 0 ) {
1265
+ contentType = contentType .substring (0 , semicolon ).trim ();
1266
+ }
1267
+ assertEquals ("Server returned content type " + contentType , "application/xml" , contentType );
1268
+
1269
+ final String response = readResponse (connect .getInputStream ());
1270
+
1271
+ assertEquals ("<bookmap id=\" bookmap-1\" />\r \n " , response );
1272
+
1273
+ } finally {
1274
+ connect .disconnect ();
1275
+ }
1276
+ }
1277
+
1278
+ @ Test
1279
+ public void getDocTypeYes () throws IOException {
1280
+ final HttpURLConnection connect = getConnection (getResourceWithDocTypeUri () + "?_output-doctype=yes" );
1281
+ try {
1282
+ connect .setRequestMethod ("GET" );
1283
+ connect .connect ();
1284
+
1285
+ final int r = connect .getResponseCode ();
1286
+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
1287
+ String contentType = connect .getContentType ();
1288
+ final int semicolon = contentType .indexOf (';' );
1289
+ if (semicolon > 0 ) {
1290
+ contentType = contentType .substring (0 , semicolon ).trim ();
1291
+ }
1292
+ assertEquals ("Server returned content type " + contentType , "application/xml" , contentType );
1293
+
1294
+ final String response = readResponse (connect .getInputStream ());
1295
+
1296
+ assertEquals (
1297
+ "<!DOCTYPE bookmap PUBLIC \" -//OASIS//DTD DITA BookMap//EN\" \" bookmap.dtd\" >\r \n " +
1298
+ "<bookmap id=\" bookmap-1\" />\r \n " , response );
1299
+
1300
+ } finally {
1301
+ connect .disconnect ();
1302
+ }
1303
+ }
1304
+
1209
1305
private void chmod (final String resourcePath , final String mode ) throws IOException {
1210
1306
final String uri = getCollectionUri () +"?_query=" + URLEncoder .encode (
1211
1307
"sm:chmod(xs:anyURI('" + resourcePath + "'), '" + mode + "')" ,
0 commit comments