/** * Configures a Digester * * @return Digester */ private Digester getDigester() { final SaxErrorHandler errorHandler = new SaxErrorHandler(); final Digester digester = new Digester(); digester.setErrorHandler(errorHandler); digester.setValidating(true); digester.setEntityResolver(new DtdEntityResolver()); return digester; }
/** * Process a single <code>faces-config.xml</code> file and add all beans found to the supplied * list of {@link FacesConfigEntry} objects. * * @param url The faces-config.xml file * @param facesConfigEntries list of entries to add the beans to */ private void processFacesConfig(URL url, List<FacesConfigEntry> facesConfigEntries) { // log name of current file if (log.isTraceEnabled()) { log.trace("Loading bean names from: " + url.toString()); } // setup digester Digester digester = new Digester(); /* * We use the context class loader to resolve classes. * This fixes ClassNotFoundExceptions on Geronimo. */ digester.setUseContextClassLoader(true); // prevent downloading of DTDs digester.setEntityResolver(new EmptyEntityResolver()); digester.setValidating(false); digester.push(facesConfigEntries); digester.addObjectCreate("faces-config/managed-bean", FacesConfigEntry.class); digester.addCallMethod("faces-config/managed-bean/managed-bean-name", "setName", 0); digester.addCallMethod("faces-config/managed-bean/managed-bean-class", "setBeanClass", 0); digester.addSetNext("faces-config/managed-bean", "add"); // stream used to read faces-config.xml file InputStream stream = null; try { // open the file and let digester pares it stream = url.openStream(); digester.parse(stream); } catch (IOException e) { // may be thrown when reading the file log.error("Failed to parse: " + url.toString(), e); } catch (SAXException e) { // parsing errors log.error("Failed to parse: " + url.toString(), e); } finally { // close stream if (stream != null) { try { stream.close(); } catch (IOException e) { // ignore IOExceptions on close } } } }
/** * Initializes the digester. * * @param useContextClassLoader whether or not to use the context class loader. * @param validating whether or not to validate XML. * @param validatingSchema whether or not to validate XML schema. */ protected void initDigester( boolean useContextClassLoader, boolean validating, boolean validatingSchema) { digester = new Digester(); digester.setNamespaceAware(true); digester.setUseContextClassLoader(useContextClassLoader); digester.setValidating(validating); initSchemaValidation(validatingSchema); digester.setEntityResolver(this); digester.setErrorHandler(this); if (addCustomDigesterRules(digester)) { addDefaultDigesterRules(digester); } }
/** * Configures the provided <code>Digester</code> instance appropriate for use with JSF. * * @param digester - the <code>Digester</code> instance to configure */ private void configureDigester(Digester digester) { digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); digester.setEntityResolver(RESOLVER); digester.setErrorHandler(ERROR_HANDLER); // disable digester log messages digester.setLogger(new NoOpLog()); if (validating) { if (logger.isLoggable(Level.FINE)) { logger.log( Level.FINE, "Attempting to configure Digester to perform" + " document validation."); } // In order to validate using *both* DTD and Schema, certain // Xerces specific features are required. Try to set these // features. If an exception is thrown trying to set these // features, then disable validation. try { digester.setFeature(XERCES_VALIDATION, true); digester.setFeature(XERCES_SCHEMA_VALIDATION, true); digester.setFeature(XERCES_SCHEMA_CONSTRAINT_VALIDATION, true); digester.setValidating(true); } catch (SAXNotSupportedException e) { if (logger.isLoggable(Level.WARNING)) { logger.log( Level.WARNING, "Attempt to set supported feature on XMLReader, " + "but the value provided was not accepted. " + "Validation will be disabledb."); } digester.setValidating(false); } catch (SAXNotRecognizedException e) { if (logger.isLoggable(Level.WARNING)) { logger.log( Level.WARNING, "Attempt to set unsupported feature on XMLReader" + " necessary for validation. Validation will be" + "disabled."); } digester.setValidating(false); } catch (ParserConfigurationException e) { if (logger.isLoggable(Level.WARNING)) { logger.log( Level.WARNING, "Digester unable to configure underlying parser." + " Validation will be disabled."); } digester.setValidating(false); } } else { digester.setValidating(false); } } // END configureDigester