Source Code Cross Referenced for Resource.java in  » Template-Engine » Velocity » org » apache » velocity » runtime » resource » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » Velocity » org.apache.velocity.runtime.resource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.velocity.runtime.resource;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.    
020:         */
021:
022:        import org.apache.velocity.runtime.RuntimeServices;
023:        import org.apache.velocity.runtime.RuntimeConstants;
024:
025:        import org.apache.velocity.runtime.resource.loader.ResourceLoader;
026:
027:        import org.apache.velocity.exception.ResourceNotFoundException;
028:        import org.apache.velocity.exception.ParseErrorException;
029:
030:        /**
031:         * This class represent a general text resource that
032:         * may have been retrieved from any number of possible
033:         * sources.
034:         *
035:         * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
036:         * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
037:         * @version $Id: Resource.java 463298 2006-10-12 16:10:32Z henning $
038:         */
039:        public abstract class Resource {
040:            protected RuntimeServices rsvc = null;
041:
042:            /**
043:             * The template loader that initially loaded the input
044:             * stream for this template, and knows how to check the
045:             * source of the input stream for modification.
046:             */
047:            protected ResourceLoader resourceLoader;
048:
049:            /**
050:             * The number of milliseconds in a minute, used to calculate the
051:             * check interval.
052:             */
053:            protected static final long MILLIS_PER_SECOND = 1000;
054:
055:            /**
056:             * How often the file modification time is checked (in seconds).
057:             */
058:            protected long modificationCheckInterval = 0;
059:
060:            /**
061:             * The file modification time (in milliseconds) for the cached template.
062:             */
063:            protected long lastModified = 0;
064:
065:            /**
066:             * The next time the file modification time will be checked (in
067:             * milliseconds).
068:             */
069:            protected long nextCheck = 0;
070:
071:            /**
072:             *  Name of the resource
073:             */
074:            protected String name;
075:
076:            /**
077:             *  Character encoding of this resource
078:             */
079:            protected String encoding = RuntimeConstants.ENCODING_DEFAULT;
080:
081:            /**
082:             *  Resource might require ancillary storage of some kind
083:             */
084:            protected Object data = null;
085:
086:            /**
087:             *  Default constructor
088:             */
089:            public Resource() {
090:            }
091:
092:            /**
093:             * @param rs
094:             */
095:            public void setRuntimeServices(RuntimeServices rs) {
096:                rsvc = rs;
097:            }
098:
099:            /**
100:             * Perform any subsequent processing that might need
101:             * to be done by a resource. In the case of a template
102:             * the actual parsing of the input stream needs to be
103:             * performed.
104:             *
105:             * @return Whether the resource could be processed successfully.
106:             * For a {@link org.apache.velocity.Template} or {@link
107:             * org.apache.velocity.runtime.resource.ContentResource}, this
108:             * indicates whether the resource could be read.
109:             * @exception ResourceNotFoundException Similar in semantics as
110:             * returning <code>false</code>.
111:             * @throws ParseErrorException
112:             * @throws Exception
113:             */
114:            public abstract boolean process() throws ResourceNotFoundException,
115:                    ParseErrorException, Exception;
116:
117:            /**
118:             * @return True if source has been modified.
119:             */
120:            public boolean isSourceModified() {
121:                return resourceLoader.isSourceModified(this );
122:            }
123:
124:            /**
125:             * Set the modification check interval.
126:             * @param modificationCheckInterval The interval (in seconds).
127:             */
128:            public void setModificationCheckInterval(
129:                    long modificationCheckInterval) {
130:                this .modificationCheckInterval = modificationCheckInterval;
131:            }
132:
133:            /**
134:             * Is it time to check to see if the resource
135:             * source has been updated?
136:             * @return True if resource must be checked.
137:             */
138:            public boolean requiresChecking() {
139:                /*
140:                 *  short circuit this if modificationCheckInterval == 0
141:                 *  as this means "don't check"
142:                 */
143:
144:                if (modificationCheckInterval <= 0) {
145:                    return false;
146:                }
147:
148:                /*
149:                 *  see if we need to check now
150:                 */
151:
152:                return (System.currentTimeMillis() >= nextCheck);
153:            }
154:
155:            /**
156:             * 'Touch' this template and thereby resetting
157:             * the nextCheck field.
158:             */
159:            public void touch() {
160:                nextCheck = System.currentTimeMillis()
161:                        + (MILLIS_PER_SECOND * modificationCheckInterval);
162:            }
163:
164:            /**
165:             * Set the name of this resource, for example
166:             * test.vm.
167:             * @param name
168:             */
169:            public void setName(String name) {
170:                this .name = name;
171:            }
172:
173:            /**
174:             * Get the name of this template.
175:             * @return The name of this template.
176:             */
177:            public String getName() {
178:                return name;
179:            }
180:
181:            /**
182:             *  set the encoding of this resource
183:             *  for example, "ISO-8859-1"
184:             * @param encoding
185:             */
186:            public void setEncoding(String encoding) {
187:                this .encoding = encoding;
188:            }
189:
190:            /**
191:             *  get the encoding of this resource
192:             *  for example, "ISO-8859-1"
193:             * @return The encoding of this resource.
194:             */
195:            public String getEncoding() {
196:                return encoding;
197:            }
198:
199:            /**
200:             * Return the lastModifed time of this
201:             * resource.
202:             * @return The lastModifed time of this resource.
203:             */
204:            public long getLastModified() {
205:                return lastModified;
206:            }
207:
208:            /**
209:             * Set the last modified time for this
210:             * resource.
211:             * @param lastModified
212:             */
213:            public void setLastModified(long lastModified) {
214:                this .lastModified = lastModified;
215:            }
216:
217:            /**
218:             * Return the template loader that pulled
219:             * in the template stream
220:             * @return The resource loader for this resource.
221:             */
222:            public ResourceLoader getResourceLoader() {
223:                return resourceLoader;
224:            }
225:
226:            /**
227:             * Set the template loader for this template. Set
228:             * when the Runtime determines where this template
229:             * came from the list of possible sources.
230:             * @param resourceLoader
231:             */
232:            public void setResourceLoader(ResourceLoader resourceLoader) {
233:                this .resourceLoader = resourceLoader;
234:            }
235:
236:            /**
237:             * Set arbitrary data object that might be used
238:             * by the resource.
239:             * @param data
240:             */
241:            public void setData(Object data) {
242:                this .data = data;
243:            }
244:
245:            /**
246:             * Get arbitrary data object that might be used
247:             * by the resource.
248:             * @return The data object for this resource.
249:             */
250:            public Object getData() {
251:                return data;
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.