Skip to content
Snippets Groups Projects
Commit 9a2e5dfd authored by srosse's avatar srosse
Browse files

OO-3021: open a new paragraph for DIV and for QTI 2.1 trim the text buffer...

OO-3021: open a new paragraph for DIV and for QTI 2.1 trim the text buffer before P and DIV to remove special blank characters
parent d7bbf662
No related branches found
No related tags found
No related merge requests found
...@@ -167,6 +167,17 @@ public class HTMLToOpenXMLHandler extends DefaultHandler { ...@@ -167,6 +167,17 @@ public class HTMLToOpenXMLHandler extends DefaultHandler {
return null; return null;
} }
protected void trimTextBuffer() {
if(textBuffer == null) return;
String text = textBuffer.toString().trim();
if(text.length() == 0) {
textBuffer = null;
} else {
textBuffer = new StringBuilder(text);
}
}
protected void flushText() { protected void flushText() {
if(textBuffer == null) return; if(textBuffer == null) return;
...@@ -403,7 +414,7 @@ public class HTMLToOpenXMLHandler extends DefaultHandler { ...@@ -403,7 +414,7 @@ public class HTMLToOpenXMLHandler extends DefaultHandler {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) { public void startElement(String uri, String localName, String qName, Attributes attributes) {
String tag = localName.toLowerCase(); String tag = localName.toLowerCase();
if("p".equalsIgnoreCase(tag)) { if("p".equals(tag)) {
getCurrentParagraph(pNeedNewParagraph); getCurrentParagraph(pNeedNewParagraph);
} else if("span".equalsIgnoreCase(tag)) { } else if("span".equalsIgnoreCase(tag)) {
flushText(); flushText();
...@@ -419,18 +430,18 @@ public class HTMLToOpenXMLHandler extends DefaultHandler { ...@@ -419,18 +430,18 @@ public class HTMLToOpenXMLHandler extends DefaultHandler {
styleStack.add(new StyleStatus(tag, styles)); styleStack.add(new StyleStatus(tag, styles));
} else if("br".equals(tag)) { } else if("br".equals(tag)) {
closeParagraph(); closeParagraph();
} else if("em".equalsIgnoreCase(tag)) { } else if("em".equals(tag)) {
flushText(); flushText();
Style[] styles = setTextPreferences(Style.italic); Style[] styles = setTextPreferences(Style.italic);
styleStack.add(new StyleStatus(tag, styles)); styleStack.add(new StyleStatus(tag, styles));
} else if("strong".equalsIgnoreCase(tag)) { } else if("strong".equals(tag)) {
flushText(); flushText();
Style[] styles = setTextPreferences(Style.bold); Style[] styles = setTextPreferences(Style.bold);
styleStack.add(new StyleStatus(tag, styles)); styleStack.add(new StyleStatus(tag, styles));
} else if("img".equals(tag)) { } else if("img".equals(tag)) {
String path = attributes.getValue("src"); String path = attributes.getValue("src");
setImage(path); setImage(path);
} else if("table".equalsIgnoreCase(tag)) { } else if("table".equals(tag)) {
startTable(); startTable();
} else if("tr".equals(tag)) { } else if("tr".equals(tag)) {
startCurrentTableRow(); startCurrentTableRow();
...@@ -456,9 +467,11 @@ public class HTMLToOpenXMLHandler extends DefaultHandler { ...@@ -456,9 +467,11 @@ public class HTMLToOpenXMLHandler extends DefaultHandler {
appendParagraph(new Spacing(120, 0)); appendParagraph(new Spacing(120, 0));
pNeedNewParagraph = false; pNeedNewParagraph = false;
} else { } else {
getCurrentParagraph(pNeedNewParagraph);
styleStack.add(new StyleStatus(tag, new Style[0])); styleStack.add(new StyleStatus(tag, new Style[0]));
} }
} else { } else {
getCurrentParagraph(pNeedNewParagraph);
styleStack.add(new StyleStatus(tag, new Style[0])); styleStack.add(new StyleStatus(tag, new Style[0]));
} }
} }
...@@ -506,6 +519,7 @@ public class HTMLToOpenXMLHandler extends DefaultHandler { ...@@ -506,6 +519,7 @@ public class HTMLToOpenXMLHandler extends DefaultHandler {
popStyle(tag); popStyle(tag);
} else if("div".equals(tag)) { } else if("div".equals(tag)) {
popStyle(tag); popStyle(tag);
closeParagraph();
} }
} }
......
...@@ -268,7 +268,7 @@ public class OpenXMLDocument { ...@@ -268,7 +268,7 @@ public class OpenXMLDocument {
if(StringHelper.containsNonWhitespace(documentHeader)) { if(StringHelper.containsNonWhitespace(documentHeader)) {
try(InputStream headerIn = OpenXMLDocument.class.getResourceAsStream("_resources/header.xml")) { try(InputStream headerIn = OpenXMLDocument.class.getResourceAsStream("_resources/header.xml")) {
String headerTemplate = IOUtils.toString(headerIn); String headerTemplate = IOUtils.toString(headerIn, "UTF-8");
String header = headerTemplate.replace("[oodocumentitlte]", documentHeader); String header = headerTemplate.replace("[oodocumentitlte]", documentHeader);
String headerId = generateId(); String headerId = generateId();
......
...@@ -471,6 +471,11 @@ public class QTI21WordExport implements MediaResource { ...@@ -471,6 +471,11 @@ public class QTI21WordExport implements MediaResource {
case "simpleassociablechoice": case "simpleassociablechoice":
//do nothing //do nothing
break; break;
case "div":
case "p":
trimTextBuffer();
super.startElement(uri, localName, qName, attributes);
break;
default: { default: {
if(renderElement) { if(renderElement) {
super.startElement(uri, localName, qName, attributes); super.startElement(uri, localName, qName, attributes);
...@@ -668,7 +673,7 @@ public class QTI21WordExport implements MediaResource { ...@@ -668,7 +673,7 @@ public class QTI21WordExport implements MediaResource {
private void startMatch(MatchInteraction matchInteraction) { private void startMatch(MatchInteraction matchInteraction) {
List<String> cssClasses = matchInteraction.getClassAttr(); List<String> cssClasses = matchInteraction.getClassAttr();
if(cssClasses.contains(QTI21Constants.CSS_MATCH_DRAG_AND_DROP)) { if(cssClasses != null && cssClasses.contains(QTI21Constants.CSS_MATCH_DRAG_AND_DROP)) {
if(hasClass(matchInteraction, QTI21Constants.CSS_MATCH_SOURCE_TOP) if(hasClass(matchInteraction, QTI21Constants.CSS_MATCH_SOURCE_TOP)
|| hasClass(matchInteraction, QTI21Constants.CSS_MATCH_SOURCE_BOTTOM)) { || hasClass(matchInteraction, QTI21Constants.CSS_MATCH_SOURCE_BOTTOM)) {
startMatchDragAndDropHorizontal(matchInteraction); startMatchDragAndDropHorizontal(matchInteraction);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment