Package javax.xml.validation

Examples of javax.xml.validation.Validator


            InputStream is = XMLConfiguration.class.getResourceAsStream("geowebcache.xsd");

            // Parsing the schema file
            try {
                Schema schema = factory.newSchema(new StreamSource(is));
                Validator validator = schema.newValidator();

                // debugPrint(rootNode);

                DOMSource domSrc = new DOMSource(rootNode);
                validator.validate(domSrc);
                log.info("Configuration file validated fine.");
            } catch (SAXException e) {
                log.info(e.getMessage());
                log.info("Will try to use configuration anyway.");
            } catch (IOException e) {
View Full Code Here


        }
       
        schemaFactory.setResourceResolver(JAVAEE_5_LS_RESOURCE_RESOLVER);
        Schema schema = schemaFactory.newSchema(schemaFile);

        Validator validator = schema.newValidator();
        URLConnection conn = xmlFile.openConnection();
        conn.setUseCaches(false);
        InputStream is = conn.getInputStream();
        Source source = new StreamSource(is);
        validator.setErrorHandler(VALIDATION_ERROR_HANDLER);
        validator.validate(source);
    }
View Full Code Here

            throw new IOException("Could not find schema file for validation.");
        }
        schemaFactory.setResourceResolver(ConfigFilesXmlValidationUtils.JAVAEE_5_LS_RESOURCE_RESOLVER);
        Schema schema = schemaFactory.newSchema(schemaFile);
   
        Validator validator = schema.newValidator();
        URLConnection conn = xmlFile.openConnection();
        conn.setUseCaches(false);
        InputStream is = conn.getInputStream();
        Source source = new StreamSource(is);
        validator.setErrorHandler(VALIDATION_ERROR_HANDLER);
        validator.validate(source);
    }
View Full Code Here

    public static Descriptor buildDescriptor(final byte[] bytes) {
        try {
            // Validate descriptor
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XSD_SCHEMA_LANGUAGE);
            Schema schema = schemaFactory.newSchema(DescriptorFactory.class.getResource(JBI_DESCRIPTOR_XSD));
            Validator validator = schema.newValidator();
            validator.setErrorHandler(new ErrorHandler() {
                public void warning(SAXParseException exception) throws SAXException {
                    //log.debug("Validation warning on " + url + ": " + exception);
                }

                public void error(SAXParseException exception) throws SAXException {
                    //log.info("Validation error on " + url + ": " + exception);
                }

                public void fatalError(SAXParseException exception) throws SAXException {
                    throw exception;
                }
            });
            validator.validate(new StreamSource(new ByteArrayInputStream(bytes)));
            // Parse descriptor
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder docBuilder = factory.newDocumentBuilder();
            Document doc = docBuilder.parse(new ByteArrayInputStream(bytes));
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();

        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 {
View Full Code Here

            String language = "http://www.w3.org/2001/XMLSchema";
            SchemaFactory factory = SchemaFactory.newInstance(language);

            Source source = new DOMSource(map.getSchema());
            Schema schema = factory.newSchema(source);
            Validator validator = schema.newValidator();
            validator.validate(new DOMSource(xml));
           
            //if no exceptions where raised, the document is valid
            return true;
        } catch(IOException e) {
            e.printStackTrace();
View Full Code Here

    }

    public static void validateSecurityOrEncryptionElement(Node toValidate) throws SAXException, IOException {
       
        Schema schema = XMLSecurityConstants.getJaxbSchemas();
        Validator validator = schema.newValidator();
        DOMSource source = new DOMSource(toValidate);
        validator.validate(source);
    }
View Full Code Here

            String language = "http://www.w3.org/2001/XMLSchema";
            SchemaFactory factory = SchemaFactory.newInstance(language);

            Source source = new DOMSource(map.getSchema());
            Schema schema = factory.newSchema(source);
            Validator validator = schema.newValidator();
            validator.validate(new DOMSource(xml));
            //if no exceptions where raised, the document is valid
            isValid=true;


        } catch(IOException e) {
View Full Code Here

        {
            String schemaPath = CHANGES_SCHEMA_PATH + "changes-" + schemaVersion + ".xsd";

            Schema schema = getSchema( schemaPath );

            Validator validator = schema.newValidator();

            XmlValidationHandler baseHandler = new XmlValidationHandler( failOnValidationError );

            validator.setErrorHandler( baseHandler );

            reader = new XmlStreamReader( file );

            validator.validate( new StreamSource( reader ) );

            return baseHandler;
        }
        catch ( IOException e )
        {
View Full Code Here

            schema = getSchema();
        } else {
            schema = createSchema();
        }

        Validator validator = schema.newValidator();

        Source source;
        Result result;
        if (useDom) {
            source = exchange.getIn().getBody(DOMSource.class);
            result = new DOMResult();
        } else {
            source = exchange.getIn().getBody(SAXSource.class);
            result = new SAXResult();
        }
        if (source == null) {
            throw new NoXmlBodyValidationException(exchange);
        }

        // create a new errorHandler and set it on the validator
        // must be a local instance to avoid problems with concurrency (to be thread safe)
        ValidatorErrorHandler handler = errorHandler.getClass().newInstance();
        validator.setErrorHandler(handler);

        validator.validate(source, result);

        handler.handleErrors(exchange, schema, result);
    }
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.