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() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

/**
 * Parse the XML file and create Document
 * @param fileName//from w  w w  .ja  v  a2 s . c o m
 * @return Document
 */
public static Document parse(InputStream fs) {
    Document document = null;
    // Initiate DocumentBuilderFactory
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    // To get a validating parser
    factory.setValidating(false);

    // To get one that understands namespaces
    factory.setNamespaceAware(true);
    try {
        // Get DocumentBuilder
        DocumentBuilder builder = factory.newDocumentBuilder();

        // Parse and load into memory the Document
        //document = builder.parse( new File(fileName));
        document = builder.parse(fs);
        return document;
    } catch (SAXParseException spe) {
        // Error generated by the parser
        System.err.println("\n** Parsing error , line " + spe.getLineNumber() + ", uri " + spe.getSystemId());
        System.err.println(" " + spe.getMessage());
        // Use the contained exception, if any
        Exception x = spe;
        if (spe.getException() != null)
            x = spe.getException();
        x.printStackTrace();
    } catch (SAXException sxe) {
        // Error generated during parsing
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        pce.printStackTrace();
    } catch (IOException ioe) {
        // I/O error
        ioe.printStackTrace();
    }

    return null;
}

From source file:tud.time4maps.request.CapabilitiesRequest.java

public static String doRequest_Plain(String wmsUrl) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // factory.setNamespaceAware( true ); factory.setValidating( true );
    try {//from  w  w  w. jav  a2 s.  c o  m
        DocumentBuilder builder = factory.newDocumentBuilder();
        return getResponseString(wmsUrl);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:tud.time4maps.request.CapabilitiesRequest.java

/**
 * This method is called by class RequestControlling and handles WMS requests.
 * /*w ww.  java  2 s  . c om*/
 * @param wmsUrl - the wms request url
 * @return response document 
 */
public static Document doRequest(String wmsUrl) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // factory.setNamespaceAware( true ); factory.setValidating( true );
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new ByteArrayInputStream(getResponseString(wmsUrl).getBytes()));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Set<String> compareXmlFiles(String firstFolderPath, String secondFolderPath, boolean outConsole) {
    Set<String> identicalFiles = new HashSet<String>();

    File firstFolder = new File(firstFolderPath);
    File secondFolder = new File(secondFolderPath);

    Map<String, File> firstFileMap = new HashMap<String, File>();
    Map<String, File> secondFileMap = new HashMap<String, File>();

    traverseFolder(firstFileMap, firstFolder, firstFolder);
    traverseFolder(secondFileMap, secondFolder, secondFolder);

    // temporarily - comparison by MD5 instead of XML parsing
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = null;/*from  w  w  w. j a  v a2  s.co  m*/
    try {
        saxParser = factory.newSAXParser();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
    System.out.println("Parser: " + saxParser);

    Set<String> sourceKeys = firstFileMap.keySet();
    Set<String> destKeys = secondFileMap.keySet();
    for (String key1 : sourceKeys) {
        File file1 = firstFileMap.get(key1);
        File file2 = secondFileMap.get(key1);
        if (file1 != null && file2 != null) {
            try {
                String node1 = calculateMd5Checksum(file1.getCanonicalPath());
                String node2 = calculateMd5Checksum(file2.getCanonicalPath());
                // System.out.println("Source:" + node1 + " Dest:" + node2);
                if (node1.equals(node2)) {
                    firstFileMap.remove(key1);
                    secondFileMap.remove(key1);
                }
            } catch (Exception ex) {
                ex.printStackTrace(); // can be ignored
            }
        }
    }

    for (String key1 : sourceKeys) {
        if (destKeys.contains(key1)) {
            identicalFiles.add(key1);
            sourceKeys.remove(key1);
            destKeys.remove(key1);
        }
    }

    if (outConsole == true) {

    }

    return identicalFiles;
}

From source file:org.wise.vle.domain.webservice.crater.CRaterHttpClient.java

/**
 * Gets and Returns the Score from the CRater response XML string,
 * or -1 if it does not exist./*from  w w w  .j  ava2  s.c o  m*/
 * @param cRaterResponseXML response XML from the CRater. Looks like this:
 * <crater-results>
 *   <tracking id="1013701"/>
 *   <client id="WISETEST"/>
 *   <items>
 *     <item id="Photo_Sun">
 *     <responses>
 *       <response id="testID" score="4" concepts="1,2,3,4,5"/>
 *     </responses>
 *   </item>
 * </items>
 * 
 * @return integer score returned from the CRater. In the case above, this method will return 4.
 */
public static int getScore(String cRaterResponseXML) {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db;
        db = dbf.newDocumentBuilder();
        Document doc = db.parse(new ByteArrayInputStream(cRaterResponseXML.getBytes()));
        NodeList responseList = doc.getElementsByTagName("response");
        Node response = responseList.item(0);
        String score = response.getAttributes().getNamedItem("score").getNodeValue();
        return Integer.valueOf(score);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:org.wise.vle.domain.webservice.crater.CRaterHttpClient.java

/**
 * Gets and Returns the Concepts from the CRater response XML string,
 * or "" if it does not exist./*w  ww . java2  s.  co m*/
 * @param cRaterResponseXML response XML from the CRater. Looks like this:
 * <crater-results>
 *   <tracking id="1013701"/>
 *   <client id="WISETEST"/>
 *   <items>
 *     <item id="Photo_Sun">
 *     <responses>
 *       <response id="testID" score="4" concepts="1,2,3,4,5"/>
 *     </responses>
 *   </item>
 * </items>
 * 
 * @return String concepts returned from the CRater. In the case above, this method will return "1,2,3,4,5".
 */
public static String getConcepts(String cRaterResponseXML) {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db;
        db = dbf.newDocumentBuilder();
        Document doc = db.parse(new ByteArrayInputStream(cRaterResponseXML.getBytes()));
        NodeList responseList = doc.getElementsByTagName("response");
        Node response = responseList.item(0);
        if (response.getAttributes().getNamedItem("concepts") != null) {
            return response.getAttributes().getNamedItem("concepts").getNodeValue();
        } else {
            return "";
        }
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:elaborate.util.XmlUtil.java

public static boolean isWellFormed(String body) {
    try {//from w ww.  ja v  a  2s . c  o m
        SAXParser parser;
        parser = SAXParserFactory.newInstance().newSAXParser();
        DefaultHandler dh = new DefaultHandler();
        parser.parse(new InputSource(new StringReader(body)), dh);
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
        return false;
    } catch (SAXException e1) {
        e1.printStackTrace();
        Log.error("body={}", body);
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.isa.ws.utiles.UtilesSWHelper.java

public static String getNodeValue(String xml, String node) {
    //get the factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    try {//w  ww .ja va 2  s. c  om

        //Using factory get an instance of document builder
        DocumentBuilder db = dbf.newDocumentBuilder();

        //parse using builder to get DOM representation of the XML file
        InputStream is = new ByteArrayInputStream(xml.getBytes());
        Document dom = db.parse(is);
        NodeList nodelist = dom.getElementsByTagName(node);
        Node node1 = nodelist.item(0);
        String value = null;
        if (node1.getFirstChild() != null) {
            if (node.equals("css:validity")) {
                value = "";
                value += node1.getChildNodes().item(0).getFirstChild().getNodeValue();
                value += ",";
                value += node1.getChildNodes().item(1).getFirstChild().getNodeValue();
            } else
                value = node1.getFirstChild().getNodeValue();
        }
        return value;

    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
        return null;
    } catch (SAXException se) {
        se.printStackTrace();
        return null;
    } catch (IOException ioe) {
        ioe.printStackTrace();
        return null;
    }
}

From source file:elaborate.editor.export.tei.TeiMaker.java

static Document createTeiDocument() {
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    try {/*from   www. j a  v  a 2 s  .com*/
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        Document teiDocument = docBuilder.newDocument();
        return teiDocument;
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:jGPIO.DTO.java

/**
 * Tries to use lshw to detect the physical system in use.
 * //www. j  a  v  a2s.c om
 * @return The filename of the GPIO Definitions file.
 */
static private String autoDetectSystemFile() {
    String definitions = System.getProperty("definitions.lookup");
    if (definitions == null) {
        definitions = DEFAULT_DEFINITIONS;
    }

    File capabilitiesFile = new File(definitions);

    // If it doesn't exist, fall back to the default
    if (!capabilitiesFile.exists() && !definitions.equals(DEFAULT_DEFINITIONS)) {
        System.out.println("Could not find definitions lookup file at: " + definitions);
        System.out.println("Trying default definitions file at: " + definitions);
        capabilitiesFile = new File(DEFAULT_DEFINITIONS);
    }

    if (!capabilitiesFile.exists()) {
        System.out.println("Could not find definitions file at: " + definitions);
        return null;
    }

    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = null;
    try {
        dBuilder = dbFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
    }

    // Generate the lshw output if available
    Process lshw;
    try {
        lshw = Runtime.getRuntime().exec("lshw -c bus -disable dmi -xml");
        lshw.waitFor();
    } catch (Exception e1) {
        System.out.println("Couldn't execute lshw to identify board");
        e1.printStackTrace();
        return null;
    }
    Document lshwXML = null;
    try {
        lshwXML = dBuilder.parse(lshw.getInputStream());
    } catch (IOException e1) {
        System.out.println("IO Exception running lshw");
        e1.printStackTrace();
        return null;
    } catch (SAXException e1) {
        System.out.println("Could not parse lshw output");
        e1.printStackTrace();
        return null;
    }

    XPath xp = XPathFactory.newInstance().newXPath();
    NodeList capabilities;
    try {
        capabilities = (NodeList) xp.evaluate("/list/node[@id=\"core\"]/capabilities/capability", lshwXML,
                XPathConstants.NODESET);
    } catch (XPathExpressionException e1) {
        System.out.println("Couldn't run Caoability lookup");
        e1.printStackTrace();
        return null;
    }

    Document lookupDocument = null;
    try {
        lookupDocument = dBuilder.parse(capabilitiesFile);
        String lookupID = null;

        for (int i = 0; i < capabilities.getLength(); i++) {
            Node c = capabilities.item(i);
            lookupID = c.getAttributes().getNamedItem("id").getNodeValue();
            System.out.println("Looking for: " + lookupID);
            NodeList nl = (NodeList) xp.evaluate("/lookup/capability[@id=\"" + lookupID + "\"]", lookupDocument,
                    XPathConstants.NODESET);

            if (nl.getLength() == 1) {
                definitionFile = nl.item(0).getAttributes().getNamedItem("file").getNodeValue();
                pinDefinitions = (JSONArray) new JSONParser().parse(new FileReader(definitionFile));
                return definitionFile;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}