Search in sources :

Example 1 with DirectoryProperty

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

the class DirectoryNode method createDirectory.

/**
     * create a new DirectoryEntry
     *
     * @param name the name of the new DirectoryEntry
     *
     * @return the new DirectoryEntry
     *
     * @exception IOException
     */
public DirectoryEntry createDirectory(final String name) throws IOException {
    DirectoryNode rval;
    DirectoryProperty property = new DirectoryProperty(name);
    if (_ofilesystem != null) {
        rval = new DirectoryNode(property, _ofilesystem, this);
        _ofilesystem.addDirectory(property);
    } else {
        rval = new DirectoryNode(property, _nfilesystem, this);
        _nfilesystem.addDirectory(property);
    }
    ((DirectoryProperty) getProperty()).addChild(property);
    _entries.add(rval);
    _byname.put(name, rval);
    return rval;
}
Also used : DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 2 with DirectoryProperty

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

the class POIFSReader method processProperties.

private void processProperties(final BlockList small_blocks, final BlockList big_blocks, final Iterator<Property> properties, final POIFSDocumentPath path) throws IOException {
    if (!properties.hasNext() && notifyEmptyDirectories) {
        Iterator<POIFSReaderListener> listeners = registry.getListeners(path, ".");
        while (listeners.hasNext()) {
            POIFSReaderListener pl = listeners.next();
            POIFSReaderEvent pe = new POIFSReaderEvent(null, path, null);
            pl.processPOIFSReaderEvent(pe);
        }
        return;
    }
    while (properties.hasNext()) {
        Property property = properties.next();
        String name = property.getName();
        if (property.isDirectory()) {
            POIFSDocumentPath new_path = new POIFSDocumentPath(path, new String[] { name });
            DirectoryProperty dp = (DirectoryProperty) property;
            processProperties(small_blocks, big_blocks, dp.getChildren(), new_path);
        } else {
            int startBlock = property.getStartBlock();
            Iterator<POIFSReaderListener> listeners = registry.getListeners(path, name);
            if (listeners.hasNext()) {
                int size = property.getSize();
                OPOIFSDocument document = null;
                if (property.shouldUseSmallBlocks()) {
                    document = new OPOIFSDocument(name, small_blocks.fetchBlocks(startBlock, -1), size);
                } else {
                    document = new OPOIFSDocument(name, big_blocks.fetchBlocks(startBlock, -1), size);
                }
                while (listeners.hasNext()) {
                    POIFSReaderListener listener = listeners.next();
                    listener.processPOIFSReaderEvent(new POIFSReaderEvent(new DocumentInputStream(document), path, name));
                }
            } else {
                // consume the document's data and discard it
                if (property.shouldUseSmallBlocks()) {
                    small_blocks.fetchBlocks(startBlock, -1);
                } else {
                    big_blocks.fetchBlocks(startBlock, -1);
                }
            }
        }
    }
}
Also used : POIFSDocumentPath(org.apache.poi.poifs.filesystem.POIFSDocumentPath) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) OPOIFSDocument(org.apache.poi.poifs.filesystem.OPOIFSDocument) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream) Property(org.apache.poi.poifs.property.Property) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) RootProperty(org.apache.poi.poifs.property.RootProperty)

Example 3 with DirectoryProperty

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

the class DirectoryNode method createDocument.

/**
     * create a new DocumentEntry
     *
     * @param document the new document
     *
     * @return the new DocumentEntry
     *
     * @exception IOException
     */
DocumentEntry createDocument(final NPOIFSDocument document) throws IOException {
    DocumentProperty property = document.getDocumentProperty();
    DocumentNode rval = new DocumentNode(property, this);
    ((DirectoryProperty) getProperty()).addChild(property);
    _nfilesystem.addDocument(document);
    _entries.add(rval);
    _byname.put(property.getName(), rval);
    return rval;
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 4 with DirectoryProperty

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

the class DirectoryNode method createDocument.

/**
     * create a new DocumentEntry
     *
     * @param document the new document
     *
     * @return the new DocumentEntry
     *
     * @exception IOException
     */
DocumentEntry createDocument(final OPOIFSDocument document) throws IOException {
    DocumentProperty property = document.getDocumentProperty();
    DocumentNode rval = new DocumentNode(property, this);
    ((DirectoryProperty) getProperty()).addChild(property);
    _ofilesystem.addDocument(document);
    _entries.add(rval);
    _byname.put(property.getName(), rval);
    return rval;
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 5 with DirectoryProperty

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

the class OPOIFSFileSystem method processProperties.

private void processProperties(final BlockList small_blocks, final BlockList big_blocks, final Iterator<Property> properties, final DirectoryNode dir, final int headerPropertiesStartAt) throws IOException {
    while (properties.hasNext()) {
        Property property = properties.next();
        String name = property.getName();
        DirectoryNode parent = (dir == null) ? ((DirectoryNode) getRoot()) : dir;
        if (property.isDirectory()) {
            DirectoryNode new_dir = (DirectoryNode) parent.createDirectory(name);
            new_dir.setStorageClsid(property.getStorageClsid());
            processProperties(small_blocks, big_blocks, ((DirectoryProperty) property).getChildren(), new_dir, headerPropertiesStartAt);
        } else {
            int startBlock = property.getStartBlock();
            int size = property.getSize();
            OPOIFSDocument document = null;
            if (property.shouldUseSmallBlocks()) {
                document = new OPOIFSDocument(name, small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt), size);
            } else {
                document = new OPOIFSDocument(name, big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt), size);
            }
            parent.createDocument(document);
        }
    }
}
Also used : Property(org.apache.poi.poifs.property.Property) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

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