added switches to ConfigParser to accept/deny documents by their

extension
pull/1/head
Michael Peter Christen 13 years ago
parent 4901cee3cc
commit 7f9b6b7a0c

@ -3,6 +3,16 @@
<head> <head>
<title>YaCy '#[clientname]#': Advanced Settings</title> <title>YaCy '#[clientname]#': Advanced Settings</title>
#%env/templates/metas.template%# #%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> </head>
<body id="Settings"> <body id="Settings">
#%env/templates/header.template%# #%env/templates/header.template%#
@ -18,14 +28,21 @@
</p> </p>
<table border="0" cellpadding="2" cellspacing="1"> <table border="0" cellpadding="2" cellspacing="1">
<tr class="TableHeader" valign="bottom"> <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> <td class="small" >Mime-Type</td>
</tr>#{parser}# </tr>#{parser}#
<tr class="TableCellDark"> <tr class="TableCellDark">
<td colspan="2">#[name]#</td> <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"> <tr class="TableCellLight">
<td class="small" align="center"><input type="checkbox" name="mimename_#[mimetype]#" #(status)#::checked="checked" #(/status)#/></td> <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> <td class="small">#[mimetype]#</td>
</tr>#{/mime}# </tr>#{/mime}#
#{/parser}# #{/parser}#

@ -53,6 +53,9 @@ public class ConfigParser {
post.remove("parserSettings"); post.remove("parserSettings");
for (final Parser parser: TextParser.parsers()) { 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()) { for (final String mimeType: parser.supportedMimeTypes()) {
TextParser.grantMime(mimeType, "on".equals(post.get("mimename_" + mimeType, ""))); TextParser.grantMime(mimeType, "on".equals(post.get("mimename_" + mimeType, "")));
} }
@ -65,6 +68,14 @@ public class ConfigParser {
for (final Parser parser: TextParser.parsers()) { for (final Parser parser: TextParser.parsers()) {
prop.put("parser_" + i + "_name", parser.getName()); 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; int mimeIdx = 0;
for (final String mimeType: parser.supportedMimeTypes()) { for (final String mimeType: parser.supportedMimeTypes()) {
prop.put("parser_" + i + "_mime_" + mimeIdx + "_mimetype", mimeType); prop.put("parser_" + i + "_mime_" + mimeIdx + "_mimetype", mimeType);

@ -380,6 +380,13 @@ public final class TextParser {
return idioms; 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) { public static String supportsMime(String mimeType) {
if (mimeType == null) return null; if (mimeType == null) return null;
mimeType = normalizeMimeType(mimeType); mimeType = normalizeMimeType(mimeType);
@ -388,8 +395,13 @@ public final class TextParser {
return null; 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 (ext == null || ext.length() == 0) return null;
if (denyExtensionx.containsKey(ext)) return "file extension '" + ext + "' is denied (2)"; if (denyExtensionx.containsKey(ext)) return "file extension '" + ext + "' is denied (2)";
final String mimeType = ext2mime.get(ext); final String mimeType = ext2mime.get(ext);
@ -400,6 +412,16 @@ public final class TextParser {
return null; 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) { public static String mimeOf(final MultiProtocolURI url) {
return mimeOf(url.getFileExtension()); return mimeOf(url.getFileExtension());
} }

Loading…
Cancel
Save