Search in sources :

Example 1 with JDOMFactory

use of org.jdom2.JDOMFactory in project mycore by MyCoRe-Org.

the class MCRXSL2XMLTransformer method getDocument.

private Document getDocument(JDOMResult result) {
    Document resultDoc = result.getDocument();
    if (resultDoc == null) {
        // Sometimes a transformation produces whitespace strings
        // JDOM would produce a empty document if it detects those
        // So we remove them, if they exists.
        List<Content> transformResult = result.getResult();
        int origSize = transformResult.size();
        Iterator<Content> iterator = transformResult.iterator();
        while (iterator.hasNext()) {
            Content content = iterator.next();
            if (content instanceof Text) {
                String trimmedText = ((Text) content).getTextTrim();
                if (trimmedText.length() == 0) {
                    iterator.remove();
                }
            }
        }
        if (transformResult.size() < origSize) {
            JDOMFactory f = result.getFactory();
            if (f == null) {
                f = new DefaultJDOMFactory();
            }
            resultDoc = f.document(null);
            resultDoc.setContent(transformResult);
        }
    }
    return resultDoc;
}
Also used : DefaultJDOMFactory(org.jdom2.DefaultJDOMFactory) MCRContent(org.mycore.common.content.MCRContent) Content(org.jdom2.Content) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) JDOMFactory(org.jdom2.JDOMFactory) DefaultJDOMFactory(org.jdom2.DefaultJDOMFactory) Text(org.jdom2.Text) Document(org.jdom2.Document)

Aggregations

Content (org.jdom2.Content)1 DefaultJDOMFactory (org.jdom2.DefaultJDOMFactory)1 Document (org.jdom2.Document)1 JDOMFactory (org.jdom2.JDOMFactory)1 Text (org.jdom2.Text)1 MCRContent (org.mycore.common.content.MCRContent)1 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)1