public void SetUp() { POIFSFileSystem filesystem = new POIFSFileSystem( POIDataSamples.GetDocumentInstance().OpenResourceAsStream("test.doc")); DocumentEntry documentProps = (DocumentEntry)filesystem.Root.GetEntry("WordDocument"); _mainStream = new byte[documentProps.Size]; filesystem.CreateDocumentInputStream("WordDocument").Read(_mainStream); // use the fib to determine the name of the table stream. _fib = new FileInformationBlock(_mainStream); String name = "0Table"; if (_fib.IsFWhichTblStm()) { name = "1Table"; } // read in the table stream. DocumentEntry tableProps = (DocumentEntry)filesystem.Root.GetEntry(name); _tableStream = new byte[tableProps.Size]; filesystem.CreateDocumentInputStream(name).Read(_tableStream); _fib.FillVariableFields(_mainStream, _tableStream); }
public void SetUp() { /**@todo verify the constructors*/ _hWPFDocFixture = new HWPFDocFixture(this); _hWPFDocFixture.SetUp(); _fileInformationBlock = _hWPFDocFixture._fib; }
private PlexOfCps ReadPLCF(byte[] tableStream, FileInformationBlock fib, FieldsDocumentPart documentPart) { int start = fib.GetFieldsPlcfOffset(documentPart); int length = fib.GetFieldsPlcfLength(documentPart); if (start <= 0 || length <= 0) return null; return new PlexOfCps(tableStream, start, length, FLD_SIZE); }
public FieldsTables(byte[] tableStream, FileInformationBlock fib) { Array values = Enum.GetValues(typeof(FieldsDocumentPart)); _tables = new Dictionary<FieldsDocumentPart, PlexOfCps>( values.Length); foreach (FieldsDocumentPart part in values) { PlexOfCps plexOfCps = ReadPLCF(tableStream, fib, part); _tables.Add(part, plexOfCps); } }
private PlexOfCps ReadPLCF(byte[] tableStream, FileInformationBlock fib, FieldsDocumentPart documentPart) { int start = fib.GetFieldsPlcfOffset(documentPart); int length = fib.GetFieldsPlcfLength(documentPart); if (start <= 0 || length <= 0) { return(null); } return(new PlexOfCps(tableStream, start, length, FLD_SIZE)); }
public void SetUp() { /**@todo verify the constructors*/ _hWPFDocFixture = new HWPFDocFixture(this); _hWPFDocFixture.SetUp(); FileInformationBlock fib = _hWPFDocFixture._fib; byte[] mainStream = _hWPFDocFixture._mainStream; byte[] tableStream = _hWPFDocFixture._tableStream; _hWPFDocFixture.SetUp(); _styleSheet = new StyleSheet(tableStream, fib.GetFcStshf()); }
public FieldsTables(byte[] tableStream, FileInformationBlock fib) { Array values = Enum.GetValues(typeof(FieldsDocumentPart)); _tables = new Dictionary <FieldsDocumentPart, PlexOfCps>( values.Length); foreach (FieldsDocumentPart part in values) { PlexOfCps plexOfCps = ReadPLCF(tableStream, fib, part); _tables.Add(part, plexOfCps); } }
public FSPATable(byte[] tableStream, FileInformationBlock fib, FSPADocumentPart part) { int offset = fib.GetFSPAPlcfOffset(part); int length = fib.GetFSPAPlcfLength(part); PlexOfCps plex = new PlexOfCps(tableStream, offset, length, FSPA.FSPA_SIZE); for (int i = 0; i < plex.Length; i++) { GenericPropertyNode property = plex.GetProperty(i); _byStart.Add(property.Start, property); } }
private void Read(byte[] tableStream, FileInformationBlock fib) { int referencesStart = fib.GetNotesDescriptorsOffset(noteType); int referencesLength = fib.GetNotesDescriptorsSize(noteType); if (referencesStart != 0 && referencesLength != 0) this.descriptors = new PlexOfCps(tableStream, referencesStart, referencesLength, FootnoteReferenceDescriptor.GetSize()); int textPositionsStart = fib.GetNotesTextPositionsOffset(noteType); int textPositionsLength = fib.GetNotesTextPositionsSize(noteType); if (textPositionsStart != 0 && textPositionsLength != 0) this.textPositions = new PlexOfCps(tableStream, textPositionsStart, textPositionsLength, 0); }
public void WriteRef(FileInformationBlock fib, HWPFStream tableStream) { if (descriptors == null || descriptors.Length == 0) { fib.SetNotesDescriptorsOffset(noteType, tableStream.Offset); fib.SetNotesDescriptorsSize(noteType, 0); return; } int start = tableStream.Offset; byte[] data = descriptors.ToByteArray(); tableStream.Write(data); int end =tableStream.Offset; fib.SetNotesDescriptorsOffset(noteType, start); fib.SetNotesDescriptorsSize(noteType, end - start); }
public void TestReadWrite() { int size = _fileInformationBlock.GetSize(); byte[] buf = new byte[size]; _fileInformationBlock.Serialize(buf, 0); FileInformationBlock newFileInformationBlock = new FileInformationBlock(buf); FieldInfo[] fields = typeof(FileInformationBlock).BaseType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic); for (int x = 0; x < fields.Length; x++) { Assert.AreEqual(fields[x].GetValue(_fileInformationBlock), fields[x].GetValue(newFileInformationBlock)); } }
public void WriteSttbfBkmk(FileInformationBlock fib, HWPFStream tableStream) { if (names == null || names.Length == 0) { fib.SetFcSttbfbkmk(0); fib.SetLcbSttbfbkmk(0); return; } int start = tableStream.Offset; SttbfUtils.Write(tableStream, names); int end = tableStream.Offset; fib.SetFcSttbfbkmk(start); fib.SetLcbSttbfbkmk(end - start); }
public void WritePlcfBkmkl(FileInformationBlock fib, HWPFStream tableStream) { if (descriptorsLim == null || descriptorsLim.Length == 0) { fib.SetFcPlcfbkl(0); fib.SetLcbPlcfbkl(0); return; } int start = tableStream.Offset; tableStream.Write(descriptorsLim.ToByteArray()); int end = tableStream.Offset; fib.SetFcPlcfbkl(start); fib.SetLcbPlcfbkl(end - start); }
public void WriteRef(FileInformationBlock fib, HWPFStream tableStream) { if (descriptors == null || descriptors.Length == 0) { fib.SetNotesDescriptorsOffset(noteType, tableStream.Offset); fib.SetNotesDescriptorsSize(noteType, 0); return; } int start = tableStream.Offset; byte[] data = descriptors.ToByteArray(); tableStream.Write(data); int end = tableStream.Offset; fib.SetNotesDescriptorsOffset(noteType, start); fib.SetNotesDescriptorsSize(noteType, end - start); }
public void WriteTxt(FileInformationBlock fib, HWPFStream tableStream) { if (textPositions == null || textPositions.Length == 0) { fib.SetNotesTextPositionsOffset(noteType, tableStream.Offset); fib.SetNotesTextPositionsSize(noteType, 0); return; } int start = tableStream.Offset; byte[] data = textPositions.ToByteArray(); tableStream.Write(data); int end = tableStream.Offset; fib.SetNotesTextPositionsOffset(noteType, start); fib.SetNotesTextPositionsSize(noteType, end - start); }
private ArrayList _shapesVisibili; //holds visible shapes public ShapesTable(byte[] tblStream, FileInformationBlock fib) { PlexOfCps binTable = new PlexOfCps(tblStream, fib.GetFcPlcspaMom(), fib.GetLcbPlcspaMom(), 26); _shapes = new ArrayList(); _shapesVisibili = new ArrayList(); for (int i = 0; i < binTable.Length; i++) { GenericPropertyNode nodo = binTable.GetProperty(i); Shape sh = new Shape(nodo); _shapes.Add(sh); if (sh.IsWithinDocument) _shapesVisibili.Add(sh); } }
private void Read(byte[] tableStream, FileInformationBlock fib) { int referencesStart = fib.GetNotesDescriptorsOffset(noteType); int referencesLength = fib.GetNotesDescriptorsSize(noteType); if (referencesStart != 0 && referencesLength != 0) { this.descriptors = new PlexOfCps(tableStream, referencesStart, referencesLength, FootnoteReferenceDescriptor.GetSize()); } int textPositionsStart = fib.GetNotesTextPositionsOffset(noteType); int textPositionsLength = fib.GetNotesTextPositionsSize(noteType); if (textPositionsStart != 0 && textPositionsLength != 0) { this.textPositions = new PlexOfCps(tableStream, textPositionsStart, textPositionsLength, 0); } }
private ArrayList _shapesVisibili; //holds visible shapes public ShapesTable(byte[] tblStream, FileInformationBlock fib) { PlexOfCps binTable = new PlexOfCps(tblStream, fib.GetFcPlcspaMom(), fib.GetLcbPlcspaMom(), 26); _shapes = new ArrayList(); _shapesVisibili = new ArrayList(); for (int i = 0; i < binTable.Length; i++) { GenericPropertyNode nodo = binTable.GetProperty(i); Shape sh = new Shape(nodo); _shapes.Add(sh); if (sh.IsWithinDocument) { _shapesVisibili.Add(sh); } } }
private void Read(byte[] tableStream, FileInformationBlock fib) { int namesStart = fib.GetFcSttbfbkmk(); int namesLength = fib.GetLcbSttbfbkmk(); if (namesStart != 0 && namesLength != 0) this.names = SttbfUtils.Read(tableStream, namesStart); int firstDescriptorsStart = fib.GetFcPlcfbkf(); int firstDescriptorsLength = fib.GetLcbPlcfbkf(); if (firstDescriptorsStart != 0 && firstDescriptorsLength != 0) descriptorsFirst = new PlexOfCps(tableStream, firstDescriptorsStart, firstDescriptorsLength, BookmarkFirstDescriptor.GetSize()); int limDescriptorsStart = fib.GetFcPlcfbkl(); int limDescriptorsLength = fib.GetLcbPlcfbkl(); if (limDescriptorsStart != 0 && limDescriptorsLength != 0) descriptorsLim = new PlexOfCps(tableStream, limDescriptorsStart, limDescriptorsLength, 0); }
private int SavePlex(FileInformationBlock fib, FieldsDocumentPart part, PlexOfCps plexOfCps, HWPFStream outputStream) { if (plexOfCps == null || plexOfCps.Length == 0) { fib.SetFieldsPlcfOffset(part, outputStream.Offset); fib.SetFieldsPlcfLength(part, 0); return(0); } byte[] data = plexOfCps.ToByteArray(); int start = outputStream.Offset; int length = data.Length; outputStream.Write(data); fib.SetFieldsPlcfOffset(part, start); fib.SetFieldsPlcfLength(part, length); return(length); }
private int SavePlex(FileInformationBlock fib, FieldsDocumentPart part, PlexOfCps plexOfCps, HWPFStream outputStream) { if (plexOfCps == null || plexOfCps.Length == 0) { fib.SetFieldsPlcfOffset(part, outputStream.Offset); fib.SetFieldsPlcfLength(part, 0); return 0; } byte[] data = plexOfCps.ToByteArray(); int start = outputStream.Offset; int length = data.Length; outputStream.Write(data); fib.SetFieldsPlcfOffset(part, start); fib.SetFieldsPlcfLength(part, length); return length; }
public void TestReadWrite() { TextPieceTable fakeTPT = new TextPieceTable(); FileInformationBlock fib = _hWPFDocFixture._fib; byte[] mainStream = _hWPFDocFixture._mainStream; byte[] tableStream = _hWPFDocFixture._tableStream; _pAPBinTable = new PAPBinTable(mainStream, tableStream, null, fib.GetFcPlcfbtePapx(), fib.GetLcbPlcfbtePapx(), fakeTPT); HWPFFileSystem fileSys = new HWPFFileSystem(); _pAPBinTable.WriteTo(fileSys, fakeTPT); MemoryStream tableOut = fileSys.GetStream("1Table"); MemoryStream mainOut = fileSys.GetStream("WordDocument"); byte[] newTableStream = tableOut.ToArray(); byte[] newMainStream = mainOut.ToArray(); PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, null, 0, newTableStream.Length, fakeTPT); List <PAPX> oldTextRuns = _pAPBinTable.GetParagraphs(); List <PAPX> newTextRuns = newBinTable.GetParagraphs(); Assert.AreEqual(oldTextRuns.Count, newTextRuns.Count); int size = oldTextRuns.Count; for (int x = 0; x < size; x++) { PropertyNode oldNode = (PropertyNode)oldTextRuns[x]; PropertyNode newNode = (PropertyNode)newTextRuns[x]; Assert.IsTrue(oldNode.Equals(newNode)); } }
public CPSplitCalculator(FileInformationBlock fib) { this.fib = fib; }
/// <summary> /// This constructor loads a Word document from a specific point in a POIFSFileSystem, probably not the default.Used typically to open embeded documents. /// </summary> /// <param name="directory">The POIFSFileSystem that Contains the Word document.</param> /// <param name="pfilesystem">If there is an unexpected IOException from the passed in POIFSFileSystem.</param> public HWPFDocumentCore(DirectoryNode directory) : base(directory) { // Sort out the hpsf properties // read in the main stream. DocumentEntry documentProps = (DocumentEntry) directory.GetEntry(STREAM_WORD_DOCUMENT); _mainStream = new byte[documentProps.Size]; directory.CreatePOIFSDocumentReader(STREAM_WORD_DOCUMENT).Read(_mainStream); // Create our FIB, and check for the doc being encrypted _fib = new FileInformationBlock(_mainStream); if (_fib.IsFEncrypted()) { throw new EncryptedDocumentException("Cannot process encrypted word files!"); } DirectoryEntry objectPoolEntry; try { objectPoolEntry = (DirectoryEntry)directory.GetEntry(STREAM_OBJECT_POOL); } catch (FileNotFoundException exc) { objectPoolEntry = null; } _objectPool = new ObjectPoolImpl(objectPoolEntry); }
public NotesTables(NoteType noteType, byte[] tableStream, FileInformationBlock fib) { this.noteType = noteType; Read(tableStream, fib); }
public void Write(FileInformationBlock fib, HWPFStream tableStream) { Array values = Enum.GetValues(typeof(FieldsDocumentPart)); foreach (FieldsDocumentPart part in values) { PlexOfCps plexOfCps = _tables[part]; SavePlex(fib, part, plexOfCps, tableStream); } }
public void TearDown() { _fileInformationBlock = null; _hWPFDocFixture = null; }
public BookmarksTables(byte[] tableStream, FileInformationBlock fib) { Read(tableStream, fib); }