List of usage examples for org.xml.sax SAXParseException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.StreamsConfigSAXParser.java
/** * Reads the configuration and invokes the (SAX-based) parser to parse the configuration file contents. * * @param config//from w w w . j a v a2s .c om * input stream to get configuration data from * @param validate * flag indicating whether to validate configuration XML against XSD schema * @return streams configuration data * @throws ParserConfigurationException * if there is an inconsistency in the configuration * @throws SAXException * if there was an error parsing the configuration * @throws IOException * if there is an error reading the configuration data */ public static StreamsConfigData parse(InputStream config, boolean validate) throws ParserConfigurationException, SAXException, IOException { if (validate) { config = config.markSupported() ? config : new ByteArrayInputStream(IOUtils.toByteArray(config)); Map<OpLevel, List<SAXParseException>> validationErrors = validate(config); if (MapUtils.isNotEmpty(validationErrors)) { for (Map.Entry<OpLevel, List<SAXParseException>> vee : validationErrors.entrySet()) { for (SAXParseException ve : vee.getValue()) { LOGGER.log(OpLevel.WARNING, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "StreamsConfigSAXParser.xml.validation.error"), ve.getLineNumber(), ve.getColumnNumber(), vee.getKey(), ve.getLocalizedMessage()); } } } } Properties p = Utils.loadPropertiesResource("sax.properties"); // NON-NLS SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser parser = parserFactory.newSAXParser(); ConfigParserHandler hndlr = null; try { String handlerClassName = p.getProperty(HANDLER_PROP_KEY, ConfigParserHandler.class.getName()); if (StringUtils.isNotEmpty(handlerClassName)) { hndlr = (ConfigParserHandler) Utils.createInstance(handlerClassName); } } catch (Exception exc) { } if (hndlr == null) { hndlr = new ConfigParserHandler(); } parser.parse(config, hndlr); return hndlr.getStreamsConfigData(); }
From source file:fr.lifl.xmlutils.ConfiguratorErrorHandler.java
public void warning(SAXParseException arg0) throws SAXException { log.warn(arg0.getLocalizedMessage(), arg0); }
From source file:fr.lifl.xmlutils.ConfiguratorErrorHandler.java
public void error(SAXParseException arg0) throws SAXException { log.error(arg0.getLocalizedMessage(), arg0); arg0.fillInStackTrace();/*w ww.j ava 2s . c om*/ throw arg0; }
From source file:fr.lifl.xmlutils.ConfiguratorErrorHandler.java
public void fatalError(SAXParseException arg0) throws SAXException { log.fatal(arg0.getLocalizedMessage(), arg0); arg0.fillInStackTrace();//w w w.ja va 2 s.c om throw arg0; }
From source file:ca.uhn.fhir.validation.SchemaBaseValidator.java
private void doValidate(IValidationContext<?> theContext, String schemaName) { Schema schema = loadSchema("dstu", schemaName); try {//from w ww .j a v a 2s .co m Validator validator = schema.newValidator(); MyErrorHandler handler = new MyErrorHandler(theContext); validator.setErrorHandler(handler); String encodedResource; if (theContext.getResourceAsStringEncoding() == EncodingEnum.XML) { encodedResource = theContext.getResourceAsString(); } else { encodedResource = theContext.getFhirContext().newXmlParser() .encodeResourceToString((IBaseResource) theContext.getResource()); } try { /* * See https://github.com/jamesagnew/hapi-fhir/issues/339 * https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing */ validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (SAXNotRecognizedException ex) { ourLog.warn("Jaxp 1.5 Support not found.", ex); } validator.validate(new StreamSource(new StringReader(encodedResource))); } catch (SAXParseException e) { SingleValidationMessage message = new SingleValidationMessage(); message.setLocationLine(e.getLineNumber()); message.setLocationCol(e.getColumnNumber()); message.setMessage(e.getLocalizedMessage()); message.setSeverity(ResultSeverityEnum.FATAL); theContext.addValidationMessage(message); } catch (SAXException e) { // Catch all throw new ConfigurationException("Could not load/parse schema file", e); } catch (IOException e) { // Catch all throw new ConfigurationException("Could not load/parse schema file", e); } }
From source file:org.apache.fop.fo.FOTreeBuilder.java
/** {@inheritDoc} */ public void warning(SAXParseException e) { LOG.warn(e.getLocalizedMessage()); }
From source file:org.geotools.styling.css.AbstractIntegrationTest.java
@Test public void translateTest() throws Exception { String css = FileUtils.readFileToString(file); if (!exclusiveRulesEnabled) { css = "@mode \"Simple\";\n" + css; }//w ww .ja va 2 s . c o m File sldFile = new File(file.getParentFile(), FilenameUtils.getBaseName(file.getName()) + (exclusiveRulesEnabled ? "" : "-first") + ".sld"); if (!sldFile.exists()) { Stylesheet ss = CssParser.parse(css); CssTranslator tx = new CssTranslator(); Style style = tx.translate(ss); writeStyle(style, sldFile); // throw new IllegalStateException("Could not locate sample sld file " + // sldFile.getPath()); } Style actual = cssToSld(css); File sldFile2 = new File("./target/css", FilenameUtils.getBaseName(file.getName()) + ".sld"); writeStyle(actual, sldFile2); String actualSld = FileUtils.readFileToString(sldFile2); List validationErrors = validateSLD(actualSld); if (!validationErrors.isEmpty()) { System.err.println("Validation failed, errors are: "); for (Object e : validationErrors) { if (e instanceof SAXParseException) { SAXParseException se = (SAXParseException) e; System.out.println("line " + se.getLineNumber() + ": " + se.getLocalizedMessage()); } else { System.out.println(e); } } System.err.println("Validation failed, the two files are: " + sldFile.getAbsolutePath() + " " + sldFile2.getAbsolutePath()); fail("Validation failed"); } String expectedSld = FileUtils.readFileToString(sldFile); StyledLayerDescriptor expectedSLD = parseToSld(expectedSld); StyledLayerDescriptor actualSLD = parseToSld(actualSld); // Document expectedDom = XMLUnit.buildControlDocument(expectedSld); // Document actualDom = XMLUnit.buildControlDocument(actualSld); // Diff diff = new Diff(expectedDom, actualDom); // if (!diff.identical()) { if (!expectedSLD.equals(actualSLD)) { String message = "Comparison failed, the two files are: " + sldFile.getAbsolutePath() + " " + sldFile2.getAbsolutePath(); System.err.println(message); fail(message); } // } }
From source file:org.patientview.patientview.EmailUtils.java
public static String createEmailBodyForXMLValidationErrors(List<SAXParseException> exceptions, String xmlFileName, String xsdFileName, ServletContext context) { StringBuilder emailBody = new StringBuilder(); emailBody.append("[This is an automated email from Renal PatientView - do not reply to this email]"); emailBody.append(NEW_LINE);//from w w w . j a v a 2s . c o m emailBody.append(NEW_LINE).append("The file <").append(xmlFileName).append("> has failed to import."); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("It did not match the schema file named: "); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append(xsdFileName); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("Before contacting the email address below please ensure that:"); emailBody.append(NEW_LINE).append(" - The file is not empty."); emailBody.append(NEW_LINE).append(" - The file is well formed XML."); emailBody.append(NEW_LINE).append(" - The file matches the RPV XML schema."); emailBody.append(NEW_LINE).append(" - There are no missing values."); emailBody.append(NEW_LINE).append(" - There are no empty tags in letters, medicines, results etc."); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append( "Please carefully read the stack trace below, there is often a good hint in there as to why your " + "file failed:"); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("Validation errors:"); emailBody.append(NEW_LINE); for (SAXParseException exception : exceptions) { emailBody.append(NEW_LINE).append(exception.getLocalizedMessage()); emailBody.append(NEW_LINE); } emailBody.append(NEW_LINE); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("For further help, please contact ") .append(LegacySpringUtils.getContextProperties().getProperty("support.email")); emailBody.append(NEW_LINE); return emailBody.toString(); }
From source file:org.patientview.patientview.EmailUtils.java
public static String createEmailBodyForXMLValidationErrors(List<SAXParseException> exceptions, String xmlFileName, String xsdFileName, String supportEmail) { StringBuilder emailBody = new StringBuilder(); emailBody.append("[This is an automated email from Renal PatientView - do not reply to this email]"); emailBody.append(NEW_LINE);//from ww w . j av a 2 s. c o m emailBody.append(NEW_LINE).append("The file <").append(xmlFileName).append("> has failed to import."); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("It did not match the schema file named: "); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append(xsdFileName); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("Before contacting the email address below please ensure that:"); emailBody.append(NEW_LINE).append(" - The file is not empty."); emailBody.append(NEW_LINE).append(" - The file is well formed XML."); emailBody.append(NEW_LINE).append(" - The file matches the RPV XML schema."); emailBody.append(NEW_LINE).append(" - There are no missing values."); emailBody.append(NEW_LINE).append(" - There are no empty tags in letters, medicines, results etc."); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append( "Please carefully read the stack trace below, there is often a good hint in there as to why your ") .append("file failed:"); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("Validation errors:"); emailBody.append(NEW_LINE); for (SAXParseException exception : exceptions) { emailBody.append(NEW_LINE).append(exception.getLocalizedMessage()); emailBody.append(NEW_LINE); } emailBody.append(NEW_LINE); emailBody.append(NEW_LINE); emailBody.append(NEW_LINE).append("For further help, please contact " + supportEmail); emailBody.append(NEW_LINE); return emailBody.toString(); }