Search in sources :

Example 6 with GrammarPool

use of org.exist.validation.GrammarPool in project exist by eXist-db.

the class Configuration method configureValidation.

private void configureValidation(final Optional<Path> dbHome, Document doc, Element validation) throws DatabaseConfigurationException {
    // Determine validation mode
    final String mode = getConfigAttributeValue(validation, XMLReaderObjectFactory.VALIDATION_MODE_ATTRIBUTE);
    if (mode != null) {
        config.put(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE, mode);
        LOG.debug(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE + ": {}", config.get(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE));
    }
    // Extract catalogs
    LOG.debug("Creating eXist catalog resolver");
    final eXistXMLCatalogResolver resolver = new eXistXMLCatalogResolver();
    final NodeList entityResolver = validation.getElementsByTagName(XMLReaderObjectFactory.CONFIGURATION_ENTITY_RESOLVER_ELEMENT_NAME);
    if (entityResolver.getLength() > 0) {
        final Element r = (Element) entityResolver.item(0);
        final NodeList catalogs = r.getElementsByTagName(XMLReaderObjectFactory.CONFIGURATION_CATALOG_ELEMENT_NAME);
        LOG.debug("Found {} catalog uri entries.", catalogs.getLength());
        LOG.debug("Using dbHome={}", dbHome);
        // Determine webapps directory. SingleInstanceConfiguration cannot
        // be used at this phase. Trick is to check wether dbHOME is
        // pointing to a WEB-INF directory, meaning inside war file)
        final Path webappHome = dbHome.map(h -> {
            if (FileUtils.fileName(h).endsWith("WEB-INF")) {
                return h.getParent().toAbsolutePath();
            } else {
                return h.resolve("webapp").toAbsolutePath();
            }
        }).orElse(Paths.get("webapp").toAbsolutePath());
        LOG.debug("using webappHome={}", webappHome.toString());
        // Get and store all URIs
        final List<String> allURIs = new ArrayList<>();
        for (int i = 0; i < catalogs.getLength(); i++) {
            String uri = ((Element) catalogs.item(i)).getAttribute("uri");
            if (uri != null) {
                // Substitute string, creating an uri from a local file
                if (uri.contains("${WEBAPP_HOME}")) {
                    uri = uri.replaceAll("\\$\\{WEBAPP_HOME\\}", webappHome.toUri().toString());
                }
                if (uri.contains("${EXIST_HOME}")) {
                    uri = uri.replaceAll("\\$\\{EXIST_HOME\\}", dbHome.toString());
                }
                // Add uri to confiuration
                LOG.info("Add catalog uri {}", uri);
                allURIs.add(uri);
            }
        }
        resolver.setCatalogs(allURIs);
        // Store all configured URIs
        config.put(XMLReaderObjectFactory.CATALOG_URIS, allURIs);
    }
    // Store resolver
    config.put(XMLReaderObjectFactory.CATALOG_RESOLVER, resolver);
    // cache
    final GrammarPool gp = new GrammarPool();
    config.put(XMLReaderObjectFactory.GRAMMAR_POOL, gp);
}
Also used : Path(java.nio.file.Path) XQueryWatchDog(org.exist.xquery.XQueryWatchDog) DefaultCacheManager(org.exist.storage.DefaultCacheManager) BrokerPool(org.exist.storage.BrokerPool) Main(org.exist.start.Main) org.exist.validation.resolver.eXistXMLCatalogResolver(org.exist.validation.resolver.eXistXMLCatalogResolver) SystemExport(org.exist.backup.SystemExport) ErrorHandler(org.xml.sax.ErrorHandler) Namespaces(org.exist.Namespaces) Document(org.w3c.dom.Document) SAXParser(javax.xml.parsers.SAXParser) XQueryPool(org.exist.storage.XQueryPool) Path(java.nio.file.Path) LockTable(org.exist.storage.lock.LockTable) NativeBroker(org.exist.storage.NativeBroker) Module(org.exist.xquery.Module) FunctionFactory(org.exist.xquery.FunctionFactory) Logger(org.apache.logging.log4j.Logger) CollectionCache(org.exist.collections.CollectionCache) BrokerFactory(org.exist.storage.BrokerFactory) TransformerFactoryAllocator(org.exist.xslt.TransformerFactoryAllocator) LockManager(org.exist.storage.lock.LockManager) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) GrammarPool(org.exist.validation.GrammarPool) SAXAdapter(org.exist.dom.memtree.SAXAdapter) java.util(java.util) CustomMatchListenerFactory(org.exist.storage.serializers.CustomMatchListenerFactory) SAXParserFactory(javax.xml.parsers.SAXParserFactory) IndexManager(org.exist.indexing.IndexManager) XMLReader(org.xml.sax.XMLReader) JobException(org.exist.scheduler.JobException) Node(org.w3c.dom.Node) FEATURE_SECURE_PROCESSING(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING) Indexer(org.exist.Indexer) XQueryContext(org.exist.xquery.XQueryContext) Nullable(javax.annotation.Nullable) Deployment(org.exist.repo.Deployment) InputSource(org.xml.sax.InputSource) JobConfig(org.exist.scheduler.JobConfig) JobType(org.exist.scheduler.JobType) Journal(org.exist.storage.journal.Journal) NodeList(org.w3c.dom.NodeList) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) IOException(java.io.IOException) NativeValueIndex(org.exist.storage.NativeValueIndex) IndexSpec(org.exist.storage.IndexSpec) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) PerformanceStats(org.exist.xquery.PerformanceStats) Paths(java.nio.file.Paths) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DBBroker(org.exist.storage.DBBroker) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Serializer(org.exist.storage.serializers.Serializer) DatabaseImpl(org.exist.xmldb.DatabaseImpl) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) org.exist.validation.resolver.eXistXMLCatalogResolver(org.exist.validation.resolver.eXistXMLCatalogResolver) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) GrammarPool(org.exist.validation.GrammarPool)

Aggregations

GrammarPool (org.exist.validation.GrammarPool)6 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)2 XPathException (org.exist.xquery.XPathException)2 Sequence (org.exist.xquery.value.Sequence)2 ValueSequence (org.exist.xquery.value.ValueSequence)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 URL (java.net.URL)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 Nullable (javax.annotation.Nullable)1 FEATURE_SECURE_PROCESSING (javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1