Example usage for org.xml.sax SAXException printStackTrace

List of usage examples for org.xml.sax SAXException printStackTrace

Introduction

In this page you can find the example usage for org.xml.sax SAXException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:org.azkfw.datasource.xml.XmlDatasourceBuilder.java

/**
 * ?//from  ww w . ja  va2s .c om
 * 
 * @return 
 * @throws FileNotFoundException
 * @throws ParseException
 * @throws IOException
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public Datasource build() throws FileNotFoundException, ParseException, IOException {
    XmlDatasource datasource = new XmlDatasource();
    datasource.name = datasourceName;

    InputStream stream = null;
    try {
        List<XmlTable> tables = new ArrayList<XmlTable>();

        for (File file : xmlFiles) {
            List<XmlTableEntity> tableList = null;

            stream = new FileInputStream(file);
            Digester digester = new Digester();

            digester.addObjectCreate("datasource/tables", ArrayList.class);

            digester.addObjectCreate("datasource/tables/table", XmlTableEntity.class);
            digester.addSetProperties("datasource/tables/table");
            digester.addSetNext("datasource/tables/table", "add");

            digester.addObjectCreate("datasource/tables/table/fields", ArrayList.class);
            digester.addSetNext("datasource/tables/table/fields", "setFields");

            digester.addObjectCreate("datasource/tables/table/fields/field", XmlFieldEntity.class);
            digester.addSetProperties("datasource/tables/table/fields/field");
            digester.addSetNext("datasource/tables/table/fields/field", "add");

            digester.addObjectCreate("datasource/tables/table/records", ArrayList.class);
            digester.addSetNext("datasource/tables/table/records", "setRecords");

            digester.addObjectCreate("datasource/tables/table/records/record", XmlRecordEntity.class);
            digester.addSetNext("datasource/tables/table/records/record", "add");

            digester.addObjectCreate("datasource/tables/table/records/record/data", XmlRecordDataEntity.class);
            digester.addSetProperties("datasource/tables/table/records/record/data");
            digester.addSetNext("datasource/tables/table/records/record/data", "add");

            tableList = digester.parse(stream);

            for (XmlTableEntity t : tableList) {
                XmlTable table = new XmlTable();
                table.label = t.label;
                table.name = t.name;

                // Read Field
                List<XmlField> fields = new ArrayList<XmlField>();
                for (int col = 0; col < t.fields.size(); col++) {
                    XmlFieldEntity f = t.fields.get(col);
                    XmlField field = readField(col, f);
                    fields.add(field);
                }

                // Read Data
                List<XmlRecord> records = new ArrayList<XmlRecord>();
                for (int row = 0; row < t.records.size(); row++) {
                    XmlRecordEntity r = t.records.get(row);
                    if (r.data.size() == fields.size()) {
                        XmlRecord record = readData(row, r, fields);
                        records.add(record);
                    } else {
                        System.out.println("Skip row(unmatch field count).[table: " + table.getName()
                                + "; row: " + r + ";]");
                    }
                }

                table.fields = (List) fields;
                table.records = (List) records;

                tables.add(table);
            }
        }

        datasource.tables = (List) tables;

    } catch (SAXException ex) {
        throw new ParseException(ex.getMessage(), -1);
    } catch (IOException ex) {
        throw ex;
    } finally {
        if (null != stream) {
            try {
                stream.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    return datasource;
}

From source file:org.azkfw.datasource.xml.XmlDatasourceFactory.java

/**
 * XML???/*w  ww  .j  a v a  2s  .c  o m*/
 * 
 * @param aName ??
 * @param aFile XML
 * @return 
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Datasource generate(final String aName, final File aFile)
        throws FileNotFoundException, ParseException, IOException {
    XmlDatasource datasource = new XmlDatasource();
    datasource.name = aName;

    List<XmlTableEntity> tableList = null;

    InputStream stream = null;
    try {
        stream = new FileInputStream(aFile);
        Digester digester = new Digester();

        digester.addObjectCreate("datasource/tables", ArrayList.class);

        digester.addObjectCreate("datasource/tables/table", XmlTableEntity.class);
        digester.addSetProperties("datasource/tables/table");
        digester.addSetNext("datasource/tables/table", "add");

        digester.addObjectCreate("datasource/tables/table/fields", ArrayList.class);
        digester.addSetNext("datasource/tables/table/fields", "setFields");

        digester.addObjectCreate("datasource/tables/table/fields/field", XmlFieldEntity.class);
        digester.addSetProperties("datasource/tables/table/fields/field");
        digester.addSetNext("datasource/tables/table/fields/field", "add");

        digester.addObjectCreate("datasource/tables/table/records", ArrayList.class);
        digester.addSetNext("datasource/tables/table/records", "setRecords");

        digester.addObjectCreate("datasource/tables/table/records/record", XmlRecordEntity.class);
        digester.addSetNext("datasource/tables/table/records/record", "add");

        digester.addObjectCreate("datasource/tables/table/records/record/data", XmlRecordDataEntity.class);
        digester.addSetProperties("datasource/tables/table/records/record/data");
        digester.addSetNext("datasource/tables/table/records/record/data", "add");

        tableList = digester.parse(stream);
    } catch (SAXException ex) {
        throw new ParseException(ex.getMessage(), -1);
    } catch (IOException ex) {
        throw ex;
    } finally {
        if (null != stream) {
            try {
                stream.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    List<XmlTable> tables = new ArrayList<XmlTable>();
    for (XmlTableEntity t : tableList) {
        XmlTable table = new XmlTable();
        table.label = t.label;
        table.name = t.name;

        // Read Field
        List<XmlField> fields = new ArrayList<XmlField>();
        for (int col = 0; col < t.fields.size(); col++) {
            XmlFieldEntity f = t.fields.get(col);
            XmlField field = readField(col, f);
            fields.add(field);
        }

        // Read Data
        List<XmlRecord> records = new ArrayList<XmlRecord>();
        for (int row = 0; row < t.records.size(); row++) {
            XmlRecordEntity r = t.records.get(row);
            if (r.data.size() == fields.size()) {
                XmlRecord record = readData(row, r, fields);
                records.add(record);
            } else {
                System.out.println(
                        "Skip row(unmatch field count).[table: " + table.getName() + "; row: " + r + ";]");
            }
        }

        table.fields = (List) fields;
        table.records = (List) records;

        tables.add(table);
    }

    datasource.tables = (List) tables;
    return datasource;
}

From source file:org.commonjava.indy.ftest.core.content.GroupMetadataMergeWhenGroupWithGroupMemberChangesTest.java

private void assertContent(String expectedXml, String actual) throws IndyClientException, IOException {

    logger.debug("Comparing downloaded XML:\n\n{}\n\nTo expected XML:\n\n{}\n\n", actual, expectedXml);

    try {/*from   www .j a  v a 2s  .c om*/
        XMLUnit.setIgnoreWhitespace(true);
        XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
        XMLUnit.setIgnoreAttributeOrder(true);
        XMLUnit.setIgnoreComments(true);

        assertXMLEqual(expectedXml, actual);
    } catch (SAXException e) {
        e.printStackTrace();
        fail("Downloaded XML not equal to expected XML");
    }
}

From source file:org.commonjava.indy.ftest.core.content.GroupMetadataRemergeWhenConstituentDisabledTest.java

private void assertContent(String actual, String expectedXml) throws IndyClientException, IOException {

    logger.debug("Comparing downloaded XML:\n\n{}\n\nTo expected XML:\n\n{}\n\n", actual, expectedXml);

    try {/*  w w w . j a  v  a2s  .c om*/
        XMLUnit.setIgnoreWhitespace(true);
        XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
        XMLUnit.setIgnoreAttributeOrder(true);
        XMLUnit.setIgnoreComments(true);

        assertXMLEqual(actual, expectedXml);
    } catch (SAXException e) {
        e.printStackTrace();
        fail("Downloaded XML not equal to expected XML");
    }
}

From source file:org.commonjava.indy.koji.content.testutil.KojiMockHandlers.java

private static ExpectationHandler kojiMessageHandler(MockScript mockScript, String resourceBase) {
    return (request, response) -> {
        String nextBase = mockScript.getNextScriptBaseName();
        if (nextBase == null) {
            fail("Cannot retrieve next base-name in mock script: "
                    + mockScript.getHumanReadableScriptAttemptCount() + "/" + mockScript.getScriptCount()
                    + " from: " + resourceBase);
        }/*from   w  w  w  . j a v a  2 s.com*/

        String requestPath = Paths.get(resourceBase, String.format("%s-request.xml", nextBase)).toString();
        String responsePath = Paths.get(resourceBase, String.format("%s-response.xml", nextBase)).toString();

        Logger logger = LoggerFactory.getLogger(KojiMockHandlers.class);
        logger.debug(
                "Verifying vs request XML resource: {}\nSending response XML resource: {}\nRequest index: {}",
                requestPath, responsePath, mockScript.getHumanReadableScriptAttemptCount());

        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(requestPath);
        if (in == null) {
            fail("Cannot find request XML for comparison: " + requestPath);
        }

        String expectedXml = IOUtils.toString(in);
        String requestXml = IOUtils.toString(request.getInputStream());

        logger.debug("Comparing request XML:\n\n{}\n\nTo expected XML:\n\n{}\n\n", requestXml, expectedXml);

        try {
            XMLUnit.setIgnoreWhitespace(true);
            XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
            XMLUnit.setIgnoreAttributeOrder(true);
            XMLUnit.setIgnoreComments(true);

            assertXMLEqual("Requested XML not equal to expected XML from: " + requestPath, expectedXml,
                    requestXml);
        } catch (SAXException e) {
            e.printStackTrace();
            fail("Cannot find parse either requested XML or expected XML from: " + requestPath);
        }

        in = Thread.currentThread().getContextClassLoader().getResourceAsStream(responsePath);
        if (in == null) {
            fail("Cannot find response XML: " + responsePath);
        }

        response.setStatus(200);
        OutputStream out = response.getOutputStream();
        IOUtils.copy(in, out);
    };
}

From source file:org.commonjava.indy.promote.ftest.RecursiveGroupMetadataFoundAfterMemberPromotedTest.java

private void assertContent(ArtifactStore store, String path, String expectedXml)
        throws IndyClientException, IOException {
    try (InputStream stream = client.content().get(store.getKey(), path)) {
        assertThat("Stream for " + store.getKey() + ":" + path + " was missing!", stream, notNullValue());

        String downloaded = IOUtils.toString(stream);

        logger.debug("{}:{}: Comparing downloaded XML:\n\n{}\n\nTo expected XML:\n\n{}\n\n", store.getKey(),
                path, downloaded, expectedXml);

        XMLUnit.setIgnoreWhitespace(true);
        XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
        XMLUnit.setIgnoreAttributeOrder(true);
        XMLUnit.setIgnoreComments(true);

        assertXMLEqual("Downloaded XML not equal to expected XML from: " + path + " in: " + store.getKey(),
                downloaded, expectedXml);
    } catch (SAXException e) {
        e.printStackTrace();
        fail("Downloaded XML not equal to expected XML from: " + path + " in: " + store.getKey());
    }//from  w  ww .ja  v  a2s.  co m
}

From source file:org.deri.pipes.endpoints.SindiceProxy.java

public void searchSindice(String term) {
    int noResults = 0, totalResults;
    String searchUrl;/*from  w  w  w . j  av a 2  s.c  o  m*/
    searchUrl = createSindiceSearchString(term, 1);

    while (true) {

        try {
            String output = readHTTP(searchUrl);
            if (output == null)
                return;
            JSONObject result = new JSONObject(output);
            JSONArray resultList = result.getJSONArray("entries");
            totalResults = result.getInt("totalResults");

            for (int i = 0; i < resultList.length(); i++) {

                noResults++;
                String link = ((JSONObject) resultList.get(i)).getString("link");
                URL url;
                String domain = "";
                try {
                    url = new URL(link);
                    domain = url.getHost().toLowerCase();

                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                if (!domains.contains(domain)) {
                    domains.add(domain);
                    System.out.println("domain" + domain);
                    if (hasSitemap(domain)) {
                        firstURI.put(domain, link);
                        try {

                            DOMParser parser = new DOMParser();

                            parser.parse("http://" + domain + "/sitemap.xml");
                            Document doc = parser.getDocument();
                            if (doc == null) {
                                System.out.println("doc null");
                                return;
                            }
                            Element rootElm = doc.getDocumentElement();
                            if (rootElm == null) {
                                System.out.println("root element null");
                                return;
                            }
                            Element datasetElm = XMLUtil.getFirstSubElementByName(rootElm, "sc:dataset");
                            if (datasetElm != null) {
                                System.out.println("first child tag " + datasetElm.getTagName());
                                String sparqlEndpoint = XMLUtil.getTextFromFirstSubEleByName(datasetElm,
                                        "sc:sparqlEndpointLocation");
                                if (sparqlEndpoint != null) {
                                    sparqlEndPoints.put(domain, sparqlEndpoint);
                                    descs.put(domain, "" + XMLUtil.getTextFromFirstSubEleByName(datasetElm,
                                            "sc:datasetLabel"));
                                }
                            }

                        } catch (SAXException se) {
                            se.printStackTrace();
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                        }
                    }
                }
                if ((noResults >= 1000) || (noResults >= totalResults))
                    return;
            }
            searchUrl = result.getString("next");

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:org.easyxml.xml.Document.java

/**
 * //from w  w w.  java 2 s. c o m
 * If there is a solid defaultContainer, then the attribute would be
 * appended to it directly.
 * 
 * {@inheritDoc}
 * 
 * 
 * 
 * @see org.easyxml.xml.Element#addAttribute(java.lang.String,
 *      java.lang.String)
 */

@Override
public Element addAttribute(String name, String value) {

    try {

        if (defaultContainer != null) {

            defaultContainer.addAttribute(name, value);

        } else {

            super.addAttribute(name, value);

        }

    } catch (SAXException ex) {

        ex.printStackTrace();

    }

    return this;

}

From source file:org.easyxml.xml.Element.java

/**
 * //w  ww . j a v  a2s . c  o m
 * Set the attribute value.
 * 
 * @param attributeName
 *            - Name of the concerned attribute.
 * 
 * @param newValue
 *            - New value of the attribute.
 * 
 * @return
 * 
 *         'false' if there is any confliction with XML specification.
 * 
 *         'true' set attribute value successfully.
 */

public Boolean setAttributeValue(String attributeName, String newValue) {

    if (this.attributes != null && this.attributes.containsKey(attributeName)) {

        this.attributes.get(attributeName).setValue(newValue);

        return true;

    }

    try {

        this.addAttribute(attributeName, newValue);

        return true;

    } catch (SAXException e) {

        e.printStackTrace();

        return false;

    }

}

From source file:org.eshark.xmlprog.cache.ClassCache.java

public void loadFromXML(File aXMLFile) throws XMLProgFormatException {
    try {/*w  w w .  j  a v a 2s . c o  m*/
        DocumentBuilder lDocumentBuilder = getDocumentBuilder();
        lDocumentBuilder.setEntityResolver(new Resolver());
        // For XML
        Document lXMLDocument = null;
        if (aXMLFile == null)
            lXMLDocument = lDocumentBuilder.parse(new File(FILE_PATH + "\\xmls", FILE_NAME));
        else
            lXMLDocument = lDocumentBuilder.parse(aXMLFile);

        // normalize the document
        lXMLDocument.getDocumentElement().normalize();

        // Read the XML and create the cache
        Element daoElement = (Element) lXMLDocument.getChildNodes().item(1);
        String xmlVersion = daoElement.getAttribute("version");
        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
            throw new XMLProgFormatException("Exported Class Cache file format version " + xmlVersion
                    + " is not supported. This XMLProg Configuration installation can read" + " versions "
                    + EXTERNAL_XML_VERSION + " or older. You" + " may need to check the configuration.");
        importClasses(daoElement);
    } catch (ParserConfigurationException PCE) {
        PCE.printStackTrace();
    } catch (SAXException SXE) {
        SXE.printStackTrace();
    } catch (IOException IOE) {
        IOE.printStackTrace();
    }
}