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:XMLConfig.java

/** Creates an empty configuration.
 *///from  w  w w .  ja v  a 2  s . co m
public XMLConfig() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        _document = builder.newDocument(); // Create from whole cloth
        // NOTE: not 1.4 compatible -- _document.setXmlStandalone(true);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:com.mirth.connect.model.util.ImportConverter.java

public static String convertFilter(String filterXml) throws Exception {
    filterXml = convertPackageNames(filterXml);
    filterXml = runStringConversions(filterXml);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document document;//from  ww w  .j  a va  2 s . c  o m
    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
        document = builder.parse(new InputSource(new StringReader(filterXml)));

        updateFilterFor1_4(document.getDocumentElement());
        updateFilterFor1_7(document);
        updateFilterFor2_0(document);

        DocumentSerializer docSerializer = new DocumentSerializer();
        filterXml = docSerializer.toXML(document);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return updateLocalAndGlobalVariables(filterXml);
}

From source file:gr.demokritos.iit.cru.creativity.reasoning.diagrammatic.DiagrammaticComputationalTools.java

public HashSet<String> Graphs(JSONArray triples1, JSONArray triples2)
        throws FileNotFoundException, UnsupportedEncodingException, URISyntaxException, IOException,
        ParserConfigurationException, SAXException, XPathExpressionException, SQLException {
    // JSON a=new JSON();
    /*//from  w w  w. jav a 2  s.co m
     JSONArray users = new JSONArray();
     JSONObject obj1 = new JSONObject();
     obj1.put("c1", "rambo");
     obj1.put("rel", "likes");
     obj1.put("c2", "mambo");
     users.add(obj1);
     JSONObject obj2 = new JSONObject();
     obj2.put("c1", "rambo");
     obj2.put("rel", "likes");
     obj2.put("c2", "mambo");
     users.add(obj2);
     Object[] m = users.toArray();*/
    String filenameSource = "C:\\Users\\George\\Desktop\\projects\\diagrammatic\\triples1.rdf";// + System.currentTimeMillis() + 
    PrintWriter writer = new PrintWriter(filenameSource, "UTF-8");
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
            + "         xmlns=\"http://c2learn.eu/onto1#\"\n"///http://www.semagrow.eu/schemas/family#
            + "xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"
            + "         xmlns:owl=\"http://www.w3.org/2002/07/owl#\">\n" + "\n"
            + "<owl:Ontology rdf:about=\"\">\n" + "</owl:Ontology>\n" + "\n");

    for (Object triple : triples1) {
        // System.out.println(triple.toString());
        JSONObject jtriple = (JSONObject) triple;
        String concept = jtriple.get("c1").toString().toLowerCase();
        String relation = jtriple.get("rel").toString().toLowerCase();
        String subject = jtriple.get("c2").toString().toLowerCase();
        //  writer.write(" <owl:Class rdf:about=" + concept + ">\n"
        //          + "</owl:Class>\n");
        if (relation.equalsIgnoreCase("isA")) {
            writer.write("<owl:Class rdf:ID=\"" + concept + "\">\n");
            writer.write("<rdfs:label>" + concept + "</rdfs:label>\n");
            writer.write("<owl:subclassof rdf:resource=\"#" + subject + "\"/>\n");
            writer.write("</owl:Class>\n");
        }
        /*else {
         writer.write("<owl:ObjectProperty rdf:ID=\"" + relation + "\">\n");
         writer.write("<rdfs:range rdf:resource=\"#" + subject + "\"/>\n");
         writer.write("<rdfs:domain rdf:resource=\"#" + concept + "\"/>\n");
         writer.write("<rdfs:label>" + relation + "</rdfs:label>\n");
         writer.write("</owl:ObjectProperty>\n");
         }*/
        writer.write("\n");
    }
    writer.write("</rdf:RDF>");
    writer.close();

    String filenameTarget = "C:\\Users\\George\\Desktop\\projects\\diagrammatic\\triples2.rdf";////" + System.currentTimeMillis() + "

    writer = new PrintWriter(filenameTarget, "UTF-8");
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
            + "         xmlns=\"http://c2learn.eu/onto2#\"\n"//http://www.semagrow.eu/schemas/family#
            + "xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"
            + "         xmlns:owl=\"http://www.w3.org/2002/07/owl#\">\n" + "\n"
            + "<owl:Ontology rdf:about=\"\">\n" + "</owl:Ontology>\n" + "\n");
    for (Object triple : triples1) {
        // System.out.println(triple.toString());
        JSONObject jtriple = (JSONObject) triple;
        String concept = jtriple.get("c1").toString().toLowerCase();
        String relation = jtriple.get("rel").toString().toLowerCase();
        String subject = jtriple.get("c2").toString().toLowerCase();
        //  writer.write(" <owl:Class rdf:about=" + concept + ">\n"
        //          + "</owl:Class>\n");
        if (relation.equalsIgnoreCase("isA")) {
            writer.write("<owl:Class rdf:ID=\"" + concept + "\">\n");
            writer.write("<rdfs:label>" + concept + "</rdfs:label>\n");
            writer.write("<owl:subclassof rdf:resource=\"#" + subject + "\"/>\n");
            writer.write("</owl:Class>\n");
        }
        /*else {
         writer.write("<owl:ObjectProperty rdf:ID=\"" + relation + "\">\n");
         writer.write("<rdfs:range rdf:resource=\"#" + subject + "\"/>\n");
         writer.write("<rdfs:domain rdf:resource=\"#" + concept + "\"/>\n");
         writer.write("<rdfs:label>" + relation + "</rdfs:label>\n");
         writer.write("</owl:ObjectProperty>\n");
         }*/
        writer.write("\n");
    }
    writer.write("</rdf:RDF>");
    writer.close();

    String fileSeparator = "\\";
    //String oaeiDirectorySubsConceptsOnly = "C:/Users/antonis/Documents/NetBeansProjects/Synthesis/benchmarks";
    //   String oaeiDirectoryEqualsConceptsOnly = "C:/Users/antonis/Documents/NetBeansProjects/Synthesis/benchmarks";
    //String onto1 = "http://oaei.ontologymatching.org/2011/benchmarks/101/onto.rdf";
    //String onto2 = "http://oaei.ontologymatching.org/2011/benchmarks/248/onto.rdf";
    String onto1 = filenameSource;// oaeiDirectoryEqualsConceptsOnly + fileSeparator + source + fileSeparator + "onto.rdf";;
    String onto2 = filenameTarget;// oaeiDirectoryEqualsConceptsOnly + fileSeparator + target + fileSeparator + "onto.rdf";;;

    onto1 = new File(onto1).toURI().toString();
    onto2 = new File(onto2).toURI().toString();

    String outputPath = System.getProperty("user.dir") + fileSeparator;
    // System.out.println(outputPath + "refalign.rdf");
    /*
             ResultsStorage storePrecisionCSR = new ResultsStorage("precisionCSR.txt");
             ResultsStorage storeRecalCSR = new ResultsStorage("recallCSR.txt");
            
             ResultsStorage storePrecisionVSM = new ResultsStorage("precisionVSM.txt");
             ResultsStorage storeRecalVSM = new ResultsStorage("recallVSM.txt");
            
             ResultsStorage storePrecisionCSRFactor = new ResultsStorage("precisionCSRFactor.txt");
             ResultsStorage storeRecalCSRFactor = new ResultsStorage("recallCSRFactor.txt");
            
             ResultsStorage storePrecisionVSMFactor = new ResultsStorage("precisionVSMFactor.txt");
             ResultsStorage storeRecalVSMFactor = new ResultsStorage("recallVSMFactor.txt");
            
             ResultsStorage storePrecisionCocluFactor = new ResultsStorage("precisionCocluFactor.txt");
             ResultsStorage storeRecalCocluFactor = new ResultsStorage("recallCocluFactor.txt");
            
             ResultsStorage storePrecisionCoclu = new ResultsStorage("precisionCoclu.txt");
             ResultsStorage storeRecalCoclu = new ResultsStorage("recallCoclu.txt");
            
             ResultsStorage storeCorrectCSR = new ResultsStorage("correctCSR.txt");
             ResultsStorage storeErrorCSR = new ResultsStorage("errorCSR.txt");
            
             ResultsStorage storeCorrectCoclu = new ResultsStorage("correctCoclu.txt");
             ResultsStorage storeErrorCoclu = new ResultsStorage("errorCoclu.txt");
            
             ResultsStorage storeCorrectCocluFactor = new ResultsStorage("correctCocluFactor.txt");
             ResultsStorage storeErrorCocluFactor = new ResultsStorage("errorCocluFactor.txt");
            
             ResultsStorage storeConfuzedEqualsForSubsCoclu = new ResultsStorage("ConfuzedEqualsForSubsCoclu.txt");
             ResultsStorage storeConfuzedEqualsForSubsCocluFactor = new ResultsStorage("ConfuzedEqualsForSubsCocluFactor.txt");
            
             ResultsStorage storeCorrectVSM = new ResultsStorage("correctVSM.txt");
             ResultsStorage storeErrorVSM = new ResultsStorage("errorVSM.txt");
             ResultsStorage storeCorrectCSRFactor = new ResultsStorage("correctCSRFactor.txt");
             ResultsStorage storeErrorCSRFactor = new ResultsStorage("errorCSRFactor.txt");
             ResultsStorage storeCorrectVSMFactor = new ResultsStorage("correctVSMFactor.txt");
             ResultsStorage storeErrorVSMFactor = new ResultsStorage("errorVSMFactor.txt");
             ResultsStorage storeConfuzedEqualsForSubsVSM = new ResultsStorage("ConfuzedEqualsForSubsVSM.txt");
             ResultsStorage storeConfuzedEqualsForSubsVSMFactor = new ResultsStorage("ConfuzedEqualsForSubsVSMFactor.txt");
             ResultsStorage storeConflictsEquals = new ResultsStorage("ConflictsEquals.txt");
             ResultsStorage storeConflictsSubs = new ResultsStorage("ConflictsSubs.txt");
             ResultsStorage storeMessages = new ResultsStorage("Messages.txt");
            
             ResultsStorage timeDuration = new ResultsStorage("timeDuration.txt");
            
             try {
             RunCoclouVsmCsrFactorGraphs synthesis = new RunCoclouVsmCsrFactorGraphs(onto1, onto2, outputPath,
             outputPath + "refalign.rdf", outputPath + "refalign.rdf", false, false, true,
             true,
             1, false, false, 0, 0.3, true, false, "over", "j48", false, false,
             10000, false, storePrecisionCSR, storeRecalCSR, storePrecisionVSM, storeRecalVSM,
             storePrecisionCSRFactor, storeRecalCSRFactor, storePrecisionVSMFactor, storeRecalVSMFactor,
             storeCorrectCSR, storeErrorCSR, storeCorrectVSM, storeErrorVSM, storeCorrectCSRFactor,
             storeErrorCSRFactor, storeCorrectVSMFactor, storeErrorVSMFactor, storeConfuzedEqualsForSubsVSM,
             storeConfuzedEqualsForSubsVSMFactor, storePrecisionCoclu, storeRecalCoclu, storeCorrectCoclu,
             storeErrorCoclu, storeConfuzedEqualsForSubsCoclu, storePrecisionCocluFactor, storeRecalCocluFactor,
             storeCorrectCocluFactor, storeErrorCocluFactor, storeConfuzedEqualsForSubsCocluFactor,
             timeDuration, storeConflictsEquals, storeConflictsSubs, storeMessages, true);
             synthesis.run();
             System.out.println(filenameTarget + " finished...");
             } catch (Exception e) {
             e.printStackTrace();
             }
            
             storePrecisionCSR.exportToFile();
             storeRecalCSR.exportToFile();
             storePrecisionVSM.exportToFile();
             storeRecalVSM.exportToFile();
             storePrecisionCSRFactor.exportToFile();
             storeRecalCSRFactor.exportToFile();
             storePrecisionVSMFactor.exportToFile();
             storeRecalVSMFactor.exportToFile();
             storeCorrectCSR.exportToFile();
             storeErrorCSR.exportToFile();
             storeCorrectVSM.exportToFile();
             storeErrorVSM.exportToFile();
             storeCorrectCSRFactor.exportToFile();
             storeErrorCSRFactor.exportToFile();
             storeCorrectVSMFactor.exportToFile();
             storeErrorVSMFactor.exportToFile();
             storeConfuzedEqualsForSubsVSM.exportToFile();
             storeConfuzedEqualsForSubsVSMFactor.exportToFile();
             storePrecisionCoclu.exportToFile();
             storeRecalCoclu.exportToFile();
             storeCorrectCoclu.exportToFile();
             storeErrorCoclu.exportToFile();
             storeConfuzedEqualsForSubsCoclu.exportToFile();
             storePrecisionCocluFactor.exportToFile();
             storeRecalCocluFactor.exportToFile();
             storeCorrectCocluFactor.exportToFile();
             storeErrorCocluFactor.exportToFile();
             storeConfuzedEqualsForSubsCocluFactor.exportToFile();
             timeDuration.exportToFile();
             storeConflictsEquals.exportToFile();
             storeConflictsSubs.exportToFile();
             storeMessages.exportToFile();
            
             storePrecisionCSR.close();
             storeRecalCSR.close();
             storePrecisionVSM.close();
             storeRecalVSM.close();
             storePrecisionCSRFactor.close();
             storeRecalCSRFactor.close();
             storePrecisionVSMFactor.close();
             storeRecalVSMFactor.close();
             storeCorrectCSR.close();
             storeErrorCSR.close();
             storeCorrectVSM.close();
             storeErrorVSM.close();
             storeCorrectCSRFactor.close();
             storeErrorCSRFactor.close();
             storeCorrectVSMFactor.close();
             storeErrorVSMFactor.close();
             storeConfuzedEqualsForSubsVSM.close();
             storeConfuzedEqualsForSubsVSMFactor.close();
             storePrecisionCoclu.close();
             storeRecalCoclu.close();
             storeCorrectCoclu.close();
             storeErrorCoclu.close();
             storeConfuzedEqualsForSubsCoclu.close();
             storePrecisionCocluFactor.close();
             storeRecalCocluFactor.close();
             storeCorrectCocluFactor.close();
             storeErrorCocluFactor.close();
             storeConfuzedEqualsForSubsCocluFactor.close();
             timeDuration.close();
             storeConflictsEquals.close();
             storeConflictsSubs.close();
             storeMessages.close();*/

    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document document = null;
    try {
        builder = builderFactory.newDocumentBuilder();
        document = (Document) builder.parse(new FileInputStream(outputPath + "alignment.rdf"));
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    document.getDocumentElement().normalize();
    System.out.println("Root element :" + document.getDocumentElement().getNodeName());

    NodeList nl = document.getElementsByTagName("Cell");

    System.out.println("----------------------------");
    for (int temp = 0; temp < nl.getLength(); temp++) {

        Node nNode = nl.item(temp);

        System.out.println("\nCurrent Element :" + nNode.getNodeName());

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

            Element eElement = (Element) nNode;
            Element ent1 = (Element) eElement.getElementsByTagName("entity1").item(0);
            Element ent2 = (Element) eElement.getElementsByTagName("entity2").item(0);
            System.out.println(ent1.getAttribute("rdf:resource").split("#")[1]);
            System.out.println(ent2.getAttribute("rdf:resource").split("#")[1]);
            //  System.out.println("Staff id : " + eElement.getAttribute("rdf:resource"));
            System.out.println(
                    "relation : " + eElement.getElementsByTagName("relation").item(0).getTextContent());
            System.out
                    .println("measure : " + eElement.getElementsByTagName("measure").item(0).getTextContent());
            if (eElement.getElementsByTagName("relation").item(0).getTextContent().equalsIgnoreCase("=")) {
                Queries q = new Queries(this.conn);
                q.Insert(ent1.getAttribute("rdf:resource").split("#")[1],
                        ent2.getAttribute("rdf:resource").split("#")[1],
                        eElement.getElementsByTagName("measure").item(0).getTextContent());
            }
        }
    }
    //  String expression = "//Alignment//Cell";
    //   XPath xPath = XPathFactory.newInstance().newXPath();
    //   XPathExpression expr = xPath.compile(expression);

    //   NodeList nl = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
    //   for (Node n : nl) {
    //         System.out.println(n.getNodeName());
    //   }
    //  Object[] idsNode = node.evaluateXPath("//Alignment/Cell");
    //read a string value
    // Node node = (Node) xPath.compile(expression).evaluate(document, XPathConstants.NODE);
    /*
     BufferedReader in = new BufferedReader(new FileReader(outputPath + "alignment.rdf"));
     String line;
     while ((line = in.readLine()) != null) {
            
     }*/
    return new HashSet<String>();
}

From source file:net.chaosserver.timelord.swingui.Timelord.java

/**
 * Check if there is a newer version of the timelord application
 * available and if so, prompt the user to download the new version.
 * //from  w w  w . j  a  v a  2  s . co m
 * @return if the user wants to download a new version
 */
public boolean isUpgradeRequested() {
    boolean result = false;
    Properties appProperties = getAppProperties();

    if (appProperties != null) {
        String pomUrlString = appProperties.getProperty("pomurl");
        String appVersion = appProperties.getProperty("implementation.version");

        if (pomUrlString != null) {
            InputStream pomStream = null;

            try {
                URL pomUrl = new URL(pomUrlString);
                pomStream = pomUrl.openStream();

                if (log.isDebugEnabled()) {
                    log.debug("Opened URL [" + pomUrl + "] with result ["
                            + (pomStream != null ? pomStream.available() : "null") + "]");
                }

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document doc = builder.parse(pomStream);

                if (log.isTraceEnabled()) {
                    log.trace("Loaded document: " + doc.getDocumentElement());
                }

                Element pomversionElement = doc.getElementById("pomversion");
                String pomVersion = "";
                if (pomversionElement != null) {
                    pomVersion = pomversionElement.getNodeValue();
                }

                if (appVersion == null) {
                    appVersion = "";
                }

                if (log.isDebugEnabled()) {
                    log.debug("Testinv version of app [" + appVersion + "] against version of pom ["
                            + pomVersion + "]");
                }

                if (!pomVersion.equals(appVersion)) {

                }

            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                if (pomStream != null) {
                    try {
                        pomStream.close();
                    } catch (IOException e) {
                        if (log.isInfoEnabled()) {
                            log.info("failed to close pomstream", e);
                        }
                    }
                }
            }

        } else {
            if (log.isWarnEnabled()) {
                log.warn("Got back blank pomurl, so not checking " + "for upgrade.");
            }
        }
    } else {
        if (log.isWarnEnabled()) {
            log.warn("Got back blank properties, so not checking " + "for upgrade.");
        }
    }

    return result;
}

From source file:uk.org.openeyes.diagnostics.AbstractFieldProcessor.java

/**
 * Attempts to extract patient and exam information from the specified file.
 *
 * @param file the file to interrogate; must be non-null and point to an
 * existing study (XML) file./*from   w  w w  .  j a v  a 2s  .com*/
 *
 * @return valid humphrey meta data if the file could be parsed; otherwise,
 * an empty
 *
 * @throws FileNotFoundException if the file does not exist.
 * @throws ParserConfigurationException if the file could not be parsed.
 * @throws XPathExpressionException if there are any issues evaluating
 * paths.
 */
protected HumphreyFieldMetaData parseFields(File file) throws FileNotFoundException {
    HumphreyFieldMetaData metaData = new HumphreyFieldMetaData(this.regex);
    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document document = builder.parse(file);
        XPath xPath = XPathFactory.newInstance().newXPath();
        if ("CZM-XML".equals(document.getDocumentElement().getNodeName())) {
            // define xpath expressions for data values:
            String root = "/CZM-XML/DataSet/CZM_HFA_EMR_IOD/";
            String patientRoot = root + "Patient_M/";
            String machineRoot = root + "CZM_HFA_Series_M/";
            String imageRoot = root + "ReferencedImage_M/";
            String dateTimeRoot = root + "GeneralStudy_M/";
            String eyeRoot = root + "GeneralSeries_M/";

            String patientId = patientRoot + "patient_id";
            String patientGivenName = patientRoot + "patients_name/given_name";
            String patientFamilyName = patientRoot + "patients_name/family_name";
            String patientDoB = patientRoot + "patients_birth_date";

            String deviceTestName = machineRoot + "test_name";
            String deviceTestStrategy = machineRoot + "test_strategy";

            String deviceTestDate = dateTimeRoot + "study_date";
            String deviceTestTime = dateTimeRoot + "study_time";

            String fileReference = imageRoot + "file_reference";
            String eye = eyeRoot + "laterality";
            // set the given values, if they exist:
            metaData.setGivenName(this.evaluate(document, xPath, patientGivenName));
            metaData.setFamilyName(this.evaluate(document, xPath, patientFamilyName));
            metaData.setDob(this.evaluate(document, xPath, patientDoB));
            metaData.setTestDate(this.evaluate(document, xPath, deviceTestDate));
            metaData.setTestTime(this.evaluate(document, xPath, deviceTestTime));
            metaData.setTestStrategy(this.evaluate(document, xPath, deviceTestStrategy));
            metaData.setTestPattern(this.evaluate(document, xPath, deviceTestName));
            metaData.setPatientId(this.evaluate(document, xPath, patientId));
            metaData.setFileReference(this.evaluate(document, xPath, fileReference));
            metaData.setEye(this.evaluate(document, xPath, eye));
        } else if ("HFA_EXPORT".equals(document.getDocumentElement().getNodeName())) {
            String root = "/HFA_EXPORT/";

            String patientRoot = root + "PATIENT/";

            String studyRoot = patientRoot + "STUDY/";
            String visitDate = this.evaluate(document, xPath, studyRoot + "VISIT_DATE");
            String seriesRoot = studyRoot + "SERIES/";
            String fieldExam = seriesRoot + "FIELD_EXAM/";
            String examTime = this.evaluate(document, xPath, fieldExam + "EXAM_TIME");
            String staticTest = fieldExam + "STATIC_TEST/";
            // laterality not stored in this version of the file; obtain it via file name
            String eye = "L";
            // OS/OD == oculus sinister/dexter = left/right
            if (file.getName().contains("_OD_")) {
                eye = "R";
            } else if (file.getName().contains("_OU_")) {
                eye = "B";
            }
            String fileReference = fieldExam + "/SINGLE_EXAM_IMAGE/IMAGE_FILE_NAME";

            metaData.setPatientId(this.evaluate(document, xPath, patientRoot + "PATIENT_ID"));
            metaData.setDob(this.evaluate(document, xPath, patientRoot + "BIRTH_DATE"));
            metaData.setGivenName(this.evaluate(document, xPath, patientRoot + "GIVEN_NAME"));
            metaData.setFamilyName(this.evaluate(document, xPath, patientRoot + "LAST_NAME"));
            metaData.setEye(eye);
            metaData.setTestStrategy(
                    this.getStrategy(this.evaluate(document, xPath, staticTest + "TEST_STRATEGY")));
            metaData.setTestPattern(
                    this.getPattern(this.evaluate(document, xPath, staticTest + "TEST_PATTERN")));
            metaData.setTestDate(visitDate);
            metaData.setTestTime(examTime);
            metaData.setFileReference(this.evaluate(document, xPath, fileReference));
        }
    } catch (SAXException e) {
        // nothing to do
        e.printStackTrace();
    } catch (IOException e) {
        // nothing to do
        e.printStackTrace();
    } catch (ParserConfigurationException pcex) {
        // nothing to do
        pcex.printStackTrace();
    }
    return metaData;
}

From source file:de.fhg.fokus.diameter.DiameterPeer.DiameterPeer.java

private boolean readConfigFile(String cfgFile) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // factory.setValidating(true);
    // factory.setNamespaceAware(true);
    try {//from  w  ww . j a  v a2s .  co  m
        DocumentBuilder builder = factory.newDocumentBuilder();
        config = builder.parse(cfgFile);
    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
        return false;
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        pce.printStackTrace();
        return false;
    } catch (IOException ioe) {
        // I/O error
        ioe.printStackTrace();
        return false;
    }
    return true;
}

From source file:de.fhg.fokus.diameter.DiameterPeer.DiameterPeer.java

private boolean readConfigString(String cfgString) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // factory.setValidating(true);
    // factory.setNamespaceAware(true);
    try {// w  w  w  . ja va  2s .co  m
        DocumentBuilder builder = factory.newDocumentBuilder();
        config = builder.parse(new InputSource(new StringReader(cfgString)));
    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
        return false;
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        pce.printStackTrace();
        return false;
    } catch (IOException ioe) {
        // I/O error
        ioe.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.hin.hl7messaging.InvoiceSvgService.java

@Override
public String createSvgDocument(Document doc, List<Concept> invoiceServiceArray, String organizationName,
        String telecom, String address, String exchangeRate, String currencyCode) {

    String stringData = "", invoiceId = "", totalAmount = "", doctorName = "", patientName = "", discount = "",
            interest = "";
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;//from w  ww .j  a  v  a 2  s.com
    HashMap<String, String> serviceMap = new HashMap<String, String>();
    HashMap<String, String> xCoordinatesMap = new HashMap<String, String>();

    String doctorPrefix = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/consultant/employmentStaff/employeePerson/name/prefix",
            XPathConstants.STRING);
    String doctorGiven = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/consultant/employmentStaff/employeePerson/name/given",
            XPathConstants.STRING);
    String doctorFamily = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/consultant/employmentStaff/employeePerson/name/family",
            XPathConstants.STRING);
    String doctorSuffix = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/consultant/employmentStaff/employeePerson/name/suffix",
            XPathConstants.STRING);

    if (doctorPrefix != null && doctorPrefix != "")
        doctorName = doctorName + " " + doctorPrefix;
    if (doctorGiven != null && doctorGiven != "")
        doctorName = doctorName + " " + doctorGiven;
    if (doctorFamily != null && doctorFamily != "")
        doctorName = doctorName + " " + doctorFamily;
    if (doctorSuffix != null && doctorSuffix != "")
        doctorName = doctorName + " " + doctorSuffix;

    NodeList idFields = (NodeList) XMLHelper.read(doc, "message/FIAB_MT020000HT02/id", XPathConstants.NODESET);
    int idSize = idFields.getLength();

    for (int i = 1; i <= idSize; i++) {

        String rootNode = "message/FIAB_MT020000HT02/id[" + i + "]/root";
        String root = (String) XMLHelper.read(doc, rootNode, XPathConstants.STRING);
        root = root.replaceAll("\\n", "").trim();
        if (root.equals("INVOICE_ID")) {
            invoiceId = (String) XMLHelper.read(doc, "message/FIAB_MT020000HT02/id[" + i + "]/extension",
                    XPathConstants.STRING);
        }
        if (root.equals("INVOICE_AMOUNT")) {
            totalAmount = (String) XMLHelper.read(doc, "message/FIAB_MT020000HT02/id[" + i + "]/extension",
                    XPathConstants.STRING);
        }
        if (root.equals("DISCOUNT")) {
            discount = (String) XMLHelper.read(doc, "message/FIAB_MT020000HT02/id[" + i + "]/extension",
                    XPathConstants.STRING);
        }
        if (root.equals("INTEREST")) {
            interest = (String) XMLHelper.read(doc, "message/FIAB_MT020000HT02/id[" + i + "]/extension",
                    XPathConstants.STRING);
        }

    }

    String date = (String) XMLHelper.read(doc, "message/FIAB_MT020000HT02/effectiveTime/value",
            XPathConstants.STRING);
    String[] myStringArray = date.split(" ");
    date = myStringArray[0];

    String prefix = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/subject/patient/patientPerson/name/prefix",
            XPathConstants.STRING);
    String given = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/subject/patient/patientPerson/name/given",
            XPathConstants.STRING);
    String family = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/subject/patient/patientPerson/name/family",
            XPathConstants.STRING);
    String suffix = (String) XMLHelper.read(doc,
            "message/FIAB_MT020000HT02/postingTo/patientAccount/pertinentInformation/encounterEvent/subject/patient/patientPerson/name/suffix",
            XPathConstants.STRING);

    if (prefix != null && prefix != "")
        patientName = patientName + " " + prefix;
    if (given != null && given != "")
        patientName = patientName + " " + given;
    if (family != null && family != "")
        patientName = patientName + " " + family;
    if (suffix != null && suffix != "")
        patientName = patientName + " " + suffix;

    //System.out.println("Patient Name: " + patientName);

    NodeList serviceFields = (NodeList) XMLHelper.read(doc, "message/FIAB_MT020000HT02/pertinentInformation",
            XPathConstants.NODESET);
    int serviceSize = serviceFields.getLength();

    for (int i = 1; i <= serviceSize; i++) {

        String serviceName = (String) XMLHelper.read(doc,
                "message/FIAB_MT020000HT02/pertinentInformation[" + i + "]/observationOrder/code/displayName",
                XPathConstants.STRING);
        serviceName = serviceName.replaceAll("\\n", "").trim();
        String cost = (String) XMLHelper.read(doc,
                "message/FIAB_MT020000HT02/component[" + i
                        + "]/financialTransactionChargeDetail/unitPriceAmt/numerator/value",
                XPathConstants.STRING);
        cost = cost.replaceAll("\\n", "").trim();

        String serviceCode = (String) XMLHelper.read(doc,
                "message/FIAB_MT020000HT02/pertinentInformation[" + i + "]/observationOrder/code/code",
                XPathConstants.STRING);
        serviceCode = serviceCode.replaceAll("\\n", "").trim();

        serviceMap.put(serviceName, cost);

        if (invoiceServiceArray != null && !invoiceServiceArray.isEmpty()) {
            for (Concept service : invoiceServiceArray) {
                if (!service.getDescription().equals(serviceCode)) {
                    serviceMap.put("---" + service.getDescription(), "");
                }
            }
        }
    }

    try {
        db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    Document document = db.newDocument();
    Element rootElement = createRootElement(document);
    Element g = document.createElement("g");
    Element subG = document.createElement("g");

    Element imageElement = createImage(document, subG);

    String style = "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#500e4a;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light";

    Element organizationElement = createTestTitleElement(document, subG, organizationName, "500", "113", style);
    Element addressElement = createTestTitleElement(document, subG, address, "500", "133", style);
    Element telecomElement = createTestTitleElement(document, subG, telecom, "500", "153", style);

    style = "font-size:25.52000046px;font-variant:normal;font-weight:bold;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light-Bold";
    Element headerElement = createTestTitleElement(document, subG, "INVOICE", "1050", "113", style);

    style = "font-size:18.44000006px;font-variant:normal;font-weight:bold;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light-Bold";
    Element customerElement = createTestTitleElement(document, subG, "To: " + patientName, "100", "290", style);

    style = "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light";
    Element invoiceNumElement = createTestTitleElement(document, subG, "Invoice Number : " + invoiceId, "930",
            "290", style);
    Element dateElement = createTestTitleElement(document, subG, "Date : " + date, "930", "310", style);
    Element doctorElement = createTestTitleElement(document, subG, "Doctor : " + doctorName, "930", "330",
            style);

    Element horizontalElement = createHorizontalLine(document, subG, "100", "380");
    Element verticalElement = createVerticleLines(document, subG, "100", "380", serviceMap.size());
    Element horizontalHeaderEndElement = createHorizontalLine(document, subG, "100", "450");

    style = "font-size:18.44000006px;font-variant:normal;font-weight:bold;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light-Bold";
    Element descriptionElement = createTestTitleElement(document, subG, "Description", "400", "410", style);
    Element amtHeaderElement = createTestTitleElement(document, subG, "Amount in USD", "980", "410", style);

    style = "font-size:18.44000006px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Myriad Pro Light;-inkscape-font-specification:Myriad Pro Light";

    xCoordinatesMap.put("115", "1150");

    Element closeElement = createEndComponent(document, subG, "100", String.valueOf(serviceYAxis + 100),
            totalAmount, exchangeRate, currencyCode, discount, interest);
    Element serviceElement = createServiceElement(document, subG, serviceMap, xCoordinatesMap, "480", style);

    rootElement.appendChild(g);
    g.appendChild(imageElement);
    g.appendChild(organizationElement);
    g.appendChild(addressElement);
    g.appendChild(telecomElement);
    g.appendChild(headerElement);
    g.appendChild(customerElement);
    g.appendChild(invoiceNumElement);
    g.appendChild(dateElement);
    g.appendChild(doctorElement);
    g.appendChild(horizontalElement);
    g.appendChild(verticalElement);
    g.appendChild(horizontalHeaderEndElement);
    g.appendChild(descriptionElement);
    g.appendChild(amtHeaderElement);
    g.appendChild(closeElement);
    g.appendChild(serviceElement);
    g.appendChild(serviceElement);

    document.appendChild(rootElement);
    stringData = XMLHelper.getXMLDocumentAsString(document);
    //System.out.println(stringData);
    return stringData;
}

From source file:info.guardianproject.mrapp.server.YouTubeSubmit.java

private String gdataUpload(File file, String uploadUrl, int start) throws IOException {

    //int chunk = end - start + 1;
    //int bufferSize = 1024;
    //byte[] buffer = new byte[bufferSize];
    FileInputStream fileStream = new FileInputStream(file);
    URL url = new URL(uploadUrl);
    HttpPost hPut = getGDataHttpPost(url.getHost(), uploadUrl, null);
    hPut.setHeader("X-HTTP-Method-Override", "PUT");

    // some mobile proxies do not support PUT, using X-HTTP-Method-Override to get around this problem
    if (isFirstRequest()) {
        Log.d(LOG_TAG,//from w  w  w.  ja v  a  2 s.  co m
                String.format("First time...Uploaded %d bytes so far.", (int) totalBytesUploaded, Locale.US));

    } else {

        Log.d(LOG_TAG, String.format(Locale.US, "Retry: Uploaded %d bytes so far.", (int) totalBytesUploaded));
    }

    String mimeType = "video/mp4";

    hPut.setHeader("Content-Type", mimeType);

    long fileLength = file.length();
    if (start != -1) {
        String cRange = String.format(Locale.US, "bytes %d-%d/%d", start, fileLength, fileLength);
        hPut.setHeader("Content-Range", cRange);
        Log.d(LOG_TAG, "upload content-range: " + cRange);
    }

    InputStreamEntityWithProgress fileEntity = new InputStreamEntityWithProgress(fileStream, start, fileLength,
            mimeType);//"binary/octet-stream");
    hPut.setEntity(fileEntity);

    HttpResponse hResp = httpClient.execute(hPut);

    int responseCode = hResp.getStatusLine().getStatusCode();

    Log.d(LOG_TAG, "responseCode=" + responseCode);
    Log.d(LOG_TAG, "responseMessage=" + hResp.getStatusLine().getReasonPhrase());

    InputStream isResp = hResp.getEntity().getContent();

    try {
        if (responseCode == 201) {
            String videoId = parseVideoId(isResp);

            /*
            String latLng = null;
            if (this.videoLocation != null) {
              latLng = String.format("lat=%f lng=%f", this.videoLocation.getLatitude(),
                  this.videoLocation.getLongitude(), Locale.US);
            }
            */

            Message msg = handler.obtainMessage(888);
            msg.getData().putInt("progress", 100);
            handler.sendMessage(msg);

            return videoId;
        } else if (responseCode == 200) {
            Header[] headers = hResp.getAllHeaders();

            Log.d(LOG_TAG, String.format("Headers keys %s.", headers.length, Locale.US));
            for (Header header : headers) {
                Log.d(LOG_TAG, String.format("Header key %s value %s.", header.getName(), header.getValue(),
                        Locale.US));
            }
            Log.w(LOG_TAG, "Received 200 response during resumable uploading");
            throw new IOException(
                    String.format(Locale.US, "Unexpected response code : responseCode=%d responseMessage=%s",
                            responseCode, hResp.getStatusLine().getReasonPhrase()));
        } else {

            if ((responseCode + "").startsWith("5")) {
                String error = String.format(Locale.US, "responseCode=%d responseMessage=%s", responseCode,
                        hResp.getStatusLine().getReasonPhrase());
                Log.w(LOG_TAG, error);
                // TODO - this exception will trigger retry mechanism to kick in
                // TODO - even though it should not, consider introducing a new type so
                // TODO - resume does not kick in upon 5xx
                throw new IOException(error);
            } else if (responseCode == 308) { // these actually means "resume incomplete"
                // OK, the chunk completed succesfully 
                Log.d(LOG_TAG, String.format("responseCode=%d responseMessage=%s", responseCode,
                        hResp.getStatusLine().getReasonPhrase()));
            } else {
                // TODO - this case is not handled properly yet
                Log.w(LOG_TAG, String.format("Unexpected return code : %d %s while uploading :%s", responseCode,
                        hResp.getStatusLine().getReasonPhrase(), uploadUrl, Locale.US));
            }

        }
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.hp.rest.GenericResource.java

@Path("/putJourney")
@POST//ww w .j av a  2 s  .c o m
@Produces(MediaType.TEXT_XML)
public String updateJourney(@FormParam("data") String str) {
    RoadManagementDAO roadManagementDAO = new RoadManagementDAOImpl();
    //Get current time
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    System.out.println(dateFormat.format(cal.getTime()));

    String pXML = "";
    try {
        pXML = new String(str.getBytes("UTF-8"), "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(new InputSource(new StringReader(pXML)));

        doc.getDocumentElement().normalize();

        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

        NodeList nList = doc.getElementsByTagName("road");

        System.out.println("----------------------------");

        for (int temp = 0; temp < nList.getLength(); temp++) {
            //init customer
            Customer customer = new Customer();

            Node nNode = nList.item(temp);

            System.out.println("\nCurrent Element :" + nNode.getNodeName());

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

                Element eElement = (Element) nNode;

                String customerid = eElement.getAttribute("id");

                float x = Float.parseFloat(eElement.getElementsByTagName("x").item(0).getTextContent());
                float y = Float.parseFloat(eElement.getElementsByTagName("y").item(0).getTextContent());
                String staffid = eElement.getElementsByTagName("staffid").item(0).getTextContent();

                System.out.println("customer id : " + customerid);
                System.out.println("staff id : " + staffid);
                System.out.println("X : " + x);
                System.out.println("Y : " + y);
                System.out.println("TIME : " + "");

                //UPDATE into Database
                RoadManagement roadManagement = new RoadManagement();
                roadManagement.setMaNhanVien(staffid);
                roadManagement.setTenNhanVien(customerid);
                roadManagement.setViDo(x);
                roadManagement.setKinhDo(y);
                roadManagement.setThoiGian(Timestamp.valueOf(dateFormat.format(cal.getTime())));

                roadManagementDAO.saveOrUpdate(roadManagement);

            }
        }

        return "OK";
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "ERROR";
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "ERROR";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "ERROR";
    }
}