cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements EPCell.java EPContent.java EPFont.java EPStyle.java
Date Fri, 12 Apr 2002 14:01:45 GMT
nicolaken    02/04/12 07:01:45

  Modified:    src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements
                        EPCell.java EPContent.java EPFont.java EPStyle.java
  Log:
  [PATCH] fixes for Fonts and minor fixes to content tag by
  acoliver@apache.org (Andy Oliver), Bug#: 7858
  
  Revision  Changes    Path
  1.3       +90 -115   xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPCell.java
  
  Index: EPCell.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPCell.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EPCell.java	8 Apr 2002 07:32:36 -0000	1.2
  +++ EPCell.java	12 Apr 2002 14:01:45 -0000	1.3
  @@ -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
  +     * end processing -- apply content to the 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
  
  
  
  1.2       +8 -2      xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPContent.java
  
  Index: EPContent.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPContent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EPContent.java	6 Mar 2002 16:58:02 -0000	1.1
  +++ EPContent.java	12 Apr 2002 14:01:45 -0000	1.2
  @@ -89,7 +89,11 @@
       {
           if (_content == null)
           {
  -            _content = getData();
  +		try {
  +            		_content = getData();
  +		} catch (NullPointerException ignored) {
  +			//ignore npe	
  +		} 
           }
           return _content;
       }
  @@ -103,6 +107,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
  
  
  
  1.2       +30 -2     xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPFont.java
  
  Index: EPFont.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPFont.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EPFont.java	6 Mar 2002 16:58:02 -0000	1.1
  +++ EPFont.java	12 Apr 2002 14:01:45 -0000	1.2
  @@ -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;
           }
       }    
       
  @@ -265,8 +267,34 @@
       {
           if (_font == null)
           {
  -            _font = getData();
  +		try {
  +            		_font = getData();
  +		} catch (NullPointerException ignored) {
  +		}
           }
  +        
           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()
!= null) {
  +            getHSSFFont().setFontName(thefont);
  +        } else if (getHSSFFont() != null) {
  +            getHSSFFont().setFontName("Arial"); //default excel font
  +        }
  +       
  +    }    
   }   // end public class EPFont
  
  
  
  1.5       +34 -9     xml-cocoon2/src/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/EPStyle.java
  
  Index: EPStyle.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/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	8 Apr 2002 18:21:50 -0000	1.4
  +++ EPStyle.java	12 Apr 2002 14:01:45 -0000	1.5
  @@ -202,21 +202,27 @@
               style.setWrapText(getWrapText());
               style.setLocked(true);
               
  -            String format = getFormat();
  -            if (format != null) {
  +            String format = null;
  +
  +	    try {
  +		format = getFormat();
  +            } catch (NullPointerException e) {
  +		format = "General";
  +            }
  +
  +            if (!format.equals("General")) {
                   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
        *
  @@ -512,11 +518,11 @@
           if (_format == null)
           {
               _format = getValue(_format_attribute);
  -            if (_format == null)
  +            /*if (_format == null)
               {
                   throw new IOException("missing " + _format_attribute
                                         + " attribute");
  -            }
  +            }*/
           }
           return _format;
       }
  @@ -634,7 +640,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 +660,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
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message