List of usage examples for org.xml.sax SAXNotRecognizedException getMessage
public String getMessage()
From source file:org.apache.tomcat.util.digester.GenericParser.java
/** * Create a <code>SAXParser</code> configured to support XML Scheman and DTD * @param properties parser specific properties/features * @return an XML Schema/DTD enabled <code>SAXParser</code> *//*from www . j av a 2 s.c o m*/ public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotRecognizedException { SAXParserFactory factory = (SAXParserFactory) properties.get("SAXParserFactory"); SAXParser parser = factory.newSAXParser(); String schemaLocation = (String) properties.get("schemaLocation"); String schemaLanguage = (String) properties.get("schemaLanguage"); try { if (schemaLocation != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); } } catch (SAXNotRecognizedException e) { log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported."); } return parser; }
From source file:org.apache.tomcat.util.digester.XercesParser.java
/** * Configure schema validation as recommended by the JAXP 1.2 spec. * The <code>properties</code> object may contains information about * the schema local and language. /* w w w. j a v a 2 s. com*/ * @param properties parser optional info */ private static void configureOldXerces(SAXParser parser, Properties properties) throws ParserConfigurationException, SAXNotSupportedException { String schemaLocation = (String) properties.get("schemaLocation"); String schemaLanguage = (String) properties.get("schemaLanguage"); try { if (schemaLocation != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); } } catch (SAXNotRecognizedException e) { log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported."); } }
From source file:org.dita.dost.module.GenMapAndTopicListModule.java
/** * Init xml reader used for pipeline parsing. * //from w w w . j a v a 2 s . c om * @param ditaDir absolute path to DITA-OT directory * @param validate whether validate input file * @throws SAXException parsing exception */ private void initXMLReader(final File ditaDir, final boolean validate) throws SAXException { reader = XMLUtils.getXMLReader(); // to check whether the current parsing file's href value is out of inputmap.dir reader.setFeature(FEATURE_NAMESPACE_PREFIX, true); if (validate) { reader.setFeature(FEATURE_VALIDATION, true); try { reader.setFeature(FEATURE_VALIDATION_SCHEMA, true); } catch (final SAXNotRecognizedException e) { // Not Xerces, ignore exception } } else { final String msg = MessageUtils.getInstance().getMessage("DOTJ037W").toString(); logger.warn(msg); } if (gramcache) { final XMLGrammarPool grammarPool = GrammarPoolManager.getGrammarPool(); try { reader.setProperty("http://apache.org/xml/properties/internal/grammar-pool", grammarPool); logger.info("Using Xerces grammar pool for DTD and schema caching."); } catch (final NoClassDefFoundError e) { logger.debug("Xerces not available, not using grammar caching"); } catch (final SAXNotRecognizedException | SAXNotSupportedException e) { logger.warn("Failed to set Xerces grammar pool for parser: " + e.getMessage()); } } CatalogUtils.setDitaDir(ditaDir); reader.setEntityResolver(CatalogUtils.getCatalogResolver()); }
From source file:org.dita.dost.module.reader.AbstractReaderModule.java
/** * Init xml reader used for pipeline parsing. * * @param ditaDir absolute path to DITA-OT directory * @param validate whether validate input file * @throws SAXException parsing exception *///from w ww. ja v a 2s. co m void initXMLReader(final File ditaDir, final boolean validate) throws SAXException { reader = XMLUtils.getXMLReader(); reader.setFeature(FEATURE_NAMESPACE, true); reader.setFeature(FEATURE_NAMESPACE_PREFIX, true); if (validate) { reader.setFeature(FEATURE_VALIDATION, true); try { reader.setFeature(FEATURE_VALIDATION_SCHEMA, true); } catch (final SAXNotRecognizedException e) { // Not Xerces, ignore exception } } else { logger.warn(MessageUtils.getMessage("DOTJ037W").toString()); } if (gramcache) { final XMLGrammarPool grammarPool = GrammarPoolManager.getGrammarPool(); try { reader.setProperty("http://apache.org/xml/properties/internal/grammar-pool", grammarPool); logger.info("Using Xerces grammar pool for DTD and schema caching."); } catch (final NoClassDefFoundError e) { logger.debug("Xerces not available, not using grammar caching"); } catch (final SAXNotRecognizedException | SAXNotSupportedException e) { logger.warn("Failed to set Xerces grammar pool for parser: " + e.getMessage()); } } CatalogUtils.setDitaDir(ditaDir); reader.setEntityResolver(CatalogUtils.getCatalogResolver()); }
From source file:org.dita.dost.module.reader.AbstractReaderModule.java
/** * Read a file and process it for list information. * * @param ref system path of the file to process * @param parseFile file to parse, may be {@code null} * @throws DITAOTException if processing failed *//*from www.ja v a 2 s. co m*/ void readFile(final Reference ref, final URI parseFile) throws DITAOTException { currentFile = ref.filename; assert currentFile.isAbsolute(); final URI src = parseFile != null ? parseFile : currentFile; assert src.isAbsolute(); final URI rel = tempFileNameScheme.generateTempFileName(currentFile); outputFile = new File(job.tempDirURI.resolve(rel)); final File outputDir = outputFile.getParentFile(); if (!outputDir.exists() && !outputDir.mkdirs()) { logger.error("Failed to create output directory " + outputDir.getAbsolutePath()); return; } validateMap = Collections.emptyMap(); defaultValueMap = Collections.emptyMap(); logger.info("Processing " + currentFile + " to " + outputFile.toURI()); final String[] params = { currentFile.toString() }; // Verify stub for current file is in Job final FileInfo fi = job.getFileInfo(currentFile); if (fi == null) { final FileInfo stub = new FileInfo.Builder().src(currentFile).uri(rel).result(currentFile) .isInput(currentFile.equals(rootFile)).build(); job.add(stub); } // InputSource in = null; Result out = null; try { final TransformerFactory tf = TransformerFactory.newInstance(); final SAXTransformerFactory stf = (SAXTransformerFactory) tf; final TransformerHandler serializer = stf.newTransformerHandler(); XMLReader parser = getXmlReader(ref.format); XMLReader xmlSource = parser; for (final XMLFilter f : getProcessingPipe(currentFile)) { f.setParent(xmlSource); f.setEntityResolver(CatalogUtils.getCatalogResolver()); xmlSource = f; } try { final LexicalHandler lexicalHandler = new DTDForwardHandler(xmlSource); parser.setProperty("http://xml.org/sax/properties/lexical-handler", lexicalHandler); parser.setFeature("http://xml.org/sax/features/lexical-handler", true); } catch (final SAXNotRecognizedException e) { } // in = new InputSource(src.toString()); out = new StreamResult(new FileOutputStream(outputFile)); serializer.setResult(out); xmlSource.setContentHandler(serializer); xmlSource.parse(src.toString()); if (listFilter.isValidInput()) { processParseResult(currentFile); categorizeCurrentFile(ref); } else if (!currentFile.equals(rootFile)) { logger.warn(MessageUtils.getMessage("DOTJ021W", params).toString()); failureList.add(currentFile); } } catch (final RuntimeException e) { throw e; } catch (final SAXParseException sax) { final Exception inner = sax.getException(); if (inner != null && inner instanceof DITAOTException) { throw (DITAOTException) inner; } if (currentFile.equals(rootFile)) { throw new DITAOTException( MessageUtils.getMessage("DOTJ012F", params).toString() + ": " + sax.getMessage(), sax); } else if (processingMode == Mode.STRICT) { throw new DITAOTException( MessageUtils.getMessage("DOTJ013E", params).toString() + ": " + sax.getMessage(), sax); } else { logger.error(MessageUtils.getMessage("DOTJ013E", params).toString() + ": " + sax.getMessage(), sax); } failureList.add(currentFile); } catch (final FileNotFoundException e) { if (!exists(currentFile)) { if (currentFile.equals(rootFile)) { throw new DITAOTException(MessageUtils.getMessage("DOTA069F", params).toString(), e); } else if (processingMode == Mode.STRICT) { throw new DITAOTException(MessageUtils.getMessage("DOTX008E", params).toString(), e); } else { logger.error(MessageUtils.getMessage("DOTX008E", params).toString()); } } else if (currentFile.equals(rootFile)) { throw new DITAOTException(MessageUtils.getMessage("DOTJ078F", params).toString() + " Cannot load file: " + e.getMessage(), e); } else if (processingMode == Mode.STRICT) { throw new DITAOTException(MessageUtils.getMessage("DOTJ079E", params).toString() + " Cannot load file: " + e.getMessage(), e); } else { logger.error(MessageUtils.getMessage("DOTJ079E", params).toString() + " Cannot load file: " + e.getMessage()); } failureList.add(currentFile); } catch (final Exception e) { if (currentFile.equals(rootFile)) { throw new DITAOTException( MessageUtils.getMessage("DOTJ012F", params).toString() + ": " + e.getMessage(), e); } else if (processingMode == Mode.STRICT) { throw new DITAOTException( MessageUtils.getMessage("DOTJ013E", params).toString() + ": " + e.getMessage(), e); } else { logger.error(MessageUtils.getMessage("DOTJ013E", params).toString() + ": " + e.getMessage(), e); } failureList.add(currentFile); } finally { if (out != null) { try { close(out); } catch (final IOException e) { logger.error(e.getMessage(), e); } } if (failureList.contains(currentFile)) { FileUtils.deleteQuietly(outputFile); } } if (!listFilter.isValidInput() && currentFile.equals(rootFile)) { if (validate) { // stop the build if all content in the input file was filtered out. throw new DITAOTException(MessageUtils.getMessage("DOTJ022F", params).toString()); } else { // stop the build if the content of the file is not valid. throw new DITAOTException(MessageUtils.getMessage("DOTJ034F", params).toString()); } } doneList.add(currentFile); listFilter.reset(); keydefFilter.reset(); }
From source file:org.exist.util.XMLReaderObjectFactory.java
private static void setReaderFeature(XMLReader xmlReader, String featureName, boolean value) { try {/*w ww . j a va2 s . c o m*/ xmlReader.setFeature(featureName, value); } catch (final SAXNotRecognizedException ex) { LOG.error("SAXNotRecognizedException: " + ex.getMessage()); } catch (final SAXNotSupportedException ex) { LOG.error("SAXNotSupportedException:" + ex.getMessage()); } }
From source file:org.exist.util.XMLReaderObjectFactory.java
private static void setReaderProperty(XMLReader xmlReader, String propertyName, Object object) { try {/*from w w w. j a v a 2s .co m*/ xmlReader.setProperty(propertyName, object); } catch (final SAXNotRecognizedException ex) { LOG.error("SAXNotRecognizedException: " + ex.getMessage()); } catch (final SAXNotSupportedException ex) { LOG.error("SAXNotSupportedException:" + ex.getMessage()); } }
From source file:org.exist.util.XMLReaderPool.java
private Object getReaderProperty(XMLReader xmlReader, String propertyName) { Object object = null;/* w ww .ja va2 s .com*/ try { object = xmlReader.getProperty(propertyName); } catch (final SAXNotRecognizedException ex) { LOG.error("SAXNotRecognizedException: " + ex.getMessage()); } catch (final SAXNotSupportedException ex) { LOG.error("SAXNotSupportedException:" + ex.getMessage()); } return object; }