Example #1
0
 /**
  * Generate an exception message
  *
  * @param aException The Exception object
  * @return A representation of the exception which is appropriate for the client type
  */
 public String generateExceptionMessage(Exception aException) {
   StringBuffer retVal = new StringBuffer("<?xml version=\"1.0\"?>\n");
   retVal.append(
       "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
   retVal.append("<wml>\n");
   retVal.append("<card><p>\n");
   retVal.append("[HTTPEventTranslator Error (");
   retVal.append(aException.getClass().toString());
   retVal.append(")]\n");
   retVal.append("</p></card>\n");
   retVal.append("</wml>");
   return retVal.toString();
 }
Example #2
0
  /**
   * This method takes a regular Java unicode string and returns an WML-safe string. This is
   * particularly useful in Maui WML renderers.
   */
  public static String encodeWML(final String javaString) {
    StringBuffer encodedString = new StringBuffer();

    for (int i = 0; i < javaString.length(); i++) {
      int thisCharValue = javaString.charAt(i);

      switch (thisCharValue) {
          // ++ 352 MW 2001.08.15
          // Tab (\t)
        case 9:
          encodedString.append("&nbsp;&nbsp;");
          break;
          // -- 352

          // Line feed (\n)
        case 10:
          encodedString.append("<br/>");
          break;

          // Quotation Mark (")
        case 34:
          encodedString.append("&quot;");
          break;

          // Dollar sign ($)
        case 36:
          encodedString.append("$$");
          break;

          // Ampersand (&)
        case 38:
          encodedString.append("&amp;");
          break;

          // Semicolon (;)
        case 59:
          encodedString.append("&#59;");
          break;

          // Less-than (<)
        case 60:
          encodedString.append("&lt;");
          break;

          // Greater-than (>)
        case 62:
          encodedString.append("&gt;");
          break;

          //
          // Macintosh ASCII
          //

          // Curly open quote (Ò)
          // Curly close quote (Ó)
        case 210:
        case 211:
          encodedString.append("\"");
          break;

          // Curly open apostrophe (Ô)
          // Curly close apostrophe (Õ)
        case 212:
        case 213:
          encodedString.append("'");
          break;

        default:
          // Handle extended ASCII and Unicode characters.
          if (thisCharValue >= 160) {
            encodedString.append("&#");
            encodedString.append(thisCharValue);
            encodedString.append(";");
          }
          // Otherwise, this is probably a safe ASCII character.
          else {
            encodedString.append(javaString.charAt(i));
          }
          break;
      }
    }

    // ++ 286 MW 2001.08.07
    return HTMLCompositor.encodeWhitespace(encodedString.toString());
    // -- 286
  }