FileDocCategorySizeDatePackage
PropertyTable.javaAPI DocApache Poi 3.0.16771Mon Jan 01 12:39:36 GMT 2007org.apache.poi.poifs.property

PropertyTable

public class PropertyTable extends Object implements BlockWritable, BATManaged
This class embodies the Property Table for the filesystem; this is basically the dsirectory for all of the documents in the filesystem.
author
Marc Johnson (mjohnson at apache dot org)

Fields Summary
private int
_start_block
private List
_properties
private BlockWritable[]
_blocks
Constructors Summary
public PropertyTable()
Default constructor

        _start_block = POIFSConstants.END_OF_CHAIN;
        _properties  = new ArrayList();
        addProperty(new RootProperty());
        _blocks = null;
    
public PropertyTable(int startBlock, RawDataBlockList blockList)
reading constructor (used when we've read in a file and we want to extract the property table from it). Populates the properties thoroughly

param
startBlock the first block of the property table
param
blockList the list of blocks
exception
IOException if anything goes wrong (which should be a result of the input being NFG)

        _start_block = POIFSConstants.END_OF_CHAIN;
        _blocks      = null;
        _properties  =
            PropertyFactory
                .convertToProperties(blockList.fetchBlocks(startBlock));
        populatePropertyTree(( DirectoryProperty ) _properties.get(0));
    
Methods Summary
public voidaddProperty(org.apache.poi.poifs.property.Property property)
Add a property to the list of properties we manage

param
property the new Property to manage

        _properties.add(property);
    
public intcountBlocks()
Return the number of BigBlock's this instance uses

return
count of BigBlock instances

        return (_blocks == null) ? 0
                                 : _blocks.length;
    
public org.apache.poi.poifs.property.RootPropertygetRoot()
Get the root property

return
the root property


        // it's always the first element in the List
        return ( RootProperty ) _properties.get(0);
    
public intgetStartBlock()
Get the start block for the property table

return
start block index

        return _start_block;
    
private voidpopulatePropertyTree(org.apache.poi.poifs.property.DirectoryProperty root)

        int index = root.getChildIndex();

        if (!Property.isValidIndex(index))
        {

            // property has no children
            return;
        }
        Stack children = new Stack();

        children.push(_properties.get(index));
        while (!children.empty())
        {
            Property property = ( Property ) children.pop();

            root.addChild(property);
            if (property.isDirectory())
            {
                populatePropertyTree(( DirectoryProperty ) property);
            }
            index = property.getPreviousChildIndex();
            if (Property.isValidIndex(index))
            {
                children.push(_properties.get(index));
            }
            index = property.getNextChildIndex();
            if (Property.isValidIndex(index))
            {
                children.push(_properties.get(index));
            }
        }
    
public voidpreWrite()
Prepare to be written

        Property[] properties =
            ( Property [] ) _properties.toArray(new Property[ 0 ]);

        // give each property its index
        for (int k = 0; k < properties.length; k++)
        {
            properties[ k ].setIndex(k);
        }

        // allocate the blocks for the property table
        _blocks = PropertyBlock.createPropertyBlockArray(_properties);

        // prepare each property for writing
        for (int k = 0; k < properties.length; k++)
        {
            properties[ k ].preWrite();
        }
    
public voidremoveProperty(org.apache.poi.poifs.property.Property property)
Remove a property from the list of properties we manage

param
property the Property to be removed

        _properties.remove(property);
    
public voidsetStartBlock(int index)
Set the start block for this instance

param
index index into the array of BigBlock instances making up the the filesystem

        _start_block = index;
    
public voidwriteBlocks(java.io.OutputStream stream)
Write the storage to an OutputStream

param
stream the OutputStream to which the stored data should be written
exception
IOException on problems writing to the specified stream

        if (_blocks != null)
        {
            for (int j = 0; j < _blocks.length; j++)
            {
                _blocks[ j ].writeBlocks(stream);
            }
        }