View Javadoc

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 479058 2006-11-25 00:26:32Z henning $
29   */
30  public final class StringResource
31  {
32      /** template body */
33      private String body;
34      
35      /** encoding */
36      private String encoding;
37  
38      /** last modified ts */
39      private long lastModified;
40  
41      /**
42       * convenience constructor; sets body to 'body' and sets lastModified to now
43       * @param body
44       */
45      public StringResource(final String body, final String encoding)
46      {
47          setBody(body);
48          setEncoding(encoding);
49      }
50  
51      /**
52       * Sets the template body.
53       * @return String containing the template body.
54       */
55      public String getBody()
56      {
57          return body;
58      }
59  
60      /**
61       * Returns the modification date of the template.
62       * @return Modification date in milliseconds.
63       */
64      public long getLastModified()
65      {
66          return lastModified;
67      }
68  
69      /**
70       * Sets a new  value for the template body.
71       * @param body New body value
72       */
73      public void setBody(final String body)
74      {
75          this.body = body;
76          this.lastModified = System.currentTimeMillis();
77      }
78  
79      /**
80       * Changes the last modified parameter.
81       * @param lastModified The modification time in millis.
82       */
83      public void setLastModified(final long lastModified)
84      {
85          this.lastModified = lastModified;
86      }
87  
88      /**
89       * Returns the encoding of this String resource.
90       * 
91       * @return The encoding of this String resource.
92       */
93      public String getEncoding() {
94          return this.encoding;
95      }
96  
97      /**
98       * Sets the encoding of this string resource.
99       * 
100      * @param encoding The new encoding of this resource.
101      */
102     public void setEncoding(final String encoding)
103     {
104         this.encoding = encoding;
105     }
106 }