Author: toad
Date: 2007-12-24 12:35:18 +0000 (Mon, 24 Dec 2007)
New Revision: 16808
Modified:
trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
trunk/freenet/src/freenet/clients/http/QueueToadlet.java
Log:
Make the MIME type form look a bit more like the big file form - show the known
info on the file, and offer to download in background.
Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-12-23
21:10:17 UTC (rev 16807)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-12-24
12:35:18 UTC (rev 16808)
@@ -82,7 +82,7 @@
}
- public static void handleDownload(ToadletContext context, Bucket data,
BucketFactory bucketFactory, String mimeType, String requestedMimeType, String
forceString, boolean forceDownload, String basePath, FreenetURI key, String
extras, String referrer) throws ToadletContextClosedException, IOException {
+ public static void handleDownload(ToadletContext context, Bucket data,
BucketFactory bucketFactory, String mimeType, String requestedMimeType, String
forceString, boolean forceDownload, String basePath, FreenetURI key, String
extras, String referrer, boolean downloadLink, ToadletContext ctx) throws
ToadletContextClosedException, IOException {
String extrasNoMime = extras; // extras will not include MIME
type to start with - REDFLAG maybe it should be an array
if(requestedMimeType != null) {
if(mimeType == null ||
!requestedMimeType.equals(mimeType)) {
@@ -91,6 +91,7 @@
}
mimeType = requestedMimeType;
}
+ long size = data.size();
long now = System.currentTimeMillis();
boolean force = false;
@@ -183,7 +184,8 @@
} catch (UnsafeContentTypeException e) {
HTMLNode pageNode =
context.getPageMaker().getPageNode(l10n("dangerousContentTitle"), context);
HTMLNode contentNode =
context.getPageMaker().getContentNode(pageNode);
-
+ HTMLNode list = contentNode.addChild("li");
+ writeSizeAndMIME(list, size, mimeType, true);
HTMLNode infobox = contentNode.addChild("div", "class",
"infobox infobox-alert");
infobox.addChild("div", "class", "infobox-header",
e.getRawTitle());
HTMLNode infoboxContent = infobox.addChild("div",
"class", "infobox-content");
@@ -205,6 +207,17 @@
L10n.addL10nSubstitution(option,
"FProxyToadlet.backToReferrer", new String[] { "link", "/link" },
new String[] { "<a
href=\""+HTMLEncoder.encode(referrer)+"\">", "</a>" });
}
+ if(ctx.isAllowedFullAccess()) {
+ option = optionList.addChild("li");
+ HTMLNode optionForm = ctx.addFormChild(option,
"/queue/", "tooBigQueueForm");
+ optionForm.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "hidden", "key", key.toString() });
+ optionForm.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "hidden", "return-type", "disk" });
+ optionForm.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "hidden", "persistence", "forever" });
+ if (mimeType != null) {
+ optionForm.addChild("input", new
String[] { "type", "name", "value" }, new String[] { "hidden", "type", mimeType
});
+ }
+ optionForm.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "submit", "download",
l10n("downloadInBackgroundToDisk") });
+ }
option = optionList.addChild("li");
L10n.addL10nSubstitution(option,
"FProxyToadlet.backToFProxy", new String[] { "link", "/link" },
new String[] { "<a href=\"/\">", "</a>"
});
@@ -382,7 +395,7 @@
String referer = sanitizeReferer(ctx);
- handleDownload(ctx, data, ctx.getBucketFactory(),
mimeType, requestedMimeType, httprequest.getParam("force", null),
httprequest.isParameterSet("forcedownload"), "/", key, maxSize != MAX_LENGTH ?
"&max-size="+maxSize : "", referer);
+ handleDownload(ctx, data, ctx.getBucketFactory(),
mimeType, requestedMimeType, httprequest.getParam("force", null),
httprequest.isParameterSet("forcedownload"), "/", key, maxSize != MAX_LENGTH ?
"&max-size="+maxSize : "", referer, true, ctx);
} catch (FetchException e) {
String msg = e.getMessage();
@@ -491,26 +504,31 @@
}
}
- private String writeSizeAndMIME(HTMLNode fileInformationList,
FetchException e) {
+ private static String writeSizeAndMIME(HTMLNode fileInformationList,
FetchException e) {
boolean finalized = e.finalizedSize();
- if(e.expectedSize > 0) {
+ String mime = e.getExpectedMimeType();
+ long size = e.expectedSize;
+ writeSizeAndMIME(fileInformationList, size, mime, finalized);
+ return mime;
+ }
+
+ private static void writeSizeAndMIME(HTMLNode fileInformationList, long
size, String mime, boolean finalized) {
+ if(size > 0) {
if (finalized) {
- fileInformationList.addChild("li",
(l10n("sizeLabel") + ' ') + SizeUtil.formatSize(e.expectedSize));
+ fileInformationList.addChild("li",
(l10n("sizeLabel") + ' ') + SizeUtil.formatSize(size));
} else {
- fileInformationList.addChild("li",
(l10n("sizeLabel") + ' ')+ SizeUtil.formatSize(e.expectedSize) +
l10n("mayChange"));
+ fileInformationList.addChild("li",
(l10n("sizeLabel") + ' ')+ SizeUtil.formatSize(size) + l10n("mayChange"));
}
} else {
fileInformationList.addChild("li", l10n("sizeUnknown"));
}
- String mime = e.getExpectedMimeType();
if(mime != null) {
fileInformationList.addChild("li",
L10n.getString("FProxyToadlet."+(finalized ? "mimeType" : "expectedMimeType"),
new String[] { "mime" }, new String[] { mime }));;
} else {
fileInformationList.addChild("li",
l10n("unknownMIMEType"));
}
- return mime;
}
-
+
private String l10n(String key, String pattern, String value) {
return L10n.getString("FProxyToadlet."+key, new String[] {
pattern }, new String[] { value });
}
Modified: trunk/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2007-12-23
21:10:17 UTC (rev 16807)
+++ trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2007-12-24
12:35:18 UTC (rev 16808)
@@ -353,7 +353,7 @@
String mimeType =
clientGet.getMIMEType();
String
requestedMimeType = request.getParam("type", null);
String forceString =
request.getParam("force");
-
FProxyToadlet.handleDownload(ctx, data, ctx.getBucketFactory(), mimeType,
requestedMimeType, forceString, request.isParameterSet("forcedownload"),
"/queue/", key, "", "/queue/");
+
FProxyToadlet.handleDownload(ctx, data, ctx.getBucketFactory(), mimeType,
requestedMimeType, forceString, request.isParameterSet("forcedownload"),
"/queue/", key, "", "/queue/", false, ctx);
return;
}
}