]> WPIA git - gigi.git/commitdiff
additional lang-cleanup
authorFelix Dörre <felix@dogcraft.de>
Thu, 19 May 2016 12:46:08 +0000 (14:46 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sun, 29 May 2016 00:16:41 +0000 (02:16 +0200)
Change-Id: Iaa547ef712d05f53455a8b4805eff41686c13dd8

18 files changed:
src/org/cacert/gigi/Gigi.java
src/org/cacert/gigi/dbObjects/Certificate.java
src/org/cacert/gigi/dbObjects/Digest.java
src/org/cacert/gigi/dbObjects/Group.java
src/org/cacert/gigi/output/CertificateIterable.java
src/org/cacert/gigi/output/HashAlgorithms.java
src/org/cacert/gigi/output/template/ForeachStatement.java
src/org/cacert/gigi/output/template/IfStatement.java
src/org/cacert/gigi/output/template/OutputVariableCommand.java
src/org/cacert/gigi/output/template/SprintfCommand.java
src/org/cacert/gigi/output/template/Template.java
src/org/cacert/gigi/output/template/TemplateBlock.java
src/org/cacert/gigi/output/template/Translatable.java [new file with mode: 0644]
src/org/cacert/gigi/output/template/TranslateCommand.java
src/org/cacert/gigi/pages/LoginPage.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
tests/org/cacert/gigi/TestCertificate.java
util-testing/org/cacert/gigi/DevelLauncher.java

index 0570416d78ef1cad08f1091642c08ca0ad9d199f..717865454ee4bba7a39001bd0467d1d74e1ae3f8 100644 (file)
@@ -393,7 +393,7 @@ public final class Gigi extends HttpServlet {
             vars.put("content", content);
             if (currentAuthContext != null) {
                 // TODO maybe move this information into the AuthContext object
-                vars.put("loginMethod", lang.getTranslation((String) req.getSession().getAttribute(LOGIN_METHOD)));
+                vars.put("loginMethod", req.getSession().getAttribute(LOGIN_METHOD));
                 vars.put("authContext", currentAuthContext);
 
             }
index 8e66c7f30c3d98c3b123ef9f6f5c73114aa95905..541272bdae1fb43a7e9b60186aaed84054309447 100644 (file)
@@ -19,6 +19,8 @@ import java.util.Map.Entry;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
 import org.cacert.gigi.util.KeyStorage;
 import org.cacert.gigi.util.Notary;
 
@@ -215,25 +217,34 @@ public class Certificate implements IdCachable {
          * This certificate is not in the database, has no id and only exists as
          * this java object.
          */
-        DRAFT(),
+        DRAFT("draft"),
         /**
          * The certificate has been signed. It is stored in the database.
          * {@link Certificate#cert()} is valid.
          */
-        ISSUED(),
+        ISSUED("issued"),
 
         /**
          * The certificate has been revoked.
          */
-        REVOKED(),
+        REVOKED("revoked"),
 
         /**
          * If this certificate cannot be updated because an error happened in
          * the signer.
          */
-        ERROR();
+        ERROR("error");
 
-        private CertificateStatus() {}
+        private final Outputable name;
+
+        private CertificateStatus(String codename) {
+            this.name = new TranslateCommand(codename);
+
+        }
+
+        public Outputable getName() {
+            return name;
+        }
 
     }
 
index 01b7c5410a234a18161dc6327d60c7f4ff6b7234..59247121c5ef04c064386b40270f674efd1fe488 100644 (file)
@@ -1,15 +1,18 @@
 package org.cacert.gigi.dbObjects;
 
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
+
 public enum Digest {
-    SHA256("Currently recommended, because the other algorithms" + " might break on some older versions of the GnuTLS library" + " (older than 3.x) still shipped in Debian for example."), SHA384(null), SHA512("Highest protection against hash collision attacks of the algorithms offered here.");
+    SHA256("Currently recommended, because the other algorithms" + " might break on some older versions of the GnuTLS library" + " (older than 3.x) still shipped in Debian for example."), SHA384(""), SHA512("Highest protection against hash collision attacks of the algorithms offered here.");
 
-    private final String exp;
+    private final Outputable exp;
 
     private Digest(String explanation) {
-        exp = explanation;
+        exp = new TranslateCommand(explanation);
     }
 
-    public String getExp() {
+    public Outputable getExp() {
         return exp;
     }
 
index 296b4dfa2536639169337d622f81e81b7d71ae72..48445ffc06dac494446b30005c69d00534e95cb3 100644 (file)
@@ -2,14 +2,19 @@ package org.cacert.gigi.dbObjects;
 
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
 
 public enum Group {
     SUPPORTER("supporter"), ARBITRATOR("arbitrator"), BLOCKEDASSURER("blockedassurer"), BLOCKEDASSUREE("blockedassuree"), BLOCKEDLOGIN("blockedlogin"), BLOCKEDCERT("blockedcert"), TTP_ASSURER("ttp-assurer"), TTP_APPLICANT("ttp-applicant"), CODESIGNING("codesigning"), ORGASSURER("orgassurer"), NUCLEUS_ASSURER("nucleus-assurer");
 
     private final String dbName;
 
+    private final TranslateCommand tc;
+
     private Group(String name) {
         dbName = name;
+        tc = new TranslateCommand(name);
     }
 
     public static Group getByString(String name) {
@@ -36,4 +41,8 @@ public enum Group {
             return users;
         }
     }
+
+    public Outputable getName() {
+        return tc;
+    }
 }
index 8bfff7ef7a7c4819f92413f6619c6d6948d1cbfb..f24d7782ce060e54896feb566269d5bad318a48e 100644 (file)
@@ -26,7 +26,7 @@ public class CertificateIterable implements IterableDataset {
             return false;
         }
         Certificate c = certificates[i++];
-        vars.put("state", l.getTranslation(c.getStatus().toString().toLowerCase()));
+        vars.put("state", c.getStatus());
         vars.put("CN", c.getDistinguishedName());
         vars.put("serial", c.getSerial());
         vars.put("digest", c.getMessageDigest());
index 8e13513a822fe178d819ea9e7abbe84f364e9459..fe29d62512717f2383b826d498b5d1161bb085a8 100644 (file)
@@ -25,7 +25,7 @@ public class HashAlgorithms implements IterableDataset {
         Digest d = length[i++];
         vars.put("algorithm", d.toString());
         vars.put("name", d.toString());
-        vars.put("info", l.getTranslation(d.getExp()));
+        vars.put("info", d.getExp());
         vars.put("checked", selected == d ? " checked='checked'" : "");
         return true;
     }
index edabab774c457eabe432f2aa49f65526db694967..8c12122be098374ecb376b69b2e8aae876676191 100644 (file)
@@ -1,12 +1,13 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 
-public final class ForeachStatement implements Outputable {
+public final class ForeachStatement implements Translatable {
 
     private final String variable;
 
@@ -28,4 +29,9 @@ public final class ForeachStatement implements Outputable {
             }
         }
     }
+
+    @Override
+    public void addTranslations(Collection<String> s) {
+        body.addTranslations(s);
+    }
 }
index 0347a363db8798f3d98356fc68bbdea737c19d1f..29cfc768f2ac674706a367325ef5eb6aa90b6dea 100644 (file)
@@ -1,11 +1,12 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 
-public final class IfStatement implements Outputable {
+public final class IfStatement implements Translatable {
 
     private final String variable;
 
@@ -36,4 +37,12 @@ public final class IfStatement implements Outputable {
         }
     }
 
+    @Override
+    public void addTranslations(Collection<String> s) {
+        iftrue.addTranslations(s);
+        if (iffalse != null) {
+            iffalse.addTranslations(s);
+        }
+    }
+
 }
index b3534edca8159a022f2824b9073d42f51fb4da1b..908a0377ad419e70caf594ee4fbe3d343578f27b 100644 (file)
@@ -1,11 +1,12 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 
-public final class OutputVariableCommand implements Outputable {
+public final class OutputVariableCommand implements Translatable {
 
     private final String raw;
 
@@ -25,4 +26,7 @@ public final class OutputVariableCommand implements Outputable {
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
         Template.outputVar(out, l, vars, raw, unescaped);
     }
+
+    @Override
+    public void addTranslations(Collection<String> s) {}
 }
index 47389643995640afa854a63469abfc345b45bbf9..07a0b8cc303175ce0ac0e855d3be58ddaba24a1a 100644 (file)
@@ -1,6 +1,7 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -10,7 +11,7 @@ import java.util.regex.Pattern;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.HTMLEncoder;
 
-public final class SprintfCommand implements Outputable {
+public final class SprintfCommand implements Translatable {
 
     private final String text;
 
@@ -73,4 +74,9 @@ public final class SprintfCommand implements Outputable {
         }
         out.print(HTMLEncoder.encodeHTML(parts.substring(pos)));
     }
+
+    @Override
+    public void addTranslations(Collection<String> s) {
+        s.add(text);
+    }
 }
index 84727f25758dfd6b6f795c40c17d5064284c9331..1705159514c02846432da50e6e4da76569f41861 100644 (file)
@@ -10,6 +10,7 @@ import java.io.Reader;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.Map;
@@ -91,7 +92,7 @@ public class Template implements Outputable {
 
     private ParseResult parse(Reader r) throws IOException {
         LinkedList<String> splitted = new LinkedList<String>();
-        LinkedList<Outputable> commands = new LinkedList<Outputable>();
+        LinkedList<Translatable> commands = new LinkedList<Translatable>();
         StringBuffer buf = new StringBuffer();
         String blockType = null;
         outer:
@@ -144,14 +145,14 @@ public class Template implements Outputable {
             }
         }
         splitted.add(buf.toString());
-        return new ParseResult(new TemplateBlock(splitted.toArray(new String[splitted.size()]), commands.toArray(new Outputable[commands.size()])), blockType);
+        return new ParseResult(new TemplateBlock(splitted.toArray(new String[splitted.size()]), commands.toArray(new Translatable[commands.size()])), blockType);
     }
 
     private boolean endsWith(StringBuffer buf, String string) {
         return buf.length() >= string.length() && buf.substring(buf.length() - string.length(), buf.length()).equals(string);
     }
 
-    private Outputable parseCommand(String s2) {
+    private Translatable parseCommand(String s2) {
         if (s2.startsWith("=_")) {
             final String raw = s2.substring(2);
             if ( !s2.contains("$") && !s2.contains("!'")) {
@@ -201,4 +202,8 @@ public class Template implements Outputable {
             out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString())));
         }
     }
+
+    public void addTranslations(Collection<String> s) {
+        data.addTranslations(s);
+    }
 }
index 15ce4e5b967c23ad463cb60017e44d57979fa8b9..1e3aac0ce5317e5c556c2c102836f8910f72f7be 100644 (file)
@@ -1,17 +1,18 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 
-class TemplateBlock implements Outputable {
+class TemplateBlock implements Translatable {
 
     private String[] contents;
 
-    private Outputable[] vars;
+    private Translatable[] vars;
 
-    public TemplateBlock(String[] contents, Outputable[] vars) {
+    public TemplateBlock(String[] contents, Translatable[] vars) {
         this.contents = contents;
         this.vars = vars;
     }
@@ -26,4 +27,10 @@ class TemplateBlock implements Outputable {
         }
     }
 
+    public void addTranslations(Collection<String> s) {
+        for (Translatable t : vars) {
+            t.addTranslations(s);
+        }
+    }
+
 }
diff --git a/src/org/cacert/gigi/output/template/Translatable.java b/src/org/cacert/gigi/output/template/Translatable.java
new file mode 100644 (file)
index 0000000..b15ffb9
--- /dev/null
@@ -0,0 +1,8 @@
+package org.cacert.gigi.output.template;
+
+import java.util.Collection;
+
+public interface Translatable extends Outputable {
+
+    public void addTranslations(Collection<String> s);
+}
index 7b7014e0775feb537428ed1e2c41af8222072d5c..9da43524c6b6a67b6e7bb659ac726dde8b44d9e2 100644 (file)
@@ -1,12 +1,13 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.util.Collection;
 import java.util.Map;
 
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.util.HTMLEncoder;
 
-public final class TranslateCommand implements Outputable {
+public final class TranslateCommand implements Translatable {
 
     private final String raw;
 
@@ -22,4 +23,9 @@ public final class TranslateCommand implements Outputable {
     public String getRaw() {
         return raw;
     }
+
+    @Override
+    public void addTranslations(Collection<String> s) {
+        s.add(raw);
+    }
 }
index ba6e0eecd8f7f2055f11b303a111398c356cd1d3..23a703ef603a5ac5c80a1ec1ec0d4acada471717 100644 (file)
@@ -20,6 +20,7 @@ import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
+import org.cacert.gigi.output.template.TranslateCommand;
 import org.cacert.gigi.util.AuthorizationContext;
 import org.cacert.gigi.util.PasswordHash;
 import org.cacert.gigi.util.ServerConstants;
@@ -114,7 +115,7 @@ public class LoginPage extends Page {
                         }
                     }
                     loginSession(req, User.getById(rs.getInt(2)));
-                    req.getSession().setAttribute(LOGIN_METHOD, "Password");
+                    req.getSession().setAttribute(LOGIN_METHOD, new TranslateCommand("Password"));
                 }
             }
         }
@@ -141,7 +142,7 @@ public class LoginPage extends Page {
         loginSession(req, user);
         req.getSession().setAttribute(CERT_SERIAL, serial);
         req.getSession().setAttribute(CERT_ISSUER, x509Certificate.getIssuerDN());
-        req.getSession().setAttribute(LOGIN_METHOD, "Certificate");
+        req.getSession().setAttribute(LOGIN_METHOD, new TranslateCommand("Certificate"));
     }
 
     public static String extractSerialFormCert(X509Certificate x509Certificate) {
index 46b92995df1231817969d4f0952ff44224b7bbd4..1a700961b34345d7ed715761aa6c9d43a8ca50d1 100644 (file)
@@ -138,7 +138,7 @@ public class SupportUserDetailsForm extends Form {
                     return false;
                 }
                 Group g = i.next();
-                vars.put("group_name", l.getTranslation("Group: " + g.getDatabaseName()));
+                vars.put("group_name", g.getName());
                 return true;
             }
         });
index 6ec26d424bc25e610039f67ffe0e638e6ece52c0..dd14e8d3c28c722e5c64d94d6f9c48b14e6a03be 100644 (file)
@@ -107,15 +107,15 @@ public class TestCertificate extends ManagedTest {
         testFails(CertificateStatus.ISSUED, c);
         X509Certificate cert = c.cert();
         assertNotNull(login(pk, cert));
-        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:revoked|issued)</td>"));
-        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:revoked|issued)</td>"));
+        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:REVOKED|ISSUED)</td>"));
+        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:REVOKED|ISSUED)</td>"));
         c.revoke().waitFor(60000);
 
         testFails(CertificateStatus.REVOKED, c);
         assertNull(login(pk, cert));
 
-        assertEquals(0, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:revoked|issued)</td>"));
-        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:revoked|issued)</td>"));
+        assertEquals(0, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH)), "<td>(?:REVOKED|ISSUED)</td>"));
+        assertEquals(1, countRegex(IOUtils.readURL(get(cookie, Certificates.PATH + "?withRevoked")), "<td>(?:REVOKED|ISSUED)</td>"));
     }
 
     private void testFails(CertificateStatus status, Certificate c) throws IOException, GeneralSecurityException, SQLException, GigiApiException {
index 8c010bdc42bdf3105abd1b3dd9a5b794862e97db..5c292fab2d2b3ea965b6b16a83efd21a762ef427 100644 (file)
@@ -31,6 +31,7 @@ import org.cacert.gigi.dbObjects.ObjectCache;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Template;
+import org.cacert.gigi.output.template.TranslateCommand;
 import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.pages.account.certs.CertificateRequest;
 import org.cacert.gigi.pages.main.RegisterPage;
@@ -208,7 +209,7 @@ public class DevelLauncher {
                     sess.setAttribute(LOGGEDIN, true);
                     sess.setAttribute(Language.SESSION_ATTRIB_NAME, user.getPreferredLocale());
                     sess.setAttribute(AUTH_CONTEXT, new AuthorizationContext(user, user));
-                    req.getSession().setAttribute(LOGIN_METHOD, "Ticket");
+                    req.getSession().setAttribute(LOGIN_METHOD, new TranslateCommand("Ticket"));
                     resp.getWriter().println("ticket consumed");
                     ticketUsed = true;
                 }