use of org.jdom2.transform.JDOMResult in project mycore by MyCoRe-Org.
the class MCRXSLTransformation method transform.
/**
* transforms a jdom Document via XSLT.
*
* @param in Document input
* @param transformer Transformer handling the transformation process
* @return the transformation result as jdom Document
* @throws TransformerException if transformation fails
*/
public static Document transform(Document in, Transformer transformer) throws TransformerException {
JDOMResult out = new JDOMResult();
transformer.transform(new JDOMSource(in), out);
return out.getDocument();
}
use of org.jdom2.transform.JDOMResult in project mycore by MyCoRe-Org.
the class ItemTest method toXML.
@Test
public void toXML() throws Exception {
JAXBContext jc = JAXBContext.newInstance(MCRNavigationItem.class);
Marshaller m = jc.createMarshaller();
JDOMResult JDOMResult = new JDOMResult();
m.marshal(this.item, JDOMResult);
Element itemElement = JDOMResult.getDocument().getRootElement();
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
out.output(itemElement, System.out);
assertEquals("template_mysample", itemElement.getAttributeValue("template"));
assertEquals("bold", itemElement.getAttributeValue("style"));
assertEquals("_self", itemElement.getAttributeValue("target"));
assertEquals("intern", itemElement.getAttributeValue("type"));
assertEquals("true", itemElement.getAttributeValue("constrainPopUp"));
assertEquals("false", itemElement.getAttributeValue("replaceMenu"));
assertEquals("item.test.key", itemElement.getAttributeValue("i18nKey"));
Element label1 = itemElement.getChildren().get(0);
Element label2 = itemElement.getChildren().get(1);
assertEquals("Deutschland", label1.getValue());
assertEquals("England", label2.getValue());
}
use of org.jdom2.transform.JDOMResult 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;
}
Aggregations