Example usage for org.w3c.dom Element hasAttribute

List of usage examples for org.w3c.dom Element hasAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element hasAttribute.

Prototype

public boolean hasAttribute(String name);

Source Link

Document

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Usage

From source file:jef.tools.XMLUtils.java

/**
 * //from   w  ww . jav  a 2s.c  o m
 * 
 * @param e
 *            
 * @param attributeName
 *            ??
 * @return xml
 */
public static String attrib(Element e, String attributeName) {
    if (!e.hasAttribute(attributeName))
        return null;
    String text = e.getAttribute(attributeName);
    return (text == null) ? null : StringEscapeUtils.unescapeXml(text.trim());
}

From source file:jef.tools.XMLUtils.java

/**
 * ?attribid?JSdocument.getElementById();
 * /*w ww.jav a2 s .  c  o m*/
 * @param node
 *            
 * @param id
 *            ID
 * @return 
 */
public static Element findElementById(Node node, String id) {
    if (node == null)
        return null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element e = (Element) node;
        if (e.hasAttribute("id")) {
            String ss = StringUtils.trim(e.getAttribute("id"));
            if (ss.equals(id)) {
                return e;
            }
        }
    }
    for (Node sub : toArray(node.getChildNodes())) {
        Element nd = findElementById(sub, id);
        if (nd != null)
            return nd;
    }
    return null;
}

From source file:com.twinsoft.convertigo.beans.core.TransactionWithVariables.java

@Override
public void parseInputDocument(Context context) throws EngineException {
    super.parseInputDocument(context);
    if (context.inputDocument != null && Engine.logContext.isInfoEnabled()) {
        Document printDoc = (Document) Visibility.Logs.replaceVariables(getVariablesList(),
                context.inputDocument);/* ww  w .  jav  a2s . c om*/
        XMLUtils.logXml(printDoc, Engine.logContext, "Input document");
    }

    NodeList variableNodes = context.inputDocument.getElementsByTagName("variable");
    Element variableNode;
    Attr valueAttrNode;
    int len = variableNodes.getLength();
    String variableName, variableValue, variableMethod;
    RequestableVariable variable;
    boolean bMulti;

    // TODO: grer les variables dites persistantes

    variables.clear();

    for (int i = 0; i < len; i++) {
        bMulti = false;
        variableNode = (Element) variableNodes.item(i);
        variableName = variableNode.getAttribute("name");
        variableValue = (variableNode.hasAttribute("value") ? variableNode.getAttribute("value") : null);
        valueAttrNode = variableNode.getAttributeNode("value");

        variableMethod = null;

        // Test case for transaction
        if (variableName.indexOf(Parameter.Testcase.getName()) == 0) {
            TestCase testcase = getTestCaseByName(variableValue);
            if (testcase != null) {
                String testCaseVariableName;
                Object testCaseVariableValue;
                // Add test case variables default value(s)
                for (TestCaseVariable testCaseVariable : testcase.getVariables()) {
                    testCaseVariableName = testCaseVariable.getName();
                    testCaseVariableValue = testcase.getVariableValue(testCaseVariableName);
                    if (testCaseVariableValue != null) {
                        variables.put(testCaseVariableName, testCaseVariableValue);
                    }
                }
            } else {
                Engine.logBeans.warn("Transaction: there's no testcase named '" + variableValue + "' for '"
                        + getName() + "' transaction");
            }
            continue;
        }
        // May be a dynamic transaction variable definition
        else if ((variableName.indexOf(Parameter.DynamicVariablePost.getName()) == 0)
                || (variableName.indexOf(Parameter.DynamicVariableGet.getName()) == 0)) {
            bMulti = variableNode.getAttribute("multi").equalsIgnoreCase("true");

            if (variableName.indexOf(Parameter.DynamicVariablePost.getName()) == 0) {
                variableName = variableName.substring(Parameter.DynamicVariablePost.getName().length());
                variableMethod = "POST";
            } else if (variableName.indexOf(Parameter.DynamicVariableGet.getName()) == 0) {
                variableName = variableName.substring(Parameter.DynamicVariableGet.getName().length());
                variableMethod = "GET";
            }

            // retrieve variable definition
            variable = (RequestableVariable) getVariable(variableName);

            if (variableMethod != null) {
                setDynamicVariable(variableName, variableValue, Boolean.valueOf(bMulti), variableMethod);
            }
        }
        // Serialized variables definition
        else {
            variable = (RequestableVariable) getVariable(variableName);
        }

        // Structured value?
        Object scopeValue = null;
        if (getProject().isStrictMode()) {
            scopeValue = (variableValue != null) ? variableValue : variableNode.getChildNodes();
        } else {
            if (variableValue != null) {
                scopeValue = variableValue;
            } else {
                String sValue = XMLUtils.prettyPrintElement(variableNode, true, false);
                sValue = sValue.replaceAll("<variable name=\"" + variableName + "\">", "");
                sValue = sValue.replaceAll("</variable>", "");
                scopeValue = sValue;
            }
        }

        // Multivalued variable ?
        if ((variable != null) && (variable.isMultiValued())) {
            List<Object> current = GenericUtils.cast(variables.get(variableName));
            if (current == null) {
                current = new ArrayList<Object>();
                variables.put(variableName, current);
            }
            if (variableValue == null || valueAttrNode != null) {
                current.add(scopeValue);
            }
        } else {
            variables.put(variableName, scopeValue);
        }
    }

    // Enumeration of all transaction variables
    if (Engine.logBeans.isDebugEnabled())
        Engine.logBeans.debug("Transaction variables: " + (variables == null ? "none"
                : Visibility.Logs.replaceVariables(getVariablesList(), variables)));
}

From source file:jef.tools.XMLUtils.java

/**
 * (???)//from ww  w .java  2 s.  co m
 * 
 * @param e
 *            
 * @param attributeName
 *            ??
 * @return ??List
 */
public static List<String> attribs(Element e, String attributeName) {
    List<String> _list = new ArrayList<String>();
    if (e.hasAttribute(attributeName)) {
        String text = e.getAttribute(attributeName);
        _list.add((text == null) ? null : StringEscapeUtils.unescapeHtml(text.trim()));
    }
    if (e.hasChildNodes()) {
        NodeList nds = e.getChildNodes();
        for (int i = 0; i < nds.getLength(); i++) {
            Node child = nds.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                _list.addAll(attribs((Element) child, attributeName));
            }
        }
    }
    return _list;
}

From source file:com.hp.application.automation.tools.results.RunResultRecorder.java

/**
 * copies, archives and creates the Test reports of LR and UFT runs.
 *
 * @param build/*w  ww .  j a  va 2  s  . c o m*/
 * @param listener
 * @param resultFiles
 * @param testResult
 * @param runWorkspace
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 * @throws InterruptedException
 */
@SuppressWarnings({ "squid:S134", "squid:S135" })
private void archiveTestsReport(Run<?, ?> build, TaskListener listener, List<String> resultFiles,
        TestResult testResult, FilePath runWorkspace)
        throws ParserConfigurationException, SAXException, IOException, InterruptedException {

    if ((resultFiles == null) || (resultFiles.isEmpty())) {
        return;
    }

    ArrayList<String> zipFileNames = new ArrayList<String>();
    ArrayList<FilePath> reportFolders = new ArrayList<FilePath>();
    List<String> reportNames = new ArrayList<String>();

    listener.getLogger()
            .println("Report archiving mode is set to: " + _resultsPublisherModel.getArchiveTestResultsMode());

    FilePath projectWS = runWorkspace;

    // get the artifacts directory where we will upload the zipped report
    // folder
    File artifactsDir = new File(build.getRootDir(), "archive");
    artifactsDir.mkdirs();

    // read each result.xml
    /*
     * The structure of the result file is: <testsuites> <testsuite>
     * <testcase.........report="path-to-report"/>
     * <testcase.........report="path-to-report"/>
     * <testcase.........report="path-to-report"/>
     * <testcase.........report="path-to-report"/> </testsuite>
     * </testsuites>
     */

    // add previous report names for aggregation when using pipelines.
    for (SuiteResult suiteResult : testResult.getSuites()) {
        String[] temp = suiteResult.getName().split("_");
        reportNames.add(temp[temp.length - 1]);
    }

    for (String resultsFilePath : resultFiles) {
        FilePath resultsFile = projectWS.child(resultsFilePath);

        List<ReportMetaData> ReportInfoToCollect = new ArrayList<ReportMetaData>();

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

        Document doc = dBuilder.parse(resultsFile.read());
        doc.getDocumentElement().normalize();

        Node testSuiteNode = doc.getElementsByTagName("testsuite").item(0);
        Element testSuiteElement = (Element) testSuiteNode;
        if (testSuiteElement.hasAttribute("name") && testSuiteElement.getAttribute("name").endsWith(".lrs")) { // LR test
            NodeList testSuiteNodes = doc.getElementsByTagName("testsuite");
            for (int i = 0; i < testSuiteNodes.getLength(); i++) {
                testSuiteNode = testSuiteNodes.item(i);
                testSuiteElement = (Element) testSuiteNode;
                if (!testSuiteElement.hasAttribute("name")) {
                    continue;
                }
                String testFolderPath = testSuiteElement.getAttribute("name");
                String testStatus = ("0".equals(testSuiteElement.getAttribute("failures"))) ? "pass" : "fail";

                Node testCaseNode = testSuiteElement.getElementsByTagName("testcase").item(0);
                if (testCaseNode == null) {
                    listener.getLogger().println("No report folder was found in results");
                    return;
                }
                if (testCaseNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element testCaseElement = (Element) testCaseNode;

                    if (!testCaseElement.hasAttribute(REPORT_NAME_FIELD)) {
                        continue;
                    }

                    String reportFolderPath = testCaseElement.getAttribute(REPORT_NAME_FIELD);
                    FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath);
                    reportFolders.add(reportFolder);

                    FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath);
                    String zipFileName = getUniqueZipFileNameInFolder(zipFileNames, testFolder.getName());
                    FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName);

                    if (archiveFolder(reportFolder, testStatus, archivedFile, listener)) {
                        zipFileNames.add(zipFileName);
                    }

                    createHtmlReport(reportFolder, testFolderPath, artifactsDir, reportNames, testResult);
                    createTransactionSummary(reportFolder, testFolderPath, artifactsDir, reportNames,
                            testResult);
                    try {
                        FilePath testSla = copyRunReport(reportFolder, build.getRootDir(),
                                testFolder.getName());
                        runReportList.add(testSla);
                    } catch (IOException | InterruptedException e) {
                        listener.getLogger().println(e.getMessage());
                    }
                }
            }
        } else { // UFT Test
            boolean reportIsHtml = false;
            NodeList testCasesNodes = ((Element) testSuiteNode).getElementsByTagName("testcase");
            for (int i = 0; i < testCasesNodes.getLength(); i++) {

                Node nNode = testCasesNodes.item(i);

                if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element eElement = (Element) nNode;

                    if (!eElement.hasAttribute(REPORT_NAME_FIELD)) {
                        continue;
                    }

                    String reportFolderPath = eElement.getAttribute(REPORT_NAME_FIELD); // e.g. "C:\UFTTest\GuiTest1\Report"
                    String testFolderPath = eElement.getAttribute("name"); // e.g. "C:\UFTTest\GuiTest1"
                    String testStatus = eElement.getAttribute("status"); // e.g. "pass"

                    Node nodeSystemInfo = eElement.getElementsByTagName("system-out").item(0);
                    String sysinfo = nodeSystemInfo.getFirstChild().getNodeValue();
                    String testDateTime = sysinfo.substring(0, 19);

                    FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath);

                    reportFolders.add(reportFolder);

                    String archiveTestResultMode = _resultsPublisherModel.getArchiveTestResultsMode();
                    boolean archiveTestResult = false;

                    //check for the new html report
                    FilePath htmlReport = new FilePath(reportFolder, "run_results.html");
                    FilePath rrvReport = new FilePath(reportFolder, "Results.xml");
                    if (htmlReport.exists()) {
                        reportIsHtml = true;
                        String htmlReportDir = reportFolder.getRemote();

                        ReportMetaData reportMetaData = new ReportMetaData();
                        reportMetaData.setFolderPath(htmlReportDir);
                        reportMetaData.setIsHtmlReport(true);
                        reportMetaData.setDateTime(testDateTime);
                        reportMetaData.setStatus(testStatus);

                        File testFileFullName = new File(testFolderPath);
                        String testName = org.apache.commons.io.FilenameUtils
                                .getName(testFileFullName.getPath());
                        String resourceUrl = "artifact/UFTReport/" + testName;
                        reportMetaData.setResourceURL(resourceUrl);
                        reportMetaData.setDisPlayName(testName); // use the name, not the full path
                        //don't know reportMetaData's URL path yet, we will generate it later.
                        ReportInfoToCollect.add(reportMetaData);

                        listener.getLogger().println(
                                "add html report info to ReportInfoToCollect: " + "[date]" + testDateTime);
                    }

                    archiveTestResult = isArchiveTestResult(testStatus, archiveTestResultMode);

                    if (archiveTestResult && rrvReport.exists()) {

                        if (reportFolder.exists()) {

                            FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath);

                            String zipFileName = getUniqueZipFileNameInFolder(zipFileNames,
                                    testFolder.getName());
                            zipFileNames.add(zipFileName);

                            listener.getLogger().println("Zipping report folder: " + reportFolderPath);

                            ByteArrayOutputStream outstr = new ByteArrayOutputStream();

                            //don't use FileFilter for zip, or it will cause bug when files are on slave
                            reportFolder.zip(outstr);

                            /*
                                     * I did't use copyRecursiveTo or copyFrom due to
                             * bug in
                             * jekins:https://issues.jenkins-ci.org/browse
                             * /JENKINS-9189 //(which is cleaimed to have been
                             * fixed, but not. So I zip the folder to stream and
                             * copy it to the master.
                             */

                            ByteArrayInputStream instr = new ByteArrayInputStream(outstr.toByteArray());

                            FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName);
                            archivedFile.copyFrom(instr);
                            listener.getLogger().println("copy from slave to master: " + archivedFile);
                            outstr.close();
                            instr.close();

                            // add to Report list
                            ReportMetaData reportMetaData = new ReportMetaData();
                            reportMetaData.setIsHtmlReport(false);
                            // reportMetaData.setFolderPath(htmlReportDir); //no need for RRV
                            File testFileFullName = new File(testFolderPath);
                            String testName = testFileFullName.getName();
                            reportMetaData.setDisPlayName(testName); // use the name, not the full path
                            String zipFileUrlName = "artifact/" + zipFileName;
                            reportMetaData.setUrlName(zipFileUrlName); // for RRV, the file url and resource url are the same.
                            reportMetaData.setResourceURL(zipFileUrlName);
                            reportMetaData.setDateTime(testDateTime);
                            reportMetaData.setStatus(testStatus);
                            ReportInfoToCollect.add(reportMetaData);

                        } else {
                            listener.getLogger().println("No report folder was found in: " + reportFolderPath);
                        }
                    }

                }
            }

            if (reportIsHtml && !ReportInfoToCollect.isEmpty()) {

                listener.getLogger().println("begin to collectAndPrepareHtmlReports");
                collectAndPrepareHtmlReports(build, listener, ReportInfoToCollect, runWorkspace);
            }

            if (!ReportInfoToCollect.isEmpty()) {
                // serialize report metadata
                File reportMetaDataXmlFile = new File(artifactsDir.getParent(), REPORTMETADATE_XML);
                String reportMetaDataXml = reportMetaDataXmlFile.getAbsolutePath();
                writeReportMetaData2XML(ReportInfoToCollect, reportMetaDataXml, listener);

                // Add UFT report action
                try {
                    listener.getLogger().println("Adding a report action to the current build.");
                    HtmlBuildReportAction reportAction = new HtmlBuildReportAction(build);
                    build.addAction(reportAction);

                } catch (IOException | SAXException | ParserConfigurationException ex) {
                    listener.getLogger().println("a problem adding action: " + ex);
                }
            }
        }
    }
}

From source file:autohit.creator.compiler.SimCompiler.java

/**
 *  handle a MATH/*  w  ww.j  a va  2 s.  c  o m*/
 *  MICROCODE
 * 1- if (eval exists)         i.eval(eval)
 * 2-    else if (value exists) i.load(value)
 * 3-    else                !!ERROR   
 * 4- i.right()
 * 5- i.fetch(left)
 * 6- i.math(oper)
 * 7- if (output exists)      i.store(output)
 * 8-    else                i.store(left)
 */
private void handleMath(Element en) {

    //runtimeDebug("handleMath");

    // 1- if (eval exists)      i.eval(eval)
    if (en.hasAttribute(ATTR_EVALUATOR)) {
        this.emitEval(en.getAttribute(ATTR_EVALUATOR));

        // 2- else if (value exists) i.load(value)    
    } else if (en.hasAttribute(ATTR_VALUE)) {
        this.emitLoad(en.getAttribute(ATTR_VALUE));

        // 3- else          !!ERROR   
    } else {
        runtimeError("ERROR Broken Math.  No right value defined.");
        this.emitLoad(LITERAL_ZERO);
        // use 0 so we can finish compile
    }

    // 4- i.right
    this.emitRight();

    // 5- i.fetch(item)
    this.emitFetch(en.getAttribute(ATTR_LEFT));

    // 6- i.math(operation)
    this.emitMath(en.getAttribute(ATTR_OPERATOR));

    // 7- if (output exists)      i.store(output)
    if (en.hasAttribute(ATTR_OUTPUT)) {
        this.emitStore(en.getAttribute(ATTR_OUTPUT));

        // else                i.store(left)
    } else {
        this.emitStore(en.getAttribute(ATTR_LEFT));
    }

}

From source file:com.hpe.application.automation.tools.results.RunResultRecorder.java

/**
 * copies, archives and creates the Test reports of LR and UFT runs.
 *
 * @param build//from   ww w.  j a  v a  2 s  .  c o m
 * @param listener
 * @param resultFiles
 * @param testResult
 * @param runWorkspace
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 * @throws InterruptedException
 */
@SuppressWarnings({ "squid:S134", "squid:S135" })
private void archiveTestsReport(Run<?, ?> build, TaskListener listener, List<String> resultFiles,
        TestResult testResult, FilePath runWorkspace)
        throws ParserConfigurationException, SAXException, IOException, InterruptedException {

    if ((resultFiles == null) || (resultFiles.isEmpty())) {
        return;
    }

    ArrayList<String> zipFileNames = new ArrayList<String>();
    ArrayList<FilePath> reportFolders = new ArrayList<FilePath>();
    List<String> reportNames = new ArrayList<String>();

    listener.getLogger()
            .println("Report archiving mode is set to: " + _resultsPublisherModel.getArchiveTestResultsMode());

    // if user specified not to archive report
    if (_resultsPublisherModel.getArchiveTestResultsMode()
            .equals(ResultsPublisherModel.dontArchiveResults.getValue()))
        return;

    FilePath projectWS = runWorkspace;

    // get the artifacts directory where we will upload the zipped report
    // folder
    File artifactsDir = new File(build.getRootDir(), "archive");
    artifactsDir.mkdirs();

    // read each result.xml
    /*
     * The structure of the result file is: <testsuites> <testsuite>
     * <testcase.........report="path-to-report"/>
     * <testcase.........report="path-to-report"/>
     * <testcase.........report="path-to-report"/>
     * <testcase.........report="path-to-report"/> </testsuite>
     * </testsuites>
     */

    // add previous report names for aggregation when using pipelines.
    PerformanceJobReportAction performanceJobReportAction = build.getAction(PerformanceJobReportAction.class);
    if (performanceJobReportAction != null) {
        reportNames
                .addAll(performanceJobReportAction.getLrResultBuildDataset().getLrScenarioResults().keySet());
    }

    for (String resultsFilePath : resultFiles) {
        FilePath resultsFile = projectWS.child(resultsFilePath);

        List<ReportMetaData> ReportInfoToCollect = new ArrayList<ReportMetaData>();

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

        Document doc = dBuilder.parse(resultsFile.read());
        doc.getDocumentElement().normalize();

        Node testSuiteNode = doc.getElementsByTagName("testsuite").item(0);
        Element testSuiteElement = (Element) testSuiteNode;
        if (testSuiteElement.hasAttribute("name") && testSuiteElement.getAttribute("name").endsWith(".lrs")) { // LR test
            NodeList testSuiteNodes = doc.getElementsByTagName("testsuite");
            for (int i = 0; i < testSuiteNodes.getLength(); i++) {
                testSuiteNode = testSuiteNodes.item(i);
                testSuiteElement = (Element) testSuiteNode;
                if (!testSuiteElement.hasAttribute("name")) {
                    continue;
                }
                String testFolderPath = testSuiteElement.getAttribute("name");
                int testPathArr = testFolderPath.lastIndexOf('\\');
                String testName = testFolderPath.substring(testPathArr + 1);
                reportNames.add(testName);
                String testStatus = ("0".equals(testSuiteElement.getAttribute("failures"))) ? "pass" : "fail";

                Node testCaseNode = testSuiteElement.getElementsByTagName("testcase").item(0);
                if (testCaseNode == null) {
                    listener.getLogger().println("No report folder was found in results");
                    return;
                }
                if (testCaseNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element testCaseElement = (Element) testCaseNode;

                    if (!testCaseElement.hasAttribute(REPORT_NAME_FIELD)) {
                        continue;
                    }

                    String reportFolderPath = testCaseElement.getAttribute(REPORT_NAME_FIELD);
                    FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath);
                    reportFolders.add(reportFolder);

                    FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath);
                    String zipFileName = getUniqueZipFileNameInFolder(zipFileNames, testFolder.getName());
                    FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName);

                    if (archiveFolder(reportFolder, testStatus, archivedFile, listener)) {
                        zipFileNames.add(zipFileName);
                    }

                    createHtmlReport(reportFolder, testFolderPath, artifactsDir, reportNames, testResult);
                    createTransactionSummary(reportFolder, testFolderPath, artifactsDir, reportNames,
                            testResult);
                    try {
                        FilePath testSla = copyRunReport(reportFolder, build.getRootDir(),
                                testFolder.getName());
                        if (testSla == null) {
                            listener.getLogger().println("no RunReport.xml file was created");
                        } else {
                            runReportList.add(testSla);
                        }
                    } catch (IOException | InterruptedException e) {
                        listener.getLogger().println(e);
                    }
                }
            }
        } else { // UFT Test
            boolean reportIsHtml = false;
            NodeList testCasesNodes = ((Element) testSuiteNode).getElementsByTagName("testcase");
            for (int i = 0; i < testCasesNodes.getLength(); i++) {

                Node nNode = testCasesNodes.item(i);

                if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element eElement = (Element) nNode;

                    if (!eElement.hasAttribute(REPORT_NAME_FIELD)) {
                        continue;
                    }

                    String reportFolderPath = eElement.getAttribute(REPORT_NAME_FIELD); // e.g. "C:\UFTTest\GuiTest1\Report"
                    String testFolderPath = eElement.getAttribute("name"); // e.g. "C:\UFTTest\GuiTest1"
                    String testStatus = eElement.getAttribute("status"); // e.g. "pass"

                    Node nodeSystemInfo = eElement.getElementsByTagName("system-out").item(0);
                    String sysinfo = nodeSystemInfo.getFirstChild().getNodeValue();
                    String testDateTime = sysinfo.substring(0, 19);

                    FilePath reportFolder = new FilePath(projectWS.getChannel(), reportFolderPath);

                    reportFolders.add(reportFolder);

                    String archiveTestResultMode = _resultsPublisherModel.getArchiveTestResultsMode();
                    boolean archiveTestResult = false;

                    //check for the new html report
                    FilePath htmlReport = new FilePath(reportFolder, "run_results.html");
                    FilePath rrvReport = new FilePath(reportFolder, "Results.xml");
                    if (htmlReport.exists()) {
                        reportIsHtml = true;
                        String htmlReportDir = reportFolder.getRemote();

                        ReportMetaData reportMetaData = new ReportMetaData();
                        reportMetaData.setFolderPath(htmlReportDir);
                        reportMetaData.setIsHtmlReport(true);
                        reportMetaData.setDateTime(testDateTime);
                        reportMetaData.setStatus(testStatus);

                        File testFileFullName = new File(testFolderPath);
                        String testName = org.apache.commons.io.FilenameUtils
                                .getName(testFileFullName.getPath());
                        String resourceUrl = "artifact/UFTReport/" + testName;
                        reportMetaData.setResourceURL(resourceUrl);
                        reportMetaData.setDisPlayName(testName); // use the name, not the full path
                        //don't know reportMetaData's URL path yet, we will generate it later.
                        ReportInfoToCollect.add(reportMetaData);

                        listener.getLogger().println(
                                "add html report info to ReportInfoToCollect: " + "[date]" + testDateTime);
                    }

                    archiveTestResult = isArchiveTestResult(testStatus, archiveTestResultMode);

                    if (archiveTestResult && rrvReport.exists()) {

                        if (reportFolder.exists()) {

                            FilePath testFolder = new FilePath(projectWS.getChannel(), testFolderPath);

                            String zipFileName = getUniqueZipFileNameInFolder(zipFileNames,
                                    testFolder.getName());
                            zipFileNames.add(zipFileName);

                            listener.getLogger().println("Zipping report folder: " + reportFolderPath);

                            ByteArrayOutputStream outstr = new ByteArrayOutputStream();

                            //don't use FileFilter for zip, or it will cause bug when files are on slave
                            reportFolder.zip(outstr);

                            /*
                                     * I did't use copyRecursiveTo or copyFrom due to
                             * bug in
                             * jekins:https://issues.jenkins-ci.org/browse
                             * /JENKINS-9189 //(which is cleaimed to have been
                             * fixed, but not. So I zip the folder to stream and
                             * copy it to the master.
                             */

                            ByteArrayInputStream instr = new ByteArrayInputStream(outstr.toByteArray());

                            FilePath archivedFile = new FilePath(new FilePath(artifactsDir), zipFileName);
                            archivedFile.copyFrom(instr);
                            listener.getLogger().println("copy from slave to master: " + archivedFile);
                            outstr.close();
                            instr.close();

                            // add to Report list
                            ReportMetaData reportMetaData = new ReportMetaData();
                            reportMetaData.setIsHtmlReport(false);
                            // reportMetaData.setFolderPath(htmlReportDir); //no need for RRV
                            File testFileFullName = new File(testFolderPath);
                            String testName = testFileFullName.getName();
                            reportMetaData.setDisPlayName(testName); // use the name, not the full path
                            String zipFileUrlName = "artifact/" + zipFileName;
                            reportMetaData.setUrlName(zipFileUrlName); // for RRV, the file url and resource url are the same.
                            reportMetaData.setResourceURL(zipFileUrlName);
                            reportMetaData.setDateTime(testDateTime);
                            reportMetaData.setStatus(testStatus);
                            ReportInfoToCollect.add(reportMetaData);

                        } else {
                            listener.getLogger().println("No report folder was found in: " + reportFolderPath);
                        }
                    }

                }
            }

            if (reportIsHtml && !ReportInfoToCollect.isEmpty()) {

                listener.getLogger().println("begin to collectAndPrepareHtmlReports");
                collectAndPrepareHtmlReports(build, listener, ReportInfoToCollect, runWorkspace);
            }

            if (!ReportInfoToCollect.isEmpty()) {
                // serialize report metadata
                File reportMetaDataXmlFile = new File(artifactsDir.getParent(), REPORTMETADATE_XML);
                String reportMetaDataXml = reportMetaDataXmlFile.getAbsolutePath();
                writeReportMetaData2XML(ReportInfoToCollect, reportMetaDataXml, listener);

                // Add UFT report action
                try {
                    listener.getLogger().println("Adding a report action to the current build.");
                    HtmlBuildReportAction reportAction = new HtmlBuildReportAction(build);
                    build.addAction(reportAction);

                } catch (IOException | SAXException | ParserConfigurationException ex) {
                    listener.getLogger().println("a problem adding action: " + ex);
                }
            }
        }
    }
}

From source file:autohit.creator.compiler.SimCompiler.java

/**
 *  handle a Input/*from  w  w w.  j a v  a 2  s  . co  m*/
 *  MICROCODE
 * 1- if (eval exists)         i.eval(eval)
 * 2-    else if (value exists) i.load(value)
 * 3-    else (buffer exists)   i.reduce(buffer)
 * 4-    else                !!ERROR   
 * 5- i.new(name)
 */
private void handleInput(Element en) {

    String name = en.getAttribute(ATTR_NAME);

    //runtimeDebug("handleInput  name=" + name);

    // 1- if (eval exists)         i.eval(eval)
    if (en.hasAttribute(ATTR_EVALUATOR)) {
        this.emitEval(en.getAttribute(ATTR_EVALUATOR));

        // 2- else if (value exists) i.load(value)    
    } else if (en.hasAttribute(ATTR_VALUE)) {
        this.emitLoad(en.getAttribute(ATTR_VALUE));

        // 3- else (buffer exists)   i.reduce(buffer) 
    } else if (en.hasAttribute(ATTR_BUFFER)) {
        this.emitReduce(en.getAttribute(ATTR_BUFFER));

        // 4- else                !!ERROR   
    } else {
        runtimeError("ERROR.  No source given for INPUT.");
        return;
    }

    // 5- i.new(name)
    this.emitNew(name);
}

From source file:autohit.creator.compiler.SimCompiler.java

/**
 *  handle a Set//  w ww .jav  a  2  s. c  om
 *  MICROCODE
 * 1- if (eval exists)         i.eval(eval)
 * 2-     else if (ref exists)   i.fetch(ref)
 * 3-    else if (value exists) i.load(value)
 * 4-    else (buffer exists)   i.reduce(buffer)
 * 5-    else                !!ERROR   
 * 6- if (new exists)         i.new(name)
 * 7-    else               i.store(name)
 */
private void handleSet(Element en) {

    String name = en.getAttribute(ATTR_NAME);

    //runtimeDebug("handleSet  name=" + name);

    // 1- if (eval exists)         i.eval(eval)
    if (en.hasAttribute(ATTR_EVALUATOR)) {
        this.emitEval(en.getAttribute(ATTR_EVALUATOR));

        // 2- else if (ref exists)   i.fetch(ref)   
    } else if (en.hasAttribute(ATTR_REFERENCE)) {
        this.emitFetch(en.getAttribute(ATTR_REFERENCE));

        // 3- else if (value exists) i.load(value)    
    } else if (en.hasAttribute(ATTR_VALUE)) {
        this.emitLoad(en.getAttribute(ATTR_VALUE));

        // 4- else (buffer exists)   i.reduce(buffer) 
    } else if (en.hasAttribute(ATTR_BUFFER)) {
        this.emitReduce(en.getAttribute(ATTR_BUFFER));

        // 5- else                !!ERROR   
    } else {
        runtimeError("ERROR.  No source given for SET.");
        return;
    }

    // 6- if (new exists)         i.new(name)
    if (en.hasAttribute(ATTR_NEW)) {
        this.emitNew(name);

        // 7-    else      i.store(name)
    } else {
        this.emitStore(name);
    }
}

From source file:com.concursive.connect.web.modules.api.beans.TransactionItem.java

/**
 * Sets the action attribute of the TransactionItem object
 *
 * @param objectElement The new action value
 *///  w w  w .  j  a  v  a2  s  .  c o  m
public void setAction(Element objectElement) {
    if (objectElement.hasAttributes()) {
        //Get the action for this item (Insert, Update, Delete, Select, etc.)
        String thisAction = objectElement.getAttribute("type");
        if (thisAction == null || thisAction.trim().equals("")) {
            thisAction = objectElement.getAttribute("action");
        }
        this.setAction(thisAction);
        //If specified, get the client's next id that should be used when
        //sending insert statements to the client
        String thisIdentity = objectElement.getAttribute("identity");
        try {
            identity = Integer.parseInt(thisIdentity);
        } catch (Exception e) {
        }
        // Enable paging
        if (objectElement.hasAttribute("offset") || objectElement.hasAttribute("items")
                || objectElement.hasAttribute("sort")) {
            // Ready for a new pagedListInfo
            pagedListInfo = new PagedListInfo();
            // If specified, get the number of max records to return, and the offset
            // to begin returning records at -- useful for large datasets
            String thisCurrentOffset = objectElement.getAttribute("offset");
            String thisItemsPerPage = objectElement.getAttribute("items");
            if (StringUtils.hasText(thisCurrentOffset) || StringUtils.hasText(thisItemsPerPage)) {
                pagedListInfo.setItemsPerPage(thisItemsPerPage);
                pagedListInfo.setCurrentOffset(thisCurrentOffset);
            }
            // Determine the sort order
            if (objectElement.hasAttribute("sort")) {
                pagedListInfo.setDefaultSort(objectElement.getAttribute("sort"),
                        objectElement.getAttribute("sortOrder"));
            }
        }
        // See if the primary key of this object should be exposed to other
        // items within the same transaction
        shareKey = "true".equals(objectElement.getAttribute("shareKey"));
        cached = "true".equals(objectElement.getAttribute("cached"));
    }
}