示例#1
0
  /**
   * parse
   *
   * @param inputSource
   * @exception XNIException
   * @exception java.io.IOException
   */
  public void parse(XMLInputSource inputSource) throws XNIException, IOException {
    // null indicates that the parser is called directly, initialize them
    if (securityManager == null) {
      securityManager = new XMLSecurityManager(true);
      fConfiguration.setProperty(Constants.SECURITY_MANAGER, securityManager);
    }
    if (securityPropertyManager == null) {
      securityPropertyManager = new XMLSecurityPropertyManager();
      fConfiguration.setProperty(Constants.XML_SECURITY_PROPERTY_MANAGER, securityPropertyManager);
    }

    reset();
    fConfiguration.parse(inputSource);
  } // parse(XMLInputSource)
示例#2
0
 public void startDocument(
     XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs)
     throws XNIException {
   fErrorReporter = (XMLErrorReporter) config.getProperty(ERROR_REPORTER);
   fGenerateSyntheticAnnotation = config.getFeature(GENERATE_SYNTHETIC_ANNOTATION);
   fHasNonSchemaAttributes.clear();
   fSawAnnotation.clear();
   schemaDOM = new SchemaDOM();
   fAnnotationDepth = -1;
   fInnerAnnotationDepth = -1;
   fDepth = -1;
   fLocator = locator;
   fNamespaceContext = namespaceContext;
   schemaDOM.setDocumentURI(locator.getExpandedSystemId());
 } // startDocument(XMLLocator,String,NamespaceContext, Augmentations)
示例#3
0
  /** Default Constructor. */
  protected XMLParser(XMLParserConfiguration config) {

    // save configuration
    fConfiguration = config;

    // add default recognized properties
    fConfiguration.addRecognizedProperties(RECOGNIZED_PROPERTIES);
  } // <init>(XMLParserConfiguration)
  /**
   * Create a SAX parser with the associated features
   *
   * @param features Hashtable of SAX features, may be null
   */
  SAXParserImpl(SAXParserFactoryImpl spf, Hashtable features, boolean secureProcessing)
      throws SAXException {
    fSecurityManager = new XMLSecurityManager(secureProcessing);
    fSecurityPropertyMgr = new XMLSecurityPropertyManager();
    // Instantiate a SAXParser directly and not through SAX so that we use the right ClassLoader
    xmlReader = new JAXPSAXParser(this, fSecurityPropertyMgr, fSecurityManager);

    // JAXP "namespaceAware" == SAX Namespaces feature
    // Note: there is a compatibility problem here with default values:
    // JAXP default is false while SAX 2 default is true!
    xmlReader.setFeature0(NAMESPACES_FEATURE, spf.isNamespaceAware());

    // SAX "namespaces" and "namespace-prefixes" features should not
    // both be false.  We make them opposite for backward compatibility
    // since JAXP 1.0 apps may want to receive xmlns* attributes.
    xmlReader.setFeature0(NAMESPACE_PREFIXES_FEATURE, !spf.isNamespaceAware());

    // Avoid setting the XInclude processing feature if the value is false.
    // This will keep the configuration from throwing an exception if it
    // does not support XInclude.
    if (spf.isXIncludeAware()) {
      xmlReader.setFeature0(XINCLUDE_FEATURE, true);
    }

    xmlReader.setProperty0(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);

    xmlReader.setProperty0(SECURITY_MANAGER, fSecurityManager);

    if (secureProcessing) {
      /**
       * By default, secure processing is set, no external access is allowed. However, we need to
       * check if it is actively set on the factory since we allow the use of the System Property or
       * jaxp.properties to override the default value
       */
      if (features != null) {

        Object temp = features.get(XMLConstants.FEATURE_SECURE_PROCESSING);
        if (temp != null) {
          boolean value = ((Boolean) temp).booleanValue();
          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);
          }
        }
      }
    }

    // Set application's features, followed by validation features.
    setFeatures(features);

    // If validating, provide a default ErrorHandler that prints
    // validation errors with a warning telling the user to set an
    // ErrorHandler.
    if (spf.isValidating()) {
      fInitErrorHandler = new DefaultValidationErrorHandler(xmlReader.getLocale());
      xmlReader.setErrorHandler(fInitErrorHandler);
    } else {
      fInitErrorHandler = xmlReader.getErrorHandler();
    }
    xmlReader.setFeature0(VALIDATION_FEATURE, spf.isValidating());

    // Get the Schema object from the factory
    this.grammar = spf.getSchema();
    if (grammar != null) {
      XMLParserConfiguration config = xmlReader.getXMLParserConfiguration();
      XMLComponent validatorComponent = null;
      /** For Xerces grammars, use built-in schema validator. * */
      if (grammar instanceof XSGrammarPoolContainer) {
        validatorComponent = new XMLSchemaValidator();
        fSchemaValidationManager = new ValidationManager();
        fUnparsedEntityHandler = new UnparsedEntityHandler(fSchemaValidationManager);
        config.setDTDHandler(fUnparsedEntityHandler);
        fUnparsedEntityHandler.setDTDHandler(xmlReader);
        xmlReader.setDTDSource(fUnparsedEntityHandler);
        fSchemaValidatorComponentManager =
            new SchemaValidatorConfiguration(
                config, (XSGrammarPoolContainer) grammar, fSchemaValidationManager);
      }
      /** For third party grammars, use the JAXP validator component. * */
      else {
        validatorComponent = new JAXPValidatorComponent(grammar.newValidatorHandler());
        fSchemaValidationManager = null;
        fUnparsedEntityHandler = null;
        fSchemaValidatorComponentManager = config;
      }
      config.addRecognizedFeatures(validatorComponent.getRecognizedFeatures());
      config.addRecognizedProperties(validatorComponent.getRecognizedProperties());
      config.setDocumentHandler((XMLDocumentHandler) validatorComponent);
      ((XMLDocumentSource) validatorComponent).setDocumentHandler(xmlReader);
      xmlReader.setDocumentSource((XMLDocumentSource) validatorComponent);
      fSchemaValidator = validatorComponent;
    } else {
      fSchemaValidationManager = null;
      fUnparsedEntityHandler = null;
      fSchemaValidatorComponentManager = null;
      fSchemaValidator = null;
    }

    // Initial EntityResolver
    fInitEntityResolver = xmlReader.getEntityResolver();
  }
示例#5
0
 /** Default constructor. */
 public SchemaDOMParser(XMLParserConfiguration config) {
   this.config = config;
   config.setDocumentHandler(this);
   config.setDTDHandler(this);
   config.setDTDContentModelHandler(this);
 }
示例#6
0
 /**
  * Delegates parsing to SchemaParsingConfig
  *
  * @param inputSource
  * @throws IOException
  */
 public void parse(XMLInputSource inputSource) throws IOException {
   config.parse(inputSource);
 }
示例#7
0
 /**
  * Delegates to SchemaParsingConfig.setEntityResolver.
  *
  * @param er XMLEntityResolver
  */
 public void setEntityResolver(XMLEntityResolver er) {
   config.setEntityResolver(er);
 }
示例#8
0
 /**
  * Delegates to SchemaParsingConfig.getProperty.
  *
  * @param propertyId
  * @return Object
  */
 public Object getProperty(String propertyId) {
   return config.getProperty(propertyId);
 }
示例#9
0
 /**
  * Delegates to SchemaParsingConfig.setProperty.
  *
  * @param propertyId
  * @param value
  */
 public void setProperty(String propertyId, Object value) {
   config.setProperty(propertyId, value);
 }
示例#10
0
 /**
  * Delegates to SchemaParsingConfig.getFeature
  *
  * @param featureId
  * @return boolean
  */
 public boolean getFeature(String featureId) {
   return config.getFeature(featureId);
 }
示例#11
0
 /**
  * Delegates to SchemaParsingConfig.setFeature
  *
  * @param featureId
  * @param state
  */
 public void setFeature(String featureId, boolean state) {
   config.setFeature(featureId, state);
 }
示例#12
0
 /** Query the state of a feature. */
 public boolean getFeature(String featureId)
     throws SAXNotSupportedException, SAXNotRecognizedException {
   return fConfiguration.getFeature(featureId);
 }