リビジョン | 1823 (tree) |
---|---|
日時 | 2008-11-10 17:46:04 |
作者 | yasunori_suzuki |
(メッセージはありません)
@@ -3,6 +3,7 @@ | ||
3 | 3 | |
4 | 4 | import java.util.ArrayList; |
5 | 5 | import jp.sourceforge.concierge.framework.ConciergeViewPart; |
6 | +import jp.sourceforge.concierge.plugin.filters.OfficeFilter; | |
6 | 7 | import jp.sourceforge.concierge.plugin.filters.PdfFilter; |
7 | 8 | import jp.sourceforge.concierge.plugin.filters.PdfFilter2; |
8 | 9 |
@@ -139,6 +140,7 @@ | ||
139 | 140 | filepath.setText(path); |
140 | 141 | try |
141 | 142 | { |
143 | + /* | |
142 | 144 | ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(); |
143 | 145 | PdfFilter2 pdf = new PdfFilter2(path); |
144 | 146 | String keys[] = pdf.getDataNames(); |
@@ -146,10 +148,13 @@ | ||
146 | 148 | kvs.add(new KeyValue(keys[i], pdf.getData(keys[i]))); |
147 | 149 | viewer.setInput(kvs); |
148 | 150 | pdf.close(); |
151 | + */ | |
152 | + OfficeFilter of = new OfficeFilter(path); | |
153 | + of.getTitle(); | |
149 | 154 | } |
150 | 155 | catch(Exception ex) |
151 | 156 | { |
152 | - ; | |
157 | + System.err.println(ex.getMessage()); | |
153 | 158 | } |
154 | 159 | } |
155 | 160 | } |
@@ -0,0 +1,65 @@ | ||
1 | +package jp.sourceforge.concierge.plugin.filters; | |
2 | + | |
3 | +import java.io.FileInputStream; | |
4 | +import java.io.IOException; | |
5 | + | |
6 | +import org.apache.poi.POITextExtractor; | |
7 | +import org.apache.poi.hpsf.PropertySet; | |
8 | +import org.apache.poi.hpsf.DocumentSummaryInformation; | |
9 | +import org.apache.poi.hpsf.PropertySetFactory; | |
10 | +import org.apache.poi.hpsf.SummaryInformation; | |
11 | +import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor; | |
12 | +import org.apache.poi.poifs.eventfilesystem.POIFSReader; | |
13 | +import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent; | |
14 | +import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; | |
15 | +import org.apache.poi.poifs.filesystem.DirectoryEntry; | |
16 | +import org.apache.poi.poifs.filesystem.DocumentEntry; | |
17 | +import org.apache.poi.poifs.filesystem.DocumentInputStream; | |
18 | +import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |
19 | + | |
20 | +public class OfficeFilter | |
21 | +{ | |
22 | + POIFSFileSystem poifs = null; | |
23 | + POIFSReader reader = null; | |
24 | + String filename = null; | |
25 | + | |
26 | + private class MyPOIFSReaderListener implements POIFSReaderListener | |
27 | + { | |
28 | + public void processPOIFSReaderEvent(POIFSReaderEvent event) | |
29 | + { | |
30 | + SummaryInformation si = null; | |
31 | + try | |
32 | + { | |
33 | + si = (SummaryInformation) | |
34 | + PropertySetFactory.create(event.getStream()); | |
35 | + } | |
36 | + catch (Exception ex) | |
37 | + { | |
38 | + throw new RuntimeException | |
39 | + ("Property set stream \"" + | |
40 | + event.getPath() + event.getName() + "\": " + ex); | |
41 | + } | |
42 | + final String title = si.getTitle(); | |
43 | + if (title != null) | |
44 | + System.out.println("Title: \"" + title + "\""); | |
45 | + else | |
46 | + System.out.println("Document has no title."); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + public OfficeFilter(String file) throws IOException | |
51 | + { | |
52 | + poifs = new POIFSFileSystem(new FileInputStream(file)); | |
53 | + reader = new POIFSReader(); | |
54 | + filename = file; | |
55 | + } | |
56 | + | |
57 | + public void getTitle() throws Exception | |
58 | + { | |
59 | + reader.registerListener(new MyPOIFSReaderListener(), | |
60 | + SummaryInformation.DEFAULT_STREAM_NAME); | |
61 | + reader.read(new FileInputStream(filename)); | |
62 | + } | |
63 | + | |
64 | + | |
65 | +} |