You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by sa...@apache.org on 2004/03/02 07:16:30 UTC

cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf HWPFDocument.java

sackley     2004/03/01 22:16:30

  Modified:    src/scratchpad/src/org/apache/poi/hwpf HWPFDocument.java
  Log:
  latest changes
  
  Revision  Changes    Path
  1.7       +72 -18    jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
  
  Index: HWPFDocument.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HWPFDocument.java	13 Nov 2003 03:26:33 -0000	1.6
  +++ HWPFDocument.java	2 Mar 2004 06:16:30 -0000	1.7
  @@ -65,9 +65,14 @@
   import org.apache.poi.poifs.filesystem.DocumentEntry;
   import org.apache.poi.poifs.common.POIFSConstants;
   import org.apache.poi.hwpf.usermodel.CharacterRun;
  +import org.apache.poi.hwpf.usermodel.Paragraph;
  +import org.apache.poi.hwpf.usermodel.TableProperties;
  +import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
  +import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
   
  -import org.apache.poi.hwpf.model.hdftypes.*;
  +import org.apache.poi.hwpf.model.*;
   import org.apache.poi.hwpf.model.io.*;
  +import org.apache.poi.hwpf.usermodel.*;
   
   
   /**
  @@ -114,6 +119,8 @@
     /** Holds fonts for this document.*/
     private FontTable _ft;
   
  +  private ListTables _lt;
  +
   
     /**
      * This constructor loads a Word document from an InputStream.
  @@ -148,6 +155,8 @@
       _tableStream = new byte[tableProps.getSize()];
       _filesystem.createDocumentInputStream(name).read(_tableStream);
   
  +    _fib.fillVariableFields(_mainStream, _tableStream);
  +
       // get the start of text in the main stream
       int fcMin = _fib.getFcMin();
   
  @@ -171,6 +180,13 @@
       _ss = new StyleSheet(_tableStream, _fib.getFcStshf());
       _ft = new FontTable(_tableStream, _fib.getFcSttbfffn(), _fib.getLcbSttbfffn());
   
  +    int listOffset = _fib.getFcPlcfLst();
  +    int lfoOffset = _fib.getFcPlfLfo();
  +    if (listOffset != 0 && _fib.getLcbPlcfLst() != 0)
  +    {
  +      _lt = new ListTables(_tableStream, _fib.getFcPlcfLst(), _fib.getFcPlfLfo());
  +    }
  +
       int x = 0;
   
     }
  @@ -185,6 +201,10 @@
       return new Range(0, _fib.getFcMac() - _fib.getFcMin(), this);
     }
   
  +  public ListTables getListTables()
  +  {
  +    return _lt;
  +  }
     /**
      * Writes out the word file that is represented by an instance of this class.
      *
  @@ -201,6 +221,7 @@
       HWPFOutputStream tableStream = docSys.getStream("1Table");
       int tableOffset = 0;
   
  +    // FileInformationBlock fib = (FileInformationBlock)_fib.clone();
       // clear the offsets and sizes in our FileInformationBlock.
       _fib.clearOffsetsSizes();
   
  @@ -250,6 +271,19 @@
       _fib.setLcbPlcfsed(tableStream.getOffset() - tableOffset);
       tableOffset = tableStream.getOffset();
   
  +    // write out the list tables
  +    if (_lt != null)
  +    {
  +      _fib.setFcPlcfLst(tableOffset);
  +      _lt.writeListDataTo(tableStream);
  +      _fib.setLcbPlcfLst(tableStream.getOffset() - tableOffset);
  +
  +      _fib.setFcPlfLfo(tableStream.getOffset());
  +      _lt.writeListOverridesTo(tableStream);
  +      _fib.setLcbPlfLfo(tableStream.getOffset() - tableOffset);
  +      tableOffset = tableStream.getOffset();
  +    }
  +
       // write out the FontTable.
       _fib.setFcSttbfffn(tableOffset);
       _ft.writeTo(docSys);
  @@ -276,6 +310,11 @@
         System.arraycopy(mainBuf, 0, tempBuf, 0, mainBuf.length);
         mainBuf = tempBuf;
       }
  +
  +    // write out the FileInformationBlock.
  +    //_fib.serialize(mainBuf, 0);
  +    _fib.writeTo(mainBuf, tableStream);
  +
       byte[] tableBuf = tableStream.toByteArray();
       if (tableBuf.length < 4096)
       {
  @@ -284,8 +323,6 @@
         tableBuf = tempBuf;
       }
   
  -    // write out the FileInformationBlock.
  -    _fib.serialize(mainBuf, 0);
   
       // spit out the Word document.
       POIFSFileSystem pfs = new POIFSFileSystem();
  @@ -295,27 +332,34 @@
       pfs.writeFilesystem(out);
     }
   
  -  CHPBinTable getCharacterTable()
  +  public CHPBinTable getCharacterTable()
     {
       return _cbt;
     }
   
  -  PAPBinTable getParagraphTable()
  +  public PAPBinTable getParagraphTable()
     {
       return _pbt;
     }
   
  -  SectionTable getSectionTable()
  +  public SectionTable getSectionTable()
     {
       return _st;
     }
   
  -  TextPieceTable getTextTable()
  +  public TextPieceTable getTextTable()
     {
       return _cft.getTextPieceTable();
     }
   
  -
  +  public int registerList(List list)
  +  {
  +    if (_lt == null)
  +    {
  +      _lt = new ListTables();
  +    }
  +    return _lt.addList(list.getListData(), list.getOverride());
  +  }
   
     /**
      * Takes two arguments, 1) name of the Word file to read in 2) location to
  @@ -328,19 +372,29 @@
       try
       {
         HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
  -      CharacterRun run = new CharacterRun();
  -      run.setBold(true);
  -      run.setItalic(true);
  -      run.setCapitalized(true);
  +      Range r = doc.getRange();
  +      TableIterator ti = new TableIterator(r);
  +      while (ti.hasNext())
  +      {
  +        Table t = ti.next();
  +        int x = 0;
  +      }
   
  -      Range range = doc.getRange();
  -      range.insertBefore("Hello World!!! HAHAHAHAHA I DID IT!!!", run);
   
  -      OutputStream out = new FileOutputStream(args[1]);
  -      doc.write(out);
   
  -      out.flush();
  -      out.close();
  +//      CharacterRun run = new CharacterRun();
  +//      run.setBold(true);
  +//      run.setItalic(true);
  +//      run.setCapitalized(true);
  +//
  +//      Range range = doc.getRange();
  +//      range.insertBefore("Hello World!!! HAHAHAHAHA I DID IT!!!", run);
  +//
  +//      OutputStream out = new FileOutputStream(args[1]);
  +//      doc.write(out);
  +//
  +//      out.flush();
  +//      out.close();
   
   
       }
  
  
  

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