List of usage examples for org.xml.sax SAXException getMessage
public String getMessage()
From source file:com.grameenfoundation.ictc.controllers.SaleforceIntegrationController.java
public static Document parseXmlText(InputSource input_data) { //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {/*from ww w . jav a 2s .com*/ //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //InputSource is = new InputSource(); //is.setCharacterStream(new StringReader(data)); //parse using builder to get DOM representation of the data Document doc = db.parse(input_data); // normalize text representation doc.getDocumentElement().normalize(); System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName()); return doc; } catch (ParserConfigurationException pce) { System.out.println("Exception is " + pce.getLocalizedMessage()); pce.printStackTrace(); return null; } catch (SAXException se) { System.out.println("Exception is " + se.getLocalizedMessage()); System.out.println("line " + se.getMessage()); se.printStackTrace(); return null; } catch (IOException ioe) { System.out.println("Exception is " + ioe.getLocalizedMessage()); ioe.printStackTrace(); return null; } catch (Exception ex) { System.out.println("Exception is " + ex.getLocalizedMessage()); // ioe.printStackTrace(); return null; } }
From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java
public static RelationMapping read(InputStream istream, File basedir) throws IOException { // Create new parser object XMLReader parser;// w ww.j a v a 2 s .com try { parser = new DefaultXMLReaderFactory().createXMLReader(); } catch (SAXException e) { throw new IOException("Problems occurred when creating SAX2 XMLReader: " + e.getMessage()); } // Create content handler RelationMapping mapping = new RelationMapping(); mapping.setBaseDirectory(basedir); ContentHandler vhandler = new ValidatingContentHandler(mapping, getRelaxNGSchema(), true); parser.setContentHandler(vhandler); try { // Parse input source parser.parse(new InputSource(istream)); } catch (FileNotFoundException e) { log.error("Resource not found: {}", e.getMessage()); throw e; } catch (SAXParseException e) { throw new OntopiaRuntimeException("XML parsing problem: " + e.toString() + " at: " + e.getSystemId() + ":" + e.getLineNumber() + ":" + e.getColumnNumber(), e); } catch (SAXException e) { if (e.getException() instanceof IOException) throw (IOException) e.getException(); throw new OntopiaRuntimeException(e); } // Compile mapping mapping.compile(); return mapping; }
From source file:edu.stanford.epad.common.util.EPADFileUtils.java
public static boolean isValidXmlUsingClassPathSchema(File f, String xsdSchema) { try {/*ww w .j a v a 2s . c om*/ log.debug("xml:" + f.getName() + " xsd:" + xsdSchema); FileInputStream xml = new FileInputStream(f); InputStream xsd = null; try { xsd = EPADFileUtils.class.getClassLoader().getResourceAsStream(xsdSchema); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(new StreamSource(xsd)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(xml)); return true; } catch (SAXException ex) { log.info("Error: validating template/annotation " + ex.getMessage()); } catch (IOException e) { log.info("Error: validating template/annotation " + e.getMessage()); } } catch (IOException e) { log.info("Exception validating a file: " + f.getName()); } return false; }
From source file:edu.stanford.epad.common.util.EPADFileUtils.java
public static String validateXml(File f, String xsdSchema) throws Exception { try {//from w ww . j a v a 2 s . co m FileInputStream xml = new FileInputStream(f); InputStream xsd = null; try { xsd = new FileInputStream(xsdSchema); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(new StreamSource(xsd)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(xml)); return ""; } catch (SAXException ex) { log.info("Error: validating template/annotation " + ex.getMessage()); return ex.getMessage(); } catch (IOException e) { log.info("Error: validating template/annotation " + e.getMessage()); throw e; } } catch (IOException e) { log.info("Exception validating a file: " + f.getName()); throw e; } }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorParserTest.java
@Test public void shouldPerformPluginXsdValidationAndFailWhenIDIsNotPresent() throws Exception { InputStream pluginXml = IOUtils.toInputStream("<go-plugin version=\"1\"></go-plugin>"); try {// www . ja v a 2 s . c o m GoPluginDescriptorParser.parseXML(pluginXml, "/tmp/", new File("/tmp/"), true); fail("xsd validation should have failed"); } catch (SAXException e) { assertThat(e.getMessage(), is("XML Schema validation of Plugin Descriptor(plugin.xml) failed")); } }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorParserTest.java
@Test public void shouldPerformPluginXsdValidationAndFailWhenVersionIsNotPresent() throws Exception { InputStream pluginXml = IOUtils.toInputStream("<go-plugin id=\"some\"></go-plugin>"); try {/*from ww w. j a v a2s. c o m*/ GoPluginDescriptorParser.parseXML(pluginXml, "/tmp/", new File("/tmp/"), true); fail("xsd validation should have failed"); } catch (SAXException e) { assertThat(e.getMessage(), is("XML Schema validation of Plugin Descriptor(plugin.xml) failed")); } }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorParserTest.java
@Test public void shouldValidatePluginVersion() throws Exception { InputStream pluginXml = IOUtils.toInputStream("<go-plugin version=\"10\"></go-plugin>"); try {/*from w ww . java2s . c o m*/ GoPluginDescriptorParser.parseXML(pluginXml, "/tmp/", new File("/tmp/"), true); fail("xsd validation should have failed"); } catch (SAXException e) { assertThat(e.getMessage(), is("XML Schema validation of Plugin Descriptor(plugin.xml) failed")); assertThat(e.getCause().getMessage(), contains("Value '10' of attribute 'version' of element 'go-plugin' is not valid")); } }
From source file:com.semsaas.jsonxml.tests.Tests.java
public void xjson2json(String xmlResource, String jsonResource) { InputStream is = ClassLoader.getSystemResourceAsStream(xmlResource); try {/* w ww. j a v a2 s.c o m*/ // The real test StringWriter result = new StringWriter(); Examples.XJson2json.xjson2json(is, result); // Check the results StringWriter expected = new StringWriter(); InputStream xmlIs = ClassLoader.getSystemResourceAsStream(jsonResource); IOUtils.copy(xmlIs, expected); assertEquals(expected.toString().replaceAll("[\\n\\s]+", ""), result.toString().replaceAll("[\\n\\s]+", "")); } catch (SAXException e) { fail(e.getMessage()); } catch (IOException e) { fail(e.getMessage()); } }
From source file:com.semsaas.jsonxml.tests.Tests.java
public void json2xjson(String jsonResource, String xmlResource) { InputStream is = ClassLoader.getSystemResourceAsStream(jsonResource); try {//from ww w . j a va 2 s. co m // The real test Node node = Examples.Json2Dom.json2dom(is); // Check the results StringWriter result = new StringWriter(); Examples.serialize(node, result); StringWriter expected = new StringWriter(); InputStream xmlIs = ClassLoader.getSystemResourceAsStream(xmlResource); IOUtils.copy(xmlIs, expected); assertEquals(expected.toString().replaceAll("[\\n\\s]+", ""), result.toString().replaceAll("[\\n\\s]+", "")); } catch (SAXException e) { fail(e.getMessage()); } catch (TransformerException e) { fail(e.getMessage()); } catch (IOException e) { fail(e.getMessage()); } }
From source file:org.javelin.sws.ext.bind.SoapEncodingMarshaller.java
@Override public void marshal(Object graph, Result result) throws IOException, XmlMappingException { try {//from w w w .j a va 2s.c o m ContentHandler contentHandler = ((SAXResult) result).getHandler(); contentHandler.startElement("", "hello", "hello", new AttributesImpl()); contentHandler.characters(((String) ((Object[]) graph)[0]).toCharArray(), 0, ((String) ((Object[]) graph)[0]).toCharArray().length); contentHandler.endElement("", "hello", "hello"); } catch (SAXException e) { throw new MarshallingFailureException(e.getMessage(), e); } }