cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/reading DatabaseReader.java
Date Fri, 31 Jan 2003 16:01:42 GMT
haul        2003/01/31 08:01:42

  Modified:    src/blocks/databases/java/org/apache/cocoon/reading
                        DatabaseReader.java
  Log:
  optionally read mimetype from database
  
  Revision  Changes    Path
  1.3       +26 -6     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/reading/DatabaseReader.java
  
  Index: DatabaseReader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/reading/DatabaseReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatabaseReader.java	7 Jan 2003 23:56:09 -0000	1.2
  +++ DatabaseReader.java	31 Jan 2003 16:01:42 -0000	1.3
  @@ -53,7 +53,6 @@
   import java.io.BufferedInputStream;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.sql.Blob;
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
  @@ -100,9 +99,11 @@
       private ComponentSelector dbselector;
       private String dsn;
       private long lastModified = System.currentTimeMillis();
  -    private Blob resource = null;
  +    private InputStream resource = null; // because HSQL doesn't yet implement getBlob()
       private Connection con = null;
       private DataSourceComponent datasource = null;
  +    private String mimeType = null;
  +    private int typeColumn = 0;
       private boolean doCommit = false;
       private boolean defaultCache = true;
   
  @@ -149,7 +150,10 @@
               Request request = ObjectModelHelper.getRequest(objectModel);
   
               if (this.modifiedSince(set, request, response)) {
  -                this.resource = set.getBlob(1);
  +                this.resource = set.getBinaryStream(1);
  +                if (this.typeColumn != 0) {
  +                    this.mimeType = set.getString(this.typeColumn);
  +                }
   
                   if (this.resource == null) {
                       throw new ResourceNotFoundException("There is no resource with that
key");
  @@ -184,6 +188,7 @@
        * <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="type-column" value="database_content_mime_type_column"/&gt;
        *   &lt;parameter name="expires" value="number_of_millis_before_refresh"/&gt;
        *   &lt;parameter name="where" value="alternate_key = 'foo'"/&gt;
        *   &lt;parameter name="order-by" value="alternate_key DESC"/&gt;
  @@ -218,6 +223,8 @@
           String key = this.parameters.getParameter("key", null);
           String where = this.parameters.getParameter("where", null);
           String orderBy = this.parameters.getParameter("order-by", null);
  +        String typeColumn = this.parameters.getParameter("type-column", null);
  +        int columnNo = 1;
   
           if (table == null || column == null || key==null) {
               throw new ProcessingException("We are missing a required parameter.  Please
include 'table', 'image', and 'key'");
  @@ -227,9 +234,11 @@
           StringBuffer query = new StringBuffer("SELECT ");
   
           query.append(column);
  +        columnNo++;
   
           if (date != null) {
               query.append(", ").append(date);
  +            columnNo++;
           }
   
           if (null != orderBy) {
  @@ -240,6 +249,13 @@
               } else {
                   query.append(orderBy);
               }
  +            columnNo++;
  +        }
  +
  +        if (null != typeColumn) {
  +            query.append(", ").append(typeColumn);
  +            this.typeColumn = columnNo;
  +            columnNo++;
           }
   
           query.append(" FROM ").append(table);
  @@ -299,7 +315,7 @@
               throw new SQLException("The Blob is empty!");
           }
   
  -        InputStream is = new BufferedInputStream(this.resource.getBinaryStream());
  +        InputStream is = new BufferedInputStream(this.resource);
   
           long expires = parameters.getParameterAsInteger("expires", -1);
   
  @@ -351,6 +367,8 @@
           super.recycle();
           this.resource = null;
           this.lastModified = 0;
  +        this.mimeType = null;
  +        this.typeColumn = 0;
   
           if (this.con != null) {
               try {
  @@ -387,7 +405,9 @@
       }
   
       public String getMimeType() {
  -        return this.parameters.getParameter("content-type", super.getMimeType());
  +        return (this.mimeType != null ? 
  +                this.mimeType : 
  +                this.parameters.getParameter("content-type", super.getMimeType()));
       }
   
   }
  
  
  

----------------------------------------------------------------------
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


Mime
View raw message