01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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;
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: /**
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"><klute@rainer-klute.de></a>
38: * @version $Id: ReadTitle.java 489730 2006-12-22 19:18:16Z bayard $
39: * @since 2003-02-01
40: */
41: public class ReadTitle {
42: /**
43: * <p>Runs the example program.</p>
44: *
45: * @param args Command-line arguments. The first command-line argument must
46: * be the name of a POI filesystem to read.
47: * @throws IOException if any I/O exception occurs.
48: */
49: public static void main(final String[] args) throws IOException {
50: final String filename = args[0];
51: POIFSReader r = new POIFSReader();
52: r.registerListener(new MyPOIFSReaderListener(),
53: "\005SummaryInformation");
54: r.read(new FileInputStream(filename));
55: }
56:
57: static class MyPOIFSReaderListener implements POIFSReaderListener {
58: public void processPOIFSReaderEvent(final POIFSReaderEvent event) {
59: SummaryInformation si = null;
60: try {
61: si = (SummaryInformation) PropertySetFactory
62: .create(event.getStream());
63: } catch (Exception ex) {
64: throw new RuntimeException("Property set stream \""
65: + event.getPath() + event.getName() + "\": "
66: + ex);
67: }
68: final String title = si.getTitle();
69: if (title != null)
70: System.out.println("Title: \"" + title + "\"");
71: else
72: System.out.println("Document has no title.");
73: }
74: }
75:
76: }
|