1 2 17 18 package org.apache.poi.hpsf.examples; 19 20 import java.io.FileInputStream ; 21 import java.io.IOException ; 22 23 import org.apache.poi.hpsf.PropertySetFactory; 24 import org.apache.poi.hpsf.SummaryInformation; 25 import org.apache.poi.poifs.eventfilesystem.POIFSReader; 26 import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent; 27 import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; 28 29 41 public class ReadTitle 42 { 43 50 public static void main(final String [] args) throws IOException 51 { 52 final String filename = args[0]; 53 POIFSReader r = new POIFSReader(); 54 r.registerListener(new MyPOIFSReaderListener(), 55 "\005SummaryInformation"); 56 r.read(new FileInputStream (filename)); 57 } 58 59 60 static class MyPOIFSReaderListener implements POIFSReaderListener 61 { 62 public void processPOIFSReaderEvent(final POIFSReaderEvent event) 63 { 64 SummaryInformation si = null; 65 try 66 { 67 si = (SummaryInformation) 68 PropertySetFactory.create(event.getStream()); 69 } 70 catch (Exception ex) 71 { 72 throw new RuntimeException 73 ("Property set stream \"" + 74 event.getPath() + event.getName() + "\": " + ex); 75 } 76 final String title = si.getTitle(); 77 if (title != null) 78 System.out.println("Title: \"" + title + "\""); 79 else 80 System.out.println("Document has no title."); 81 } 82 } 83 84 } 85 | Popular Tags |