26
26
import java .util .Map ;
27
27
import java .util .Properties ;
28
28
import javax .servlet .ServletContext ;
29
+ import javax .servlet .jsp .JspFactory ;
29
30
30
31
import org .apache .commons .logging .Log ;
31
32
import org .apache .commons .logging .LogFactory ;
@@ -143,8 +144,6 @@ public TilesConfigurer() {
143
144
Boolean .toString (false ));
144
145
this .tilesPropertyMap .put (DefinitionsFactory .LOCALE_RESOLVER_IMPL_PROPERTY ,
145
146
SpringLocaleResolver .class .getName ());
146
- this .tilesPropertyMap .put (TilesContainerFactory .ATTRIBUTE_EVALUATOR_INIT_PARAM , tilesElPresent ?
147
- "org.apache.tiles.evaluator.el.ELAttributeEvaluator" : DirectAttributeEvaluator .class .getName ());
148
147
}
149
148
150
149
@@ -288,6 +287,15 @@ public void setServletContext(ServletContext servletContext) {
288
287
* @see #createTilesInitializer()
289
288
*/
290
289
public void afterPropertiesSet () throws TilesException {
290
+ boolean activateEl = false ;
291
+ if (tilesElPresent ) {
292
+ activateEl = new JspExpressionChecker ().isExpressionFactoryAvailable ();
293
+ if (!this .tilesPropertyMap .containsKey (TilesContainerFactory .ATTRIBUTE_EVALUATOR_INIT_PARAM )) {
294
+ this .tilesPropertyMap .put (TilesContainerFactory .ATTRIBUTE_EVALUATOR_INIT_PARAM , activateEl ?
295
+ "org.apache.tiles.evaluator.el.ELAttributeEvaluator" : DirectAttributeEvaluator .class .getName ());
296
+ }
297
+ }
298
+
291
299
SpringTilesApplicationContextFactory factory = new SpringTilesApplicationContextFactory ();
292
300
factory .init (this .tilesPropertyMap );
293
301
TilesApplicationContext preliminaryContext = factory .createApplicationContext (this .servletContext );
@@ -300,6 +308,7 @@ public void afterPropertiesSet() throws TilesException {
300
308
// We need to do this after initialization simply because we're reusing the
301
309
// original CompleteAutoloadTilesInitializer above. We cannot subclass
302
310
// CompleteAutoloadTilesInitializer when compiling against Tiles 2.1...
311
+ logger .debug ("Registering Tiles 2.2 LocaleResolver for complete-autoload setup" );
303
312
try {
304
313
BasicTilesContainer container = (BasicTilesContainer ) ServletUtil .getContainer (this .servletContext );
305
314
DefinitionsFactory definitionsFactory = container .getDefinitionsFactory ();
@@ -311,12 +320,12 @@ public void afterPropertiesSet() throws TilesException {
311
320
}
312
321
}
313
322
314
- if (tilesElPresent && this .tilesInitializer instanceof SpringTilesInitializer ) {
323
+ if (activateEl && this .tilesInitializer instanceof SpringTilesInitializer ) {
315
324
// Again, we need to do this after initialization since SpringTilesContainerFactory
316
325
// cannot override template methods that refer to Tiles 2.2 classes: in this case,
317
326
// AttributeEvaluatorFactory as createAttributeEvaluatorFactory return type.
318
327
BasicTilesContainer container = (BasicTilesContainer ) ServletUtil .getContainer (this .servletContext );
319
- TilesElActivator .registerEvaluator (container );
328
+ new TilesElActivator () .registerEvaluator (container );
320
329
}
321
330
}
322
331
@@ -423,9 +432,29 @@ protected PreparerFactory createPreparerFactory(TilesApplicationContext applicat
423
432
}
424
433
425
434
426
- private static class TilesElActivator {
435
+ private class JspExpressionChecker {
436
+
437
+ public boolean isExpressionFactoryAvailable () {
438
+ try {
439
+ JspFactory factory = JspFactory .getDefaultFactory ();
440
+ if (factory != null &&
441
+ factory .getJspApplicationContext (servletContext ).getExpressionFactory () != null ) {
442
+ logger .info ("Found JSP 2.1 ExpressionFactory" );
443
+ return true ;
444
+ }
445
+ }
446
+ catch (Throwable ex ) {
447
+ logger .warn ("Could not obtain JSP 2.1 ExpressionFactory" , ex );
448
+ }
449
+ return false ;
450
+ }
451
+ }
452
+
453
+
454
+ private class TilesElActivator {
427
455
428
- public static void registerEvaluator (BasicTilesContainer container ) {
456
+ public void registerEvaluator (BasicTilesContainer container ) {
457
+ logger .debug ("Registering Tiles 2.2 AttributeEvaluatorFactory for JSP 2.1" );
429
458
try {
430
459
ClassLoader cl = TilesElActivator .class .getClassLoader ();
431
460
Class aef = cl .loadClass ("org.apache.tiles.evaluator.AttributeEvaluatorFactory" );
0 commit comments