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

(-)a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (-9 / +12 lines)
Lines 32-43 import org.apache.poi.hwpf.model.ComplexFileTable; Link Here
32
import org.apache.poi.hwpf.model.DocumentProperties;
32
import org.apache.poi.hwpf.model.DocumentProperties;
33
import org.apache.poi.hwpf.model.EscherRecordHolder;
33
import org.apache.poi.hwpf.model.EscherRecordHolder;
34
import org.apache.poi.hwpf.model.FSPATable;
34
import org.apache.poi.hwpf.model.FSPATable;
35
import org.apache.poi.hwpf.model.FieldsTables;
35
import org.apache.poi.hwpf.model.FontTable;
36
import org.apache.poi.hwpf.model.FontTable;
36
import org.apache.poi.hwpf.model.GenericPropertyNode;
37
import org.apache.poi.hwpf.model.ListTables;
37
import org.apache.poi.hwpf.model.ListTables;
38
import org.apache.poi.hwpf.model.PAPBinTable;
38
import org.apache.poi.hwpf.model.PAPBinTable;
39
import org.apache.poi.hwpf.model.PicturesTable;
39
import org.apache.poi.hwpf.model.PicturesTable;
40
import org.apache.poi.hwpf.model.PlexOfCps;
41
import org.apache.poi.hwpf.model.PropertyNode;
40
import org.apache.poi.hwpf.model.PropertyNode;
42
import org.apache.poi.hwpf.model.RevisionMarkAuthorTable;
41
import org.apache.poi.hwpf.model.RevisionMarkAuthorTable;
43
import org.apache.poi.hwpf.model.SavedByTable;
42
import org.apache.poi.hwpf.model.SavedByTable;
Lines 100-105 public final class HWPFDocument extends HWPFDocumentCore Link Here
100
99
101
  /** Holds Office Art objects */
100
  /** Holds Office Art objects */
102
  protected ShapesTable _officeArts;
101
  protected ShapesTable _officeArts;
102
  
103
  /** Holds the fields PLCFs */
104
  protected FieldsTables _fieldsTables;
103
105
104
  protected HWPFDocument()
106
  protected HWPFDocument()
105
  {
107
  {
Lines 250-262 public final class HWPFDocument extends HWPFDocumentCore Link Here
250
      _rmat = new RevisionMarkAuthorTable(_tableStream, rmarkOffset, rmarkLength);
252
      _rmat = new RevisionMarkAuthorTable(_tableStream, rmarkOffset, rmarkLength);
251
    }
253
    }
252
    
254
    
253
    PlexOfCps plc = new PlexOfCps(_tableStream, _fib.getFcPlcffldMom(), _fib.getLcbPlcffldMom(), 2);
255
    _fieldsTables = new FieldsTables(_tableStream, _fib);
254
    for (int x = 0; x < plc.length(); x++)
255
    {
256
      GenericPropertyNode node = plc.getProperty(x);
257
      byte[] fld = node.getBytes();
258
      int breakpoint = 0;
259
    }
260
  }
256
  }
261
257
262
  public TextPieceTable getTextTable()
258
  public TextPieceTable getTextTable()
Lines 402-407 public final class HWPFDocument extends HWPFDocumentCore Link Here
402
  }
398
  }
403
399
404
  /**
400
  /**
401
   * @return FieldsTables object, that is able to extract fields descriptors from this document
402
   */
403
  public FieldsTables getFieldsTables() {
404
      return _fieldsTables;
405
  }
406
  
407
  /**
405
   * Writes out the word file that is represented by an instance of this class.
408
   * Writes out the word file that is represented by an instance of this class.
406
   *
409
   *
407
   * @param out The OutputStream to write to.
410
   * @param out The OutputStream to write to.
(-)a/src/scratchpad/src/org/apache/poi/hwpf/model/FieldDescriptor.java (-10 / +133 lines)
Lines 17-39 Link Here
17
17
18
package org.apache.poi.hwpf.model;
18
package org.apache.poi.hwpf.model;
19
19
20
import org.apache.poi.util.BitField;
20
import java.text.MessageFormat;
21
import org.apache.poi.util.BitFieldFactory;
22
21
22
import org.apache.poi.util.HexDump;
23
24
/**
25
 * Class for the FLD structure.
26
 * 
27
 * @author Cedric Bosdonnat <cbosdonnat@novell.com>
28
 *
29
 */
23
public final class FieldDescriptor
30
public final class FieldDescriptor
24
{
31
{
32
  public static final int FIELD_BEGIN_MARK = 0x13;
33
  public static final int FIELD_SEPARATOR_MARK = 0x14;
34
  public static final int FIELD_END_MARK = 0x15;
35
36
  private static final short BOUNDARY_MASK = 0x1F;
37
  private static final short TYPE_MASK = 0xFF;
38
  private static final short ZOMBIE_EMBED_MASK = 0x02;
39
  private static final short RESULT_DIRTY_MASK = 0x04;
40
  private static final short RESULT_EDITED_MASK = 0x08;
41
  private static final short LOCKED_MASK = 0x10;
42
  private static final short PRIVATE_RESULT_MASK = 0x20;
43
  private static final short NESTED_MASK = 0x40;
44
  private static final short HAS_SEP_MASK = 0x80;
45
25
  byte _fieldBoundaryType;
46
  byte _fieldBoundaryType;
26
  byte _info;
47
  byte _info;
27
    private final static BitField fZombieEmbed = BitFieldFactory.getInstance(0x02);
28
    private final static BitField fResultDiry = BitFieldFactory.getInstance(0x04);
29
    private final static BitField fResultEdited = BitFieldFactory.getInstance(0x08);
30
    private final static BitField fLocked = BitFieldFactory.getInstance(0x10);
31
    private final static BitField fPrivateResult = BitFieldFactory.getInstance(0x20);
32
    private final static BitField fNested = BitFieldFactory.getInstance(0x40);
33
    private final static BitField fHasSep = BitFieldFactory.getInstance(0x80);
34
48
49
  private int fieldType;
50
  private boolean zombieEmbed;
51
  private boolean resultDirty;
52
  private boolean resultEdited;
53
  private boolean locked;
54
  private boolean privateResult;
55
  private boolean nested;
56
  private boolean hasSep;
57
58
  public FieldDescriptor(byte[] data)
59
  {
60
    _fieldBoundaryType = (byte) (data[0] & BOUNDARY_MASK);
61
    _info = data[1];
62
63
    if (_fieldBoundaryType == FIELD_BEGIN_MARK)
64
    {
65
      fieldType = _info & TYPE_MASK;
66
    } else if (_fieldBoundaryType == FIELD_END_MARK)
67
    {
68
      zombieEmbed = ((_info & ZOMBIE_EMBED_MASK) == 1);
69
      resultDirty = ((_info & RESULT_DIRTY_MASK) == 1);
70
      resultEdited = ((_info & RESULT_EDITED_MASK) == 1);
71
      locked = ((_info & LOCKED_MASK) == 1);
72
      privateResult = ((_info & PRIVATE_RESULT_MASK) == 1);
73
      nested = ((_info & NESTED_MASK) == 1);
74
      hasSep = ((_info & HAS_SEP_MASK) == 1);
75
    }
76
  }
77
78
  public int getBoundaryType()
79
  {
80
    return _fieldBoundaryType;
81
  }
82
83
  public int getFieldType()
84
  {
85
    if (_fieldBoundaryType != FIELD_BEGIN_MARK)
86
      throw new UnsupportedOperationException(
87
          "This field is only defined for begin marks.");
88
    return fieldType;
89
  }
35
90
36
  public FieldDescriptor()
91
  public boolean isZombieEmbed()
37
  {
92
  {
93
    if (_fieldBoundaryType != FIELD_END_MARK)
94
      throw new UnsupportedOperationException(
95
          "This field is only defined for end marks.");
96
    return zombieEmbed;
97
  }
98
99
  public boolean isResultDirty()
100
  {
101
    if (_fieldBoundaryType != FIELD_END_MARK)
102
      throw new UnsupportedOperationException(
103
          "This field is only defined for end marks.");
104
    return resultDirty;
105
  }
106
107
  public boolean isResultEdited()
108
  {
109
    if (_fieldBoundaryType != FIELD_END_MARK)
110
      throw new UnsupportedOperationException(
111
          "This field is only defined for end marks.");
112
    return resultEdited;
113
  }
114
115
  public boolean isLocked()
116
  {
117
    if (_fieldBoundaryType != FIELD_END_MARK)
118
      throw new UnsupportedOperationException(
119
          "This field is only defined for end marks.");
120
    return locked;
121
  }
122
123
  public boolean isPrivateResult()
124
  {
125
    if (_fieldBoundaryType != FIELD_END_MARK)
126
      throw new UnsupportedOperationException(
127
          "This field is only defined for end marks.");
128
    return privateResult;
129
  }
130
131
  public boolean isNested()
132
  {
133
    if (_fieldBoundaryType != FIELD_END_MARK)
134
      throw new UnsupportedOperationException(
135
          "This field is only defined for end marks.");
136
    return nested;
137
  }
138
139
  public boolean isHasSep()
140
  {
141
    if (_fieldBoundaryType != FIELD_END_MARK)
142
      throw new UnsupportedOperationException(
143
          "This field is only defined for end marks.");
144
    return hasSep;
145
  }
146
147
  public String toString()
148
  {
149
    String details = new String();
150
    if (_fieldBoundaryType == FIELD_BEGIN_MARK)
151
    {
152
      details = " type: " + fieldType;
153
    }
154
    else if (_fieldBoundaryType == FIELD_END_MARK)
155
    {
156
      details = " flags: 0x" + HexDump.toHex(_info);
157
    }
158
159
    return MessageFormat.format("FLD - 0x{0}{1}", HexDump
160
        .toHex((byte) _fieldBoundaryType), details);
38
  }
161
  }
39
}
162
}
(-)a/src/scratchpad/src/org/apache/poi/hwpf/model/FieldsTables.java (+114 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hwpf.model;
19
20
import java.util.ArrayList;
21
import java.util.HashMap;
22
23
24
/**
25
 * This class provides access to all the fields Plex.
26
 * 
27
 * @author Cedric Bosdonnat <cbosdonnat@novell.com>
28
 *
29
 */
30
public class FieldsTables
31
{
32
  public static final int PLCFFLDATN = 0;
33
  public static final int PLCFFLDEDN = 1;
34
  public static final int PLCFFLDFTN = 2;
35
  public static final int PLCFFLDHDR = 3;
36
  public static final int PLCFFLDHDRTXBX = 4;
37
  public static final int PLCFFLDMOM = 5;
38
  public static final int PLCFFLDTXBX = 6;
39
40
  // The size in bytes of the FLD data structure
41
  private static final int FLD_SIZE = 2;
42
43
  private HashMap<Integer, ArrayList<PlexOfField>> _tables;
44
45
  public FieldsTables(byte[] tableStream, FileInformationBlock fib)
46
  {
47
    _tables = new HashMap<Integer, ArrayList<PlexOfField>>();
48
49
    for (int i = PLCFFLDATN; i <= PLCFFLDTXBX; i++ )
50
    {
51
      _tables.put(i, readPLCF(tableStream, fib, i));
52
    }
53
  }
54
  
55
  public ArrayList<PlexOfField> getFieldsPLCF( int type )
56
  {
57
    return _tables.get(type);
58
  }
59
60
  private ArrayList<PlexOfField> readPLCF(byte[] tableStream, FileInformationBlock fib, int type)
61
  {
62
    int start = 0;
63
    int length = 0;
64
65
    switch (type)
66
    {
67
    case PLCFFLDATN:
68
      start = fib.getFcPlcffldAtn();
69
      length = fib.getLcbPlcffldAtn();
70
      break;
71
    case PLCFFLDEDN:
72
      start = fib.getFcPlcffldEdn();
73
      length = fib.getLcbPlcffldEdn();
74
      break;
75
    case PLCFFLDFTN:
76
      start = fib.getFcPlcffldFtn();
77
      length = fib.getLcbPlcffldFtn();
78
      break;
79
    case PLCFFLDHDR:
80
      start = fib.getFcPlcffldHdr();
81
      length = fib.getLcbPlcffldHdr();
82
      break;
83
    case PLCFFLDHDRTXBX:
84
      start = fib.getFcPlcffldHdrtxbx();
85
      length = fib.getLcbPlcffldHdrtxbx();
86
      break;
87
    case PLCFFLDMOM:
88
      start = fib.getFcPlcffldMom();
89
      length = fib.getLcbPlcffldMom();
90
      break;
91
    case PLCFFLDTXBX:
92
      start = fib.getFcPlcffldTxbx();
93
      length = fib.getLcbPlcffldTxbx();
94
    default:
95
      break;
96
    }
97
98
    ArrayList<PlexOfField> fields = new ArrayList<PlexOfField>();
99
100
    if (start > 0 && length > 0)
101
    {
102
      PlexOfCps plcf = new PlexOfCps(tableStream, start, length, FLD_SIZE);
103
      fields.ensureCapacity(plcf.length());
104
105
      for ( int i = 0; i < plcf.length(); i ++ ) {
106
        GenericPropertyNode propNode = plcf.getProperty( i );
107
        PlexOfField plex = new PlexOfField( propNode.getStart(), propNode.getEnd(), propNode.getBytes() );
108
        fields.add( plex );
109
      }
110
    }
111
112
    return fields;
113
  }
114
}
(-)a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (+66 lines)
Lines 66-72 public final class FileInformationBlock extends FIBAbstractType Link Here
66
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFSED));
66
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFSED));
67
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFLST));
67
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFLST));
68
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLFLFO));
68
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLFLFO));
69
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDATN));
70
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDEDN));
71
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDFTN));
72
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDHDR));
73
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDHDRTXBX));
69
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDMOM));
74
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDMOM));
75
      fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDTXBX));
70
      fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFFFN));
76
      fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFFFN));
71
      fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFRMARK));
77
      fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFRMARK));
72
      fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBSAVEDBY));
78
      fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBSAVEDBY));
Lines 456-461 public final class FileInformationBlock extends FIBAbstractType Link Here
456
      _fieldHandler.clearFields();
462
      _fieldHandler.clearFields();
457
    }
463
    }
458
464
465
    public int getFcPlcffldAtn()
466
    {
467
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDATN);
468
    }
469
470
    public int getLcbPlcffldAtn()
471
    {
472
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDATN);
473
    }
474
475
    public int getFcPlcffldEdn()
476
    {
477
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDEDN);
478
    }
479
480
    public int getLcbPlcffldEdn()
481
    {
482
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDEDN);
483
    }
484
485
    public int getFcPlcffldFtn()
486
    {
487
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDFTN);
488
    }
489
490
    public int getLcbPlcffldFtn()
491
    {
492
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDFTN);
493
    }
494
495
    public int getFcPlcffldHdr()
496
    {
497
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDHDR);
498
    }
499
500
    public int getLcbPlcffldHdr()
501
    {
502
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDHDR);
503
    }
504
505
    public int getFcPlcffldHdrtxbx()
506
    {
507
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDHDRTXBX);
508
    }
509
510
    public int getLcbPlcffldHdrtxbx()
511
    {
512
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDHDRTXBX);
513
    }
514
    
459
    public int getFcPlcffldMom()
515
    public int getFcPlcffldMom()
460
    {
516
    {
461
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
517
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDMOM);
Lines 465-470 public final class FileInformationBlock extends FIBAbstractType Link Here
465
    {
521
    {
466
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
522
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDMOM);
467
    }
523
    }
524
    
525
    public int getFcPlcffldTxbx()
526
    {
527
      return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFFLDTXBX);
528
    }
529
530
    public int getLcbPlcffldTxbx()
531
    {
532
      return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFFLDTXBX);
533
    }
468
534
469
    public int getFcPlcspaMom()
535
    public int getFcPlcspaMom()
470
    {
536
    {
(-)a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfField.java (+58 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hwpf.model;
19
20
import java.text.MessageFormat;
21
22
/**
23
 * Structure describing the Plex for fields (contained plclfd* in the spec).
24
 * 
25
 * @author Cedric Bosdonnat <cbosdonnat@novell.com>
26
 *
27
 */
28
public class PlexOfField 
29
{
30
  private int fcStart;
31
  private int fcEnd;
32
  private FieldDescriptor fld;
33
  
34
  public PlexOfField( int fcStart, int fcEnd, byte[] data ) {
35
      this.fcStart = fcStart;
36
      this.fcEnd = fcEnd;
37
      
38
      fld = new FieldDescriptor( data );
39
  }
40
  
41
  public int getFcStart() {
42
      return fcStart;
43
  }
44
45
  public int getFcEnd() {
46
      return fcEnd;
47
  }
48
49
  public FieldDescriptor getFld() {
50
      return fld;
51
  }
52
  
53
  public String toString() {
54
      return MessageFormat.format( "[{0}, {1}) - {2}", 
55
              fcStart, fcEnd, fld.toString() );
56
      
57
  }
58
}
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java (+1 lines)
Lines 69-74 public final class AllHWPFTests { Link Here
69
		suite.addTestSuite(TestSectionTable.class);
69
		suite.addTestSuite(TestSectionTable.class);
70
		suite.addTestSuite(TestStyleSheet.class);
70
		suite.addTestSuite(TestStyleSheet.class);
71
		suite.addTestSuite(TestTextPieceTable.class);
71
		suite.addTestSuite(TestTextPieceTable.class);
72
		suite.addTestSuite(TestFieldsTables.class);
72
73
73
		suite.addTestSuite(TestBug46610.class);
74
		suite.addTestSuite(TestBug46610.class);
74
		suite.addTestSuite(TestHeaderStories.class);
75
		suite.addTestSuite(TestHeaderStories.class);
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFDocFixture.java (-3 / +6 lines)
Lines 25-37 import org.apache.poi.POIDataSamples; Link Here
25
25
26
public final class HWPFDocFixture
26
public final class HWPFDocFixture
27
{
27
{
28
  public static final String DEFAULT_TEST_FILE = "test.doc";
29
  
28
  public byte[] _tableStream;
30
  public byte[] _tableStream;
29
  public byte[] _mainStream;
31
  public byte[] _mainStream;
30
  public FileInformationBlock _fib;
32
  public FileInformationBlock _fib;
33
  private String _testFile;
31
34
32
  public HWPFDocFixture(Object obj)
35
  public HWPFDocFixture(Object obj, String testFile)
33
  {
36
  {
34
37
    _testFile = testFile;
35
  }
38
  }
36
39
37
  public void setUp()
40
  public void setUp()
Lines 39-45 public final class HWPFDocFixture Link Here
39
    try
42
    try
40
    {
43
    {
41
      POIFSFileSystem filesystem = new POIFSFileSystem(
44
      POIFSFileSystem filesystem = new POIFSFileSystem(
42
              POIDataSamples.getDocumentInstance().openResourceAsStream("test.doc"));
45
              POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
43
46
44
      DocumentEntry documentProps =
47
      DocumentEntry documentProps =
45
        (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");
48
        (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/HWPFTestCase.java (-1 / +6 lines)
Lines 32-42 public abstract class HWPFTestCase extends TestCase { Link Here
32
	protected void setUp() throws Exception {
32
	protected void setUp() throws Exception {
33
		super.setUp();
33
		super.setUp();
34
		/** @todo verify the constructors */
34
		/** @todo verify the constructors */
35
		_hWPFDocFixture = new HWPFDocFixture(this);
35
		_hWPFDocFixture = new HWPFDocFixture(this, getTestFile());
36
36
37
		_hWPFDocFixture.setUp();
37
		_hWPFDocFixture.setUp();
38
	}
38
	}
39
39
40
	protected String getTestFile()
41
	{
42
	  return HWPFDocFixture.DEFAULT_TEST_FILE;
43
	}
44
40
	protected void tearDown() throws Exception {
45
	protected void tearDown() throws Exception {
41
		if (_hWPFDocFixture != null) {
46
		if (_hWPFDocFixture != null) {
42
			_hWPFDocFixture.tearDown();
47
			_hWPFDocFixture.tearDown();
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/TestFieldsTables.java (+89 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hwpf;
19
20
import java.util.ArrayList;
21
22
import org.apache.poi.hwpf.model.FieldsTables;
23
import org.apache.poi.hwpf.model.FileInformationBlock;
24
import org.apache.poi.hwpf.model.PlexOfField;
25
26
/**
27
 * Test case for the fields tables, this test is based on the test-fields.doc file
28
 * instead of the usual test.doc.
29
 * 
30
 * @author Cedric Bosdonnat <cbosdonnat@novell.com>
31
 *
32
 */
33
public class TestFieldsTables extends HWPFTestCase
34
{
35
  private static final int ALL_TYPES[] = {
36
      FieldsTables.PLCFFLDATN,
37
      FieldsTables.PLCFFLDEDN,
38
      FieldsTables.PLCFFLDFTN,
39
      FieldsTables.PLCFFLDHDR,
40
      FieldsTables.PLCFFLDHDRTXBX,
41
      FieldsTables.PLCFFLDMOM,
42
      FieldsTables.PLCFFLDTXBX
43
  };
44
  
45
  private static final String EXPECTED[] = {
46
      "[19, 43) - FLD - 0x13 type: 31\n[43, 54) - FLD - 0x14\n[54, 59) - FLD - 0x15 flags: 0x81\n",
47
      "[31, 59) - FLD - 0x13 type: 69\n[59, 61) - FLD - 0x14\n[61, 66) - FLD - 0x15 flags: 0x80\n",
48
      "[23, 49) - FLD - 0x13 type: 17\n[49, 64) - FLD - 0x14\n[64, 69) - FLD - 0x15 flags: 0x80\n",
49
      "[18, 42) - FLD - 0x13 type: 33\n[42, 44) - FLD - 0x14\n[44, 47) - FLD - 0x15 flags: 0x81\n" +
50
        "[47, 75) - FLD - 0x13 type: 29\n[75, 85) - FLD - 0x14\n[85, 91) - FLD - 0x15 flags: 0x81\n",
51
      "[30, 54) - FLD - 0x13 type: 32\n[54, 62) - FLD - 0x14\n[62, 68) - FLD - 0x15 flags: 0x81\n",
52
      "[1, 31) - FLD - 0x13 type: 21\n[31, 51) - FLD - 0x14\n[51, 541) - FLD - 0x15 flags: 0x81\n",
53
      "[19, 47) - FLD - 0x13 type: 25\n[47, 49) - FLD - 0x14\n[49, 55) - FLD - 0x15 flags: 0x81\n"
54
  };
55
  
56
  public TestFieldsTables()
57
  {
58
  }
59
  
60
  protected String getTestFile()
61
  {
62
    return "test-fields.doc";
63
  }
64
  
65
  public void testReadFields()
66
  {
67
    FileInformationBlock fib = _hWPFDocFixture._fib;
68
    byte[] tableStream = _hWPFDocFixture._tableStream;
69
    
70
    FieldsTables fieldsTables = new FieldsTables(tableStream, fib);
71
    
72
    for (int i = 0; i < ALL_TYPES.length; i++)
73
    {
74
      ArrayList<PlexOfField> fieldsPlexes = fieldsTables.getFieldsPLCF( ALL_TYPES[i] );
75
      String result = dumpPlexes(fieldsPlexes);
76
      assertEquals(EXPECTED[i], result);
77
    }
78
  }
79
80
  private String dumpPlexes(ArrayList<PlexOfField> fieldsPlexes)
81
  {
82
    String dump = new String();
83
    for ( int i=0; i<fieldsPlexes.size(); i++)
84
    {
85
      dump += fieldsPlexes.get(i).toString() + "\n";
86
    }
87
    return dump;
88
  }
89
}
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java (-1 / +1 lines)
Lines 77-83 public final class TestCHPBinTable Link Here
77
    throws Exception
77
    throws Exception
78
  {
78
  {
79
    super.setUp();
79
    super.setUp();
80
    _hWPFDocFixture = new HWPFDocFixture(this);
80
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
81
81
82
    _hWPFDocFixture.setUp();
82
    _hWPFDocFixture.setUp();
83
  }
83
  }
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java (-1 / +1 lines)
Lines 66-72 public final class TestDocumentProperties Link Here
66
    super.setUp();
66
    super.setUp();
67
    /**@todo verify the constructors*/
67
    /**@todo verify the constructors*/
68
68
69
    _hWPFDocFixture = new HWPFDocFixture(this);
69
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
70
70
71
    _hWPFDocFixture.setUp();
71
    _hWPFDocFixture.setUp();
72
72
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFileInformationBlock.java (-1 / +1 lines)
Lines 53-59 public final class TestFileInformationBlock Link Here
53
  {
53
  {
54
    super.setUp();
54
    super.setUp();
55
    /**@todo verify the constructors*/
55
    /**@todo verify the constructors*/
56
    _hWPFDocFixture = new HWPFDocFixture(this);
56
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
57
57
58
    _hWPFDocFixture.setUp();
58
    _hWPFDocFixture.setUp();
59
    _fileInformationBlock = _hWPFDocFixture._fib;
59
    _fileInformationBlock = _hWPFDocFixture._fib;
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestFontTable.java (-1 / +1 lines)
Lines 58-64 public final class TestFontTable Link Here
58
  {
58
  {
59
    super.setUp();
59
    super.setUp();
60
    /**@todo verify the constructors*/
60
    /**@todo verify the constructors*/
61
    _hWPFDocFixture = new HWPFDocFixture(this);
61
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
62
62
63
    _hWPFDocFixture.setUp();
63
    _hWPFDocFixture.setUp();
64
  }
64
  }
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java (-1 / +1 lines)
Lines 77-83 public final class TestPAPBinTable Link Here
77
  {
77
  {
78
    super.setUp();
78
    super.setUp();
79
    /**@todo verify the constructors*/
79
    /**@todo verify the constructors*/
80
    _hWPFDocFixture = new HWPFDocFixture(this);
80
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
81
81
82
    _hWPFDocFixture.setUp();
82
    _hWPFDocFixture.setUp();
83
  }
83
  }
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPlexOfCps.java (-1 / +1 lines)
Lines 61-67 public final class TestPlexOfCps Link Here
61
  {
61
  {
62
    super.setUp();
62
    super.setUp();
63
    /**@todo verify the constructors*/
63
    /**@todo verify the constructors*/
64
    _hWPFDocFixture = new HWPFDocFixture(this);
64
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
65
65
66
    _hWPFDocFixture.setUp();
66
    _hWPFDocFixture.setUp();
67
  }
67
  }
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSectionTable.java (-1 / +1 lines)
Lines 92-98 public final class TestSectionTable Link Here
92
  {
92
  {
93
    super.setUp();
93
    super.setUp();
94
    /**@todo verify the constructors*/
94
    /**@todo verify the constructors*/
95
    _hWPFDocFixture = new HWPFDocFixture(this);
95
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
96
96
97
    _hWPFDocFixture.setUp();
97
    _hWPFDocFixture.setUp();
98
  }
98
  }
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java (-1 / +1 lines)
Lines 66-72 public final class TestStyleSheet Link Here
66
  {
66
  {
67
    super.setUp();
67
    super.setUp();
68
    /**@todo verify the constructors*/
68
    /**@todo verify the constructors*/
69
    _hWPFDocFixture = new HWPFDocFixture(this);
69
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
70
    _hWPFDocFixture.setUp();
70
    _hWPFDocFixture.setUp();
71
    FileInformationBlock fib = _hWPFDocFixture._fib;
71
    FileInformationBlock fib = _hWPFDocFixture._fib;
72
    byte[] mainStream = _hWPFDocFixture._mainStream;
72
    byte[] mainStream = _hWPFDocFixture._mainStream;
(-)a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java (-1 / +1 lines)
Lines 170-176 public final class TestTextPieceTable extends TestCase { Link Here
170
  {
170
  {
171
    super.setUp();
171
    super.setUp();
172
172
173
    _hWPFDocFixture = new HWPFDocFixture(this);
173
    _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
174
    _hWPFDocFixture.setUp();
174
    _hWPFDocFixture.setUp();
175
  }
175
  }
176
176

Return to bug 50313