@@ -372,8 +372,6 @@ public Configuration(@Nullable String configFilename, Optional<Path> existHomeDi
372
372
configureElement (doc , XQUERY_CONFIGURATION_ELEMENT_NAME , this ::configureXQuery );
373
373
// Validation
374
374
configureElement (doc , XMLReaderObjectFactory .CONFIGURATION_ELEMENT_NAME , element -> configureValidation (existHomePath , element ));
375
- // Grammar cache
376
- configureElement (doc , GrammarPool .GRAMMAR_POOL , element -> configureGrammarCache (existHomePath , element ));
377
375
// RPC server
378
376
configureElement (doc , "rpc-server" , this ::configureRpcServer );
379
377
} catch (final SAXException | IOException | ParserConfigurationException e ) {
@@ -1194,11 +1192,15 @@ private void configureIndexer(final Document doc, final Element indexer) throws
1194
1192
setProperty (IndexManager .PROPERTY_INDEXER_MODULES , modConfig );
1195
1193
}
1196
1194
1197
- private void configureGrammarCache (final Optional <Path > dbHome , final Element validation ) {
1198
- configureProperty (validation , GrammarPool .ATTRIBUTE_MAXIMUM_SIZE , GrammarPool .PROPERTY_MAXIMUM_SIZE , Configuration ::asInteger , null );
1199
- configureProperty (validation , GrammarPool .ATTRIBUTE_EXPIRE_AFTER_ACCESS , GrammarPool .PROPERTY_EXPIRE_AFTER_ACCESS , Configuration ::asInteger , null );
1200
-
1201
- setProperty (GrammarPool .GRAMMAR_POOL , new GrammarPool (getInteger (GrammarPool .PROPERTY_MAXIMUM_SIZE ), getInteger (GrammarPool .PROPERTY_EXPIRE_AFTER_ACCESS )));
1195
+ private void configureGrammarCache (final NodeList grammarPoolNl ) {
1196
+ if (grammarPoolNl .getLength () == 0 ) {
1197
+ setProperty (GrammarPool .GRAMMAR_POOL , new GrammarPool ());
1198
+ } else {
1199
+ final Element grammarPoolElem = (Element ) grammarPoolNl .item (0 );
1200
+ configureProperty (grammarPoolElem , GrammarPool .ATTRIBUTE_MAXIMUM_SIZE , GrammarPool .PROPERTY_MAXIMUM_SIZE , Configuration ::asInteger , null );
1201
+ configureProperty (grammarPoolElem , GrammarPool .ATTRIBUTE_EXPIRE_AFTER_ACCESS , GrammarPool .PROPERTY_EXPIRE_AFTER_ACCESS , Configuration ::asInteger , null );
1202
+ setProperty (GrammarPool .GRAMMAR_POOL , new GrammarPool (getInteger (GrammarPool .PROPERTY_MAXIMUM_SIZE ), getInteger (GrammarPool .PROPERTY_EXPIRE_AFTER_ACCESS )));
1203
+ }
1202
1204
}
1203
1205
1204
1206
private void configureValidation (final Optional <Path > dbHome , final Element validation ) {
@@ -1207,17 +1209,51 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
1207
1209
1208
1210
// Configure the Entity Resolver
1209
1211
final NodeList entityResolver = validation .getElementsByTagName (XMLReaderObjectFactory .CONFIGURATION_ENTITY_RESOLVER_ELEMENT_NAME );
1210
- if (entityResolver .getLength () == 0 ) {
1211
- return ;
1212
+ if (entityResolver .getLength () != 0 ) {
1213
+ final Element elemEntityResolver = (Element ) entityResolver .item (0 );
1214
+ setupEntityResolver (dbHome , elemEntityResolver );
1212
1215
}
1216
+
1217
+ // Configure the grammar pool
1218
+ final NodeList grammarPoolNl = validation .getElementsByTagName (GrammarPool .GRAMMAR_POOL );
1219
+ configureGrammarCache (grammarPoolNl );
1220
+
1221
+ }
1222
+
1223
+ private void setupEntityResolver (final Optional <Path > dbHome , final Element elemEntityResolver ) {
1213
1224
LOG .info ("Creating xmlresolver.org OASIS Catalog resolver" );
1214
1225
1215
- final Element elemEntityResolver = (Element ) entityResolver .item (0 );
1216
1226
final NodeList nlCatalogs = elemEntityResolver .getElementsByTagName (XMLReaderObjectFactory .CONFIGURATION_CATALOG_ELEMENT_NAME );
1217
1227
1218
- // Determine webapps directory. SingleInstanceConfiguration cannot
1219
- // be used at this phase. Trick is to check whether dbHOME is
1220
- // pointing to a WEB-INF directory, meaning inside the war file.
1228
+ final Path webappHome = getWebappHome (dbHome , nlCatalogs );
1229
+
1230
+ // Store all configured URIs
1231
+ final List <String > catalogUris = getCatalogUris (dbHome , nlCatalogs , webappHome );
1232
+ setProperty (XMLReaderObjectFactory .CATALOG_URIS , catalogUris );
1233
+
1234
+ setupResolver (catalogUris );
1235
+ }
1236
+
1237
+ private void setupResolver (final List <String > catalogUris ) {
1238
+ // Create and Store the resolver
1239
+ try {
1240
+ final List <Tuple2 <String , Optional <InputSource >>> catalogs = catalogUris .stream ()
1241
+ .map (catalogUri -> Tuple (catalogUri , Optional .<InputSource >empty ()))
1242
+ .toList ();
1243
+ final Resolver resolver = ResolverFactory .newResolver (catalogs );
1244
+ setProperty (XMLReaderObjectFactory .CATALOG_RESOLVER , resolver );
1245
+ } catch (final URISyntaxException e ) {
1246
+ LOG .error ("Unable to parse catalog uri: {}" , e .getMessage (), e );
1247
+ }
1248
+ }
1249
+
1250
+ /*
1251
+ Determine webapps directory. SingleInstanceConfiguration cannot
1252
+ be used at this phase. Trick is to check whether dbHOME is
1253
+ pointing to a WEB-INF directory, meaning inside the war file.
1254
+ */
1255
+ private static Path getWebappHome (Optional <Path > dbHome , NodeList nlCatalogs ) {
1256
+
1221
1257
final Path webappHome = dbHome .map (h -> {
1222
1258
if (FileUtils .fileName (h ).endsWith ("WEB-INF" )) {
1223
1259
return h .getParent ().toAbsolutePath ();
@@ -1230,7 +1266,10 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
1230
1266
LOG .debug ("Using dbHome={}" , dbHome );
1231
1267
LOG .debug ("using webappHome={}" , webappHome );
1232
1268
}
1269
+ return webappHome ;
1270
+ }
1233
1271
1272
+ private static List <String > getCatalogUris (Optional <Path > dbHome , NodeList nlCatalogs , Path webappHome ) {
1234
1273
// Get the Catalog URIs
1235
1274
final List <String > catalogUris = new ArrayList <>();
1236
1275
for (int i = 0 ; i < nlCatalogs .getLength (); i ++) {
@@ -1252,20 +1291,7 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
1252
1291
catalogUris .add (uri );
1253
1292
}
1254
1293
}
1255
-
1256
- // Store all configured URIs
1257
- setProperty (XMLReaderObjectFactory .CATALOG_URIS , catalogUris );
1258
-
1259
- // Create and Store the resolver
1260
- try {
1261
- final List <Tuple2 <String , Optional <InputSource >>> catalogs = catalogUris .stream ()
1262
- .map (catalogUri -> Tuple (catalogUri , Optional .<InputSource >empty ()))
1263
- .toList ();
1264
- final Resolver resolver = ResolverFactory .newResolver (catalogs );
1265
- setProperty (XMLReaderObjectFactory .CATALOG_RESOLVER , resolver );
1266
- } catch (final URISyntaxException e ) {
1267
- LOG .error ("Unable to parse catalog uri: {}" , e .getMessage (), e );
1268
- }
1294
+ return catalogUris ;
1269
1295
}
1270
1296
1271
1297
private void configureRpcServer (final Element validation ) throws DatabaseConfigurationException {
0 commit comments