On Tue, 4 Nov 2003, Nick Burch wrote:
> Since I'm also getting information from the spreadsheet itself via the 
> hssf.usermodel stuff, which accepts a POIFSFileSystem object, I thought 
> I'd do something similar (rather than the eventfilesystem route described 
> in docs/POI/hpsf/how-to.html)

I've figured this out for myself. In case anyone else is interested, the 
trick was to create a DocumentInputStream from the DocumentNode I've 
found, then use this to create the PropertySet object
 
I've attached a patch for org/apache/poi/hpsf/PropertySetFactory which 
allows you to call PropertySetFactory.create on a POIFSFilesystem, as well 
as on an InputStream as you currently can

Nick
--- PropertySetFactory.java.sav 2003-02-01 13:28:28.000000000 +0000
+++ PropertySetFactory.java     2003-11-12 13:43:39.000000000 +0000
@@ -54,7 +54,11 @@
  */
 package org.apache.poi.hpsf;
 
+import org.apache.poi.poifs.filesystem.*;
+import org.apache.poi.poifs.property.*;
+
 import java.io.*;
+import java.util.Iterator;
 
 /**
  * <p>Factory class to create instances of [EMAIL PROTECTED] SummaryInformation},
@@ -98,4 +102,81 @@
             return ps;
     }
 
+    /**
+     * <p>Creates the most specific [EMAIL PROTECTED] PropertySet} from an [EMAIL 
PROTECTED]
+     * POIFSFileSystem}. This is preferrably a [EMAIL PROTECTED]
+     * DocumentSummaryInformation} or a [EMAIL PROTECTED] SummaryInformation}. If
+     * the specified [EMAIL PROTECTED] InputStream} does not contain a property
+     * set stream, an exception is thrown.</p>
+     *
+     * @param fs the POI filesystem that contains the PropertySet stream.
+     * @return The created [EMAIL PROTECTED] PropertySet}.
+     * @throws IOException if the stream cannot be read
+     * @throws NoPropertySetStreamException if the stream does not
+     * contain a property set.
+     * @throws UnexpectedPropertySetTypeException if the property
+     * set's type is unexpected.
+     */
+    public static PropertySet create(final POIFSFileSystem fs)
+       throws NoPropertySetStreamException,
+              UnexpectedPropertySetTypeException, IOException
+    {
+               // Fetch the DocumentNode of the PropertySet
+               DocumentNode setNode = getInformationNode(fs.getRoot());
+
+               if(setNode == null) {
+                       throw new NoPropertySetStreamException("No property set found 
in the Root of that File System");
+               }
+
+               // Look through for the POIFSDocument
+               Iterator infoSections = setNode.getViewableIterator();
+               while(infoSections.hasNext()) {
+                       Object o = infoSections.next();
+                       if(o instanceof POIFSDocument) {
+                               POIFSDocument pd = (POIFSDocument)o;
+                               
+                               // Now make the PropertySet
+                               DocumentInputStream docin = new 
DocumentInputStream(pd);
+
+                               try {
+                                       return create(docin);
+                               } catch (MarkUnsupportedException mse) {
+                                       // The DocumentInputStream supports this
+                               }
+                       }
+               }
+
+               throw new NoPropertySetStreamException("No property set found in the 
Root of that File System");
+    }
+
+    /**
+     * <p>Find the first [EMAIL PROTECTED] DocumentNode} in the supplied
+        * [EMAIL PROTECTED] DirectoryEntry} that corresponds to a HPSF
+        * DocumentNode, and returns that.</p>
+     *
+     * @param dir the POI DirectoryNode that contains the PropertySet
+     * @return The created [EMAIL PROTECTED] DocumentNode}.
+     */
+       private static DocumentNode getInformationNode(DirectoryEntry dir) {
+               Iterator entries = dir.getEntries();
+
+               while(entries.hasNext()) {
+                       Object o = entries.next();
+                       if(o instanceof DocumentNode) {
+                               DocumentNode doc = (DocumentNode)o;
+                               String docName = doc.getName();
+
+                               if(docName.equals("\005SummaryInformation")) {
+                                       // Bingo, got a SummaryInformation
+                                       return doc;
+                               }
+                               if(docName.equals("\005DocumentSummaryInformation")) {
+                                       // Bingo, got a DocumentSummaryInformation
+                                       return doc;
+                               }
+                       }
+               }
+
+               return null;
+       }
 }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to