List of usage examples for javax.xml.parsers SAXParserFactory newInstance
public static SAXParserFactory newInstance()
From source file:com.inferiorhumanorgans.WayToGo.Agency.BART.Station.StationTask.java
@Override protected Void doInBackground(BARTAgency... someAgencies) { Assert.assertEquals(1, someAgencies.length); super.doInBackground(someAgencies); Log.i(LOG_NAME, "Trying to get BART station list."); InputStream content = null;/*from w w w . j a v a 2 s .com*/ ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient hc = new DefaultHttpClient(connman, params); Log.i(LOG_NAME, "Fetching basic station info from: " + BART_URL + BARTAgency.API_KEY); HttpGet getRequest = new HttpGet(BART_URL + BARTAgency.API_KEY); try { content = hc.execute(getRequest).getEntity().getContent(); } catch (ClientProtocolException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } Log.i(LOG_NAME, "Put the station list in the background."); try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(dataHandler); xr.parse(new InputSource(content)); } catch (ParserConfigurationException pce) { Log.e(LOG_NAME + " SAX XML", "sax parse error", pce); } catch (AbortXMLParsingException abrt) { Log.i(LOG_NAME + " AsyncXML", "Cancelled!!!!!"); return null; // Pass on some exception to the caller? } catch (SAXException se) { Log.e(LOG_NAME + " SAX XML", "sax error", se); } catch (IOException ioe) { Log.e(LOG_NAME + " SAX XML", "sax parse io error", ioe); } Log.i(LOG_NAME + " SAX XML", "Done parsing BART station XML"); final DetailXMLHandler detailDataHandler = new DetailXMLHandler(this); for (String aStationTag : theStations.keySet()) { getRequest = new HttpGet(BART_DETAIL_URL + BARTAgency.API_KEY + "&orig=" + aStationTag); try { content = hc.execute(getRequest).getEntity().getContent(); } catch (ClientProtocolException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(LOG_NAME).log(Level.SEVERE, null, ex); } Log.i(LOG_NAME, "Put the station detail for " + aStationTag + " in the background."); try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.setContentHandler(detailDataHandler); xr.parse(new InputSource(content)); } catch (ParserConfigurationException pce) { Log.e(LOG_NAME + " SAX XML", "sax parse error", pce); } catch (AbortXMLParsingException abrt) { Log.i(LOG_NAME + " AsyncXML", "Cancelled!!!!!"); } catch (SAXException se) { Log.e(LOG_NAME + " SAX XML", "sax error", se); } catch (IOException ioe) { Log.e(LOG_NAME + " SAX XML", "sax parse io error", ioe); } Log.i(LOG_NAME + " SAX XML", "Done parsing BART station XML"); } return null; }
From source file:ensen.controler.DBpediaLookupClient.java
public Model qetEntities(String query, String classes, int numberOfRes) throws Exception { HttpClient client = new HttpClient(); // client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); String query2 = URLEncoder.encode(query, "utf-8"); HttpMethod method = new GetMethod( gatway + "QueryString=" + query2 + "&QueryClass=" + classes + "&MaxHits=" + numberOfRes); // method.setFollowRedirects(true); try {/* ww w .j a va2s .co m*/ client.executeMethod(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.out.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.out.println("Unable to connect to lookup.dbpedia.org"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } method.releaseConnection(); Model model = ModelFactory.createDefaultModel(); Resource core = model.createResource("http://ensen.org/data#q-" + query2); int num_results = Results.size(); if (num_results > 0) { for (DBpediaLookupResModel res : Results) { // System.out.println("URI: " + res.uri); if (res.uri.contains("http://")) { Resource O = model.createResource(res.uri); Property P = model.createProperty("http://ensen.org/data#has-a"); Literal O1 = model.createLiteral(res.label + ""); Literal O2 = model.createLiteral(res.desc + ""); Property P1 = model.createProperty("http://www.w3.org/2000/01/rdf-schema#label"); Property P2 = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#description"); O.addProperty(P1, O1); O.addProperty(P2, O2); for (String cat : res.cats) { Resource OO = model.createResource(cat); Property PP = model.createProperty("http://purl.org/dc/terms/subject"); O.addProperty(PP, OO); } for (String c : res.classes) { Resource OO = model.createResource(c); Property PP = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); O.addProperty(PP, OO); } core.addProperty(P, O); } } } return model; }
From source file:eu.scape_project.planning.xml.PlanMigrator.java
/** * Detect the version of the given XML representation of plans. If the * version of the XML representation is not up to date, necessary * transformations are applied./*w ww . j a v a 2s . c o m*/ * * @param importData * @return null if the transformation fails, otherwise an up to date XML * representation * @throws IOException * if parsing the XML representation fails * @throws SAXException * if parsing the XML representation fails */ public String getCurrentVersionData(final InputStream in, final String tempPath, final List<String> appliedTransformations) throws PlatoException { String originalFile = tempPath + "_original.xml"; try { FileUtils.writeToFile(in, new FileOutputStream(originalFile)); /** check for the version of the file **/ // The version of the read xml file is unknown, so it is not possible to // validate it // moreover, in old plans the version attribute was on different // nodes(project, projects), // with a different name (fileVersion) // to be backwards compatible we create rules for all these attributes fileVersion = "xxx"; SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(false); Digester d = new Digester(factory.newSAXParser()); d.setValidating(false); // StrictErrorHandler errorHandler = new StrictErrorHandler(); // d.setErrorHandler(errorHandler); d.push(this); // to read the version we have to support all versions: d.addSetProperties("*/projects", "version", "fileVersion"); // manually migrated projects may have the file version in the node // projects/project d.addSetProperties("*/projects/project", "version", "fileVersion"); // pre V1.3 version info was stored in the project node d.addSetProperties("*/project", "version", "fileVersion"); // since V1.9 the root node is plans: d.addSetProperties("plans", "version", "fileVersion"); InputStream inV = new FileInputStream(originalFile); d.parse(inV); inV.close(); /** this could be more sophisticated, but for now this is enough **/ String version = "1.0"; if (fileVersion != null) { version = fileVersion; } String fileTo = originalFile; String fileFrom = originalFile; boolean success = true; if ("xxx".equals(version)) { fileFrom = fileTo; fileTo = fileFrom + "_V1.3.xml"; /** this is an old export file, transform it to the 1.3 schema **/ success = transformXmlData(fileFrom, fileTo, "data/xslt/Vxxx-to-V1.3.xsl"); appliedTransformations.add("Vxxx-to-V1.3.xsl"); version = "1.3"; } if (success && "1.3".equals(version)) { fileFrom = fileTo; fileTo = fileFrom + "_V1.9.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V1.3-to-V1.9.xsl"); appliedTransformations.add("V1.3-to-V1.9.xsl"); version = "1.9"; } // with release of Plato 2.0 and its schema ProjectExporter creates // documents with version 2.0 if (success && "1.9".equals(version)) { version = "2.0"; } if (success && "2.0".equals(version)) { // transform the document to version 2.1 fileFrom = fileTo; fileTo = fileFrom + "_V2.1.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V2.0-to-V2.1.xsl"); appliedTransformations.add("V2.0-to-V2.1.xsl"); version = "2.1"; } if (success && "2.1".equals(version)) { // transform the document to version 2.1.2 fileFrom = fileTo; fileTo = fileFrom + "_V2.1.2.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V2.1-to-V2.1.2.xsl"); appliedTransformations.add("V2.1-to-V2.1.2.xsl"); version = "2.1.2"; } if (success && "2.1.1".equals(version)) { // transform the document to version 2.1.2 fileFrom = fileTo; fileTo = fileFrom + "_V2.1.2.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V2.1.1-to-V2.1.2.xsl"); appliedTransformations.add("V2.1.1-to-V2.1.2.xsl"); version = "2.1.2"; } if (success && "2.1.2".equals(version)) { // transform the document to version 3.0.0 fileFrom = fileTo; fileTo = fileFrom + "_V3.0.0.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V2.1.2-to-V3.0.0.xsl"); appliedTransformations.add("V2.1.2-to-V3.0.0.xsl"); version = "3.0.0"; } if (success && "3.0.0".equals(version)) { // transform the document to version 3.0.1 fileFrom = fileTo; fileTo = fileFrom + "_V3.0.1.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V3.0.0-to-V3.0.1.xsl"); appliedTransformations.add("V3.0.0-to-V3.0.1.xsl"); version = "3.0.1"; } if (success && "3.0.1".equals(version)) { // transform the document to version 3.9.0 fileFrom = fileTo; fileTo = fileFrom + "_V3.9.0.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V3.0.1-to-V3.9.0.xsl"); appliedTransformations.add("V3.0.1-to-V3.9.0.xsl"); version = "3.9.0"; } if (success && "3.9.0".equals(version)) { // transform the document to version 3.9.9 fileFrom = fileTo; fileTo = fileFrom + "_V3.9.9.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V3.9.0-to-V3.9.9.xsl"); appliedTransformations.add("V3.9.0-to-V3.9.9.xsl"); version = "3.9.9"; } if (success && "3.9.9".equals(version)) { // transform the document to version 4.0.0 fileFrom = fileTo; fileTo = fileFrom + "_V4.0.1.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V3.9.9-to-V4.0.1.xsl"); appliedTransformations.add("V3.9.9-to-V4.0.1.xsl"); version = "4.0.1"; } if (success && "4.0.1".equals(version)) { // transform the document to version 4.0.0 fileFrom = fileTo; fileTo = fileFrom + "_V4.0.2.xml"; success = transformXmlData(fileFrom, fileTo, "data/xslt/V4.0.1-to-V4.0.2.xsl"); appliedTransformations.add("V4.0.1-to-V4.0.2.xsl"); version = "4.0.2"; } if (success) { return fileTo; } else { return null; } } catch (Exception e) { throw new PlatoException("Failed to update plan to current version.", e); } }
From source file:de.tlabs.ssr.g1.client.XmlInputThread.java
@Override public void run() { Log.d(TAG, "(" + this.getId() + ") HELLO"); try {//from w w w .j a v a 2 s .co m // create sax parser SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); // get an xml reader XMLReader xr = sp.getXMLReader(); // set up xml input source XMLChunkInputStream xmlChunkInputStream; synchronized (GlobalData.socketChannel) { xmlChunkInputStream = new XMLChunkInputStream(new ByteArrayBuffer(32 * 1024), GlobalData.socketChannel.socket().getInputStream()); } InputSource inputSource = new InputSource(xmlChunkInputStream); // create handler for scene description and assign it SceneDescrXMLHandler sceneDescrXMLHandler = new SceneDescrXMLHandler(GlobalData.audioScene); xr.setContentHandler(sceneDescrXMLHandler); // parse scene description //Log.d(TAG, "(" + this.getId() + ") parsing description..."); //xmlChunkInputStream.printToLog = true; while (xmlChunkInputStream.bufferNextChunk() && !sceneDescrXMLHandler.receivedSceneDescr()) { // parse and process xml input xr.parse(inputSource); } //xmlChunkInputStream.printToLog = false; // signal that scene description was parsed //Log.d(TAG, "(" + this.getId() + ") sending SCENEPARSED_OK_MSG"); GlobalData.sourcesMoverMsgHandler .sendMessage(GlobalData.sourcesMoverMsgHandler.obtainMessage(SourcesMover.SCENEPARSED_OK_MSG)); // create handler for scene updates and assign it SceneUpdateXMLHandler sceneUpdateXMLHandler = new SceneUpdateXMLHandler(GlobalData.audioScene); xr.setContentHandler(sceneUpdateXMLHandler); // parse scene updates Log.d(TAG, "(" + this.getId() + ") starting xml input loop..."); while (xmlChunkInputStream.bufferNextChunk()) { // parse and process xml input xr.parse(inputSource); // check if we should abort synchronized (abortFlag) { if (abortFlag == true) { break; } } } } catch (Exception e) { Log.d(TAG, "(" + this.getId() + ") Exception " + e.toString() + ": " + e.getMessage()); // check if this thread was aborted and/or stopped by a call to interrupt() if (Thread.interrupted() || abortFlag) { Log.d(TAG, "(" + this.getId() + ") interrupted/aborted"); } else { GlobalData.sourcesMoverMsgHandler.sendMessage(GlobalData.sourcesMoverMsgHandler .obtainMessage(SourcesMover.XMLINPUT_ERR_MSG, e.getMessage())); Log.d(TAG, "(" + this.getId() + ") sending XMLINPUT_ERR_MSG"); } } Log.d(TAG, "(" + this.getId() + ") GOOD BYE"); }
From source file:com.itude.mobile.mobbl.core.model.parser.MBXmlDocumentParser.java
private void doParseFragment(byte[] data, MBDocument document, String rootPath, boolean copyRootAttributes) { if (data != null) { try {//from ww w. j a v a2 s. co m SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); _stack = new Stack<MBElementContainer>(); _pathStack = new Stack<String>(); _definition = document.getDefinition(); _characters = new StringBuilder(); _copyRootAttributes = copyRootAttributes; _ignoredPaths = new HashSet<String>(); if (rootPath != null) { List<String> parts = MBPathUtil.splitPath(rootPath); for (String part : parts) { _pathStack.add(NUMBERPATTERN.matcher(part).replaceAll("")); } _rootElementName = _pathStack.peek(); _rootElement = (MBElementContainer) document.getValueForPath(rootPath); } else { _rootElement = document; _rootElementName = (_definition.getRootElement() != null) ? _definition.getRootElement() : _definition.getName(); } parser.parse(new ByteArrayInputStream(data), this); } catch (Exception e) { MBLog.d(MBConstants.APPLICATION_NAME, new String(data)); MBLog.e(MBConstants.APPLICATION_NAME, "MBXmlDocumentParser.doParseFragment (for the data, see debug log above)", e); } } }
From source file:com.amytech.android.library.utils.asynchttp.SaxAsyncHttpResponseHandler.java
/** * Deconstructs response into given content handler * * @param entity/*from w ww. ja v a2 s . c om*/ * returned HttpEntity * @return deconstructed response * @throws java.io.IOException * if there is problem assembling SAX response from stream * @see org.apache.http.HttpEntity */ @Override protected byte[] getResponseData(HttpEntity entity) throws IOException { if (entity != null) { InputStream instream = entity.getContent(); InputStreamReader inputStreamReader = null; if (instream != null) { try { SAXParserFactory sfactory = SAXParserFactory.newInstance(); SAXParser sparser = sfactory.newSAXParser(); XMLReader rssReader = sparser.getXMLReader(); rssReader.setContentHandler(handler); inputStreamReader = new InputStreamReader(instream, DEFAULT_CHARSET); rssReader.parse(new InputSource(inputStreamReader)); } catch (SAXException e) { Log.e(LOG_TAG, "getResponseData exception", e); } catch (ParserConfigurationException e) { Log.e(LOG_TAG, "getResponseData exception", e); } finally { AsyncHttpClient.silentCloseInputStream(instream); if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (IOException e) { /* ignore */ } } } } } return null; }
From source file:com.edgenius.wiki.render.impl.FilterPipeImpl.java
public void load() throws FilterInitializeException { ClassLoader classLoader = Filter.class.getClassLoader(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Load filter configure XML file try {// www . j av a 2 s.c o m SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(this.new FilterMetaParaser()); reader.parse(new InputSource(classLoader.getResourceAsStream(filterResource))); } catch (Exception e) { log.error("Unable load filter configuare file " + filterResource, e); throw new FilterInitializeException(e); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Load filter Pattern resource bundle file Properties patternResource = new Properties(); try { patternResource.load(classLoader.getResourceAsStream(filterResourcePattern)); } catch (Exception e) { log.error("Unable load PatternFilter pattern file " + filterResourcePattern, e); throw new FilterInitializeException(e); } Map<Integer, Filter> sortSet = new TreeMap<Integer, Filter>(new CompareToComparator()); Map<Integer, RegionContentFilter> regionSortSet = new TreeMap<Integer, RegionContentFilter>( new CompareToComparator()); for (FilterMetadata filterMeta : filterMetaList) { try { Object obj = classLoader.loadClass(filterMeta.getClassName().trim()).newInstance(); if (obj instanceof Filter) { if (obj instanceof MacroFilter) ((MacroFilter) obj).setMacroMgr(macroManager); //initial filter, if it is patternFilter, then do further initial if (obj instanceof PatternFilter) { //!!! this markupPring must happen before setRegex() which may need getMarkupPrint() to build regex String markupPrintVal = patternResource.getProperty( ((PatternFilter) obj).getPatternKey() + PatternFilter.SUFFIX_MARKUP_PRINT); if (!StringUtils.isBlank(markupPrintVal)) { ((PatternFilter) obj).setMarkupPrint(markupPrintVal); } String matchVal = patternResource .getProperty(((PatternFilter) obj).getPatternKey() + PatternFilter.SUFFIX_MATCH); if (!StringUtils.isBlank(matchVal)) { //special for link replacer if (obj instanceof LinkFilter) { linkReplacerFilter.setRegex(matchVal); } ((PatternFilter) obj).setRegex(matchVal); } String printVal = patternResource .getProperty(((PatternFilter) obj).getPatternKey() + PatternFilter.SUFFIX_PRINT); if (!StringUtils.isBlank(printVal)) { ((PatternFilter) obj).setReplacement(printVal); } String htmlIDVal = patternResource.getProperty( ((PatternFilter) obj).getPatternKey() + PatternFilter.SUFFIX_HTML_IDENTIFIER); if (!StringUtils.isBlank(htmlIDVal)) { ((PatternFilter) obj).setHTMLIdentifier(htmlIDVal); } } filterNameMap.put(obj.getClass().getName(), (Filter) obj); ((Filter) obj).init(); //new line filter always be last, but need special handle. see MarkupRenderEngineImpl.render() sortSet.put(filterMeta.getOrder(), (Filter) obj); if (obj instanceof RegionContentFilter) { regionSortSet.put(filterMeta.getOrder(), (RegionContentFilter) obj); } log.info("Filter loaded into FilterPipe:" + obj.getClass().getName()); } else { log.warn("Class " + obj.getClass().getName() + " does not implement Filter interface. " + "It cannot be loaded into FilterPipe."); } } catch (InstantiationException e) { log.error("Filter failed on Instantiation " + filterMeta, e); } catch (IllegalAccessException e) { log.error("Filter failed on IllegalAccessException " + filterMeta, e); } catch (ClassNotFoundException e) { log.error("Filter ClassNotFoundException failed " + filterMeta, e); } } linkReplacerFilter.init(); filterList.clear(); filterList.addAll(sortSet.values()); regionFilterList.clear(); regionFilterList.addAll(regionSortSet.values()); }
From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromXmlStream.java
private ViewImpl read() { try {/*from ww w. j a v a2s . c o m*/ SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new SaxParserHandler(); saxParser.parse(inputStream, handler); // If user wanted just one root remove others if we have more than one. // We don't want to abort the loading of entities in the middle of // the stream because that could throw off XML processing. EntityCursorImpl rootCursor = view.getViewCursor().getEntityCursor(lodDef.getRoot()); if (control.contains(ActivateFlags.fSINGLE) && rootCursor.getEntityCount() > 1) { rootCursor.setFirst(); while (rootCursor.setNext().isSet()) rootCursor.dropEntity(); rootCursor.setFirst(); } if (selectedInstances.size() > 0) setCursors(); else view.reset(); return view; } catch (Exception e) { ZeidonException ze = ZeidonException.wrapException(e); if (locator != null) ze.appendMessage("Line/col = %d/%d", locator.getLineNumber(), locator.getColumnNumber()); throw ze; } }
From source file:importer.handler.post.stages.SAXSplitter.java
/** * Split a TEI-XML file into versions of XML * @param tei the TEI content containing versions * @return an analysis of the variant markup in a file * @throws ImportException if something went wrong *//*from w w w . java 2 s .c o m*/ public JSONArray scan(String tei) throws ImporterException { this.layers = new HashMap<String, Integer>(); this.lineNo = 1; this.splits = new HashSet<String>(); this.attributes = new HashMap<String, String>(); this.siblings = new HashMap<String, String>(); this.states = new Stack<Integer>(); this.states.push(0); this.siblingCount = 0; this.path = new StringBuilder(); // hard-wire config for now attributes.put("add", "n"); attributes.put("rdg", "wit"); attributes.put("lem", "wit"); siblings.put("add", "del"); siblings.put("del", "add"); siblings.put("lem", "rdg"); siblings.put("rdg", "lem"); splits.add("add"); splits.add("del"); splits.add("sic"); splits.add("corr"); splits.add("abbrev"); splits.add("expan"); splits.add("rdg"); splits.add("lem"); splits.add("app"); splits.add("mod"); splits.add("choice"); splits.add("subst"); try { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); parser = spf.newSAXParser(); xmlReader = parser.getXMLReader(); xmlReader.setContentHandler(this); xmlReader.setErrorHandler(new MyErrorHandler(System.err)); CharArrayReader car = new CharArrayReader(tei.toCharArray()); xmlReader.parse(new InputSource(car)); return layersToJson(); } catch (Exception e) { throw new ImporterException(e); } }
From source file:io.onedecision.engine.decisions.model.dmn.validators.SchemaValidator.java
public void validate(InputStream obj, Errors errors) { InputStream is = (InputStream) obj; SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new LocalResourceResolver()); try {// w w w . j av a2 s . com schemaFactory.newSchema(new StreamSource(getResourceAsStreamWrapper("schema/dmn.xsd"))); } catch (SAXException e1) { errors.reject("Cannot find / read schema", "Exception: " + e1.getMessage()); } SAXParserFactory parserFactory = SAXParserFactory.newInstance(); // parserFactory.setValidating(true); parserFactory.setNamespaceAware(true); // parserFactory.setSchema(schema); SAXParser parser = null; try { parser = parserFactory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(this); try { parser.parse(new InputSource(is), (DefaultHandler) null); } catch (Exception e) { String msg = "Schema validation failed"; LOGGER.error(msg, e); errors.reject(msg, "Exception: " + e.getMessage()); } if (this.errors.size() > 0) { errors.reject("Schema validation failed", this.errors.toString()); } } catch (ParserConfigurationException e1) { errors.reject("Cannot create parser", "Exception: " + e1.getMessage()); } catch (SAXException e1) { errors.reject("Parser cannot be created", "Exception: " + e1.getMessage()); } }