1 5 package com.teamkonzept.lib.templates; 6 7 import java.io.*; 8 9 import com.teamkonzept.lib.*; 10 11 17 public class TKTemplateFileLoader implements TKTemplateSourceLoader { 18 19 public final static String CLASS_ID = "file"; 20 21 public final static File getFile( String location ) 22 { 23 try { 24 return new File( location.substring( location.indexOf(':')+1 ) ); 25 } 26 catch( Exception e ) { 27 return null; 28 } 29 } 30 31 public final static File childFile( String location, String parentLocation ) 32 { 33 int newProtEnd = location.indexOf(':'); 34 String newFilename = ( newProtEnd < 0 ? location : location.substring( newProtEnd+1 ) ); 35 File newFile = new File( newFilename ); 36 if( ! (parentLocation == null || newFile.isAbsolute()) ) { 37 newFile = new File( getFile( parentLocation ).getParent(), newFilename ); 38 } 39 return newFile; 40 } 41 42 public String childLocation( String location, String parentLocation ) 43 { 44 return CLASS_ID+":"+childFile( location, parentLocation ).getAbsolutePath(); 45 } 46 47 public boolean exists( String location ) 48 { 49 return new File( location.substring( location.indexOf(':')+1 ) ).exists(); 50 } 51 52 public long lastModified( String location ) 53 { 54 return getFile( location ).lastModified(); 55 } 56 57 public String loadSource( String location ) 58 { 59 return TKLib.slurpfile( getFile( location ) ); 60 } 61 62 } 63 64 | Popular Tags |