KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: StringTemplateSource.java,v 1.5 2005/05/13 15:47:08 blueshift 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.ByteArrayInputStream JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.io.InputStream JavaDoc;
19
20
21 /**
22  * A simple template source, which provides a template from a String
23  *
24  * @author <a HREF="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
25  * @version $Revision: 1.5 $
26  */

27 public class StringTemplateSource implements TemplateSource {
28
29     private static long COUNTER = 0;
30
31     private static final synchronized long getNextId() {
32         return COUNTER++;
33     }
34
35     /**
36      * Try to make generate a unique canonical name.
37      */

38     private final String JavaDoc canonicalName = getClass().getName() + "_" + getNextId();
39
40     private String JavaDoc template;
41
42     private long lastModified;
43
44
45     public StringTemplateSource() {
46     }
47
48
49     public StringTemplateSource(String JavaDoc template) {
50         setTemplate(template);
51     }
52
53     public final void setTemplate(String JavaDoc t) {
54         this.template = t;
55         lastModified = System.currentTimeMillis();
56     }
57     
58     // Implementation of org.wings.template.TemplateSource
59

60     public long lastModified() {
61         return lastModified;
62     }
63
64     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
65         return new ByteArrayInputStream JavaDoc(template.getBytes());
66     }
67
68     public final String JavaDoc getCanonicalName() {
69         return canonicalName;
70     }
71
72 }// StringTemplateSource
73

74
Popular Tags