Example usage for javax.xml.parsers ParserConfigurationException toString

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

private static synchronized DocumentBuilder getDocumentBuilder() {
    DocumentBuilder domBuilder = (DocumentBuilder) domBuilders.get(Thread.currentThread());

    if (domBuilder != null) {
        return domBuilder;
    } else {/*from   ww  w. j  a v a2 s .co m*/
        try {
            domBuilder = domBuilderFactory.newDocumentBuilder();
            domBuilders.put(Thread.currentThread(), domBuilder);

            return domBuilder;
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Cannot build parser: " + e.toString());
        }
    }
}

From source file:com.granule.json.utils.XML.java

/**
 * Method to do the transform from an XML input stream to a JSON stream.
 * Neither input nor output streams are closed.  Closure is left up to the caller.
 *
 * @param XMLStream The XML stream to convert to JSON
 * @param JSONStream The stream to write out JSON to.  The contents written to this stream are always in UTF-8 format.
 * @param verbose Flag to denote whether or not to render the JSON text in verbose (indented easy to read), or compact (not so easy to read, but smaller), format.
 *
 * @throws SAXException Thrown if a parse error occurs.
 * @throws IOException Thrown if an IO error occurs.
 *///ww  w.j  a v  a  2 s  .co  m
public static void toJson(InputStream XMLStream, OutputStream JSONStream, boolean verbose)
        throws SAXException, IOException {
    if (logger.isLoggable(Level.FINER)) {
        logger.entering(className, "toJson(InputStream, OutputStream)");
    }

    if (XMLStream == null) {
        throw new NullPointerException("XMLStream cannot be null");
    } else if (JSONStream == null) {
        throw new NullPointerException("JSONStream cannot be null");
    } else {

        if (logger.isLoggable(Level.FINEST)) {
            logger.logp(Level.FINEST, className, "transform",
                    "Fetching a SAX parser for use with JSONSAXHandler");
        }

        try {
            /**
             * Get a parser.
             */
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            SAXParser sParser = factory.newSAXParser();
            XMLReader parser = sParser.getXMLReader();
            JSONSAXHandler jsonHandler = new JSONSAXHandler(JSONStream, verbose);
            parser.setContentHandler(jsonHandler);
            parser.setErrorHandler(jsonHandler);
            InputSource source = new InputSource(new BufferedInputStream(XMLStream));

            if (logger.isLoggable(Level.FINEST)) {
                logger.logp(Level.FINEST, className, "transform", "Parsing the XML content to JSON");
            }

            /** 
             * Parse it.
             */
            source.setEncoding("UTF-8");
            parser.parse(source);
            jsonHandler.flushBuffer();
        } catch (javax.xml.parsers.ParserConfigurationException pce) {
            throw new SAXException("Could not get a parser: " + pce.toString());
        }
    }

    if (logger.isLoggable(Level.FINER)) {
        logger.exiting(className, "toJson(InputStream, OutputStream)");
    }
}

From source file:de.betterform.xml.dom.DOMUtil.java

/**
 * __UNDOCUMENTED__/* www. j  av  a  2  s  .  c  o  m*/
 *
 * @param isNamespaceAware __UNDOCUMENTED__
 * @param isValidating     __UNDOCUMENTED__
 * @return __UNDOCUMENTED__
 */
public static Document newDocument(boolean isNamespaceAware, boolean isValidating) {
    // !!! workaround to enable betterForm to run within WebLogic Server
    // Force JAXP to use xerces as the default JAXP parser doesn't work with BetterForm
    //
    //        String oldFactory = System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
    //        System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    // restore to original factory
    //
    //        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",oldFactory);
    // !!! end workaround
    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(isNamespaceAware);
    factory.setValidating(isValidating);

    try {
        // Create builder.
        DocumentBuilder builder = factory.newDocumentBuilder();

        return builder.newDocument();
    } catch (ParserConfigurationException pce) {
        System.err.println(pce.toString());
    }

    return null;
}

From source file:com.michael.feng.utils.YahooWeather4a.WOEIDUtils.java

private Document convertStringToDocument(Context context, String src) {
    Log.d("tag", "convertStringToDocument");
    Document dest = null;/*from   w ww.  j ava2 s .  c  o  m*/

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;

    try {
        parser = dbFactory.newDocumentBuilder();
        dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
        Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show();
    } catch (SAXException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return dest;

}

From source file:org.soapfromhttp.service.CallSOAP.java

/**
 * Contruction dynamique de la requte SOAP
 *
 * @param pBody/*from   w  w  w. j  a v  a 2s.  c  om*/
 * @param method
 * @return SOAPMessage
 * @throws SOAPException
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
private SOAPMessage createSOAPRequest(final String pBody, final String method)
        throws SOAPException, IOException, SAXException, ParserConfigurationException {

    // Prcise la version du protocole SOAP  utiliser (ncessaire pour les appels de WS Externe)
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

    SOAPMessage soapMessage = messageFactory.createMessage();

    MimeHeaders headers = soapMessage.getMimeHeaders();

    // Prcise la mthode du WSDL  interroger
    headers.addHeader("SOAPAction", method);
    // Encodage UTF-8
    headers.addHeader("Content-Type", "text/xml;charset=UTF-8");

    final SOAPBody soapBody = soapMessage.getSOAPBody();

    // convert String into InputStream - traitement des caracres escaps > < ... (contraintes de l'affichage IHM)
    //InputStream is = new ByteArrayInputStream(HtmlUtils.htmlUnescape(pBody).getBytes());
    InputStream is = new ByteArrayInputStream(pBody.getBytes());
    DocumentBuilder builder = null;

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

    // Important  laisser sinon KO
    builderFactory.setNamespaceAware(true);
    try {
        builder = builderFactory.newDocumentBuilder();

        Document document = builder.parse(is);

        soapBody.addDocument(document);
    } catch (ParserConfigurationException e) {
        MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString());
    } finally {
        is.close();
        if (builder != null) {
            builder.reset();
        }
    }
    soapMessage.saveChanges();

    return soapMessage;
}

From source file:com.phildatoon.weather.WOEIDUtils.java

private Document convertStringToDocument(Context context, String src) {
    MyLog.d("convert string to document");
    Document dest = null;/* w w w.j  a  v a  2 s  . c om*/

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;

    try {
        parser = dbFactory.newDocumentBuilder();
        dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
        Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show();
    } catch (SAXException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return dest;
}

From source file:com.example.apis.ifashion.WOEIDUtils.java

private Document convertStringToDocument(Context context, String src) {
    YahooWeatherLog.d("convert string to document");
    Document dest = null;/*  w  w  w . j a va 2s.c o  m*/

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;

    try {
        parser = dbFactory.newDocumentBuilder();
        dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
        Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show();
    } catch (SAXException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return dest;

}

From source file:info.androidhive.androidsplashscreentimer.WOEIDUtils.java

private Document convertStringToDocument(Context context, String src) {
    MyLog.d("convert string to document");
    Document dest = null;// w ww.ja v  a2 s . c o m

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;

    try {
        parser = dbFactory.newDocumentBuilder();
        dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
        Toast.makeText(context, e1.toString(), Toast.LENGTH_LONG).show();
    } catch (SAXException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return dest;

}

From source file:com.photon.phresco.nativeapp.unit.test.testcases.A_MainActivityTest.java

/**
 * Read phresco-env-config.xml file to get to connect to web service
 *//*from   w  ww.  j a  va 2 s .c o m*/
public void readConfigXML() {
    try {

        String protocol = "protocol";
        String host = "host";
        String port = "port";
        String context = "context";
        Resources resources = this.mContext.getResources();
        AssetManager assetManager = resources.getAssets();
        Properties properties = new Properties();

        // Read from the /assets directory
        InputStream inputStream = assetManager.open(Constants.PHRESCO_ENV_CONFIG);

        ConfigReader confReaderObj = new ConfigReader(inputStream);

        PhrescoLogger.info(TAG + "Default ENV = " + confReaderObj.getDefaultEnvName());

        List<Configuration> configByEnv = confReaderObj.getConfigByEnv(confReaderObj.getDefaultEnvName());

        for (Configuration configuration : configByEnv) {
            properties = configuration.getProperties();
            PhrescoLogger.info(TAG + "config value = " + configuration.getProperties());
            String webServiceProtocol = properties.getProperty(protocol).endsWith("://")
                    ? properties.getProperty(protocol)
                    : properties.getProperty(protocol) + "://"; // http://

            String webServiceHost = properties.getProperty(port).equalsIgnoreCase("")
                    ? (properties.getProperty(host).endsWith("/") ? properties.getProperty(host)
                            : properties.getProperty(host) + "/")
                    : properties.getProperty(host); // localhost/
            // localhost

            String webServicePort = properties.getProperty(port).equalsIgnoreCase("") ? ""
                    : (properties.getProperty(port).startsWith(":") ? properties.getProperty(port)
                            : ":" + properties.getProperty(port)); // "" (blank)
            // :1313

            String webServiceContext = properties.getProperty(context).startsWith("/")
                    ? properties.getProperty(context)
                    : "/" + properties.getProperty(context); // /phresco

            Constants.setWebContextURL(
                    webServiceProtocol + webServiceHost + webServicePort + webServiceContext + "/");
            Constants.setRestAPI(Constants.REST_API);
            PhrescoLogger.info(
                    TAG + "Constants.webContextURL : " + Constants.getWebContextURL() + Constants.getRestAPI());
        }

    } catch (ParserConfigurationException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : ParserConfigurationException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (SAXException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : SAXException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "readConfigXML : Exception: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:com.photon.phresco.hybrid.eshop.activity.PhrescoActivity.java

/**
 * Read phresco-env-config.xml file to get to connect to web service
 */// w w  w  . j av  a  2s  .c  o  m
public void readConfigXML() {
    try {

        Resources resources = getResources();
        AssetManager assetManager = resources.getAssets();

        // Read from the /assets directory
        InputStream inputStream = assetManager.open(Constants.PHRESCO_ENV_CONFIG);

        ConfigReader confReaderObj = new ConfigReader(inputStream);

        PhrescoLogger.info(TAG + "Default ENV = " + confReaderObj.getDefaultEnvName());

        List<Configuration> configByEnv = confReaderObj.getConfigByEnv(confReaderObj.getDefaultEnvName());

        for (Configuration configuration : configByEnv) {
            String envName = configuration.getEnvName();
            String envType = configuration.getType();
            PhrescoLogger.info(TAG + "envName = " + envName + " ----- envType = " + envType);
            //            properties = configuration.getProperties();

            if (envType.equalsIgnoreCase("webservice")) {
                /*String configJsonString = confReaderObj.getConfigAsJSON(envName, WEB_SERVICE, WEBSERVICE_CONFIG_NAME);
                getWebServiceURL(configJsonString);*/
            } else if (envType.equalsIgnoreCase("server")) {
                String configJsonString = confReaderObj.getConfigAsJSON(envName, SERVER, SERVER_CONFIG_NAME);
                getServerURL(configJsonString);
            }

        }

    } catch (ParserConfigurationException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : ParserConfigurationException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (SAXException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : SAXException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (IOException ex) {
        PhrescoLogger.info(TAG + "readConfigXML : IOException: " + ex.toString());
        PhrescoLogger.warning(ex);
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "readConfigXML : Exception: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}