List of usage examples for org.xml.sax SAXParseException getMessage
public String getMessage()
From source file:com.spoledge.util.xml.XMLValidatorInstance.java
/** * XML parser method.// w w w. j a v a 2 s. c o m */ public void error(SAXParseException e) throws SAXException { throw new SAXParseException("line " + locator.getLineNumber() + " column " + locator.getColumnNumber() + (lastStartElement != null ? " in '" + lastStartElement + "'" : (lastEndElement != null ? " after '" + lastEndElement + "'" : "")) + ": " + e.getMessage(), locator); }
From source file:com.spoledge.util.xml.XMLValidatorInstance.java
/** * XML parser method./* www. j a v a 2 s . com*/ */ public void fatalError(SAXParseException e) throws SAXException { throw new SAXParseException("line " + locator.getLineNumber() + " column " + locator.getColumnNumber() + (lastStartElement != null ? " in '" + lastStartElement + "'" : (lastEndElement != null ? " after '" + lastEndElement + "'" : "")) + ": " + e.getMessage(), locator); }
From source file:ch.entwine.weblounge.common.impl.content.page.PageReader.java
/** * The parser encountered problems while parsing. The error is printed out and * the parsing process is stopped.// w w w .j a v a2 s.c o m * * @param e * information about the error */ public void error(SAXParseException e) { logger.warn("Error while reading {}: {}", page, e.getMessage()); }
From source file:ch.entwine.weblounge.common.impl.content.page.PageReader.java
/** * The parser encountered problems while parsing. The warning is printed out * but the parsing process continues.//from w ww .j a va2 s . c o m * * @param e * information about the warning */ public void warning(SAXParseException e) { logger.warn("Warning while reading {}: {}", page, e.getMessage()); }
From source file:ch.entwine.weblounge.common.impl.content.page.PageReader.java
/** * The parser encountered problems while parsing. The fatal error is printed * out and the parsing process is stopped. * /*from w w w.j a va2 s .c om*/ * @param e * information about the error */ public void fatalError(SAXParseException e) { logger.warn("Fatal error while reading {}: {}", page, e.getMessage()); }
From source file:com.cyberway.issue.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./* w ww . ja v a 2 s .c o m*/ * @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(f.getPath()); } } 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.slc.sli.ingestion.validation.XsdErrorHandler.java
/** * Incorporate the SAX error message into an ingestion error message. * * @param saxErrorMessage/*from w ww . ja v a 2s . c o m*/ * Error message returned by SAX * @return Error message returned by Ingestion */ private String getErrorMessage(SAXParseException ex) { // Create an ingestion error message incorporating the SAXParseException information. String fullParsefilePathname = (ex.getSystemId() == null) ? "" : ex.getSystemId(); File parseFile = new File(fullParsefilePathname); // Return the ingestion error message. return MessageSourceHelper.getMessage(messageSource, "XSD_VALIDATION_ERROR", parseFile.getName(), String.valueOf(ex.getLineNumber()), String.valueOf(ex.getColumnNumber()), ex.getMessage()); }
From source file:com.gdo.stencils.factory.InterpretedStencilFactory.java
@Override @SuppressWarnings("unchecked") public synchronized _Stencil<C, S> loadStencil(C stclContext, Reader in, String name) { try {//from w ww . j a v a2 s . c om Object parsed = _digester.parse(in); if (parsed instanceof StencilDescriptor) { StencilDescriptor<C, S> descriptor = (StencilDescriptor<C, S>) parsed; String rootId = descriptor.getId(); InstanceRepository<C, S> instances = new InstanceRepository<C, S>(rootId); return descriptor.createInstance(stclContext, rootId, instances, 0); } } catch (SAXParseException e) { logError(stclContext, "'t:%s, l:%s, c:%s : %s)", name, Integer.toString(e.getLineNumber()), Integer.toString(e.getColumnNumber()), e.getMessage()); } catch (Exception e) { logError(stclContext, "Error when loading stencil %s", e); } return null; }
From source file:eionet.gdem.validation.ValidationService.java
/** /**//from ww w . j a va 2 s .co m * Validate XML. If schema is null, then read the schema or DTD from the header of XML. If schema or DTD is defined, then ignore * the defined schema or DTD. * * @param srcStream XML file as InputStream to be validated. * @param schema XML Schema URL. * @return Validation result as HTML snippet. * @throws DCMException in case of unknnown system error. */ public String validateSchema(InputStream srcStream, String schema) throws DCMException { String result = ""; boolean isDTD = false; boolean isBlocker = false; if (Utils.isNullStr(schema)) { schema = null; } try { SAXParserFactory spfact = SAXParserFactory.newInstance(); SAXParser parser = spfact.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(errHandler); XmlconvCatalogResolver catalogResolver = new XmlconvCatalogResolver(); reader.setEntityResolver(catalogResolver); // make parser to validate reader.setFeature("http://xml.org/sax/features/validation", true); reader.setFeature("http://apache.org/xml/features/validation/schema", true); reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); reader.setFeature("http://xml.org/sax/features/namespaces", true); reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); reader.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false); InputAnalyser inputAnalyser = new InputAnalyser(); inputAnalyser.parseXML(uriXml); String namespace = inputAnalyser.getSchemaNamespace(); // if schema is not in the parameter, then sniff it from the header of xml if (schema == null) { schema = inputAnalyser.getSchemaOrDTD(); isDTD = inputAnalyser.isDTD(); } else { // if the given schema ends with dtd, then don't do schema validation isDTD = schema.endsWith("dtd"); } // schema is already given as a parameter. Read the default namespace from XML file and set external schema. if (schema != null) { if (!isDTD) { if (Utils.isNullStr(namespace)) { // XML file does not have default namespace setNoNamespaceSchemaProperty(reader, schema); } else { setNamespaceSchemaProperty(reader, namespace, schema); } } else { // validate against DTD setLocalSchemaUrl(schema); LocalEntityResolver localResolver = new LocalEntityResolver(schema, getValidatedSchema()); reader.setEntityResolver(localResolver); } } else { return validationFeedback.formatFeedbackText( "Could not validate XML file. Unable to locate XML Schema reference.", QAFeedbackType.WARNING, isBlocker); } // if schema is not available, then do not parse the XML and throw error if (!Utils.resourceExists(getValidatedSchema())) { return validationFeedback.formatFeedbackText( "Failed to read schema document from the following URL: " + getValidatedSchema(), QAFeedbackType.ERROR, isBlocker); } Schema schemaObj = schemaManager.getSchema(getOriginalSchema()); if (schemaObj != null) { isBlocker = schemaObj.isBlocker(); } validationFeedback.setSchema(getOriginalSchema()); InputSource is = new InputSource(srcStream); reader.parse(is); } catch (SAXParseException se) { return validationFeedback.formatFeedbackText("Document is not well-formed. Column: " + se.getColumnNumber() + "; line:" + se.getLineNumber() + "; " + se.getMessage(), QAFeedbackType.ERROR, isBlocker); } catch (IOException ioe) { return validationFeedback.formatFeedbackText( "Due to an IOException, the parser could not check the document. " + ioe.getMessage(), QAFeedbackType.ERROR, isBlocker); } catch (Exception e) { Exception se = e; if (e instanceof SAXException) { se = ((SAXException) e).getException(); } if (se != null) { se.printStackTrace(System.err); } else { e.printStackTrace(System.err); } return validationFeedback.formatFeedbackText( "The parser could not check the document. " + e.getMessage(), QAFeedbackType.ERROR, isBlocker); } validationFeedback.setValidationErrors(getErrorList()); result = validationFeedback.formatFeedbackText(isBlocker); // validation post-processor QAResultPostProcessor postProcessor = new QAResultPostProcessor(); result = postProcessor.processQAResult(result, schema); warningMessage = postProcessor.getWarningMessage(schema); return result; }
From source file:com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.java
private TcConfiguration getConfigFromSourceStream(InputStream in, boolean trustedSource, String descrip, String source, ClassLoader loader) throws ConfigurationSetupException { TcConfiguration tcConfigDoc;//w w w . j av a 2 s.c o m try { ByteArrayOutputStream dataCopy = new ByteArrayOutputStream(); IOUtils.copy(in, dataCopy); in.close(); InputStream copyIn = new ByteArrayInputStream(dataCopy.toByteArray()); BeanWithErrors beanWithErrors = beanFactory.createBean(copyIn, descrip, source, loader); if (beanWithErrors.errors() != null && beanWithErrors.errors().length > 0) { logger.debug("Configuration didn't parse; it had " + beanWithErrors.errors().length + " error(s)."); StringBuffer buf = new StringBuffer(); for (int i = 0; i < beanWithErrors.errors().length; ++i) { SAXParseException error = beanWithErrors.errors()[i]; buf.append(" [" + i + "]: Line " + error.getLineNumber() + ", column " + error.getColumnNumber() + ": " + error.getMessage() + "\n"); } throw new ConfigurationSetupException("The configuration data in the " + descrip + " does not obey the Terracotta schema:\n" + buf); } else { logger.debug("Configuration is valid."); } tcConfigDoc = ((TcConfiguration) beanWithErrors.bean()); this.providedTcConfigDocument = tcConfigDoc; } catch (IOException ioe) { throw new ConfigurationSetupException("We were unable to read configuration data from the " + descrip + ": " + ioe.getLocalizedMessage(), ioe); } catch (SAXException saxe) { throw new ConfigurationSetupException("The configuration data in the " + descrip + " is not well-formed XML: " + saxe.getLocalizedMessage(), saxe); } catch (ParserConfigurationException pce) { throw Assert.failure("The XML parser can't be configured correctly; this should not happen.", pce); } return tcConfigDoc; }