コード例 #1
0
 /**
  * Override SAXParser's setFeature method to track the initial state of features. This keeps us
  * from affecting the performance of the SAXParser when it is created with XMLReaderFactory.
  */
 public synchronized void setFeature(String name, boolean value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     // TODO: Add localized error message.
     throw new NullPointerException();
   }
   if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
     try {
       fSecurityManager.setSecureProcessing(value);
       setProperty(SECURITY_MANAGER, fSecurityManager);
     } catch (SAXNotRecognizedException exc) {
       // If the property is not supported
       // re-throw the exception if the value is true.
       if (value) {
         throw exc;
       }
     } catch (SAXNotSupportedException exc) {
       // If the property is not supported
       // re-throw the exception if the value is true.
       if (value) {
         throw exc;
       }
     }
     return;
   }
   if (!fInitFeatures.containsKey(name)) {
     boolean current = super.getFeature(name);
     fInitFeatures.put(name, current ? Boolean.TRUE : Boolean.FALSE);
   }
   /** Forward feature to the schema validator if there is one. * */
   if (fSAXParser != null && fSAXParser.fSchemaValidator != null) {
     setSchemaValidatorFeature(name, value);
   }
   super.setFeature(name, value);
 }
コード例 #2
0
  /** Constructs a component manager suitable for Xerces' schema validator. */
  public XMLSchemaValidatorComponentManager(XSGrammarPoolContainer grammarContainer) {
    // setup components
    fEntityManager = new XMLEntityManager();
    fComponents.put(ENTITY_MANAGER, fEntityManager);

    fErrorReporter = new XMLErrorReporter();
    fComponents.put(ERROR_REPORTER, fErrorReporter);

    fNamespaceContext = new NamespaceSupport();
    fComponents.put(NAMESPACE_CONTEXT, fNamespaceContext);

    fSchemaValidator = new XMLSchemaValidator();
    fComponents.put(SCHEMA_VALIDATOR, fSchemaValidator);

    fValidationManager = new ValidationManager();
    fComponents.put(VALIDATION_MANAGER, fValidationManager);

    // setup other properties
    fComponents.put(ENTITY_RESOLVER, null);
    fComponents.put(ERROR_HANDLER, null);

    fComponents.put(SYMBOL_TABLE, new SymbolTable());

    // setup grammar pool
    fComponents.put(XMLGRAMMAR_POOL, grammarContainer.getGrammarPool());
    fUseGrammarPoolOnly = grammarContainer.isFullyComposed();

    // add schema message formatter to error reporter
    fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());

    // add all recognized features and properties and apply their defaults
    addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer);
    addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer);
    addRecognizedParamsAndSetDefaults(fSchemaValidator, grammarContainer);

    boolean secureProcessing = grammarContainer.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
    if (System.getSecurityManager() != null) {
      _isSecureMode = true;
      secureProcessing = true;
    }

    fInitSecurityManager = (XMLSecurityManager) grammarContainer.getProperty(SECURITY_MANAGER);
    if (fInitSecurityManager != null) {
      fInitSecurityManager.setSecureProcessing(secureProcessing);
    } else {
      fInitSecurityManager = new XMLSecurityManager(secureProcessing);
    }

    setProperty(SECURITY_MANAGER, fInitSecurityManager);

    // pass on properties set on SchemaFactory
    fSecurityPropertyMgr =
        (XMLSecurityPropertyManager)
            grammarContainer.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER);
    setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
  }
コード例 #3
0
  /**
   * Set the state of a feature.
   *
   * @param featureId The unique identifier (URI) of the feature.
   * @param state The requested state of the feature (true or false).
   * @exception XMLConfigurationException If the requested feature is not known.
   */
  public void setFeature(String featureId, boolean value) throws XMLConfigurationException {
    if (PARSER_SETTINGS.equals(featureId)) {
      throw new XMLConfigurationException(Status.NOT_SUPPORTED, featureId);
    } else if (value == false
        && (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId))) {
      throw new XMLConfigurationException(Status.NOT_SUPPORTED, featureId);
    } else if (USE_GRAMMAR_POOL_ONLY.equals(featureId) && value != fUseGrammarPoolOnly) {
      throw new XMLConfigurationException(Status.NOT_SUPPORTED, featureId);
    }
    if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(featureId)) {
      if (_isSecureMode && !value) {
        throw new XMLConfigurationException(
            Status.NOT_ALLOWED, XMLConstants.FEATURE_SECURE_PROCESSING);
      }
      fInitSecurityManager.setSecureProcessing(value);
      setProperty(SECURITY_MANAGER, fInitSecurityManager);

      if (value && Constants.IS_JDK8_OR_ABOVE) {
        fSecurityPropertyMgr.setValue(
            XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD,
            XMLSecurityPropertyManager.State.FSP,
            Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
        fSecurityPropertyMgr.setValue(
            XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA,
            XMLSecurityPropertyManager.State.FSP,
            Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
        setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
      }

      return;
    }
    fConfigUpdated = true;
    fEntityManager.setFeature(featureId, value);
    fErrorReporter.setFeature(featureId, value);
    fSchemaValidator.setFeature(featureId, value);
    if (!fInitFeatures.containsKey(featureId)) {
      boolean current = super.getFeature(featureId);
      fInitFeatures.put(featureId, current ? Boolean.TRUE : Boolean.FALSE);
    }
    super.setFeature(featureId, value);
  }