use of org.dom4j.Text in project tmdm-studio-se by Talend.
the class XmlUtilTest method testTreeWalk.
/*
* treeWalk(Element element, NodeProcess nodeProcess)
*/
@Test
public void testTreeWalk() {
// $NON-NLS-1$
String tag = "name";
Element parent = DocumentHelper.createElement(tag);
// $NON-NLS-1$ //$NON-NLS-2$
Attribute attr1 = DocumentHelper.createAttribute(parent, "Attr", "Value");
// $NON-NLS-1$
CDATA cDATA1 = DocumentHelper.createCDATA("cdata");
// $NON-NLS-1$
Comment comment1 = DocumentHelper.createComment("comment");
// $NON-NLS-1$ //$NON-NLS-2$
Entity entity1 = DocumentHelper.createEntity("entity", "entityname");
// $NON-NLS-1$
Text text1 = DocumentHelper.createText("text");
parent.add(attr1);
parent.add(cDATA1);
parent.add(comment1);
parent.add(entity1);
parent.add(text1);
// $NON-NLS-1$
Element childElement = DocumentHelper.createElement("child");
parent.add(childElement);
// $NON-NLS-1$ //$NON-NLS-2$
Attribute attr2 = DocumentHelper.createAttribute(parent, "Attr", "Value");
// $NON-NLS-1$
CDATA cDATA2 = DocumentHelper.createCDATA("cdata");
// $NON-NLS-1$
Comment comment2 = DocumentHelper.createComment("comment");
// $NON-NLS-1$ //$NON-NLS-2$
Entity entity2 = DocumentHelper.createEntity("entity", "entityname");
// $NON-NLS-1$
Text text2 = DocumentHelper.createText("text");
childElement.add(attr2);
childElement.add(cDATA2);
childElement.add(comment2);
childElement.add(entity2);
childElement.add(text2);
NodeProcess mockNodeProcess = mock(NodeProcess.class);
XmlUtil.treeWalk(parent, mockNodeProcess);
verify(mockNodeProcess, times(0)).process(attr1);
verify(mockNodeProcess).process(cDATA1);
verify(mockNodeProcess).process(comment1);
verify(mockNodeProcess).process(entity1);
verify(mockNodeProcess).process(text1);
verify(mockNodeProcess, times(0)).process(attr2);
verify(mockNodeProcess).process(cDATA2);
verify(mockNodeProcess).process(comment2);
verify(mockNodeProcess).process(entity2);
verify(mockNodeProcess).process(text2);
}
use of org.dom4j.Text in project sw360portal by sw360.
the class XhtmlGeneratorTest method findLicenses.
private String findLicenses(Document document, String releaseNameString) {
List list = document.selectNodes("//*[local-name()='li'][@id='" + releaseNameString + "']/*[local-name()='ul'][@class='licenseEntries']");
StringBuffer result = new StringBuffer();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
Element element = (Element) iter.next();
for (Object liObject : element.content()) {
Element liElement = (Element) liObject;
String licenseEntryId = liElement.attribute("id").getValue();
String licenseTextId = licenseEntryId.replace("licenseEntry", "licenseText");
List licenseTexts = document.selectNodes("//*[local-name()='pre'][@id='" + licenseTextId + "']/text()");
Object licenseText = licenseTexts.stream().map(l -> ((Text) l).getStringValue()).reduce("", (BinaryOperator<String>) (l1, l2) -> (String) (l1 + l2));
result.append(((String) licenseText).trim());
result.append("\n");
}
}
return result.toString();
}
use of org.dom4j.Text in project sw360portal by sw360.
the class XhtmlGeneratorTest method findCopyrights.
private String findCopyrights(Document document, String releaseNameString) {
List list = document.selectNodes("//*[local-name()='li'][@id='" + releaseNameString + "']/*[@class='copyrights']/text()");
StringBuffer result = new StringBuffer();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
Text text = (Text) iter.next();
if (!"".equals(text.getStringValue().trim())) {
result.append(text.getStringValue());
}
}
return result.toString();
}
Aggregations