BootstrapRTE with blank lines causes Document Generation error

1
I have a string attribute of unlimited length that is rendered using the Bootstrap WYSIWYG editor widget from the App Store.  I have a Document Template and have set the “Render XHTML” to true for that attribute. When there are no blank lines in the Rich Text Editor, the document generates just fine.  Where there are blank lines, the document generation fails with this stack trace: " com.mendix.modules.microflowengine.MicroflowException: Error processing XHTML at SPXMain.IVK_PDF_AccountPlan (DocumentExport : 'Generate PDF (.pdf) document using template 'AccountPlan_PDF'') at SPXMain.IVK_Generate_AccountPlan_PDF (SubMicroflow : 'IVK_PDF_AccountPlan') Advanced stacktrace: at com.mendix.modules.microflowengine.MicroflowUtil.processException(MicroflowUtil.java:146) Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: Error processing XHTML at com.mendix.documentexporter.focomponents.DynamicLabel$1.run(DynamicLabel.java:145) Caused by: net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 609; The element type "br" must be terminated by the matching end-tag "</br>". at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:469) at net.sf.saxon.event.Sender.send(Sender.java:177) at net.sf.saxon.Controller.makeSourceTree(Controller.java:1910) at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:573) at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:183) at com.mendix.documentexporter.focomponents.DynamicLabel$1.run(DynamicLabel.java:142) at java.security.AccessController.doPrivileged(Native Method) at com.mendix.documentexporter.focomponents.DynamicLabel.parseHtml(DynamicLabel.java:111) at com.mendix.documentexporter.focomponents.DynamicLabel.generateFO(DynamicLabel.java:78) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.render(DocumentTemplateRepresentator.java:328) at com.mendix.documentexporter.focomponents.Table.generateFO(Table.java:71) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.render(DocumentTemplateRepresentator.java:328) at com.mendix.documentexporter.focomponents.Dataview.generateFO(Dataview.java:34) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.render(DocumentTemplateRepresentator.java:328) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.generate(DocumentTemplateRepresentator.java:132) at com.mendix.documentexporter.documents.FOBasedDocument.exportToInputStream(FOBasedDocument.java:81) at com.mendix.documentexporter.DocumentGenerator.exportToInputStream(DocumentGenerator.java:111) at com.mendix.documentexporter.DocumentGenerator.exportToIMendixObject(DocumentGenerator.java:78) at com.mendix.documentexporter.actions.microflow.DocumentExportAction.execute(DocumentExportAction.scala:75) at com.mendix.documentexporter.actions.microflow.DocumentExportAction.execute(DocumentExportAction.scala:17) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:201) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:76) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:55) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:186) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:191) at com.mendix.basis.component.InternalCore.executeSync(InternalCore.java:661) at com.mendix.modules.microflowengine.actions.SubMicroflowAction.execute(SubMicroflowAction.scala:43) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:201) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:76) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:55) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:186) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:191) at com.mendix.basis.component.InternalCore.execute(InternalCore.java:583) at com.mendix.webui.actions.client.ExecuteAction.execute(ExecuteAction.java:135) at com.mendix.webui.requesthandling.ClientRequestHandler.$anonfun$handleRequest$2(ClientRequestHandler.scala:328) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor(IMonitoredAction.scala:49) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor$(IMonitoredAction.scala:25) at com.mendix.webui.requesthandling.ClientRequestHandler$ClientMonitoredAction.monitor(ClientRequestHandler.scala:431) at com.mendix.webui.requesthandling.ClientRequestHandler.handleRequest(ClientRequestHandler.scala:313) at com.mendix.webui.requesthandling.ClientRequestHandler.handleActionWithSessionRequired(ClientRequestHandler.scala:251) at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:220) at com.mendix.webui.requesthandling.ClientRequestHandler.liftedTree1$1(ClientRequestHandler.scala:104) at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:96) at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:70) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:67) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:73) at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:877) at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:561) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597) at java.lang.Thread.run(Thread.java:745) Caused by: org.xml.sax.SAXParseException: The element type "br" must be terminated by the matching end-tag "</br>". at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:449) at net.sf.saxon.event.Sender.send(Sender.java:177) at net.sf.saxon.Controller.makeSourceTree(Controller.java:1910) at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:573) at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:183) at com.mendix.documentexporter.focomponents.DynamicLabel$1.run(DynamicLabel.java:142) at java.security.AccessController.doPrivileged(Native Method) at com.mendix.documentexporter.focomponents.DynamicLabel.parseHtml(DynamicLabel.java:111) at com.mendix.documentexporter.focomponents.DynamicLabel.generateFO(DynamicLabel.java:78) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.render(DocumentTemplateRepresentator.java:328) at com.mendix.documentexporter.focomponents.Table.generateFO(Table.java:71) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.render(DocumentTemplateRepresentator.java:328) at com.mendix.documentexporter.focomponents.Dataview.generateFO(Dataview.java:34) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.render(DocumentTemplateRepresentator.java:328) at com.mendix.documentexporter.focomponents.DocumentTemplateRepresentator.generate(DocumentTemplateRepresentator.java:132) at com.mendix.documentexporter.documents.FOBasedDocument.exportToInputStream(FOBasedDocument.java:81) at com.mendix.documentexporter.DocumentGenerator.exportToInputStream(DocumentGenerator.java:111) at com.mendix.documentexporter.DocumentGenerator.exportToIMendixObject(DocumentGenerator.java:78) at com.mendix.documentexporter.actions.microflow.DocumentExportAction.execute(DocumentExportAction.scala:75) at com.mendix.documentexporter.actions.microflow.DocumentExportAction.execute(DocumentExportAction.scala:17) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:201) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:76) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:55) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:186) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:191) at com.mendix.basis.component.InternalCore.executeSync(InternalCore.java:661) at com.mendix.modules.microflowengine.actions.SubMicroflowAction.execute(SubMicroflowAction.scala:43) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:201) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:76) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:55) at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:55) at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:186) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:191) at com.mendix.basis.component.InternalCore.execute(InternalCore.java:583) at com.mendix.webui.actions.client.ExecuteAction.execute(ExecuteAction.java:135) at com.mendix.webui.requesthandling.ClientRequestHandler.$anonfun$handleRequest$2(ClientRequestHandler.scala:328) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor(IMonitoredAction.scala:49) at com.mendix.basis.actionmanagement.IMonitoredAction.monitor$(IMonitoredAction.scala:25) at com.mendix.webui.requesthandling.ClientRequestHandler$ClientMonitoredAction.monitor(ClientRequestHandler.scala:431) at com.mendix.webui.requesthandling.ClientRequestHandler.handleRequest(ClientRequestHandler.scala:313) at com.mendix.webui.requesthandling.ClientRequestHandler.handleActionWithSessionRequired(ClientRequestHandler.scala:251) at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:220) at com.mendix.webui.requesthandling.ClientRequestHandler.liftedTree1$1(ClientRequestHandler.scala:104) at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:96) at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:70) at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:67) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32) at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:73) at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:877) at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:561) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597) at java.lang.Thread.run(Thread.java:745) " I can reproduce the error at will with modeler 7.13.1 or 7.10.0 and the latest versions of BootstrapRTE and CommunityCommons. Any ideas?
asked
1 answers
6

Hi Sunder,

The widget is generating an html string and the document needs an xhtml string. I've built something similar and had to create a java action that converts the html string to xhtml for the document template.

Here is the code for the java action. It takes in a string parameter and returns the xhtml string.

// This file was generated by Mendix Modeler.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package docugen.actions;

import javax.swing.text.Document;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import org.jsoup.*;
import org.jsoup.select.Elements;
import org.jsoup.parser.Parser;
import org.jsoup.nodes.*;

public class ConvertToXHTML extends CustomJavaAction<java.lang.String>
{
	private java.lang.String HTML;

	public ConvertToXHTML(IContext context, java.lang.String HTML)
	{
		super(context);
		this.HTML = HTML;
	}

	@Override
	public java.lang.String executeAction() throws Exception
	{
		// BEGIN USER CODE
		org.jsoup.nodes.Document document = Jsoup.parse(HTML);
		document.outputSettings().syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml); 
	    return document.toString();
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 */
	@Override
	public java.lang.String toString()
	{
		return "ConvertToXHTML";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

 

You would need to download and add the jsoup jar file to the userlib folder in your project.

You can find that here

 

And here is some documentation on creating a java action.

https://docs.mendix.com/howto/logic-business-rules/extending-your-application-with-custom-java

 

Hope this helps!

answered