Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

added switches to ConfigParser to accept/deny documents by their extension

Michael Peter Christen7f9b6b7a0c2f
diff --git a/htroot/ConfigParser.html b/htroot/ConfigParser.html
index 11c39bfb3..2b00b4e40 100644
--- a/htroot/ConfigParser.html
+++ b/htroot/ConfigParser.html
@@ -3,6 +3,16 @@
<head>
<title>YaCy '#[clientname]#': Advanced Settings</title>
#%env/templates/metas.template%#
+ <script type="text/javascript">
+ <!--
+ function checkAll(formToCheckAll, checkStatus) {
+ var inputs=document.getElementById(formToCheckAll);
+ for (var i =0; i < inputs.elements.length; i++) {
+ inputs.elements[i].checked = checkStatus;
+ }
+ }
+ -->
+ </script>
</head>
<body id="Settings">
#%env/templates/header.template%#
@@ -18,14 +28,21 @@
</p>
<table border="0" cellpadding="2" cellspacing="1">
<tr class="TableHeader" valign="bottom">
- <td class="small" >enable/disable Parser</td>
+ <td class="small" ><input type="checkbox" id="allswitch" onclick="checkAll(this.form.id, this.checked);" /> enable/disable</td>
+ <td class="small" >Extension</td>
<td class="small" >Mime-Type</td>
</tr>#{parser}#
<tr class="TableCellDark">
<td colspan="2">#[name]#</td>
- </tr>#{mime}#
+ </tr>#{ext}#
+ <tr id="#[name]#" class="TableCellLight">
+ <td class="small" align="center"><input type="checkbox" name="extension_#[extension]#" #(status)#::checked="checked" #(/status)#/></td>
+ <td class="small">#[extension]#</td>
+ <td class="small"></td>
+ </tr>#{/ext}##{mime}#
<tr class="TableCellLight">
<td class="small" align="center"><input type="checkbox" name="mimename_#[mimetype]#" #(status)#::checked="checked" #(/status)#/></td>
+ <td class="small"></td>
<td class="small">#[mimetype]#</td>
</tr>#{/mime}#
#{/parser}#
diff --git a/htroot/ConfigParser.java b/htroot/ConfigParser.java
index 86182ec96..a861da556 100644
--- a/htroot/ConfigParser.java
+++ b/htroot/ConfigParser.java
@@ -53,6 +53,9 @@ public class ConfigParser {
post.remove("parserSettings");
for (final Parser parser: TextParser.parsers()) {
+ for (final String ext: parser.supportedExtensions()) {
+ TextParser.grantExtension(ext, "on".equals(post.get("extension_" + ext, "")));
+ }
for (final String mimeType: parser.supportedMimeTypes()) {
TextParser.grantMime(mimeType, "on".equals(post.get("mimename_" + mimeType, "")));
}
@@ -65,6 +68,14 @@ public class ConfigParser {
for (final Parser parser: TextParser.parsers()) {
prop.put("parser_" + i + "_name", parser.getName());
+ int extIdx = 0;
+ for (final String ext: parser.supportedExtensions()) {
+ prop.put("parser_" + i + "_ext_" + extIdx + "_extension", ext);
+ prop.put("parser_" + i + "_ext_" + extIdx + "_status", (TextParser.supportsExtension(ext) == null) ? 1 : 0);
+ extIdx++;
+ }
+ prop.put("parser_" + i + "_ext", extIdx);
+
int mimeIdx = 0;
for (final String mimeType: parser.supportedMimeTypes()) {
prop.put("parser_" + i + "_mime_" + mimeIdx + "_mimetype", mimeType);
diff --git a/source/net/yacy/document/TextParser.java b/source/net/yacy/document/TextParser.java
index cd5cd2ca7..850a7a433 100644
--- a/source/net/yacy/document/TextParser.java
+++ b/source/net/yacy/document/TextParser.java
@@ -380,6 +380,13 @@ public final class TextParser {
return idioms;
}
+
+ /**
+ * checks if the parser supports the given mime type. It is not only checked if the parser can parse such types,
+ * it is also checked if the mime type is not included in the mimetype-deny list.
+ * @param mimeType
+ * @return an error if the mime type is not supported, null otherwise
+ */
public static String supportsMime(String mimeType) {
if (mimeType == null) return null;
mimeType = normalizeMimeType(mimeType);
@@ -388,8 +395,13 @@ public final class TextParser {
return null;
}
- public static String supportsExtension(final MultiProtocolURI url) {
- final String ext = url.getFileExtension().toLowerCase();
+ /**
+ * checks if the parser supports the given extension. It is not only checked if the parser can parse such files,
+ * it is also checked if the extension is not included in the extension-deny list.
+ * @param extention
+ * @return an error if the extension is not supported, null otherwise
+ */
+ public static String supportsExtension(final String ext) {
if (ext == null || ext.length() == 0) return null;
if (denyExtensionx.containsKey(ext)) return "file extension '" + ext + "' is denied (2)";
final String mimeType = ext2mime.get(ext);
@@ -400,6 +412,16 @@ public final class TextParser {
return null;
}
+ /**
+ * checks if the parser supports the given extension. It is not only checked if the parser can parse such files,
+ * it is also checked if the extension is not included in the extension-deny list.
+ * @param extention
+ * @return an error if the extension is not supported, null otherwise
+ */
+ public static String supportsExtension(final MultiProtocolURI url) {
+ return supportsExtension(url.getFileExtension().toLowerCase());
+ }
+
public static String mimeOf(final MultiProtocolURI url) {
return mimeOf(url.getFileExtension());
}