public ValidatorHandlerImpl(XSGrammarPoolContainer grammarContainer) {
   this(new XMLSchemaValidatorComponentManager(grammarContainer));
   fComponentManager.addRecognizedFeatures(new String[] {NAMESPACE_PREFIXES});
   fComponentManager.setFeature(NAMESPACE_PREFIXES, false);
   setErrorHandler(null);
   setResourceResolver(null);
 }
 public ValidatorHandlerImpl(XMLSchemaValidatorComponentManager componentManager) {
   fComponentManager = componentManager;
   fErrorReporter = (XMLErrorReporter) fComponentManager.getProperty(ERROR_REPORTER);
   fNamespaceContext = (NamespaceContext) fComponentManager.getProperty(NAMESPACE_CONTEXT);
   fSchemaValidator = (XMLSchemaValidator) fComponentManager.getProperty(SCHEMA_VALIDATOR);
   fSymbolTable = (SymbolTable) fComponentManager.getProperty(SYMBOL_TABLE);
   fValidationManager = (ValidationManager) fComponentManager.getProperty(VALIDATION_MANAGER);
 }
 public void setProperty(String name, Object object)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException();
   }
   try {
     fComponentManager.setProperty(name, object);
   } catch (XMLConfigurationException e) {
     final String identifier = e.getIdentifier();
     final String key =
         e.getType() == XMLConfigurationException.NOT_RECOGNIZED
             ? "property-not-recognized"
             : "property-not-supported";
     throw new SAXNotRecognizedException(
         SAXMessageFormatter.formatMessage(Locale.getDefault(), key, new Object[] {identifier}));
   }
 }
 public boolean getFeature(String name)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException();
   }
   try {
     return fComponentManager.getFeature(name);
   } catch (XMLConfigurationException e) {
     final String identifier = e.getIdentifier();
     final String key =
         e.getType() == XMLConfigurationException.NOT_RECOGNIZED
             ? "feature-not-recognized"
             : "feature-not-supported";
     throw new SAXNotRecognizedException(
         SAXMessageFormatter.formatMessage(Locale.getDefault(), key, new Object[] {identifier}));
   }
 }
  public void validate(Source source, Result result) throws SAXException, IOException {

    if (result == null || result instanceof StAXResult) {

      if (identityTransformer1 == null) {
        try {
          SAXTransformerFactory tf =
              fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM)
                  ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
                  : (SAXTransformerFactory)
                      TransformerFactory.newInstance(
                          DEFAULT_TRANSFORMER_IMPL, StAXValidatorHelper.class.getClassLoader());
          identityTransformer1 = tf.newTransformer();
          identityTransformer2 = tf.newTransformerHandler();
        } catch (TransformerConfigurationException e) {
          // this is impossible, but again better safe than sorry
          throw new TransformerFactoryConfigurationError(e);
        }
      }

      handler = new ValidatorHandlerImpl(fComponentManager);
      if (result != null) {
        handler.setContentHandler(identityTransformer2);
        identityTransformer2.setResult(result);
      }

      try {
        identityTransformer1.transform(source, new SAXResult(handler));
      } catch (TransformerException e) {
        if (e.getException() instanceof SAXException) throw (SAXException) e.getException();
        throw new SAXException(e);
      } finally {
        handler.setContentHandler(null);
      }
      return;
    }
    throw new IllegalArgumentException(
        JAXPValidationMessageFormatter.formatMessage(
            Locale.getDefault(),
            "SourceResultMismatch",
            new Object[] {source.getClass().getName(), result.getClass().getName()}));
  }
 public void startDocument() throws SAXException {
   fComponentManager.reset();
   fSchemaValidator.setDocumentHandler(this);
   fValidationManager.setEntityState(this);
   fTypeInfoProvider.finishStartElement(); // cleans up TypeInfoProvider
   fNeedPushNSContext = true;
   if (fUnparsedEntities != null && !fUnparsedEntities.isEmpty()) {
     // should only clear this if the last document contained unparsed entities
     fUnparsedEntities.clear();
   }
   fErrorReporter.setDocumentLocator(fSAXLocatorWrapper);
   try {
     fSchemaValidator.startDocument(
         fSAXLocatorWrapper, fSAXLocatorWrapper.getEncoding(), fNamespaceContext, null);
   } catch (XMLParseException e) {
     throw Util.toSAXParseException(e);
   } catch (XNIException e) {
     throw Util.toSAXException(e);
   }
 }
  public void validate(Source source, Result result) throws SAXException, IOException {
    if (result instanceof SAXResult || result == null) {
      final SAXSource saxSource = (SAXSource) source;
      final SAXResult saxResult = (SAXResult) result;

      if (result != null) {
        setContentHandler(saxResult.getHandler());
      }

      try {
        XMLReader reader = saxSource.getXMLReader();
        if (reader == null) {
          // create one now
          SAXParserFactory spf = SAXParserFactory.newInstance();
          spf.setNamespaceAware(true);
          try {
            reader = spf.newSAXParser().getXMLReader();
            // If this is a Xerces SAX parser, set the security manager if there is one
            if (reader instanceof com.sun.org.apache.xerces.internal.parsers.SAXParser) {
              SecurityManager securityManager =
                  (SecurityManager) fComponentManager.getProperty(SECURITY_MANAGER);
              if (securityManager != null) {
                try {
                  reader.setProperty(SECURITY_MANAGER, securityManager);
                }
                // Ignore the exception if the security manager cannot be set.
                catch (SAXException exc) {
                }
              }
            }
          } catch (Exception e) {
            // this is impossible, but better safe than sorry
            throw new FactoryConfigurationError(e);
          }
        }

        // If XML names and Namespace URIs are already internalized we
        // can avoid running them through the SymbolTable.
        try {
          fStringsInternalized = reader.getFeature(STRING_INTERNING);
        } catch (SAXException exc) {
          // The feature isn't recognized or getting it is not supported.
          // In either case, assume that strings are not internalized.
          fStringsInternalized = false;
        }

        ErrorHandler errorHandler = fComponentManager.getErrorHandler();
        reader.setErrorHandler(
            errorHandler != null ? errorHandler : DraconianErrorHandler.getInstance());
        reader.setEntityResolver(fResolutionForwarder);
        fResolutionForwarder.setEntityResolver(fComponentManager.getResourceResolver());
        reader.setContentHandler(this);
        reader.setDTDHandler(this);

        InputSource is = saxSource.getInputSource();
        reader.parse(is);
      } finally {
        // release the reference to user's handler ASAP
        setContentHandler(null);
      }
      return;
    }
    throw new IllegalArgumentException(
        JAXPValidationMessageFormatter.formatMessage(
            Locale.getDefault(),
            "SourceResultMismatch",
            new Object[] {source.getClass().getName(), result.getClass().getName()}));
  }
 public LSResourceResolver getResourceResolver() {
   return fComponentManager.getResourceResolver();
 }
 public void setResourceResolver(LSResourceResolver resourceResolver) {
   fComponentManager.setResourceResolver(resourceResolver);
 }
Example #10
0
 public ErrorHandler getErrorHandler() {
   return fComponentManager.getErrorHandler();
 }
Example #11
0
 public void setErrorHandler(ErrorHandler errorHandler) {
   fComponentManager.setErrorHandler(errorHandler);
 }