{
type = "application/x-zip"; //$NON-NLS-2$
}
response.setContentType(type);
final ZipConfigurationWriter pw = ZipConfigurationWriter.create(response.getOutputStream());
printConfigurationInventory(pw, null, handler);
pw.finish();
}
else if (request.getPathInfo().endsWith(".nfo"))
{
if (handler == null)
{
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
response.setContentType("text/html; charset=utf-8");
final HtmlConfigurationWriter pw = new HtmlConfigurationWriter(response.getWriter());
pw.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
pw.println(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
pw.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
pw.println("<head><title>dummy</title></head><body><div>");
if (handler.supports(Format.HTML))
{
handler.print(pw, Format.HTML, false);
}
else if (handler.supports(Format.TEXT))
{
pw.enableFilter(true);
handler.print(pw, Format.TEXT, false);
pw.enableFilter(false);
}
else
{
pw.enableFilter(true);
handler.print(pw, Format.JSON, false);
pw.enableFilter(false);
}
pw.println("</div></body></html>");
return;
}
else if (request.getPathInfo().endsWith(".json"))
{
if (handler == null)
{
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
response.setContentType("application/json"); //$NON-NLS-1$
response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
final JSONConfigurationWriter jcw = new JSONConfigurationWriter(response.getWriter());
final Format format;
if (handler.supports(Format.JSON))
{
format = Format.JSON;
}
else
{
format = Format.TEXT;
jcw.startJSONWrapper();
}
printConfigurationInventory(jcw, format, handler);
jcw.endJSONWrapper();
jcw.flush();
}
else
{
if (handler == null)
{
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
final HtmlConfigurationWriter pw = new HtmlConfigurationWriter(response.getWriter());
pw.println("<script type=\"text/javascript\">");
pw.println("// <![CDATA[");
pw.println("function pad(value) { if ( value < 10 ) { return '0' + value;} return '' + value;}");
pw.println("function downloadDump(ext, full) {");
pw.println(" if (full) {");
pw.println(" var now = new Date();");
pw.println(" var name = \"configuration-status-\" + now.getUTCFullYear() + pad(now.getUTCMonth() + 1) + pad(now.getUTCDate()) + \"-\" + pad(now.getUTCHours()) + pad(now.getUTCMinutes()) + pad(now.getUTCSeconds()) + \".\";");
pw.println(" location.href = location.href + \"/\" + name + ext;");
pw.println(" } else {");
pw.println(" location.href = location.href + '.' + ext;");
pw.println(" }");
pw.println("}");
pw.println("$(document).ready(function() {");
pw.println(" $('.downloadTxt').click(function() { downloadDump('txt', false)});");
pw.println(" $('.downloadJson').click(function() { downloadDump('json', false)});");
pw.println(" $('.downloadZip').click(function() { downloadDump('zip', false)});");
pw.println(" $('.downloadFullZip').click(function() { downloadDump('zip', true)});");
pw.println(" $('.downloadFullTxt').click(function() { downloadDump('txt', true)});");
pw.println("});");
pw.println("// ]]>");
pw.println("</script>");
pw.println("<br/><p class=\"statline\">");
pw.print("Date: ");
pw.println(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.US).format(new Date()));
pw.print("<button type=\"button\" class=\"downloadFullZip\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download Full Zip</button>");
pw.print("<button type=\"button\" class=\"downloadFullTxt\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download Full Text</button>");
if (handler.supports(Format.JSON))
{
pw.print("<button type=\"button\" class=\"downloadJson\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download As JSON</button>");
}
pw.print("<button type=\"button\" class=\"downloadZip\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download As Zip</button>");
if (handler.supports(Format.TEXT))
{
pw.print("<button type=\"button\" class=\"downloadTxt\" style=\"float: right; margin-right: 30px; margin-top: 5px;\">Download As Text</button>");
}
pw.println("<br/> </p>"); // status line
pw.print("<div>");
final boolean filter;
final Format format;
if (handler.supports(Format.HTML))
{
filter = false;
format = Format.HTML;
}
else if (handler.supports(Format.TEXT))
{
// prefer TEXT of JSON if available
filter = true;
format = Format.TEXT;
}
else if (handler.supports(Format.JSON))
{
filter = true;
format = Format.JSON;
}
else
{
// fallback to TEXT (if unknown format)
filter = true;
format = Format.TEXT;
}
pw.enableFilter(filter);
handler.print(pw, format, false);
pw.enableFilter(false);
pw.print("</div>");
}
}