KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > template > FileTemplateSource


1 /*
2  * $Id: FileTemplateSource.java,v 1.3 2004/12/01 07:54:28 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.template;
15
16 import java.io.File JavaDoc;
17 import java.io.FileInputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
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  * @version $Revision: 1.3 $ $Date: 2004/12/01 07:54:28 $
27  */

28 public class FileTemplateSource implements TemplateSource {
29     private File JavaDoc file;
30     protected String JavaDoc canonicalName = null;
31
32     public FileTemplateSource(File JavaDoc f) {
33         this.file = f;
34         if (file != null) {
35             try {
36                 canonicalName = "file:" + file.getCanonicalPath();
37             } catch (IOException JavaDoc e) {
38                 // should never happen for files ..
39
}
40         }
41     }
42
43     /**
44      * Returns a canonical name of this DataSource.
45      */

46     public String JavaDoc getCanonicalName() {
47         return canonicalName;
48     }
49
50     /**
51      * Returns the time the content of this File
52      * was last modified.
53      * <p/>
54      * The return value is used to decide whether to reparse a
55      * Source or not. Reparsing is done if the value returned
56      * here differs from the value returned at the last processing
57      * time.
58      *
59      * @return long a modification time
60      */

61     public long lastModified() {
62         return file.lastModified();
63     }
64
65     /**
66      * Gets an InputStream of the File.
67      */

68     public InputStream JavaDoc getInputStream()
69             throws IOException JavaDoc {
70         return new FileInputStream JavaDoc(file);
71     }
72 }
73
74
75
76
77
Popular Tags