01: /*
02: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/templates/TKTemplateFileLoader.java,v 1.7 2001/08/14 13:59:48 mischa Exp $
03: *
04: */
05: package com.teamkonzept.lib.templates;
06:
07: import java.io.*;
08:
09: 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 CLASS_ID = "file";
20:
21: public final static File getFile(String location) {
22: try {
23: return new File(location
24: .substring(location.indexOf(':') + 1));
25: } catch (Exception e) {
26: return null;
27: }
28: }
29:
30: public final static File childFile(String location,
31: String parentLocation) {
32: int newProtEnd = location.indexOf(':');
33: String newFilename = (newProtEnd < 0 ? location : location
34: .substring(newProtEnd + 1));
35: File newFile = new File(newFilename);
36: if (!(parentLocation == null || newFile.isAbsolute())) {
37: newFile = new File(getFile(parentLocation).getParent(),
38: newFilename);
39: }
40: return newFile;
41: }
42:
43: public String childLocation(String location, String parentLocation) {
44: return CLASS_ID + ":"
45: + childFile(location, parentLocation).getAbsolutePath();
46: }
47:
48: public boolean exists(String location) {
49: return new File(location.substring(location.indexOf(':') + 1))
50: .exists();
51: }
52:
53: public long lastModified(String location) {
54: return getFile(location).lastModified();
55: }
56:
57: public String loadSource(String location) {
58: return TKLib.slurpfile(getFile(location));
59: }
60:
61: }
|