protected void loadXML() throws IOException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); XMLReader xr = factory.newSAXParser().getXMLReader(); rules = new HashMap<String, JSGFRule>(); GrXMLHandler handler = new GrXMLHandler(baseURL, rules, logger); xr.setContentHandler(handler); xr.setErrorHandler(handler); InputStream is = baseURL.openStream(); xr.parse(new InputSource(is)); is.close(); } catch (SAXParseException e) { String msg = "Error while parsing line " + e.getLineNumber() + " of " + baseURL + ": " + e.getMessage(); throw new IOException(msg); } catch (SAXException e) { throw new IOException("Problem with XML: " + e); } catch (ParserConfigurationException e) { throw new IOException(e.getMessage()); } return; }
@Override public void fatalError(SAXParseException ex) throws SAXParseException { throw new SAXParseException(makeBetterErrorString("Fatal Error", ex), ex.getPublicId(), ex.getSystemId(), ex.getLineNumber(), ex.getColumnNumber()); // throw new RuntimeException(makeBetterErrorString("Fatal Error", ex)); }
/** * Throws back the exception with the name of the XML file and the position where the exception * occurred. */ @Override public void error(final SAXParseException exception) throws SAXException { throw new SAXParseException("Error while parsing XML at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), null, exception); }
private String getMessage(String level, SAXParseException e) { return "Parsing " + level + "\n" + "Line: " + e.getLineNumber() + "\n" + "URI: " + e.getSystemId() + "\n" + "Message: " + e.getMessage(); } }
throw new IllegalArgumentException("Null input."); if (is.getByteStream() == null && is.getCharacterStream() == null) { String systemId = is.getSystemId(); if (systemId == null) { throw new IllegalArgumentException( is = new InputSource(); is.setSystemId(systemId); is.setByteStream(new URL(systemId).openStream()); throw new ParsingException(e.getMessage(), e.getSystemId(), e.getLineNumber(), e.getColumnNumber(), e); } catch (SAXException e) { throw new ParsingException(e.getMessage(), e);
doc = saxReader.read( new InputSource( xmlInputStream ) ); if ( errors.size() != 0 ) { SAXParseException exception = errors.get( 0 ); final String errorMessage = exception.getMessage(); for ( SAXParseException error : errors ) { errorMessage.append( "Error parsing XML (line" ) .append( error.getLineNumber() ) .append( " : column " ) .append( error.getColumnNumber() ) .append( "): " ) .append( error.getMessage() ) .append( "\n" ); xmlInputStream.close();
inputSource = new InputSource(inputStream); inputSource.setSystemId(uri); project.log("parsing buildfile " + bFile + " with URI = " + uri, Project.MSG_VERBOSE); HandlerBase hb = new RootHandler(this); parser.parse(inputSource); } catch (SAXParseException exc) { Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc .getColumnNumber()); Throwable t = exc.getException(); if (t instanceof BuildException) { BuildException be = (BuildException) t; throw new BuildException(exc.getMessage(), t, location); } catch (SAXException exc) { Throwable t = exc.getException(); if (t instanceof BuildException) { throw (BuildException) t; throw new BuildException(exc.getMessage(), t); } catch (FileNotFoundException exc) { throw new BuildException(exc);
public void parse(InputSource source) throws SAXException, IOException systemId = source.getSystemId(); contentHandler.setDocumentLocator(this); SAXParseException saxException = new SAXParseException( "null source systemId" , this); errorHandler.fatalError(saxException); return; final URL url = new URL(systemId); stream = url.openStream(); } catch (MalformedURLException nue) { try { stream = new FileInputStream(systemId); } catch (FileNotFoundException fnfe) { final SAXParseException saxException = new SAXParseException( "could not open file with systemId "+systemId, this, fnfe); errorHandler.fatalError(saxException); return; final SAXParseException saxException = new SAXParseException( "parsing initialization error: "+ex, this, ex); final SAXParseException saxException = new SAXParseException( "expected start tag not"+pp.getPositionDescription(), this); final SAXParseException saxException = new SAXParseException( "parsing initialization error: "+ex, this, ex);
URLConnection conn = new URL(url).openConnection(); parser.parse(new InputSource(conn.getInputStream())); } 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 new OntopiaRuntimeException(e.getException()); throw new OntopiaRuntimeException(e); } catch (Exception e) {
private static Document newDocument(InputSource source) throws IOException, SAXException { try { return getDocumentBuilder().parse(source); } catch (SAXParseException e) { throw new SAXException(String.format("SAXParseException at line:%d, col:%d, %s", e.getLineNumber(), e.getColumnNumber(), e.getMessage())); } }
try { in = getInputStream(location); InputSource is = new InputSource(in); is.setSystemId(location); parser.parse(is, this); } finally { in.close(); throw new EngineException("Sax error on line " + e.getLineNumber() + " column " + e.getColumnNumber() + " : " + e.getMessage(), e); } catch (Exception e) { throw new EngineException(e);
String qualifiedName = null; DocumentType doctype = null; String inputEncoding = source.getEncoding(); String systemId = source.getSystemId(); DocumentImpl document = new DocumentImpl( dom, namespaceURI, qualifiedName, doctype, inputEncoding); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware); if (source.getByteStream() != null) { parser.setInput(source.getByteStream(), inputEncoding); } else if (source.getCharacterStream() != null) { parser.setInput(source.getCharacterStream()); } else if (systemId != null) { URL url = new URL(systemId); URLConnection urlConnection = url.openConnection(); urlConnection.connect(); throw new SAXParseException("InputSource needs a stream, reader or URI", null); throw new SAXParseException("Unexpected end of document", null); locator.setColumnNumber(ex.getColumnNumber()); SAXParseException newEx = new SAXParseException(ex.getMessage(), locator); errorHandler.error(newEx);
public PomReader(URL descriptorURL, Resource res) throws IOException, SAXException { InputStream stream = new AddDTDFilterInputStream(URLHandlerRegistry.getDefault() .openStream(descriptorURL)); InputSource source = new InputSource(stream); source.setSystemId(XMLHelper.toSystemId(descriptorURL)); try { Document pomDomDoc = XMLHelper.parseToDom(source, new EntityResolver() { throws SAXException, IOException { if ((systemId != null) && systemId.endsWith("m2-entities.ent")) { return new InputSource(PomReader.class .getResourceAsStream("m2-entities.ent")); if (!PROJECT.equals(projectElement.getNodeName()) && !MODEL.equals(projectElement.getNodeName())) { throw new SAXParseException("project must be the root tag", res.getName(), res.getName(), 0, 0); } finally { try { stream.close(); } catch (IOException e) {
if (!in.markSupported()) in = new BufferedInputStream(in); if (FileUtils.UTF_8.equals(encoding) || FileUtils.UTF_16.equals(encoding)) InputSource inputSource = new InputSource(in); inputSource.setEncoding(encoding); doc = docBuilder.parse(inputSource); doc = docBuilder.parse(in); Integer line = new Integer(ex.getLineNumber()); Integer col = new Integer(ex.getColumnNumber()); String message = ex.getMessage(); e.setMessage(ex.getMessage()); e.setRootCause(ex); throw e;
+ "] web configuration resource " + source.getSystemId()); source.setByteStream(stream); log.error(sm.getString("contextConfig.defaultParse"), e); log.error(sm.getString("contextConfig.defaultPosition", "" + e.getLineNumber(), "" + e.getColumnNumber())); ok = false; } catch (Exception e) { try { if (stream != null) { stream.close();
private boolean doesSaxSupportCharacterSet(final String charSetName) throws ParserConfigurationException, SAXException, IOException { final byte[] data = ("<?xml version=\"1.0\" encoding=\"" + charSetName + "\"?><Z/>").getBytes(charSetName); final DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); try { final InputSource is = new InputSource(new ByteArrayInputStream(data)); is.setEncoding(charSetName); documentBuilder.parse(is); } catch (final SAXParseException e) { if (e.getMessage().contains(charSetName)) { return false; } } return true; } }
public void readXML(InputStream stream, String encoding) throws IOException { try { InputStreamReader streamReader = new InputStreamReader(stream, encoding); this.root = new TextNode(); XMLEventHandler handler = new XMLEventHandler(root); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); // XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.parse(new InputSource(streamReader)); } catch (SAXParseException spe) { StringBuffer sb = new StringBuffer(spe.toString()); sb.append("\n Line number: " + spe.getLineNumber()); sb.append("\n Column number: " + spe.getColumnNumber()); sb.append("\n Public ID: " + spe.getPublicId()); sb.append("\n System ID: " + spe.getSystemId() + "\n"); System.out.println(sb.toString()); } catch (SAXException se) { System.out.println("loadDOM threw " + se); se.printStackTrace(System.out); } catch (ParserConfigurationException e) { e.printStackTrace(); } }
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new File(fileName)); System.out.println("Retrieving Metric List from xml file: " + fileName); System.out.println("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch (SAXException e) { Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) {
private void parse(InputSource in, ContentHandler handler) throws IOException, ParserException { try { Document d = BUILDER_FACTORY.newDocumentBuilder().parse(in); buildCalendar(d, handler); } catch (ParserConfigurationException e) { throw new CalendarException(e); } catch (SAXException e) { if (e instanceof SAXParseException) { SAXParseException pe = (SAXParseException) e; throw new ParserException("Could not parse XML", pe.getLineNumber(), e); } throw new ParserException(e.getMessage(), -1, e); } }
public static void load( final ConfigurationBuffer buffer, final InputStream r, final String path, final String context, String rootElement, boolean ignoreUnknownItems ) throws ConfigurationException { ThreadLocalToolkit.log( new LoadingConfiguration(path) ); Handler h = new Handler( buffer, path, context, rootElement, ignoreUnknownItems ); SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); InputSource source = new InputSource( r ); parser.parse( source, h ); } catch (SAXConfigurationException e) { throw e.innerException; } catch (SAXParseException e) { throw new ConfigurationException.OtherThrowable( e, null, path, e.getLineNumber() ); } catch (Exception e) { throw new ConfigurationException.OtherThrowable( e, null, path, -1 ); } }