List of usage examples for org.xml.sax SAXException getMessage
public String getMessage()
From source file:org.jajuk.base.TestCollection.java
/** * Test method for./*from ww w.j av a 2 s . c o m*/ * * @throws Exception the exception * {@link org.jajuk.base.Collection#error(org.xml.sax.SAXParseException)}. */ public final void testErrorSAXParseException() throws Exception { Collection coll = Collection.getInstance(); try { coll.error(new SAXParseException("Testexception", null)); fail("Should throw exception here..."); } catch (SAXException e) { assertTrue(e.getMessage(), e.getMessage().contains("Testexception")); } }
From source file:org.jajuk.base.TestCollection.java
/** * Test method for./*from ww w . j av a 2 s . co m*/ * * @throws Exception the exception * {@link org.jajuk.base.Collection#fatalError(org.xml.sax.SAXParseException)} * . */ public final void testFatalErrorSAXParseException() throws Exception { Collection coll = Collection.getInstance(); try { coll.fatalError(new SAXParseException("Testexception", null)); fail("Should throw exception here..."); } catch (SAXException e) { assertTrue(e.getMessage(), e.getMessage().contains("Testexception")); } }
From source file:org.jajuk.services.bookmark.TestHistory.java
/** * Test method for./* w w w . ja va 2 s .c o m*/ * * {@link org.jajuk.services.bookmark.History#warning(org.xml.sax.SAXParseException)} * . */ public final void testWarningSAXParseException() { try { History.getInstance().warning(new SAXParseException("testmessage", null)); fail("Will throw exception"); } catch (SAXException e) { assertTrue(e.getMessage(), e.getMessage().contains("testmessage")); } }
From source file:org.jajuk.services.bookmark.TestHistory.java
/** * Test method for./*from www . ja v a 2 s . c o m*/ * * {@link org.jajuk.services.bookmark.History#error(org.xml.sax.SAXParseException)} * . */ public final void testErrorSAXParseException() { try { History.getInstance().error(new SAXParseException("testmessage", null)); fail("Will throw exception"); } catch (SAXException e) { assertTrue(e.getMessage(), e.getMessage().contains("testmessage")); } }
From source file:org.jajuk.services.bookmark.TestHistory.java
/** * Test method for.// w w w . j a v a 2 s .com * * {@link org.jajuk.services.bookmark.History#fatalError(org.xml.sax.SAXParseException)} * . */ public final void testFatalErrorSAXParseException() { try { History.getInstance().fatalError(new SAXParseException("testmessage", null)); fail("Will throw exception"); } catch (SAXException e) { assertTrue(e.getMessage(), e.getMessage().contains("testmessage")); } }
From source file:org.jts.eclipse.ui.actions.importbinding.Util.java
/** * Filter jsidl files, unmarshal and place in a Map. * @param fileList list of JSIDL XML files containing service sets * @return A Map from service set ID/version strings to JAXB instances representing those service sets. * @throws JAXBException /* w ww . j a v a 2 s . co m*/ * @throws SAXException */ public static Map getObjectMapFromFile(List<File> fileList, List<ServiceDef> tmp) throws JAXBException, SAXException { Map objMap = new HashMap(); Document doc = null; DocumentBuilder db = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Unmarshaller um = null; // Set up the unmarshaller with the schema included with the code // generator. try { JAXBContext jc = JAXBContext.newInstance("org.jts.jsidl.binding"); um = jc.createUnmarshaller(); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Bundle bundle = CjsidlActivator.getInstance().getBundle(); String schema_loc; if (new File(SCHEMA_PATH).exists()) { schema_loc = SCHEMA_PATH; } else if (new File(JTS_SCHEMA_PATH).exists()) { schema_loc = JTS_SCHEMA_PATH; } else if (new File(DEPLOYED_SCHEMA_PATH).exists()) { schema_loc = DEPLOYED_SCHEMA_PATH; } else { throw new Exception("Unable to find the schema path for jsidl_plus.xsd: " + (new File(SCHEMA_PATH).getAbsolutePath()) + "\n\t" + (new File(JTS_SCHEMA_PATH).getAbsolutePath()) + "\n\t" + (new File(DEPLOYED_SCHEMA_PATH).getAbsolutePath())); } // IPath path = new Path(schema_loc); // URL schemaUrl = FileLocator.find(bundle, path, // Collections.EMPTY_MAP); // File schemaFile = new File(FileLocator.toFileURL(schemaUrl).toURI()); File schemaFile = new File(schema_loc); Schema schema = sf.newSchema(schemaFile); um.setSchema(schema); // Try parsing each file. db = dbf.newDocumentBuilder(); for (int ii = 0; ii < fileList.size(); ii++) { File file = fileList.get(ii); final String fileName = file.toString(); doc = db.parse(file); Element root = doc.getDocumentElement(); if (root.getAttribute("xmlns").equals("urn:jaus:jsidl:1.0")) { Object o = um.unmarshal(file); objMap.put(root.getAttribute("id") + "-" + root.getAttribute("version"), o); if (o instanceof ServiceDef) { tmp.add((ServiceDef) o); } } } } catch (JAXBException jaxbe) { Logger.getLogger(ImportServiceSet.class.getName()).log(Level.SEVERE, jaxbe.getMessage(), jaxbe); throw jaxbe; } catch (SAXException saxe) { Logger.getLogger(ImportServiceSet.class.getName()).log(Level.SEVERE, saxe.getMessage(), saxe); throw saxe; } catch (URISyntaxException e) { Logger.getLogger(ImportServiceSet.class.getName()).log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { Logger.getLogger(ImportServiceSet.class.getName()).log(Level.SEVERE, e.getMessage(), e); } catch (ParserConfigurationException e) { Logger.getLogger(ImportServiceSet.class.getName()).log(Level.SEVERE, e.getMessage(), e); } catch (Exception e) { Logger.getLogger(ImportServiceSet.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return objMap; }
From source file:org.kuali.kfs.module.tem.batch.PerDiemXmlInputFileType.java
/** * @see org.kuali.kfs.sys.batch.XmlBatchInputFileTypeBase#validateContentsAgainstSchema(java.lang.String, java.io.InputStream) *///from www . j a va 2 s .c o m @Override protected void validateContentsAgainstSchema(String schemaLocation, InputStream fileContents) throws ParseException { try { // get schemaFile UrlResource schemaResource = new UrlResource(schemaLocation); // load a WXS schema, represented by a Schema instance Source schemaSource = new StreamSource(schemaResource.getInputStream()); // create a SchemaFactory capable of understanding WXS schemas SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(schemaSource); // create a validator instance, which can be used to validate an instance document Validator validator = schema.newValidator(); validator.setErrorHandler(new XmlErrorHandler()); Source source = this.transform(fileContents); validator.validate(source); } catch (MalformedURLException e2) { LOG.error("error getting schema url: " + e2.getMessage()); throw new RuntimeException("error getting schema url: " + e2.getMessage(), e2); } catch (SAXException e) { LOG.error("error encountered while parsing xml " + e.getMessage()); throw new ParseException("Schema validation error occured while processing file: " + e.getMessage(), e); } catch (IOException e1) { LOG.error("error occured while validating file contents: " + e1.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + e1.getMessage(), e1); } }
From source file:org.kuali.kfs.module.tem.batch.PerDiemXmlInputFileType.java
protected Source transform(InputStream fileContents) { try {//from w ww . java 2 s .c om DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(fileContents); document.getDocumentElement().setAttribute("xmlns", "http://www.kuali.org/kfs/tem/perDiem"); Source domSource = new DOMSource(document); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); StreamResult streamResult = new StreamResult(outputStream); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); // Transform the document to the result stream transformer.transform(domSource, streamResult); InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); return new StreamSource(inputStream); } catch (TransformerConfigurationException ex) { LOG.error("error occurred while validating file contents: " + ex.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + ex.getMessage(), ex); } catch (TransformerException ex) { LOG.error("error occurred while validating file contents: " + ex.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + ex.getMessage(), ex); } catch (SAXException e) { LOG.error("error encountered while parsing xml " + e.getMessage()); throw new ParseException("Schema validation error occured while processing file: " + e.getMessage(), e); } catch (IOException e1) { LOG.error("error occured while validating file contents: " + e1.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + e1.getMessage(), e1); } catch (ParserConfigurationException ex) { LOG.error("error occurred while validating file contents: " + ex.getMessage()); throw new RuntimeException("error occurred while validating file contents: " + ex.getMessage(), ex); } }
From source file:org.kuali.kfs.sys.batch.XmlBatchInputFileTypeBase.java
/** * Validates the xml contents against the batch input type schema using the java 1.5 validation package. * // ww w. j av a2s .c o m * @param schemaLocation - location of the schema file * @param fileContents - xml contents to validate against the schema */ protected void validateContentsAgainstSchema(String schemaLocation, InputStream fileContents) throws ParseException { // create a SchemaFactory capable of understanding WXS schemas SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // get schemaFile Resource schemaResource = SpringContext.getResource(schemaLocation); // load a WXS schema, represented by a Schema instance Source schemaSource = null; try { schemaSource = new StreamSource(schemaResource.getInputStream()); } catch (IOException e2) { LOG.error("error getting schema stream from url: " + e2.getMessage()); throw new RuntimeException("error getting schema stream from url: " + e2.getMessage(), e2); } Schema schema = null; try { schema = factory.newSchema(schemaSource); } catch (SAXException e) { LOG.error("error occured while setting schema file: " + e.getMessage()); throw new RuntimeException("error occured while setting schema file: " + e.getMessage(), e); } // create a Validator instance, which can be used to validate an instance document Validator validator = schema.newValidator(); validator.setErrorHandler(new XmlErrorHandler()); // validate try { validator.validate(new StreamSource(fileContents)); } catch (SAXException e) { LOG.error("error encountered while parsing xml " + e.getMessage()); throw new ParseException("Schema validation error occured while processing file: " + e.getMessage(), e); } catch (IOException e1) { LOG.error("error occured while validating file contents: " + e1.getMessage()); throw new RuntimeException("error occured while validating file contents: " + e1.getMessage(), e1); } }
From source file:org.kuali.ole.sys.batch.XmlBatchInputFileTypeBase.java
/** * Validates the xml contents against the batch input type schema using the java 1.5 validation package. * /* w w w . ja v a 2 s . com*/ * @param schemaLocation - location of the schema file * @param fileContents - xml contents to validate against the schema */ protected void validateContentsAgainstSchema(String schemaLocation, InputStream fileContents) throws ParseException { // create a SchemaFactory capable of understanding WXS schemas SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // get schemaFile UrlResource schemaResource = null; try { schemaResource = new UrlResource(schemaLocation); } catch (MalformedURLException e2) { LOG.error("error getting schema url: " + e2.getMessage()); throw new RuntimeException("error getting schema url: " + e2.getMessage(), e2); } // load a WXS schema, represented by a Schema instance Source schemaSource = null; try { schemaSource = new StreamSource(schemaResource.getInputStream()); } catch (IOException e2) { LOG.error("error getting schema stream from url: " + e2.getMessage()); throw new RuntimeException("error getting schema stream from url: " + e2.getMessage(), e2); } Schema schema = null; try { schema = factory.newSchema(schemaSource); } catch (SAXException e) { LOG.error("error occured while setting schema file: " + e.getMessage()); throw new RuntimeException("error occured while setting schema file: " + e.getMessage(), e); } // create a Validator instance, which can be used to validate an instance document Validator validator = schema.newValidator(); validator.setErrorHandler(new XmlErrorHandler()); // validate try { validator.validate(new StreamSource(fileContents)); } catch (SAXException e) { LOG.error("error encountered while parsing xml " + e.getMessage()); throw new ParseException("Schema validation error occured while processing file: " + e.getMessage(), e); } catch (IOException e1) { LOG.error("error occured while validating file contents: " + e1.getMessage()); throw new RuntimeException("error occured while validating file contents: " + e1.getMessage(), e1); } }