Search in sources :

Example 6 with DirectoryProperty

use of org.apache.poi.poifs.property.DirectoryProperty in project poi by apache.

the class POIFSHeaderDumper method displayProperties.

public static void displayProperties(DirectoryProperty prop, String indent) {
    String nextIndent = indent + "  ";
    System.out.println(indent + "-> " + prop.getName());
    for (Property cp : prop) {
        if (cp instanceof DirectoryProperty) {
            displayProperties((DirectoryProperty) cp, nextIndent);
        } else {
            System.out.println(nextIndent + "=> " + cp.getName());
            System.out.print(nextIndent + "   " + cp.getSize() + " bytes in ");
            if (cp.shouldUseSmallBlocks()) {
                System.out.print("mini");
            } else {
                System.out.print("main");
            }
            System.out.println(" stream, starts at " + cp.getStartBlock());
        }
    }
}
Also used : DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) Property(org.apache.poi.poifs.property.Property) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 7 with DirectoryProperty

use of org.apache.poi.poifs.property.DirectoryProperty in project poi by apache.

the class TestPropertySorter method getVBAProperties.

/**
     * @return array of properties read from ROOT._VBA_PROJECT_CUR.VBA node
     */
protected Property[] getVBAProperties(POIFSFileSystem fs) throws IOException {
    String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR";
    String VBA = "VBA";
    DirectoryEntry root = fs.getRoot();
    DirectoryEntry vba_project = (DirectoryEntry) root.getEntry(_VBA_PROJECT_CUR);
    DirectoryNode vba = (DirectoryNode) vba_project.getEntry(VBA);
    DirectoryProperty p = (DirectoryProperty) vba.getProperty();
    List<Property> lst = new ArrayList<Property>();
    for (Iterator<Property> it = p.getChildren(); it.hasNext(); ) {
        Property ch = it.next();
        lst.add(ch);
    }
    return lst.toArray(new Property[0]);
}
Also used : DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) ArrayList(java.util.ArrayList) Property(org.apache.poi.poifs.property.Property) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 8 with DirectoryProperty

use of org.apache.poi.poifs.property.DirectoryProperty in project poi by apache.

the class TestDocumentInputStream method setUp.

@Override
protected void setUp() throws Exception {
    int blocks = (_workbook_size + 511) / 512;
    _workbook_data = new byte[512 * blocks];
    Arrays.fill(_workbook_data, (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];
    ByteArrayInputStream stream = new ByteArrayInputStream(_workbook_data);
    for (int j = 0; j < blocks; j++) {
        rawBlocks[j] = new RawDataBlock(stream);
    }
    OPOIFSDocument document = new OPOIFSDocument("Workbook", rawBlocks, _workbook_size);
    _workbook_o = new DocumentNode(document.getDocumentProperty(), new DirectoryNode(new DirectoryProperty("Root Entry"), (POIFSFileSystem) null, null));
    // Now create the NPOIFS Version
    byte[] _workbook_data_only = new byte[_workbook_size];
    System.arraycopy(_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, (byte) -1);
    npoifs.getBlockAt(-1).put(minus1);
    npoifs.getBlockAt(0).put(minus1);
    npoifs.getBlockAt(1).put(minus1);
    // Create the NPOIFS document
    _workbook_n = (DocumentNode) npoifs.createDocument(new ByteArrayInputStream(_workbook_data_only), "Workbook");
}
Also used : DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) RawDataBlock(org.apache.poi.poifs.storage.RawDataBlock) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 9 with DirectoryProperty

use of org.apache.poi.poifs.property.DirectoryProperty in project poi by apache.

the class TestDocumentNode method testConstructor.

/**
     * test constructor
     */
public void testConstructor() throws IOException {
    DirectoryProperty property1 = new DirectoryProperty("directory");
    RawDataBlock[] rawBlocks = new RawDataBlock[4];
    ByteArrayInputStream stream = new ByteArrayInputStream(new byte[2048]);
    for (int j = 0; j < 4; j++) {
        rawBlocks[j] = new RawDataBlock(stream);
    }
    OPOIFSDocument document = new OPOIFSDocument("document", rawBlocks, 2000);
    DocumentProperty property2 = document.getDocumentProperty();
    DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem) null, null);
    DocumentNode node = new DocumentNode(property2, parent);
    // verify we can retrieve the document
    assertEquals(property2.getDocument(), node.getDocument());
    // verify we can get the size
    assertEquals(property2.getSize(), node.getSize());
    // verify isDocumentEntry returns true
    assertTrue(node.isDocumentEntry());
    // verify isDirectoryEntry returns false
    assertTrue(!node.isDirectoryEntry());
    // verify getName behaves correctly
    assertEquals(property2.getName(), node.getName());
    // verify getParent behaves correctly
    assertEquals(parent, node.getParent());
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) RawDataBlock(org.apache.poi.poifs.storage.RawDataBlock)

Example 10 with DirectoryProperty

use of org.apache.poi.poifs.property.DirectoryProperty in project poi by apache.

the class TestDirectoryNode method testNonEmptyConstructor.

/**
     * test non-trivial constructor (a DirectoryNode with children)
     */
public void testNonEmptyConstructor() throws IOException {
    DirectoryProperty property1 = new DirectoryProperty("parent");
    DirectoryProperty property2 = new DirectoryProperty("child1");
    property1.addChild(property2);
    property1.addChild(new DocumentProperty("child2", 2000));
    property2.addChild(new DocumentProperty("child3", 30000));
    DirectoryNode node = new DirectoryNode(property1, new POIFSFileSystem(), null);
    // verify that getEntries behaves correctly
    int count = 0;
    Iterator<Entry> iter = node.getEntries();
    while (iter.hasNext()) {
        count++;
        iter.next();
    }
    assertEquals(2, count);
    // verify behavior of isEmpty
    assertTrue(!node.isEmpty());
    // verify behavior of getEntryCount
    assertEquals(2, node.getEntryCount());
    // verify behavior of getEntry
    DirectoryNode child1 = (DirectoryNode) node.getEntry("child1");
    child1.getEntry("child3");
    node.getEntry("child2");
    try {
        node.getEntry("child3");
        fail("should have caught FileNotFoundException");
    } catch (FileNotFoundException ignored) {
    // as expected
    }
    // verify behavior of isDirectoryEntry
    assertTrue(node.isDirectoryEntry());
    // verify behavior of getName
    assertEquals(property1.getName(), node.getName());
    // verify behavior of isDocumentEntry
    assertTrue(!node.isDocumentEntry());
    // verify behavior of getParent
    assertNull(node.getParent());
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

DirectoryProperty (org.apache.poi.poifs.property.DirectoryProperty)11 DocumentProperty (org.apache.poi.poifs.property.DocumentProperty)4 Property (org.apache.poi.poifs.property.Property)4 FileNotFoundException (java.io.FileNotFoundException)2 RawDataBlock (org.apache.poi.poifs.storage.RawDataBlock)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)1 OPOIFSDocument (org.apache.poi.poifs.filesystem.OPOIFSDocument)1 POIFSDocumentPath (org.apache.poi.poifs.filesystem.POIFSDocumentPath)1 RootProperty (org.apache.poi.poifs.property.RootProperty)1