protected void configureDigester(Digester digester)
      throws SAXException, ParserConfigurationException {
    boolean validating = JRProperties.getBooleanProperty(JRProperties.COMPILER_XML_VALIDATION);

    digester.setErrorHandler(this);
    digester.setValidating(validating);
    digester.setFeature("http://xml.org/sax/features/validation", validating);

    digester.addRuleSet(rules);
  }
Пример #2
0
  /**
   * 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