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.dklisiaris.downtown.helper.XMLParser.java

public Document getDomElement(String xml) {
    Document doc = null;/*  w  ww.ja  v  a  2s  .  c o  m*/
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {

        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xml));
        doc = db.parse(is);

    } catch (ParserConfigurationException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (SAXException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    } catch (IOException e) {
        Log.e("Error: ", e.getMessage());
        return null;
    }
    // return DOM
    return doc;
}

From source file:jetbrains.buildServer.clouds.azure.connector.AzureApiConnector.java

public OperationResponse stopVM(@NotNull final AzureCloudInstance instance)
        throws ServiceException, IOException {
    final VirtualMachineOperations vmOperations = myClient.getVirtualMachinesOperations();
    final AzureCloudImageDetails imageDetails = instance.getImage().getImageDetails();
    final VirtualMachineShutdownParameters shutdownParams = new VirtualMachineShutdownParameters();
    shutdownParams.setPostShutdownAction(PostShutdownAction.StoppedDeallocated);
    final HostedServiceGetDetailedResponse.Deployment serviceDeployment = getServiceDeployment(
            imageDetails.getServiceName());
    if (serviceDeployment != null) {
        try {/*from w  w  w . j av  a2 s  .com*/
            return vmOperations.beginShutdown(imageDetails.getServiceName(), serviceDeployment.getName(),
                    instance.getName(), shutdownParams);
        } catch (ParserConfigurationException e) {
            throw new CloudException(e.getMessage(), e);
        } catch (SAXException e) {
            throw new CloudException(e.getMessage(), e);
        } catch (TransformerException e) {
            throw new CloudException(e.getMessage(), e);
        }
    } else {
        throw new CloudException(String.format("Unable to find deployment for service '%s' and instance '%s'",
                imageDetails.getServiceName(), instance.getName()));
    }
}

From source file:org.mumod.util.HttpManager.java

public Document getDocument(String url, String httpMethod, ArrayList<NameValuePair> params)
        throws IOException, MustardException, AuthException {
    Document dom = null;//  w  w w  . j  a  v  a 2 s .c  o  m
    InputStream is = null;
    try {
        is = requestData(url, httpMethod, params);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        DocumentBuilder builder = factory.newDocumentBuilder();
        dom = builder.parse(is);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        throw new MustardException(980, "Parser exception: " + e.getMessage());
    } catch (SAXException e) {
        e.printStackTrace();
        throw new MustardException(981, "Parser exception: " + e.getMessage());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
            }
        }
    }
    return dom;
}

From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java

/**
 * Create a document with mapping file/*  www .  ja  va2 s. com*/
 * 
 * @param mappingStream stream of mapping file
 * @throws PPTGeneratorException if error while parsing mapping file
 */
public void setMapping(InputStream mappingStream) throws PPTGeneratorException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(true);
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setEntityResolver(new XmlResolver(PUBLIC_ID, DTD_LOCATION));
        db.setErrorHandler(new ParsingHandler(LOGGER, errors));
        mapping = db.parse(mappingStream);
        if (errors.length() > 0) {
            handleException("export.audit_report.mapping.error", new String[] { errors.toString() });
        }
    } catch (ParserConfigurationException e) {
        handleException("export.audit_report.mapping.error", new String[] { e.getMessage() });
    } catch (SAXException e) {
        handleException("export.audit_report.mapping.error", new String[] { e.getMessage() });
    } catch (IOException e) {
        handleException("export.audit_report.mapping.error", new String[] { e.getMessage() });
    }
}

From source file:com.stratelia.webactiv.util.XMLConfigurationStore.java

public XMLConfigurationStore() throws Exception {
    try {//from  w  w w  . j a v  a2 s  . c  om
        javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        xmlConfigDOMDoc = dbf.newDocumentBuilder().newDocument();
    } catch (javax.xml.parsers.ParserConfigurationException e) {
        throw new Exception(e.getMessage());
    }
}

From source file:com.sfs.jbtimporter.JBTProcessor.java

/**
 * Parses the xml index./*  w ww  .  j  av  a  2  s .  c om*/
 *
 * @return the list
 * @throws SAXException the SAX exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public final List<JBTIssue> parseXmlIndex() throws SAXException, IOException {

    final List<JBTIssue> issues = new ArrayList<JBTIssue>();

    final File file = new File(this.getExportBase() + "index.xml");

    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
    try {
        db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
        throw new SAXException("Error configuring XML parser: " + pce.getMessage());
    }
    final Document doc = db.parse(file);
    doc.getDocumentElement().normalize();

    final NodeList bugList = doc.getElementsByTagName("bug");

    for (int s = 0; s < bugList.getLength(); s++) {

        final Node bugNode = bugList.item(s);

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

            final JBTIssue issue = new JBTIssue(this);

            final Element bugElmnt = (Element) bugNode;

            issue.setId(bugElmnt.getAttribute("id"));
            issue.setBase(bugElmnt.getAttribute("base"));

            NodeList fileElmntLst = bugNode.getChildNodes();

            for (int t = 0; t < fileElmntLst.getLength(); t++) {

                final Node fileNode = fileElmntLst.item(t);

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

                    final Element fileElmnt = (Element) fileNode;
                    final NodeList chldFile = fileElmnt.getChildNodes();
                    final Node filenameNode = (Node) chldFile.item(0);

                    if (StringUtils.equals(fileElmnt.getAttribute("primary"), "true")) {
                        issue.setFileName(filenameNode.getNodeValue());

                        // Add the issue to the array
                        issues.add(issue);
                    }
                }
            }
        }
    }
    return issues;
}

From source file:uk.ac.bbsrc.tgac.miso.core.manager.ERASubmissionManager.java

@Override
public String generateSubmissionMetadata(Submission submission) throws SubmissionException {
    File subPath = new File(misoFileManager.getFileStorageDirectory() + "/submission/" + submission.getName());
    //File subPath = null;
    StringBuilder sb = new StringBuilder();
    try {/*ww w .j ava2s. co  m*/
        //subPath = misoFileManager.storeFile(submission.getClass(),submission.getName());
        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

        String d = df.format(new Date());
        submissionProperties.put("submissionDate", d);

        if (LimsUtils.checkDirectory(subPath, true)) {
            Map<String, List<Submittable<Document>>> map = new HashMap<String, List<Submittable<Document>>>();
            map.put("study", new ArrayList<Submittable<Document>>());
            map.put("sample", new ArrayList<Submittable<Document>>());
            map.put("experiment", new ArrayList<Submittable<Document>>());
            map.put("run", new ArrayList<Submittable<Document>>());

            Set<Submittable<Document>> subs = submission.getSubmissionElements();
            for (Submittable<Document> sub : subs) {

                if (sub instanceof Study) {
                    map.get("study").add(sub);
                } else if (sub instanceof Sample) {
                    map.get("sample").add(sub);
                } else if (sub instanceof Experiment) {
                    map.get("experiment").add(sub);
                } else if (sub instanceof SequencerPoolPartition) {
                    map.get("run").add(sub);
                }
            }

            for (String key : map.keySet()) {
                List<Submittable<Document>> submittables = map.get(key);
                Document submissionDocument = docBuilder.newDocument();
                ERASubmissionFactory.generateSubmissionXML(submissionDocument, submittables, key,
                        submissionProperties);

                //generate xml files on disk
                File f = new File(subPath,
                        File.separator + submission.getName() + "_" + key + "_" + d + ".xml");
                if (f.exists()) {
                    f.delete();
                }
                SubmissionUtils.transform(submissionDocument, f);

                sb.append(SubmissionUtils.transform(submissionDocument, true));
            }

            Document submissionDocument = docBuilder.newDocument();
            ERASubmissionFactory.generateParentSubmissionXML(submissionDocument, submission,
                    submissionProperties);
            File f = new File(subPath, File.separator + submission.getName() + "_submission_" + d + ".xml");
            if (f.exists()) {
                f.delete();
            }
            SubmissionUtils.transform(submissionDocument, f, true);

            sb.append(SubmissionUtils.transform(submissionDocument, true));
        }
    } catch (ParserConfigurationException e) {
        throw new SubmissionException(e.getMessage());
    } catch (TransformerException e) {
        throw new SubmissionException(e.getMessage());
    } catch (IOException e) {
        throw new SubmissionException("Cannot write to submission storage directory: " + subPath
                + ". Please check this directory exists and is writable.");
    } finally {
        submissionProperties.remove("submissionDate");
    }

    return sb.toString();
}

From source file:com.evolveum.midpoint.prism.marshaller.ItemPathHolder.java

public Element toElement(String elementNamespace, String localElementName) {
    // TODO: is this efficient?
    try {/*from   ww  w  .  j  a  v  a2s.  co m*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder loader = factory.newDocumentBuilder();
        return toElement(elementNamespace, localElementName, loader.newDocument());
    } catch (ParserConfigurationException ex) {
        throw new AssertionError("Error on creating XML document " + ex.getMessage());
    }
}

From source file:de.knowwe.defi.usermanager.XMLUserDatabase.java

private void buildDOM() {
    // Read DOM//w w  w  .  ja va 2 s  .com
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    factory.setExpandEntityReferences(false);
    factory.setIgnoringComments(true);
    factory.setNamespaceAware(false);
    try {
        c_dom = factory.newDocumentBuilder().parse(c_file);
        Log.fine("Database successfully initialized");
        c_lastModified = c_file.lastModified();
        c_lastCheck = System.currentTimeMillis();
    } catch (ParserConfigurationException e) {
        Log.severe("Configuration error: " + e.getMessage());
    } catch (SAXException e) {
        Log.severe("SAX error: " + e.getMessage());
    } catch (FileNotFoundException e) {
        Log.info("User database not found; creating from scratch...");
    } catch (IOException e) {
        Log.severe("IO error: " + e.getMessage());
    }
    if (c_dom == null) {
        try {
            //
            //  Create the DOM from scratch
            //
            c_dom = factory.newDocumentBuilder().newDocument();
            c_dom.appendChild(c_dom.createElement("users"));
        } catch (ParserConfigurationException e) {
            Log.severe("Could not create in-memory DOM");
        }
    }
}

From source file:es.upm.fi.dia.oeg.sitemap4rdf.Generator.java

/**
 * Generates the sitemap_index.xml file/* w w w.j  a  va 2s  .c o  m*/
-    */
protected void generateSiteMapIndex() {
    if (siteroot == null || siteroot.isEmpty()) {
        //Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, null, new java.lang.Exception());
        System.err.print(
                "You should provide the siteroot parameter needed because a sitemapindex is being created");
        System.exit(3);
    }

    try {
        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        String indexFileName = indexOutputFile;
        if (outputDir != null && !outputDir.isEmpty())
            indexFileName = outputDir + indexOutputFile;

        Element root = doc.createElement(siteMapIndexTag);
        root.setAttribute(XMLNS, namespace);
        doc.appendChild(root);

        generateSitemapsSection(root, doc);

        OutputFormat format = new OutputFormat(defaultDocumentType, DEFAULT_ENCODING, true);
        format.setIndenting(true);
        format.setIndent(4);
        Writer output = new BufferedWriter(new FileWriter(indexFileName));
        XMLSerializer serializer = new XMLSerializer(output, format);
        serializer.serialize(doc);

    } catch (ParserConfigurationException e) {
        logger.debug("ParserConfigurationException ", e);
        System.err.println(e.getMessage());
        System.exit(3);
    } catch (IOException e) {
        logger.debug("IOException ", e);
        System.err.println(e.getMessage());
        System.exit(3);
    }
}