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 org.wings.session.SessionManager;
16: import java.io.ByteArrayInputStream;
17: import java.io.IOException;
18: import java.io.InputStream;
19: import java.io.Serializable;
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: */
26: public class StringTemplateSource implements TemplateSource,
27: Serializable {
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 canonicalName = getClass().getName() + "_"
39: + getNextId();
40:
41: private String template;
42:
43: private long lastModified;
44:
45: public StringTemplateSource() {
46: }
47:
48: public StringTemplateSource(String template) {
49: setTemplate(template);
50: }
51:
52: public final void setTemplate(String t) {
53: this .template = t;
54: lastModified = System.currentTimeMillis();
55: }
56:
57: // Implementation of org.wings.template.TemplateSource
58:
59: public long lastModified() {
60: return lastModified;
61: }
62:
63: public InputStream getInputStream() throws IOException {
64: return new ByteArrayInputStream(template
65: .getBytes(SessionManager.getSession()
66: .getCharacterEncoding()));
67: }
68:
69: public final String getCanonicalName() {
70: return canonicalName;
71: }
72:
73: }// StringTemplateSource
|