Package javax.xml.validation

Examples of javax.xml.validation.Validator


     * @param xml The XML to validate.
     * @return true if valid, false otherwise.
     */
    public static boolean validate(final Schema schema, final String xml)
    {
        final Validator validator = schema.newValidator() ;
        try
        {
            validator.validate(new StreamSource(new StringReader(xml))) ;
            return true ;
        }
        catch (final IOException ioe)
        {
            log.debug(ioe.getMessage(), ioe);
View Full Code Here


            }
        }

        // no need to synchronize, schema instances are thread-safe
        try {
            Validator validator = cachedSchema.newValidator();
            validator.setErrorHandler(errorHandler);

            // perform actual validation
            validator.validate(validateSrc);

            if (errorHandler.isValidationError()) {

                if (synLog.isTraceOrDebugEnabled()) {
                    String msg = "Validation of element returned by XPath : " + source +
View Full Code Here

            throw new JBIException("Failed to load schema: " + e, e);
        }
    }

    protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
        Validator validator = schema.newValidator();

        CountingErrorHandler errorHandler = new CountingErrorHandler();
        validator.setErrorHandler(errorHandler);
        DOMResult result = new DOMResult();
        // Transform first so that the input source will be parsed only once
        // if it is a StreamSource
        getMessageTransformer().transform(exchange, in, out);
        try {
          // Only DOMSource and SAXSource are allowed for validating
          // See http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
          // As we expect a DOMResult as output, we must ensure that the input is a
          // DOMSource
          Source src = new SourceTransformer().toDOMSource(out.getContent());
            validator.validate(src, result);
            if (errorHandler.hasErrors()) {
                Fault fault = exchange.createFault();
                fault.setProperty("org.servicemix.schema", schema);
                fault.setContent(new DOMSource(result.getNode(), result.getSystemId()));
                throw new FaultException("Failed to validate against schema: " + schema, exchange, fault);
View Full Code Here

                    schema = factory.newSchema(src);
                } catch (final SAXException ex) {
                    LOGGER.error("Error parsing Log4j schema", ex);
                }
                if (schema != null) {
                    final Validator validator = schema.newValidator();
                    try {
                        validator.validate(new StreamSource(new ByteArrayInputStream(buffer)));
                    } catch (final IOException ioe) {
                        LOGGER.error("Error reading configuration for validation", ioe);
                    } catch (final SAXException ex) {
                        LOGGER.error("Error validating configuration", ex);
                    }
View Full Code Here

        || m_eMode == OdfValidatorMode.EXTENDED_CONFORMANCE) {
      XMLFilter aAlienFilter = new ForeignContentFilter(aLogger, aVersion, m_aResult);
      aAlienFilter.setParent(aFilter);
      aFilter = aAlienFilter;
    }
    Validator aValidator = null;
    if (m_eMode == OdfValidatorMode.VALIDATE_STRICT) {
      aValidator = m_aValidatorProvider.getStrictValidator(aParentLogger.getOutputStream(), aVersion);
    } else {
      aValidator = m_aValidatorProvider.getValidator(aParentLogger.getOutputStream(), aVersion);
    }
View Full Code Here

      XMLFilter aAlienFilter = new ForeignContentFilter(aLogger, aVersion, m_aResult);
      aAlienFilter.setParent(aFilter);
      aFilter = aAlienFilter;
    }

    Validator aValidator = null;
    if (m_eMode == OdfValidatorMode.VALIDATE_STRICT) {
      aValidator = m_aValidatorProvider.getStrictValidator(aParentLogger.getOutputStream(), aVersion);
    } else {
      aValidator = m_aValidatorProvider.getValidator(aParentLogger.getOutputStream(), aVersion);
    }
View Full Code Here

    String aMathMLDTDSystemId = m_aValidatorProvider.getMathMLDTDSystemId(aVersion);
    if (aMathMLDTDSystemId != null) {
      // validate using DTD
      return parseEntry(new MathML101Filter(aMathMLDTDSystemId, aLogger), aLogger, aEntryName, true);
    } else {
      Validator aMathMLValidator = m_aValidatorProvider.getMathMLValidator(aParentLogger.getOutputStream(), null);
      if (aMathMLValidator == null) {
        aLogger.logInfo("MathML schema is not available. Validation has been skipped.", false);
        return false;
      }
      return validateEntry(new MathML20Filter(aLogger), aMathMLValidator, aLogger, aEntryName);
View Full Code Here

      return validateEntry(new MathML20Filter(aLogger), aMathMLValidator, aLogger, aEntryName);
    }
  }

  protected boolean validateDSig(Logger aParentLogger, String aEntryName, OdfVersion aVersion) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
    Validator aValidator = m_aValidatorProvider.getDSigValidator(aParentLogger.getOutputStream(), aVersion);
    Logger aLogger = new Logger(aEntryName, aParentLogger);
    if (aValidator == null) {
      aLogger.logWarning("Signature not validated because there is no Signature Validator configured for the selected Configuration");
      return false;
    }
View Full Code Here

    public ExtendedElement addDefaults() {
        try {
            SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            URL schemaLocation = ClassLoader.getSystemClassLoader().getResource("testdefinition.xsd");
            Schema schema = factory.newSchema(schemaLocation);
            Validator validator = schema.newValidator();

            DOMSource source = new DOMSource(m_element);
            DOMResult result = new DOMResult();

            validator.validate(source, result);
            m_element = ((Document) result.getNode()).getDocumentElement();
        } catch (Exception exc) {
            System.err.println(exc);
            exc.printStackTrace();
        }
View Full Code Here

     * @param validationErrors
     * @throws IOException
     * @throws SAXException
     */
    protected void checkValidationErrors(Document dom, Schema schema) throws SAXException, IOException {
        final Validator validator = schema.newValidator();
        final List<Exception> validationErrors = new ArrayList<Exception>();
        validator.setErrorHandler(new ErrorHandler() {
           
            public void warning(SAXParseException exception) throws SAXException {
                System.out.println(exception.getMessage());
            }

            public void fatalError(SAXParseException exception) throws SAXException {
                validationErrors.add(exception);
            }

            public void error(SAXParseException exception) throws SAXException {
                validationErrors.add(exception);
            }

          });
        validator.validate(new DOMSource(dom));
        if (validationErrors != null && validationErrors.size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (Exception ve : validationErrors) {
                sb.append(ve.getMessage()).append("\n");
            }
View Full Code Here

TOP

Related Classes of javax.xml.validation.Validator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.