Package org.apache.cocoon.components.validation

Examples of org.apache.cocoon.components.validation.SchemaParser


    public ValidationHandler getValidationHandler(Source source, String grammar,
                                               ErrorHandler errorHandler)
    throws IOException, SAXException, ValidatorException {
        if (errorHandler == null) errorHandler = DraconianErrorHandler.INSTANCE;

        SchemaParser parser = null;
        try {
            /* If no grammar was supplied, try to detect one */
            if (grammar == null) grammar = this.detectGrammar(source);

            /* Save the grammar name and try to find a schema parser */
            String language = grammar;
            parser = this.lookupParserByGrammar(grammar);

            /*
             * If the schema parser for the language was not found, we might have to
             * look up for the form name:grammar as specified by Validator.
             */
            if (parser == null) {
                int index = grammar.indexOf(':');
                if (index > 0) {
                    String name = grammar.substring(0, index);
                    language = grammar.substring(index + 1);
                    parser = this.lookupParserByName(name);
                }
            }

            /* If still we didn't find any parser, simply die of natural death */
            if (parser == null) {
                String message = "Unsupported grammar language" + grammar;
                throw new ValidatorException(message);
            }

            /* Somehow we have a schema parser, check it supports the gramar */
            String languages[] = parser.getSupportedGrammars();
            for (int x = 0; x < languages.length; x++) {
                if (! language.equals(languages[x])) continue;
                /* Hah! language supported, go ahead and parse now */
                Schema schema = this.getSchema(parser, source, language);
                return schema.createValidator(errorHandler);
            }

            /* Something really odd going on, this should never happen */
            String message = "Schema parser " + parser.getClass().getName() +
                             " does not support grammar " + grammar;
            throw new ValidatorException(message);

        } finally {
            if (parser != null) this.releaseParser(parser);
View Full Code Here


            /* Dump some debugging information, just in case */
            this.logger.debug("Configuring schema parser " + selectionKey + " as "
                              + className + " from " + configuration.getLocation());

            /* Try to load and instantiate the SchemaParser */
            final SchemaParser schemaParser;
            try {
                /* Load the class */
                final Class clazz = Class.forName(className);

                /* ClassCastExceptions normally don't come with messages (darn) */
                if (! SchemaParser.class.isAssignableFrom(clazz)) {
                    String message = "Class " + className + " doesn't implement the "
                                     + SchemaParser.class.getName() + " interface";
                    throw new ConfigurationException(message, configuration);
                }

                /* We only support ThreadSafe SchemaParser instances */
                if (! ThreadSafe.class.isAssignableFrom(clazz)) {
                    String message = "Class " + className + " doesn't implement the "
                                     + ThreadSafe.class.getName() + " interface";
                    throw new ConfigurationException(message, configuration);
                }

                /* Instantiate and set up the new SchemaParser */
                schemaParser = (SchemaParser) clazz.newInstance();
                this.setupComponent(selectionKey, schemaParser, configuration);

            } catch (ConfigurationException exception) {
                throw exception;
            } catch (Exception exception) {
                String message = "Unable to instantiate SchemaParser " + className;
                throw new ConfigurationException(message, configuration, exception);
            }

            /* Store this instance (and report about it) */
            this.components.put(selectionKey, schemaParser);
            this.logger.debug("SchemaParser \"" + selectionKey + "\" instantiated" +
                              " from class " + className);

            /* Analyze the grammars provided by the current SchemaParser */
            String grammars[] = schemaParser.getSupportedGrammars();
            if (grammars == null) continue;

            /* Iterate through the grammars and store them (default lookup) */
            for (int k = 0; k < grammars.length; k++) {
                if (this.grammars.containsKey(grammars[k])) {
View Full Code Here

    public ValidationHandler getValidationHandler(Source source, String grammar,
                                               ErrorHandler errorHandler)
    throws IOException, SAXException, ValidatorException {
        if (errorHandler == null) errorHandler = DraconianErrorHandler.INSTANCE;

        SchemaParser parser = null;
        try {
            /* If no grammar was supplied, try to detect one */
            if (grammar == null) grammar = this.detectGrammar(source);

            /* Save the grammar name and try to find a schema parser */
            String language = grammar;
            parser = this.lookupParserByGrammar(grammar);

            /*
             * If the schema parser for the language was not found, we might have to
             * look up for the form name:grammar as specified by Validator.
             */
            if (parser == null) {
                int index = grammar.indexOf(':');
                if (index > 0) {
                    String name = grammar.substring(0, index);
                    language = grammar.substring(index + 1);
                    parser = this.lookupParserByName(name);
                }
            }

            /* If still we didn't find any parser, simply die of natural death */
            if (parser == null) {
                String message = "Unsupported grammar language" + grammar;
                throw new ValidatorException(message);
            }

            /* Somehow we have a schema parser, check it supports the gramar */
            String languages[] = parser.getSupportedGrammars();
            for (int x = 0; x < languages.length; x++) {
                if (! language.equals(languages[x])) continue;
                /* Hah! language supported, go ahead and parse now */
                Schema schema = this.getSchema(parser, source, language);
                return schema.createValidator(errorHandler);
            }

            /* Something really odd going on, this should never happen */
            String message = "Schema parser " + parser.getClass().getName() +
                             " does not support grammar " + grammar;
            throw new ValidatorException(message);

        } finally {
            if (parser != null) this.releaseParser(parser);
View Full Code Here

            /* Dump some debugging information, just in case */
            this.logger.debug("Configuring schema parser " + selectionKey + " as "
                              + className + " from " + configuration.getLocation());

            /* Try to load and instantiate the SchemaParser */
            final SchemaParser schemaParser;
            try {
                /* Load the class */
                final Class clazz = Class.forName(className);

                /* ClassCastExceptions normally don't come with messages (darn) */
                if (! SchemaParser.class.isAssignableFrom(clazz)) {
                    String message = "Class " + className + " doesn't implement the "
                                     + SchemaParser.class.getName() + " interface";
                    throw new ConfigurationException(message, configuration);
                }

                /* We only support ThreadSafe SchemaParser instances */
                if (! ThreadSafe.class.isAssignableFrom(clazz)) {
                    String message = "Class " + className + " doesn't implement the "
                                     + ThreadSafe.class.getName() + " interface";
                    throw new ConfigurationException(message, configuration);
                }

                /* Instantiate and set up the new SchemaParser */
                schemaParser = (SchemaParser) clazz.newInstance();
                this.setupComponent(selectionKey, schemaParser, configuration);

            } catch (ConfigurationException exception) {
                throw exception;
            } catch (Exception exception) {
                String message = "Unable to instantiate SchemaParser " + className;
                throw new ConfigurationException(message, configuration, exception);
            }

            /* Store this instance (and report about it) */
            this.components.put(selectionKey, schemaParser);
            this.logger.debug("SchemaParser \"" + selectionKey + "\" instantiated" +
                              " from class " + className);

            /* Analyze the grammars provided by the current SchemaParser */
            String grammars[] = schemaParser.getSupportedGrammars();
            if (grammars == null) continue;

            /* Iterate through the grammars and store them (default lookup) */
            for (int k = 0; k < grammars.length; k++) {
                if (this.grammars.containsKey(grammars[k])) {
View Full Code Here

    public ValidationHandler getValidationHandler(Source source, String grammar,
                                               ErrorHandler errorHandler)
    throws IOException, SAXException, ValidatorException {
        if (errorHandler == null) errorHandler = DraconianErrorHandler.INSTANCE;

        SchemaParser parser = null;
        try {
            /* If no grammar was supplied, try to detect one */
            if (grammar == null) grammar = this.detectGrammar(source);

            /* Save the grammar name and try to find a schema parser */
            String language = grammar;
            parser = this.lookupParserByGrammar(grammar);

            /*
             * If the schema parser for the language was not found, we might have to
             * look up for the form name:grammar as specified by Validator.
             */
            if (parser == null) {
                int index = grammar.indexOf(':');
                if (index > 0) {
                    String name = grammar.substring(0, index);
                    language = grammar.substring(index + 1);
                    parser = this.lookupParserByName(name);
                }
            }

            /* If still we didn't find any parser, simply die of natural death */
            if (parser == null) {
                String message = "Unsupported grammar language" + grammar;
                throw new ValidatorException(message);
            }

            /* Somehow we have a schema parser, check it supports the gramar */
            String languages[] = parser.getSupportedGrammars();
            for (int x = 0; x < languages.length; x++) {
                if (! language.equals(languages[x])) continue;
                /* Hah! language supported, go ahead and parse now */
                Schema schema = this.getSchema(parser, source, language);
                return schema.createValidator(errorHandler);
            }

            /* Something really odd going on, this should never happen */
            String message = "Schema parser " + parser.getClass().getName() +
                             " does not support grammar " + grammar;
            throw new ValidatorException(message);

        } finally {
            if (parser != null) this.releaseParser(parser);
View Full Code Here

            /* Dump some debugging information, just in case */
            this.logger.debug("Configuring schema parser " + selectionKey + " as "
                              + className + " from " + configuration.getLocation());

            /* Try to load and instantiate the SchemaParser */
            final SchemaParser schemaParser;
            try {
                /* Load the class */
                final Class clazz = Class.forName(className);

                /* ClassCastExceptions normally don't come with messages (darn) */
                if (! SchemaParser.class.isAssignableFrom(clazz)) {
                    String message = "Class " + className + " doesn't implement the "
                                     + SchemaParser.class.getName() + " interface";
                    throw new ConfigurationException(message, configuration);
                }

                /* We only support ThreadSafe SchemaParser instances */
                if (! ThreadSafe.class.isAssignableFrom(clazz)) {
                    String message = "Class " + className + " doesn't implement the "
                                     + ThreadSafe.class.getName() + " interface";
                    throw new ConfigurationException(message, configuration);
                }

                /* Instantiate and set up the new SchemaParser */
                schemaParser = (SchemaParser) clazz.newInstance();
                this.setupComponent(selectionKey, schemaParser, configuration);

            } catch (ConfigurationException exception) {
                throw exception;
            } catch (Exception exception) {
                String message = "Unable to instantiate SchemaParser " + className;
                throw new ConfigurationException(message, configuration, exception);
            }

            /* Store this instance (and report about it) */
            this.components.put(selectionKey, schemaParser);
            this.logger.debug("SchemaParser \"" + selectionKey + "\" instantiated" +
                              " from class " + className);

            /* Analyze the grammars provided by the current SchemaParser */
            String grammars[] = schemaParser.getSupportedGrammars();
            if (grammars == null) continue;

            /* Iterate through the grammars and store them (default lookup) */
            for (int k = 0; k < grammars.length; k++) {
                if (this.grammars.containsKey(grammars[k])) {
View Full Code Here

TOP

Related Classes of org.apache.cocoon.components.validation.SchemaParser

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.