1 package org.apache.velocity.runtime.resource; 2 3 18 19 import org.apache.velocity.runtime.RuntimeServices; 20 import org.apache.velocity.runtime.RuntimeConstants; 21 22 import org.apache.velocity.runtime.resource.loader.ResourceLoader; 23 24 import org.apache.velocity.exception.ResourceNotFoundException; 25 import org.apache.velocity.exception.ParseErrorException; 26 27 36 public abstract class Resource 37 { 38 protected RuntimeServices rsvc = null; 39 40 45 protected ResourceLoader resourceLoader; 46 47 51 protected static final long MILLIS_PER_SECOND = 1000; 52 53 56 protected long modificationCheckInterval = 0; 57 58 61 protected long lastModified = 0; 62 63 67 protected long nextCheck = 0; 68 69 72 protected String name; 73 74 77 protected String encoding = RuntimeConstants.ENCODING_DEFAULT; 78 79 82 protected Object data = null; 83 84 87 public Resource() 88 { 89 } 90 91 public void setRuntimeServices( RuntimeServices rs ) 92 { 93 rsvc = rs; 94 } 95 96 109 public abstract boolean process() 110 throws ResourceNotFoundException, ParseErrorException, Exception ; 111 112 public boolean isSourceModified() 113 { 114 return resourceLoader.isSourceModified(this); 115 } 116 117 121 public void setModificationCheckInterval(long modificationCheckInterval) 122 { 123 this.modificationCheckInterval = modificationCheckInterval; 124 } 125 126 130 public boolean requiresChecking() 131 { 132 136 137 if (modificationCheckInterval <= 0 ) 138 { 139 return false; 140 } 141 142 145 146 return ( System.currentTimeMillis() >= nextCheck ); 147 } 148 149 153 public void touch() 154 { 155 nextCheck = System.currentTimeMillis() + ( MILLIS_PER_SECOND * modificationCheckInterval); 156 } 157 158 162 public void setName(String name) 163 { 164 this.name = name; 165 } 166 167 170 public String getName() 171 { 172 return name; 173 } 174 175 179 public void setEncoding( String encoding ) 180 { 181 this.encoding = encoding; 182 } 183 184 188 public String getEncoding() 189 { 190 return encoding; 191 } 192 193 194 198 public long getLastModified() 199 { 200 return lastModified; 201 } 202 203 207 public void setLastModified(long lastModified) 208 { 209 this.lastModified = lastModified; 210 } 211 212 216 public ResourceLoader getResourceLoader() 217 { 218 return resourceLoader; 219 } 220 221 226 public void setResourceLoader(ResourceLoader resourceLoader) 227 { 228 this.resourceLoader = resourceLoader; 229 } 230 231 235 public void setData(Object data) 236 { 237 this.data = data; 238 } 239 240 244 public Object getData() 245 { 246 return data; 247 } 248 } 249 | Popular Tags |