2005-10-18 09:45:27 +02:00
|
|
|
//ViewFile.java
|
|
|
|
//-----------------------
|
|
|
|
//part of YaCy
|
2008-07-20 19:14:51 +02:00
|
|
|
//(C) by Michael Peter Christen; mc@yacy.net
|
2005-10-18 09:45:27 +02:00
|
|
|
//first published on http://www.anomic.de
|
|
|
|
//Frankfurt, Germany, 2004
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2005-10-18 09:45:27 +02:00
|
|
|
//last major change: 12.07.2004
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2005-10-18 09:45:27 +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.
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2005-10-18 09:45:27 +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.
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2005-10-18 09:45:27 +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
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2005-10-18 09:45:27 +02:00
|
|
|
//you must compile this file with
|
|
|
|
//javac -classpath .:../Classes Status.java
|
|
|
|
//if the shell's current path is HTROOT
|
|
|
|
|
2009-11-19 11:17:26 +01:00
|
|
|
import java.io.ByteArrayInputStream;
|
2009-10-01 15:08:19 +02:00
|
|
|
import java.io.IOException;
|
2005-11-06 07:27:17 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2006-11-23 16:47:19 +01:00
|
|
|
import java.net.MalformedURLException;
|
2005-11-06 07:27:17 +01:00
|
|
|
import java.net.URLDecoder;
|
2009-01-04 03:27:29 +01:00
|
|
|
import java.util.Enumeration;
|
2008-02-25 15:08:15 +01:00
|
|
|
import java.util.HashMap;
|
2006-12-07 03:40:57 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
2005-10-18 09:45:27 +02:00
|
|
|
|
2009-10-18 02:53:43 +02:00
|
|
|
import net.yacy.document.Condenser;
|
|
|
|
import net.yacy.document.Document;
|
|
|
|
import net.yacy.document.ParserException;
|
|
|
|
import net.yacy.document.parser.html.CharacterCoding;
|
|
|
|
import net.yacy.document.parser.html.ImageEntry;
|
2009-10-11 02:12:19 +02:00
|
|
|
import net.yacy.kelondro.data.meta.DigestURI;
|
|
|
|
import net.yacy.kelondro.data.meta.URIMetadataRow;
|
2009-11-05 21:28:37 +01:00
|
|
|
import net.yacy.kelondro.logging.Log;
|
2009-10-21 17:12:34 +02:00
|
|
|
import net.yacy.repository.LoaderDispatcher;
|
2009-10-10 03:14:19 +02:00
|
|
|
|
2009-07-15 23:07:46 +02:00
|
|
|
import de.anomic.crawler.retrieval.Response;
|
2009-07-19 22:37:44 +02:00
|
|
|
import de.anomic.http.client.Cache;
|
2009-10-11 23:29:18 +02:00
|
|
|
import de.anomic.http.server.RequestHeader;
|
|
|
|
import de.anomic.http.server.ResponseHeader;
|
2009-10-11 02:12:19 +02:00
|
|
|
import de.anomic.search.Segment;
|
|
|
|
import de.anomic.search.Segments;
|
2009-07-19 22:37:44 +02:00
|
|
|
import de.anomic.search.Switchboard;
|
2005-10-18 09:45:27 +02:00
|
|
|
import de.anomic.server.serverObjects;
|
|
|
|
import de.anomic.server.serverSwitch;
|
|
|
|
|
|
|
|
public class ViewFile {
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2005-10-18 09:45:27 +02:00
|
|
|
public static final int VIEW_MODE_NO_TEXT = 0;
|
|
|
|
public static final int VIEW_MODE_AS_PLAIN_TEXT = 1;
|
|
|
|
public static final int VIEW_MODE_AS_PARSED_TEXT = 2;
|
|
|
|
public static final int VIEW_MODE_AS_PARSED_SENTENCES = 3;
|
2010-03-07 00:41:51 +01:00
|
|
|
public static final int VIEW_MODE_AS_IFRAME_FROM_WEB = 4;
|
|
|
|
public static final int VIEW_MODE_AS_IFRAME_FROM_CACHE = 5;
|
|
|
|
public static final int VIEW_MODE_AS_LINKLIST = 6;
|
|
|
|
public static final int VIEW_MODE_AS_PARSED_WORDS = 7;
|
2007-01-06 13:21:13 +01:00
|
|
|
|
|
|
|
private static final String HIGHLIGHT_CSS = "searchHighlight";
|
|
|
|
private static final int MAX_HIGHLIGHTS = 6;
|
2005-10-18 09:45:27 +02:00
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
final serverObjects prop = new serverObjects();
|
2009-07-19 22:37:44 +02:00
|
|
|
final Switchboard sb = (Switchboard)env;
|
2008-10-18 21:39:46 +02:00
|
|
|
|
2010-03-05 16:41:15 +01:00
|
|
|
if (post == null) {
|
|
|
|
prop.put("display", 1);
|
|
|
|
prop.put("error_display", 0);
|
|
|
|
prop.putHTML("error_words", "");
|
|
|
|
prop.put("error_vMode-sentences", "1");
|
|
|
|
prop.put("error", "1");
|
|
|
|
prop.put("url", "");
|
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final int display = post.getInt("display", 1);
|
2008-10-18 21:39:46 +02:00
|
|
|
|
2009-10-09 16:44:20 +02:00
|
|
|
// get segment
|
|
|
|
Segment indexSegment = null;
|
2010-05-06 00:45:54 +02:00
|
|
|
boolean authorized = sb.verifyAuthentication(header, false);
|
|
|
|
if (post != null && post.containsKey("segment") && authorized) {
|
|
|
|
indexSegment = sb.indexSegments.segment(post.get("segment"));
|
2009-10-09 16:44:20 +02:00
|
|
|
} else {
|
|
|
|
indexSegment = sb.indexSegments.segment(Segments.Process.PUBLIC);
|
2010-05-06 00:45:54 +02:00
|
|
|
}
|
2009-10-09 16:44:20 +02:00
|
|
|
|
2008-10-18 21:39:46 +02:00
|
|
|
prop.put("display", display);
|
|
|
|
prop.put("error_display", display);
|
2005-11-14 13:05:57 +01:00
|
|
|
|
2010-03-05 16:41:15 +01:00
|
|
|
if (post.containsKey("words"))
|
2008-06-06 18:01:27 +02:00
|
|
|
prop.putHTML("error_words", post.get("words"));
|
2007-01-06 13:21:13 +01:00
|
|
|
else {
|
2008-10-21 13:27:50 +02:00
|
|
|
prop.putHTML("error_words", "");
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
|
|
|
|
2010-03-11 16:43:06 +01:00
|
|
|
final String viewMode = post.get("viewMode","parsed");
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error_vMode-" + viewMode, "1");
|
2007-01-06 13:21:13 +01:00
|
|
|
|
2009-10-11 02:12:19 +02:00
|
|
|
DigestURI url = null;
|
2006-11-23 16:47:19 +01:00
|
|
|
String descr = "";
|
2008-08-02 14:12:04 +02:00
|
|
|
final int wordCount = 0;
|
2006-11-28 16:00:15 +01:00
|
|
|
int size = 0;
|
|
|
|
boolean pre = false;
|
2006-11-23 16:47:19 +01:00
|
|
|
|
2009-10-09 16:44:20 +02:00
|
|
|
// get the url hash from which the content should be loaded
|
2010-04-08 02:11:32 +02:00
|
|
|
String urlHash = post.get("urlHash", "");
|
2010-03-05 16:41:15 +01:00
|
|
|
URIMetadataRow urlEntry = null;
|
|
|
|
// get the urlEntry that belongs to the url hash
|
2010-04-08 02:11:32 +02:00
|
|
|
if (urlHash.length() > 0 && (urlEntry = indexSegment.urlMetadata().load(urlHash.getBytes(), null, 0)) != null) {
|
2010-03-05 16:41:15 +01:00
|
|
|
// get the url that belongs to the entry
|
2009-10-11 02:12:19 +02:00
|
|
|
final URIMetadataRow.Components metadata = urlEntry.metadata();
|
2009-03-02 12:04:13 +01:00
|
|
|
if ((metadata == null) || (metadata.url() == null)) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "3");
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
2006-09-20 14:25:07 +02:00
|
|
|
return prop;
|
2006-10-19 00:25:07 +02:00
|
|
|
}
|
2009-03-02 12:04:13 +01:00
|
|
|
url = metadata.url();
|
|
|
|
descr = metadata.dc_title();
|
2009-05-15 01:11:10 +02:00
|
|
|
//urlEntry.wordCount();
|
2006-11-23 16:47:19 +01:00
|
|
|
size = urlEntry.size();
|
2009-04-03 15:23:45 +02:00
|
|
|
pre = urlEntry.flags().get(Condenser.flag_cat_indexof);
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
|
|
|
|
2010-03-05 16:41:15 +01:00
|
|
|
prop.put("error_inurldb", urlEntry == null ? 0 : 1);
|
|
|
|
|
2006-11-23 16:47:19 +01:00
|
|
|
// alternatively, get the url simply from a url String
|
|
|
|
// this can be used as a simple tool to test the text parser
|
2008-08-02 14:12:04 +02:00
|
|
|
final String urlString = post.get("url", "");
|
2006-11-23 16:47:19 +01:00
|
|
|
if (urlString.length() > 0) try {
|
2006-11-23 18:13:25 +01:00
|
|
|
// this call forces the peer to download web pages
|
|
|
|
// it is therefore protected by the admin password
|
|
|
|
|
|
|
|
if (!sb.verifyAuthentication(header, false)) {
|
|
|
|
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// define an url by post parameter
|
2009-10-11 02:12:19 +02:00
|
|
|
url = new DigestURI(urlString, null);
|
2010-04-08 02:11:32 +02:00
|
|
|
urlHash = new String(url.hash());
|
2006-11-28 16:00:15 +01:00
|
|
|
pre = post.get("pre", "false").equals("true");
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final MalformedURLException e) {}
|
2006-11-23 16:47:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (url == null) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "1");
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
2010-03-05 16:41:15 +01:00
|
|
|
prop.put("url", "");
|
2006-11-23 16:47:19 +01:00
|
|
|
return prop;
|
2010-03-05 16:41:15 +01:00
|
|
|
} else {
|
|
|
|
prop.put("url", url.toNormalform(false, true));
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// loading the resource content as byte array
|
2010-03-05 16:41:15 +01:00
|
|
|
prop.put("error_incache", Cache.has(url) ? 1 : 0);
|
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
ResponseHeader responseHeader = null;
|
2006-11-23 16:47:19 +01:00
|
|
|
String resMime = null;
|
2010-05-15 01:50:07 +02:00
|
|
|
byte[] resource = Cache.getContent(url);
|
2010-05-06 00:45:54 +02:00
|
|
|
|
|
|
|
if (resource == null && authorized) {
|
|
|
|
// load resource from net
|
|
|
|
Response response = null;
|
|
|
|
try {
|
2010-05-14 20:30:11 +02:00
|
|
|
response = sb.loader.load(url, true, false, Long.MAX_VALUE);
|
2010-05-06 00:45:54 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.logException(e);
|
|
|
|
}
|
2010-05-09 00:09:36 +02:00
|
|
|
if (response != null) {
|
|
|
|
resource = response.getContent();
|
|
|
|
responseHeader = response.getResponseHeader();
|
|
|
|
}
|
2010-05-06 00:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (responseHeader == null) responseHeader = Cache.getResponseHeader(url);
|
2008-04-05 15:17:16 +02:00
|
|
|
|
|
|
|
// if the resource body was not cached we try to load it from web
|
|
|
|
if (resource == null) {
|
2009-07-15 23:07:46 +02:00
|
|
|
Response entry = null;
|
2008-04-05 15:17:16 +02:00
|
|
|
try {
|
2010-05-14 20:30:11 +02:00
|
|
|
entry = sb.loader.load(url, true, false, Long.MAX_VALUE);
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final Exception e) {
|
2008-04-05 15:17:16 +02:00
|
|
|
prop.put("error", "4");
|
|
|
|
prop.putHTML("error_errorText", e.getMessage());
|
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry != null) {
|
2009-11-19 11:17:26 +01:00
|
|
|
resource = entry.getContent();
|
2008-04-05 15:17:16 +02:00
|
|
|
}
|
2006-11-23 16:47:19 +01:00
|
|
|
|
|
|
|
if (resource == null) {
|
2008-04-05 15:17:16 +02:00
|
|
|
prop.put("error", "4");
|
|
|
|
prop.put("error_errorText", "No resource available");
|
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to load resource metadata
|
2008-08-25 20:11:47 +02:00
|
|
|
if (responseHeader == null) {
|
2008-04-05 15:17:16 +02:00
|
|
|
|
|
|
|
// try to load the metadata from cache
|
|
|
|
try {
|
2009-07-23 23:31:51 +02:00
|
|
|
responseHeader = Cache.getResponseHeader(url);
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final Exception e) {
|
2008-04-05 15:17:16 +02:00
|
|
|
/* ignore this */
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the metadata was not cached try to load it from web
|
2008-08-25 20:11:47 +02:00
|
|
|
if (responseHeader == null) {
|
2008-08-02 14:12:04 +02:00
|
|
|
final String protocol = url.getProtocol();
|
2008-04-05 15:17:16 +02:00
|
|
|
if (!((protocol.equals("http") || protocol.equals("https")))) {
|
|
|
|
prop.put("error", "6");
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
}
|
2006-09-20 14:25:07 +02:00
|
|
|
|
2010-05-04 22:57:09 +02:00
|
|
|
try {
|
2010-05-14 20:30:11 +02:00
|
|
|
Response response = sb.loader.load(url, true, false, Long.MAX_VALUE);
|
2010-05-04 22:57:09 +02:00
|
|
|
responseHeader = response.getResponseHeader();
|
|
|
|
resource = response.getContent();
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.logException(e);
|
|
|
|
}
|
2008-04-05 15:17:16 +02:00
|
|
|
if (responseHeader == null) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "4");
|
2008-04-05 15:17:16 +02:00
|
|
|
prop.put("error_errorText", "Unable to load resource metadata.");
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
}
|
2008-04-05 15:17:16 +02:00
|
|
|
resMime = responseHeader.mime();
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
2008-04-05 15:17:16 +02:00
|
|
|
} else {
|
2008-08-25 20:11:47 +02:00
|
|
|
resMime = responseHeader.mime();
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
2008-02-26 22:17:41 +01:00
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
final String[] wordArray = wordArray(post.get("words", null));
|
2006-11-23 16:47:19 +01:00
|
|
|
|
|
|
|
if (viewMode.equals("plain")) {
|
|
|
|
|
|
|
|
// TODO: how to handle very large files here ?
|
|
|
|
String content;
|
|
|
|
try {
|
2009-11-19 11:17:26 +01:00
|
|
|
content = new String(resource, "UTF-8");
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final Exception e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "4");
|
|
|
|
prop.putHTML("error_errorText", e.getMessage());
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
} finally {
|
2009-11-19 11:17:26 +01:00
|
|
|
resource = null;
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
|
|
|
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "0");
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_AS_PLAIN_TEXT);
|
2008-02-26 22:17:41 +01:00
|
|
|
prop.put("viewMode_plainText", markup(wordArray, content).replaceAll("\n", "<br />").replaceAll("\t", " "));
|
2007-01-06 13:21:13 +01:00
|
|
|
|
2010-03-07 00:41:51 +01:00
|
|
|
} else if (viewMode.equals("iframeWeb")) {
|
|
|
|
prop.put("viewMode", VIEW_MODE_AS_IFRAME_FROM_WEB);
|
|
|
|
prop.put("viewMode_url", url.toNormalform(false, true));
|
|
|
|
|
|
|
|
} else if (viewMode.equals("iframeCache")) {
|
|
|
|
prop.put("viewMode", VIEW_MODE_AS_IFRAME_FROM_CACHE);
|
2007-07-19 17:32:10 +02:00
|
|
|
prop.put("viewMode_url", url.toNormalform(false, true));
|
2007-01-06 13:21:13 +01:00
|
|
|
|
2009-01-04 03:27:29 +01:00
|
|
|
} else if (viewMode.equals("parsed") || viewMode.equals("sentences") || viewMode.equals("words") || viewMode.equals("links")) {
|
2006-11-23 16:47:19 +01:00
|
|
|
// parsing the resource content
|
2009-07-08 23:48:08 +02:00
|
|
|
Document document = null;
|
2006-11-23 16:47:19 +01:00
|
|
|
try {
|
2010-05-04 22:57:09 +02:00
|
|
|
document = LoaderDispatcher.parseDocument(url, resource.length, new ByteArrayInputStream(resource), responseHeader);
|
2006-11-23 16:47:19 +01:00
|
|
|
if (document == null) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "5");
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("error_errorText", "Unknown error");
|
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
2006-09-20 14:25:07 +02:00
|
|
|
}
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final ParserException e) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "5");
|
|
|
|
prop.putHTML("error_errorText", e.getMessage());
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
|
|
|
} finally {
|
2009-11-19 11:17:26 +01:00
|
|
|
resource = null;
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
|
|
|
|
2008-01-22 12:51:43 +01:00
|
|
|
resMime = document.dc_format();
|
2008-02-26 22:17:41 +01:00
|
|
|
|
2006-11-23 16:47:19 +01:00
|
|
|
if (viewMode.equals("parsed")) {
|
2008-08-02 14:12:04 +02:00
|
|
|
final String content = new String(document.getTextBytes());
|
2007-02-03 21:22:39 +01:00
|
|
|
// content = wikiCode.replaceHTML(content); // added by Marc Nause
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_AS_PARSED_TEXT);
|
2010-03-11 01:11:14 +01:00
|
|
|
prop.put("viewMode_title", document.dc_title());
|
|
|
|
prop.put("viewMode_creator", document.dc_creator());
|
|
|
|
prop.put("viewMode_subject", document.dc_subject(','));
|
|
|
|
prop.put("viewMode_description", document.dc_description());
|
|
|
|
prop.put("viewMode_publisher", document.dc_publisher());
|
|
|
|
prop.put("viewMode_format", document.dc_format());
|
|
|
|
prop.put("viewMode_identifier", document.dc_identifier());
|
|
|
|
prop.put("viewMode_source", document.dc_source().toString());
|
2008-02-26 22:17:41 +01:00
|
|
|
prop.put("viewMode_parsedText", markup(wordArray, content).replaceAll("\n", "<br />").replaceAll("\t", " "));
|
2007-01-06 13:21:13 +01:00
|
|
|
|
2006-12-07 03:40:57 +01:00
|
|
|
} else if (viewMode.equals("sentences")) {
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode", VIEW_MODE_AS_PARSED_SENTENCES);
|
2008-12-04 13:54:16 +01:00
|
|
|
final Iterator<StringBuilder> sentences = document.getSentences(pre);
|
2006-11-23 16:47:19 +01:00
|
|
|
|
|
|
|
boolean dark = true;
|
|
|
|
int i = 0;
|
2007-01-06 13:21:13 +01:00
|
|
|
String sentence;
|
2006-12-07 03:40:57 +01:00
|
|
|
if (sentences != null) {
|
|
|
|
|
|
|
|
// Search word highlighting
|
2006-12-09 03:13:43 +01:00
|
|
|
while (sentences.hasNext()) {
|
2008-01-22 12:51:43 +01:00
|
|
|
sentence = sentences.next().toString();
|
2007-01-06 13:21:13 +01:00
|
|
|
if (sentence.trim().length() > 0) {
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("viewMode_sentences_" + i + "_nr", i + 1);
|
|
|
|
prop.put("viewMode_sentences_" + i + "_text", markup(wordArray, sentence));
|
|
|
|
prop.put("viewMode_sentences_" + i + "_dark", dark ? "1" : "0");
|
2007-01-06 13:21:13 +01:00
|
|
|
dark = !dark;
|
|
|
|
i++;
|
|
|
|
}
|
2006-09-20 14:25:07 +02:00
|
|
|
}
|
2006-12-07 03:40:57 +01:00
|
|
|
}
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("viewMode_sentences", i);
|
2006-09-20 14:25:07 +02:00
|
|
|
|
2009-01-04 03:27:29 +01:00
|
|
|
} else if (viewMode.equals("words")) {
|
|
|
|
prop.put("viewMode", VIEW_MODE_AS_PARSED_WORDS);
|
|
|
|
final Iterator<StringBuilder> sentences = document.getSentences(pre);
|
|
|
|
|
|
|
|
boolean dark = true;
|
|
|
|
int i = 0;
|
|
|
|
String sentence, token;
|
|
|
|
if (sentences != null) {
|
|
|
|
|
|
|
|
// Search word highlighting
|
|
|
|
while (sentences.hasNext()) {
|
|
|
|
sentence = sentences.next().toString();
|
2009-04-03 15:23:45 +02:00
|
|
|
Enumeration<StringBuilder> tokens = Condenser.wordTokenizer(sentence, "UTF-8");
|
2009-01-04 03:27:29 +01:00
|
|
|
while (tokens.hasMoreElements()) {
|
|
|
|
token = tokens.nextElement().toString();
|
|
|
|
if (token.length() > 0) {
|
|
|
|
prop.put("viewMode_words_" + i + "_nr", i + 1);
|
|
|
|
prop.put("viewMode_words_" + i + "_word", token);
|
|
|
|
prop.put("viewMode_words_" + i + "_dark", dark ? "1" : "0");
|
|
|
|
dark = !dark;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop.put("viewMode_words", i);
|
|
|
|
|
2006-12-07 03:40:57 +01:00
|
|
|
} else if (viewMode.equals("links")) {
|
|
|
|
prop.put("viewMode", VIEW_MODE_AS_LINKLIST);
|
|
|
|
boolean dark = true;
|
|
|
|
int i = 0;
|
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getVideolinks(), "video", (i % 2 == 0));
|
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getAudiolinks(), "audio", (i % 2 == 0));
|
|
|
|
dark = (i % 2 == 0);
|
|
|
|
|
2009-07-08 23:48:08 +02:00
|
|
|
final HashMap<String, ImageEntry> ts = document.getImages();
|
|
|
|
final Iterator<ImageEntry> tsi = ts.values().iterator();
|
|
|
|
ImageEntry entry;
|
2006-12-07 03:40:57 +01:00
|
|
|
while (tsi.hasNext()) {
|
2008-01-22 12:51:43 +01:00
|
|
|
entry = tsi.next();
|
2006-12-07 03:40:57 +01:00
|
|
|
prop.put("viewMode_links_" + i + "_nr", i);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("viewMode_links_" + i + "_dark", dark ? "1" : "0");
|
2006-12-07 03:40:57 +01:00
|
|
|
prop.put("viewMode_links_" + i + "_type", "image");
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("viewMode_links_" + i + "_text", markup(wordArray, entry.alt()));
|
2007-10-19 06:13:46 +02:00
|
|
|
prop.put("viewMode_links_" + i + "_url", entry.url().toNormalform(false, true));
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("viewMode_links_" + i + "_link", markup(wordArray, entry.url().toNormalform(false, true)));
|
2007-02-03 21:22:39 +01:00
|
|
|
if (entry.width() > 0 && entry.height() > 0)
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("viewMode_links_" + i + "_attr", entry.width() + "x" + entry.height() + " Pixel");
|
2007-02-03 21:22:39 +01:00
|
|
|
else
|
|
|
|
prop.put("viewMode_links_" + i + "_attr", "unknown");
|
2006-12-07 03:40:57 +01:00
|
|
|
dark = !dark;
|
|
|
|
i++;
|
|
|
|
}
|
2007-06-11 17:15:10 +02:00
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getApplinks(), "app", (i % 2 == 0));
|
2010-03-11 18:52:07 +01:00
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getHyperlinks(), "link", (i % 2 == 0));
|
2006-12-07 03:40:57 +01:00
|
|
|
prop.put("viewMode_links", i);
|
|
|
|
|
2006-09-20 14:25:07 +02:00
|
|
|
}
|
2006-11-23 16:47:19 +01:00
|
|
|
if (document != null) document.close();
|
|
|
|
}
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error", "0");
|
2007-07-19 17:32:10 +02:00
|
|
|
prop.put("error_url", url.toNormalform(false, true));
|
2006-11-23 16:47:19 +01:00
|
|
|
prop.put("error_hash", urlHash);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("error_wordCount", wordCount);
|
|
|
|
prop.putHTML("error_desc", descr);
|
|
|
|
prop.putNum("error_size", size);
|
|
|
|
prop.put("error_mimeTypeAvailable", (resMime == null) ? "0" : "1");
|
2007-01-06 13:21:13 +01:00
|
|
|
prop.put("error_mimeTypeAvailable_mimeType", resMime);
|
2006-11-23 16:47:19 +01:00
|
|
|
return prop;
|
2005-10-18 09:45:27 +02:00
|
|
|
}
|
2006-09-06 16:31:17 +02:00
|
|
|
|
2006-12-07 03:40:57 +01:00
|
|
|
private static final String[] wordArray(String words) {
|
2008-10-21 13:27:50 +02:00
|
|
|
String[] w = new String[0];
|
|
|
|
if (words == null || words.length() == 0) return w;
|
|
|
|
try {
|
2006-12-07 03:40:57 +01:00
|
|
|
words = URLDecoder.decode(words, "UTF-8");
|
|
|
|
w = words.substring(1, words.length() - 1).split(",");
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final UnsupportedEncodingException e) {}
|
2006-12-07 03:40:57 +01:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2008-08-02 14:12:04 +02:00
|
|
|
private static final String markup(final String[] wordArray, String message) {
|
2009-07-08 23:48:08 +02:00
|
|
|
message = CharacterCoding.unicode2html(message, true);
|
2007-01-06 13:21:13 +01:00
|
|
|
if (wordArray != null)
|
|
|
|
for (int j = 0; j < wordArray.length; j++) {
|
2008-08-02 14:12:04 +02:00
|
|
|
final String currentWord = wordArray[j].trim();
|
2007-02-03 21:22:39 +01:00
|
|
|
// TODO: replace upper-/lowercase words as well
|
2007-01-06 13:21:13 +01:00
|
|
|
message = message.replaceAll(currentWord,
|
|
|
|
"<span class=\"" + HIGHLIGHT_CSS + ((j % MAX_HIGHLIGHTS) + 1) + "\">" +
|
|
|
|
currentWord +
|
|
|
|
"</span>");
|
|
|
|
}
|
2006-12-07 03:40:57 +01:00
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2009-10-11 02:12:19 +02:00
|
|
|
private static int putMediaInfo(final serverObjects prop, final String[] wordArray, int c, final Map<DigestURI, String> media, final String name, boolean dark) {
|
|
|
|
final Iterator<Map.Entry<DigestURI, String>> mi = media.entrySet().iterator();
|
|
|
|
Map.Entry<DigestURI, String> entry;
|
2006-12-07 03:40:57 +01:00
|
|
|
int i = 0;
|
|
|
|
while (mi.hasNext()) {
|
2008-01-06 20:23:38 +01:00
|
|
|
entry = mi.next();
|
2006-12-07 03:40:57 +01:00
|
|
|
prop.put("viewMode_links_" + c + "_nr", c);
|
|
|
|
prop.put("viewMode_links_" + c + "_dark", ((dark) ? 1 : 0));
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.putHTML("viewMode_links_" + c + "_type", name);
|
2008-06-06 18:01:27 +02:00
|
|
|
prop.put("viewMode_links_" + c + "_text", markup(wordArray, entry.getValue()));
|
2008-01-22 12:51:43 +01:00
|
|
|
prop.put("viewMode_links_" + c + "_link", markup(wordArray, entry.getKey().toNormalform(true, false)));
|
|
|
|
prop.put("viewMode_links_" + c + "_url", entry.getKey().toNormalform(true, false));
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.putHTML("viewMode_links_" + c + "_attr", "");
|
2006-12-07 03:40:57 +01:00
|
|
|
dark = !dark;
|
|
|
|
c++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-10-18 09:45:27 +02:00
|
|
|
}
|