public void TestConstructor() { DirectoryProperty property1 = new DirectoryProperty("directory"); RawDataBlock[] rawBlocks = new RawDataBlock[4]; MemoryStream stream = new MemoryStream(new byte[2048]); for (int j = 0; j < 4; j++) { rawBlocks[j] = new RawDataBlock(stream); } POIFSDocument document = new POIFSDocument("document", rawBlocks, 2000); DocumentProperty property2 = document.DocumentProperty; DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem)null, null); DocumentNode node = new DocumentNode(property2, parent); // Verify we can retrieve the document Assert.AreEqual(property2.Document, node.Document); // Verify we can Get the size Assert.AreEqual(property2.Size, node.Size); // Verify isDocumentEntry returns true Assert.IsTrue(node.IsDocumentEntry); // Verify isDirectoryEntry returns false Assert.IsTrue(!node.IsDirectoryEntry); // Verify GetName behaves correctly Assert.AreEqual(property2.Name, node.Name); // Verify GetParent behaves correctly Assert.AreEqual(parent, node.Parent); }
public DocumentTreeNode(DocumentNode documentNode) : base(documentNode) { this.DocumentNode = documentNode; ChangeImage(documentNode.Name.EndsWith("SummaryInformation") ? "SummaryStream" : "File"); }
public TestDocumentInputStream() { int blocks = (_workbook_size + 511) / 512; _workbook_data = new byte[512 * blocks]; Arrays.Fill(_workbook_data, unchecked((byte)-1)); for (int j = 0; j < _workbook_size; j++) { _workbook_data[j] = (byte)(j * j); } // Create the Old POIFS Version RawDataBlock[] rawBlocks = new RawDataBlock[blocks]; MemoryStream stream = new MemoryStream(_workbook_data); for (int j = 0; j < blocks; j++) { rawBlocks[j] = new RawDataBlock(stream); } POIFSDocument document = new POIFSDocument("Workbook", rawBlocks, _workbook_size); _workbook_o = new DocumentNode( document.DocumentProperty, new DirectoryNode( new DirectoryProperty("Root Entry"), (POIFSFileSystem)null, null)); // Now create the NPOIFS Version byte[] _workbook_data_only = new byte[_workbook_size]; Array.Copy(_workbook_data, 0, _workbook_data_only, 0, _workbook_size); NPOIFSFileSystem npoifs = new NPOIFSFileSystem(); // Make it easy when debugging to see what isn't the doc byte[] minus1 = new byte[512]; Arrays.Fill(minus1, unchecked((byte)-1)); npoifs.GetBlockAt(-1).Write(minus1); npoifs.GetBlockAt(0).Write(minus1); npoifs.GetBlockAt(1).Write(minus1); // Create the NPOIFS document _workbook_n = (DocumentNode)npoifs.CreateDocument( new MemoryStream(_workbook_data_only), "Workbook" ); }
/// <summary> /// Create a DirectoryNode. This method Is not public by design; it /// Is intended strictly for the internal use of this package /// </summary> /// <param name="property">the DirectoryProperty for this DirectoryEntry</param> /// <param name="filesystem">the POIFSFileSystem we belong to</param> /// <param name="parent">the parent of this entry</param> public DirectoryNode(DirectoryProperty property, POIFSFileSystem filesystem, DirectoryNode parent):base(property, parent) { if (parent == null) { _path = new POIFSDocumentPath(); } else { _path = new POIFSDocumentPath(parent._path, new String[] { property.Name }); } _filesystem = filesystem; _entries = new Hashtable(); IEnumerator iter = property.Children; while (iter.MoveNext()) { Property child = ( Property ) iter.Current; Entry childNode = null; if (child.IsDirectory) { childNode = new DirectoryNode(( DirectoryProperty ) child, _filesystem, this); } else { childNode = new DocumentNode(( DocumentProperty ) child, this); } _entries[childNode.Name]=childNode; } }
/// <summary> /// Create a new DocumentEntry /// </summary> /// <param name="document">the new document</param> /// <returns>the new DocumentEntry</returns> internal DocumentEntry CreateDocument(POIFSDocument document) { DocumentProperty property = document.DocumentProperty; DocumentNode rval = new DocumentNode(property, this); (( DirectoryProperty ) Property).AddChild(property); _filesystem.AddDocument(document); _entries[property.Name]=rval; return rval; }
/** * Constructor for an existing Document */ public NPOIFSDocument(DocumentNode document) : this((DocumentProperty)document.Property, ((DirectoryNode)document.Parent).NFileSystem) { }