Example usage for org.dom4j Element elementText

List of usage examples for org.dom4j Element elementText

Introduction

In this page you can find the example usage for org.dom4j Element elementText.

Prototype

String elementText(QName qname);

Source Link

Usage

From source file:com.beyondb.io.DBConfig.java

/**
 *??/*from ww  w  .ja  va 2s . co  m*/
 * @param path
 * @return
 */
public static DataSource readDBConfig(String path) {
    DataSource ds = null;

    try {

        SAXReader reader = new SAXReader();
        File file = new File(path);

        if (file.exists()) {
            Document doc = reader.read(file);

            Element datasource = doc.getRootElement();
            Element dbElement = datasource.element(Node_database);
            if (dbElement != null) {
                String id = dbElement.attribute(Attribute_id).getValue();
                String username = dbElement.attribute(Attribute_username).getValue();
                String password = dbElement.attribute(Attribute_password).getValue();
                String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue();
                String url = dbElement.elementText(Attribute_jdbcurl);
                ds = new BydDataSource(url, username, password);
                ds.setVirtualNode(virtualNode);
                ds.setID(id);
            }

        }

    } catch (DocumentException ex) {

        Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex);
    }
    return ds;
}

From source file:com.beyondb.io.DBConfig.java

/**
 *??//from  w  w w  .  j  a va2  s . c  o  m
 * @param path
 * @return
 */
public static ArrayList<DataSource> readDBConfig1(String path) {
    ArrayList<DataSource> dslist = new ArrayList<>();

    try {

        SAXReader reader = new SAXReader();
        File file = new File(path);

        if (file.exists()) {
            Document doc = reader.read(file);

            Element datasource = doc.getRootElement();
            Iterator it = datasource.elementIterator(Node_database);
            while (it.hasNext()) {
                Element dbElement = (Element) it.next();
                String id = dbElement.attribute(Attribute_id).getValue();
                String username = dbElement.attribute(Attribute_username).getValue();
                String password = dbElement.attribute(Attribute_password).getValue();
                String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue();
                String url = dbElement.elementText(Attribute_jdbcurl);

                DataSource ds = new BydDataSource(url, username, password);
                ds.setVirtualNode(virtualNode);
                ds.setID(id);
                dslist.add(ds);
            }

        }

    } catch (DocumentException ex) {

        Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex);
    }
    return dslist;
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * //from w w w.j a v  a2s  . co  m
 *
 * @param root
 *            
 * @param subTagName
 *            
 * @return 
 */
public static String getSubTagValue(Element root, String subTagName) {
    String returnString = root.elementText(subTagName);
    return returnString;
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * //from  w  w w. ja v  a2 s . co  m
 *
 *
 *
 * @param root
 *            
 * @param tagName
 *            
 *
 *
 *
 * @param subTagName
 *            
 * @return 
 */
public static String getSubTagValue(Element root, String tagName, String subTagName) {
    Element child = root.element(tagName);
    String returnString = child.elementText(subTagName);
    return returnString;
}

From source file:com.buddycloud.channeldirectory.crawler.node.FirehoseCrawler.java

License:Apache License

@Override
public void crawl(BuddycloudNode node, String server) throws Exception {

    String newerThan = CrawlerHelper.getLastItemCrawled(server, dataSource);
    String olderItemId = null;/*from w w  w . j  a va2  s  .c o m*/

    Set<String> nodesAlreadyVisited = new HashSet<String>();

    while (true) {
        List<PacketExtension> additionalExtensions = new LinkedList<PacketExtension>();
        List<PacketExtension> returnedExtensions = new LinkedList<PacketExtension>();
        List<Item> items = null;
        if (olderItemId != null) {
            RSMSet nextRsmSet = RSMSet.newAfter(olderItemId);
            additionalExtensions.add(nextRsmSet);
        }
        items = node.getItems(additionalExtensions, returnedExtensions);
        if (items.isEmpty()) {
            break;
        }
        boolean done = false;
        for (Item item : items) {
            Element itemEntry = CrawlerHelper.getAtomEntry(item);
            String itemId = itemEntry.elementText("id");
            if (newerThan != null && itemId.equals(newerThan)) {
                done = true;
                break;
            }
            olderItemId = itemId;
            try {
                String nodeId = CrawlerHelper.getNodeFromItemId(itemId);
                postCrawler.processPost(nodeId, CrawlerHelper.getChannelFromNode(nodeId), item);
                if (nodesAlreadyVisited.add(nodeId)) {
                    CrawlerHelper.updateLastItemCrawled(node, itemId, server, dataSource);
                }
            } catch (Exception e) {
                LOGGER.warn(e);
            }
        }
        if (done) {
            break;
        }
    }
}

From source file:com.buddycloud.channeldirectory.crawler.node.PostCrawler.java

License:Apache License

@SuppressWarnings("unchecked")
private void processPost(String nodeFullJid, String nodeId, Item item) throws Exception {

    PayloadItem<PacketExtension> payloadItem = (PayloadItem<PacketExtension>) item;
    PacketExtension payload = payloadItem.getPayload();

    Element atomEntry = DocumentHelper.parseText(payload.toXML()).getRootElement();

    PostData postData = new PostData();

    postData.setParentFullId(nodeFullJid);
    postData.setParentSimpleId(nodeId);/*from   w w  w  .ja  v  a 2  s.  c  o m*/

    Element authorElement = atomEntry.element("author");
    String authorName = authorElement.elementText("name");
    String authorUri = authorElement.elementText("uri");

    postData.setAuthor(authorName);
    postData.setAuthorURI(authorUri);

    String content = atomEntry.elementText("content");
    String updated = atomEntry.elementText("updated");
    String published = atomEntry.elementText("published");
    String id = atomEntry.elementText("id");

    postData.setContent(content);
    postData.setUpdated(DATE_FORMAT.parse(updated));
    postData.setPublished(DATE_FORMAT.parse(published));
    postData.setId(id);

    Element geolocElement = atomEntry.element("geoloc");

    if (geolocElement != null) {
        Geolocation geolocation = new Geolocation();

        String text = geolocElement.elementText("text");
        geolocation.setText(text);

        String lat = geolocElement.elementText("lat");
        String lon = geolocElement.elementText("lon");

        if (lat != null && lon != null) {
            geolocation.setLat(Double.valueOf(lat));
            geolocation.setLng(Double.valueOf(lon));
        }

        postData.setGeolocation(geolocation);
    }

    Element inReplyToElement = atomEntry.element("in-reply-to");
    if (inReplyToElement != null) {
        String replyRef = inReplyToElement.attributeValue("ref");
        postData.setInReplyTo(replyRef);
    }

    insert(postData);
    ActivityHelper.updateActivity(postData, dataSource, configuration);
}

From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.CaseResult.java

License:Open Source License

CaseResult(SuiteResult parent, Element testCase, String testClassName, boolean keepLongStdio) {
    // schema for JUnit report XML format is not available in Ant,
    // so I don't know for sure what means what.
    // reports in http://www.nabble.com/difference-in-junit-publisher-and-ant-junitreport-tf4308604.html#a12265700
    // indicates that maybe I shouldn't use @classname altogether.

    // String cn = testCase.attributeValue("classname");
    // if(cn==null)
    // // Maven seems to skip classname, and that shows up in testSuite/@name
    // cn = parent.getName();

    /*/*  www . j a v a 2  s . co  m*/
        According to http://www.nabble.com/NPE-(Fatal%3A-Null)-in-recording-junit-test-results-td23562964.html
        there's some odd-ball cases where testClassName is null but
        @name contains fully qualified name.
     */
    String nameAttr = testCase.attributeValue("name");
    if (testClassName == null && nameAttr.contains(".")) {
        testClassName = nameAttr.substring(0, nameAttr.lastIndexOf('.'));
        nameAttr = nameAttr.substring(nameAttr.lastIndexOf('.') + 1);
    }

    className = testClassName;
    testName = nameAttr;
    errorStackTrace = getError(testCase);
    errorDetails = getErrorMessage(testCase);
    this.parent = parent;
    duration = parseTime(testCase);
    skipped = isMarkedAsSkipped(testCase);
    @SuppressWarnings("LeakingThisInConstructor")
    Collection<CaseResult> _this = Collections.singleton(this);
    stdout = possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-out"));
    stderr = possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-err"));
}

From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.CaseResult.java

License:Open Source License

private static String getError(Element testCase) {
    String msg = testCase.elementText("error");
    if (msg != null)
        return msg;
    return testCase.elementText("failure");
}

From source file:com.cwctravel.hudson.plugins.suitegroupedtests.junit.SuiteResult.java

License:Open Source License

/**
 * @param xmlReport//from   www.j ava 2s.c  o m
 *        A JUnit XML report file whose top level element is 'testsuite'.
 * @param suite
 *        The parsed result of {@code xmlReport}
 */
private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio)
        throws DocumentException, IOException {
    this.file = xmlReport.getAbsolutePath();
    String name = suite.attributeValue("name");
    if (name == null)
        // some user reported that name is null in their environment.
        // see http://www.nabble.com/Unexpected-Null-Pointer-Exception-in-Hudson-1.131-tf4314802.html
        name = '(' + xmlReport.getName() + ')';
    else {
        String pkg = suite.attributeValue("package");
        if (pkg != null && pkg.length() > 0)
            name = pkg + '.' + name;
    }
    this.name = TestObject.safe(name);
    this.timestamp = suite.attributeValue("timestamp");

    Element ex = suite.element("error");
    if (ex != null) {
        // according to junit-noframes.xsl l.229, this happens when the test class failed to load
        addCase(new CaseResult(this, suite, "<init>", keepLongStdio));
    }

    for (Element e : (List<Element>) suite.elements("testcase")) {
        // https://hudson.dev.java.net/issues/show_bug.cgi?id=1233 indicates that
        // when <testsuites> is present, we are better off using @classname on the
        // individual testcase class.

        // https://hudson.dev.java.net/issues/show_bug.cgi?id=1463 indicates that
        // @classname may not exist in individual testcase elements. We now
        // also test if the testsuite element has a package name that can be used
        // as the class name instead of the file name which is default.
        String classname = e.attributeValue("classname");
        if (classname == null) {
            classname = suite.attributeValue("name");
        }

        // https://hudson.dev.java.net/issues/show_bug.cgi?id=1233 and
        // http://www.nabble.com/difference-in-junit-publisher-and-ant-junitreport-tf4308604.html#a12265700
        // are at odds with each other --- when both are present,
        // one wants to use @name from <testsuite>,
        // the other wants to use @classname from <testcase>.

        addCase(new CaseResult(this, e, classname, keepLongStdio));
    }

    String stdout = suite.elementText("system-out");
    String stderr = suite.elementText("system-err");
    if (stdout == null && stderr == null) {
        // Surefire never puts stdout/stderr in the XML. Instead, it goes to a separate file
        Matcher m = SUREFIRE_FILENAME.matcher(xmlReport.getName());
        if (m.matches()) {
            // look for ***-output.txt from TEST-***.xml
            File mavenOutputFile = new File(xmlReport.getParentFile(), m.group(1) + "-output.txt");
            if (mavenOutputFile.exists()) {
                try {
                    stdout = FileUtils.readFileToString(mavenOutputFile);
                } catch (IOException e) {
                    throw new IOException2("Failed to read " + mavenOutputFile, e);
                }
            }
        }
    }

    this.stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, stdout);
    this.stderr = CaseResult.possiblyTrimStdio(cases, keepLongStdio, stderr);
}

From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java

License:Mozilla Public License

private Survey constructSurvey(Element element) {
    Survey survey = new Survey();
    survey.setName(element.elementText("name"));

    for (Object levelElement : element.elements("level")) {
        survey.getSurveyLevels().add(constructLevel((Element) levelElement));
    }/* w  ww .  j av  a 2s.  co m*/

    for (Object sectionElement : element.elements("section")) {
        survey.getSurveySections().add(constructSection((Element) sectionElement));
    }

    // Link Back
    for (SurveyLevel l : survey.getSurveyLevels()) {
        l.setSurvey(survey);
    }

    for (SurveySection s : survey.getSurveySections()) {
        s.setSurvey(survey);
    }

    return survey;
}