Skip to content

Commit b37c209

Browse files
committed
[bugfix] Java Admin Client should allow you to see and edit a Document's Document Type Declaration if present
1 parent b37e49e commit b37c209

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

exist-core/src/main/java/org/exist/client/InteractiveClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import se.softhouse.jargo.ArgumentException;
8585

8686
import static java.nio.charset.StandardCharsets.UTF_8;
87+
import static org.exist.storage.serializers.EXistOutputKeys.OUTPUT_DOCTYPE;
8788

8889
/**
8990
* Command-line client based on the XML:DB API.
@@ -137,6 +138,7 @@ public class InteractiveClient {
137138
defaultProps.setProperty(USER, USER_DEFAULT);
138139
defaultProps.setProperty(EDITOR, EDIT_CMD);
139140
defaultProps.setProperty(INDENT, "true");
141+
defaultProps.setProperty(OUTPUT_DOCTYPE, "true");
140142
defaultProps.setProperty(ENCODING, ENCODING_DEFAULT.name());
141143
defaultProps.setProperty(COLORS, "false");
142144
defaultProps.setProperty(PERMISSIONS, "false");

exist-core/src/test/java/org/exist/xmldb/SerializationTest.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.exist.Namespaces;
2525
import org.exist.TestUtils;
26+
import org.exist.storage.serializers.EXistOutputKeys;
2627
import org.exist.test.ExistWebServer;
2728
import org.junit.After;
2829
import org.junit.Before;
@@ -77,7 +78,7 @@ private final String getBaseUri() {
7778

7879
private static final String EOL = System.getProperty("line.separator");
7980

80-
private static final String TEST_COLLECTION_NAME = "test";
81+
private static final String TEST_COLLECTION_NAME = "xmlrpc-serialization-test";
8182

8283
private static final String XML_DOC_NAME = "defaultns.xml";
8384
private static final String XML =
@@ -107,6 +108,12 @@ private final String getBaseUri() {
107108
" <entry xmlns=\"\" xml:id=\"aargh\"/>" + EOL +
108109
"</root>";
109110

111+
private static final XmldbURI TEST_XML_DOC_WITH_DOCTYPE_URI = XmldbURI.create("test-with-doctype.xml");
112+
113+
private static final String XML_WITH_DOCTYPE =
114+
"<!DOCTYPE bookmap PUBLIC \"-//OASIS//DTD DITA BookMap//EN\" \"bookmap.dtd\">\n" +
115+
"<bookmap id=\"bookmap-1\"/>";
116+
110117
private Collection testCollection;
111118

112119
@Test
@@ -161,6 +168,40 @@ public void xqueryUpdateNsTest() throws XMLDBException {
161168
assertXMLEquals(XML_UPDATED_EXPECTED, onDiskResource);
162169
}
163170

171+
@Test
172+
public void getDocTypeDefault() throws XMLDBException {
173+
final Resource res = testCollection.getResource(TEST_XML_DOC_WITH_DOCTYPE_URI.lastSegmentString());
174+
assertEquals("<bookmap id=\"bookmap-1\"/>", res.getContent());
175+
}
176+
177+
@Test
178+
public void getDocTypeNo() throws XMLDBException {
179+
final String prevOutputDocType = testCollection.getProperty(EXistOutputKeys.OUTPUT_DOCTYPE);
180+
try {
181+
final Resource res = testCollection.getResource(TEST_XML_DOC_WITH_DOCTYPE_URI.lastSegmentString());
182+
testCollection.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, "NO");
183+
assertEquals("<bookmap id=\"bookmap-1\"/>", res.getContent());
184+
} finally {
185+
if (prevOutputDocType != null) {
186+
testCollection.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, prevOutputDocType);
187+
}
188+
}
189+
}
190+
191+
@Test
192+
public void getDocTypeYes() throws XMLDBException {
193+
final String prevOutputDocType = testCollection.getProperty(EXistOutputKeys.OUTPUT_DOCTYPE);
194+
try {
195+
final Resource res = testCollection.getResource(TEST_XML_DOC_WITH_DOCTYPE_URI.lastSegmentString());
196+
testCollection.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, "yes");
197+
assertEquals(XML_WITH_DOCTYPE, res.getContent());
198+
} finally {
199+
if (prevOutputDocType != null) {
200+
testCollection.setProperty(EXistOutputKeys.OUTPUT_DOCTYPE, prevOutputDocType);
201+
}
202+
}
203+
}
204+
164205
private static void assertXMLEquals(final String expected, final Resource actual) throws XMLDBException {
165206
final Source srcExpected = Input.fromString(expected).build();
166207
final Source srcActual = Input.fromString(actual.getContent().toString()).build();
@@ -182,6 +223,10 @@ public void setUp() throws XMLDBException {
182223
final XMLResource res = (XMLResource) testCollection.createResource(XML_DOC_NAME, "XMLResource");
183224
res.setContent(XML);
184225
testCollection.storeResource(res);
226+
227+
final XMLResource res1 = (XMLResource) testCollection.createResource(TEST_XML_DOC_WITH_DOCTYPE_URI.lastSegmentString(), "XMLResource");
228+
res1.setContent(XML_WITH_DOCTYPE);
229+
testCollection.storeResource(res1);
185230
}
186231

187232
@After

exist-distribution/src/main/config/client.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ expand-xincludes=yes
4848
## highlight matches in element and attribute values?
4949
## possible values are "none", "both", "elements", "attributes"
5050
highlight-matches=none
51+
52+
## output the doctype of documents
53+
output-doctype=yes

0 commit comments

Comments
 (0)