source: apps/routerconsole/jsp/flags.jsp @ da9c06e

Last change on this file since da9c06e was da9c06e, checked in by str4d <str4d@…>, 3 years ago

/configui: Use larger flags for language selection

  • Property mode set to 100644
File size: 2.6 KB
Line 
1<%
2/*
3 * USE CAUTION WHEN EDITING
4 * Trailing whitespace OR NEWLINE on the last line will cause
5 * IllegalStateExceptions !!!
6 *
7 * Do not tag this file for translation.
8 */
9
10/**
11 *  flags.jsp?c=de => icons/flags/de.png
12 *  flags.jsp?c=de&s=48 => icons/flags48x48/de.png
13 *  with headers set so the browser caches.
14 */
15String c = request.getParameter("c");
16if (c != null &&
17    (c.length() == 2 || c.length() == 7) &&
18    c.replaceAll("[a-z0-9_]", "").length() == 0) {
19    String flagSet = "flags";
20    String s = request.getParameter("s");
21    if ("48".equals(s)) {
22        flagSet = "flags48x48";
23    }
24    java.io.OutputStream cout = response.getOutputStream();
25    String base = net.i2p.I2PAppContext.getGlobalContext().getBaseDir().getAbsolutePath();
26    String file = "docs" + java.io.File.separatorChar + "icons" + java.io.File.separatorChar +
27                  flagSet + java.io.File.separatorChar + c + ".png";
28    java.io.File ffile = new java.io.File(base, file);
29    long lastmod = ffile.lastModified();
30    if (lastmod > 0) {
31        long iflast = request.getDateHeader("If-Modified-Since");
32        // iflast is -1 if not present; round down file time
33        if (iflast >= ((lastmod / 1000) * 1000)) {
34            response.sendError(304, "Not Modified");
35            return;
36        }
37        response.setDateHeader("Last-Modified", lastmod);
38        // cache for a day
39        response.setDateHeader("Expires", net.i2p.I2PAppContext.getGlobalContext().clock().now() + 86400000l);
40        response.setHeader("Cache-Control", "public, max-age=604800");
41        response.setHeader("X-Content-Type-Options", "nosniff");
42    }
43    long length = ffile.length();
44    if (length > 0)
45        response.setHeader("Content-Length", Long.toString(length));
46    response.setContentType("image/png");
47    try {
48        net.i2p.util.FileUtil.readFile(file, base, cout);
49    } catch (java.io.IOException ioe) {
50        // prevent 'Committed' IllegalStateException from Jetty
51        if (!response.isCommitted()) {
52            response.sendError(403, ioe.toString());
53        }  else {
54            // not an error, happens when the browser closes the stream
55            net.i2p.I2PAppContext.getGlobalContext().logManager().getLog(getClass()).warn("Error serving flags/" + c + ".png", ioe);
56            // Jetty doesn't log this
57            throw ioe;
58        }
59    }
60} else {
61    /*
62     *  Send a 403 instead of a 404, because the server sends error.jsp
63     *  for 404 errors, complete with the summary bar, which would be
64     *  a huge load for a page full of flags if the user didn't have the
65     *  flags directory for some reason.
66     */
67    response.sendError(403, "No flag specified");
68}
69%>
Note: See TracBrowser for help on using the repository browser.