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);
}
Aggregations