List of usage examples for org.jdom2.transform JDOMResult getFactory
public JDOMFactory getFactory()
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 w w w. j a v a 2s. c om*/ } } } if (transformResult.size() < origSize) { JDOMFactory f = result.getFactory(); if (f == null) { f = new DefaultJDOMFactory(); } resultDoc = f.document(null); resultDoc.setContent(transformResult); } } return resultDoc; }