Skip to content

Commit 628652f

Browse files
EXM-49360: Insert the prolog only when schema allows
1 parent 85c3238 commit 628652f

File tree

4 files changed

+72
-21
lines changed

4 files changed

+72
-21
lines changed

src/main/java/com/oxygenxml/prolog/updater/dita/editor/DitaTopicAuthorEditor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,9 @@ private void addProlog(boolean isNewDocument) throws AuthorOperationException {
177177
);
178178

179179
if (prologXpath != null) {
180+
// EXM-49360: Insert only when a valid xpath was found using schema
180181
AuthorPageDocumentUtil.insertFragmentSchemaAware(page, documentController, prologFragment, prologXpath,
181182
AuthorConstants.POSITION_AFTER);
182-
} else {
183-
AuthorPageDocumentUtil.insertFragmentSchemaAware(page, documentController, prologFragment,
184-
ElementXPathUtils.getRootXpath(documentType), AuthorConstants.POSITION_INSIDE_FIRST);
185183
}
186184
}
187185
}

src/main/java/com/oxygenxml/prolog/updater/dita/editor/DitaTopicTextEditor.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,10 @@ private void addProlog(boolean isNewDocument) throws TextOperationException {
119119
ElementXPathUtils.getRootXpath(documentType));
120120

121121
if (xp != null) {
122-
TextPageDocumentUtil.insertXmlFragment(wsTextEditorPage,
122+
// EXM-49360: Insert only when a valid xpath was found using schema
123+
TextPageDocumentUtil.insertXmlFragment(wsTextEditorPage,
123124
prologCreator.getPrologFragment(isNewDocument, documentType), xp,
124125
RelativeInsertPosition.INSERT_LOCATION_AFTER);
125-
} else {
126-
TextPageDocumentUtil.insertXmlFragment(wsTextEditorPage,
127-
prologCreator.getPrologFragment(isNewDocument, documentType), ElementXPathUtils.getRootXpath(documentType),
128-
RelativeInsertPosition.INSERT_LOCATION_AS_FIRST_CHILD);
129126
}
130127
}
131128

src/test/java/com/oxygenxml/prolog/updater/AuthorTestCase.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,31 @@ private static void initializeCatalogs() throws IOException {
8181
*/
8282
protected void testInAuthorMode(String inputXML, boolean isNewDocument, String expectedXML)
8383
throws IOException, SAXException, BadLocationException, ParserConfigurationException, TransformerException {
84-
initializeCatalogs();
84+
String toXML = updateProlog(inputXML, isNewDocument);
85+
86+
String expected = XmlPrettyPrinterUtil.indent(expectedXML).replaceAll(" +", " ");
87+
String actual = XmlPrettyPrinterUtil.indent(toXML).replaceAll(" +", " ");
88+
89+
expected = expected.replaceAll(" <", "<");
90+
actual = actual.replaceAll(" <", "<");
91+
92+
expected = expected.replaceAll("> ", ">");
93+
actual = actual.replaceAll("> ", ">");
94+
95+
assertEquals("The updated content is wrong", expected, actual);
96+
}
97+
98+
/**
99+
* Update the prolog into the given input xml.
100+
*
101+
* @param inputXML The input xml content to update.
102+
* @param isNewDocument <code>true</code> if document is new, <code>false</code> otherwise
103+
*
104+
* @return The updated xml content.
105+
*/
106+
public String updateProlog(String inputXML, boolean isNewDocument)
107+
throws IOException, SAXException, BadLocationException {
108+
initializeCatalogs();
85109

86110
//
87111
// Create a AuthorDocumentController
@@ -133,18 +157,8 @@ protected int getMaxNoOfRevisedElements() {
133157
AuthorDocument documentNode = controller.getAuthorDocumentNode();
134158
AuthorDocumentFragment fragment = controller.createDocumentFragment(documentNode, true);
135159
String toXML = controller.serializeFragmentToXML(fragment);
136-
137-
String expected = XmlPrettyPrinterUtil.indent(expectedXML).replaceAll(" +", " ");
138-
String actual = XmlPrettyPrinterUtil.indent(toXML).replaceAll(" +", " ");
139-
140-
expected = expected.replaceAll(" <", "<");
141-
actual = actual.replaceAll(" <", "<");
142-
143-
expected = expected.replaceAll("> ", ">");
144-
actual = actual.replaceAll("> ", ">");
145-
146-
assertEquals("The updated content is wrong", expected, actual);
147-
}
160+
return toXML;
161+
}
148162

149163
/**
150164
* Get the date format for TCs

src/test/java/com/oxygenxml/prolog/updater/DitaTopicUpdaterAuthorTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,47 @@ public void testSaveTwice() throws Exception {
222222

223223
}
224224

225+
/**
226+
* <p><b>Description:</b>Test that resusable files are not updated.</p>
227+
* <p><b>Bug ID:</b> EXM-49360</p>
228+
*
229+
* @author cosmin_duna
230+
*/
231+
public void testReusableFileAreNotUpdated() throws IOException, SAXException, BadLocationException, ParserConfigurationException, TransformerException {
232+
String xml ="<?xml version='1.0' encoding='UTF-8'?>\n" +
233+
"<!DOCTYPE oXygen:ReusableComponent [\n" +
234+
"<!ELEMENT oXygen:ReusableComponent (oXygen:ComponentDescription, oXygen:ComponentDefinition)>\n" +
235+
"<!ATTLIST oXygen:ReusableComponent \n" +
236+
" xmlns:oXygen CDATA #FIXED \"http://www.oxygenxml.com/ns/dita/reuse\" \n" +
237+
" id CDATA #IMPLIED\n" +
238+
" xml:lang CDATA #IMPLIED\n" +
239+
" domains CDATA \"(topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d) (topic oXygen-reuse-d) \"\n" +
240+
" class CDATA \"- topic/topic oXygen:ReusableComponent/oXygen:ReusableComponent \" \n" +
241+
" xmlns:ditaarch CDATA #FIXED \"http://dita.oasis-open.org/architecture/2005/\"\n" +
242+
" ditaarch:DITAArchVersion CDATA #FIXED \"1.2\" \n" +
243+
" >\n" +
244+
"<!ELEMENT oXygen:ComponentDescription (#PCDATA)>\n" +
245+
"<!ATTLIST oXygen:ComponentDescription \n" +
246+
" class CDATA \"- topic/title oXygen:ReusableComponent/oXygen:ComponentDescription \">\n" +
247+
"<!ELEMENT oXygen:ComponentDefinition ANY>\n" +
248+
"<!ATTLIST oXygen:ComponentDefinition\n" +
249+
" class CDATA \"- topic/body oXygen:ReusableComponent/oXygen:ComponentDefinition \">\n" +
250+
"\n" +
251+
"<!ENTITY % dtd PUBLIC \"-//OASIS//DTD DITA Topic//EN\" \"topic.dtd\">\n" +
252+
"%dtd;\n" +
253+
"\n" +
254+
"]>\n" +
255+
"<oXygen:ReusableComponent id=\"ReusableComponent_ucc_kgx_xrb\">\n" +
256+
" <oXygen:ComponentDescription></oXygen:ComponentDescription>\n" +
257+
" <oXygen:ComponentDefinition>\n" +
258+
" <p id=\"p_wcc_kgx_xrb\">Most of the information was taken from <xref\n" +
259+
" href=\"http://www.wikipedia.com\" format=\"html\" scope=\"external\">Wikipedia</xref>, the\n" +
260+
" free encyclopedia.</p></oXygen:ComponentDefinition>\n" +
261+
"</oXygen:ReusableComponent>\n" +
262+
"";
263+
264+
String contentAfterUpdate = updateProlog(xml, true);
265+
assertFalse(contentAfterUpdate.contains("prolog"));
266+
}
225267

226268
}

0 commit comments

Comments
 (0)