cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew C. Oliver" <acoli...@apache.org>
Subject [PATCH] HSSF Serializer fonts (posted to list because bugzilla is being a ****)
Date Tue, 09 Apr 2002 02:33:25 GMT
This mostly just fixes the Fonts and date formats. - sorry for the break with protocol.  Bugzilla
decided I will not be submitting today...  bah!

Index: src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPCell.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPCell.java,v
retrieving revision 1.2
diff -u -r1.2 EPCell.java
--- src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPCell.java
8 Apr 2002 07:32:36 -0000	1.2
+++ src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPCell.java
9 Apr 2002 01:04:56 -0000
@@ -1,36 +1,36 @@
 /*
-
+ 
  ============================================================================
                    The Apache Software License, Version 1.1
  ============================================================================
-
+ 
  Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
-
+ 
  Redistribution and use in source and binary forms, with or without modifica-
  tion, are permitted provided that the following conditions are met:
-
+ 
  1. Redistributions of  source code must  retain the above copyright  notice,
     this list of conditions and the following disclaimer.
-
+ 
  2. Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
-
+ 
  3. The end-user documentation included with the redistribution, if any, must
     include  the following  acknowledgment:  "This product includes  software
     developed  by the  Apache Software Foundation  (http://www.apache.org/)."
     Alternately, this  acknowledgment may  appear in the software itself,  if
     and wherever such third-party acknowledgments normally appear.
-
+ 
  4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
     used to  endorse or promote  products derived from  this software without
     prior written permission. For written permission, please contact
     apache@apache.org.
-
+ 
  5. Products  derived from this software may not  be called "Apache", nor may
     "Apache" appear  in their name,  without prior written permission  of the
     Apache Software Foundation.
-
+ 
  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
@@ -41,13 +41,13 @@
  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+ 
  This software  consists of voluntary contributions made  by many individuals
  on  behalf of the Apache Software  Foundation and was  originally created by
  Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
  Software Foundation, please see <http://www.apache.org/>.
-
-*/
+ 
+ */
 
 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
 
@@ -56,6 +56,7 @@
 import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
 import org.apache.cocoon.components.elementprocessor.types.NumericResult;
 import org.apache.cocoon.components.elementprocessor.types.Validator;
+import org.apache.poi.hssf.usermodel.HSSFCell;
 
 import java.io.IOException;
 
@@ -68,8 +69,7 @@
  */
 
 public class EPCell
-    extends BaseElementProcessor
-{
+extends BaseElementProcessor {
     private Cell                   _cell;
     private NumericResult          _col;
     private NumericResult          _row;
@@ -90,23 +90,20 @@
     private static final String    _rows_attribute         = "Rows";
     private static final String    _value_type_attribute   = "ValueType";
     private static final String    _value_format_attribute = "ValueFormat";
-    private static final Validator _cell_type_validator    = new Validator()
-    {
-        public IOException validate(final Number number)
-        {
+    private static final Validator _cell_type_validator    = new Validator() {
+        public IOException validate(final Number number) {
             return CellType.isValid(number.intValue()) ? null
-                                                       : new IOException(
-                                                           "\"" + number
-                                                           + "\" is not a legal value");
+            : new IOException(
+            "\"" + number
+            + "\" is not a legal value");
         }
     };
-
+    
     /**
      * constructor
      */
-
-    public EPCell()
-    {
+    
+    public EPCell() {
         super(null);
         _cell                 = null;
         _col                  = null;
@@ -122,152 +119,135 @@
         _value_type_fetched   = false;
         _value_format_fetched = false;
     }
-
+    
     /**
      * @return column
      *
      * @exception IOException
      */
-
+    
     public int getColumn()
-        throws IOException
-    {
-        if (_col == null)
-        {
+    throws IOException {
+        if (_col == null) {
             _col = NumericConverter
-                .extractNonNegativeInteger(getValue(_col_attribute));
+            .extractNonNegativeInteger(getValue(_col_attribute));
         }
         return _col.intValue();
     }
-
+    
     /**
      * @return row
      *
      * @exception IOException
      */
-
+    
     public int getRow()
-        throws IOException
-    {
-        if (_row == null)
-        {
+    throws IOException {
+        if (_row == null) {
             _row = NumericConverter
-                .extractNonNegativeInteger(getValue(_row_attribute));
+            .extractNonNegativeInteger(getValue(_row_attribute));
         }
         return _row.intValue();
     }
-
+    
     /**
      * @return expression id
      *
      * @exception IOException
      * @exception NullPointerException
      */
-
+    
     public int getExpressionId()
-        throws IOException, NullPointerException
-    {
-        if (!_expr_id_fetched)
-        {
+    throws IOException, NullPointerException {
+        if (!_expr_id_fetched) {
             String valueString = getValue(_expr_id_attribute);
-
-            if (valueString != null)
-            {
+            
+            if (valueString != null) {
                 _expr_id =
-                    NumericConverter.extractPositiveInteger(valueString);
+                NumericConverter.extractPositiveInteger(valueString);
             }
             _expr_id_fetched = true;
         }
         return _expr_id.intValue();
     }
-
+    
     /**
      * @return columns
      *
      * @exception IOException
      * @exception NullPointerException
      */
-
+    
     public int getColumns()
-        throws IOException, NullPointerException
-    {
-        if (!_cols_fetched)
-        {
+    throws IOException, NullPointerException {
+        if (!_cols_fetched) {
             String valueString = getValue(_cols_attribute);
-
-            if (valueString != null)
-            {
+            
+            if (valueString != null) {
                 _cols = NumericConverter.extractPositiveInteger(valueString);
             }
             _cols_fetched = true;
         }
         return _cols.intValue();
     }
-
+    
     /**
      * @return rows
      *
      * @exception IOException
      * @exception NullPointerException
      */
-
+    
     public int getRows()
-        throws IOException, NullPointerException
-    {
-        if (!_rows_fetched)
-        {
+    throws IOException, NullPointerException {
+        if (!_rows_fetched) {
             String valueString = getValue(_rows_attribute);
-
-            if (valueString != null)
-            {
+            
+            if (valueString != null) {
                 _rows = NumericConverter.extractPositiveInteger(valueString);
             }
             _rows_fetched = true;
         }
         return _rows.intValue();
     }
-
+    
     /**
      * @return cell type as a public member of CellType
      *
      * @exception IOException, NullPointerException
      * @exception NullPointerException
      */
-
+    
     public int getCellType()
-        throws IOException, NullPointerException
-    {
-        if (!_value_type_fetched)
-        {
+    throws IOException, NullPointerException {
+        if (!_value_type_fetched) {
             String valueString = getValue(_value_type_attribute);
-
-            if (valueString != null)
-            {
+            
+            if (valueString != null) {
                 _value_type = NumericConverter.extractInteger(valueString,
-                        _cell_type_validator);
+                _cell_type_validator);
             }
             _value_type_fetched = true;
         }
-        return _value_type.intValue();
+        
+        return  _value_type.intValue();
     }
-
+    
     /**
      * @return format string; null if no such attribute
      *
      * @exception IOException
      */
-
+    
     public String getFormat()
-        throws IOException
-    {
-        if (!_value_format_fetched)
-        {
+    throws IOException {
+        if (!_value_format_fetched) {
             _value_format         = getValue(_value_format_attribute);
             _value_format_fetched = true;
         }
         return _value_format;
     }
-
+    
     /**
      * Override of Initialize() implementation
      *
@@ -277,56 +257,51 @@
      *
      * @exception IOException if anything is wrong
      */
-
+    
     public void initialize(final Attribute [] attributes,
-                           final ElementProcessor parent)
-        throws IOException
-    {
+    final ElementProcessor parent)
+    throws IOException {
         super.initialize(attributes, parent);
         int cellType = -1;
-
-        try
-        {
+        
+        try {
             cellType = getCellType();
         }
-        catch (NullPointerException ignored)
-        {
+        catch (NullPointerException ignored) {
         }
         _cell = getSheet().getRow(( short ) getRow()).createCell(getColumn(),
-                                  cellType);
+        cellType);
+        
         
-       
     }
- 
-    public String getContent()
-    {
-      String content = getData();
-      return content;
+    
+    public String getContent() {
+        String content = getData();
+        return content;
     }
-
+    
     /**
      * end processing -- pass their content up to their cell
      *
      * @exception IOException
      */
-
-    public void endProcessing() throws IOException
-    {
-      String content = getContent();
-      if (content != null && !content.trim().equals(""))
-      {
-        getCell().setContent(getContent());
-      }
+    
+    public void endProcessing() throws IOException {
+        String content = getContent();
+        if (content != null && !content.trim().equals("")) {
+            getCell().setContent(getContent());
+        }
     }
-
+    
     /**
      * override of getCell()
      *
      * @return the cell
      */
-
-    protected Cell getCell()
-    {
+    
+    protected Cell getCell() {
         return _cell;
     }
+    
+    
 }   // end public class EPCell
Index: src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPContent.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPContent.java,v
retrieving revision 1.1
diff -u -r1.1 EPContent.java
--- src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPContent.java
6 Mar 2002 16:58:02 -0000	1.1
+++ src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPContent.java
9 Apr 2002 01:04:56 -0000
@@ -103,6 +103,8 @@
     public void endProcessing()
         throws IOException
     {
-        getCell().setContent(getContent());
+        String thecontent = getContent();
+        if (thecontent != null && !thecontent.trim().equals(""))
+            getCell().setContent(getContent());
     }
 }   // end public class EPContent
Index: src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPFont.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPFont.java,v
retrieving revision 1.1
diff -u -r1.1 EPFont.java
--- src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPFont.java
6 Mar 2002 16:58:02 -0000	1.1
+++ src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPFont.java
9 Apr 2002 01:04:56 -0000
@@ -93,6 +93,7 @@
     private NumericResult          _underline;
     private BooleanResult          _strike_through;
     private String                 _font;
+    private HSSFFont               hssfFont;
     private static final String    _unit_attribute           = "Unit";
     private static final String    _bold_attribute           = "Bold";
     private static final String    _italic_attribute         = "Italic";
@@ -153,7 +154,7 @@
             HSSFFont font = workbook.createFont();
             style.setFont(font);
             font.setFontHeightInPoints((short)getUnit());
-            font.setFontName(getFont());
+            //font.setFontName(getFont());
             font.setItalic(getItalic());
             if (getBold()) {
                 font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
@@ -167,6 +168,7 @@
             //System.out.println(pstyle.getForegroundColor().toString());
             if (color == null) color = new HSSFColor.BLACK();
             font.setColor(color.getIndex());
+            hssfFont = font;
         }
     }    
     
@@ -267,6 +269,29 @@
         {
             _font = getData();
         }
+        
         return _font;
     }
+    
+    private HSSFFont getHSSFFont() {
+        return hssfFont;
+    }
+    
+    /**
+     * push the data into the font
+     *
+     * @exception IOException
+     */
+
+    public void endProcessing()
+        throws IOException
+    {
+        String thefont = getFont();
+        if (thefont != null && !thefont.trim().equals("")) {
+            getHSSFFont().setFontName(thefont);
+        } else {
+            getHSSFFont().setFontName("Arial"); //default excel font
+        }
+       
+    }    
 }   // end public class EPFont
Index: src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java,v
retrieving revision 1.4
diff -u -r1.4 EPStyle.java
--- src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java
8 Apr 2002 18:21:50 -0000	1.4
+++ src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java
9 Apr 2002 01:04:56 -0000
@@ -205,18 +205,17 @@
             String format = getFormat();
             if (format != null) {
                 format = kludgeForGnumericMisformats(format);
+                format = kludgeForGnumericDateDivergence(format);
                 short nformat = org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(format);
-                getLogger().debug("setting format to "+ nformat);
+                        getLogger().debug("setting format to "+ nformat);
                 style.setDataFormat(nformat);
-             }
-             
+            }
         } else {
             
             invalid = true;
         }
     }    
     
-
     /**
      * @return true if horizontal alignment general bit is set
      *
@@ -634,7 +633,7 @@
         }
         return retval;
    }
-
+   
     /**
      * Takes in a Gnumeric format string and applies some rules to it.  Some
      * versions of Gnumeric seem to leave off the first parenthesis which 
@@ -654,5 +653,24 @@
         getLogger().debug("going out of the format kludger "+ retval);        
         return retval;
     }    
+
+    private String kludgeForGnumericDateDivergence(String format) {
+        String retval = format;
+        getLogger().debug("going into the format kludgeForGnumericDateDivergence"+ retval);
         
+       
+        if (retval.equals("mm/dd/yy")) {
+            retval = "m/d/yy";
+        } else if (retval.equals("dd-mmm-yy")) {
+            retval = "d-mmm-yy";
+        } else if (retval.equals("dd-mmm")) {
+            retval = "d-mmm";
+        }
+
+        getLogger().debug("going out of the format kludgeForGnumericDateDivergence"+ retval);
       
+        return retval;
+    }
    
+    
+   
+
 }   // end public class EPStyle
-- 
http://www.superlinksoftware.com
http://jakarta.apache.org/poi - port of Excel/Word/OLE 2 Compound
Document 
                            format to java
http://developer.java.sun.com/developer/bugParade/bugs/4487555.html 
			- fix java generics!
The avalanche has already started. It is too late for the pebbles to
vote.
-Ambassador Kosh


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message