KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > lib > templates > TKTemplateFileLoader


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/templates/TKTemplateFileLoader.java,v 1.7 2001/08/14 13:59:48 mischa Exp $
3  *
4  */

5 package com.teamkonzept.lib.templates;
6
7 import java.io.*;
8
9 import com.teamkonzept.lib.*;
10
11 /**
12     Klasse, die Templates aus dem Filesystem lädt
13     was soll das, mit einer URL ist man davon erstmal unabhängig - bis auf DB
14  * @author $Author: mischa $
15  * @version $Revision: 1.7 $
16 */

17 public class TKTemplateFileLoader implements TKTemplateSourceLoader {
18     
19     public final static String JavaDoc CLASS_ID = "file";
20     
21     public final static File getFile( String JavaDoc location )
22     {
23         try {
24             return new File( location.substring( location.indexOf(':')+1 ) );
25         }
26         catch( Exception JavaDoc e ) {
27             return null;
28         }
29     }
30     
31     public final static File childFile( String JavaDoc location, String JavaDoc parentLocation )
32     {
33         int newProtEnd = location.indexOf(':');
34         String JavaDoc 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 JavaDoc childLocation( String JavaDoc location, String JavaDoc parentLocation )
43     {
44         return CLASS_ID+":"+childFile( location, parentLocation ).getAbsolutePath();
45     }
46     
47     public boolean exists( String JavaDoc location )
48     {
49         return new File( location.substring( location.indexOf(':')+1 ) ).exists();
50     }
51     
52     public long lastModified( String JavaDoc location )
53     {
54         return getFile( location ).lastModified();
55     }
56     
57     public String JavaDoc loadSource( String JavaDoc location )
58     {
59         return TKLib.slurpfile( getFile( location ) );
60     }
61     
62 }
63
64
Popular Tags