@@ -1196,22 +1196,64 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
1196
1196
// Determine validation mode
1197
1197
configureProperty (validation , XMLReaderObjectFactory .VALIDATION_MODE_ATTRIBUTE , PROPERTY_VALIDATION_MODE );
1198
1198
1199
- // cache
1200
- setProperty (XMLReaderObjectFactory .GRAMMAR_POOL , new GrammarPool ());
1201
-
1202
1199
// Configure the Entity Resolver
1203
- final NodeList entityResolver = validation .getElementsByTagName (XMLReaderObjectFactory .CONFIGURATION_ENTITY_RESOLVER_ELEMENT_NAME );
1204
- if (entityResolver .getLength () == 0 ) {
1205
- return ;
1200
+ final NodeList entityResolverElements = validation .getElementsByTagName (XMLReaderObjectFactory .CONFIGURATION_ENTITY_RESOLVER_ELEMENT_NAME );
1201
+ if (entityResolverElements .getLength () != 0 ) {
1202
+ final Element elemEntityResolver = (Element ) entityResolverElements .item (0 );
1203
+ configureEntityResolver (dbHome , elemEntityResolver );
1206
1204
}
1205
+
1206
+ // Configure the grammar pool
1207
+ final NodeList grammarPoolElements = validation .getElementsByTagName (GrammarPool .GRAMMAR_POOL_ELEMENT );
1208
+ configureGrammarCache (grammarPoolElements );
1209
+
1210
+ }
1211
+
1212
+ private void configureGrammarCache (final NodeList grammarCacheElements ) {
1213
+ if (grammarCacheElements .getLength () == 0 ) {
1214
+ setProperty (GrammarPool .GRAMMAR_POOL_ELEMENT , new GrammarPool ());
1215
+
1216
+ } else {
1217
+ final Element grammarPoolElem = (Element ) grammarCacheElements .item (0 );
1218
+ configureProperty (grammarPoolElem , GrammarPool .ATTRIBUTE_MAXIMUM_SIZE ,
1219
+ GrammarPool .PROPERTY_MAXIMUM_SIZE , Configuration ::asInteger , null );
1220
+ configureProperty (grammarPoolElem , GrammarPool .ATTRIBUTE_EXPIRE_AFTER_ACCESS ,
1221
+ GrammarPool .PROPERTY_EXPIRE_AFTER_ACCESS , Configuration ::asInteger , null );
1222
+ setProperty (GrammarPool .GRAMMAR_POOL_ELEMENT ,
1223
+ new GrammarPool (getInteger (GrammarPool .PROPERTY_MAXIMUM_SIZE ), getInteger (GrammarPool .PROPERTY_EXPIRE_AFTER_ACCESS )));
1224
+ }
1225
+ }
1226
+
1227
+ private void configureEntityResolver (final Optional <Path > dbHome , final Element entityResolverElement ) {
1207
1228
LOG .info ("Creating xmlresolver.org OASIS Catalog resolver" );
1208
1229
1209
- final Element elemEntityResolver = (Element ) entityResolver .item (0 );
1210
- final NodeList nlCatalogs = elemEntityResolver .getElementsByTagName (XMLReaderObjectFactory .CONFIGURATION_CATALOG_ELEMENT_NAME );
1230
+ final NodeList catalogElements = entityResolverElement
1231
+ .getElementsByTagName (XMLReaderObjectFactory .CONFIGURATION_CATALOG_ELEMENT_NAME );
1232
+ final Path webappHome = getWebappHome (dbHome , catalogElements );
1233
+
1234
+ // Store all configured URIs
1235
+ final List <String > catalogUris = getCatalogUris (dbHome , catalogElements , webappHome );
1236
+ setProperty (XMLReaderObjectFactory .CATALOG_URIS , catalogUris );
1237
+
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 (final Optional <Path > dbHome , final NodeList catalogElements ) {
1211
1256
1212
- // Determine webapps directory. SingleInstanceConfiguration cannot
1213
- // be used at this phase. Trick is to check whether dbHOME is
1214
- // pointing to a WEB-INF directory, meaning inside the war file.
1215
1257
final Path webappHome = dbHome .map (h -> {
1216
1258
if (FileUtils .fileName (h ).endsWith ("WEB-INF" )) {
1217
1259
return h .getParent ().toAbsolutePath ();
@@ -1220,15 +1262,18 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
1220
1262
}).orElse (Paths .get ("webapp" ).toAbsolutePath ());
1221
1263
1222
1264
if (LOG .isDebugEnabled ()) {
1223
- LOG .debug ("Found {} catalog uri entries." , nlCatalogs .getLength ());
1265
+ LOG .debug ("Found {} catalog uri entries." , catalogElements .getLength ());
1224
1266
LOG .debug ("Using dbHome={}" , dbHome );
1225
1267
LOG .debug ("using webappHome={}" , webappHome );
1226
1268
}
1269
+ return webappHome ;
1270
+ }
1227
1271
1272
+ private static List <String > getCatalogUris (final Optional <Path > dbHome , final NodeList catalogElements , final Path webappHome ) {
1228
1273
// Get the Catalog URIs
1229
1274
final List <String > catalogUris = new ArrayList <>();
1230
- for (int i = 0 ; i < nlCatalogs .getLength (); i ++) {
1231
- final String uriAttributeValue = ((Element ) nlCatalogs .item (i )).getAttribute ("uri" );
1275
+ for (int i = 0 ; i < catalogElements .getLength (); i ++) {
1276
+ final String uriAttributeValue = ((Element ) catalogElements .item (i )).getAttribute ("uri" );
1232
1277
1233
1278
if (!uriAttributeValue .isEmpty ()) {
1234
1279
final String uri ;
@@ -1246,20 +1291,7 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
1246
1291
catalogUris .add (uri );
1247
1292
}
1248
1293
}
1249
-
1250
- // Store all configured URIs
1251
- setProperty (XMLReaderObjectFactory .CATALOG_URIS , catalogUris );
1252
-
1253
- // Create and Store the resolver
1254
- try {
1255
- final List <Tuple2 <String , Optional <InputSource >>> catalogs = catalogUris .stream ()
1256
- .map (catalogUri -> Tuple (catalogUri , Optional .<InputSource >empty ()))
1257
- .toList ();
1258
- final Resolver resolver = ResolverFactory .newResolver (catalogs );
1259
- setProperty (XMLReaderObjectFactory .CATALOG_RESOLVER , resolver );
1260
- } catch (final URISyntaxException e ) {
1261
- LOG .error ("Unable to parse catalog uri: {}" , e .getMessage (), e );
1262
- }
1294
+ return catalogUris ;
1263
1295
}
1264
1296
1265
1297
private void configureRpcServer (final Element validation ) throws DatabaseConfigurationException {
0 commit comments