cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r370197 - in /cocoon/branches/BRANCH_2_1_X: src/java/org/apache/cocoon/generation/CSVGenerator.java status.xml
Date Wed, 18 Jan 2006 17:37:57 GMT
Author: jbq
Date: Wed Jan 18 09:37:49 2006
New Revision: 370197

URL: http://svn.apache.org/viewcvs?rev=370197&view=rev
Log:
CSVGenerator now looks for the sitemap parameter "process-headers" (with the s
at the end) as told in the documentation.  Accepts a new sitemap parameter
"max-records" which allows to limit the number of records to read.  Fixes a
caching bug: the same result was returned notwithstanding the modification of
separator or escape character.

Reported by Philippe Laplanche <philippe.laplanche@horus-si.com>

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CSVGenerator.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CSVGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CSVGenerator.java?rev=370197&r1=370196&r2=370197&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CSVGenerator.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CSVGenerator.java Wed
Jan 18 09:37:49 2006
@@ -44,6 +44,10 @@
  *     different if this is <i>true</i> or <i>false</i> (default:
<i>false</i>).
  *   </li>
  *   <li>
+ *     <b>max-records</b>: the maximum number of records to read
+ *     (default: <i>-1</i> read all records).
+ *   </li>
+ *   <li>
  *     <b>encoding</b>: the character encoding (UTF-8, ISO8859-1, ...) used to
  *     interpret the input CSV source file (default: <i>system default</i>).
  *   </li>
@@ -110,6 +114,7 @@
     private static final String DEFAULT_ESCAPE = "\"";
     /** <p>The default field separator character.</p> */
     private static final int DEFAULT_BUFFER_SIZE = 4096;
+    private static final int UNLIMITED_MAXRECORDS = -1;
     /** <p>A string used for indenting.</p> */
     private static final char INDENT_STRING[] = "\n          ".toCharArray();
 
@@ -125,6 +130,8 @@
     private int fieldnumber = 1;
     /** <p>The current record (line) number in the current CSV.</p> */
     private int recordnumber = 1;
+    /** <p>The maximum number of records to read (-1 = read all records)</p>
*/
+    private int maxrecords;
     /** <p>A flag indicating whether the &lt;record&gt; tag was opened.</p>
*/
     private boolean openrecord = false;
     /** <p>The character buffer for the current field.</p> */
@@ -164,12 +171,13 @@
     throws ProcessingException, SAXException, IOException {
         super.setup(resolver, object_model, source, parameters);
 
-        boolean header = parameters.getParameterAsBoolean("process-header", false);
+        boolean header = parameters.getParameterAsBoolean("process-headers", false);
 
         this.encoding = parameters.getParameter("encoding", DEFAULT_ENCODING);
         this.separator = parameters.getParameter("separator", DEFAULT_SEPARATOR).charAt(0);
         this.escape = parameters.getParameter("escape", DEFAULT_ESCAPE).charAt(0);
         this.buffersize = parameters.getParameterAsInteger("buffer-size", DEFAULT_BUFFER_SIZE);
+        this.maxrecords = parameters.getParameterAsInteger("max-records", UNLIMITED_MAXRECORDS);
         this.buffer = new CharArrayWriter();
         this.columns =  (header ? new HashMap() : null);
         this.recordnumber = (header ? 0 : 1);
@@ -181,8 +189,11 @@
      * <p>Generate the unique key.</p>
      */
     public Serializable getKey() {
-        String key = this.inputSource.getURI();
-        if (this.columns != null) return (key + "+headers");
+        StringBuffer key = new StringBuffer(this.inputSource.getURI());
+        if (this.columns != null) key.append("headers");
+        key.append(separator);
+        key.append(maxrecords);
+        key.append(escape);
         return key;
     }
 
@@ -209,7 +220,7 @@
             int curr = -1;
 
             /* Parse the file reading characters one-by-one */
-            while ((curr = csv.read()) >= 0) {
+            while ((curr = csv.read()) >= 0 && (this.maxrecords == UNLIMITED_MAXRECORDS
|| recordnumber <= this.maxrecords)) {
 
                 /* Process any occurrence of the escape character */
                 if (curr == this.escape) {

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=370197&r1=370196&r2=370197&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Wed Jan 18 09:37:49 2006
@@ -180,6 +180,13 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.9" date="TBD">
+    <action dev="JBQ" type="fix" due-to="Philippe Laplanche" due-to-email="philippe.laplanche@horus-si.com">
+       CSVGenerator now looks for the sitemap parameter "process-headers" (with
+       the s at the end) as told in the documentation.  Accepts a new sitemap
+       parameter "max-records" which allows to limit the number of records to
+       read.  Fixes a caching bug: the same result was returned notwithstanding
+       the modification of separator or escape character.
+    </action>
     <action dev="JBQ" type="fix" fixes-bug="COCOON-1610" due-to="Thomas Lutz" due-to-email="mattom@gmx.at">
        Add ids to CForms validation messages, so that they can be unit-tested
     </action>



Mime
View raw message