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:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java

/**
 * create child/*from w ww  .ja v a 2s  .c  om*/
 *
 * @param childXpath
 *
 * @return
 */
protected final Element createChildElement(String childXpath) {
    int index = childXpath.indexOf("/");
    String elementName = childXpath;
    String subChildXpath = null;
    Element element = null;
    Element child = null;
    if (index > 0) {
        elementName = childXpath.substring(0, index);
        subChildXpath = childXpath.substring(index + 1);
        child = createChildElement(subChildXpath);
    }
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.newDocument();
        element = document.createElement(elementName);
        if (child != null) {
            Node importedNode = document.importNode(child, true);
            element.appendChild(importedNode);
        }
    } catch (ParserConfigurationException pce) {
        log.error("Exception thrown from createChildElement(): " + pce.getMessage());
        pce.printStackTrace();
    }

    return element;
}

From source file:org.sakaiproject.tool.help.RestContentProvider.java

/**
 * create document/*from   ww  w.j av  a  2s  .  com*/
 * @return document
 */
private static Document createDocument() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createDocument()");
    }

    Document document = null;
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    try {
        DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
        document = documentBuilder.newDocument();
    } catch (ParserConfigurationException e) {
        LOG.error(e.getMessage(), e);
        e.printStackTrace();
    }

    return document;
}

From source file:org.scantegrity.crypto.FlatFileTable.java

public void saveXmlFile(File p_directory, String p_name) {
    try {//w  ww. jav a 2  s  .c om
        DocumentBuilder l_b = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document l_doc = l_b.newDocument();

        Element l_root = l_doc.createElement("table");

        for (int x = 0; x < c_list.size(); x++) {
            Element l_row = l_doc.createElement("row");
            for (int y = 0; y < c_list.get(x).size(); y++) {
                Object l_obj = c_list.get(x).get(y);
                l_row.appendChild(getXmlRepresentation(l_doc, l_obj));
            }
            l_root.appendChild(l_row);
        }

        l_doc.appendChild(l_root);

        Transformer l_trans = TransformerFactory.newInstance().newTransformer();
        l_trans.setOutputProperty(OutputKeys.INDENT, "yes");
        l_trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        DOMSource l_source = new DOMSource(l_doc);
        StreamResult l_res = new StreamResult(
                new FileOutputStream(p_directory.getAbsolutePath() + File.separatorChar + p_name + ".xml"));

        l_trans.transform(l_source, l_res);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TransformerFactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.scantegrity.IRVTally.IRVTally.java

public static void main(String args[]) {
    TreeMap<Integer, Vector<ContestChoice>> l_results = null;

    setOptions();/*from  w  w  w .  j ava  2s . com*/

    String l_args[] = null;
    CommandLine l_cmdLine = null;
    try {
        CommandLineParser l_parser = new PosixParser();
        l_cmdLine = l_parser.parse(c_opts, args);
        l_args = l_cmdLine.getArgs();
    } catch (ParseException l_e) {
        l_e.printStackTrace();
        return;
    }

    if (l_cmdLine == null || l_cmdLine.hasOption("help") || l_args == null || l_args.length != 2) {
        printUsage();
        return;
    }

    //Looks like we have valid arguments, try to read M3
    try {
        l_results = ParseMeetingThree(l_args[0]);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        return;
    } catch (SAXException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        System.out.println("Could not read '" + l_args[0] + "'");
        return;
    }

    //Get contest information, if possible.
    Vector<Contest> l_c = null;
    if (l_cmdLine.hasOption("info")) {
        System.out.println("Contest Information");
        try {
            l_c = loadContest(l_cmdLine.getOptionValue("info"));
            //validateContest(l_results, l_c);
        } catch (Exception l_e) {
            l_e.printStackTrace();
            l_c = null;
        }
    }

    if (l_c == null) {
        //Load defaults
        System.out.print("Contest information is missing! ");
        System.out.print("Generating default contest information...");
        l_c = getContestDefaults(l_results);
        System.out.println("done");
    }

    //Get the ballots and Print
    try {
        createResults(l_c, l_results, l_args[1]);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.scantegrity.openstv.m32ostv.java

public static void main(String args[]) {
    TreeMap<Integer, Vector<Ballot>> l_results = null;

    setOptions();/*ww w  . j ava2s . c o  m*/

    String l_args[] = null;
    CommandLine l_cmdLine = null;
    try {
        CommandLineParser l_parser = new PosixParser();
        l_cmdLine = l_parser.parse(c_opts, args);
        l_args = l_cmdLine.getArgs();
    } catch (ParseException l_e) {
        l_e.printStackTrace();
        return;
    }

    if (l_cmdLine == null || l_cmdLine.hasOption("help") || l_args == null || l_args.length < 1
            || l_args.length > 2) {
        printUsage();
        return;
    }

    //Looks like we have valid arguments, try to read M3
    try {
        l_results = ParseMeetingThree(l_args[0]);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        return;
    } catch (SAXException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        System.out.println("Could not read '" + l_args[0] + "'");
        return;
    }

    //Get contest information, if possible.
    Vector<Contest> l_c = null;
    if (l_cmdLine.hasOption("info")) {
        System.out.println("Contest Information");
        try {
            l_c = loadContest(l_cmdLine.getOptionValue("info"));
            //validateContest(l_results, l_c);
        } catch (Exception l_e) {
            l_e.printStackTrace();
            l_c = null;
        }
    }

    if (l_c == null) {
        //Load defaults
        System.out.print("Contest information is missing! ");
        System.out.print("Generating default contest information...");
        l_c = getContestDefaults(l_results);
        System.out.println("done");
    }

    //Convert results to BLT format.
    Integer l_key = l_results.firstKey();
    while (l_key != null) {
        /*
        for (Ballot l_b : l_results.get(l_key))
        {
           System.out.println(l_b.getId());
           System.out.println(java.util.Arrays.deepToString(l_b.getBallotData().get(0)));
                   
        }*/
        //Find the corresponding contest
        Contest l_contest = null;
        for (Contest l_con : l_c)
            if (l_con.getId().equals(l_key)) {
                l_contest = l_con;
                break;
            }
        if (l_contest == null) {
            System.out.println("Contest " + l_key + " could not be found...");
            continue;
        }
        //Get the ballots and Print
        try {
            createBLT(l_contest, l_results.get(l_key));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        l_key = l_results.higherKey(l_key);
    }

}

From source file:org.sead.va.dataone.Object.java

@POST
@Path("/{objectId}")
@Consumes(MediaType.APPLICATION_XML)//  w  w w .j  a v  a 2  s  . c o  m
@Produces(MediaType.APPLICATION_XML)
public Response addObject(@Context HttpServletRequest request, @PathParam("objectId") String id,
        @QueryParam("creators") String creators, @QueryParam("deprecateFgdc") String deprecateFgdc,
        String fgdcString) throws UnsupportedEncodingException {

    Document metaInfo = new Document();
    metaInfo.put(Constants.META_FORMAT, "http://www.fgdc.gov/schemas/metadata/fgdc-std-001-1998.xsd");
    metaInfo.put(Constants.RO_ID, id);

    org.w3c.dom.Document doc = null;
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(new ByteArrayInputStream(fgdcString.getBytes()));
    } catch (ParserConfigurationException e) {
        System.out.println(e.getMessage());
    } catch (SAXException e) {
        System.out.println(e.getMessage());
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }

    String creator = "";
    if (creators != null && !creators.equals("")) {
        creator = URLEncoder.encode(creators.split("\\|")[0].replace(" ", "").replace(",", "")) + "-";
    }
    String fgdcId = "seadva-" + creator + UUID.randomUUID().toString();
    metaInfo.put(Constants.FGDC_ID, fgdcId);

    final byte[] utf8Bytes = fgdcString.getBytes("UTF-8");
    metaInfo.put(Constants.SIZE, utf8Bytes.length);

    String strDate = simpleDateFormat.format(new Date());
    metaInfo.put(Constants.META_UPDATE_DATE, strDate);
    metaInfo.put(Constants.DEPOSIT_DATE, strDate);

    try {
        DigestInputStream digestStream = new DigestInputStream(new ByteArrayInputStream(fgdcString.getBytes()),
                MessageDigest.getInstance("SHA-1"));
        if (digestStream.read() != -1) {
            byte[] buf = new byte[1024];
            while (digestStream.read(buf) != -1)
                ;
        }
        byte[] digest = digestStream.getMessageDigest().digest();
        metaInfo.put(Constants.FIXITY_FORMAT, "SHA-1");
        metaInfo.put(Constants.FIXITY_VAL, new String(Hex.encodeHex(digest)));
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    Document document = new Document();
    document.put(Constants.META_INFO, metaInfo);
    document.put(Constants.METADATA, fgdcString);

    RO_STATUS updated = RO_STATUS.NOT_EXIST;
    updated = deprecateFGDC(id, document);
    if (deprecateFgdc != null && !deprecateFgdc.equals("") && updated == RO_STATUS.NOT_EXIST) {
        updated = deprecateFGDC(deprecateFgdc, document);
    }

    if (updated == RO_STATUS.NON_IDENTICAL || updated == RO_STATUS.NOT_EXIST) {
        fgdcCollection.insertOne(document);
    }

    return Response.ok().build();
}

From source file:org.sofun.platform.opta.parser.AbstractOptaParser.java

public void parseXmlFile() {
    SAXParserFactory factory = SAXParserFactory.newInstance();

    try {//from ww w .j  a v  a2  s  . co m
        SAXParser parser = factory.newSAXParser();
        if (f != null) {
            parser.parse(f, this);
        } else {
            log.error("File is null. Cannot parse.");
        }
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
}

From source file:org.stathissideris.ascii2image.core.ConversionOptions.java

public ConversionOptions(CommandLine cmdLine) throws UnsupportedEncodingException {

    processingOptions.setVerbose(cmdLine.hasOption("verbose"));
    renderingOptions.setDropShadows(!cmdLine.hasOption("no-shadows"));
    this.setDebug(cmdLine.hasOption("debug"));
    processingOptions.setOverwriteFiles(cmdLine.hasOption("overwrite"));

    if (cmdLine.hasOption("scale")) {
        Float scale = Float.parseFloat(cmdLine.getOptionValue("scale"));
        renderingOptions.setScale(scale.floatValue());
    }/*  w ww . ja v a  2  s.c o m*/

    processingOptions.setAllCornersAreRound(cmdLine.hasOption("round-corners"));
    processingOptions.setPerformSeparationOfCommonEdges(!cmdLine.hasOption("no-separation"));
    renderingOptions.setAntialias(!cmdLine.hasOption("no-antialias"));
    renderingOptions.setFixedSlope(cmdLine.hasOption("fixed-slope"));

    if (cmdLine.hasOption("background")) {
        String b = cmdLine.getOptionValue("background");
        Color background = parseColor(b);
        renderingOptions.setBackgroundColor(background);
    }

    if (cmdLine.hasOption("transparent")) {
        renderingOptions.setBackgroundColor(new Color(0, 0, 0, 0));
    }

    if (cmdLine.hasOption("tabs")) {
        Integer tabSize = Integer.parseInt(cmdLine.getOptionValue("tabs"));
        int tabSizeValue = tabSize.intValue();
        if (tabSizeValue < 0)
            tabSizeValue = 0;
        processingOptions.setTabSize(tabSizeValue);
    }

    String encoding = (String) cmdLine.getOptionValue("encoding");
    if (encoding != null) {
        new String(new byte[2], encoding);
        processingOptions.setCharacterEncoding(encoding);
    }

    ConfigurationParser configParser = new ConfigurationParser();
    try {
        for (Option curOption : cmdLine.getOptions()) {
            if (curOption.getLongOpt().equals("config")) {
                String configFilename = curOption.getValue();
                System.out.println("Parsing configuration file " + configFilename);
                File file = new File(configFilename);
                if (file.exists()) {
                    configParser.parseFile(file);
                    HashMap<String, CustomShapeDefinition> shapes = configParser.getShapeDefinitionsHash();
                    processingOptions.putAllInCustomShapes(shapes);
                } else {
                    System.err.println("File " + file + " does not exist, skipping");
                }
            }
        }
    } 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();
    }
}

From source file:org.talend.dataprofiler.core.migration.impl.CheckAndUpdateAnalysisDependencyTask.java

private File removeNotUsedModels(File file) {
    // remove not used any more: where aide rule
    DocumentBuilder db;//ww  w. ja  va 2s .  co m
    try {
        boolean needSave = false;
        db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = db.parse(file);
        Element root = document.getDocumentElement();
        NodeList list = root.getElementsByTagName("indicators"); //$NON-NLS-1$
        for (int i = 0; i < list.getLength(); i++) {
            Node item = list.item(i);
            NamedNodeMap attributes = item.getAttributes();
            Node typeItem = attributes.getNamedItem("xsi:type"); //$NON-NLS-1$
            if (StringUtils.equals("dataquality.indicators.sql:WhereRuleAideIndicator", //$NON-NLS-1$
                    typeItem.getNodeValue())) {
                item.getParentNode().removeChild(item);
                needSave = true;
            }
        }
        if (needSave) {
            saveFile(file, document);
        }

    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        return null;
    } catch (SAXException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return file;
}

From source file:org.tinymce.spellchecker.GoogleSpellChekerServlet.java

public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter();
    try {//w ww .j  av  a 2 s.co  m
        JSONObject requestJSONdata = requestDataToJSON(request.getInputStream());
        String method = requestJSONdata.getString("method");
        String language = requestJSONdata.getJSONArray("params").getString(0);
        this.connect(language);
        this.setHeaders();
        String textToCheck;

        if (method.equalsIgnoreCase("checkWords")) {
            JSONArray words = requestJSONdata.getJSONArray("params").getJSONArray(1);
            textToCheck = words.join(" ").replaceAll("\"", "");
        } else if (method.equalsIgnoreCase("getSuggestions")) {
            textToCheck = requestJSONdata.getJSONArray("params").getString(1);
        } else {
            out.println(
                    "{\"id\":null,\"results\":null,\"error\":\"Invalid request, method not yet implemented\"}");
            out.flush();
            return;
        }

        this.sendData(getXML(textToCheck));
        JSONObject responseJSON = this.receiveData(method, textToCheck);
        if (responseJSON == null) {
            out.println("{\"id\":null,\"results\":null,\"error\":\"No suggestions were received\"}");
            out.flush();
            return;
        }

        responseJSON.write(out);
        out.flush();
    } catch (JSONException e1) {
        e1.printStackTrace();
        //Send error to client, exit
        out.println("{\"id\":null,\"results\":null,\"error\":\"Invalid request, cannot parse json data\"}");
        out.flush();
        return;
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }

}