Example usage for javax.xml.parsers ParserConfigurationException printStackTrace

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

Introduction

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

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);/*from w w w  .  j av a2 s.  c  om*/
    spf.setValidating(true);
    System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ") + "be namespace aware");
    System.out.println("Parser will " + (spf.isValidating() ? "" : "not ") + "validate XML");

    SAXParser parser = null;
    try {
        parser = spf.newSAXParser();
    } catch (ParserConfigurationException e) {
        e.printStackTrace(System.err);
    } catch (SAXException e) {
        e.printStackTrace(System.err);
    }
    System.out.println("Parser object is: " + parser);
}

From source file:de.interactive_instruments.ShapeChange.ShapeChangeResult.java

public ShapeChangeResult(Options o) {
    init();/*from  www  .j  a  va 2 s .  c  om*/

    options = o;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        dbf.setAttribute(Options.JAXP_SCHEMA_LANGUAGE, Options.W3C_XML_SCHEMA);
        DocumentBuilder db = dbf.newDocumentBuilder();
        document = db.newDocument();

        root = document.createElementNS(Options.SCRS_NS, "ShapeChangeResult");
        document.appendChild(root);
        root.setAttribute("resultCode", "0");
        root.setAttribute("xmlns:r", Options.SCRS_NS);
        root.setAttribute("start", (new Date()).toString());

        String version = "[dev]";
        InputStream stream = getClass().getResourceAsStream("/sc.properties");
        if (stream != null) {
            Properties properties = new Properties();
            properties.load(stream);
            version = properties.getProperty("sc.version");
        }
        root.setAttribute("version", version);

        messages = document.createElementNS(Options.SCRS_NS, "Messages");
        root.appendChild(messages);

        resultFiles = document.createElementNS(Options.SCRS_NS, "Results");
        root.appendChild(resultFiles);
    } catch (ParserConfigurationException e) {
        System.err.println("Bootstrap Error: XML parser was unable to be configured.");
        String m = e.getMessage();
        if (m != null) {
            System.err.println(m);
        }
        e.printStackTrace(System.err);
        System.exit(1);
    } catch (Exception e) {
        System.err.println("Bootstrap Error: " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }

    outputFormat.setProperty("encoding", "UTF-8");
    outputFormat.setProperty("indent", "yes");
    outputFormat.setProperty("{http://xml.apache.org/xalan}indent-amount", "2");
}

From source file:de.interactive_instruments.ShapeChange.Target.FeatureCatalogue.FeatureCatalogue.java

protected Document createDocument() {
    Document document = null;/*w ww . j  a  va 2  s . c om*/
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        document = db.newDocument();
    } catch (ParserConfigurationException e) {
        result.addFatalError(null, 2);
        String m = e.getMessage();
        if (m != null) {
            result.addFatalError(m);
        }
        e.printStackTrace(System.err);
        System.exit(1);
    } catch (Exception e) {
        result.addFatalError(e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }

    return document;
}

From source file:org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor.java

public void processMavenSpyLogs(StepContext context, FilePath mavenSpyLogFolder, List<MavenPublisher> options)
        throws IOException, InterruptedException {
    FilePath[] mavenSpyLogsList = mavenSpyLogFolder.list("maven-spy-*.log");
    LOGGER.log(Level.FINE, "Found {0} maven execution reports in {1}",
            new Object[] { mavenSpyLogsList.length, mavenSpyLogFolder });

    TaskListener listener = context.get(TaskListener.class);
    if (listener == null) {
        LOGGER.warning("TaskListener is NULL, default to stderr");
        listener = new StreamBuildListener((OutputStream) System.err);
    }/*from  ww  w .  j  av  a 2 s  .co m*/
    FilePath workspace = context.get(FilePath.class);

    DocumentBuilder documentBuilder;
    try {
        documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("Failure to create a DocumentBuilder", e);
    }

    for (FilePath mavenSpyLogs : mavenSpyLogsList) {
        try {
            if (LOGGER.isLoggable(Level.FINE)) {
                listener.getLogger()
                        .println("[withMaven]  Evaluate Maven Spy logs: " + mavenSpyLogs.getRemote());
            }
            InputStream mavenSpyLogsInputStream = mavenSpyLogs.read();
            if (mavenSpyLogsInputStream == null) {
                throw new IllegalStateException("InputStream for " + mavenSpyLogs.getRemote() + " is null");
            }

            FilePath archiveJenkinsMavenEventSpyLogs = workspace.child(".archive-jenkins-maven-event-spy-logs");
            if (archiveJenkinsMavenEventSpyLogs.exists()) {
                LOGGER.log(Level.FINE, "Archive Jenkins Maven Event Spy logs {0}", mavenSpyLogs.getRemote());
                new JenkinsMavenEventSpyLogsPublisher().process(context, mavenSpyLogs);
            }

            Element mavenSpyLogsElt = documentBuilder.parse(mavenSpyLogsInputStream).getDocumentElement();

            List<MavenPublisher> mavenPublishers = MavenPublisher.buildPublishersList(options, listener);
            for (MavenPublisher mavenPublisher : mavenPublishers) {
                String skipFileName = mavenPublisher.getDescriptor().getSkipFileName();
                if (Boolean.TRUE.equals(mavenPublisher.isDisabled())) {
                    listener.getLogger().println("[withMaven] Skip '"
                            + mavenPublisher.getDescriptor().getDisplayName() + "' disabled by configuration");
                } else if (StringUtils.isNotEmpty(skipFileName) && workspace.child(skipFileName).exists()) {
                    listener.getLogger()
                            .println("[withMaven] Skip '" + mavenPublisher.getDescriptor().getDisplayName()
                                    + "' disabled by marker file '" + skipFileName + "'");
                } else {
                    if (LOGGER.isLoggable(Level.FINE)) {
                        listener.getLogger().println(
                                "[withMaven] Run '" + mavenPublisher.getDescriptor().getDisplayName() + "'...");
                    }
                    try {
                        mavenPublisher.process(context, mavenSpyLogsElt);
                    } catch (IOException | RuntimeException e) {
                        PrintWriter error = listener
                                .error("[withMaven] WARNING Exception executing Maven reporter '"
                                        + mavenPublisher.getDescriptor().getDisplayName() + "' / "
                                        + mavenPublisher.getDescriptor().getId() + "."
                                        + " Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org ");
                        e.printStackTrace(error);

                    }
                }
            }

        } catch (SAXException e) {
            Run run = context.get(Run.class);
            if (run.getActions(InterruptedBuildAction.class).isEmpty()) {
                listener.error(
                        "[withMaven] WARNING Exception parsing the logs generated by the Jenkins Maven Event Spy "
                                + mavenSpyLogs + ", ignore file. "
                                + " Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org ");
            } else {
                // job has been aborted (see InterruptedBuildAction)
                listener.error(
                        "[withMaven] WARNING logs generated by the Jenkins Maven Event Spy " + mavenSpyLogs
                                + " are invalid, probably due to the interruption of the job, ignore file.");
            }
            listener.error(e.toString());
        } catch (Exception e) {
            PrintWriter errorWriter = listener.error(
                    "[withMaven] WARNING Exception processing the logs generated by the Jenkins Maven Event Spy "
                            + mavenSpyLogs + ", ignore file. "
                            + " Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org ");
            e.printStackTrace(errorWriter);
        }
    }
    FilePath[] mavenSpyLogsInterruptedList = mavenSpyLogFolder.list("maven-spy-*.log.tmp");
    if (mavenSpyLogsInterruptedList.length > 0) {
        listener.getLogger()
                .print("[withMaven] One or multiple Maven executions have been ignored by the "
                        + "Jenkins Pipeline Maven Plugin because they have been interrupted before completion "
                        + "(" + mavenSpyLogsInterruptedList.length + "). See ");
        listener.hyperlink(
                "https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin#PipelineMavenPlugin-mavenExecutionInterrupted",
                "Pipeline Maven Plugin FAQ");
        listener.getLogger().println(" for more details.");
        if (LOGGER.isLoggable(Level.FINE)) {
            for (FilePath mavenSpyLogsInterruptedLogs : mavenSpyLogsInterruptedList) {
                listener.getLogger().print("[withMaven] Ignore: " + mavenSpyLogsInterruptedLogs.getRemote());
            }
        }
    }
}

From source file:org.openmicroscopy.shoola.env.data.model.FileObject.java

/**
 * Parses the image's description.//from w w  w  . j a v a  2s  .c o  m
 *
 * @param xmlStr The string to parse.
 * @return See above.
 */
private Document xmlParser(String xmlStr) throws SAXException {
    InputSource stream = new InputSource();
    stream.setCharacterStream(new StringReader(xmlStr));
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    DocumentBuilder builder;
    Document doc = null;
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        doc = builder.parse(stream);
    } catch (ParserConfigurationException e) {
        e.printStackTrace(pw);
        IJ.log(sw.toString());
    } catch (IOException e) {
        e.printStackTrace(pw);
        IJ.log(sw.toString());
    } finally {
        try {
            sw.close();
        } catch (IOException e) {
            IJ.log("I/O Exception:" + e.getMessage());
        }
        pw.close();
    }
    return doc;
}