Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r844 committed - Fix issue with 'Report Problem' button. ...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r844 committed - Fix issue with 'Report Problem' button. ...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r844 committed - Fix issue with 'Report Problem' button. ...
  • Date: Tue, 15 Oct 2013 12:58:08 +0000

Revision: 844
Author:

Date: Tue Oct 15 12:57:51 2013 UTC
Log: Fix issue with 'Report Problem' button.
The mailTo link was not properly handled by applet because all parameters (name, host, subject, body) were not encoded.
http://code.google.com/p/ndt/source/detail?r=844

Modified:
/branches/applet_usability/Applet/NDTUtils.java
/branches/applet_usability/Applet/Tcpbw100.java

=======================================
--- /branches/applet_usability/Applet/NDTUtils.java Thu Oct 10 13:32:52 2013 UTC
+++ /branches/applet_usability/Applet/NDTUtils.java Tue Oct 15 12:57:51 2013 UTC
@@ -1,3 +1,5 @@
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import java.util.ResourceBundle;

/**
@@ -103,4 +105,44 @@
return !isEmpty(str);
} // isNotEmpty() method ends

+
+ /**
+ * Utility method to create mailTo link
+ *
+ * @param name
+ * user identifier
+ * @param host
+ * fully qualified domain name
+ * @param subject
+ * email subject
+ * @param body
+ * email body
+ * @return created mailTo link with the encoded parameters
+ */
+ public static String mailTo(final String name, final String host,
+ final String
subject, final String body) {
+ return String.format(
+
"mailto:%s@%s?subject=%s&body=%s",
+ new Object[]{
+ urlEncode(name),
urlEncode(host),
+ urlEncode(subject),
urlEncode(body)
+ }
+ );
+ } // mailTo() method ends
+
+ /**
+ * Utility method to encode the given string using UTF-8 encoding
+ *
+ * @param str
+ * String to encode
+ * @return encoded string with replacing '+' to '%20'
+ */
+ public static String urlEncode(String str) {
+ try {
+ return URLEncoder.encode(str, "utf-8").replace("+",
"%20");
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e);
+ }
+ } // urlEncode() method ends
+
}
=======================================
--- /branches/applet_usability/Applet/Tcpbw100.java Fri Oct 11 09:01:16 2013 UTC
+++ /branches/applet_usability/Applet/Tcpbw100.java Tue Oct 15 12:57:51 2013 UTC
@@ -84,6 +84,7 @@
import java.net.Socket;
import java.net.SocketException;
import java.net.URL;
+import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -1179,28 +1180,38 @@
throw new IllegalArgumentException("H
parameter Required:");
}

- String theURL = "; + sName + "@" +
sHost;
- String subject = getParameter("subject"); //
get subject
+ String sSubject = getParameter("subject"); //
get subject

- if (subject == null) {
- subject = _resBundDisplayMsgs
+ if (sSubject == null) {
+ sSubject = _resBundDisplayMsgs

.getString("troubleReportFrom")
+ " "
+
getCodeBase().getHost();
}
- theURL += "?subject=" + subject;
- theURL += "&body=" +
_resBundDisplayMsgs.getString("comments")
- + ":%0A%0A" + _sEmailText + "
"
- +
_resBundDisplayMsgs.getString("endOfEmail") + "\n%0A";
- // System.out.println("Message body is '" + emailText +
"'\n");
- _targetURL = new URL(theURL);
+
+ String sBody =
_resBundDisplayMsgs.getString("comments")
+ + ":\n\n" + _sEmailText +
"\n\n"
+ +
_resBundDisplayMsgs.getString("endOfEmail");
+
+ String sUrl = NDTUtils.mailTo(sName, sHost,
sSubject, sBody);
+
+ _targetURL = new URL(sUrl);
+
+ getAppletContext().showDocument(_targetURL);
+ _buttonMailTo.setEnabled(true);
+ } catch (Exception e) {
+ e.printStackTrace();

- } catch (MalformedURLException rsi) {
- throw new IllegalArgumentException("Can't create
mailto: URL"
- + rsi.getMessage());
- }
+ String sMessage =
NDTUtils.isEmpty(e.getMessage())
+ ?
_resBundDisplayMsgs.getString("withoutMessage")
+ : e.getMessage();
+
+ _sErrMsg =
_resBundDisplayMsgs.getString("unexpectedException")
+ + " (" + e.getClass().getName() +
"): "
+ + sMessage + "\n";

- getAppletContext().showDocument(_targetURL);
+ _resultsTxtPane.append(_sErrMsg);
+ }
} // end mail-to functionality
} // actionPerformed()



  • [ndt-dev] [ndt] r844 committed - Fix issue with 'Report Problem' button. ..., ndt, 10/15/2013

Archive powered by MHonArc 2.6.16.

Top of Page