if (type == null) {
type = "text/plain";
}
ClientMetadata contentType = new ClientMetadata(type);
RandomAccessBucket bucket = request.getPart("filename");
PageNode page = ctx.getPageMaker().getPageNode(l10n("insertedTitle"), ctx);
HTMLNode pageNode = page.outer;
HTMLNode contentNode = page.content;
HTMLNode content;
String filenameHint = null;
if (key.getKeyType().equals("CHK")) {
String[] metas = key.getAllMetaStrings();
if ((metas != null) && (metas.length > 1)) {
filenameHint = metas[0];
}
}
InsertBlock block = new InsertBlock(bucket, contentType, key);
try {
key = this.insert(block, filenameHint, false);
content = ctx.getPageMaker().getInfobox("infobox-success", l10n("insertSucceededTitle"), contentNode, "successful-insert", false);
String u = key.toString();
NodeL10n.getBase().addL10nSubstitution(content, "WelcomeToadlet.keyInsertedSuccessfullyWithKeyAndName",
new String[]{"link", "name"},
new HTMLNode[] { HTMLNode.link("/"+u), HTMLNode.text(u) });
} catch (InsertException e) {
content = ctx.getPageMaker().getInfobox("infobox-error", l10n("insertFailedTitle"), contentNode, "failed-insert", false);
content.addChild("#", l10n("insertFailedWithMessage", "message", e.getMessage()));
content.addChild("br");
if (e.uri != null) {
content.addChild("#", l10n("uriWouldHaveBeen", "uri", e.uri.toString()));
}
InsertExceptionMode mode = e.getMode();
if ((mode == InsertExceptionMode.FATAL_ERRORS_IN_BLOCKS) || (mode == InsertExceptionMode.TOO_MANY_RETRIES_IN_BLOCKS)) {
content.addChild("br"); /* TODO */
content.addChild("#", l10n("splitfileErrorLabel"));
content.addChild("pre", e.errorCodes.toVerboseString());
}
}
content.addChild("br");
addHomepageLink(content);
writeHTMLReply(ctx, 200, "OK", pageNode.generate());
request.freeParts();
bucket.free();
} else if (request.isPartSet("exit")) {
PageNode page = ctx.getPageMaker().getPageNode(l10n("shutdownConfirmTitle"), ctx);
HTMLNode pageNode = page.outer;
HTMLNode contentNode = page.content;
HTMLNode content = ctx.getPageMaker().getInfobox("infobox-query", l10n("shutdownConfirmTitle"), contentNode, "shutdown-confirm", true);