Index: DatabaseReader.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/reading/DatabaseReader.java,v
retrieving revision 1.2.2.8
diff -u -r1.2.2.8 DatabaseReader.java
--- DatabaseReader.java	2001/10/15 13:40:39	1.2.2.8
+++ DatabaseReader.java	2001/10/24 17:57:04
@@ -38,9 +38,10 @@
 /**
  * This Reader pulls a resource from a database.  It is configured with
  * the Connection to use, parameters specify the table and column
- * to pull the image from, and source specifies the source key information.
+ * to pull the document/image from, and source specifies the source key information.
  *
  * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
+ * @author <a href="mailto:bertram@n-bis.de">Klaus Bertram</a>
  */
 public class DatabaseReader extends AbstractReader implements Composable, Configurable, Disposable, Cacheable, Poolable {
     private ComponentSelector dbselector;
@@ -51,6 +52,8 @@
     private DataSourceComponent datasource = null;
     private boolean doCommit = false;
     private boolean defaultCache = true;
+    private String mimeType;
+    private long expires = -1;
 
     private ComponentManager manager;
 
@@ -66,6 +69,9 @@
     /**
      * Configure the <code>Reader</code> so that we can use the same database
      * for all instances.
+     * <pre>
+     *   &lt;use-connection&gt;database_pool_name&lt;/use-connection&gt;
+     * </pre>
      */
     public void configure(Configuration conf) throws ConfigurationException {
         this.dsn = conf.getChild("use-connection").getValue();
@@ -81,6 +87,7 @@
         super.setup(resolver, objectModel, src, par);
 
         try {
+            getLogger().debug("Database dsn: "+dsn);
             this.datasource = (DataSourceComponent) dbselector.select(dsn);
             this.con = datasource.getConnection();
 
@@ -90,15 +97,27 @@
 
             PreparedStatement statement = con.prepareStatement(getQuery());
             statement.setString(1, this.source);
+
             ResultSet set = statement.executeQuery();
             if (set.next() == false) throw new ResourceNotFoundException("There is no resource with that key");
+            
+            if (this.parameters.getParameter("content-type", null) != null){
+              this.mimeType=set.getString(this.parameters.getParameter("content-type", null));
+            } else {
+              this.mimeType = null;
+            }
+            getLogger().debug("mimeType: "+this.mimeType);
+
+            if (this.parameters.getParameter("expires", null) != null){
+              this.expires=set.getLong(this.parameters.getParameter("expires", null));
+            }
+            getLogger().debug("expires: "+this.expires);
 
+            this.resource = set.getBlob(1);
             Response response = (Response) objectModel.get(Constants.RESPONSE_OBJECT);
             Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
-
+            
             if (this.modifiedSince(set, request, response)) {
-                this.resource = set.getBlob(1);
-
                 if (this.resource == null) {
                     throw new ResourceNotFoundException("There is no image with that key");
                 }
@@ -133,8 +152,8 @@
      *
      * <pre>
      *   &lt;parameter name="last-modified" value="database_timestamp_column_name"/&gt;
-     *   &lt;parameter name="content-type" value="content_mime_type"/&gt;
-     *   &lt;parameter name="expires" value="number_of_millis_before_refresh"/&gt;
+     *   &lt;parameter name="content-type" value="database_enum_column_name or database_string_column_name"/&gt;
+     *   &lt;parameter name="expires" value="database_bigint_column_name"/&gt;
      *   &lt;parameter name="where" value="alternate_key = 'foo'"/&gt;
      *   &lt;parameter name="order-by" value="alternate_key DESC"/&gt;
      * </pre>
@@ -176,6 +195,9 @@
         }
 
         String date = this.parameters.getParameter("last-modified", null);
+        String contentType = this.parameters.getParameter("content-type", null);
+        String expire = this.parameters.getParameter("expires", null);
+
         StringBuffer query = new StringBuffer("SELECT ");
 
         query.append(column);
@@ -183,6 +205,14 @@
         if (date != null) {
             query.append(", ").append(date);
         }
+        
+        if (contentType != null) {
+            query.append(", ").append(contentType);
+        }
+        
+        if (expire != null) {
+            query.append(", ").append(expire);
+        }
 
         if (null != orderBy) {
             query.append(", ");
@@ -225,7 +255,8 @@
         String lastModified = this.parameters.getParameter("last-modified", null);
 
         if (lastModified != null) {
-            Timestamp modified = set.getTimestamp(lastModified, null);
+            //changed to bellow mySQL throw exeption with set.getTimestamp(lastModified, null);
+            Timestamp modified = set.getTimestamp(lastModified);
             if (null != modified) {
                 this.lastModified = modified.getTime();
             } else {
@@ -253,10 +284,12 @@
 
         InputStream is = new BufferedInputStream(this.resource.getBinaryStream());
 
-        long expires = parameters.getParameterAsInteger("expires", -1);
+        if (this.expires > 0) {
+            response.setDateHeader("Expires", new Date().getTime() + this.expires);
+        }
 
-        if (expires > 0) {
-            response.setDateHeader("Expires", new Date().getTime() + expires);
+        if (this.mimeType != null){
+          response.setHeader("Content-Type",this.mimeType);
         }
 
         response.setHeader("Accept-Ranges", "bytes");
@@ -339,7 +372,7 @@
     }
 
     public String getMimeType() {
-        return this.parameters.getParameter("content-type", super.getMimeType());
+        return this.mimeType;
     }
 
 }
