01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.template;
14:
15: import java.io.File;
16: import java.io.FileInputStream;
17: import java.io.IOException;
18: import java.io.InputStream;
19: import java.io.Serializable;
20:
21: /**
22: * A <CODE>FileDataSource</CODE> implements a TemplateSource
23: * for a file.
24: *
25: * @author <A href="mailto:H.Zeller@acm.org">Henner Zeller</A>
26: */
27: public class FileTemplateSource implements TemplateSource, Serializable {
28: private File file;
29: protected String canonicalName = null;
30:
31: public FileTemplateSource(File f) {
32: this .file = f;
33: if (file != null) {
34: try {
35: canonicalName = "file:" + file.getCanonicalPath();
36: } catch (IOException e) {
37: // should never happen for files ..
38: }
39: }
40: }
41:
42: /**
43: * Returns a canonical name of this DataSource.
44: */
45: public String getCanonicalName() {
46: return canonicalName;
47: }
48:
49: /**
50: * Returns the time the content of this File
51: * was last modified.
52: * <p/>
53: * The return value is used to decide whether to reparse a
54: * Source or not. Reparsing is done if the value returned
55: * here differs from the value returned at the last processing
56: * time.
57: *
58: * @return long a modification time
59: */
60: public long lastModified() {
61: return file.lastModified();
62: }
63:
64: /**
65: * Gets an InputStream of the File.
66: */
67: public InputStream getInputStream() throws IOException {
68: return new FileInputStream(file);
69: }
70: }
|