2009-06-21 22:08:52 +02:00
|
|
|
//swfParser.java
|
2006-11-01 01:52:42 +01:00
|
|
|
//------------------------
|
|
|
|
//part of YaCy
|
2008-07-20 19:14:51 +02:00
|
|
|
//(C) by Michael Peter Christen; mc@yacy.net
|
2006-11-01 01:52:42 +01:00
|
|
|
//first published on http://www.anomic.de
|
|
|
|
//Frankfurt, Germany, 2005
|
|
|
|
//
|
|
|
|
//this file is contributed by Marc Nause
|
2009-06-21 22:08:52 +02:00
|
|
|
//
|
|
|
|
// $LastChangedDate$
|
|
|
|
// $LastChangedRevision$
|
|
|
|
// $LastChangedBy$
|
2006-11-01 01:52:42 +01: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.
|
|
|
|
//
|
|
|
|
//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.
|
|
|
|
//
|
|
|
|
//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-11-01 01:52:42 +01:00
|
|
|
|
2009-09-14 23:17:42 +02:00
|
|
|
import java.io.IOException;
|
2006-11-01 01:52:42 +01:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.HashMap;
|
2010-12-27 16:37:11 +01:00
|
|
|
import java.util.Map;
|
2011-04-21 15:58:49 +02:00
|
|
|
import java.util.Properties;
|
2009-07-14 13:01:05 +02:00
|
|
|
|
2010-05-25 14:54:57 +02:00
|
|
|
import net.yacy.cora.document.MultiProtocolURI;
|
2011-03-11 00:25:07 +01:00
|
|
|
import net.yacy.cora.document.UTF8;
|
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
|
|
|
|
2008-01-22 12:51:43 +01:00
|
|
|
import pt.tumba.parser.swf.SWF2HTML;
|
2006-11-01 01:52:42 +01:00
|
|
|
|
2010-06-29 21:20:45 +02:00
|
|
|
public class swfParser extends AbstractParser implements Parser {
|
2006-11-01 01:52:42 +01:00
|
|
|
|
2010-06-29 21:20:45 +02:00
|
|
|
public swfParser() {
|
|
|
|
super("Adobe Flash Parser");
|
2009-07-14 13:01:05 +02:00
|
|
|
SUPPORTED_EXTENSIONS.add("swf");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/x-shockwave-flash");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/x-shockwave-flash2-preview");
|
|
|
|
SUPPORTED_MIME_TYPES.add("application/futuresplash");
|
|
|
|
SUPPORTED_MIME_TYPES.add("image/vnd.rn-realflash");
|
2006-11-01 01:52:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parses the source documents and returns a plasmaParserDocument containing
|
|
|
|
* all extracted information about the parsed document
|
|
|
|
*/
|
2010-12-27 21:13:31 +01:00
|
|
|
public Document[] parse(final MultiProtocolURI location, final String mimeType,
|
|
|
|
final String charset, final InputStream source)
|
|
|
|
throws Parser.Failure, InterruptedException
|
|
|
|
{
|
2006-11-01 01:52:42 +01:00
|
|
|
|
|
|
|
try {
|
2008-08-02 14:12:04 +02:00
|
|
|
final SWF2HTML swf2html = new SWF2HTML();
|
2009-06-11 11:54:48 +02:00
|
|
|
String contents = "";
|
|
|
|
try {
|
|
|
|
contents = swf2html.convertSWFToHTML(source);
|
2009-07-25 23:38:57 +02:00
|
|
|
} catch (NegativeArraySizeException e) {
|
2010-06-29 21:20:45 +02:00
|
|
|
throw new Parser.Failure(e.getMessage(), location);
|
2009-09-14 23:17:42 +02:00
|
|
|
} catch (IOException e) {
|
2010-06-29 21:20:45 +02:00
|
|
|
throw new Parser.Failure(e.getMessage(), location);
|
2009-06-11 11:54:48 +02:00
|
|
|
} catch (Exception e) {
|
2009-11-05 21:28:37 +01:00
|
|
|
Log.logException(e);
|
2010-06-29 21:20:45 +02:00
|
|
|
throw new Parser.Failure(e.getMessage(), location);
|
2009-06-11 11:54:48 +02:00
|
|
|
}
|
2006-11-01 01:52:42 +01:00
|
|
|
String url = null;
|
|
|
|
String urlnr = null;
|
2008-08-02 14:12:04 +02:00
|
|
|
final String linebreak = System.getProperty("line.separator");
|
|
|
|
final String[] sections = null;
|
|
|
|
final String abstrct = null;
|
2006-12-02 20:34:59 +01:00
|
|
|
//TreeSet images = null;
|
2011-04-21 15:58:49 +02:00
|
|
|
final Map<MultiProtocolURI, Properties> anchors = new HashMap<MultiProtocolURI, Properties>();
|
2006-11-01 01:52:42 +01:00
|
|
|
int urls = 0;
|
|
|
|
int urlStart = -1;
|
|
|
|
int urlEnd = 0;
|
|
|
|
int p0 = 0;
|
|
|
|
|
|
|
|
//getting rid of HTML-Tags
|
|
|
|
p0 = contents.indexOf("<html><body>");
|
|
|
|
contents = contents.substring(p0+12);
|
|
|
|
p0 = contents.indexOf("</body></html>");
|
|
|
|
contents = contents.substring(0,p0);
|
|
|
|
|
|
|
|
//extracting urls
|
|
|
|
while ((urlStart = contents.indexOf("http://",urlEnd)) >= 0){
|
|
|
|
urlEnd = contents.indexOf(linebreak,urlStart);
|
|
|
|
url = contents.substring(urlStart,urlEnd);
|
2010-10-09 10:55:57 +02:00
|
|
|
urlnr = Integer.toString(++urls).toString();
|
2011-04-21 15:58:49 +02:00
|
|
|
Properties p = new Properties();
|
|
|
|
p.put("name", urlnr);
|
|
|
|
anchors.put(new MultiProtocolURI(url), p);
|
2006-11-01 10:22:15 +01:00
|
|
|
contents = contents.substring(0,urlStart)+contents.substring(urlEnd);
|
2006-11-01 01:52:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// As the result of parsing this function must return a plasmaParserDocument object
|
2010-06-29 21:20:45 +02:00
|
|
|
return new Document[]{new Document(
|
2006-11-01 01:52:42 +01:00
|
|
|
location, // url of the source document
|
|
|
|
mimeType, // the documents mime type
|
|
|
|
"UTF-8", // charset of the document text
|
2011-04-21 15:58:49 +02:00
|
|
|
this,
|
2008-09-20 00:19:11 +02:00
|
|
|
null,
|
2006-11-01 01:52:42 +01:00
|
|
|
null, //keywords
|
|
|
|
((contents.length() > 80)? contents.substring(0, 80):contents.trim()).
|
|
|
|
replaceAll("\r\n"," ").
|
|
|
|
replaceAll("\n"," ").
|
|
|
|
replaceAll("\r"," ").
|
2007-03-18 13:33:19 +01:00
|
|
|
replaceAll("\t"," "), // title
|
2007-03-17 02:18:34 +01:00
|
|
|
"", // TODO: AUTHOR
|
2010-05-11 13:14:05 +02:00
|
|
|
"",
|
2006-11-01 01:52:42 +01:00
|
|
|
sections, // an array of section headlines
|
|
|
|
abstrct, // an abstract
|
2011-03-30 02:49:47 +02:00
|
|
|
0.0f, 0.0f,
|
2011-03-11 00:25:07 +01:00
|
|
|
UTF8.getBytes(contents), // the parsed document text
|
2006-11-01 01:52:42 +01:00
|
|
|
anchors, // a map of extracted anchors
|
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)}; // a treeset of image URLs
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final Exception e) {
|
2006-11-01 01:52:42 +01:00
|
|
|
if (e instanceof InterruptedException) throw (InterruptedException) e;
|
|
|
|
|
2010-06-29 21:20:45 +02:00
|
|
|
// if an unexpected error occures just log the error and raise a new Parser.Failure
|
2008-08-02 14:12:04 +02:00
|
|
|
final String errorMsg = "Unable to parse the swf document '" + location + "':" + e.getMessage();
|
2010-06-29 21:20:45 +02:00
|
|
|
this.log.logSevere(errorMsg);
|
|
|
|
throw new Parser.Failure(errorMsg, location);
|
2006-11-01 01:52:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|