Package org.exist.validation

Examples of org.exist.validation.GrammarPool


        // Get validation settings
        final String option = (String) config.getProperty(PROPERTY_VALIDATION_MODE);
        final VALIDATION_SETTING validation = convertValidationMode(option);

        final GrammarPool grammarPool =
                (GrammarPool) config.getProperty(XMLReaderObjectFactory.GRAMMER_POOL);
       
        final eXistXMLCatalogResolver resolver =
                (eXistXMLCatalogResolver) config.getProperty(CATALOG_RESOLVER);
View Full Code Here


            reader.setContentHandler(DUMMY_HANDLER);
            reader.setErrorHandler(DUMMY_HANDLER);
            reader.setProperty(Namespaces.SAX_LEXICAL_HANDLER, DUMMY_HANDLER);
           
            // DIZZZ; workaround Xerces bug. Cached DTDs cause for problems during validation parsing.
            final GrammarPool grammarPool =
               (GrammarPool) getReaderProperty(reader,
                                    XMLReaderObjectFactory.APACHE_PROPERTIES_INTERNAL_GRAMMARPOOL);
            if(grammarPool!=null){
                grammarPool.clearDTDs();
            }
           
            super.returnObject(reader);
           
        } catch (final Exception e) {
View Full Code Here

        // Store resolver
        config.put( XMLReaderObjectFactory.CATALOG_RESOLVER, resolver );

        // cache
        final GrammarPool gp = new GrammarPool();
        config.put( XMLReaderObjectFactory.GRAMMER_POOL, gp );

    }
View Full Code Here

     * @see org.exist.xquery.BasicFunction#eval(Sequence[], Sequence)
     */
    public Sequence eval(Sequence[] args, Sequence contextSequence)
    throws XPathException {
       
        final GrammarPool grammarpool
            = (GrammarPool) config.getProperty(XMLReaderObjectFactory.GRAMMER_POOL);
       
        if (isCalledAs("clear-grammar-cache")){
           
            final Sequence result = new ValueSequence();
           
            final int before = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Clearing "+before+" grammars");
           
            clearGrammarPool(grammarpool);
           
            final int after = countTotalNumberOfGrammar(grammarpool);
            LOG.debug("Remained "+after+" grammars");
           
            final int delta=before-after;
           
            result.add(new IntegerValue(delta));
           
            return result;
           
           
        } else if (isCalledAs("show-grammar-cache")){
            final MemTreeBuilder builder = context.getDocumentBuilder();
            final NodeImpl result = writeReport(grammarpool, builder);
            return result;
           
        } else if (isCalledAs("pre-parse-grammar")){
           
            if (args[0].isEmpty())
                {return Sequence.EMPTY_SEQUENCE;}
           
            // Setup for XML schema support only
            final XMLGrammarPreparser parser = new XMLGrammarPreparser();
            parser.registerPreparser(TYPE_XSD , null);
           
          
            final List<Grammar> allGrammars = new ArrayList<Grammar>();
           
             // iterate through the argument sequence and parse url
            for (final SequenceIterator i = args[0].iterate(); i.hasNext();) {
                String url = i.nextItem().getStringValue();
               
                // Fix database urls
                if(url.startsWith("/")){
                    url="xmldb:exist://"+url;
                }
              
                LOG.debug("Parsing "+url);
               
                // parse XSD grammar
                try {
                    if(url.endsWith(".xsd")){
                       
                        final InputStream is = new URL(url).openStream();
                        final XMLInputSource xis = new XMLInputSource(null, url, url, is, null);
                        final Grammar schema = parser.preparseGrammar(TYPE_XSD, xis);
                        is.close();

                        allGrammars.add(schema);

                    } else {
                        throw new XPathException(this, "Only XMLSchemas can be preparsed.");
                    }

                } catch(final IOException ex) {
                    LOG.debug(ex);
                    throw new XPathException(this, ex);
                   
                } catch(final Exception ex) {
                    LOG.debug(ex);
                    throw new XPathException(this, ex);
                }
               
               
            }

            LOG.debug("Successfully parsed "+allGrammars.size()+" grammars.");
           
            // Send all XSD grammars to grammarpool
            Grammar grammars[] = new Grammar[allGrammars.size()];
            grammars = allGrammars.toArray(grammars);
            grammarpool.cacheGrammars(TYPE_XSD, grammars);
            // Construct result to end user
            final ValueSequence result = new ValueSequence();
            for(final Grammar one : grammars){
                result.add( new StringValue(one.getGrammarDescription().getNamespace()) );
View Full Code Here

     */
    public Sequence eval(Sequence[] args, Sequence contextSequence)
            throws XPathException {

        XMLEntityResolver entityResolver = null;
        GrammarPool grammarPool = null;

        final ValidationReport report = new ValidationReport();
        ContentHandler contenthandler = null;
        MemTreeBuilder instanceBuilder = null;
        InputSource instance = null;
View Full Code Here

TOP

Related Classes of org.exist.validation.GrammarPool

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.