Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 28398 invoked from network); 7 Nov 2003 09:29:54 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 7 Nov 2003 09:29:54 -0000 Received: (qmail 3160 invoked by uid 500); 7 Nov 2003 09:29:28 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 3115 invoked by uid 500); 7 Nov 2003 09:29:28 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 3104 invoked by uid 500); 7 Nov 2003 09:29:27 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 3101 invoked from network); 7 Nov 2003 09:29:27 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 7 Nov 2003 09:29:27 -0000 Received: (qmail 28326 invoked by uid 1746); 7 Nov 2003 09:29:52 -0000 Date: 7 Nov 2003 09:29:52 -0000 Message-ID: <20031107092952.28324.qmail@minotaur.apache.org> From: antonio@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements EPStyle.java Workbook.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N antonio 2003/11/07 01:29:52 Modified: . status.xml src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements EPStyle.java Workbook.java Log: Fix HSSFSerializer Bug: Same cell definitions blows document. Applying patch from Grigorios Merenidis (Grigorios.Merenidis@Dresdner-Bank.com). Revision Changes Path 1.185 +5 -1 cocoon-2.1/status.xml Index: status.xml =================================================================== RCS file: /home/cvs//cocoon-2.1/status.xml,v retrieving revision 1.184 retrieving revision 1.185 diff -u -r1.184 -r1.185 --- status.xml 7 Nov 2003 09:14:34 -0000 1.184 +++ status.xml 7 Nov 2003 09:29:51 -0000 1.185 @@ -192,6 +192,10 @@ + + Fix HSSFSerializer Bug: Same cell definitions blows document. Applying + patch from Grigorios Merenidis (Grigorios.Merenidis@Dresdner-Bank.com). + SQLTransformer: Correcting handling of XML data with XML declarations. Applying patch from Andrzej Taramina (andrzej@chaeron.com). 1.5 +41 -19 cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java Index: EPStyle.java =================================================================== RCS file: /home/cvs//cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- EPStyle.java 1 Jul 2003 23:43:21 -0000 1.4 +++ EPStyle.java 7 Nov 2003 09:29:52 -0000 1.5 @@ -79,6 +79,7 @@ * @version CVS $Id$ */ public class EPStyle extends BaseElementProcessor { + private static final String _general_format = "General"; private HorizontalAlignment _h_align; private VerticalAlignment _v_align; private BooleanResult _wrap_text; @@ -153,11 +154,14 @@ style.setVerticalAlignment(cnvvalign); style.setFillPattern((short)getShade()); - + Workbook workbook = getWorkbook(); + HSSFDataFormat dataformat = workbook.createDataFormat(); if (getShade() == 1) { // TODO: change to constant when upgrade to new HSSF // solid w/foreground, bg doesn't matter - getLogger().debug("shade = 1"); + if (getLogger().isDebugEnabled()) { + getLogger().debug("shade = 1"); + } HSSFColor color = (HSSFColor)colorhash.get(getBackgroundColor().toString()); if (color == null) { getLogger().debug("s1 BG couldn't find color for " + getBackgroundColor().toString()); @@ -166,20 +170,26 @@ style.setFillForegroundColor(color.getIndex()); color = (HSSFColor)colorhash.get(getPatternColor().toString()); if (color == null) { - getLogger().debug("s1 PC couldn't find color for " + getPatternColor().toString()); + if (getLogger().isDebugEnabled()) { + getLogger().debug("s1 PC couldn't find color for " + getPatternColor().toString()); + } color = new HSSFColor.BLACK(); } style.setFillBackgroundColor(color.getIndex()); } else { HSSFColor color = (HSSFColor)colorhash.get(getBackgroundColor().toString()); if (color == null) { - getLogger().debug("BG couldn't find color for " + getBackgroundColor().toString()); + if (getLogger().isDebugEnabled()) { + getLogger().debug("BG couldn't find color for " + getBackgroundColor().toString()); + } color = new HSSFColor.BLACK(); } style.setFillBackgroundColor(color.getIndex()); color = (HSSFColor)colorhash.get(getPatternColor().toString()); if (color == null) { - getLogger().debug("PC couldn't find color for " + getPatternColor().toString()); + if (getLogger().isDebugEnabled()) { + getLogger().debug("PC couldn't find color for " + getPatternColor().toString()); + } color = new HSSFColor.WHITE(); } style.setFillForegroundColor(color.getIndex()); @@ -191,15 +201,21 @@ try { format = getFormat(); } catch (NullPointerException e) { - format = "General"; + format = _general_format; } - if (!format.equals("General")) { + if (!format.equals(_general_format)) { + short valuenumber; format = kludgeForGnumericMisformats(format); format = kludgeForGnumericDateDivergence(format); - short nformat = HSSFDataFormat.getBuiltinFormat(format); - getLogger().debug("setting format to " + nformat); - style.setDataFormat(nformat); + if (getLogger().isDebugEnabled()) { + getLogger().debug("setting format to " + format); + } + Object o = workbook.getValidate(format, dataformat.getFormat(format)); + Short sh = null; + sh = (Short) o; + valuenumber = sh.shortValue(); + style.setDataFormat(valuenumber); } } else { invalid = true; @@ -529,7 +545,6 @@ default: retval = HSSFCellStyle.ALIGN_GENERAL; } - return retval; } @@ -566,19 +581,25 @@ */ private String kludgeForGnumericMisformats(String format) { String retval = format; - getLogger().debug("going out of the format kludger " + retval); - getLogger().debug("first )=" + format.indexOf(')')); - getLogger().debug("first (=" + format.indexOf('(')); + if (getLogger().isDebugEnabled()) { + getLogger().debug("going out of the format kludger " + retval); + getLogger().debug("first )=" + format.indexOf(')')); + getLogger().debug("first (=" + format.indexOf('(')); + } if ((format.indexOf(')') < format.indexOf('(')) && (format.indexOf(')') != -1)) { retval = "(" + format; } - getLogger().debug("going out of the format kludger " + retval); + if (getLogger().isDebugEnabled()) { + 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 (getLogger().isDebugEnabled()) { + getLogger().debug("going into the format kludgeForGnumericDateDivergence" + retval); + } if (retval.equals("mm/dd/yy")) { retval = "m/d/yy"; @@ -587,8 +608,9 @@ } else if (retval.equals("dd-mmm")) { retval = "d-mmm"; } - - getLogger().debug("going out of the format kludgeForGnumericDateDivergence" + retval); + if (getLogger().isDebugEnabled()) { + getLogger().debug("going out of the format kludgeForGnumericDateDivergence" + retval); + } return retval; } 1.5 +33 -3 cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Workbook.java Index: Workbook.java =================================================================== RCS file: /home/cvs//cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Workbook.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Workbook.java 22 Sep 2003 22:44:15 -0000 1.4 +++ Workbook.java 7 Nov 2003 09:29:52 -0000 1.5 @@ -53,8 +53,11 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -73,6 +76,8 @@ { private HSSFWorkbook _workbook; private int _sheet_index; + private final static int REPEAT_CAPACITY = 91; + private Map _repeat; /** * Constructor Workbook @@ -82,8 +87,35 @@ { _workbook = new HSSFWorkbook(); _sheet_index = 0; + _repeat = new HashMap(REPEAT_CAPACITY); } + /** + * Method createDataFormat + * + * @return newly created DataFormat + */ + + HSSFDataFormat createDataFormat() + { + return _workbook.createDataFormat(); + } + + /** + * check if the format exists + * + * @param format and the value + * + * @return the format index + */ + Object getValidate(String format, short value) + { + if (_repeat.containsKey(format) == false) { + _repeat.put(format, new Short(value)); + } + return _repeat.get(format); + } + /** * Method getNextName * @@ -150,12 +182,10 @@ * create a font in the underlying HSSF model and return the reference */ HSSFFont createFont() { - HSSFFont font = _workbook.createFont(); return font; } - HSSFWorkbook getWorkbook() { return _workbook;