You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2003/06/14 02:24:59 UTC

cvs commit: cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements Cell.java

joerg       2003/06/13 17:24:59

  Modified:    src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements
                        Cell.java
  Log:
  fixed internationalization support (hack: harcoded encoding UTF-16), bug 15365
  
  Revision  Changes    Path
  1.3       +41 -60    cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Cell.java
  
  Index: Cell.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/poi/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Cell.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Cell.java	11 Mar 2003 19:05:01 -0000	1.2
  +++ Cell.java	14 Jun 2003 00:24:59 -0000	1.3
  @@ -1,4 +1,3 @@
  -
   /*
   
    ============================================================================
  @@ -69,33 +68,36 @@
    * @version CVS $Id$
    */
   // package scope
  -class Cell
  -{
  +
  +class Cell {
  +
       private HSSFCell _cell;
   
       // original CellType value
  -    private int      _celltype;
  -    private Locale   locale; 
  +    private int _celltype;
  +    private Locale locale;
   
       /**
  -     * Constructor Cell
  +     * Constructor Cell.
  +     * Only a hack as long as the POI stuff is not maintained in the POI CVS:
  +     * Setting the encoding to UTF-16 for internationalization
  +     * (<a href="http://jakarta.apache.org/poi/javadocs/org/apache/poi/hssf/usermodel/HSSFCell.html#getEncoding()">POI API</a>).
        *
        * @param cell
        */
  -
  -    Cell(final HSSFCell cell, final int cellType)
  -    {
  -        _cell     = cell;
  +    Cell(final HSSFCell cell, final int cellType) {
  +        _cell = cell;
           _celltype = cellType;
  +        _cell.setEncoding(HSSFCell.ENCODING_UTF_16);
       }
   
       /**
        * if there is a locale that can be used for validation it is
  -     * set here.  Cell expects a fully constructed locale.  It must 
  +     * set here.  Cell expects a fully constructed locale.  It must
        * be passed in before SetContent can be called.
        */
       void setLocale(Locale locale) {
  -          this.locale = locale;
  +        this.locale = locale;
       }
   
       /**
  @@ -105,54 +107,39 @@
        *
        * @exception IOException
        */
  -
  -    void setContent(final String content)
  -        throws IOException
  -    {
  -        if (content.charAt(0) == '=') {  //seems like a kludge but this is
  -                                         //actually how gnumeric does it
  +    void setContent(final String content) throws IOException {
  +        if (content.charAt(0) == '=') {
  +            //seems like a kludge but this is actually how gnumeric does it
               _cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
           }
  -        
  -        if (_cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
  -        {
  -            try
  -            {
  -                if (_celltype == CellType.CELL_TYPE_FLOAT)
  -                {       // if there is a locale set then we'll use it to 
  -                        // parse the string form of the number... otherwise
  -                        // we'll use the default.
  -                        NumberFormat form = null;
  -                        if (locale == null) { 
  -                            form = NumberFormat.getInstance(); 
  -                        } else { 
  -                            form = NumberFormat.getInstance(locale); 
  -                        }
  -                        _cell.setCellValue(form.parse(content).doubleValue());
  -                }
  -                else
  -                {
  +        if (_cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
  +            try {
  +                if (_celltype == CellType.CELL_TYPE_FLOAT) {
  +                    // if there is a locale set then we'll use it to parse the
  +                    // string form of the number... otherwise we'll use the default.
  +                    NumberFormat form = null;
  +                    if (locale == null) {
  +                        form = NumberFormat.getInstance();
  +                    } else {
  +                        form = NumberFormat.getInstance(locale);
  +                    }
  +                    _cell.setCellValue(form.parse(content).doubleValue());
  +                } else {
                       _cell.setCellValue(Integer.parseInt(content));
                   }
  -            }
  -            catch (NumberFormatException e)
  -            {
  -                throw new CascadingIOException("Invalid value for a numeric cell: "
  -                                      + content, e);
  -            } 
  -            catch (ParseException e) {
  +            } catch (NumberFormatException e) {
  +                throw new CascadingIOException("Invalid value for a numeric cell: " + content, e);
  +            } catch (ParseException e) {
                   throw new CascadingIOException("Invalid value for a numberic cell: " + content, e);
               }
  -        }
  -        else if (_cell.getCellType() == HSSFCell.CELL_TYPE_STRING)
  -        {
  +        } else if (_cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
               _cell.setCellValue(content);
           } else if (_cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
  -                _cell.setCellFormula(content.toUpperCase().substring(1));
  +            _cell.setCellFormula(content.toUpperCase().substring(1));
           }
       }
  -    
  -    void setStyle (HSSFCellStyle style) {
  +
  +    void setStyle(HSSFCellStyle style) {
           if (style != null) {
               _cell.setCellStyle(style);
           }
  @@ -161,27 +148,21 @@
       /**
        * @return cell type
        */
  -
  -    int getCellType()
  -    {
  +    int getCellType() {
           return _cell.getCellType();
       }
   
       /**
        * @return string value
        */
  -
  -    String getStringValue()
  -    {
  +    String getStringValue() {
           return _cell.getStringCellValue();
       }
   
       /**
        * @return numeric value
        */
  -
  -    double getNumericValue()
  -    {
  +    double getNumericValue() {
           return _cell.getNumericCellValue();
       }
   }   // end package scope class Cell