Skip to content
Permalink
Browse files

Added "Show Metadata" links to the ViewFile.html links mode

To conveniently follow parsed links in the file viewer
  • Loading branch information...
luccioman committed Apr 18, 2019
1 parent 8c068a9 commit d16bc99835a1cb2856e60ff3df5dca9d2a7621b6
Showing with 66 additions and 17 deletions.
  1. +2 −0 htroot/ViewFile.html
  2. +45 −17 htroot/ViewFile.java
  3. +19 −0 source/net/yacy/cora/document/encoding/UTF8.java
@@ -202,6 +202,7 @@ <h2>View URL Content</h2>
<table border="0">
<tr class="head">
<td>nr</td>
<td class="tt"><span class="glyphicon glyphicon-list" title="action"></span></td>
<td class="tt">type</td>
<td class="tt">name</td>
<td class="tt">link</td>
@@ -211,6 +212,7 @@ <h2>View URL Content</h2>
#{links}#
<tr class="TableCell#(dark)#Light::Dark::Summary#(/dark)#">
<td>#[nr]#</td>
<td class="tt"><a href="ViewFile.html?viewMode=links#(agent)#::&agentName=#[name]##(/agent)#&url=#[encodedUrl]#" title="Show Metadata"><img src="env/grafics/doc.gif" alt=""></a></td>
<td class="tt"><tt>#[type]#</tt></td>
<td class="tt"><tt>#[name]#</tt></td>
<td class="tt"><tt><a href="#[url]#">#[link]#</a></tt></td>
@@ -184,7 +184,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje

Response response = null;
try {
ClientIdentification.Agent agent = ClientIdentification.getAgent(post.get("agentName", ClientIdentification.yacyInternetCrawlerAgentName));
final ClientIdentification.Agent agent = ClientIdentification.getAgent(post.get("agentName", ClientIdentification.yacyInternetCrawlerAgentName));
// use sb.loader.requst( , , global=true) to use crawlprofile to allow index update
response = sb.loader.load(sb.loader.request(url, true, true), authorized ? CacheStrategy.IFEXIST : CacheStrategy.CACHEONLY, Integer.MAX_VALUE, null, agent);
} catch (final IOException e) {
@@ -341,7 +341,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("viewMode_words", i);

} else if (viewMode.equals("links")) {
putLinks(prop, wordArray, document);
putLinks(prop, wordArray, document, post.get("agentName"));

}
// optional: generate snippet
@@ -442,29 +442,38 @@ public static serverObjects respond(final RequestHeader header, final serverObje
* @param prop object to be filled. Must not be null
* @param wordArray aray of words from word post parameter
* @param document document to process
* @param agentName the eventual custom identification agent name used to load documents
*/
private static void putLinks(final serverObjects prop, final String[] wordArray, Document document) {
private static void putLinks(final serverObjects prop, final String[] wordArray, final Document document, final String agentName) {
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));
i += putMediaInfo(prop, wordArray, i, document.getVideolinks(), "video", (i % 2 == 0), agentName);
i += putMediaInfo(prop, wordArray, i, document.getAudiolinks(), "audio", (i % 2 == 0), agentName);
dark = (i % 2 == 0);
i += putIconsInfos(prop, wordArray, i, document.getIcons().values(), (i % 2 == 0));
i += putIconsInfos(prop, wordArray, i, document.getIcons().values(), (i % 2 == 0), agentName);
dark = (i % 2 == 0);

final Map<DigestURL, ImageEntry> ts = document.getImages();
final Iterator<ImageEntry> tsi = ts.values().iterator();
ImageEntry entry;
while (tsi.hasNext()) {
entry = tsi.next();
final String urlStr = entry.url().toNormalform(true);
prop.put("viewMode_links_" + i + "_nr", i);
prop.put("viewMode_links_" + i + "_dark", dark ? "1" : "0");
prop.put("viewMode_links_" + i + "_type", "image");
prop.put("viewMode_links_" + i + "_text", (entry.alt().isEmpty()) ? "&nbsp;" : markup(wordArray, entry.alt()));
prop.put("viewMode_links_" + i + "_url", entry.url().toNormalform(true));
prop.put("viewMode_links_" + i + "_link", markup(wordArray, entry.url().toNormalform(true)));
prop.put("viewMode_links_" + i + "_encodedUrl", UTF8.encodeUrl(urlStr));
if(agentName != null) {
prop.put("viewMode_links_" + i + "_agent", true);
prop.put("viewMode_links_" + i + "_agent_name", UTF8.encodeUrl(agentName));
} else {
prop.put("viewMode_links_" + i + "_agent", false);
}
prop.put("viewMode_links_" + i + "_url", urlStr);
prop.put("viewMode_links_" + i + "_link", markup(wordArray, urlStr));
if (entry.width() > 0 && entry.height() > 0) {
prop.put("viewMode_links_" + i + "_rel", entry.width() + "x" + entry.height() + " Pixel");
} else {
@@ -474,8 +483,8 @@ private static void putLinks(final serverObjects prop, final String[] wordArray,
dark = !dark;
i++;
}
i += putMediaInfo(prop, wordArray, i, document.getApplinks(), "app", (i % 2 == 0));
i += putMediaInfo(prop, wordArray, i, document.getHyperlinks(), "link", (i % 2 == 0));
i += putMediaInfo(prop, wordArray, i, document.getApplinks(), "app", (i % 2 == 0), agentName);
i += putMediaInfo(prop, wordArray, i, document.getHyperlinks(), "link", (i % 2 == 0), agentName);
prop.put("viewMode_links", i);
}

@@ -518,6 +527,7 @@ private static final String markup(final String[] wordArray, String message) {
* @param media media links
* @param type type of media link
* @param dark current result line style
* @param agentName the eventual custom identification agent name used to load documents
* @return number of links added to prop
*/
private static int putMediaInfo(
@@ -526,19 +536,28 @@ private static int putMediaInfo(
int c,
final Map<AnchorURL, String> media,
final String type,
boolean dark) {
boolean dark,
final String agentName) {
int i = 0;
for (final Map.Entry<AnchorURL, String> entry : media.entrySet()) {
final String name = entry.getKey().getNameProperty(); // the name attribute
final String rel = entry.getKey().getRelProperty(); // the rel-attribute
final String text = entry.getKey().getTextProperty(); // the text between the <a></a> tag
final String urlStr = entry.getKey().toNormalform(true);

prop.put("viewMode_links_" + c + "_nr", c);
prop.put("viewMode_links_" + c + "_dark", ((dark) ? 1 : 0));
prop.putHTML("viewMode_links_" + c + "_type", type);
prop.put("viewMode_links_" + c + "_text", text);
prop.put("viewMode_links_" + c + "_link", markup(wordArray, entry.getKey().toNormalform(true)));
prop.put("viewMode_links_" + c + "_url", entry.getKey().toNormalform(true));
prop.put("viewMode_links_" + c + "_link", markup(wordArray, urlStr));
prop.put("viewMode_links_" + c + "_url", urlStr);
prop.put("viewMode_links_" + c + "_encodedUrl", UTF8.encodeUrl(urlStr));
if(agentName != null) {
prop.put("viewMode_links_" + c + "_agent", true);
prop.put("viewMode_links_" + c + "_agent_name", UTF8.encodeUrl(agentName));
} else {
prop.put("viewMode_links_" + c + "_agent", false);
}
prop.put("viewMode_links_" + c + "_rel", rel);
prop.put("viewMode_links_" + c + "_name", name);
dark = !dark;
@@ -555,26 +574,36 @@ private static int putMediaInfo(
* @param c current links count
* @param icons icon links
* @param dark current result line style
* @param agentName the eventual custom identification agent name used to load documents
* @return number of links added to prop
*/
private static int putIconsInfos(
final serverObjects prop,
final String[] wordArray,
int c,
final Collection<IconEntry> icons,
boolean dark) {
boolean dark,
final String agentName) {
int i = 0;
for (final IconEntry entry : icons) {
final String name = ""; // the name attribute
final String rel = entry.relToString(); // the rel-attribute
final String text = ""; // the text between the <a></a> tag
final String urlStr = entry.getUrl().toNormalform(true);

prop.put("viewMode_links_" + c + "_nr", c);
prop.put("viewMode_links_" + c + "_dark", ((dark) ? 1 : 0));
prop.putHTML("viewMode_links_" + c + "_type", "icon");
prop.put("viewMode_links_" + c + "_text", text);
prop.put("viewMode_links_" + c + "_link", markup(wordArray, entry.getUrl().toNormalform(true)));
prop.put("viewMode_links_" + c + "_url", entry.getUrl().toNormalform(true));
prop.put("viewMode_links_" + c + "_link", markup(wordArray, urlStr));
prop.put("viewMode_links_" + c + "_url", urlStr);
prop.put("viewMode_links_" + c + "_encodedUrl", UTF8.encodeUrl(urlStr));
if(agentName != null) {
prop.put("viewMode_links_" + c + "_agent", true);
prop.put("viewMode_links_" + c + "_agent_name", UTF8.encodeUrl(agentName));
} else {
prop.put("viewMode_links_" + c + "_agent", false);
}
prop.put("viewMode_links_" + c + "_rel", rel);
prop.put("viewMode_links_" + c + "_name", name);
dark = !dark;
@@ -583,5 +612,4 @@ private static int putIconsInfos(
}
return i;
}

}
@@ -24,6 +24,8 @@

package net.yacy.cora.document.encoding;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;

@@ -268,5 +270,22 @@ public static String decodeURL(final String s) {

return (needToChange? sb.toString() : s);
}

/**
* Utility wrapper around the standard JDK {@link URLEncoder#encode(String)}
* function, using the UTF-8 character set and catching
* {@link UnsupportedEncodingException} exception.
*
* @param str a string to encode. Must not be null.
* @return str encoded in application/x-www-form-urlencoded format
*/
public static String encodeUrl(final String str) {
try {
return URLEncoder.encode(str, StandardCharsets.UTF_8.name());
} catch (final UnsupportedEncodingException e) {
/* Should not happen : UTF-8 support is required for any Java platform */
return str;
}
}

}

0 comments on commit d16bc99

Please sign in to comment.
You can’t perform that action at this time.