KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > examples > ReadTitle


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.hpsf.examples;
19
20 import java.io.FileInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
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 /**
30  * <p>Sample application showing how to read a OLE 2 document's
31  * title. Call it with the document's file name as command line
32  * parameter.</p>
33  *
34  * <p>Explanations can be found in the HPSF HOW-TO.</p>
35  *
36  * @author Rainer Klute <a
37  * HREF="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
38  * @version $Id: ReadTitle.java,v 1.5 2004/04/09 13:05:14 glens Exp $
39  * @since 2003-02-01
40  */

41 public class ReadTitle
42 {
43     /**
44      * <p>Runs the example program.</p>
45      *
46      * @param args Command-line arguments. The first command-line argument must
47      * be the name of a POI filesystem to read.
48      * @throws IOException if any I/O exception occurs.
49      */

50     public static void main(final String JavaDoc[] args) throws IOException JavaDoc
51     {
52         final String JavaDoc filename = args[0];
53         POIFSReader r = new POIFSReader();
54         r.registerListener(new MyPOIFSReaderListener(),
55                            "\005SummaryInformation");
56         r.read(new FileInputStream JavaDoc(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 JavaDoc ex)
71             {
72                 throw new RuntimeException JavaDoc
73                     ("Property set stream \"" +
74                      event.getPath() + event.getName() + "\": " + ex);
75             }
76             final String JavaDoc 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