private static Digester initDigester()
      throws SAXNotRecognizedException, SAXNotSupportedException {
    Digester digester = new Digester();
    digester.setValidating(true);
    digester.setErrorHandler(
        new ErrorHandler() {
          @Override
          public void warning(SAXParseException exception) throws SAXException {
            throw new SAXException(
                "XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
          }

          @Override
          public void error(SAXParseException exception) throws SAXException {
            throw new SAXException(
                "XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
          }

          @Override
          public void fatalError(SAXParseException exception) throws SAXException {
            throw new SAXException(
                "XML Schema validation of Plugin Descriptor(plugin.xml) failed", exception);
          }
        });
    digester.setProperty(
        "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
        XMLConstants.W3C_XML_SCHEMA_NS_URI);
    digester.setProperty(
        "http://java.sun.com/xml/jaxp/properties/schemaSource",
        GoPluginDescriptorParser.class.getResourceAsStream("/plugin-descriptor.xsd"));
    return digester;
  }
  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);
  }
  /**
   * 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;
  }
  /**
   * 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);
    }
  }
Exemplo n.º 5
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