1 package org.apache.velocity.runtime.resource.util;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 /**
23 * Wrapper for Strings containing templates, allowing to add additional meta
24 * data like timestamps.
25 *
26 * @author <a href="mailto:eelco.hillenius@openedge.nl">Eelco Hillenius</a>
27 * @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
28 * @version $Id: StringResource.java 685685 2008-08-13 21:43:27Z nbubna $
29 * @since 1.5
30 */
31 public final class StringResource
32 {
33 /** template body */
34 private String body;
35
36 /** encoding */
37 private String encoding;
38
39 /** last modified ts */
40 private long lastModified;
41
42 /**
43 * convenience constructor; sets body to 'body' and sets lastModified to now
44 * @param body
45 */
46 public StringResource(final String body, final String encoding)
47 {
48 setBody(body);
49 setEncoding(encoding);
50 }
51
52 /**
53 * Sets the template body.
54 * @return String containing the template body.
55 */
56 public String getBody()
57 {
58 return body;
59 }
60
61 /**
62 * Returns the modification date of the template.
63 * @return Modification date in milliseconds.
64 */
65 public long getLastModified()
66 {
67 return lastModified;
68 }
69
70 /**
71 * Sets a new value for the template body.
72 * @param body New body value
73 */
74 public void setBody(final String body)
75 {
76 this.body = body;
77 this.lastModified = System.currentTimeMillis();
78 }
79
80 /**
81 * Changes the last modified parameter.
82 * @param lastModified The modification time in millis.
83 */
84 public void setLastModified(final long lastModified)
85 {
86 this.lastModified = lastModified;
87 }
88
89 /**
90 * Returns the encoding of this String resource.
91 *
92 * @return The encoding of this String resource.
93 */
94 public String getEncoding() {
95 return this.encoding;
96 }
97
98 /**
99 * Sets the encoding of this string resource.
100 *
101 * @param encoding The new encoding of this resource.
102 */
103 public void setEncoding(final String encoding)
104 {
105 this.encoding = encoding;
106 }
107 }