Search in sources :

Example 1 with Text

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);
}
Also used : Comment(org.dom4j.Comment) Entity(org.dom4j.Entity) NodeProcess(com.amalto.workbench.utils.callback.NodeProcess) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) Text(org.dom4j.Text) CDATA(org.dom4j.CDATA) Test(org.junit.Test)

Example 2 with Text

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();
}
Also used : InputSource(org.xml.sax.InputSource) Document(org.dom4j.Document) java.util(java.util) BeforeClass(org.junit.BeforeClass) Text(org.dom4j.Text) Test(org.junit.Test) SAXReader(org.dom4j.io.SAXReader) BinaryOperator(java.util.function.BinaryOperator) StringReader(java.io.StringReader) org.eclipse.sw360.datahandler.thrift.licenseinfo(org.eclipse.sw360.datahandler.thrift.licenseinfo) Element(org.dom4j.Element) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Matchers.containsString(org.hamcrest.Matchers.containsString) EntityResolver(org.xml.sax.EntityResolver) InputStream(java.io.InputStream) Element(org.dom4j.Element) Text(org.dom4j.Text) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 3 with Text

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();
}
Also used : Text(org.dom4j.Text)

Aggregations

Text (org.dom4j.Text)3 Element (org.dom4j.Element)2 Test (org.junit.Test)2 NodeProcess (com.amalto.workbench.utils.callback.NodeProcess)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 java.util (java.util)1 BinaryOperator (java.util.function.BinaryOperator)1 Attribute (org.dom4j.Attribute)1 CDATA (org.dom4j.CDATA)1 Comment (org.dom4j.Comment)1 Document (org.dom4j.Document)1 Entity (org.dom4j.Entity)1 SAXReader (org.dom4j.io.SAXReader)1 org.eclipse.sw360.datahandler.thrift.licenseinfo (org.eclipse.sw360.datahandler.thrift.licenseinfo)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.is (org.hamcrest.Matchers.is)1 BeforeClass (org.junit.BeforeClass)1 EntityResolver (org.xml.sax.EntityResolver)1