Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

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

License:Open Source License

/**
 * @param xmlReport/*w ww .  j  av  a 2 s  .  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 SurveyLevel constructLevel(Element levelElement) {
    SurveyLevel level = new SurveyLevel();
    level.setNumber(Integer.parseInt(levelElement.attributeValue("number")));
    level.setDescription(levelElement.getTextTrim());

    return level;
}

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

License:Mozilla Public License

private SurveySection constructSection(Element sectionElement) {
    SurveySection section = new SurveySection();
    section.setSectionName(sectionElement.attributeValue("name"));
    section.setColor(sectionElement.attributeValue("color"));
    section.setLightColor(sectionElement.attributeValue("lightColor"));

    for (Object practiceElement : sectionElement.elements("practice")) {
        section.getSurveyPractices().add(constructPractice((Element) practiceElement));
    }//  w w w . ja  v a  2s .  co  m

    for (SurveyPractice practice : section.getSurveyPractices()) {
        practice.setSurveySection(section);
    }

    return section;
}

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

License:Mozilla Public License

private SurveyPractice constructPractice(Element practiceElement) {
    SurveyPractice practice = new SurveyPractice();
    practice.setName(practiceElement.attributeValue("name"));

    for (Object objectiveElement : practiceElement.elements("objective")) {
        practice.getSurveyObjectives().add(constructObjective((Element) objectiveElement));
    }//from  ww  w.ja va 2 s  .com

    for (SurveyObjective objective : practice.getSurveyObjectives()) {
        objective.setSurveyPractice(practice);
    }

    return practice;
}

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

License:Mozilla Public License

private SurveyObjective constructObjective(Element objectiveElement) {
    SurveyObjective objective = new SurveyObjective();
    objective.setDescription(objectiveElement.elementText("description"));
    objective.setLevelNumber(Integer.parseInt(objectiveElement.attributeValue("level")));

    for (Object questionElement : objectiveElement.elements("question")) {
        objective.getSurveyQuestions().add(constructQuestion((Element) questionElement));
    }/* w w  w  . ja  v  a 2 s .com*/

    for (SurveyQuestion question : objective.getSurveyQuestions()) {
        question.setSurveyObjective(objective);
    }

    return objective;
}

From source file:com.devoteam.srit.xmlloader.asn1.BN_ASNMessage.java

License:Open Source License

public void parseFromXML(Element root) throws Exception {
    this.className = root.attributeValue("className");

    List<Element> children = root.elements();
    for (Element element : children) {
        Class thisClass = Class.forName(className);
        int pos = className.lastIndexOf('.');
        String packageName = "";
        if (pos > 0) {
            packageName = className.substring(0, pos + 1);
        }// www .ja v a2 s .c o  m
        this.asnObject = thisClass.newInstance();
        String resultPath = "";
        XMLToASNParser.getInstance().parseFromXML(resultPath, this, this.asnObject, element, packageName);
    }
}

From source file:com.devoteam.srit.xmlloader.asn1.dictionary.ASNDictionary.java

License:Open Source License

public void parseFromXML(Element root) throws Exception {
    this.layer = root.attributeValue("layer");
    this.className = root.attributeValue("className");

    List<Element> listElement = root.elements("element");
    for (Element elem : listElement) {
        String coding = elem.attributeValue("coding");
        ElementAbstract elemInfo = ElementAbstract.buildFactory(coding);
        elemInfo.parseFromXML(elem, this, null, true);
        addElement(elemInfo);// w  w w  .  j av a2  s  .  c  o m
    }

    List<Element> listEmbedded = root.elements("embedded");
    for (Element elem : listEmbedded) {
        Embedded embedded = new Embedded();
        embedded.parseFromXML(elem, this);

        this.embeddedList.addEmbedded(embedded);
    }

}

From source file:com.devoteam.srit.xmlloader.asn1.dictionary.Embedded.java

License:Open Source License

public void parseFromXML(Element elementRoot, Dictionary dictionary) throws Exception {
    this.initial = elementRoot.attributeValue("initial");
    this.replace = elementRoot.attributeValue("replace");
    this.condition = elementRoot.attributeValue("condition");
}

From source file:com.devoteam.srit.xmlloader.core.coding.binary.Dictionary.java

License:Open Source License

public Dictionary(Element root, String syntax) throws Exception {

    List<Element> listElem = root.element("header").elements("field");
    for (Element element : listElem) {
        fieldsMapHeader.put(element.attributeValue("name"), new EnumerationField(element));
    }/*  ww  w  .ja  va 2s  . c  o  m*/

    List<Element> list = root.elements("element");
    for (Element elem : list) {
        ElementAbstract elemInfo = null;
        if ("Q931".equalsIgnoreCase(syntax)) {
            elemInfo = ElementAbstract.buildFactory("Q931");
        } else {
            String coding = elem.attributeValue("coding");
            elemInfo = ElementAbstract.buildFactory(coding);
        }

        elemInfo.parseFromXML(elem, null, null);

        elementsMapByLabel.put(elemInfo.getLabel(), elemInfo);
        elementsMapByTag.put(elemInfo.getTag(), elemInfo);
    }

}

From source file:com.devoteam.srit.xmlloader.core.coding.binary.Dictionary.java

License:Open Source License

public ElementAbstract getElementFromXML(Element elementRoot) throws Exception {
    //si elem dans dico on prend dico sinon on envoie ce qu'il y a dans le fichier xml
    String tag = elementRoot.attributeValue("identifier");
    if (tag == null) {
        tag = elementRoot.attributeValue("tag");
    }//from w  w  w  .ja v a  2 s  .  co  m
    tag = tag.trim();

    ElementAbstract elemDico = getElementFromTag(tag);
    // the element is present in the dictionary
    if (elemDico != null) {
        return elemDico;
    }
    // the element is not present in the dictionary
    String coding = elementRoot.attributeValue("coding");
    ElementAbstract newElement = ElementAbstract.buildFactory(coding);
    return newElement;
}