Author: remy.maucherat(a)jboss.com
Date: 2008-05-30 12:39:59 -0400 (Fri, 30 May 2008)
New Revision: 652
Modified:
trunk/java/org/apache/naming/resources/DirContextURLConnection.java
Log:
- Better date format.
Modified: trunk/java/org/apache/naming/resources/DirContextURLConnection.java
===================================================================
--- trunk/java/org/apache/naming/resources/DirContextURLConnection.java 2008-05-30
16:03:08 UTC (rev 651)
+++ trunk/java/org/apache/naming/resources/DirContextURLConnection.java 2008-05-30
16:39:59 UTC (rev 652)
@@ -17,11 +17,11 @@
package org.apache.naming.resources;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileNotFoundException;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Collections;
@@ -30,15 +30,16 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
+
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.NameClassPair;
-import javax.naming.directory.DirContext;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
import org.apache.naming.JndiPermission;
-import org.apache.naming.resources.Resource;
-import org.apache.naming.resources.ResourceAttributes;
+import org.apache.tomcat.util.http.FastHttpDateFormat;
/**
* Connection to a JNDI directory context.
@@ -222,6 +223,17 @@
}
+ protected String getHeaderValueAsString(Object headerValue) {
+ if (headerValue == null) return null;
+ if (headerValue instanceof Date) {
+ // return date strings (ie Last-Modified) in HTTP format, rather
+ // than Java format
+ return FastHttpDateFormat.formatDate(((Date)headerValue).getTime(), null);
+ }
+ return headerValue.toString();
+ }
+
+
/**
* Returns an unmodifiable Map of the header fields.
*/
@@ -248,7 +260,8 @@
ArrayList attributeValueList = new ArrayList(attribute.size());
NamingEnumeration attributeValues = attribute.getAll();
while (attributeValues.hasMore()) {
- attributeValueList.add(attributeValues.next().toString());
+ Object attrValue = attributeValues.next();
+ attributeValueList.add(getHeaderValueAsString(attrValue));
}
attributeValueList.trimToSize(); // should be a no-op if attribute.size()
didn't lie
headerFields.put(attributeID,
Collections.unmodifiableList(attributeValueList));
@@ -285,7 +298,7 @@
if (attributeID.equalsIgnoreCase(name)) {
Attribute attribute = attributes.get(attributeID);
if (attribute == null) return null;
- return attribute.get(attribute.size()-1).toString();
+ return getHeaderValueAsString(attribute.get(attribute.size()-1));
}
}
} catch (NamingException ne) {
Show replies by date