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:org.jts.protocolvalidator.FileFinder.java

/**
 * Filter jsidl files and place in a Map with associated id.
 * @param fileList list of JSIDL XML files
 *//*from w  w  w. jav a  2  s. c  o m*/
private void populateIDMap(List<File> fileList) throws Exception {
    fileMap = new HashMap();
    reverseFileMap = new HashMap();
    processedFileMap = new HashMap();

    Document doc = null;
    DocumentBuilder db = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    String id = "";

    try {
        db = dbf.newDocumentBuilder();
    } catch (javax.xml.parsers.ParserConfigurationException pce) {
        Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                "Exception while configuring parser: " + pce.toString(), pce);
        throw new Exception("Exception while configuring parser: " + pce.getMessage());
    }

    // store the path/id for each path in the list
    for (int ii = 0; ii < fileList.size(); ii++) {
        File file = fileList.get(ii);
        final String fileName = file.getPath();

        // see if the file can be parsed
        try {
            doc = db.parse(file);
        } catch (final IOException ioe) {
            Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                    "Unable to read file" + fileName + " \n " + ioe.toString(), ioe);
            continue; // weaken import to allow bad files in target dir
        } catch (final SAXException saxe) {
            Logger.getLogger(JTSFileWriter.class.getName()).log(Level.SEVERE,
                    "Unable to parse file" + fileName + " \n " + saxe.toString(), saxe);
            continue; // weaken import to allow bad files in target dir
        }

        // getting the id from the file
        Element root = doc.getDocumentElement();
        id = root.getAttribute("id");

        if (root.getAttribute("xmlns").equals("urn:jaus:jsidl:1.0") && !id.isEmpty()) {
            fileMap.put(fileName, root.getAttribute("id"));
            reverseFileMap.put(root.getAttribute("id"), fileName);
        }
    }

}

From source file:org.jzkit.search.util.RecordConversion.FragmentTransformerService.java

public void init() {
    log.debug("FragmentTransformerService::init");
    try {/*from w ww. ja v  a  2  s  .  co  m*/
        for (Iterator i = configuration.getRegisteredConverterTypes(); i.hasNext();) {
            Object o = i.next();
            RecordTransformerTypeInformationDBO rtti = (RecordTransformerTypeInformationDBO) o;
            registerType(rtti.getType(), rtti.getClassname());
        }

        for (Iterator i = configuration.getRegisteredRecordMappings(); i.hasNext();) {
            RecordMappingInformationDBO rmi = (RecordMappingInformationDBO) i.next();
            registerMapping(rmi.getFromSpec(), rmi.getToSpec(), rmi.getType(), rmi.getResource());
        }

        DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
        dfactory.setNamespaceAware(true);
        docBuilder = dfactory.newDocumentBuilder();
        context.put("DocBuilder", docBuilder);
        context.put("TransformerFactory", tFactory);
    } catch (org.jzkit.configuration.api.ConfigurationException ce) {
        throw new RuntimeException(ce.toString());
    } catch (ParserConfigurationException pce) {
        throw new RuntimeException(pce.toString());
    } finally {
        // configuration.close();
    }
}

From source file:org.jzkit.search.util.RecordModel.SGMLRecord.java

public Document getDocument() {
    if ((doc == null) && (orig != null)) {
        DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
        dfactory.setNamespaceAware(true);
        try {/*from www  . ja  va2s .co m*/
            DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
            doc = docBuilder.parse(new ByteArrayInputStream(orig.getBytes()));
        } catch (ParserConfigurationException pce) {
            log.error(pce.toString(), pce);
        } catch (org.xml.sax.SAXException saxe) {
            log.error(saxe.toString(), saxe);
        } catch (java.io.IOException ioe) {
            log.error(ioe.toString(), ioe);
        }
    }

    return doc;
}

From source file:org.jzkit.search.util.RecordModel.XMLRecord.java

public Document getDocument() {
    if ((doc == null) && (orig != null)) {
        // DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
        // dfactory.setNamespaceAware(true);
        // dfactory.setValidating(false);
        // Experimental for ANG Project
        // Don't expand entity references.
        // dfactory.setExpandEntityReferences(false);
        // Wonder if there is a way to get case-insensitive tag parsers?

        try {/*from w w w  .j  a  v  a  2 s .  c o  m*/
            // log.debug("Parse record:" +orig);
            DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
            doc = docBuilder.parse(new ByteArrayInputStream(orig.getBytes()));
        } catch (ParserConfigurationException pce) {
            log.warn(pce.toString(), pce);
        } catch (org.xml.sax.SAXException saxe) {
            log.warn(saxe.toString(), saxe);
        } catch (java.io.IOException ioe) {
            log.warn(ioe.toString(), ioe);
        }
    }

    return doc;
}

From source file:org.sakaiproject.kernel.component.core.PersistenceUnitClassLoader.java

/**
 * Gets resources from the classloader. This filters for
 * META-INF/{persistence.xml, orm.xml} and merges those files respectively, so
 * it appears there is only one copy of each. This is needed for all
 * persistence units to be grouped together in JPA.
 *
 * {@inheritDoc}/*from w w  w .j a v  a2  s  . com*/
 *
 * @see java.lang.ClassLoader#getResources(java.lang.String)
 */
@Override
public Enumeration<URL> getResources(final String name) throws IOException {
    try {
        Enumeration<URL> retEnum = null;
        if (PERSISTENCE_XML.equals(name)) {
            if (persistenceXMLurl == null) {
                String xml = scanPersistenceXml();
                if (xml != null) {
                    persistenceXMLurl = constructUrl(xml, PERSISTENCE_XML);
                }
                xml = scanOrmXml();
                if (xml != null) {
                    ormXMLurl = constructUrl(xml, ORM_XML);
                }
            }
            retEnum = new UrlEnumeration(persistenceXMLurl);
        }
        // make sure subsequent lookups for orm.xml get the merged copy of the
        // file
        else if (ORM_XML.equals(name)) {
            if (ormXMLurl == null) {
                final String xml = scanOrmXml();
                if (xml != null) {
                    ormXMLurl = constructUrl(xml, ORM_XML);
                }
            }
            retEnum = new UrlEnumeration(ormXMLurl);
        } else {
            retEnum = super.getResources(name);
        }
        return retEnum;
    } catch (ParserConfigurationException e) {
        throw new IOException(e.toString());
    } catch (SAXException e) {
        throw new IOException(e.toString());
    } catch (XPathExpressionException e) {
        throw new IOException(e.toString());
    } catch (TransformerException e) {
        throw new IOException(e.toString());
    }
}

From source file:org.smartfrog.avalanche.client.sf.apps.gt4.javawscore.DeployToTomcat.java

/**
 * This method is valid for both Tomcat 4.1.x and 5.x
 * // ww  w . j a v  a 2 s .  c  o m
 * Edits the file $<tomcat.dir>/conf/server.xml to include the appropriate 
 * connectors. 
 * If default port (8443) is not used, then edits the file 
 * $<tomcat.dir>/webapps/wsrf/WEB-INF/web.xml to include the non-default port.
 * @param connectionAttrs
 * @param valueAttrs
 * @return
 */
public void editXMLFiles(String version, Hashtable connectionAttrs, Hashtable valveAttrs)
        throws WSCoreException {
    String fileName = new String(tomcatDirectory.concat("/conf/server.xml"));
    fileName = fileName.replace('\\', File.separatorChar);
    fileName = fileName.replace('/', File.separatorChar);

    EditXML xmlHelper;
    EditXML webXMLHelper;
    boolean defaultPort = true;
    Element engine = null;
    log.info("Entered editXMLFiles... with tomcat version : " + version);
    try {
        log.info("server.xml file location : " + fileName);
        xmlHelper = new EditXML(fileName);
        log.info("EditXML object created");

        if (version.startsWith("4.1")) {
            addConnectorForTomcat4_1_x(xmlHelper, connectionAttrs);
            engine = xmlHelper.getElementByTagNameAttrName("Engine", "Standalone");
        } else if (version.startsWith("5.")) {
            log.info("Before adding connector");
            addConnectorForTomcat5_x(xmlHelper, connectionAttrs);
            log.info("After adding connector");
            engine = xmlHelper.getElementByTagNameAttrName("Engine", "Catalina");
        } else {
            log.error("The version " + version + " is not supported");
            throw new WSCoreException("The version " + version + " is not supported");
        }

        log.info("Before adding Valve");
        Element valve = xmlHelper.createElementWithAttrs("Valve", valveAttrs);
        xmlHelper.addFirstChild(engine, valve);
        log.info("After adding Valve");

        if (!((String) connectionAttrs.get("port")).equals("8443")) {
            defaultPort = false;
            String webXMLFile = new String(
                    tomcatDirectory.concat("/webapps/" + webappName + "/WEB-INF/web.xml"));
            webXMLFile = webXMLFile.replace('/', File.separatorChar);
            webXMLFile = webXMLFile.replace('\\', File.separatorChar);
            webXMLHelper = new EditXML(webXMLFile);
            Element servlet = webXMLHelper.getElementByTagName("servlet");
            if (null == servlet) {
                log.error("Cannot find the node 'servlet' in the file " + webXMLFile);
                throw new WSCoreException("Cannot find the node 'servlet' in the file " + webXMLFile);
            }

            /*
             * adding the following xml elements
             * <init-param>
             *       <param-name>defaultProtocol</param-name>
             *       <param-value>https</param-value>
             * </init-param>
             */
            Element protocol = webXMLHelper.createElement("init-param", null);
            Element protocolName = webXMLHelper.createElement("param-name", "defaultProtocol");
            Element protocolValue = webXMLHelper.createElement("param-value", "https");
            webXMLHelper.addLastChild(protocol, protocolName);
            webXMLHelper.addLastChild(protocol, protocolValue);
            webXMLHelper.addBeforeLastChild(servlet, protocol);

            /*
             * Adds the following elements to web.xml
             * <init-param>
             *       <param-name>defaultPort</param-name>
             *       <param-value>443</param-value>
             * </init-param>   
             */
            Element portElement = webXMLHelper.createElement("init-param", null);
            Element portName = webXMLHelper.createElement("param-name", "defaultPort");
            Element portValue = webXMLHelper.createElement("param-value", (String) connectionAttrs.get("port"));
            webXMLHelper.addLastChild(portElement, portName);
            webXMLHelper.addLastChild(portElement, portValue);
            webXMLHelper.addBeforeLastChild(servlet, portElement);
            xmlHelper.commitChanges();
            if (!defaultPort) {
                webXMLHelper.commitChanges();
            }
        }
    } catch (ParserConfigurationException pce) {
        throw new WSCoreException(pce.toString());
    } catch (IOException ioe) {
        throw new WSCoreException(ioe.toString());
    } catch (SAXException se) {
        throw new WSCoreException(se.toString());
    } catch (TransformerException te) {
        throw new WSCoreException(te.toString());
    }
    /*finally {
       try {
    xmlHelper.commitChanges();
    if (!defaultPort) {
       webXMLHelper.commitChanges();
    }            
       }catch (FileNotFoundException fnf) {
    log.error(fnf);
            
       }catch (TransformerException te) {
    log.error(te);
            
       }         
    }*/

}

From source file:org.smartfrog.avalanche.client.sf.apps.gt4.javawscore.DeployToTomcat.java

public void cleanXMLFiles(String version) throws WSCoreException {
    String serverxml = new String(tomcatDirectory.concat("/conf/server.xml"));
    serverxml = serverxml.replace('\\', File.separatorChar);
    serverxml = serverxml.replace('/', File.separatorChar);

    EditXML xmlHelper = null;//from  w  w  w  .ja va  2s.  c  om
    Element connector = null;
    Element valve = null;
    try {
        xmlHelper = new EditXML(serverxml);

        if (version.startsWith("4.1")) {
            connector = xmlHelper.getElementByTagNameAttrName("Connector", "className",
                    "org.apache.catalina.connector.http.HttpConnector");
            xmlHelper.removeNode(connector);

            valve = xmlHelper.getElementByTagNameAttrName("Valve", "className",
                    "org.globus.tomcat.catalina.valves.HTTPSValve");
            xmlHelper.removeNode(valve);
        } else if (version.startsWith("5.")) {
            connector = xmlHelper.getElementByTagNameAttrName("Connector", "className",
                    "org.globus.tomcat.coyote.net.HTTPSConnector");
            xmlHelper.removeNode(connector);

            valve = xmlHelper.getElementByTagNameAttrName("Valve", "className",
                    "org.globus.tomcat.coyote.valves.HTTPSValve");
            xmlHelper.removeNode(valve);
        } else {
            log.error("The version " + version + " is not supported");
            throw new WSCoreException("The version " + version + " is not supported");
        }
    } catch (ParserConfigurationException pce) {
        throw new WSCoreException(pce.toString());
    } catch (IOException ioe) {
        throw new WSCoreException(ioe.toString());
    } catch (SAXException se) {
        throw new WSCoreException(se.toString());
    } finally {
        try {
            xmlHelper.commitChanges();
        } catch (FileNotFoundException fnf) {
            log.error(fnf);
            throw new WSCoreException(fnf);
        } catch (TransformerException te) {
            log.error(te);
            throw new WSCoreException(te);
        }
    }
}

From source file:org.smartfrog.avalanche.client.sf.apps.gt4.javawscore.UndeployFrmTomcat.java

public void cleanXMLFiles() throws WSCoreException {
    String serverxml = new String(tomcatDir.concat("/conf/server.xml"));
    serverxml = serverxml.replace('\\', File.separatorChar);
    serverxml = serverxml.replace('/', File.separatorChar);

    log.info("Started cleaning XML files of Tomcat");
    EditXML xmlHelper = null;/*  w w  w.ja  v  a2  s  . c o  m*/
    Element connector = null;
    Element valve = null;
    try {
        xmlHelper = new EditXML(serverxml);

        if (version.startsWith("4.1")) {
            connector = xmlHelper.getElementByTagNameAttrName("Connector", "className",
                    "org.apache.catalina.connector.http.HttpConnector");
            xmlHelper.removeNode(connector);

            valve = xmlHelper.getElementByTagNameAttrName("Valve", "className",
                    "org.globus.tomcat.catalina.valves.HTTPSValve");
            xmlHelper.removeNode(valve);
        } else if (version.startsWith("5.")) {
            log.info("cleaning 5.* xml files");
            connector = xmlHelper.getElementByTagNameAttrName("Connector", "className",
                    "org.globus.tomcat.coyote.net.HTTPSConnector");
            xmlHelper.removeNode(connector);

            valve = xmlHelper.getElementByTagNameAttrName("Valve", "className",
                    "org.globus.tomcat.coyote.valves.HTTPSValve");
            xmlHelper.removeNode(valve);
        } else {
            log.error("The version " + version + " is not supported");
            throw new WSCoreException("The version " + version + " is not supported");
        }
        log.info("Cleaning complete");
    } catch (ParserConfigurationException pce) {
        throw new WSCoreException(pce.toString());
    } catch (IOException ioe) {
        throw new WSCoreException(ioe.toString());
    } catch (SAXException se) {
        throw new WSCoreException(se.toString());
    } finally {
        try {
            xmlHelper.commitChanges();
            log.info("Cleaning changes committed");
        } catch (FileNotFoundException fnf) {
            log.error(fnf);
            throw new WSCoreException(fnf);
        } catch (TransformerException te) {
            log.error(te);
            throw new WSCoreException(te);
        }
    }
}

From source file:org.smartfrog.avalanche.client.sf.apps.gt4wscore.DeployToTomcat.java

/**
 * This method is valid for both Tomcat 4.1.x and 5.x
 * //from  w  w w  . j  a  v a 2 s. com
 * Edits the file $<tomcat.dir>/conf/server.xml to include the appropriate 
 * connectors. 
 * If default port (8443) is not used, then edits the file 
 * $<tomcat.dir>/webapps/wsrf/WEB-INF/web.xml to include the non-default port.
 * @param connectionAttrs
 * @param valueAttrs
 * @return
 */
public boolean editXMLFiles(String version, Hashtable connectionAttrs, Hashtable valveAttrs)
        throws TomcatConfigException {
    String fileName = new String(tomcatDirectory.concat("/conf/server.xml"));
    fileName = fileName.replace('\\', File.separatorChar);
    fileName = fileName.replace('/', File.separatorChar);

    EditXML xmlHelper = null;
    EditXML webXMLHelper = null;
    boolean defaultPort = true;
    Element engine = null;
    try {
        xmlHelper = new EditXML(fileName);
        try {
            if (version.startsWith("4.1")) {
                if (!addConnectorForTomcat4_1_x(xmlHelper, connectionAttrs)) {
                    return false;
                }
                engine = xmlHelper.getElementByTagNameAttrName("Engine", "Standalone");
            } else if (version.startsWith("5.")) {
                if (!addConnectorForTomcat5_x(xmlHelper, connectionAttrs)) {
                    return false;
                }
                engine = xmlHelper.getElementByTagNameAttrName("Engine", "Catalina");
            } else {
                log.error("The version " + version + " is not supported");
                return false;
            }
        } catch (TransformerException te) {
            throw new TomcatConfigException(te.toString());
        }

        Element valve = xmlHelper.createElementWithAttrs("Valve", valveAttrs);
        xmlHelper.addFirstChild(engine, valve);

        if (!((String) connectionAttrs.get("port")).equals("8443")) {
            defaultPort = false;
            String webXMLFile = new String(
                    tomcatDirectory.concat("/webapps/" + webappName + "/WEB-INF/web.xml"));
            webXMLFile = webXMLFile.replace('/', File.separatorChar);
            webXMLFile = webXMLFile.replace('\\', File.separatorChar);
            webXMLHelper = new EditXML(webXMLFile);
            Element servlet = webXMLHelper.getElementByTagName("servlet");
            if (null == servlet) {
                log.error("Cannot find the node 'servlet' in the file " + webXMLFile);
                return false;
            }

            /*
             * adding the following xml elements
             * <init-param>
             *       <param-name>defaultProtocol</param-name>
             *       <param-value>https</param-value>
             * </init-param>
             */
            Element protocol = webXMLHelper.createElement("init-param", null);
            Element protocolName = webXMLHelper.createElement("param-name", "defaultProtocol");
            Element protocolValue = webXMLHelper.createElement("param-value", "https");
            webXMLHelper.addLastChild(protocol, protocolName);
            webXMLHelper.addLastChild(protocol, protocolValue);
            webXMLHelper.addBeforeLastChild(servlet, protocol);

            /*
             * Adds the following elements to web.xml
             * <init-param>
             *       <param-name>defaultPort</param-name>
             *       <param-value>443</param-value>
             * </init-param>   
             */
            Element portElement = webXMLHelper.createElement("init-param", null);
            Element portName = webXMLHelper.createElement("param-name", "defaultPort");
            Element portValue = webXMLHelper.createElement("param-value", (String) connectionAttrs.get("port"));
            webXMLHelper.addLastChild(portElement, portName);
            webXMLHelper.addLastChild(portElement, portValue);
            webXMLHelper.addBeforeLastChild(servlet, portElement);
        }
    } catch (ParserConfigurationException pce) {
        throw new TomcatConfigException(pce.toString());
    } catch (IOException ioe) {
        throw new TomcatConfigException(ioe.toString());
    } catch (SAXException se) {
        throw new TomcatConfigException(se.toString());
    } finally {
        try {
            xmlHelper.commitChanges();
            if (!defaultPort) {
                webXMLHelper.commitChanges();
            }
        } catch (FileNotFoundException fnf) {
            log.error(fnf);
            return false;
        } catch (TransformerException te) {
            log.error(te);
            return false;
        }
    }
    return true;
}

From source file:org.smartfrog.avalanche.client.sf.apps.gt4wscore.DeployToTomcat.java

public void cleanXMLFiles(String version) throws TomcatConfigException {
    String serverxml = new String(tomcatDirectory.concat("/conf/server.xml"));
    serverxml = serverxml.replace('\\', File.separatorChar);
    serverxml = serverxml.replace('/', File.separatorChar);

    EditXML xmlHelper = null;/*from w w w.  j  a va  2 s.c  om*/
    Element connector = null;
    Element valve = null;
    try {
        xmlHelper = new EditXML(serverxml);

        if (version.startsWith("4.1")) {
            connector = xmlHelper.getElementByTagNameAttrName("Connector", "className",
                    "org.apache.catalina.connector.http.HttpConnector");
            xmlHelper.removeNode(connector);

            valve = xmlHelper.getElementByTagNameAttrName("Valve", "className",
                    "org.globus.tomcat.catalina.valves.HTTPSValve");
            xmlHelper.removeNode(valve);
        } else if (version.startsWith("5.")) {
            connector = xmlHelper.getElementByTagNameAttrName("Connector", "className",
                    "org.globus.tomcat.coyote.net.HTTPSConnector");
            xmlHelper.removeNode(connector);

            valve = xmlHelper.getElementByTagNameAttrName("Valve", "className",
                    "org.globus.tomcat.coyote.valves.HTTPSValve");
            xmlHelper.removeNode(valve);
        } else {
            log.error("The version " + version + " is not supported");
            throw new TomcatConfigException("The version " + version + " is not supported");
        }
    } catch (ParserConfigurationException pce) {
        throw new TomcatConfigException(pce.toString());
    } catch (IOException ioe) {
        throw new TomcatConfigException(ioe.toString());
    } catch (SAXException se) {
        throw new TomcatConfigException(se.toString());
    } finally {
        try {
            xmlHelper.commitChanges();
        } catch (FileNotFoundException fnf) {
            log.error(fnf);
            throw new TomcatConfigException(fnf);
        } catch (TransformerException te) {
            log.error(te);
            throw new TomcatConfigException(te);
        }
    }
}