remm 2004/07/13 02:40:48
Modified: catalina/src/share/org/apache/naming/resources
ResourceAttributes.java ProxyDirContext.java
Log:
- Expose cache lookup and cache entries. The standard lookup methods will work as
usual.
- Add extra fields in the attributes.
Revision Changes Path
1.4 +75 -2
jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ResourceAttributes.java
Index: ResourceAttributes.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ResourceAttributes.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResourceAttributes.java 27 Feb 2004 14:58:54 -0000 1.3
+++ ResourceAttributes.java 13 Jul 2004 09:40:47 -0000 1.4
@@ -20,6 +20,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
+import java.util.TimeZone;
import java.util.Vector;
import javax.naming.NamingEnumeration;
@@ -138,12 +139,28 @@
*/
protected static final SimpleDateFormat formats[] = {
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
- new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
};
+ protected final static TimeZone gmtZone = TimeZone.getTimeZone("GMT");
+
+
+ /**
+ * GMT timezone - all HTTP dates are on GMT
+ */
+ static {
+
+ format.setTimeZone(gmtZone);
+
+ formats[0].setTimeZone(gmtZone);
+ formats[1].setTimeZone(gmtZone);
+ formats[2].setTimeZone(gmtZone);
+
+ }
+
+
// ----------------------------------------------------------- Constructors
@@ -200,6 +217,18 @@
*/
protected Date lastModifiedDate = null;
+
+ /**
+ * Last modified date in HTTP format.
+ */
+ protected String lastModifiedHttp = null;
+
+
+ /**
+ * MIME type.
+ */
+ protected String mimeType = null;
+
/**
* Name.
@@ -553,6 +582,50 @@
attributes.put(LAST_MODIFIED, lastModifiedDate);
}
+
+ /**
+ * @return Returns the lastModifiedHttp.
+ */
+ public String getLastModifiedHttp() {
+ if (lastModifiedHttp != null)
+ return lastModifiedHttp;
+ Date modifiedDate = getLastModifiedDate();
+ if (modifiedDate == null) {
+ modifiedDate = getCreationDate();
+ }
+ if (modifiedDate == null) {
+ modifiedDate = new Date();
+ }
+ synchronized (format) {
+ lastModifiedHttp = format.format(modifiedDate);
+ }
+ return lastModifiedHttp;
+ }
+
+
+ /**
+ * @param lastModifiedHttp The lastModifiedHttp to set.
+ */
+ public void setLastModifiedHttp(String lastModifiedHttp) {
+ this.lastModifiedHttp = lastModifiedHttp;
+ }
+
+
+ /**
+ * @return Returns the mimeType.
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
+
+
+ /**
+ * @param mimeType The mimeType to set.
+ */
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
/**
* Get name.
1.16 +53 -6
jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java
Index: ProxyDirContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ProxyDirContext.java 27 Feb 2004 14:58:54 -0000 1.15
+++ ProxyDirContext.java 13 Jul 2004 09:40:47 -0000 1.16
@@ -252,6 +252,9 @@
throws NamingException {
CacheEntry entry = cacheLookup(name.toString());
if (entry != null) {
+ if (!entry.exists) {
+ throw notFoundException;
+ }
if (entry.resource != null) {
// Check content caching.
return entry.resource;
@@ -278,6 +281,9 @@
throws NamingException {
CacheEntry entry = cacheLookup(name);
if (entry != null) {
+ if (!entry.exists) {
+ throw notFoundException;
+ }
if (entry.resource != null) {
return entry.resource;
} else {
@@ -796,6 +802,9 @@
throws NamingException {
CacheEntry entry = cacheLookup(name.toString());
if (entry != null) {
+ if (!entry.exists) {
+ throw notFoundException;
+ }
return entry.attributes;
}
Attributes attributes = dirContext.getAttributes(parseName(name));
@@ -817,6 +826,9 @@
throws NamingException {
CacheEntry entry = cacheLookup(name);
if (entry != null) {
+ if (!entry.exists) {
+ throw notFoundException;
+ }
return entry.attributes;
}
Attributes attributes = dirContext.getAttributes(parseName(name));
@@ -1351,6 +1363,45 @@
}
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Retrieves the named object as a cache entry, without any exception.
+ *
+ * @param name the name of the object to look up
+ * @return the cache entry bound to name
+ */
+ public CacheEntry lookupCache(String name) {
+ CacheEntry entry = cacheLookup(name);
+ if (entry == null) {
+ entry = new CacheEntry();
+ entry.name = name;
+ try {
+ Object object = dirContext.lookup(parseName(name));
+ if (object instanceof InputStream) {
+ entry.resource = new Resource((InputStream) object);
+ } else if (object instanceof DirContext) {
+ entry.context = (DirContext) object;
+ } else if (object instanceof Resource) {
+ entry.resource = (Resource) object;
+ } else {
+ entry.resource = new Resource(new ByteArrayInputStream
+ (object.toString().getBytes()));
+ }
+ Attributes attributes = dirContext.getAttributes(parseName(name));
+ if (!(attributes instanceof ResourceAttributes)) {
+ attributes = new ResourceAttributes(attributes);
+ }
+ entry.attributes = (ResourceAttributes) attributes;
+ } catch (NamingException e) {
+ entry.exists = false;
+ }
+ }
+ return entry;
+ }
+
+
// ------------------------------------------------------ Protected Methods
@@ -1379,8 +1430,7 @@
/**
* Lookup in cache.
*/
- protected CacheEntry cacheLookup(String name)
- throws NamingException {
+ protected CacheEntry cacheLookup(String name) {
if (cache == null)
return (null);
if (name == null)
@@ -1407,9 +1457,6 @@
}
}
cacheEntry.accessCount++;
- }
- if (!cacheEntry.exists) {
- throw notFoundException;
}
return (cacheEntry);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]