Author: nextgens
Date: 2007-04-13 19:03:42 +0000 (Fri, 13 Apr 2007)
New Revision: 12649

Modified:
   trunk/plugins/TranslationHelper/TranslationHelper.java
Log:
TranslationHelper: fix it

Modified: trunk/plugins/TranslationHelper/TranslationHelper.java
===================================================================
--- trunk/plugins/TranslationHelper/TranslationHelper.java      2007-04-13 
19:02:54 UTC (rev 12648)
+++ trunk/plugins/TranslationHelper/TranslationHelper.java      2007-04-13 
19:03:42 UTC (rev 12649)
@@ -3,20 +3,20 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package plugins.TranslationHelper;

-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
+import java.io.StringWriter;
 import java.util.Enumeration;
 import java.util.Properties;

 import freenet.l10n.L10n;
+import freenet.pluginmanager.DownloadPluginHTTPException;
 import freenet.pluginmanager.FredPlugin;
 import freenet.pluginmanager.FredPluginHTTP;
 import freenet.pluginmanager.FredPluginThreadless;
 import freenet.pluginmanager.PluginHTTPException;
 import freenet.pluginmanager.PluginRespirator;
+import freenet.pluginmanager.RedirectPluginHTTPException;
 import freenet.support.HTMLNode;
-import freenet.support.MultiValueTable;
 import freenet.support.api.HTTPRequest;

 /**
@@ -93,25 +93,11 @@
                                                L10n.getDefaultString(key)
                                );
                                String newValue = 
editedProperties.getProperty(key);
-                               
-                               // Deal with unicode characters:
-                               // It works for french characters: I'm not sure 
about others.
-                               StringBuffer sb = new StringBuffer();
-                               int index = 0;
-                               while (index <= newValue.length() - 1) {
-                                       if(newValue.charAt(index) == (char)195) 
{ // unicode marker
-                                               char generatedChar = 
(char)((195 & 11110000) + (newValue.charAt(index + 1)));
-                                               sb.append(generatedChar);
-                                               index++;
-                                       }else
-                                               
sb.append(newValue.charAt(index));
-                                       index++;
-                               }

                                contentRow.addChild("td", "class", 
"translation-new").addChild(
                                                "input",
                                                new String[] { "type", "name", 
"value" },
-                                               new String[] { "text", key,  
sb.toString()
+                                               new String[] { "text", key,  
newValue
                                });
                        }
                        HTMLNode contentRow = legendTable.addChild("tr");
@@ -128,18 +114,21 @@

                        contentRow.addChild("%", "&nbsp;&nbsp;");               
        
                        contentRow.addChild("a", "href", 
PLUGIN_BASE_URL).addChild("#", "Return to the plugin's main page");
-                                               
+
                        return pageNode.generate();
                        // It doesn't help: we need to decode unicode 
characters!
                        //throw new PluginHTTPException(200, "text/html; 
charset=ISO-8859-1", "Found", pageNode.generate());
                } else if(request.isParameterSet("getTranlationFile")) {
-                       OutputStream os = new ByteArrayOutputStream();
+                       byte[] data = null;
                        try {
-                               editedProperties.store(os, "Translation file 
for "+editedLang);
-                       } catch (IOException e) {} // huh ?
-                       MultiValueTable headers = new MultiValueTable();
-                       headers.put("Content-Disposition", "attachment; 
filename=\"" + "freenet.l10n."+editedLang+".properties" + '"');
-                       throw new PluginHTTPException(200, "Ok", headers, 
"text/plain", os.toString());
+                               StringWriter sw = new StringWriter();
+                               editedProperties.store(sw, "Translation file 
for "+editedLang);
+                               data = 
sw.getBuffer().toString().getBytes("UTF-8");
+                       } catch (IOException e) {
+                               throw new PluginHTTPException("Should not 
happen !", PLUGIN_BASE_URL);
+                       }
+                       
+                       throw new DownloadPluginHTTPException(data, 
"freenet.l10n."+editedLang+".properties", "text/plain");
                }

                HTMLNode pageNode = pr.getPageMaker().getPageNode(PLUGIN_NAME+" 
page", false, null);
@@ -176,22 +165,18 @@
        }

        public String handleHTTPPost(HTTPRequest request) throws 
PluginHTTPException {
-               if(request.isPartSet("update")){
+               if(request.isPartSet("update")){                        
                        Enumeration keys = editedProperties.keys();
                        while(keys.hasMoreElements()) {
                                String key = (String)keys.nextElement();
                                editedProperties.setProperty(key, 
request.getPartAsString(key, 256));
                        }

-                       MultiValueTable headers = new MultiValueTable();
-                       headers.put("Location", 
PLUGIN_BASE_URL+"?lang="+editedLang);
-                       throw new PluginHTTPException(302, "Found", headers, 
null, null);
+                       throw new RedirectPluginHTTPException("Redirect", 
PLUGIN_BASE_URL, PLUGIN_BASE_URL+"?lang="+editedLang);
                }else if(request.isPartSet("reload")) {
                        editedProperties = L10n.loadProperties(editedLang);
-                       
-                       MultiValueTable headers = new MultiValueTable();
-                       headers.put("Location", 
PLUGIN_BASE_URL+"?lang="+editedLang);
-                       throw new PluginHTTPException(302, "Found", headers, 
null, null);
+
+                       throw new RedirectPluginHTTPException("Redirect", 
PLUGIN_BASE_URL, PLUGIN_BASE_URL+"?lang="+editedLang);
                }
                return null;
        }


Reply via email to