public Template globalLoad ( String name , boolean lookupOnly ) { // If this context was created without a Compiler object specified, then // no global lookups can be done. Just return null indicating that the // requested template can't be found. if ( compiler == null ) { return null ; } // Use the full lookup to find the correct template file. This must // always be done on a global load because the actual template file on // disk may be different for different object templates. The raw // (unduplicated) value of LOADPATH can be used because it will not be // changed by the code below. SourceRepository repository = compiler . getSourceRepository ( ) ; SourceFile source = repository . retrievePanSource ( name , relativeLoadpaths ) ; if ( source . isAbsent ( ) ) { if ( lookupOnly ) { // Files that were searched for but not found are still // dependencies. Keep track of these so that they can be // included in the dependency file and checked when trying to // see if profiles are up-to-date. otherDependencies . add ( source ) ; return null ; } else { // The lookupOnly flag was not set, so it is an error if the // template has not been found. throw EvaluationException . create ( ( SourceRange ) null , ( BuildContext ) this , MSG_CANNOT_LOCATE_TEMPLATE , name ) ; } } // Now actually retrieve the other object's root, waiting if the // result isn't yet available. CompileCache ccache = compiler . getCompileCache ( ) ; CompileResult cresult = ccache . waitForResult ( source . getPath ( ) . getAbsolutePath ( ) ) ; Template template = null ; try { // Extract the compiled template and ensure that the name is // correct. The template must not be null if no exception is thrown. template = cresult . template ; template . templateNameVerification ( name ) ; // Found the template. Put this into the dependencies only if we're // really going to use it. I.e. if the lookupOnly flag is false. if ( ! lookupOnly ) { dependencies . put ( name , template ) ; if ( template . type == TemplateType . OBJECT ) { objectDependencies . add ( template . name ) ; } } } catch ( SyntaxException se ) { // This can happen if there is a syntax error while including // the given template. If this isn't just a lookup, then convert // this into an evaluation exception // and throw it. if ( ! lookupOnly ) { throw new EvaluationException ( se . getMessage ( ) ) ; } else { template = null ; } } catch ( EvaluationException ee ) { // Eat the exception if we're only doing a lookup; otherwise, // rethrow it. if ( ! lookupOnly ) { throw ee ; } else { template = null ; } } return template ; }
A method to load a template from the global cache . This may trigger the global cache to compile the template .