List of usage examples for org.xml.sax XMLReader setErrorHandler
public void setErrorHandler(ErrorHandler handler);
From source file:com.mirth.connect.plugins.datatypes.edi.EDISerializer.java
@Override public String fromXML(String source) throws MessageSerializerException { XMLReader xr; try {//from w ww .ja v a2s .co m xr = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { throw new MessageSerializerException("Error converting XML to EDI", e, ErrorMessageBuilder .buildErrorMessage(this.getClass().getSimpleName(), "Error converting XML to EDI", e)); } EDIXMLHandler handler = new EDIXMLHandler(); xr.setContentHandler(handler); xr.setErrorHandler(handler); try { //Parse, but first replace all spaces between brackets. This fixes pretty-printed XML we might receive xr.parse(new InputSource(new StringReader( prettyPattern2.matcher(prettyPattern1.matcher(source).replaceAll("<$1>")).replaceAll("<$1>")))); } catch (Exception e) { throw new MessageSerializerException("Error converting XML to EDI", e, ErrorMessageBuilder .buildErrorMessage(this.getClass().getSimpleName(), "Error converting XML to EDI", e)); } return handler.getOutput().toString(); }
From source file:architecture.common.util.L10NUtils.java
private void loadProps(String resource, boolean breakOnError) throws IOException { HashSet<URL> hashset = new HashSet<URL>(); if (log.isDebugEnabled()) { log.debug((new StringBuilder()).append("Searching ").append(resource).toString()); }/*www.j a v a 2s.c om*/ Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(resource); if (urls != null) { URL url; for (; urls.hasMoreElements(); hashset.add(url)) { url = urls.nextElement(); if (log.isDebugEnabled()) log.debug((new StringBuilder()).append("Adding ").append(url).toString()); } } for (URL url : hashset) { if (log.isDebugEnabled()) log.debug((new StringBuilder()).append("Loading from ").append(url).toString()); InputStream is = null; try { is = url.openStream(); InputSource input = new InputSource(is); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); XMLReader xmlreader = factory.newSAXParser().getXMLReader(); I18nParsingHandler handler = new I18nParsingHandler(); xmlreader.setContentHandler(handler); xmlreader.setDTDHandler(handler); xmlreader.setEntityResolver(handler); xmlreader.setErrorHandler(handler); xmlreader.parse(input); localizers.addAll(handler.localizers); } catch (IOException e) { if (log.isDebugEnabled()) log.debug((new StringBuilder()).append("Skipping ").append(url).toString()); if (breakOnError) throw e; } catch (Exception e) { log.error(e); } finally { if (is != null) IOUtils.closeQuietly(is); } } }
From source file:se.lu.nateko.edca.svc.DescribeFeatureType.java
/** * Parses an XML response from a DescribeFeatureType request and stores the layer * attribute names and their data types in a GeographyLayer object. * @param xmlResponse A reader wrapped around an InputStream containing the XML response from a DescribeFeatureType request. *///from w w w .j av a2s .c om protected boolean parseXMLResponse(Reader xmlResponse) { // Log.d(TAG, "parseXMLResponse(Reader) called."); try { SAXParserFactory spfactory = SAXParserFactory.newInstance(); // Make a SAXParser factory. spfactory.setValidating(false); // Tell the factory not to make validating parsers. SAXParser saxParser = spfactory.newSAXParser(); // Use the factory to make a SAXParser. XMLReader xmlReader = saxParser.getXMLReader(); // Get an XML reader from the parser, which will send event calls to its specified event handler. XMLEventHandler xmlEventHandler = new XMLEventHandler(); xmlReader.setContentHandler(xmlEventHandler); // Set which event handler to use. xmlReader.setErrorHandler(xmlEventHandler); // Also set where to send error calls. InputSource source = new InputSource(xmlResponse); // Make an InputSource from the XML input to give to the reader. xmlReader.parse(source); // Start parsing the XML. } catch (Exception e) { Log.e(TAG, e.toString()); return false; } return true; }
From source file:net.lightbody.bmp.proxy.jetty.xml.XmlParser.java
/** * Parse InputStream./* w w w. ja va2 s . com*/ */ public synchronized Node parse(InputStream in) throws IOException, SAXException { Handler handler = new Handler(); XMLReader reader = _parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); _parser.parse(new InputSource(in), handler); if (handler._error != null) throw handler._error; Node doc = (Node) handler._top.get(0); handler.clear(); return doc; }
From source file:net.lightbody.bmp.proxy.jetty.xml.XmlParser.java
public synchronized Node parse(InputSource source) throws IOException, SAXException { Handler handler = new Handler(); XMLReader reader = _parser.getXMLReader(); reader.setContentHandler(handler);// www .ja va 2 s . c o m reader.setErrorHandler(handler); reader.setEntityResolver(handler); if (log.isDebugEnabled()) log.debug("parsing: sid=" + source.getSystemId() + ",pid=" + source.getPublicId()); _parser.parse(source, handler); if (handler._error != null) throw handler._error; Node doc = (Node) handler._top.get(0); handler.clear(); return doc; }
From source file:se.lu.nateko.edca.svc.GetCapabilities.java
/** * Parses an XML response from a GetCapabilities request and stores available Layers * and options in the local SQLite database. * @param xmlResponse A reader wrapped around an InputStream containing the XML response from a GetCapabilities request. *///from w w w . jav a 2 s.c om protected boolean parseXMLResponse(BufferedReader xmlResponse) { Log.d(TAG, "parseXMLResponse(Reader) called."); try { SAXParserFactory spfactory = SAXParserFactory.newInstance(); // Make a SAXParser factory. spfactory.setValidating(false); // Tell the factory not to make validating parsers. SAXParser saxParser = spfactory.newSAXParser(); // Use the factory to make a SAXParser. XMLReader xmlReader = saxParser.getXMLReader(); // Get an XML reader from the parser, which will send event calls to its specified event handler. XMLEventHandler xmlEventHandler = new XMLEventHandler(); xmlReader.setContentHandler(xmlEventHandler); // Set which event handler to use. xmlReader.setErrorHandler(xmlEventHandler); // Also set where to send error calls. InputSource source = new InputSource(xmlResponse); // Make an InputSource from the XML input to give to the reader. xmlReader.parse(source); // Start parsing the XML. } catch (Exception e) { Log.e(TAG, "XML parsing error: " + e.toString() + " - " + e.getMessage()); return false; } return true; }
From source file:SAXTreeViewer.java
/** * <p>This handles building the Swing UI tree.</p> * * @param treeModel Swing component to build upon. * @param base tree node to build on.//from ww w.j a v a 2 s . c om * @param xmlURI URI to build XML document from. * @throws <code>IOException</code> - when reading the XML URI fails. * @throws <code>SAXException</code> - when errors in parsing occur. */ public void buildTree(DefaultTreeModel treeModel, DefaultMutableTreeNode base, String xmlURI) throws IOException, SAXException { // Create instances needed for parsing XMLReader reader = XMLReaderFactory.createXMLReader(vendorParserClass); ContentHandler jTreeContentHandler = new JTreeContentHandler(treeModel, base); ErrorHandler jTreeErrorHandler = new JTreeErrorHandler(); // Register content handler reader.setContentHandler(jTreeContentHandler); // Register error handler reader.setErrorHandler(jTreeErrorHandler); // Parse InputSource inputSource = new InputSource(xmlURI); reader.parse(inputSource); }
From source file:com.amazonaws.eclipse.dynamodb.testtool.TestToolManager.java
/** * Parse a manifest file describing a list of test tool versions. * * @param file The file to parse./*from w w w. jav a 2s. co m*/ * @return The parsed list of versions. * @throws IOException on error. */ private List<TestToolVersion> parseManifest(final File file) throws IOException { FileInputStream stream = null; try { stream = new FileInputStream(file); BufferedReader buffer = new BufferedReader(new InputStreamReader(stream)); ManifestContentHandler handler = new ManifestContentHandler(); XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.parse(new InputSource(buffer)); return handler.getResult(); } catch (SAXException exception) { throw new IOException("Error parsing DynamoDB Local manifest file", exception); } finally { if (stream != null) { stream.close(); } } }
From source file:net.sf.firemox.xml.XmlParser.java
/** * @param source//from ww w .j a v a2 s . c o m * the document source. * @return the node of document. * @throws IOException * error while opening the stream. * @throws SAXException * error while parsing. */ public synchronized Node parse(InputSource source) throws IOException, SAXException { Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); parser.parse(source, handler); if (handler.error != null) { throw handler.error; } Node doc = (Node) handler.top.get(0); handler.clear(); return doc; }