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:hoot.services.utils.XmlDocumentBuilder.java

/**
 * Creates a new XML DOM//from   w w  w .ja  v a  2 s  .  c o  m
 * 
 * @return XML document
 * @throws IOException
 */
public static Document create() throws IOException {
    DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = dBF.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IOException("Error creating document builder. (" + e.getMessage() + ")");
    }
    return builder.newDocument();
}

From source file:ua.kiev.doctorvera.utils.SMSGateway.java

public static Document loadXMLFromString(String xml) {
    Document doc = null;//  www.j a  v a  2 s  .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.severe(e.getMessage());
        return null;
    } catch (SAXException e) {
        LOG.severe(e.getMessage());
        return null;
    } catch (IOException e) {
        LOG.severe(e.getMessage());
        return null;
    }
    // return DOM
    return doc;
}

From source file:com.tvs.signaltracker.Utils.java

public static Document XMLfromString(String xml) {

    Document doc = null;//w  w w.  j  a  v a  2 s. 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) {
        System.out.println("XML parse error: " + e.getMessage());
        return null;
    } catch (SAXException e) {
        System.out.println("Wrong XML file structure: " + e.getMessage());
        return null;
    } catch (IOException e) {
        System.out.println("I/O exeption: " + e.getMessage());
        return null;
    }

    return doc;

}

From source file:de.itomig.itoplib.GetItopData.java

public static XmlResult getDataFromItopServer(String selectExpression) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;/*w w  w.  j a v  a 2s.c om*/

    XmlResult x = new XmlResult();
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e1) {
        x.error = "error: " + e1.getMessage();
        return x;
    }

    AndroidHttpClient client = AndroidHttpClient.newInstance("Android");

    try {
        HttpPost request = new HttpPost();
        String req = createUrlWithCredentials(selectExpression);
        // do not log password, log only search expression
        if (debug)
            Log.i(TAG, "expr.=" + selectExpression);
        request.setURI(new URI(req));

        HttpResponse response = client.execute(request);
        String status = response.getStatusLine().toString();
        if (debug)
            Log.i(TAG, "status: " + status);

        if (status.contains("200") && status.contains("OK")) {

            // request worked fine, retrieved some data
            InputStream instream = response.getEntity().getContent();
            x.doc = builder.parse(instream);
            x.error = "";
        } else // some error in http response
        {
            Log.e(TAG, "Get data - http-ERROR: " + status);
            x.error = "http-error, status " + status;
        }

    } catch (Exception e) {
        // Toast does not work in background task
        Log.e(TAG, "Get data -  " + e.toString());
        x.error = "Get data -  " + e.toString();
    } finally {
        client.close(); // needs to be done for androidhttpclient
        if (debug)
            Log.i(TAG, "...finally.. get data finished");
    }

    return x;
}

From source file:eu.europeana.uim.sugarcrmclient.internal.helpers.ClientUtils.java

/**
 * @param responseString/*from  ww  w .j  av a2s.  c  o  m*/
 * @return
 */
public static String extractSimpleResponse(String responseString) {

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(new InputSource(new StringReader(responseString)));
        String sessionID = null;
        NodeList nl = document.getElementsByTagName("id");

        if (nl.getLength() > 0) {
            sessionID = nl.item(0).getTextContent();
        }

        return sessionID;

    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    }

    return null;
}

From source file:com.atlassw.tools.eclipse.checkstyle.builder.PackageNamesLoader.java

/**
 * Returns the default list of package names.
 * /*w  w w  .  j a  v a  2s  .  co  m*/
 * @param aClassLoader the class loader that gets the default package names.
 * @return the default list of package names.
 * @throws CheckstylePluginException if an error occurs.
 */
public static List<String> getPackageNames(ClassLoader aClassLoader) throws CheckstylePluginException {

    if (sPackages == null) {
        sPackages = new ArrayList<String>();

        PackageNamesLoader nameLoader = null;

        try {
            nameLoader = new PackageNamesLoader();
            final InputStream stream = aClassLoader.getResourceAsStream(DEFAULT_PACKAGES);
            InputSource source = new InputSource(stream);
            nameLoader.parseInputSource(source);
        } catch (ParserConfigurationException e) {
            CheckstylePluginException.rethrow(e, "unable to parse " + DEFAULT_PACKAGES); //$NON-NLS-1$
        } catch (SAXException e) {
            CheckstylePluginException.rethrow(e, "unable to parse " + DEFAULT_PACKAGES + " - " //$NON-NLS-1$ //$NON-NLS-2$
                    + e.getMessage());
        } catch (IOException e) {
            CheckstylePluginException.rethrow(e, "unable to read " + DEFAULT_PACKAGES); //$NON-NLS-1$
        }

        // load custom package files
        try {
            Enumeration<URL> packageFiles = aClassLoader.getResources("checkstyle_packages.xml"); //$NON-NLS-1$

            while (packageFiles.hasMoreElements()) {

                URL aPackageFile = packageFiles.nextElement();
                InputStream iStream = null;

                try {

                    iStream = new BufferedInputStream(aPackageFile.openStream());
                    InputSource source = new InputSource(iStream);
                    nameLoader.parseInputSource(source);
                } catch (SAXException e) {
                    LimyEclipsePluginUtils.log(e);
                    //                        CheckstyleLog.log(e, "unable to parse " + aPackageFile.toExternalForm() //$NON-NLS-1$
                    //                                + " - " + e.getLocalizedMessage()); //$NON-NLS-1$
                } catch (IOException e) {
                    LimyEclipsePluginUtils.log(e);
                    //                        CheckstyleLog.log(e, "unable to read " + aPackageFile.toExternalForm()); //$NON-NLS-1$
                } finally {
                    IOUtils.closeQuietly(iStream);
                }
            }
        } catch (IOException e1) {
            CheckstylePluginException.rethrow(e1);
        }
    }

    return sPackages;
}

From source file:de.codesourcery.eve.apiclient.utils.XMLParseHelper.java

public static Document parseXML(String xml) throws UnparseableResponseException {

    final DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder;
    try {// w w  w  .  java 2 s.  co m
        docBuilder = fac.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("Error while creating XML document builder factory: " + e.getMessage(), e);
    }

    try {
        return docBuilder.parse(new ByteArrayInputStream(xml.getBytes()));
    } catch (SAXException e) {
        throw new UnparseableResponseException("Received invalid XML from server", e);
    } catch (IOException e) {
        // should never happen, we're reading a byte array....
        throw new RuntimeException(e);
    }

}

From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java

public static Document loadDocument(byte[] data) {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);//from   w  ww . j  a  va 2 s  .c  om
    DocumentBuilder domBuilder;
    try {
        domBuilder = domFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("parser configuration error: " + e.getMessage(), e);
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
    InputSource inputSource = new InputSource(inputStream);
    try {
        return domBuilder.parse(inputSource);
    } catch (SAXException e) {
        throw new RuntimeException("SAX error: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException("IO error: " + e.getMessage(), e);
    }
}

From source file:com.ikon.util.FormUtils.java

/**
 * Parse params.xml definitions//w w w.  j  a va  2 s .  c  om
 * 
 * @return A List parameter elements.
 */
public static List<FormElement> parseReportParameters(InputStream is) throws ParseException {
    log.debug("parseReportParameters({})", is);
    List<FormElement> params = new ArrayList<FormElement>();

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        ErrorHandler handler = new ErrorHandler();
        // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.setEntityResolver(resolver);

        if (is != null) {
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nlForm = doc.getElementsByTagName("report-parameters");

            for (int i = 0; i < nlForm.getLength(); i++) {
                Node nForm = nlForm.item(i);

                if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                    NodeList nlField = nForm.getChildNodes();
                    params = parseField(nlField);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), e);
    }

    log.debug("parseReportParameters: {}", params);
    return params;
}

From source file:com.ikon.util.FormUtils.java

/**
 * Parse form.xml definitions//ww  w  .  j a  va2  s  .  co m
 * 
 * @return A Map with all the forms and its form elements.
 */
public static Map<String, List<FormElement>> parseWorkflowForms(InputStream is) throws ParseException {
    log.debug("parseWorkflowForms({})", is);
    Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>();

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(true);
        ErrorHandler handler = new ErrorHandler();
        // EntityResolver resolver = new LocalResolver(Config.DTD_BASE);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.setEntityResolver(resolver);

        if (is != null) {
            Document doc = db.parse(is);
            doc.getDocumentElement().normalize();
            NodeList nlForm = doc.getElementsByTagName("workflow-form");

            for (int i = 0; i < nlForm.getLength(); i++) {
                Node nForm = nlForm.item(i);

                if (nForm.getNodeType() == Node.ELEMENT_NODE) {
                    String taskName = nForm.getAttributes().getNamedItem("task").getNodeValue();
                    NodeList nlField = nForm.getChildNodes();
                    List<FormElement> fe = parseField(nlField);
                    forms.put(taskName, fe);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new ParseException(e.getMessage(), e);
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), e);
    }

    log.debug("parseWorkflowForms: {}", forms);
    return forms;
}