You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/05/03 14:16:38 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/generation FileGenerator.java
cziegeler 01/05/03 05:16:38
Modified: src/org/apache/cocoon/generation Tag: xml-cocoon2
FileGenerator.java
Log:
FileGenerator caches now local and distant files (via http)
Revision Changes Path
No revision
No revision
1.1.2.33 +21 -6 xml-cocoon/src/org/apache/cocoon/generation/Attic/FileGenerator.java
Index: FileGenerator.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/FileGenerator.java,v
retrieving revision 1.1.2.32
retrieving revision 1.1.2.33
diff -u -r1.1.2.32 -r1.1.2.33
--- FileGenerator.java 2001/04/30 14:17:21 1.1.2.32
+++ FileGenerator.java 2001/05/03 12:16:36 1.1.2.33
@@ -37,7 +37,7 @@
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.32 $ $Date: 2001/04/30 14:17:21 $
+ * @version CVS $Revision: 1.1.2.33 $ $Date: 2001/05/03 12:16:36 $
*/
public class FileGenerator extends ComposerGenerator
implements Cacheable {
@@ -46,6 +46,8 @@
private InputSource inputSource;
/** The system ID of the input source */
private String systemID;
+ /** Last modification date of the source */
+ private long lastModificationDate;
/**
* Set the current <code>ComponentManager</code> instance used by this
@@ -67,12 +69,26 @@
/**
* Setup the file generator.
+ * Try to get the last modification date of the source for caching.
*/
public void setup(EntityResolver resolver, Map objectModel, String src, Parameters par)
throws ProcessingException, SAXException, IOException {
super.setup(resolver, objectModel, src, par);
this.inputSource = super.resolver.resolveEntity(null, super.source);
this.systemID = this.inputSource.getSystemId();
+ if (this.systemID.startsWith("file:") == true) {
+ File xmlFile = new File(this.systemID.substring("file:".length()));
+ this.lastModificationDate = xmlFile.lastModified();
+ } else {
+ try {
+ java.net.URL u= new java.net.URL(this.systemID);
+ java.net.URLConnection conn = u.openConnection();
+ this.lastModificationDate = u.openConnection().getLastModified();
+ } catch (java.net.MalformedURLException local) {
+ // we ignore this at this stage
+ this.lastModificationDate = 0; // no caching!
+ }
+ }
}
/**
@@ -82,8 +98,8 @@
* @return The generated key hashes the src
*/
public long generateKey() {
- if (this.systemID.startsWith("file:") == true) {
- return HashUtil.hash(super.source);
+ if (this.lastModificationDate != 0) {
+ return HashUtil.hash(this.systemID);
}
return 0;
}
@@ -95,9 +111,8 @@
* component is currently not cacheable.
*/
public CacheValidity generateValidity() {
- if (this.systemID.startsWith("file:") == true) {
- File xmlFile = new File(this.systemID.substring("file:".length()));
- return new TimeStampCacheValidity(xmlFile.lastModified());
+ if (this.lastModificationDate != 0) {
+ return new TimeStampCacheValidity(this.lastModificationDate);
}
return null;
}
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org