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

PropertyFactory

public class PropertyFactory extends Object
Factory for turning an array of RawDataBlock instances containing Proprty data into an array of proper Property objects. The array produced may be sparse, in that any portion of data that should correspond to a Property, but which does not map to a proper Property (i.e., a DirectoryProperty, DocumentProperty, or RootProperty) will get mapped to a null Property in the array.
author
Marc Johnson (mjohnson at apache dot org)

Fields Summary
Constructors Summary
private PropertyFactory()

    
Methods Summary
static java.util.ListconvertToProperties(org.apache.poi.poifs.storage.ListManagedBlock[] blocks)
Convert raw data blocks to an array of Property's

param
blocks to be converted
return
the converted List of Property objects. May contain nulls, but will not be null
exception
IOException if any of the blocks are empty

        List properties = new ArrayList();

        for (int j = 0; j < blocks.length; j++)
        {
            byte[] data           = blocks[ j ].getData();
            int    property_count = data.length
                                    / POIFSConstants.PROPERTY_SIZE;
            int    offset         = 0;

            for (int k = 0; k < property_count; k++)
            {
                switch (data[ offset + PropertyConstants.PROPERTY_TYPE_OFFSET ])
                {

                    case PropertyConstants.DIRECTORY_TYPE :
                        properties
                            .add(new DirectoryProperty(properties.size(),
                                                       data, offset));
                        break;

                    case PropertyConstants.DOCUMENT_TYPE :
                        properties.add(new DocumentProperty(properties.size(),
                                                            data, offset));
                        break;

                    case PropertyConstants.ROOT_TYPE :
                        properties.add(new RootProperty(properties.size(),
                                                        data, offset));
                        break;

                    default :
                        properties.add(null);
                        break;
                }
                offset += POIFSConstants.PROPERTY_SIZE;
            }
        }
        return properties;