Author: nextgens
Date: 2007-04-22 12:40:27 +0000 (Sun, 22 Apr 2007)
New Revision: 12856

Added:
   trunk/freenet/src/freenet/clients/http/TranslationToadlet.java
Modified:
   trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
   trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
   trunk/freenet/src/freenet/l10n/L10n.java
Log:
Create a translationToadlet, move all methods there and update links everywhere

Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java   2007-04-22 
12:04:29 UTC (rev 12855)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java   2007-04-22 
12:40:27 UTC (rev 12856)
@@ -613,6 +613,10 @@
                        BrowserTestToadlet browsertTestToadlet = new 
BrowserTestToadlet(client, core);
                        server.register(browsertTestToadlet, "/test/", true, 
false);

+                       TranslationToadlet translationToadlet = new 
TranslationToadlet(client, core);
+                       server.register(translationToadlet, 
TranslationToadlet.TOADLET_URL, true, "Translation", "helper" +
+                                       " to translate the node's interface 
into your native language", true);
+                       
                        // Now start the server.
                        server.start();


Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2007-04-22 12:04:29 UTC (rev 12855)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2007-04-22 12:40:27 UTC (rev 12856)
@@ -176,8 +176,8 @@
                HTMLNode logsList = statGatheringBox.addChild("ul");
                if(nodeConfig.config.get("logger").getBoolean("enabled"))
                        logsList.addChild("li").addChild("a", new String[]{ 
"href", "target"}, new String[]{ "/?latestlog", "_new"}, "Get latest node's 
logfile");
-               logsList.addChild("li").addChild("a", "href", 
"/?getOverrideTranlationFile").addChild("#", "Download the override translation 
file");
-               logsList.addChild("li").addChild("a", "href", 
"/?getTranlationFile").addChild("#", "Download the full translation file");
+               logsList.addChild("li").addChild("a", "href", 
TranslationToadlet.TOADLET_URL+"?getOverrideTranlationFile").addChild("#", 
"Download the override translation file");
+               logsList.addChild("li").addChild("a", "href", 
TranslationToadlet.TOADLET_URL+"?getTranlationFile").addChild("#", "Download 
the full translation file");

                if(advancedModeEnabled) {
                        // store size box

Added: trunk/freenet/src/freenet/clients/http/TranslationToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/TranslationToadlet.java              
                (rev 0)
+++ trunk/freenet/src/freenet/clients/http/TranslationToadlet.java      
2007-04-22 12:40:27 UTC (rev 12856)
@@ -0,0 +1,211 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.clients.http;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Iterator;
+
+import freenet.client.HighLevelSimpleClient;
+import freenet.l10n.L10n;
+import freenet.node.NodeClientCore;
+import freenet.support.HTMLNode;
+import freenet.support.Logger;
+import freenet.support.MultiValueTable;
+import freenet.support.SimpleFieldSet;
+import freenet.support.api.HTTPRequest;
+import freenet.support.io.BucketTools;
+
+/**
+ * A toadlet dedicated to translations ... and easing the work of translators
+ * 
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ */
+public class TranslationToadlet extends Toadlet {
+       public static final String TOADLET_URL = "/translation/";
+       private final NodeClientCore core;
+       
+       TranslationToadlet(HighLevelSimpleClient client, NodeClientCore core) {
+               super(client);
+               this.core = core;
+       }
+       
+       public void handleGet(URI uri, HTTPRequest request, ToadletContext ctx) 
throws ToadletContextClosedException, IOException {
+               if(!ctx.isAllowedFullAccess()) {
+                       super.sendErrorPage(ctx, 403, "Unauthorized", "You are 
not permitted access to this page");
+                       return;
+               }
+               
+               if (request.isParameterSet("getTranlationFile")) {
+                       byte[] data = 
L10n.getCurrentLanguageTranslation().toOrderedString().getBytes("UTF-8");
+                       MultiValueTable head = new MultiValueTable();
+                       head.put("Content-Disposition", "attachment; 
filename=\"" + L10n.PREFIX +L10n.getSelectedLanguage()+ L10n.SUFFIX + '"');
+                       ctx.sendReplyHeaders(200, "Found", head, "text/plain", 
data.length);
+                       ctx.writeData(data);
+                       return;
+               } else if (request.isParameterSet("getOverrideTranlationFile")) 
{
+                       SimpleFieldSet sfs = 
L10n.getOverrideForCurrentLanguageTranslation();
+                       if(sfs == null) {
+                               super.sendErrorPage(ctx, 503 /* Service 
Unavailable */, "Service Unavailable", "There is no custom translation 
available.");
+                               return;
+                       }
+                       byte[] data = sfs.toOrderedString().getBytes("UTF-8");
+                       MultiValueTable head = new MultiValueTable();
+                       head.put("Content-Disposition", "attachment; 
filename=\"" + L10n.PREFIX +L10n.getSelectedLanguage()+ L10n.OVERRIDE_SUFFIX + 
'"');
+                       ctx.sendReplyHeaders(200, "Found", head, "text/plain", 
data.length);
+                       ctx.writeData(data);
+                       return;
+               } else if (request.isParameterSet("transupdated")) {
+                       String key = request.getParam("transupdated");
+                       HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Translation updated!", true, ctx);
+                       HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
+
+                       HTMLNode translationNode = contentNode.addChild("div", 
"class", "translation");
+                       HTMLNode legendTable = 
translationNode.addChild("table", "class", "translation");
+                       
+                       HTMLNode legendRow = 
legendTable.addChild("tr").addChild("b");
+                       legendRow.addChild("td", "class", "translation-key", 
"Translation key");
+                       legendRow.addChild("td", "class", "translation-key", 
"Original (english version)");
+                       legendRow.addChild("td", "class", "translation-key", 
"Current translation");
+                       
+                       HTMLNode contentRow = legendTable.addChild("tr");
+                       contentRow.addChild("td", "class", "translation-key",
+                                       key
+                       );
+                       contentRow.addChild("td", "class", "translation-orig",
+                                       L10n.getDefaultString(key)
+                       );
+                       contentRow.addChild("td", "class", "translation-new",
+                                       L10n.getString(key)
+                       );
+                       
+                       HTMLNode footer = translationNode.addChild("div", 
"class", "warning");
+                       footer.addChild("a", "href", 
TOADLET_URL+"?getOverrideTranlationFile").addChild("#", "Download the override 
translation file");
+                       footer.addChild("%", "  ");
+                       footer.addChild("a", "href", 
TOADLET_URL+"?getTranlationFile").addChild("#", "Download the full translation 
file");
+                       footer.addChild("%", "  ");
+                       footer.addChild("a", "href", "/").addChild("#", "Return 
to the main page");
+
+                       this.writeReply(ctx, 200, "text/html; charset=utf-8", 
"OK", pageNode.generate());
+                       return;                         
+               } else if (request.isParameterSet("translate")) {
+                       String key = request.getParam("translate");
+                       HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Translation update", true, ctx);
+                       HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
+
+                       HTMLNode translationNode = contentNode.addChild("div", 
"class", "translation");
+                       HTMLNode updateForm =  
ctx.addFormChild(translationNode, TOADLET_URL, "trans_update");
+                       HTMLNode legendTable = updateForm.addChild("table", 
"class", "translation");
+                       
+                       HTMLNode legendRow = 
legendTable.addChild("tr").addChild("b");
+                       legendRow.addChild("td", "class", "translation-key", 
"Translation key");
+                       legendRow.addChild("td", "class", "translation-key", 
"Original (english version)");
+                       legendRow.addChild("td", "class", "translation-key", 
"Current translation");
+                       
+                       HTMLNode contentRow = legendTable.addChild("tr");
+                       contentRow.addChild("td", "class", "translation-key",
+                                       key
+                       );
+                       contentRow.addChild("td", "class", "translation-orig",
+                                       L10n.getDefaultString(key)
+                       );
+                       
+                       contentRow.addChild("td", "class", 
"translation-new").addChild(
+                                       "input",
+                                       new String[] { "type", "name", "value" 
},
+                                       new String[] { "text", "trans",  
L10n.getString(key)
+                                       });
+                       
+                       contentRow.addChild("input", 
+                                       new String[] { "type", "name", "value" 
}, 
+                                       new String[] { "hidden", "key", key
+                       });
+
+                       contentRow = legendTable.addChild("tr");
+                       contentRow.addChild("input", 
+                                       new String[] { "type", "name", "value" 
}, 
+                                       new String[] { "submit", "trupdate", 
"Update the translation!"
+                       });
+                       contentRow.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "submit", "cancel", "Cancel" });
+                       this.writeReply(ctx, 200, "text/html; charset=utf-8", 
"OK", pageNode.generate());
+                       return;
+               }
+               
+               HTMLNode pageNode = ctx.getPageMaker().getPageNode("Translation 
update", true, ctx);
+               HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
+
+               HTMLNode translationNode = contentNode.addChild("div", "class", 
"translation");
+               HTMLNode updateForm =  ctx.addFormChild(translationNode, 
TOADLET_URL, "trans_update");
+               HTMLNode legendTable = updateForm.addChild("table", "class", 
"translation");
+               
+               HTMLNode legendRow = legendTable.addChild("tr").addChild("b");
+               legendRow.addChild("td", "class", "translation-key", 
"Translation key");
+               legendRow.addChild("td", "class", "translation-key", "Original 
(english version)");
+               legendRow.addChild("td", "class", "translation-key", "Current 
translation");
+               
+               SimpleFieldSet sfs = L10n.getCurrentLanguageTranslation();
+               Iterator it = sfs.keyIterator();
+               
+               while(it.hasNext()) {
+                       String key = (String)it.next();
+
+                       HTMLNode contentRow = legendTable.addChild("tr");
+                       contentRow.addChild("td", "class", "translation-key",
+                                       key
+                       );
+                       contentRow.addChild("td", "class", "translation-orig",
+                                       L10n.getDefaultString(key)
+                       );
+
+                       contentRow.addChild("td", "class", 
"translation-new").addChild(
+                                       "input",
+                                       new String[] { "type", "name", "value" 
},
+                                       new String[] { "text", "trans",  
L10n.getString(key)
+                                       });
+
+                       contentRow.addChild("td", 
+                                       new String[] { "type", "name", "value" 
}, 
+                                       new String[] { "text", "key", key
+                       });
+               }
+               this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", 
pageNode.generate());
+       }
+       
+       public void handlePost(URI uri, HTTPRequest request, ToadletContext 
ctx) throws ToadletContextClosedException, IOException {
+               if(!ctx.isAllowedFullAccess()) {
+                       super.sendErrorPage(ctx, 403, "Unauthorized", "You are 
not permitted access to this page");
+                       return;
+               }
+               
+               final boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+               final String passwd = request.getPartAsString("formPassword", 
32);
+               boolean noPassword = (passwd == null) || 
!passwd.equals(core.formPassword);
+               if(noPassword) {
+                       if(logMINOR) Logger.minor(this, "No password 
("+passwd+" should be "+core.formPassword+ ')');
+                       redirectTo(ctx, "/");
+                       return;
+               }
+               
+               if(request.getPartAsString("trupdate", 32).length() > 0){
+                       String key = request.getPartAsString("key", 256);
+                       L10n.setOverride(key, new 
String(BucketTools.toByteArray(request.getPart("trans")), "UTF-8"));
+                       
+                       redirectTo(ctx, TOADLET_URL+"?transupdated="+key);
+                       return;
+               } else // Shouldn't reach that point!
+                       redirectTo(ctx, "/");
+       }
+       
+       private void redirectTo(ToadletContext ctx, String target) throws 
ToadletContextClosedException, IOException {
+               MultiValueTable headers = new MultiValueTable();
+               headers.put("Location", target);
+               ctx.sendReplyHeaders(302, "Found", headers, null, 0);
+               return;
+       }
+       
+       public String supportedMethods() {
+               return "GET, POST";
+       }
+
+}

Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2007-04-22 
12:04:29 UTC (rev 12855)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2007-04-22 
12:40:27 UTC (rev 12856)
@@ -21,7 +21,6 @@
 import freenet.client.InserterException;
 import freenet.clients.http.filter.GenericReadFilterCallback;
 import freenet.keys.FreenetURI;
-import freenet.l10n.L10n;
 import freenet.node.Node;
 import freenet.node.NodeClientCore;
 import freenet.node.NodeStarter;
@@ -30,10 +29,8 @@
 import freenet.support.HTMLNode;
 import freenet.support.Logger;
 import freenet.support.MultiValueTable;
-import freenet.support.SimpleFieldSet;
 import freenet.support.api.Bucket;
 import freenet.support.api.HTTPRequest;
-import freenet.support.io.BucketTools;

 import freenet.frost.message.*;

@@ -82,23 +79,11 @@
                        if(Logger.shouldLog(Logger.MINOR, this)) 
Logger.minor(this, "No password ("+passwd+" should be "+core.formPassword+ ')');
                }

-               if(request.getPartAsString("trupdate", 32).length() > 0){
+               if(request.getPartAsString("updateconfirm", 32).length() > 0){
                        if(noPassword) {
                                redirectToRoot(ctx);
                                return;
                        }
-                       String key = request.getPartAsString("key", 256);
-                       L10n.setOverride(key, new 
String(BucketTools.toByteArray(request.getPart("trans")), "UTF-8"));
-                       
-                       MultiValueTable headers = new MultiValueTable();
-                       headers.put("Location", "/?transupdated="+key);
-                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
-                       return;
-               } else if(request.getPartAsString("updateconfirm", 32).length() 
> 0){
-                       if(noPassword) {
-                               redirectToRoot(ctx);
-                               return;
-                       }
                        // false for no navigation bars, because that would be 
very silly
                        HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Node updating", ctx);
                        HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
@@ -465,100 +450,6 @@

                                this.writeReply(ctx, 200, "text/plain", "OK", 
sw.toString());
                                return;
-                       } else if (request.isParameterSet("getTranlationFile")) 
{
-                               byte[] data = 
L10n.getCurrentLanguageTranslation().toOrderedString().getBytes("UTF-8");
-                               MultiValueTable head = new MultiValueTable();
-                               head.put("Content-Disposition", "attachment; 
filename=\"" + L10n.PREFIX +L10n.getSelectedLanguage()+ L10n.SUFFIX + '"');
-                               ctx.sendReplyHeaders(200, "Found", head, 
"text/plain", data.length);
-                               ctx.writeData(data);
-                               return;
-                       } else if 
(request.isParameterSet("getOverrideTranlationFile")) {
-                               SimpleFieldSet sfs = 
L10n.getOverrideForCurrentLanguageTranslation();
-                               if(sfs == null) {
-                                       super.sendErrorPage(ctx, 503 /* Service 
Unavailable */, "Service Unavailable", "There is no custom translation 
available.");
-                                       return;
-                               }
-                               byte[] data = 
sfs.toOrderedString().getBytes("UTF-8");
-                               MultiValueTable head = new MultiValueTable();
-                               head.put("Content-Disposition", "attachment; 
filename=\"" + L10n.PREFIX +L10n.getSelectedLanguage()+ L10n.OVERRIDE_SUFFIX + 
'"');
-                               ctx.sendReplyHeaders(200, "Found", head, 
"text/plain", data.length);
-                               ctx.writeData(data);
-                               return;
-                               
-                       } else if (request.isParameterSet("transupdated")) {
-                               String key = request.getParam("transupdated");
-                               HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Translation updated!", true, ctx);
-                               HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
-
-                               HTMLNode translationNode = 
contentNode.addChild("div", "class", "translation");
-                               HTMLNode legendTable = 
translationNode.addChild("table", "class", "translation");
-                               
-                               HTMLNode legendRow = 
legendTable.addChild("tr").addChild("b");
-                               legendRow.addChild("td", "class", 
"translation-key", "Translation key");
-                               legendRow.addChild("td", "class", 
"translation-key", "Original (english version)");
-                               legendRow.addChild("td", "class", 
"translation-key", "Current translation");
-                               
-                               HTMLNode contentRow = 
legendTable.addChild("tr");
-                               contentRow.addChild("td", "class", 
"translation-key",
-                                               key
-                               );
-                               contentRow.addChild("td", "class", 
"translation-orig",
-                                               L10n.getDefaultString(key)
-                               );
-                               contentRow.addChild("td", "class", 
"translation-new",
-                                               L10n.getString(key)
-                               );
-                               
-                               HTMLNode footer = 
translationNode.addChild("div", "class", "warning");
-                               footer.addChild("a", "href", 
"/?getOverrideTranlationFile").addChild("#", "Download the override translation 
file");
-                               footer.addChild("%", "  ");
-                               footer.addChild("a", "href", 
"/?getTranlationFile").addChild("#", "Download the full translation file");
-                               footer.addChild("%", "  ");
-                               footer.addChild("a", "href", "/").addChild("#", 
"Return to the main page");
-
-                               this.writeReply(ctx, 200, "text/html; 
charset=utf-8", "OK", pageNode.generate());
-                               return;                         
-                       } else if (request.isParameterSet("translate")) {
-                               String key = request.getParam("translate");
-                               HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Translation update", true, ctx);
-                               HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
-
-                               HTMLNode translationNode = 
contentNode.addChild("div", "class", "translation");
-                               HTMLNode updateForm =  
ctx.addFormChild(translationNode, "/", "trans_update");
-                               HTMLNode legendTable = 
updateForm.addChild("table", "class", "translation");
-                               
-                               HTMLNode legendRow = 
legendTable.addChild("tr").addChild("b");
-                               legendRow.addChild("td", "class", 
"translation-key", "Translation key");
-                               legendRow.addChild("td", "class", 
"translation-key", "Original (english version)");
-                               legendRow.addChild("td", "class", 
"translation-key", "Current translation");
-                               
-                               HTMLNode contentRow = 
legendTable.addChild("tr");
-                               contentRow.addChild("td", "class", 
"translation-key",
-                                               key
-                               );
-                               contentRow.addChild("td", "class", 
"translation-orig",
-                                               L10n.getDefaultString(key)
-                               );
-                               
-                               contentRow.addChild("td", "class", 
"translation-new").addChild(
-                                               "input",
-                                               new String[] { "type", "name", 
"value" },
-                                               new String[] { "text", "trans", 
 L10n.getString(key)
-                                               });
-                               
-                               contentRow.addChild("input", 
-                                               new String[] { "type", "name", 
"value" }, 
-                                               new String[] { "hidden", "key", 
key
-                               });
-
-                               contentRow = legendTable.addChild("tr");
-                               contentRow.addChild("input", 
-                                               new String[] { "type", "name", 
"value" }, 
-                                               new String[] { "submit", 
"trupdate", "Update the translation!"
-                               });
-                               contentRow.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "submit", "cancel", "Cancel" });
-                               this.writeReply(ctx, 200, "text/html; 
charset=utf-8", "OK", pageNode.generate());
-                               return;
                        } else if (request.isParameterSet("terminated")) {
                                if((!request.isParameterSet("formPassword")) || 
!request.getParam("formPassword").equals(core.formPassword)) {
                                        redirectToRoot(ctx);

Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java    2007-04-22 12:04:29 UTC (rev 
12855)
+++ trunk/freenet/src/freenet/l10n/L10n.java    2007-04-22 12:40:27 UTC (rev 
12856)
@@ -10,6 +10,7 @@
 import java.io.InputStream;
 import java.util.MissingResourceException;

+import freenet.clients.http.TranslationToadlet;
 import freenet.support.HTMLNode;
 import freenet.support.Logger;
 import freenet.support.SimpleFieldSet;
@@ -27,7 +28,6 @@
  * for other access (telnet) using system locale would probably be good, but
  * it would be nice to have a command to switch locale on the fly.
  */
-
 public class L10n {
        public static final String CLASS_NAME = "L10n";
        public static final String PREFIX = "freenet.l10n.";
@@ -184,7 +184,7 @@
                        return new HTMLNode("#", value);
                HTMLNode translationField = new HTMLNode("span", "class", 
"translate_it") ;
                translationField.addChild("#", getDefaultString(key));
-               translationField.addChild("a", "href", "/?translate=" + 
key).addChild("small", " (translate it in your native language!)");
+               translationField.addChild("a", "href", 
TranslationToadlet.TOADLET_URL+"?translate=" + key).addChild("small", " 
(translate it in your native language!)");

                return translationField;
        }


Reply via email to