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

To conveniently follow parsed links in the file viewer
pull/303/head
luccioman 6 years ago
parent 8c068a9c99
commit d16bc99835

@ -202,6 +202,7 @@ function updatepage(str) {
<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 @@ function updatepage(str) {
#{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 class ViewFile {
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 class ViewFile {
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,16 +442,17 @@ public class ViewFile {
* @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();
@ -459,12 +460,20 @@ public class ViewFile {
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 @@ public class ViewFile {
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 @@ public class ViewFile {
* @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 @@ public class ViewFile {
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,6 +574,7 @@ public class ViewFile {
* @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(
@ -562,19 +582,28 @@ public class ViewFile {
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 @@ public class ViewFile {
}
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 class UTF8 implements Comparator<String> {
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;
}
}
}

Loading…
Cancel
Save