Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 73393 invoked by uid 500); 2 Nov 2001 17:11:14 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 73377 invoked from network); 2 Nov 2001 17:11:12 -0000 From: "Klaus Bertram" To: "Cocoon dev" Subject: second: [C2.1][PATCH] DatabaseReader Date: Fri, 2 Nov 2001 16:27:46 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0045_01C163BB.4E009620" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_0045_01C163BB.4E009620 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit -----Original Message----- From: Klaus Bertram [mailto:bertram@n-bis.de] Sent: Wednesday, October 24, 2001 8:27 PM To: Cocoon dev Subject: [C2.1][PATCH] DatabaseReader Hi all, here are a patch for the DatabaseReader changes: The optional params for expires and content-type are now for database column names if they are not set the sidemap params used so that the DatabaseReader is a litle bit more transparent there was also a term inside Timestamp modified = set.getTimestamp(lastModified,null); this don't work with the mySQL driver i had chaned it to Timestamp modified = set.getTimestamp(lastModified); so please try it with other database drivers also Have fun Klaus ------=_NextPart_000_0045_01C163BB.4E009620 Content-Type: application/octet-stream; name="DatabaseReader.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="DatabaseReader.diff" Index: DatabaseReader.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 Berin Loritsch + * @author Klaus Bertram */ public class DatabaseReader extends AbstractReader implements = Composable, Configurable, Disposable, Cacheable, Poolable { private ComponentSelector dbselector; @@ -51,6 +52,8 @@ private DataSourceComponent datasource =3D null; private boolean doCommit =3D false; private boolean defaultCache =3D true; + private String mimeType; + private long expires =3D -1; =20 private ComponentManager manager; =20 @@ -66,6 +69,9 @@ /** * Configure the Reader so that we can use the same = database * for all instances. + *
+     *   =
<use-connection>database_pool_name</use-connection>
+     * 
*/ public void configure(Configuration conf) throws = ConfigurationException { this.dsn =3D conf.getChild("use-connection").getValue(); @@ -81,6 +87,7 @@ super.setup(resolver, objectModel, src, par); =20 try { + getLogger().debug("Database dsn: "+dsn); this.datasource =3D (DataSourceComponent) = dbselector.select(dsn); this.con =3D datasource.getConnection(); =20 @@ -90,15 +97,27 @@ =20 PreparedStatement statement =3D = con.prepareStatement(getQuery()); statement.setString(1, this.source); + ResultSet set =3D statement.executeQuery(); if (set.next() =3D=3D false) throw new = ResourceNotFoundException("There is no resource with that key"); + =20 + if (this.parameters.getParameter("content-type", null) !=3D = null){ + = this.mimeType=3Dset.getString(this.parameters.getParameter("content-type"= , null)); + } else { + this.mimeType =3D null; + } + getLogger().debug("mimeType: "+this.mimeType); + + if (this.parameters.getParameter("expires", null) !=3D = null){ + = this.expires=3Dset.getLong(this.parameters.getParameter("expires", = null)); + } + getLogger().debug("expires: "+this.expires); =20 + this.resource =3D set.getBlob(1); Response response =3D (Response) = objectModel.get(Constants.RESPONSE_OBJECT); Request request =3D (Request) = objectModel.get(Constants.REQUEST_OBJECT); - + =20 if (this.modifiedSince(set, request, response)) { - this.resource =3D set.getBlob(1); - if (this.resource =3D=3D null) { throw new ResourceNotFoundException("There is no = image with that key"); } @@ -133,8 +152,8 @@ * *
      *   <parameter name=3D"last-modified" =
value=3D"database_timestamp_column_name"/>
-     *   <parameter name=3D"content-type" =
value=3D"content_mime_type"/>
-     *   <parameter name=3D"expires" =
value=3D"number_of_millis_before_refresh"/>
+     *   <parameter name=3D"content-type" =
value=3D"database_enum_column_name or database_string_column_name"/>
+     *   <parameter name=3D"expires" =
value=3D"database_bigint_column_name"/>
      *   <parameter name=3D"where" value=3D"alternate_key =3D =
'foo'"/>
      *   <parameter name=3D"order-by" value=3D"alternate_key =
DESC"/>
      * 
@@ -176,6 +195,9 @@ } =20 String date =3D this.parameters.getParameter("last-modified", = null); + String contentType =3D = this.parameters.getParameter("content-type", null); + String expire =3D this.parameters.getParameter("expires", = null); + StringBuffer query =3D new StringBuffer("SELECT "); =20 query.append(column); @@ -183,6 +205,14 @@ if (date !=3D null) { query.append(", ").append(date); } + =20 + if (contentType !=3D null) { + query.append(", ").append(contentType); + } + =20 + if (expire !=3D null) { + query.append(", ").append(expire); + } =20 if (null !=3D orderBy) { query.append(", "); @@ -225,7 +255,8 @@ String lastModified =3D = this.parameters.getParameter("last-modified", null); =20 if (lastModified !=3D null) { - Timestamp modified =3D set.getTimestamp(lastModified, = null); + //changed to bellow mySQL throw exeption with = set.getTimestamp(lastModified, null); + Timestamp modified =3D set.getTimestamp(lastModified); if (null !=3D modified) { this.lastModified =3D modified.getTime(); } else { @@ -253,10 +284,12 @@ =20 InputStream is =3D new = BufferedInputStream(this.resource.getBinaryStream()); =20 - long expires =3D parameters.getParameterAsInteger("expires", = -1); + if (this.expires > 0) { + response.setDateHeader("Expires", new Date().getTime() + = this.expires); + } =20 - if (expires > 0) { - response.setDateHeader("Expires", new Date().getTime() + = expires); + if (this.mimeType !=3D null){ + response.setHeader("Content-Type",this.mimeType); } =20 response.setHeader("Accept-Ranges", "bytes"); @@ -339,7 +372,7 @@ } =20 public String getMimeType() { - return this.parameters.getParameter("content-type", = super.getMimeType()); + return this.mimeType; } =20 } ------=_NextPart_000_0045_01C163BB.4E009620 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org ------=_NextPart_000_0045_01C163BB.4E009620--