View | Details | Raw Unified | Return to bug 38647
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hwpf/model/SavedByTable.java (+121 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2002-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
18
package org.apache.poi.hwpf.model;
19
20
import java.io.IOException;
21
import java.util.Arrays;
22
import java.util.Collections;
23
import java.util.List;
24
25
import org.apache.poi.util.LittleEndian;
26
import org.apache.poi.util.StringUtil;
27
28
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
29
30
/**
31
 * String table containing the history of the last few revisions ("saves") of the document.
32
 * Read-only for the time being.
33
 * 
34
 * @author Daniel Noll
35
 */
36
public class SavedByTable
37
{
38
  /**
39
   * A value that I don't know what it does, but is maintained for accuracy.
40
   */
41
  private short unknownValue = -1;
42
43
  /**
44
   * Array of entries.
45
   */
46
  private SavedByEntry[] entries;
47
48
  /**
49
   * Constructor to read the table from the table stream.
50
   *
51
   * @param tableStream the table stream.
52
   * @param offset the offset into the byte array.
53
   * @param size the size of the table in the byte array.
54
   */
55
  public SavedByTable(byte[] tableStream, int offset, int size)
56
  {
57
    // Read the value that I don't know what it does. :-)
58
    unknownValue = LittleEndian.getShort(tableStream, offset);
59
    offset += 2;
60
61
    // The stored int is the number of strings, and there are two strings per entry.
62
    int numEntries = LittleEndian.getInt(tableStream, offset) / 2;
63
    offset += 4;
64
65
    entries = new SavedByEntry[numEntries];
66
    for (int i = 0; i < numEntries; i++)
67
    {
68
      int len = LittleEndian.getShort(tableStream, offset);
69
      offset += 2;
70
      String userName = StringUtil.getFromUnicodeLE(tableStream, offset, len);
71
      offset += len * 2;
72
      len = LittleEndian.getShort(tableStream, offset);
73
      offset += 2;
74
      String saveLocation = StringUtil.getFromUnicodeLE(tableStream, offset, len);
75
      offset += len * 2;
76
77
      entries[i] = new SavedByEntry(userName, saveLocation);
78
    }
79
  }
80
81
  /**
82
   * Gets the entries.  The returned list cannot be modified.
83
   *
84
   * @return the list of entries.
85
   */
86
  public List getEntries()
87
  {
88
    return Collections.unmodifiableList(Arrays.asList(entries));
89
  }
90
91
  /**
92
   * Writes this table to the table stream.
93
   *
94
   * @param tableStream the table stream to write to.
95
   * @throws IOException if an error occurs while writing.
96
   */
97
  public void writeTo(HWPFOutputStream tableStream)
98
    throws IOException
99
  {
100
    byte[] header = new byte[6];
101
    LittleEndian.putShort(header, 0, unknownValue);
102
    LittleEndian.putInt(header, 2, entries.length * 2);
103
    tableStream.write(header);
104
105
    for (int i = 0; i < entries.length; i++)
106
    {
107
      writeStringValue(tableStream, entries[i].getUserName());
108
      writeStringValue(tableStream, entries[i].getSaveLocation());
109
    }
110
  }
111
112
  private void writeStringValue(HWPFOutputStream tableStream, String value)
113
    throws IOException
114
  {
115
    byte[] buf = new byte[value.length() * 2 + 2];
116
    LittleEndian.putShort(buf, 0, (short) value.length());
117
    StringUtil.putUnicodeLE(value, buf, 2);
118
    tableStream.write(buf);
119
  }
120
}
121
0
  + *
122
  + *
(-)src/scratchpad/src/org/apache/poi/hwpf/model/SavedByEntry.java (+46 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2002-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
18
package org.apache.poi.hwpf.model;
19
20
21
/**
22
 * A single entry in the {@link SavedByTable}.
23
 * 
24
 * @author Daniel Noll
25
 */
26
public class SavedByEntry
27
{
28
  private String userName;
29
  private String saveLocation;
30
31
  public SavedByEntry(String userName, String saveLocation)
32
  {
33
    this.userName = userName;
34
    this.saveLocation = saveLocation;
35
  }
36
37
  public String getUserName()
38
  {
39
    return userName;
40
  }
41
42
  public String getSaveLocation()
43
  {
44
    return saveLocation;
45
  }
46
}
0
  + *
47
  + *
(-)src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (+21 lines)
Lines 61-66 Link Here
61
      fieldSet.add(new Integer(FIBFieldHandler.PLFLFO));
61
      fieldSet.add(new Integer(FIBFieldHandler.PLFLFO));
62
      fieldSet.add(new Integer(FIBFieldHandler.PLCFFLDMOM));
62
      fieldSet.add(new Integer(FIBFieldHandler.PLCFFLDMOM));
63
      fieldSet.add(new Integer(FIBFieldHandler.STTBFFFN));
63
      fieldSet.add(new Integer(FIBFieldHandler.STTBFFFN));
64
      fieldSet.add(new Integer(FIBFieldHandler.STTBSAVEDBY));
64
      fieldSet.add(new Integer(FIBFieldHandler.MODIFIED));
65
      fieldSet.add(new Integer(FIBFieldHandler.MODIFIED));
65
66
66
67
Lines 251-256 Link Here
251
      _fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN, lcbSttbFffn);
252
      _fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN, lcbSttbFffn);
252
    }
253
    }
253
254
255
    public int getFcSttbSavedBy()
256
    {
257
        return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBSAVEDBY);
258
    }
259
260
    public int getLcbSttbSavedBy()
261
    {
262
        return _fieldHandler.getFieldSize(FIBFieldHandler.STTBSAVEDBY);
263
    }
264
265
    public void setFcSttbSavedBy(int fcSttbSavedBy)
266
    {
267
      _fieldHandler.setFieldOffset(FIBFieldHandler.STTBSAVEDBY, fcSttbSavedBy);
268
    }
269
270
    public void setLcbSttbSavedBy(int fcSttbSavedBy)
271
    {
272
      _fieldHandler.setFieldSize(FIBFieldHandler.STTBSAVEDBY, fcSttbSavedBy);
273
    }
274
254
    public int getModifiedLow()
275
    public int getModifiedLow()
255
    {
276
    {
256
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
277
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
(-)src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (+30 lines)
Lines 89-94 Link Here
89
  /** Hold list tables */
89
  /** Hold list tables */
90
  protected ListTables _lt;
90
  protected ListTables _lt;
91
91
92
  /** Holds the save history for this document. */
93
  protected SavedByTable _sbt;
94
92
  protected HWPFDocument()
95
  protected HWPFDocument()
93
  {
96
  {
94
97
Lines 182-187 Link Here
182
      _lt = new ListTables(_tableStream, _fib.getFcPlcfLst(), _fib.getFcPlfLfo());
185
      _lt = new ListTables(_tableStream, _fib.getFcPlcfLst(), _fib.getFcPlfLfo());
183
    }
186
    }
184
187
188
    int sbtOffset = _fib.getFcSttbSavedBy();
189
    if (sbtOffset != 0)
190
    {
191
      _sbt = new SavedByTable(_tableStream, sbtOffset, _fib.getLcbSttbSavedBy());
192
    }
193
185
    PlexOfCps plc = new PlexOfCps(_tableStream, _fib.getFcPlcffldMom(), _fib.getLcbPlcffldMom(), 2);
194
    PlexOfCps plc = new PlexOfCps(_tableStream, _fib.getFcPlcffldMom(), _fib.getLcbPlcffldMom(), 2);
186
    for (int x = 0; x < plc.length(); x++)
195
    for (int x = 0; x < plc.length(); x++)
187
    {
196
    {
Lines 237-243 Link Here
237
  {
246
  {
238
    return _lt;
247
    return _lt;
239
  }
248
  }
249
240
  /**
250
  /**
251
   * Gets a reference to the saved -by table, which holds the save history for the document.
252
   *
253
   * @return the saved-by table.
254
   */
255
  public SavedByTable getSavedByTable()
256
  {
257
    return _sbt;
258
  }
259
260
  /**
241
   * Writes out the word file that is represented by an instance of this class.
261
   * Writes out the word file that is represented by an instance of this class.
242
   *
262
   *
243
   * @param out The OutputStream to write to.
263
   * @param out The OutputStream to write to.
Lines 317-322 Link Here
317
      tableOffset = tableStream.getOffset();
337
      tableOffset = tableStream.getOffset();
318
    }
338
    }
319
339
340
    // write out the saved-by table.
341
    if (_sbt != null)
342
    {
343
      _fib.setFcSttbSavedBy(tableOffset);
344
      _sbt.writeTo(tableStream);
345
      _fib.setLcbSttbSavedBy(tableStream.getOffset() - tableOffset);
346
347
      tableOffset = tableStream.getOffset();
348
    }
349
320
    // write out the FontTable.
350
    // write out the FontTable.
321
    _fib.setFcSttbfffn(tableOffset);
351
    _fib.setFcSttbfffn(tableOffset);
322
    _ft.writeTo(docSys);
352
    _ft.writeTo(docSys);

Return to bug 38647