List of usage examples for org.xml.sax SAXParseException getColumnNumber
public int getColumnNumber()
From source file:org.apache.tomcat.util.digester.Digester.java
/** * Forward notification of a parsing error to the application supplied * error handler (if any)./*from w ww .ja v a 2 s.c o m*/ * * @param exception The error information * * @exception SAXException if a parsing exception occurs */ public void error(SAXParseException exception) throws SAXException { log.error("Parse Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); if (errorHandler != null) { errorHandler.error(exception); } }
From source file:org.apache.tomcat.util.digester.Digester.java
/** * Forward notification of a fatal parsing error to the application * supplied error handler (if any).//from ww w .ja va 2s . c o m * * @param exception The fatal error information * * @exception SAXException if a parsing exception occurs */ public void fatalError(SAXParseException exception) throws SAXException { log.error("Parse Fatal Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); if (errorHandler != null) { errorHandler.fatalError(exception); } }
From source file:org.apache.tomcat.util.digester.Digester.java
/** * Forward notification of a parse warning to the application supplied * error handler (if any)./*from w w w. j ava 2s. c o m*/ * * @param exception The warning information * * @exception SAXException if a parsing exception occurs */ public void warning(SAXParseException exception) throws SAXException { if (errorHandler != null) { log.warn("Parse Warning Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); errorHandler.warning(exception); } }
From source file:org.apache.torque.engine.database.transform.XmlToAppData.java
/** * Parses a XML input file and returns a newly created and * populated Database structure.// w ww .jav a 2 s . c o m * * @param xmlFile The input file to parse. * @return Database populated by <code>xmlFile</code>. */ public Database parseFile(String xmlFile) throws EngineException { try { // in case I am missing something, make it obvious if (!firstPass) { throw new Error("No more double pass"); } // check to see if we alread have parsed the file if ((alreadyReadFiles != null) && alreadyReadFiles.contains(xmlFile)) { return database; } else if (alreadyReadFiles == null) { alreadyReadFiles = new Vector(3, 1); } // remember the file to avoid looping alreadyReadFiles.add(xmlFile); currentXmlFile = xmlFile; SAXParser parser = saxFactory.newSAXParser(); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(xmlFile); } catch (FileNotFoundException fnfe) { throw new FileNotFoundException(new File(xmlFile).getAbsolutePath()); } BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); try { log.info("Parsing file: '" + (new File(xmlFile)).getName() + "'"); InputSource is = new InputSource(bufferedInputStream); is.setSystemId(new File(xmlFile).getAbsolutePath()); parser.parse(is, this); } finally { bufferedInputStream.close(); } } catch (SAXParseException e) { throw new EngineException("Sax error on line " + e.getLineNumber() + " column " + e.getColumnNumber() + " : " + e.getMessage(), e); } catch (Exception e) { throw new EngineException(e); } if (!isExternalSchema) { firstPass = false; } database.doFinalInitialization(); return database; }
From source file:org.apache.torque.engine.database.transform.XmlToAppData.java
/** * Handles exception which occur when the xml file is parsed * @param e the exception which occured while parsing * @throws SAXException always/*from w ww . j av a2 s. co m*/ */ public void error(SAXParseException e) throws SAXException { log.error("Sax parser threw an Exception", e); throw new SAXException("Error while parsing " + currentXmlFile + " at line " + e.getLineNumber() + " column " + e.getColumnNumber() + " : " + e.getMessage()); }
From source file:org.apache.torque.generator.configuration.controller.ControlConfigurationXmlParser.java
/** * Reads the controller configuration out of a configurationProvider. * * @param configurationProvider the object for accessing the configuration, * not null./*from www . j a va2 s .c om*/ * @param projectPaths the paths inside the configuration, not null. * @param configurationHandlers the available configuration handlers, * not null. * * @return the Controller configuration. * @throws ConfigurationException if an error in the configuration * is encountered. * @throws NullPointerException if an argument is null. */ public ControlConfiguration readControllerConfiguration(ConfigurationProvider configurationProvider, ProjectPaths projectPaths, ConfigurationHandlers configurationHandlers) throws ConfigurationException { InputStream controlConfigurationInputStream = configurationProvider.getControlConfigurationInputStream(); try { ControlConfiguration result = new ControlConfiguration(); try { SAXParser parser = saxFactory.newSAXParser(); InputSource is = new InputSource(controlConfigurationInputStream); parser.parse(is, new ControlConfigurationSaxHandler(result, configurationProvider, projectPaths, configurationHandlers)); } catch (SAXParseException e) { throw new ConfigurationException("Error parsing controller Configuration " + configurationProvider.getControlConfigurationLocation() + " at line " + e.getLineNumber() + " column " + e.getColumnNumber() + " : " + e.getMessage(), e); } catch (Exception e) { throw new ConfigurationException("Error parsing controller Configuration " + configurationProvider.getControlConfigurationLocation() + e.getMessage(), e); } return result; } finally { try { controlConfigurationInputStream.close(); } catch (IOException e) { log.warn("Could not close controlConfigurationInputStream", e); } } }
From source file:org.apache.torque.generator.configuration.outlet.OutletConfigurationXmlParser.java
/** * Reads all outlet configuration files and creates the outlet * configuration from them./*from w w w .j a v a 2 s . c o m*/ * All the outlet configuration files known to the provide are parsed. * These are typically all XML files in the outletDefintiton configuration * directory and its subdirectories. * * @param configurationProvider The access object for the configuration * files, not null. * @param configurationHandlers the handlers for reading the configuration, * not null. * @param unitDescriptor the unit descriptor, not null. * * @return the outlet configuration. * * @throws ConfigurationException if the Configuration cannot be read * or errors exists in the outlet configuration files. */ public OutletConfiguration readOutletConfiguration(ConfigurationProvider configurationProvider, ConfigurationHandlers configurationHandlers, UnitDescriptor unitDescriptor) throws ConfigurationException { if (configurationHandlers == null) { log.error("OutletConfiguration: " + " configurationHandlers is null"); throw new NullPointerException("configurationHandlers is null"); } if (configurationProvider == null) { log.error("OutletConfiguration: " + " configurationProvider is null"); throw new NullPointerException("configurationProvider is null"); } List<Outlet> allOutlets = new ArrayList<Outlet>(); List<MergepointMapping> allMergepointMappings = new ArrayList<MergepointMapping>(); // Outlets from all files Collection<String> outletConfigNames = configurationProvider.getOutletConfigurationNames(); for (String outletConfigName : outletConfigNames) { InputStream inputStream = null; try { inputStream = configurationProvider.getOutletConfigurationInputStream(outletConfigName); OutletConfigFileContent fileContent = readOutletConfig(inputStream, configurationProvider, unitDescriptor.getProjectPaths(), configurationHandlers); allOutlets.addAll(fileContent.getOutlets()); allMergepointMappings.addAll(fileContent.getMergepointMappings()); } catch (SAXParseException e) { throw new ConfigurationException( "Error parsing outlet configuration " + outletConfigName + " at line " + e.getLineNumber() + " column " + e.getColumnNumber() + " : " + e.getMessage(), e); } catch (Exception e) { throw new ConfigurationException("Error parsing outlet configuration " + outletConfigName, e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { log.warn("Could not close " + "outletConfigurationInputStream " + outletConfigName, e); } } } } return new OutletConfiguration(allOutlets, allMergepointMappings, unitDescriptor); }
From source file:org.archive.crawler.settings.XMLSettingsHandler.java
/** Read the CrawlerSettings object from a specific file. * * @param settings the settings object to be updated with data from the * persistent storage./*from w ww. j a va 2 s. c om*/ * @param f the file to read from. * @return the updated settings object or null if there was no data for this * in the persistent storage. */ protected final CrawlerSettings readSettingsObject(CrawlerSettings settings, File f) { CrawlerSettings result = null; try { InputStream is = null; if (!f.exists()) { // Perhaps the file we're looking for is on the CLASSPATH. // DON'T look on the CLASSPATH for 'settings.xml' files. The // look for 'settings.xml' files happens frequently. Not looking // on classpath for 'settings.xml' is an optimization based on // ASSUMPTION that there will never be a 'settings.xml' saved // on classpath. if (!f.getName().startsWith(settingsFilename)) { is = XMLSettingsHandler.class.getResourceAsStream(toResourcePath(f)); } } else { is = new FileInputStream(f); } if (is != null) { XMLReader parser = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); InputStream file = new BufferedInputStream(is); parser.setContentHandler(new CrawlSettingsSAXHandler(settings)); InputSource source = new InputSource(file); source.setSystemId(f.toURL().toExternalForm()); parser.parse(source); result = settings; } } catch (SAXParseException e) { logger.warning(e.getMessage() + " in '" + e.getSystemId() + "', line: " + e.getLineNumber() + ", column: " + e.getColumnNumber()); } catch (SAXException e) { logger.warning(e.getMessage() + ": " + e.getException().getMessage()); } catch (ParserConfigurationException e) { logger.warning(e.getMessage() + ": " + e.getCause().getMessage()); } catch (FactoryConfigurationError e) { logger.warning(e.getMessage() + ": " + e.getException().getMessage()); } catch (IOException e) { logger.warning("Could not access file '" + f.getAbsolutePath() + "': " + e.getMessage()); } return result; }
From source file:org.bibsonomy.rest.renderer.impl.JAXBRenderer.java
/** * Unmarshalls the document from the reader to the generated java * model./*w ww . ja va2 s . co m*/ * * @return A BibsonomyXML object that contains the unmarshalled content * @throws InternServerException * if the content can't be unmarshalled */ private BibsonomyXML parse(final Reader reader) throws InternServerException { // first: check the reader this.checkReader(reader); try { // initialize JAXB context. We provide the classloader here because we experienced that under // certain circumstances (e.g. when used within JabRef as a JPF-Plugin), the wrong classloader is // used which has the following exception as consequence: // // javax.xml.bind.JAXBException: "org.bibsonomy.rest.renderer.xml" doesnt contain ObjectFactory.class or jaxb.index // // (see also http://ws.apache.org/jaxme/apidocs/javax/xml/bind/JAXBContext.html) final JAXBContext jc = this.getJAXBContext(); // create an Unmarshaller final Unmarshaller u = jc.createUnmarshaller(); // set schema to validate input documents if (this.validateXMLInput) { u.setSchema(schema); } /* * unmarshal a xml instance document into a tree of Java content * objects composed of classes from the restapi package. */ final JAXBElement<BibsonomyXML> xmlDoc = unmarshal(u, reader); return xmlDoc.getValue(); } catch (final JAXBException e) { if (e.getLinkedException() != null && e.getLinkedException().getClass() == SAXParseException.class) { final SAXParseException ex = (SAXParseException) e.getLinkedException(); throw new BadRequestOrResponseException("Error while parsing XML (Line " + ex.getLineNumber() + ", Column " + ex.getColumnNumber() + ": " + ex.getMessage()); } throw new InternServerException(e.toString()); } }
From source file:org.bibsonomy.rest.renderer.impl.JAXBRenderer.java
/** * Initializes java xml bindings, builds the document and then marshalls * it to the writer./*from ww w. j a va 2 s . c o m*/ * * @throws InternServerException * if the document can't be marshalled */ private void serialize(final Writer writer, final BibsonomyXML xmlDoc) throws InternServerException { try { // initialize context for java xml bindings final JAXBContext jc = this.getJAXBContext(); // buildup document model final JAXBElement<BibsonomyXML> webserviceElement = new ObjectFactory().createBibsonomy(xmlDoc); // create a marshaller final Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (this.validateXMLOutput) { // validate the XML produced by the marshaller marshaller.setSchema(schema); } // marshal to the writer this.marshal(marshaller, webserviceElement, writer); // TODO log // log.debug(""); } catch (final JAXBException e) { final Throwable linkedException = e.getLinkedException(); if (present(linkedException) && linkedException.getClass() == SAXParseException.class) { final SAXParseException ex = (SAXParseException) linkedException; throw new BadRequestOrResponseException("Error while parsing XML (Line " + ex.getLineNumber() + ", Column " + ex.getColumnNumber() + ": " + ex.getMessage()); } throw new InternServerException(e.toString()); } }