KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bluecubs > xinco > index > filetypes > XincoIndexMicrosoftPowerpoint


1 /**
2 *Copyright 2005 blueCubs.com
3 *
4 *Licensed under the Apache License, Version 2.0 (the "License");
5 *you may not use this file except in compliance with the License.
6 *You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *Unless required by applicable law or agreed to in writing, software
11 *distributed under the License is distributed on an "AS IS" BASIS,
12 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *See the License for the specific language governing permissions and
14 *limitations under the License.
15 *
16 *************************************************************
17 * This project supports the blueCubs vision of giving back
18 * to the community in exchange for free software!
19 * More information on: http://www.bluecubs.org
20 *************************************************************
21 *
22 * Name: XincoIndexMicrosoftPowerpoint
23 *
24 * Description: indexing Microsoft Powerpoint files
25 *
26 * Original Author: Alexander Manes
27 * Date: 2005/02/06
28 *
29 * Modifications:
30 *
31 * Who? When? What?
32 * - - -
33 *
34 *************************************************************
35 */

36
37 package com.bluecubs.xinco.index.filetypes;
38
39 import java.io.FileInputStream JavaDoc;
40 import java.io.InputStreamReader JavaDoc;
41 import java.io.Reader JavaDoc;
42 import java.io.File JavaDoc;
43 import java.io.BufferedReader JavaDoc;
44
45 import org.apache.poi.hpsf.PropertySet;
46 import org.apache.poi.poifs.eventfilesystem.POIFSReader;
47 import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
48 import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
49 import org.apache.poi.poifs.filesystem.DocumentInputStream;
50
51 public class XincoIndexMicrosoftPowerpoint implements XincoIndexFileType {
52
53     public XincoIndexMicrosoftPowerpoint() {
54         super();
55     }
56
57     public Reader JavaDoc getFileContentReader(File JavaDoc f) {
58         Reader JavaDoc reader = null;
59         return reader;
60     }
61
62     public String JavaDoc getFileContentString(File JavaDoc f) {
63         String JavaDoc text = null;
64         try {
65             POIFSReader r = new POIFSReader();
66             XincoIndexMicrosoftPowerpointPOIFSReaderListener ximpprl = new XincoIndexMicrosoftPowerpointPOIFSReaderListener();
67             r.registerListener(ximpprl);
68             r.read(new FileInputStream JavaDoc(f));
69             text = ximpprl.getEventText();
70         } catch (Exception JavaDoc e) {
71             text = null;
72         }
73         return text;
74     }
75
76     static class XincoIndexMicrosoftPowerpointPOIFSReaderListener implements POIFSReaderListener {
77
78         String JavaDoc EventText = "";
79         
80         public String JavaDoc getEventText() {
81             return EventText;
82         }
83         
84         public void processPOIFSReaderEvent(POIFSReaderEvent event) {
85             PropertySet ps = null;
86             try {
87                 DocumentInputStream dis = null;
88                 dis = event.getStream();
89                 Reader JavaDoc EventReader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(dis));
90                 int l = 0;
91                 char ca[] = new char[1024];
92                 while (true) {
93                     l = EventReader.read(ca, 0, 1024);
94                     if (!(l>0)) {
95                         break;
96                     }
97                     EventText = EventText + String.copyValueOf(ca, 0 , l);
98                 }
99             } catch (Exception JavaDoc ex) {
100                 EventText = "";
101             }
102         }
103     }
104 }
105
Popular Tags