Example usage for javax.xml.parsers ParserConfigurationException getMessage

List of usage examples for javax.xml.parsers ParserConfigurationException getMessage

Introduction

In this page you can find the example usage for javax.xml.parsers ParserConfigurationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.zaproxy.zap.extension.exportreport.Export.ReportExport.java

public static File JSON_EXPORT(ViewDelegate view, Logger logger, String absolutePath, String p_result,
        String p_source) {//  w ww .  j a va2  s .co  m
    int PRETTY_PRINT_INDENT_FACTOR = 4;

    File fXmlFile = new File(p_source);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = null;
    try {
        dBuilder = dbFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("exportreport.message.error.parser"));
    }
    Document doc = null;
    try {
        doc = dBuilder.parse(fXmlFile);
    } catch (SAXException e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("exportreport.message.error.sax"));
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("exportreport.message.error.io"));
    }
    String temp = getStringFromDoc(doc);
    String jsonPrettyPrintString = null;
    try {
        JSONObject xmlJSONObj = XML.toJSONObject(temp);
        jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
    } catch (JSONException e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("exportreport.message.error.json"));
    }
    File f = null;
    try {
        f = write(p_result, jsonPrettyPrintString, false);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("exportreport.message.error.exception"));
    }
    return f;
}

From source file:perflab.LoadrunnerWrapper.java

/**
 * @param transactions - ArrayList of LoadRunnerTransaction objects
 * @param summaryFile  - location of xml summary file to be generated out of transaction objects in jUnit format
 * @return//  w w w. j  ava  2  s  .  c  om
 */
private void generatejUnitReport(ArrayList<LoadRunnerTransaction> transactions, String summaryFile) {

    getLog().info("Transformation to jUnit XML started ...");

    String stringReport = "";

    try {
        /*
         * http://llg.cubic.org/docs/junit/
         <testsuite tests="3" time="42.5">
           <testcase classname="ZZZ_1" name="ZZZ_1" time="10.1"/>
           <testcase classname="ZZZ_2" name="ZZZ_2" time="11.7"/>
           <testcase classname="ZZZ_3" name="ZZZ_3" time="12.2">
            <!--failure type="NotEnoughFoo"> too slow </failure-->
           </testcase>
        </testsuite>
         */

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        org.w3c.dom.Document doc = (org.w3c.dom.Document) docBuilder.newDocument();
        org.w3c.dom.Element testsuiteElement = (org.w3c.dom.Element) doc.createElement("testsuite");
        testsuiteElement.setAttribute("tests", String.valueOf(transactions.size()));
        //testsuiteElement.setAttribute("time", "total test duration");
        doc.appendChild(testsuiteElement);

        ////////////////////////////////////////////////////////////////////////////

        for (LoadRunnerTransaction tr : this.transactions) {

            getLog().info("Dump " + tr.getName());

            org.w3c.dom.Element testcaseElement = doc.createElement("testcase");
            testcaseElement.setAttribute("classname", "load.ResponseTime");
            testcaseElement.setAttribute("name", tr.getName());
            testcaseElement.setAttribute("time", String.valueOf(tr.getAvgRT()));

            testsuiteElement.appendChild(testcaseElement);
        }

        ////////////////////////////////////////////////////////////////////////////
        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

        DOMSource source = new DOMSource(doc);

        File lr_report = new File(summaryFile);
        StreamResult result = new StreamResult(lr_report);

        transformer.transform(source, result);

        getLog().info("File saved in " + lr_report.getAbsolutePath());

    } catch (ParserConfigurationException pce) {
        getLog().error(pce.getMessage());
        pce.printStackTrace();
    } catch (TransformerException tfe) {
        getLog().error(tfe.getMessage());
        tfe.printStackTrace();
    }
}

From source file:perflab.LoadrunnerWrapper.java

/**
 * @param transactions - ArrayList of LoadRunnerTransaction objects
 * @return// w  w  w .  java 2s .  c  o m
 */
private void generatePerfPublisherReport(ArrayList<LoadRunnerTransaction> transactions, String xmlFile) {
    getLog().info("Transformation to XML started ...");
    try {

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        org.w3c.dom.Document doc = (org.w3c.dom.Document) docBuilder.newDocument();
        org.w3c.dom.Element reportElement = (org.w3c.dom.Element) doc.createElement("report");
        doc.appendChild(reportElement);

        ////////////////////////////////////////////////////////////////////////////

        //<categories>
        //   <category name="memory" scale="mb">
        //       <observations>
        //           <observation name="Server 1">100</observation>
        //           <observation name="Server 2">200</observation>
        //       </observations>
        //   </category>

        //   <category name="disk" scale="gb">
        //       <observations>
        //           <observation name="Server 1">41</observation>
        //           <observation name="Server 2">58</observation>
        //       </observations>
        //   </category>
        //</categories>

        // start element
        org.w3c.dom.Element startElement = (org.w3c.dom.Element) doc.createElement("start");
        reportElement.appendChild(startElement);

        // date element
        org.w3c.dom.Element date = (org.w3c.dom.Element) doc.createElement("date");
        startElement.appendChild(date);

        date.setAttribute("format", "YYYYMMDD");
        date.setAttribute("val", "20100922");

        // time element
        org.w3c.dom.Element time = (org.w3c.dom.Element) doc.createElement("date");
        startElement.appendChild(time);

        time.setAttribute("format", "HHMMSS");
        time.setAttribute("val", "215935");

        ////////////////////////////////////////////////////////////////////////////

        //<test name="Smoke test" executed="yes" categ="Smoke test">

        //<description>Tests if ATE LAN socket and communication works.</description>

        //<result>
        //   <success passed="yes" state ="100" hasTimedOut="no" />
        //   <compiletime unit="s" mesure="0" isRelevant="yes" />
        //   <performance unit="%" mesure="0" isRelevant="yes" />
        //   <executiontime unit="s" mesure="12" isRelevant="yes" />
        //   <metrics>
        //      <006_My_Benefits unit="sec" mesure="0.115" isRelevant="yes"/>
        //      <007_My_Timesheet unit="sec" mesure="1.247" isRelevant="yes"/>
        //   </metrics>
        //</result>
        //</test>
        //</report>

        ////////////////////////////////////////////////////////////////////////////
        // test element
        org.w3c.dom.Element testElement = doc.createElement("test");
        reportElement.appendChild(testElement);

        testElement.setAttribute("name", "Smoke test");
        testElement.setAttribute("executed", "yes");
        testElement.setAttribute("categ", "Smoke test");

        // description element
        org.w3c.dom.Element descriptionElement = doc.createElement("description");
        descriptionElement.appendChild(doc.createTextNode("This is the best Load test ever executed..."));
        reportElement.appendChild(descriptionElement);

        ////////////////////////////////////////////////////////////////////////////
        // result
        org.w3c.dom.Element resultElement = doc.createElement("result");
        reportElement.appendChild(resultElement);

        org.w3c.dom.Element successElement = doc.createElement("success");
        resultElement.appendChild(successElement);

        org.w3c.dom.Element compiletimeElement = doc.createElement("compiletime");
        resultElement.appendChild(compiletimeElement);

        org.w3c.dom.Element performanceElement = doc.createElement("performance");
        resultElement.appendChild(performanceElement);

        org.w3c.dom.Element executiontimeElement = doc.createElement("executiontime");
        resultElement.appendChild(executiontimeElement);

        org.w3c.dom.Element metricsElement = doc.createElement("metrics");
        resultElement.appendChild(metricsElement);

        ////////////////////////////////////////////////////////////////////////////

        for (LoadRunnerTransaction tr : this.transactions) {
            //<006_My_Benefits unit="sec" mesure="0.115" isRelevant="yes"/>
            String trName = "tr_" + tr.getName();
            getLog().info("Dump " + trName);

            org.w3c.dom.Element trElement = doc.createElement(trName);
            trElement.setAttribute("unit", "sec");
            trElement.setAttribute("mesure", String.valueOf(tr.getAvgRT()));
            trElement.setAttribute("isRelevant", "yes");
            metricsElement.appendChild(trElement);
        }

        ////////////////////////////////////////////////////////////////////////////
        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

        DOMSource source = new DOMSource(doc);

        File lr_report = new File(xmlFile);
        StreamResult result = new StreamResult(lr_report);

        transformer.transform(source, result);

        getLog().info("File saved in " + lr_report.getAbsolutePath());

    } catch (ParserConfigurationException pce) {
        getLog().error(pce.getMessage());
        pce.printStackTrace();
    } catch (TransformerException tfe) {
        getLog().error(tfe.getMessage());
        tfe.printStackTrace();
    }
}

From source file:perflab.loadrunnerwrapperjenkins.LoadRunnerWrapper.java

/**
 * @param transactions - ArrayList of LoadRunnerTransaction objects
 * @return//from   ww w.j a  v  a 2  s.c  o  m
 */
private String generatejUnitReport(ArrayList<LoadRunnerTransaction> transactions) {
    String stringReport = "";
    logger.println("Transformation to jUnit XML started ...");
    try {
        /*
         * http://llg.cubic.org/docs/junit/
         *<testsuite tests="3" time="42.5"> 
         *    <testcase classname="ZZZ_1" name="ZZZ_1" time="10.1"/>
         *  <testcase classname="ZZZ_2" name="ZZZ_2" time="11.7"/>
         *  <testcase classname="ZZZ_3" name="ZZZ_3" time="12.2">
         *  <!--failure type="NotEnoughFoo"> too slow </failure-->
         *  </testcase> 
         *</testsuite>
         */

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        org.w3c.dom.Document doc = (org.w3c.dom.Document) docBuilder.newDocument();
        org.w3c.dom.Element testsuiteElement = (org.w3c.dom.Element) doc.createElement("testsuite");
        testsuiteElement.setAttribute("tests", String.valueOf(transactions.size()));
        // testsuiteElement.setAttribute("time", "total test duration");
        doc.appendChild(testsuiteElement);

        // //////////////////////////////////////////////////////////////////////////

        for (LoadRunnerTransaction tr : this.transactions) {

            logger.println("Dump " + tr.getName());

            org.w3c.dom.Element testcaseElement = doc.createElement("testcase");
            //testcaseElement.setAttribute("classname", tr.getName());
            testcaseElement.setAttribute("classname",
                    "load." + new File(this.loadRunnerScenario).getName().replace(".lrs", ""));
            testcaseElement.setAttribute("name", tr.getName());
            testcaseElement.setAttribute("time", String.valueOf(tr.getAvgRT()));

            testsuiteElement.appendChild(testcaseElement);
        }

        // //////////////////////////////////////////////////////////////////////////
        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

        stringReport = this.getStringFromDoc(doc);

    } catch (ParserConfigurationException pce) {
        logger.println(pce.getMessage());
        pce.printStackTrace();
    } catch (TransformerException tfe) {
        logger.println(tfe.getMessage());
        tfe.printStackTrace();
    }
    return stringReport;
}

From source file:perflab.loadrunnerwrapperjenkins.LoadRunnerWrapper.java

/**
 * @param transactions - ArrayList of LoadRunnerTransaction objects
 * //@param summaryFile  - location of SCV summary file to be generated out of
 *                     transaction objects in PerfPublisher Report format
 * @return/*  w  w w  .  j  a  v  a2 s  . c om*/
 */
private String generatePerfPublisherReport(ArrayList<LoadRunnerTransaction> transactions) {

    logger.println("Transformation to XML started ...");
    String stringReport = "";
    try {

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        org.w3c.dom.Document doc = (org.w3c.dom.Document) docBuilder.newDocument();
        org.w3c.dom.Element reportElement = (org.w3c.dom.Element) doc.createElement("report");
        doc.appendChild(reportElement);

        // //////////////////////////////////////////////////////////////////////////

        // <categories>
        // <category name="memory" scale="mb">
        // <observations>
        // <observation name="Server 1">100</observation>
        // <observation name="Server 2">200</observation>
        // </observations>
        // </category>

        // <category name="disk" scale="gb">
        // <observations>
        // <observation name="Server 1">41</observation>
        // <observation name="Server 2">58</observation>
        // </observations>
        // </category>
        // </categories>

        // start element
        org.w3c.dom.Element startElement = (org.w3c.dom.Element) doc.createElement("start");
        reportElement.appendChild(startElement);

        // date element
        org.w3c.dom.Element date = (org.w3c.dom.Element) doc.createElement("date");
        startElement.appendChild(date);

        date.setAttribute("format", "YYYYMMDD");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMdd");
        date.setAttribute("val", sdf.format(startTime));

        // time element
        org.w3c.dom.Element time = (org.w3c.dom.Element) doc.createElement("date");
        startElement.appendChild(time);

        time.setAttribute("format", "HHMMSS");
        SimpleDateFormat stf = new SimpleDateFormat("hhmmss");
        time.setAttribute("val", stf.format(startTime));

        // //////////////////////////////////////////////////////////////////////////

        // <test name="Smoke test" executed="yes" categ="Smoke test">

        // <description>Tests if ATE LAN socket and communication
        // works.</description>

        // <result>
        // <success passed="yes" state ="100" hasTimedOut="no" />
        // <compiletime unit="s" mesure="0" isRelevant="yes" />
        // <performance unit="%" mesure="0" isRelevant="yes" />
        // <executiontime unit="s" mesure="12" isRelevant="yes" />
        // <metrics>
        // <006_My_Benefits unit="sec" mesure="0.115" isRelevant="yes"/>
        // <007_My_Timesheet unit="sec" mesure="1.247" isRelevant="yes"/>
        // </metrics>
        // </result>
        // </test>
        // </report>

        // //////////////////////////////////////////////////////////////////////////
        // test element
        org.w3c.dom.Element testElement = doc.createElement("test");
        reportElement.appendChild(testElement);

        testElement.setAttribute("name", "Load test");
        testElement.setAttribute("executed", "yes");
        testElement.setAttribute("categ", "Load test");

        // description element
        org.w3c.dom.Element descriptionElement = doc.createElement("description");
        descriptionElement.appendChild(doc.createTextNode("This is the best Load test ever executed..."));
        reportElement.appendChild(descriptionElement);

        // //////////////////////////////////////////////////////////////////////////
        // result
        org.w3c.dom.Element resultElement = doc.createElement("result");
        reportElement.appendChild(resultElement);

        org.w3c.dom.Element successElement = doc.createElement("success");
        resultElement.appendChild(successElement);

        org.w3c.dom.Element compiletimeElement = doc.createElement("compiletime");
        resultElement.appendChild(compiletimeElement);

        org.w3c.dom.Element performanceElement = doc.createElement("performance");
        resultElement.appendChild(performanceElement);

        org.w3c.dom.Element executiontimeElement = doc.createElement("executiontime");
        resultElement.appendChild(executiontimeElement);

        org.w3c.dom.Element metricsElement = doc.createElement("metrics");
        resultElement.appendChild(metricsElement);

        // //////////////////////////////////////////////////////////////////////////

        for (LoadRunnerTransaction tr : this.transactions) {
            // <006_My_Benefits unit="sec" mesure="0.115" isRelevant="yes"/>
            String trName = "tr_" + tr.getName();
            logger.println("Dump " + trName);

            org.w3c.dom.Element trElement = doc.createElement(trName);
            trElement.setAttribute("unit", "sec");
            trElement.setAttribute("mesure", String.valueOf(tr.getAvgRT()));
            trElement.setAttribute("isRelevant", "yes");
            metricsElement.appendChild(trElement);
        }

        // //////////////////////////////////////////////////////////////////////////
        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

        stringReport = this.getStringFromDoc(doc);

    } catch (ParserConfigurationException pce) {
        logger.println(pce.getMessage());
        pce.printStackTrace();
    } catch (TransformerException tfe) {
        logger.println(tfe.getMessage());
        tfe.printStackTrace();
    }
    return stringReport;
}

From source file:petascope.util.XMLUtil.java

public static void init() {
    if (factory != null) {
        return;/*from   w w w.j a  va  2  s.com*/
    }
    System.setProperty("javax.xml.parsers.SAXParserFactory",
            "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
    factory = SAXParserFactory.newInstance();

    try {
        factory.setFeature(SET_FEATURE_XXE_FALSE, false);
    } catch (ParserConfigurationException ex) {
        //If feature does not exist, then no XXE support anyway so there is nothing to do
        log.warn("Set feature XXE False: " + ex.getMessage());
        log.debug(ExceptionUtils.getStackTrace(ex));
    } catch (SAXNotRecognizedException ex) {
        //If feature does not exist then,no XXE support anyway so there is nothing to do
        log.warn("Set feature XXE False: " + ex.getMessage());
        log.debug(ExceptionUtils.getStackTrace(ex));
    } catch (SAXNotSupportedException ex) {
        //If feature does not exist,then no XXE support anyway so there is nothing to do
        log.warn("Set feature XXE False: " + ex.getMessage());
        log.debug(ExceptionUtils.getStackTrace(ex));
    }

    factory.setNamespaceAware(true);
    factory.setValidating(true);
    builder = new MyBuilder(false);
    builder.get();
}

From source file:petascope.util.XMLUtil.java

public static org.w3c.dom.Document convert(Document n) {
    DocumentBuilder db = null;/*  www .j  a  v a2  s.  co  m*/
    try {
        db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return DOMConverter.convert(n, db.getDOMImplementation());
    } catch (ParserConfigurationException exc) {
        System.err.println(exc.getMessage());
        return null;
    }
}

From source file:pt.ist.fenixedu.teacher.servlet.AnnualTeachingCreditsDocumentFilter.java

protected ByteArrayOutputStream getAnnualTeacherCreditsDocument(ServletRequest arg0, ServletResponse arg1,
        FilterChain arg2, Teacher teacher, ExecutionYear executionYear) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) arg0;
    ResponseWrapper response = (ResponseWrapper) arg1;
    request.setAttribute("teacher", teacher);
    request.setAttribute("executionYear", executionYear);
    arg2.doFilter(arg0, arg1);// w  w  w.j av  a 2s.co m
    String responseHtml = clean(response.getContent());
    DocumentBuilder builder;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IOException(e.getMessage());
    }
    Document doc;
    try {
        doc = builder.parse(new ByteArrayInputStream(responseHtml.getBytes()));
    } catch (SAXException e) {
        throw new IOException(e.getMessage());
    }
    patchLinks(doc, request);
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(doc, "");
    renderer.layout();
    ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
    try {
        renderer.createPDF(pdfStream);
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
    return pdfStream;
}

From source file:sce.Main.java

public String scheduleXML(JSONObject jsonObject) {
    try {//from w  w  w  . j av  a2  s.  c o  m
        String xml = (String) jsonObject.get("xml");
        String xmlpath = "/tmp/job.xml";
        CascadingClassLoadHelper helper = new CascadingClassLoadHelper();
        helper.initialize();
        XMLSchedulingDataProcessor proc = new XMLSchedulingDataProcessor(helper);
        //InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
        //proc.processStreamAndScheduleJobs(stream, xml, sched);
        //InputSource inputSource = new InputSource(new StringReader(xml));
        //proc.process(inputSource);
        /*FileWriter fstream = new FileWriter(xmlpath, false);
         BufferedWriter out = new BufferedWriter(fstream);
         out.write(xml);
         out.close();*/
        proc.processFileAndScheduleJobs(xmlpath, sched);
        return "true";
    } catch (ParserConfigurationException e) {
        return e.getMessage();
    } catch (SchedulerException e) {
        return e.getMessage();
    } catch (ClassNotFoundException e) {
        return e.getMessage();
    } catch (ParseException e) {
        return e.getMessage();
    } catch (FileNotFoundException e) {
        return e.getMessage();
    } catch (Exception e) {
        return e.getMessage();
    }
}

From source file:shnakkydoodle.measuring.provider.MetricsProviderSQLServer.java

/**
 * Get all scripts to be run to create logging db tables with procs and
 * constraints Execute each scripts//from  w  w  w .j ava2s  .  c  o  m
 */
private void ProcessConfigFile() {

    try {
        InputStream in = getClass()
                .getResourceAsStream("shnakkydoodle/measuring/provider/resources/config.xml");

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder;
        dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(in);
        doc.getDocumentElement().normalize();

        NodeList nList = doc.getElementsByTagName("resourcepath");

        for (int temp = 0; temp < nList.getLength(); temp++) {

            Node nNode = nList.item(temp);

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

                Element eElement = (Element) nNode;
                String resourcePath = eElement.getTextContent();

                // Read in script and execute
                if (ReadExecuteScript(resourcePath)) {
                    System.out.println("Successfully created: " + resourcePath);
                } else {
                    System.err.println("Failed on creating: " + resourcePath);
                }
            }
        }

    } catch (ParserConfigurationException e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        e.printStackTrace();
    } catch (SAXException e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        e.printStackTrace();
    }
}