Example usage for org.jdom2.transform JDOMResult getResult

List of usage examples for org.jdom2.transform JDOMResult getResult

Introduction

In this page you can find the example usage for org.jdom2.transform JDOMResult getResult.

Prototype

public List<Content> getResult() 

Source Link

Document

Returns the result of an XSL Transformation as a list of JDOM nodes.

Usage

From source file:org.mycore.common.content.transformer.MCRXSL2XMLTransformer.java

License:Open Source License

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();/*from ww w . ja v  a  2s . com*/
                }
            }
        }
        if (transformResult.size() < origSize) {
            JDOMFactory f = result.getFactory();
            if (f == null) {
                f = new DefaultJDOMFactory();
            }
            resultDoc = f.document(null);
            resultDoc.setContent(transformResult);
        }
    }
    return resultDoc;
}