protected void executeWithNamedTemplate ( Context context , String name ) throws EvaluationException { assert ( context != null ) ; assert ( name != null ) ; Template template = null ; boolean runStatic = false ; try { template = context . localLoad ( name ) ; if ( template == null ) { template = context . globalLoad ( name ) ; runStatic = true ; } } catch ( EvaluationException ee ) { throw ee . addExceptionInfo ( getSourceRange ( ) , context ) ; } // Check that the template was actually loaded. if ( template == null ) { throw new EvaluationException ( "failed to load template: " + name , getSourceRange ( ) ) ; } TemplateType includeeType = context . getCurrentTemplate ( ) . type ; TemplateType includedType = template . type ; // Check that the template types are correct for the inclusion. if ( ! Template . checkValidInclude ( includeeType , includedType ) ) { throw new EvaluationException ( includeeType + " template cannot include " + includedType + " template" , getSourceRange ( ) ) ; } // Push the template, execute it, then pop it from the stack. // Template loops will be caught by the call depth check when pushing // the template. context . pushTemplate ( template , getSourceRange ( ) , Level . INFO , includedType . toString ( ) ) ; template . execute ( context , runStatic ) ; context . popTemplate ( Level . INFO , includedType . toString ( ) ) ; }
This is a utility method which performs an include from a fixed template name . The validity of the name should be checked by the subclass ; this avoids unnecessary regular expression matching .