2006-10-12 19:28:53 +02:00
|
|
|
//pptParser.java
|
|
|
|
//------------------------
|
|
|
|
//part of YaCy
|
2008-07-20 19:14:51 +02:00
|
|
|
//(C) by Michael Peter Christen; mc@yacy.net
|
2006-10-12 19:28:53 +02:00
|
|
|
//first published on http://www.anomic.de
|
|
|
|
//Frankfurt, Germany, 2005
|
2009-06-27 11:33:09 +02:00
|
|
|
//
|
2006-10-12 19:28:53 +02:00
|
|
|
//this file is contributed by Tim Riemann
|
2009-06-27 11:33:09 +02:00
|
|
|
//
|
2009-06-27 11:56:01 +02:00
|
|
|
// $LastChangedDate$
|
|
|
|
// $LastChangedRevision$
|
|
|
|
// $LastChangedBy$
|
2009-06-27 11:33:09 +02:00
|
|
|
//
|
2006-10-12 19:28:53 +02:00
|
|
|
//This program is free software; you can redistribute it and/or modify
|
|
|
|
//it under the terms of the GNU General Public License as published by
|
|
|
|
//the Free Software Foundation; either version 2 of the License, or
|
|
|
|
//(at your option) any later version.
|
2009-06-27 11:33:09 +02:00
|
|
|
//
|
2006-10-12 19:28:53 +02:00
|
|
|
//This program is distributed in the hope that it will be useful,
|
|
|
|
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
//GNU General Public License for more details.
|
2009-06-27 11:33:09 +02:00
|
|
|
//
|
2006-10-12 19:28:53 +02:00
|
|
|
//You should have received a copy of the GNU General Public License
|
|
|
|
//along with this program; if not, write to the Free Software
|
|
|
|
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2009-10-18 02:53:43 +02:00
|
|
|
package net.yacy.document.parser;
|
2006-10-12 19:28:53 +02:00
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.InputStream;
|
2009-07-14 13:01:05 +02:00
|
|
|
|
2010-05-25 14:54:57 +02:00
|
|
|
import net.yacy.cora.document.MultiProtocolURI;
|
2009-10-18 02:53:43 +02:00
|
|
|
import net.yacy.document.AbstractParser;
|
|
|
|
import net.yacy.document.Document;
|
2010-06-29 21:20:45 +02:00
|
|
|
import net.yacy.document.Parser;
|
2009-11-05 21:28:37 +01:00
|
|
|
import net.yacy.kelondro.logging.Log;
|
2009-10-11 02:12:19 +02:00
|
|
|
|
2006-10-12 19:28:53 +02:00
|
|
|
import org.apache.poi.hslf.extractor.PowerPointExtractor;
|
|
|
|
|
2010-06-29 21:20:45 +02:00
|
|
|
public class pptParser extends AbstractParser implements Parser {
|
2006-10-12 19:28:53 +02:00
|
|
|
|
2010-06-29 21:20:45 +02:00
|
|
|
public pptParser(){
|
|
|
|
super("Microsoft Powerpoint Parser");
|
2009-07-14 13:01:05 +02:00
|
|
|
SUPPORTED_EXTENSIONS.add("ppt");
|
2010-06-29 21:20:45 +02:00
|
|
|
SUPPORTED_EXTENSIONS.add("pps");
|
2009-07-14 13:01:05 +02:00
|
|
|
SUPPORTED_MIME_TYPES.add("application/mspowerpoint");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/powerpoint");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/vnd.ms-powerpoint");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/ms-powerpoint");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/mspowerpnt");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/vnd-mspowerpoint");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/x-powerpoint");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/x-m");
|
2006-10-12 19:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parses the source documents and returns a plasmaParserDocument containing
|
|
|
|
* all extracted information about the parsed document
|
|
|
|
*/
|
2010-06-29 21:20:45 +02:00
|
|
|
public Document[] parse(final MultiProtocolURI location, final String mimeType,
|
|
|
|
final String charset, final InputStream source) throws Parser.Failure,
|
2006-10-12 19:28:53 +02:00
|
|
|
InterruptedException {
|
|
|
|
try {
|
|
|
|
/*
|
|
|
|
* create new PowerPointExtractor and extract text and notes
|
|
|
|
* of the document
|
|
|
|
*/
|
2008-08-02 14:12:04 +02:00
|
|
|
final PowerPointExtractor pptExtractor = new PowerPointExtractor(new BufferedInputStream(source));
|
2009-02-05 16:15:13 +01:00
|
|
|
final String contents = pptExtractor.getText(true, true).trim();
|
|
|
|
String title = contents.replaceAll("\r"," ").replaceAll("\n"," ").replaceAll("\t"," ").trim();
|
|
|
|
if (title.length() > 80) title = title.substring(0, 80);
|
|
|
|
int l = title.length();
|
|
|
|
while (true) {
|
|
|
|
title = title.replaceAll(" ", " ");
|
|
|
|
if (title.length() == l) break;
|
|
|
|
l = title.length();
|
|
|
|
}
|
2009-07-08 23:48:08 +02:00
|
|
|
|
2006-10-12 19:28:53 +02:00
|
|
|
/*
|
|
|
|
* create the plasmaParserDocument for the database
|
|
|
|
* and set shortText and bodyText properly
|
|
|
|
*/
|
2010-06-29 21:20:45 +02:00
|
|
|
final Document[] docs = new Document[]{new Document(
|
2006-10-12 19:28:53 +02:00
|
|
|
location,
|
|
|
|
mimeType,
|
|
|
|
"UTF-8",
|
|
|
|
null,
|
2008-09-20 00:19:11 +02:00
|
|
|
null,
|
2009-02-05 16:15:13 +01:00
|
|
|
title,
|
2007-03-17 02:18:34 +01:00
|
|
|
"", // TODO: AUTHOR
|
2010-05-11 13:14:05 +02:00
|
|
|
pptExtractor.getDocSummaryInformation().getCompany(),
|
2006-10-12 19:28:53 +02:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
contents.getBytes("UTF-8"),
|
|
|
|
null,
|
2010-03-04 00:32:56 +01:00
|
|
|
null,
|
2010-08-25 20:24:54 +02:00
|
|
|
null,
|
2010-06-29 21:20:45 +02:00
|
|
|
false)};
|
|
|
|
return docs;
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final Exception e) {
|
2006-10-12 19:28:53 +02:00
|
|
|
if (e instanceof InterruptedException) throw (InterruptedException) e;
|
|
|
|
|
|
|
|
/*
|
2010-06-29 21:20:45 +02:00
|
|
|
* an unexpected error occurred, log it and throw a Parser.Failure
|
2009-10-21 17:12:34 +02:00
|
|
|
*/
|
2009-11-05 21:28:37 +01:00
|
|
|
Log.logException(e);
|
2008-08-02 14:12:04 +02:00
|
|
|
final String errorMsg = "Unable to parse the ppt document '" + location + "':" + e.getMessage();
|
2010-06-29 21:20:45 +02:00
|
|
|
this.log.logSevere(errorMsg);
|
|
|
|
throw new Parser.Failure(errorMsg, location);
|
2006-10-12 19:28:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|