private static final int MAX_HIGHLIGHTS = 6;
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard)env;
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);
// get segment
Segment indexSegment = null;
final boolean authorized = sb.verifyAuthentication(header);
if (post != null && post.containsKey("segment") && authorized) {
indexSegment = sb.indexSegments.segment(post.get("segment"));
} else {
indexSegment = sb.indexSegments.segment(Segments.Process.PUBLIC);
}
prop.put("display", display);
prop.put("error_display", display);
if (post.containsKey("words"))
prop.putHTML("error_words", post.get("words"));
else {
prop.putHTML("error_words", "");
}
final String viewMode = post.get("viewMode","parsed");
prop.put("error_vMode-" + viewMode, "1");
DigestURI url = null;
String descr = "";
final int wordCount = 0;
int size = 0;
boolean pre = false;
// get the url hash from which the content should be loaded
String urlHash = post.get("urlHash", "");
URIMetadataRow urlEntry = null;
// get the urlEntry that belongs to the url hash
if (urlHash.length() > 0 && (urlEntry = indexSegment.urlMetadata().load(ASCII.getBytes(urlHash))) != null) {
// get the url that belongs to the entry
final URIMetadataRow.Components metadata = urlEntry.metadata();
if ((metadata == null) || (metadata.url() == null)) {
prop.put("error", "3");
prop.put("viewMode", VIEW_MODE_NO_TEXT);
return prop;
}
url = metadata.url();
descr = metadata.dc_title();
//urlEntry.wordCount();
size = urlEntry.size();
pre = urlEntry.flags().get(Condenser.flag_cat_indexof);
}
prop.put("error_inurldb", urlEntry == null ? 0 : 1);
// alternatively, get the url simply from a url String
// this can be used as a simple tool to test the text parser
final String urlString = post.get("url", "");
if (urlString.length() > 0) try {
// this call forces the peer to download web pages
// it is therefore protected by the admin password
if (!sb.verifyAuthentication(header)) {
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
// define an url by post parameter