List of usage examples for javax.xml.parsers SAXParserFactory setValidating
public void setValidating(boolean validating)
From source file:org.iterx.miru.dispatcher.handler.factory.XmlHandlerChainParser.java
public void parse(StreamSource source) throws IOException { try {//ww w .ja v a 2s .c om SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(source.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { if (LOGGER.isErrorEnabled()) LOGGER.error(e); throw new IOException("Invalid xml stream [" + source + "]. " + e.getMessage()); } }
From source file:org.iterx.miru.handler.XmlHandlerMappingParser.java
public void parse(Resource resource) throws IOException { try {/*from w ww . j a va2s. c om*/ SAXParserFactory factory; SAXParser parser; factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); parser = factory.newSAXParser(); parser.parse(resource.getInputStream(), this); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new IOException("Invalid xml stream: " + e.getMessage()); } }
From source file:org.jajuk.base.Collection.java
/** * Parse collection.xml file and put all collection information into memory * * @param file /* w w w . j av a 2 s. co m*/ * * @throws SAXException the SAX exception * @throws ParserConfigurationException the parser configuration exception * @throws JajukException the jajuk exception * @throws IOException Signals that an I/O exception has occurred. */ public static void load(File file) throws SAXException, ParserConfigurationException, JajukException, IOException { // If we load the regular collection.xml file, try to recover it from previous crash java.io.File regularFile = SessionService.getConfFileByPath(Const.FILE_COLLECTION); if (file.equals(regularFile)) { UtilSystem.recoverFileIfRequired(regularFile); } Log.debug("Loading: " + file.getName()); if (!file.exists()) { throw new JajukException(5, file.toString()); } lTime = System.currentTimeMillis(); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(false); spf.setNamespaceAware(false); // See http://xerces.apache.org/xerces-j/features.html for details spf.setFeature("http://xml.org/sax/features/external-general-entities", false); spf.setFeature("http://xml.org/sax/features/string-interning", true); SAXParser saxParser = spf.newSAXParser(); saxParser.parse(file.toURI().toURL().toString(), getInstance()); }
From source file:org.jbpm.jpdl.internal.convert.Jpdl3ConverterParser.java
private static SAXParserFactory createSaxParserFactory() { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); saxParserFactory.setNamespaceAware(true); return saxParserFactory; }
From source file:org.jlibrary.core.search.extraction.XMLExtractor.java
public XMLExtractor() throws ExtractionException { try {/*from w w w . ja v a 2s . c o m*/ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(false); SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setFeature("http://xml.org/sax/features/validation", false); xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); parser = new XMLParser(xmlReader); } catch (Exception e) { throw new ExtractionException(e); } }
From source file:org.kuali.kra.test.OjbRepositoryMappingTest.java
/** * This method verifies the tables for a repository file * @throws SQLException// w ww. ja v a 2 s . c om * @throws ParserConfigurationException * @throws SAXException * @throws IOException * @throws ClassNotFoundException */ private void verifyTableForRepository(String repositoryFilePath) throws SQLException, ParserConfigurationException, SAXException, IOException, ClassNotFoundException { //loading the driver class so that DriverManager can find it Class.forName(dsDriver); final Connection conn = DriverManager.getConnection(dsUrl, dsUser, dsPass); final DefaultHandler handler = new TableValidationHandler(conn); LOG.debug(String.format("Starting XML validation")); final InputStream repositoryStream = getFileResource(repositoryFilePath).getInputStream(); LOG.debug(String.format("Found repository url %s\n", repositoryFilePath)); final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); saxParserFactory.setNamespaceAware(false); final SAXParser parser = saxParserFactory.newSAXParser(); try { parser.parse(repositoryStream, handler); } finally { try { conn.close(); } catch (Exception e) { } } }
From source file:org.kuali.kra.test.OjbRepositoryMappingTest.java
/** * @param repositoryFilePath/*from ww w . j av a 2s . c o m*/ * @throws ParserConfigurationException * @throws SAXException */ private void validateXml(String repositoryFilePath) throws Exception { LOG.debug(String.format("Starting XML validation")); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); saxParserFactory.setNamespaceAware(false); SAXParser parser = saxParserFactory.newSAXParser(); final InputStream repositoryStream = getFileResource(repositoryFilePath).getInputStream(); parser.parse(repositoryStream, new DefaultHandler()); }
From source file:org.olat.ims.qti.qpool.ItemFileResourceValidator.java
private boolean validateDocument(Document in) { try {/*from w ww. j av a2 s. c om*/ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(true); SimpleErrorHandler errorHandler = new SimpleErrorHandler(); ItemContentHandler contentHandler = new ItemContentHandler(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setEntityResolver(new IMSEntityResolver()); reader.setErrorHandler(errorHandler); reader.setContentHandler(contentHandler); SAXValidator validator = new SAXValidator(reader); validator.validate(in); return errorHandler.isValid() && contentHandler.isItem(); } catch (ParserConfigurationException e) { return false; } catch (SAXException e) { return false; } catch (Exception e) { return false; } }
From source file:org.openbravo.test.webservice.BaseWSTest.java
/** * Validates the xml against the generated schema. * //from w w w . j a v a 2 s . c om * @param xml * the xml to validate */ protected void validateXML(String xml) { final Reader schemaReader = new StringReader(getXMLSchema()); final Reader xmlReader = new StringReader(xml); try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); factory.setSchema(schemaFactory.newSchema(new Source[] { new StreamSource(schemaReader) })); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(new SimpleErrorHandler()); reader.parse(new InputSource(xmlReader)); } catch (Exception e) { throw new OBException(e); } }
From source file:org.opencastproject.metadata.dublincore.DublinCoreXmlFormat.java
private DublinCoreCatalog readImpl(InputSource in) throws ParserConfigurationException, SAXException, IOException { final SAXParserFactory factory = SAXParserFactory.newInstance(); // no DTD//from w w w . j a v a 2 s . c o m factory.setValidating(false); // namespaces! factory.setNamespaceAware(true); // read document factory.newSAXParser().parse(in, this); return dc; }