You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by gl...@apache.org on 2004/08/24 14:54:01 UTC

cvs commit: jakarta-poi/src/java/org/apache/poi/hssf/usermodel HSSFWorkbook.java

glens       2004/08/24 05:54:01

  Modified:    src/scratchpad/src/org/apache/poi/hwpf/model ListLevel.java
                        ListTables.java SectionTable.java TextPiece.java
                        TextPieceTable.java
               src/scratchpad/src/org/apache/poi/hwpf/sprm
                        ParagraphSprmUncompressor.java
                        TableSprmUncompressor.java
               src/scratchpad/src/org/apache/poi/hwpf/usermodel
                        CharacterRun.java Paragraph.java Range.java
                        Table.java TableRow.java
               src/java/org/apache/poi/hssf/usermodel HSSFWorkbook.java
  Log:
  Pier's other HWPF patch.
  
  Revision  Changes    Path
  1.3       +7 -3      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
  
  Index: ListLevel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ListLevel.java	9 Apr 2004 13:05:32 -0000	1.2
  +++ ListLevel.java	24 Aug 2004 12:53:59 -0000	1.3
  @@ -14,7 +14,7 @@
      See the License for the specific language governing permissions and
      limitations under the License.
   ==================================================================== */
  -        
  +
   
   package org.apache.poi.hwpf.model;
   
  @@ -106,10 +106,10 @@
   
       _grpprlPapx = new byte[_cbGrpprlPapx];
       _grpprlChpx = new byte[_cbGrpprlChpx];
  -    System.arraycopy(buf, offset, _grpprlChpx, 0, _cbGrpprlChpx);
  -    offset += _cbGrpprlChpx;
       System.arraycopy(buf, offset, _grpprlPapx, 0, _cbGrpprlPapx);
       offset += _cbGrpprlPapx;
  +    System.arraycopy(buf, offset, _grpprlChpx, 0, _cbGrpprlChpx);
  +    offset += _cbGrpprlChpx;
   
       int numberTextLength = LittleEndian.getShort(buf, offset);
       _numberText = new char[numberTextLength];
  @@ -168,6 +168,10 @@
       _grpprlPapx = grpprl;
     }
   
  +  public byte[] getLevelProperties()
  +  {
  +    return _grpprlPapx;
  +  }
   
     public boolean equals(Object obj)
     {
  
  
  
  1.5       +5 -0      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java
  
  Index: ListTables.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ListTables.java	9 Apr 2004 13:05:32 -0000	1.4
  +++ ListTables.java	24 Aug 2004 12:53:59 -0000	1.5
  @@ -192,6 +192,11 @@
       return lvl;
     }
   
  +  public ListData getListData(int listID)
  +  {
  +    return (ListData) _listMap.get(new Integer(listID));
  +  }
  +
     public boolean equals(Object obj)
     {
       if (obj == null)
  
  
  
  1.5       +49 -39    jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java
  
  Index: SectionTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SectionTable.java	19 Apr 2004 23:48:02 -0000	1.4
  +++ SectionTable.java	24 Aug 2004 12:53:59 -0000	1.5
  @@ -45,6 +45,7 @@
     {
       PlexOfCps sedPlex = new PlexOfCps(tableStream, offset, size, SED_SIZE);
       _text = tpt;
  +
       int length = sedPlex.length();
   
       for (int x = 0; x < length; x++)
  @@ -85,50 +86,51 @@
       }
     }
   
  -  private int CPtoFC(int cp)
  +  // goss version of CPtoFC - this takes into account non-contiguous textpieces
  +  // that we have come across in real world documents. Tests against the example
  +  // code in HWPFDocument show no variation to Ryan's version of the code in
  +  // normal use, but this version works with our non-contiguous test case.
  +  // So far unable to get this test case to be written out as well due to
  +  // other issues. - piers
  +   private int CPtoFC(int CP)
     {
  -    int size = _text.size();
  -    int x = 0;
  -    int end = 0;
  -    int fc = 0;
  -    for (; x < size; x++)
  -    {
  -      TextPiece piece = (TextPiece)_text.get(x);
  -      int currentStart = end;
  -      end += ((piece.getEnd()- piece.getStart())/(piece.usesUnicode() ? 2 : 1));
  -      if (cp <= end)
  -      {
  -        fc += ((cp - currentStart) * (piece.usesUnicode() ? 2 : 1));
  -        break;
  -      }
  -      else
  +      TextPiece TP = null;
  +
  +      for(int i=_text.size()-1; i>-1; i--)
         {
  -        fc += (piece.getEnd() - piece.getStart());
  +        TP = (TextPiece)_text.get(i);
  +
  +        if(CP >= TP.getCP()) break;
         }
  +      int FC = TP.getPieceDescriptor().getFilePosition();
  +      int offset = CP - TP.getCP();
  +      if(TP.usesUnicode()) offset*=2;
  +      FC = FC+offset-((TextPiece)_text.get(0)).getPieceDescriptor().getFilePosition();
  +      return FC;
       }
  -    return fc;
  -  }
   
  -  private int FCtoCP(int fc)
  -  {
  -    int size = _text.size();
  -    int cp = 0;
  -    for (int x = 0; x < size; x++)
  -    {
  -      TextPiece piece = (TextPiece)_text.get(x);
  +    // Ryans code
  +    private int FCtoCP(int fc)
  +   {
  +     int size = _text.size();
  +     int cp = 0;
  +     for (int x = 0; x < size; x++)
  +     {
  +       TextPiece piece = (TextPiece)_text.get(x);
  +
  +       if (fc <= piece.getEnd())
  +       {
  +         cp += ((fc - piece.getStart())/ (piece.usesUnicode() ? 2 : 1));
  +         break;
  +       }
  +       else
  +       {
  +         cp += ((piece.getEnd() - piece.getStart())/ (piece.usesUnicode() ? 2 : 1));
  +       }
  +     }
  +     return cp;
  +   }
   
  -      if (fc <= piece.getEnd())
  -      {
  -        cp += ((fc - piece.getStart())/ (piece.usesUnicode() ? 2 : 1));
  -        break;
  -      }
  -      else
  -      {
  -        cp += ((piece.getEnd() - piece.getStart())/ (piece.usesUnicode() ? 2 : 1));
  -      }
  -    }
  -    return cp;
  -  }
   
     public ArrayList getSections()
     {
  @@ -163,12 +165,20 @@
         sed.setFc(offset);
   
         // add the section descriptor bytes to the PlexOfCps.
  +
  +
  +      // original line -
  +      //GenericPropertyNode property = new GenericPropertyNode(sepx.getStart(), sepx.getEnd(), sed.toByteArray());
  +
  +      // Line using Ryan's FCtoCP() conversion method -
  +      // unable to observe any effect on our testcases when using this code - piers
         GenericPropertyNode property = new GenericPropertyNode(FCtoCP(sepx.getStart()), FCtoCP(sepx.getEnd()), sed.toByteArray());
  +
  +
         plex.addProperty(property);
   
         offset = docStream.getOffset();
       }
       tableStream.write(plex.toByteArray());
     }
  -
   }
  
  
  
  1.5       +10 -6     jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
  
  Index: TextPiece.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TextPiece.java	19 Apr 2004 23:48:02 -0000	1.4
  +++ TextPiece.java	24 Aug 2004 12:53:59 -0000	1.5
  @@ -31,13 +31,15 @@
   
     private PieceDescriptor _pd;
   
  +  private int _cpStart;
  +
     /**
      * @param start Offset in main document stream.
      * @param length The total length of the text in bytes. Note: 1 character
      *        does not necessarily refer to 1 byte.
      * @param unicode true if this text is unicode.
      */
  -  public TextPiece(int start, int end, byte[] text, PieceDescriptor pd)
  +  public TextPiece(int start, int end, byte[] text, PieceDescriptor pd, int cpStart)
       throws UnsupportedEncodingException
     {
        /** start - end is length on file. This is double the expected when its
  @@ -45,6 +47,7 @@
       super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252")));
       _usesUnicode = pd.isUnicode();
       _pd = pd;
  +    _cpStart = cpStart;
     }
     /**
      * @return If this text piece uses unicode
  @@ -64,11 +67,6 @@
        return (StringBuffer)_buf;
      }
   
  -   public void setStringBuffer(StringBuffer buf)
  -   {
  -     _buf = buf;
  -   }
  -
      public byte[] getRawBytes()
      {
        try
  @@ -111,6 +109,12 @@
                 tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd);
        }
        return false;
  +   }
  +
  +
  +   public int getCP()
  +   {
  +     return _cpStart;
      }
   
   }
  
  
  
  1.5       +4 -9      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
  
  Index: TextPieceTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TextPieceTable.java	19 Apr 2004 23:48:02 -0000	1.4
  +++ TextPieceTable.java	24 Aug 2004 12:53:59 -0000	1.5
  @@ -65,10 +65,8 @@
   //      }
       }
   
  -    _cpMin = pieces[0].getFilePosition() - fcMin;
  -    // if a piece is unicode the actual offset may be bumped because of the
  -    // doubling of the needed size.
  -    int bump = 0;
  +    int firstPieceFilePosition = pieces[0].getFilePosition();
  +        _cpMin = firstPieceFilePosition - fcMin;
   
       // using the PieceDescriptors, build our list of TextPieces.
       for (int x = 0; x < pieces.length; x++)
  @@ -92,12 +90,9 @@
   
         byte[] buf = new byte[textSize];
         System.arraycopy(documentStream, start, buf, 0, textSize);
  -      _textPieces.add(new TextPiece(nodeStart + bump, nodeEnd + bump, buf, pieces[x]));
   
  -      if (unicode)
  -      {
  -        bump += (node.getEnd() - nodeStart);
  -      }
  +      int startFilePosition = start - firstPieceFilePosition;
  +      _textPieces.add(new TextPiece(startFilePosition, startFilePosition+textSize, buf, pieces[x], node.getStart()));
       }
     }
   
  
  
  
  1.6       +2 -2      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java
  
  Index: ParagraphSprmUncompressor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParagraphSprmUncompressor.java	9 Apr 2004 13:05:33 -0000	1.5
  +++ ParagraphSprmUncompressor.java	24 Aug 2004 12:54:00 -0000	1.6
  @@ -14,7 +14,7 @@
      See the License for the specific language governing permissions and
      limitations under the License.
   ==================================================================== */
  -        
  +
   
   package org.apache.poi.hwpf.sprm;
   
  @@ -407,7 +407,7 @@
   
       for (int x = 0; x < delSize; x++)
       {
  -      tabMap.remove(new Integer(LittleEndian.getInt(grpprl, offset)));
  +      tabMap.remove(new Integer(LittleEndian.getShort(grpprl, offset)));
         offset += LittleEndian.SHORT_SIZE;
       }
   
  
  
  
  1.4       +17 -3     jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java
  
  Index: TableSprmUncompressor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TableSprmUncompressor.java	9 Apr 2004 13:05:33 -0000	1.3
  +++ TableSprmUncompressor.java	24 Aug 2004 12:54:00 -0000	1.4
  @@ -14,7 +14,7 @@
      See the License for the specific language governing permissions and
      limitations under the License.
   ==================================================================== */
  -        
  +
   
   package org.apache.poi.hwpf.sprm;
   
  @@ -133,12 +133,26 @@
           newTAP.setRgdxaCenter (rgdxaCenter);
           newTAP.setRgtc (rgtc);
   
  +        // get the rgdxaCenters
           for (int x = 0; x < itcMac; x++)
           {
             rgdxaCenter[x] = LittleEndian.getShort (grpprl, offset + (1 + (x * 2)));
  -          rgtc[x] = TableCellDescriptor.convertBytesToTC (grpprl,
  -            offset + (1 + ((itcMac + 1) * 2) + (x * 20)));
           }
  +
  +        // only try to get the TC entries if they exist...
  +        int endOfSprm = offset+sprm.size()-6; // -2 bytes for sprm - 2 for size short - 2 to correct offsets being 0 based
  +        int startOfTCs = offset + (1 + (itcMac + 1) * 2);
  +
  +        boolean hasTCs = startOfTCs < endOfSprm;
  +
  +        for (int x = 0; x < itcMac; x++)
  +        {
  +          if(hasTCs) rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl,
  +              offset + (1 + ( (itcMac + 1) * 2) + (x * 20)));
  +          else
  +            rgtc[x] = new TableCellDescriptor();
  +        }
  +
           rgdxaCenter[itcMac] = LittleEndian.getShort (grpprl, offset + (1 + (itcMac * 2)));
           break;
         }
  
  
  
  1.10      +0 -4      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java
  
  Index: CharacterRun.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CharacterRun.java	24 Aug 2004 12:34:32 -0000	1.9
  +++ CharacterRun.java	24 Aug 2004 12:54:00 -0000	1.10
  @@ -18,13 +18,9 @@
   
   package org.apache.poi.hwpf.usermodel;
   
  -import org.apache.poi.hwpf.model.types.CHPAbstractType;
  -import org.apache.poi.hwpf.model.StyleDescription;
   import org.apache.poi.hwpf.model.CHPX;
   import org.apache.poi.hwpf.model.StyleSheet;
  -
   import org.apache.poi.hwpf.sprm.SprmBuffer;
  -import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
   
   /**
    * This class represents a run of text that share common properties.
  
  
  
  1.9       +9 -11     jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java
  
  Index: Paragraph.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Paragraph.java	24 Aug 2004 12:34:32 -0000	1.8
  +++ Paragraph.java	24 Aug 2004 12:54:00 -0000	1.9
  @@ -14,7 +14,7 @@
      See the License for the specific language governing permissions and
      limitations under the License.
   ==================================================================== */
  -        
  +
   
   package org.apache.poi.hwpf.usermodel;
   
  @@ -431,16 +431,14 @@
     }
   
     public int getIlfo()
  -  {
  -    return _props.getIlfo();
  -  }
  -
  -  public int getIlvl()
  -  {
  -    return _props.getIlvl();
  -  }
  -
  -
  +   {
  +     return _props.getIlfo();
  +   }
  +
  +   public int getIlvl()
  +   {
  +     return _props.getIlvl();
  +   }
   
     void setTableRowEnd(TableProperties props)
     {
  
  
  
  1.13      +9 -2      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
  
  Index: Range.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Range.java	24 Aug 2004 12:34:32 -0000	1.12
  +++ Range.java	24 Aug 2004 12:54:00 -0000	1.13
  @@ -252,7 +252,13 @@
         TextPiece piece = (TextPiece)_text.get(x);
         int start = _start > piece.getStart() ? _start - piece.getStart() : 0;
         int end = _end <= piece.getEnd() ? _end - piece.getStart() : piece.getEnd() - piece.getStart();
  -      sb.append(piece.substring(start, end));
  +
  +      if(piece.usesUnicode()) // convert the byte pointers to char pointers
  +      {
  +        start/=2;
  +        end/=2;
  +      }
  +      sb.append(piece.getStringBuffer().substring(start, end));
       }
       return sb.toString();
     }
  @@ -693,7 +699,8 @@
       r.initAll();
       int tableEnd = r._parEnd;
   
  -    if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable())
  +    if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable()
  +        && getParagraph(r._parStart - 1)._sectionEnd >= r._sectionStart)
       {
         throw new IllegalArgumentException("This paragraph is not the first one in the table");
       }
  
  
  
  1.6       +2 -2      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Table.java	11 Jul 2004 05:54:36 -0000	1.5
  +++ Table.java	24 Aug 2004 12:54:00 -0000	1.6
  @@ -36,12 +36,12 @@
       while (rowEnd < numParagraphs)
       {
         Paragraph p = getParagraph(rowEnd);
  +      rowEnd++;
         if (p.isTableRowEnd() && p.getTableLevel() == levelNum)
         {
  -        _rows.add(new TableRow(rowStart, rowEnd + 1, this, levelNum));
  +        _rows.add(new TableRow(rowStart, rowEnd, this, levelNum));
           rowStart = rowEnd;
         }
  -      rowEnd++;
       }
     }
   
  
  
  
  1.6       +1 -2      jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java
  
  Index: TableRow.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableRow.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TableRow.java	24 Aug 2004 12:34:32 -0000	1.5
  +++ TableRow.java	24 Aug 2004 12:54:00 -0000	1.6
  @@ -14,11 +14,10 @@
      See the License for the specific language governing permissions and
      limitations under the License.
   ==================================================================== */
  -        
  +
   package org.apache.poi.hwpf.usermodel;
   
   import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
  -import org.apache.poi.hwpf.sprm.SprmBuffer;
   
   public class TableRow
     extends Paragraph
  
  
  
  1.36      +19 -18    jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
  
  Index: HSSFWorkbook.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- HSSFWorkbook.java	23 Aug 2004 08:52:42 -0000	1.35
  +++ HSSFWorkbook.java	24 Aug 2004 12:54:01 -0000	1.36
  @@ -22,15 +22,6 @@
    */
   package org.apache.poi.hssf.usermodel;
   
  -import java.io.ByteArrayInputStream;
  -import java.io.IOException;
  -import java.io.InputStream;
  -import java.io.OutputStream;
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.List;
  -import java.util.Stack;
  -
   import org.apache.poi.hssf.eventmodel.EventRecordFactory;
   import org.apache.poi.hssf.model.Sheet;
   import org.apache.poi.hssf.model.Workbook;
  @@ -39,14 +30,19 @@
   import org.apache.poi.hssf.record.formula.MemFuncPtg;
   import org.apache.poi.hssf.record.formula.UnionPtg;
   import org.apache.poi.hssf.util.CellReference;
  -import org.apache.poi.poifs.filesystem.DirectoryEntry;
  -import org.apache.poi.poifs.filesystem.DocumentEntry;
  -import org.apache.poi.poifs.filesystem.DocumentInputStream;
  -import org.apache.poi.poifs.filesystem.Entry;
  -import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  +import org.apache.poi.poifs.filesystem.*;
   import org.apache.poi.util.POILogFactory;
   import org.apache.poi.util.POILogger;
   
  +import java.io.ByteArrayInputStream;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Stack;
  +
   /**
    * High level representation of a workbook.  This is the first object most users
    * will construct whether they are reading or writing a workbook.  It is also the
  @@ -84,7 +80,7 @@
        * this holds the HSSFSheet objects attached to this workbook
        */
   
  -    private ArrayList sheets;
  +    protected ArrayList sheets;
   
       /**
        * this holds the HSSFName objects attached to this workbook
  @@ -121,9 +117,14 @@
   
       public HSSFWorkbook()
       {
  -        workbook = Workbook.createWorkbook();
  -        sheets = new ArrayList(INITIAL_CAPACITY);
  -        names  = new ArrayList(INITIAL_CAPACITY);
  +        this(Workbook.createWorkbook());
  +    }
  +
  +    protected HSSFWorkbook( Workbook book )
  +    {
  +        workbook = book;
  +        sheets = new ArrayList( INITIAL_CAPACITY );
  +        names = new ArrayList( INITIAL_CAPACITY );
       }
   
       public HSSFWorkbook(POIFSFileSystem fs) throws IOException {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org