Source Code Cross Referenced for ResourceLoader.java in  » Template-Engine » Velocity » org » apache » velocity » runtime » resource » loader » 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.loader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.velocity.runtime.resource.loader;
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 java.io.InputStream;
023:
024:        import org.apache.velocity.runtime.RuntimeServices;
025:        import org.apache.velocity.runtime.log.Log;
026:        import org.apache.velocity.runtime.resource.Resource;
027:        import org.apache.velocity.runtime.resource.ResourceCacheImpl;
028:
029:        import org.apache.velocity.exception.ResourceNotFoundException;
030:
031:        import org.apache.commons.collections.ExtendedProperties;
032:
033:        /**
034:         * This is abstract class the all text resource loaders should
035:         * extend.
036:         *
037:         * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
038:         * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
039:         * @version $Id: ResourceLoader.java 463298 2006-10-12 16:10:32Z henning $
040:         */
041:        public abstract class ResourceLoader {
042:            /**
043:             * Does this loader want templates produced with it
044:             * cached in the Runtime.
045:             */
046:            protected boolean isCachingOn = false;
047:
048:            /**
049:             * This property will be passed on to the templates
050:             * that are created with this loader.
051:             */
052:            protected long modificationCheckInterval = 2;
053:
054:            /**
055:             * Class name for this loader, for logging/debuggin
056:             * purposes.
057:             */
058:            protected String className = null;
059:
060:            protected RuntimeServices rsvc = null;
061:            protected Log log = null;
062:
063:            /**
064:             * This initialization is used by all resource
065:             * loaders and must be called to set up common
066:             * properties shared by all resource loaders
067:             * @param rs
068:             * @param configuration
069:             */
070:            public void commonInit(RuntimeServices rs,
071:                    ExtendedProperties configuration) {
072:                this .rsvc = rs;
073:                this .log = rsvc.getLog();
074:
075:                /*
076:                 *  these two properties are not required for all loaders.
077:                 *  For example, for ClasspathLoader, what would cache mean?
078:                 *  so adding default values which I think are the safest
079:                 *
080:                 *  don't cache, and modCheckInterval irrelevant...
081:                 */
082:
083:                try {
084:                    isCachingOn = configuration.getBoolean("cache", false);
085:                } catch (Exception e) {
086:                    isCachingOn = false;
087:                    log.error("Exception using default of '" + isCachingOn
088:                            + '\'', e);
089:                }
090:                try {
091:                    modificationCheckInterval = configuration.getLong(
092:                            "modificationCheckInterval", 0);
093:                } catch (Exception e) {
094:                    modificationCheckInterval = 0;
095:                    log.error("Exception using default of '"
096:                            + modificationCheckInterval + '\'', e);
097:                }
098:
099:                /*
100:                 * this is a must!
101:                 */
102:                className = ResourceCacheImpl.class.getName();
103:                try {
104:                    className = configuration.getString("class", className);
105:                } catch (Exception e) {
106:                    log.error(
107:                            "Exception using default of '" + className + '\'',
108:                            e);
109:                }
110:            }
111:
112:            /**
113:             * Initialize the template loader with a
114:             * a resources class.
115:             * @param configuration
116:             */
117:            public abstract void init(ExtendedProperties configuration);
118:
119:            /**
120:             * Get the InputStream that the Runtime will parse
121:             * to create a template.
122:             * @param source
123:             * @return The input stream for the requested resource.
124:             * @throws ResourceNotFoundException
125:             */
126:            public abstract InputStream getResourceStream(String source)
127:                    throws ResourceNotFoundException;
128:
129:            /**
130:             * Given a template, check to see if the source of InputStream
131:             * has been modified.
132:             * @param resource
133:             * @return True if the resource has been modified.
134:             */
135:            public abstract boolean isSourceModified(Resource resource);
136:
137:            /**
138:             * Get the last modified time of the InputStream source
139:             * that was used to create the template. We need the template
140:             * here because we have to extract the name of the template
141:             * in order to locate the InputStream source.
142:             * @param resource
143:             * @return Time in millis when the resource has been modified.
144:             */
145:            public abstract long getLastModified(Resource resource);
146:
147:            /**
148:             * Return the class name of this resource Loader
149:             * @return Class name of the resource loader.
150:             */
151:            public String getClassName() {
152:                return className;
153:            }
154:
155:            /**
156:             * Set the caching state. If true, then this loader
157:             * would like the Runtime to cache templates that
158:             * have been created with InputStreams provided
159:             * by this loader.
160:             * @param value
161:             */
162:            public void setCachingOn(boolean value) {
163:                isCachingOn = value;
164:            }
165:
166:            /**
167:             * The Runtime uses this to find out whether this
168:             * template loader wants the Runtime to cache
169:             * templates created with InputStreams provided
170:             * by this loader.
171:             * @return True if this resource loader caches.
172:             */
173:            public boolean isCachingOn() {
174:                return isCachingOn;
175:            }
176:
177:            /**
178:             * Set the interval at which the InputStream source
179:             * should be checked for modifications.
180:             * @param modificationCheckInterval
181:             */
182:            public void setModificationCheckInterval(
183:                    long modificationCheckInterval) {
184:                this .modificationCheckInterval = modificationCheckInterval;
185:            }
186:
187:            /**
188:             * Get the interval at which the InputStream source
189:             * should be checked for modifications.
190:             * @return The modification check interval.
191:             */
192:            public long getModificationCheckInterval() {
193:                return modificationCheckInterval;
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.