[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [exonerator/master] Start using a JSP to prepare moving to metrics-web.



commit 2df185357b580cfda302e4679637a33e9083895d
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Fri Aug 18 14:17:54 2017 +0200

    Start using a JSP to prepare moving to metrics-web.
---
 build.xml                                          |   3 +-
 .../torproject/exonerator/ExoneraTorServlet.java   | 114 ++++++---------------
 src/main/resources/ExoneraTor.properties           |   2 -
 src/main/resources/ExoneraTor_de.properties        |   2 -
 src/main/resources/ExoneraTor_fr.properties        |   2 -
 src/main/resources/ExoneraTor_ro.properties        |   2 -
 src/main/resources/ExoneraTor_sv.properties        |   2 -
 src/main/webapp/WEB-INF/bottom.jsp                 |  12 +++
 src/main/webapp/WEB-INF/index.jsp                  |   4 +
 src/main/webapp/WEB-INF/top.jsp                    |  25 +++++
 10 files changed, 75 insertions(+), 93 deletions(-)

diff --git a/build.xml b/build.xml
index eb39e7e..4e05077 100644
--- a/build.xml
+++ b/build.xml
@@ -103,8 +103,7 @@
           depends="compile">
     <war destfile="${warfile}"
          webxml="${webxmlfile}">
-      <fileset dir="${webapp}" includes="css/*"/>
-      <fileset dir="${webapp}" includes="images/*"/>
+      <fileset dir="${webapp}" includes="css/* images/* WEB-INF/*"/>
       <lib dir="${libs}">
         <include name="commons-codec-1.10.jar"/>
         <include name="commons-lang-2.6.jar"/>
diff --git a/src/main/java/org/torproject/exonerator/ExoneraTorServlet.java b/src/main/java/org/torproject/exonerator/ExoneraTorServlet.java
index 1fb7073..749becc 100644
--- a/src/main/java/org/torproject/exonerator/ExoneraTorServlet.java
+++ b/src/main/java/org/torproject/exonerator/ExoneraTorServlet.java
@@ -9,6 +9,7 @@ import org.apache.commons.lang.StringEscapeUtils;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.ParseException;
@@ -143,7 +144,8 @@ public class ExoneraTorServlet extends HttpServlet {
         Locale.forLanguageTag(langStr));
 
     /* Start writing response. */
-    PrintWriter out = response.getWriter();
+    StringWriter so = new StringWriter();
+    PrintWriter out = new PrintWriter(so);
     this.writeHeader(out, rb, langStr);
 
     /* Write form. */
@@ -161,39 +163,31 @@ public class ExoneraTorServlet extends HttpServlet {
      * This is the start page. */
     if ("".equals(relayIp) && "".equals(timestampStr)) {
       this.writeFooter(out, rb, null, null);
-      return;
-    }
 
     /* If we were unable to connect to the database, write an error message. */
-    if (!successfullyConnectedToDatabase) {
+    } else if (!successfullyConnectedToDatabase) {
       this.writeSummaryUnableToConnectToDatabase(out, rb);
       this.writeFooter(out, rb, null, null);
-      return;
-    }
 
     /* Similarly, if we found the database to be empty, write an error message,
      * too. */
-    if (null == firstDate || null == lastDate) {
+    } else if (null == firstDate || null == lastDate) {
       this.writeSummaryNoData(out, rb);
       this.writeFooter(out, rb, null, null);
-      return;
-    }
 
     /* If either parameter is empty, print summary with warning message
      * and exit. */
-    if ("".equals(relayIp) || "".equals(timestampStr)) {
+    } else if ("".equals(relayIp) || "".equals(timestampStr)) {
       if ("".equals(relayIp)) {
         writeSummaryNoIp(out, rb);
       } else {
         writeSummaryNoTimestamp(out, rb);
       }
       this.writeFooter(out, rb, null, null);
-      return;
-    }
 
     /* If there's a user error, print summary with exit message and
      * exit. */
-    if (relayIpHasError || timestampHasError || timestampOutOfRange) {
+    } else if (relayIpHasError || timestampHasError || timestampOutOfRange) {
       if (relayIpHasError) {
         this.writeSummaryInvalidIp(out, rb, ipParameter);
       } else if (timestampHasError) {
@@ -203,17 +197,13 @@ public class ExoneraTorServlet extends HttpServlet {
             firstDate, lastDate);
       }
       this.writeFooter(out, rb, relayIp, timestampStr);
-      return;
-    }
 
-    if (noRelevantConsensuses) {
+    } else if (noRelevantConsensuses) {
       this.writeSummaryNoDataForThisInterval(out, rb);
       this.writeFooter(out, rb, relayIp, timestampStr);
-      return;
-    }
 
     /* Print out result. */
-    if (!statusEntries.isEmpty()) {
+    } else if (!statusEntries.isEmpty()) {
       this.writeSummaryPositive(out, rb, relayIp, timestampStr);
       this.writeTechnicalDetails(out, rb, relayIp, timestampStr,
           statusEntries);
@@ -228,6 +218,12 @@ public class ExoneraTorServlet extends HttpServlet {
     this.writePermanentLink(out, rb, relayIp, timestampStr, langStr);
 
     this.writeFooter(out, rb, relayIp, timestampStr);
+
+    /* Forward to the JSP that adds header and footer. */
+    request.setAttribute("lang", langStr);
+    request.setAttribute("body", so.toString());
+    request.getRequestDispatcher("WEB-INF/index.jsp").forward(request,
+        response);
   }
 
   /* Helper methods for handling the request. */
@@ -339,38 +335,7 @@ public class ExoneraTorServlet extends HttpServlet {
 
   private void writeHeader(PrintWriter out, ResourceBundle rb, String langStr)
       throws IOException {
-    out.printf("<!DOCTYPE html>\n"
-        + "<html lang=\"%s\">\n"
-        + "  <head>\n"
-        + "    <meta charset=\"utf-8\">\n"
-        + "    <meta http-equiv=\"X-UA-Compatible\" "
-          + "content=\"IE=edge\">\n"
-        + "    <meta name=\"viewport\" content=\"width=device-width, "
-          + "initial-scale=1\">\n"
-        + "    <title>ExoneraTor</title>\n"
-        + "    <link rel=\"stylesheet\" href=\"css/bootstrap.min.css\">\n"
-        + "    <link rel=\"stylesheet\" href=\"css/exonerator.css\">\n"
-        + "    <link href=\"images/favicon.ico\" type=\"image/x-icon\" "
-          + "rel=\"icon\">\n"
-        + "  </head>\n"
-        + "  <body>\n"
-        + "    <div class=\"container\">\n"
-        + "      <div class=\"row\">\n"
-        + "        <div class=\"col-xs-12\">\n"
-        + "          <div class=\"page-header\">\n"
-        + "            <h1>\n"
-        + "              <div class=\"text-center\">\n"
-        + "                <a href=\"/?lang=%<s\">"
-          + "<img src=\"images/exonerator-logo.png\" "
-          + "width=\"334\" height=\"252\" alt=\"ExoneraTor logo\">"
-          + "<img src=\"images/exonerator-wordmark.png\" width=\"428\" "
-          + "height=\"63\" alt=\"ExoneraTor wordmark\"></a>\n"
-        + "              </div><!-- text-center -->\n"
-        + "            </h1>\n"
-        + "          </div><!-- page-header -->\n"
-        + "        </div><!-- col -->\n"
-        + "      </div><!-- row -->\n",
-        langStr);
+    out.printf("    <div class=\"container\">\n");
   }
 
   private void writeForm(PrintWriter out, ResourceBundle rb,
@@ -663,13 +628,12 @@ public class ExoneraTorServlet extends HttpServlet {
   private void writeFooter(PrintWriter out, ResourceBundle rb, String relayIp,
       String timestampStr) throws IOException {
     out.printf("    </div><!-- container -->\n"
-        + "    <div class=\"footer\">\n"
-        + "      <div class=\"container\">\n"
-        + "        <div class=\"row\">\n"
-        + "          <div class=\"col-xs-6\">\n"
-        + "            <h3>%s</h3>\n"
-        + "            <p class=\"small\">%s</p>\n"
-        + "          </div><!-- col -->\n",
+        + "    <div class=\"container\">\n"
+        + "      <div class=\"row\">\n"
+        + "        <div class=\"col-xs-6\">\n"
+        + "          <h3>%s</h3>\n"
+        + "          <p class=\"small\">%s</p>\n"
+        + "        </div><!-- col -->\n",
         rb.getString("footer.abouttor.heading"),
         String.format(rb.getString("footer.abouttor.body.text"),
             "<a href=\"https://www.torproject.org/about/";
@@ -679,16 +643,16 @@ public class ExoneraTorServlet extends HttpServlet {
             + rb.getString("footer.abouttor.body.link2") + "</a>",
             "<a href=\"https://www.torproject.org/about/contact\";>"
             + rb.getString("footer.abouttor.body.link3") + "</a>"));
-    out.printf("          <div class=\"col-xs-6\">\n"
-        + "            <h3>%s</h3>\n"
-        + "            <p class=\"small\">%s</p>\n"
-        + "          </div><!-- col -->\n"
-        + "        </div><!-- row -->\n",
+    out.printf("        <div class=\"col-xs-6\">\n"
+        + "          <h3>%s</h3>\n"
+        + "          <p class=\"small\">%s</p>\n"
+        + "        </div><!-- col -->\n"
+        + "      </div><!-- row -->\n",
         rb.getString("footer.aboutexonerator.heading"),
         rb.getString("footer.aboutexonerator.body"));
-    out.printf("        <div class=\"row\">\n"
-        + "          <div class=\"col-xs-12\">\n"
-        + "            <p class=\"text-center small\">%s",
+    out.printf("      <div class=\"row\">\n"
+        + "        <div class=\"col-xs-12\">\n"
+        + "          <p class=\"text-center small\">%s",
         rb.getString("footer.language.text"));
     for (Map.Entry<String, String> entry
         : this.availableLanguageNames.entrySet()) {
@@ -701,21 +665,9 @@ public class ExoneraTorServlet extends HttpServlet {
       }
     }
     out.printf("</p>\n"
-        + "          </div><!-- col -->\n"
-        + "        </div><!-- row -->\n"
-        + "        <div class=\"row\">\n"
-        + "          <div class=\"col-xs-12\">\n"
-        + "            <p class=\"text-center small\">%s</p>\n"
-        + "          </div><!-- col -->\n"
-        + "        </div><!-- row -->\n"
-        + "      </div><!-- container -->\n"
-        + "    </div><!-- footer -->\n"
-        + "  </body>\n"
-        + "</html>\n",
-        String.format(rb.getString("footer.trademark.text"),
-            "<a href=\"https://www.torproject.org/docs/";
-            + "trademark-faq.html.en\">"
-            + rb.getString("footer.trademark.link") + "</a>"));
+        + "        </div><!-- col -->\n"
+        + "      </div><!-- row -->\n"
+        + "    </div><!-- container -->\n");
     out.close();
   }
 }
diff --git a/src/main/resources/ExoneraTor.properties b/src/main/resources/ExoneraTor.properties
index 03b8489..8488623 100644
--- a/src/main/resources/ExoneraTor.properties
+++ b/src/main/resources/ExoneraTor.properties
@@ -47,8 +47,6 @@ footer.abouttor.body.link2=learn more about Tor
 footer.abouttor.body.link3=contact The Tor Project, Inc.
 footer.aboutexonerator.heading=About ExoneraTor
 footer.aboutexonerator.body=The ExoneraTor service maintains a database of IP addresses that have been part of the Tor network.&nbsp; It answers the question whether there was a Tor relay running on a given IP address on a given date.&nbsp; ExoneraTor may store more than one IP address per relay if relays use a different IP address for exiting to the Internet than for registering in the Tor network, and it stores whether a relay permitted transit of Tor traffic to the open Internet at that time.
-footer.trademark.text="Tor" and the "Onion Logo" are %s of The Tor Project, Inc.
-footer.trademark.link=registered trademarks
 footer.language.name=English
 footer.language.text=This page is also available in the following languages:
 
diff --git a/src/main/resources/ExoneraTor_de.properties b/src/main/resources/ExoneraTor_de.properties
index ed37730..d830e31 100644
--- a/src/main/resources/ExoneraTor_de.properties
+++ b/src/main/resources/ExoneraTor_de.properties
@@ -47,8 +47,6 @@ footer.abouttor.body.link2=hier
 footer.abouttor.body.link3=Fragen
 footer.aboutexonerator.heading=\u00dcber ExoneraTor
 footer.aboutexonerator.body=Der ExoneraTor-Dienst basiert auf einer Datenbank von IP-Adressen, die Teil des Tor-Netzwerks sind oder waren. Dieser Dienst beantwortet die Frage, ob es an einem bestimmten Tag einen Tor-Server mit einer bestimmten IP-Adresse gegeben hat. ExoneraTor kann in einigen F\u00e4llen mehr als nur eine IP-Adresse pro Tor-Server ausgeben, falls ein Tor-Server verschiedene IP-Adressen f\u00fcr ausgehende Verbindungen und die Registrierung im Tor-Netzwerk verwendet hat. ExoneraTor speichert au\u00dferdem, ob ein Tor-Server Verbindungen ins offene Internet zugelassen hat oder nicht.
-footer.trademark.text="Tor" und das "Onion Logo" sind %s von The Tor Project, Inc.
-footer.trademark.link=eingetragene Warenzeichen
 footer.language.name=Deutsch
 footer.language.text=Diese Seite gibt es auch in den folgenden Sprachen:
 
diff --git a/src/main/resources/ExoneraTor_fr.properties b/src/main/resources/ExoneraTor_fr.properties
index 09c8e65..70d4d2f 100644
--- a/src/main/resources/ExoneraTor_fr.properties
+++ b/src/main/resources/ExoneraTor_fr.properties
@@ -47,8 +47,6 @@ footer.abouttor.body.link2=renseigner d'avantage au sujet de Tor
 footer.abouttor.body.link3=contacter \u00ab\u00a0The Tor Project, Inc.\u00a0\u00bb
 footer.aboutexonerator.heading=\u00c0 propos d'ExoneraTor
 footer.aboutexonerator.body=Le service ExoneraTor g\u00e8re une base de donn\u00e9es d'adresses IP qui ont fait partie du r\u00e9seau Tor. Il permet de savoir si un relais Tor fonctionnait pour une adresse IP donn\u00e9e \u00e0 une date pr\u00e9cise. ExoneraTor peut enregistrer plus d'une adresse IP par relais si ces derniers utilisent une adresse IP diff\u00e9rente pour se connecter \u00e0 Internet de celle utilis\u00e9e pour s'enregistrer sur le r\u00e9seau Tor. ExoneraTor enregistre \u00e9galement les dates et heures auxquelles un relais a permis de faire transiter du trafic en provenance de Tor vers Internet.
-footer.trademark.text=\u00ab\u00a0Tor\u00a0\u00bb et le \u00ab\u00a0logo Oignon\u00a0\u00bb sont des %s de \u00ab\u00a0The Tor Project, Inc.\u00a0\u00bb
-footer.trademark.link=marques d\u00e9pos\u00e9es
 footer.language.name=fran\u00e7ais
 footer.language.text=Cette page est aussi disponible dans les langues suivantes :
 
diff --git a/src/main/resources/ExoneraTor_ro.properties b/src/main/resources/ExoneraTor_ro.properties
index 7ded64e..3663c06 100644
--- a/src/main/resources/ExoneraTor_ro.properties
+++ b/src/main/resources/ExoneraTor_ro.properties
@@ -47,8 +47,6 @@ footer.abouttor.body.link2=Afla\u021bi mai multe despre Tor
 footer.abouttor.body.link3=contacta\u021bi The Tor Project, Inc.
 footer.aboutexonerator.heading=Despre ExoneraTor
 footer.aboutexonerator.body=Serviciul ExoneraTor opereaz\u0103 o baz\u0103 de date de adrese IP care au fost parte din re\u021belaua Tor la un anumit moment.&nbsp; Acest serviciu r\u0103spunde la \u00eentrebarea dac\u0103 a existat un nod Tor care a func\u021bionat pe o anumit\u0103 adres\u0103 IP la o anumit\u0103 dat\u0103.&nbsp;  ExoneraTor poate stoca mai mult de o adresa IP per nod dac\u0103 nodurile folosesc o alt\u0103 adres\u0103 IP pentru a ie\u0219i pe internet dec\u00e2t cea folosit\u0103 pentru \u00eenregistrarea \u00een re\u021beaua Tor \u0219i stocheaz\u0103 dac\u0103 un nod a permis tranzitarea de trafic din re\u021beaua Tor catre internetul public la acea dat\u0103.
-footer.trademark.text="Tor" \u0219i "Onion Logo" sunt %s The Tor Project, Inc.
-footer.trademark.link=Marci \u00eenregistrate
 footer.language.name=rom\u00e2n\u0103
 footer.language.text=Aceast\u0103 pagin\u0103 mai este disponibil\u0103 \u00een urm\u0103toarele limbi:
 
diff --git a/src/main/resources/ExoneraTor_sv.properties b/src/main/resources/ExoneraTor_sv.properties
index 5979e4d..277a5b8 100644
--- a/src/main/resources/ExoneraTor_sv.properties
+++ b/src/main/resources/ExoneraTor_sv.properties
@@ -47,8 +47,6 @@ footer.abouttor.body.link2=l\u00e4sa p\u00e5 om Tor
 footer.abouttor.body.link3=kontakta Tor-projektet
 footer.aboutexonerator.heading=Om ExoneraTor
 footer.aboutexonerator.body=Tj\u00e4nsten ExoneraTor uppr\u00e4tth\u00e5ller en databas \u00f6ver IP-adresser som har varit en del av Tor-n\u00e4tverket. Den ger svar p\u00e5 fr\u00e5gan om det var ett Tor-rel\u00e4 som anv\u00e4nde en viss IP-adress vid ett givet datum. ExoneraTor kan komma att lagra fler \u00e4n en IP-adress per rel\u00e4 f\u00f6r rel\u00e4n som anv\u00e4nder en annan IP-adress f\u00f6r att ansluta till internet \u00e4n den som anv\u00e4ndes f\u00f6r att registrera sig i Tor-n\u00e4tverket. Huruvida ett rel\u00e4 har till\u00e5tit Tor-trafik ut mot internet vid tidpunkten eller ej lagras ocks\u00e5.
-footer.trademark.text="Tor" och "Onion-loggan" \u00e4r %s av The Tor Project, Inc.
-footer.trademark.link=registrerade varum\u00e4rken
 footer.language.name=svenska
 footer.language.text=Denna sida finns \u00e4ven p\u00e5 f\u00f6ljande spr\u00e5k:
 
diff --git a/src/main/webapp/WEB-INF/bottom.jsp b/src/main/webapp/WEB-INF/bottom.jsp
new file mode 100644
index 0000000..edfb99b
--- /dev/null
+++ b/src/main/webapp/WEB-INF/bottom.jsp
@@ -0,0 +1,12 @@
+    <div class="footer">
+      <div class="container">
+        <div class="row">
+          <div class="col-xs-12">
+            <p class="text-center small">"Tor" and the "Onion Logo" are <a href="https://www.torproject.org/docs/trademark-faq.html.en";>registered trademarks</a> of The Tor Project, Inc.</p>
+          </div><!-- col -->
+        </div><!-- row -->
+      </div><!-- container -->
+    </div><!-- footer -->
+  </body>
+</html>
+
diff --git a/src/main/webapp/WEB-INF/index.jsp b/src/main/webapp/WEB-INF/index.jsp
new file mode 100644
index 0000000..a8c86c6
--- /dev/null
+++ b/src/main/webapp/WEB-INF/index.jsp
@@ -0,0 +1,4 @@
+<jsp:include page="top.jsp"/>
+${body}
+<jsp:include page="bottom.jsp"/>
+
diff --git a/src/main/webapp/WEB-INF/top.jsp b/src/main/webapp/WEB-INF/top.jsp
new file mode 100644
index 0000000..481996b
--- /dev/null
+++ b/src/main/webapp/WEB-INF/top.jsp
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="${lang}">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <title>ExoneraTor</title>
+    <link rel="stylesheet" href="css/bootstrap.min.css">
+    <link rel="stylesheet" href="css/exonerator.css">
+    <link href="images/favicon.ico" type="image/x-icon" rel="icon">
+  </head>
+  <body>
+    <div class="container">
+      <div class="row">
+        <div class="col-xs-12">
+          <div class="page-header">
+            <h1>
+              <div class="text-center">
+                <a href="/?lang=${lang}"><img src="images/exonerator-logo.png" width="334" height="252" alt="ExoneraTor logo"><img src="images/exonerator-wordmark.png" width="428" height="63" alt="ExoneraTor wordmark"></a>
+              </div><!-- text-center -->
+            </h1>
+          </div><!-- page-header -->
+        </div><!-- col -->
+      </div><!-- row -->
+    </div><!-- container -->



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits