}
// 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 " + catalogs.getLength() + " catalog uri entries." );
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)
File webappHome = null;
if( dbHome == null ) { /// DWES Why? let's make jUnit happy
webappHome = new File( "webapp" ).getAbsoluteFile();
} else if( dbHome.endsWith( "WEB-INF" ) ) {
webappHome = new File( dbHome ).getParentFile().getAbsoluteFile();
} else {
webappHome = new File( dbHome, "webapp" ).getAbsoluteFile();
}
LOG.debug( "using webappHome=" + webappHome.toURI().toString() );
// Get and store all URIs
final List<String> allURIs = new ArrayList<String>();
for( int i = 0; i < catalogs.getLength(); i++ ) {
String uri = ( (Element)catalogs.item( i ) ).getAttribute( "uri" );
if( uri != null ) { // when uri attribute is filled in
// Substitute string, creating an uri from a local file
if( uri.indexOf( "${WEBAPP_HOME}" ) != -1 ) {
uri = uri.replaceAll( "\\$\\{WEBAPP_HOME\\}", webappHome.toURI().toString() );
}
if( uri.indexOf( "${EXIST_HOME}" ) != -1 ) {
uri = uri.replaceAll( "\\$\\{EXIST_HOME\\}", dbHome );
}
// 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 );
}