Get a template by name, with caching. Note: this should be updated to search the resource path first, etc. Create a new instance of a template from the specified file. The file text is cached so lookup is fast. Failure to find the file is also cached so the read will not happen twice.
( String file )
| 76 | |
| 77 | */ |
| 78 | public static SimpleTemplate getTemplate( String file ) |
| 79 | { |
| 80 | String templateText = (String)templateData.get( file ); |
| 81 | |
| 82 | if ( templateText == null || !cacheTemplates ) { |
| 83 | try { |
| 84 | FileReader fr = new FileReader( file ); |
| 85 | templateText = SimpleTemplate.getStringFromStream( fr ); |
| 86 | templateData.put( file, templateText ); |
| 87 | } catch ( IOException e ) { |
| 88 | // Not found |
| 89 | templateData.put( file, NO_TEMPLATE ); |
| 90 | } |
| 91 | } else |
| 92 | // Quick check prevents trying each time |
| 93 | if ( templateText.equals( NO_TEMPLATE ) ) |
| 94 | return null; |
| 95 | |
| 96 | if ( templateText == null ) |
| 97 | return null; |
| 98 | else |
| 99 | return new SimpleTemplate( templateText ); |
| 100 | } |
| 101 | |
| 102 | public static String getStringFromStream( InputStream ins ) |
| 103 | throws IOException |
nothing calls this directly
no test coverage detected