From ca4f1da93d3d3558174f4c6ea7239ef65801c367 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Tue, 21 Feb 2017 13:54:21 +0100 Subject: [PATCH] OO-2573: better clean up p namespaces, replace <p/> with <p></p> --- .../org/olat/core/util/openxml/OpenXMLDocument.java | 13 +++++++++++++ .../ims/qti21/model/xml/AssessmentHtmlBuilder.java | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java b/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java index d4cf066313d..c2e754eab53 100644 --- a/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java +++ b/src/main/java/org/olat/core/util/openxml/OpenXMLDocument.java @@ -406,6 +406,7 @@ public class OpenXMLDocument { public void appendHtmlText(String html, Spacing spacing) { if(!StringHelper.containsNonWhitespace(html)) return; try { + html = cleanUpHTML(html); SAXParser parser = new SAXParser(); parser.setContentHandler(new HTMLToOpenXMLHandler(this, spacing)); parser.parse(new InputSource(new StringReader(html))); @@ -419,6 +420,7 @@ public class OpenXMLDocument { public void appendHtmlText(String html, boolean newParagraph) { if(!StringHelper.containsNonWhitespace(html)) return; try { + html = cleanUpHTML(html); SAXParser parser = new SAXParser(); Element paragraphEl = getParagraphToAppendTo(newParagraph); parser.setContentHandler(new HTMLToOpenXMLHandler(this, paragraphEl)); @@ -433,6 +435,7 @@ public class OpenXMLDocument { public void appendHtmlText(String html, boolean newParagraph, HTMLToOpenXMLHandler handler) { if(!StringHelper.containsNonWhitespace(html)) return; try { + html = cleanUpHTML(html); SAXParser parser = new SAXParser(); Element paragraphEl = getParagraphToAppendTo(newParagraph); handler.setInitialParagraph(paragraphEl); @@ -445,6 +448,16 @@ public class OpenXMLDocument { } } + /** + * The Neko HTMl parser has some issues with <p/>. + * + * @param html The HTML to clean up + * @return HTML code which Neko understands + */ + private String cleanUpHTML(String html) { + return html.replace("<p/>", "<p></p>"); + } + public Node appendTable(Integer... width) { Element tableEl = createTable(width); return getCursor().appendChild(tableEl); diff --git a/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java b/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java index 8050498787b..e05c47167a0 100644 --- a/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java +++ b/src/main/java/org/olat/ims/qti21/model/xml/AssessmentHtmlBuilder.java @@ -101,8 +101,11 @@ public class AssessmentHtmlBuilder { private String cleanUpNamespaces(StringOutput sb) { String content = sb.toString(); + content = content.replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); content = content.replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); + content = content.replace("\n xmlns=\"http://www.imsglobal.org/xsd/imsqti_v2p1\"", ""); content = content.replace("xmlns=\"http://www.imsglobal.org/xsd/imsqti_v2p1\"", ""); + content = content.replace("\n xsi:schemaLocation=\"http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/imsqti_v2p1.xsd\"", ""); content = content.replace("xsi:schemaLocation=\"http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/imsqti_v2p1.xsd\"", ""); return content.trim(); } -- GitLab