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
|
|
|
|
2010-12-27 18:07:21 +01:00
|
|
|
// $LastChangedDate$
|
|
|
|
// $LastChangedRevision$
|
|
|
|
// $LastChangedBy$
|
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
|
|
|
|
|
2011-02-12 01:01:40 +01:00
|
|
|
import java.io.ByteArrayInputStream;
|
2011-06-13 23:44:03 +02:00
|
|
|
import java.io.IOException;
|
2006-11-23 16:47:19 +01:00
|
|
|
import java.net.MalformedURLException;
|
2010-09-22 22:50:02 +02:00
|
|
|
import java.util.Collection;
|
2009-01-04 03:27:29 +01:00
|
|
|
import java.util.Enumeration;
|
2006-12-07 03:40:57 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
2011-08-25 17:52:25 +02:00
|
|
|
import java.util.Properties;
|
2005-10-18 09:45:27 +02:00
|
|
|
|
2011-05-27 10:24:54 +02:00
|
|
|
import net.yacy.cora.document.ASCII;
|
2010-05-25 14:54:57 +02:00
|
|
|
import net.yacy.cora.document.MultiProtocolURI;
|
2011-03-07 21:36:40 +01:00
|
|
|
import net.yacy.cora.document.UTF8;
|
2010-08-23 14:32:02 +02:00
|
|
|
import net.yacy.cora.protocol.RequestHeader;
|
2011-06-13 23:44:03 +02:00
|
|
|
import net.yacy.cora.services.federated.yacy.CacheStrategy;
|
2009-10-18 02:53:43 +02:00
|
|
|
import net.yacy.document.Condenser;
|
|
|
|
import net.yacy.document.Document;
|
2011-02-12 01:01:40 +01:00
|
|
|
import net.yacy.document.LibraryProvider;
|
2010-06-29 21:20:45 +02:00
|
|
|
import net.yacy.document.Parser;
|
2011-02-12 01:01:40 +01:00
|
|
|
import net.yacy.document.WordTokenizer;
|
2009-10-18 02:53:43 +02:00
|
|
|
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;
|
2011-09-25 18:59:06 +02:00
|
|
|
import net.yacy.search.Switchboard;
|
|
|
|
import net.yacy.search.index.Segment;
|
|
|
|
import net.yacy.search.index.Segments;
|
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;
|
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;
|
2011-06-13 23:44:03 +02:00
|
|
|
|
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;
|
2011-06-13 23:44:03 +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;
|
|
|
|
}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2010-03-05 16:41:15 +01:00
|
|
|
final int display = post.getInt("display", 1);
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2009-10-09 16:44:20 +02:00
|
|
|
// get segment
|
|
|
|
Segment indexSegment = null;
|
2011-11-25 15:09:25 +01:00
|
|
|
final boolean authorized = sb.verifyAuthentication(header);
|
2010-05-06 00:45:54 +02:00
|
|
|
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);
|
2011-06-13 23:44:03 +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");
|
2011-06-13 23:44:03 +02: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;
|
2011-06-13 23:44:03 +02: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
|
2011-05-27 10:24:54 +02:00
|
|
|
if (urlHash.length() > 0 && (urlEntry = indexSegment.urlMetadata().load(ASCII.getBytes(urlHash))) != 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);
|
2011-06-13 23:44:03 +02:00
|
|
|
|
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
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2011-11-25 15:09:25 +01:00
|
|
|
if (!sb.verifyAuthentication(header)) {
|
2006-11-23 18:13:25 +01:00
|
|
|
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// define an url by post parameter
|
2010-10-26 18:10:20 +02:00
|
|
|
url = new DigestURI(MultiProtocolURI.unescape(urlString));
|
2011-05-27 10:24:54 +02:00
|
|
|
urlHash = ASCII.String(url.hash());
|
2011-03-15 02:03:35 +01:00
|
|
|
pre = post.getBoolean("pre", false);
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final MalformedURLException e) {}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
|
|
|
|
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);
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2010-06-22 14:28:53 +02:00
|
|
|
Response response = null;
|
|
|
|
try {
|
2011-08-02 01:28:23 +02:00
|
|
|
response = sb.loader.load(sb.loader.request(url, true, false), authorized ? CacheStrategy.IFEXIST : CacheStrategy.CACHEONLY, Integer.MAX_VALUE, true);
|
2011-06-13 23:44:03 +02:00
|
|
|
} catch (final IOException e) {
|
2010-06-22 14:28:53 +02:00
|
|
|
prop.put("error", "4");
|
|
|
|
prop.put("error_errorText", "error loading resource: " + e.getMessage());
|
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
2008-04-05 15:17:16 +02:00
|
|
|
}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2010-06-22 14:28:53 +02:00
|
|
|
if (response == null) {
|
2010-06-21 16:54:54 +02:00
|
|
|
prop.put("error", "4");
|
|
|
|
prop.put("error_errorText", "No resource available");
|
|
|
|
prop.put("viewMode", VIEW_MODE_NO_TEXT);
|
|
|
|
return prop;
|
2006-11-23 16:47:19 +01:00
|
|
|
}
|
2011-06-13 23:44:03 +02: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 {
|
2011-03-07 21:36:40 +01:00
|
|
|
content = UTF8.String(response.getContent());
|
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;
|
|
|
|
}
|
|
|
|
|
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", " "));
|
2011-06-13 23:44:03 +02: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));
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2010-03-07 00:41:51 +01:00
|
|
|
} else if (viewMode.equals("iframeCache")) {
|
|
|
|
prop.put("viewMode", VIEW_MODE_AS_IFRAME_FROM_CACHE);
|
2010-12-27 18:07:21 +01:00
|
|
|
final String ext = url.getFileExtension();
|
2010-11-27 10:16:16 +01:00
|
|
|
if ("jpg.jpeg.png.gif".indexOf(ext) >= 0) {
|
|
|
|
prop.put("viewMode_png", 1);
|
|
|
|
prop.put("viewMode_png_url", url.toNormalform(false, true));
|
|
|
|
} else {
|
|
|
|
prop.put("viewMode_html", 1);
|
|
|
|
prop.put("viewMode_html_url", url.toNormalform(false, true));
|
|
|
|
}
|
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-06-29 21:20:45 +02:00
|
|
|
document = Document.mergeDocuments(response.url(), response.getMimeType(), response.parse());
|
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
|
|
|
}
|
2010-06-29 21:20:45 +02:00
|
|
|
} catch (final Parser.Failure 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;
|
|
|
|
}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2006-11-23 16:47:19 +01:00
|
|
|
if (viewMode.equals("parsed")) {
|
2011-03-07 21:36:40 +01:00
|
|
|
final String content = UTF8.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());
|
2010-06-29 21:20:45 +02:00
|
|
|
prop.put("viewMode_source", url.toString());
|
2011-03-30 02:49:47 +02:00
|
|
|
prop.put("viewMode_lat", document.lat());
|
|
|
|
prop.put("viewMode_lon", document.lon());
|
2008-02-26 22:17:41 +01:00
|
|
|
prop.put("viewMode_parsedText", markup(wordArray, content).replaceAll("\n", "<br />").replaceAll("\t", " "));
|
2011-06-13 23:44:03 +02: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);
|
2010-09-22 22:50:02 +02:00
|
|
|
final Collection<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) {
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2006-12-07 03:40:57 +01:00
|
|
|
// Search word highlighting
|
2010-12-27 18:07:21 +01:00
|
|
|
for (final StringBuilder s: sentences) {
|
2010-09-22 22:50:02 +02:00
|
|
|
sentence = s.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);
|
2010-09-22 22:50:02 +02:00
|
|
|
final Collection<StringBuilder> sentences = document.getSentences(pre);
|
2009-01-04 03:27:29 +01:00
|
|
|
|
|
|
|
boolean dark = true;
|
|
|
|
int i = 0;
|
2011-11-09 15:42:55 +01:00
|
|
|
String sentence;
|
|
|
|
StringBuilder token;
|
2009-01-04 03:27:29 +01:00
|
|
|
if (sentences != null) {
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2009-01-04 03:27:29 +01:00
|
|
|
// Search word highlighting
|
2010-12-27 18:07:21 +01:00
|
|
|
for (final StringBuilder s: sentences) {
|
2010-09-22 22:50:02 +02:00
|
|
|
sentence = s.toString();
|
2011-11-09 15:42:55 +01:00
|
|
|
Enumeration<StringBuilder> tokens = null;
|
2011-03-11 00:25:07 +01:00
|
|
|
tokens = new WordTokenizer(new ByteArrayInputStream(UTF8.getBytes(sentence)), LibraryProvider.dymLib);
|
2009-01-04 03:27:29 +01:00
|
|
|
while (tokens.hasMoreElements()) {
|
2010-10-18 13:35:09 +02:00
|
|
|
token = tokens.nextElement();
|
2009-01-04 03:27:29 +01:00
|
|
|
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;
|
2011-08-25 17:52:25 +02:00
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getVideolinks(), "video", (i % 2 == 0), document.getAnchors());
|
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getAudiolinks(), "audio", (i % 2 == 0), document.getAnchors());
|
2006-12-07 03:40:57 +01:00
|
|
|
dark = (i % 2 == 0);
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2010-12-27 18:07:21 +01:00
|
|
|
final Map<MultiProtocolURI, ImageEntry> ts = document.getImages();
|
2009-07-08 23:48:08 +02:00
|
|
|
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");
|
2010-10-17 18:51:29 +02:00
|
|
|
prop.put("viewMode_links_" + i + "_text", (entry.alt().isEmpty()) ? " " : 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)));
|
2011-08-25 17:52:25 +02:00
|
|
|
if (entry.width() > 0 && entry.height() > 0) {
|
|
|
|
prop.put("viewMode_links_" + i + "_rel", entry.width() + "x" + entry.height() + " Pixel");
|
|
|
|
} else {
|
|
|
|
prop.put("viewMode_links_" + i + "_rel", "");
|
|
|
|
}
|
|
|
|
prop.put("viewMode_links_" + i + "_name", "");
|
2006-12-07 03:40:57 +01:00
|
|
|
dark = !dark;
|
|
|
|
i++;
|
|
|
|
}
|
2011-08-25 17:52:25 +02:00
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getApplinks(), "app", (i % 2 == 0), document.getAnchors());
|
|
|
|
i += putMediaInfo(prop, wordArray, i, document.getHyperlinks(), "link", (i % 2 == 0), document.getAnchors());
|
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);
|
2010-10-17 18:51:29 +02:00
|
|
|
prop.putHTML("error_desc", (descr.isEmpty()) ? " " : descr);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.putNum("error_size", size);
|
2010-06-22 14:28:53 +02:00
|
|
|
prop.put("error_mimeTypeAvailable", (response.getMimeType() == null) ? "0" : "1");
|
|
|
|
prop.put("error_mimeTypeAvailable_mimeType", response.getMimeType());
|
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;
|
2010-05-21 00:05:04 +02:00
|
|
|
if (words.length() > 1 && words.charAt(0) == '[' && words.charAt(words.length() - 1) == ']') {
|
|
|
|
words = words.substring(1, words.length() - 1);
|
|
|
|
}
|
2011-11-08 13:02:22 +01:00
|
|
|
words = UTF8.decodeURL(words);
|
2011-11-25 12:23:52 +01:00
|
|
|
if (words.indexOf(' ',0) >= 0) return words.split(" ");
|
|
|
|
if (words.indexOf(',',0) >= 0) return words.split(",");
|
|
|
|
if (words.indexOf('+',0) >= 0) return words.split("\\+");
|
2011-11-08 13:02:22 +01:00
|
|
|
w = new String[1];
|
|
|
|
w[0] = words;
|
2006-12-07 03:40:57 +01:00
|
|
|
return w;
|
|
|
|
}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
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);
|
2010-12-27 18:07:21 +01:00
|
|
|
if (wordArray != null) {
|
|
|
|
int j = 0;
|
|
|
|
for (String currentWord : wordArray) {
|
|
|
|
currentWord = currentWord.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,
|
2010-12-27 18:07:21 +01:00
|
|
|
"<span class=\"" + HIGHLIGHT_CSS + ((j++ % MAX_HIGHLIGHTS) + 1) + "\">" +
|
2011-06-13 23:44:03 +02:00
|
|
|
currentWord +
|
2007-01-06 13:21:13 +01:00
|
|
|
"</span>");
|
|
|
|
}
|
2010-12-27 18:07:21 +01:00
|
|
|
}
|
2006-12-07 03:40:57 +01:00
|
|
|
return message;
|
|
|
|
}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2011-08-25 17:52:25 +02:00
|
|
|
private static int putMediaInfo(
|
|
|
|
final serverObjects prop,
|
|
|
|
final String[] wordArray,
|
|
|
|
int c,
|
|
|
|
final Map<MultiProtocolURI, String> media,
|
|
|
|
final String type,
|
|
|
|
boolean dark,
|
|
|
|
final Map<MultiProtocolURI, Properties> alllinks) {
|
2006-12-07 03:40:57 +01:00
|
|
|
int i = 0;
|
2011-06-13 23:44:03 +02:00
|
|
|
for (final Map.Entry<MultiProtocolURI, String> entry : media.entrySet()) {
|
2011-08-25 17:52:25 +02:00
|
|
|
final Properties p = alllinks.get(entry.getKey());
|
|
|
|
final String name = p.getProperty("name", ""); // the name attribute
|
|
|
|
final String rel = p.getProperty("rel", ""); // the rel-attribute
|
|
|
|
final String text = p.getProperty("text", ""); // the text between the <a></a> tag
|
|
|
|
|
2006-12-07 03:40:57 +01:00
|
|
|
prop.put("viewMode_links_" + c + "_nr", c);
|
|
|
|
prop.put("viewMode_links_" + c + "_dark", ((dark) ? 1 : 0));
|
2011-08-25 17:52:25 +02:00
|
|
|
prop.putHTML("viewMode_links_" + c + "_type", type);
|
2011-08-29 11:16:41 +02:00
|
|
|
prop.put("viewMode_links_" + c + "_text", text);
|
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));
|
2011-08-25 17:52:25 +02:00
|
|
|
prop.put("viewMode_links_" + c + "_rel", rel);
|
|
|
|
prop.put("viewMode_links_" + c + "_name", name);
|
2006-12-07 03:40:57 +01:00
|
|
|
dark = !dark;
|
|
|
|
c++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
2011-06-13 23:44:03 +02:00
|
|
|
|
2005-10-18 09:45:27 +02:00
|
|
|
}
|