1 /***
2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.codestreet.messageforge;
19
20 import java.text.SimpleDateFormat;
21 import java.util.TimeZone;
22 import java.sql.*;
23
24 /***
25 * The class contains a utility method for converting from a MIME format called "x-www-form-urlencoded"
26 * to a <tt>String</tt>. Designed to be used by Java 1.1 clients. Java 1.2 and higher clients classes
27 * should be using java.net.URLDecoder instead.
28 */
29
30 // This appears in Core Web Programming from
31 // Prentice Hall Publishers, and may be freely used
32 // or adapted. 1997 Marty Hall, hall@apl.jhu.edu.
33
34 public class RURLDecoder {
35
36 /***
37 * Decodes a "x-www-form-urlencoded" to a String.
38 * @param encoded string to decode
39 * @return decoded string
40 */ public static String decode(String encoded) {
41 int len = encoded.length();
42 StringBuffer decoded = new StringBuffer(len);
43 for (int i = 0; i < len; ++i) {
44 char currentChar = encoded.charAt(i);
45 if (currentChar == '+')
46 {
47 decoded.append(' ');
48 ++i;
49 }
50 else if (currentChar == '%')
51 {
52 String charCode = encoded.substring(i+1, i+3);
53 char decodedChar = (char)Integer.parseInt(charCode, 16);
54 decoded.append(decodedChar);
55 i = i + 3;
56 }
57 else
58 {
59 decoded.append(currentChar);
60 ++i;
61 }
62 }
63 return decoded.toString();
64 }
65
66 public static void main(String[] args) {
67 System.out.println(decode(java.net.URLEncoder.encode(args[0])));
68
69 /*
70 SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy HH:mm:ss,SSS z");
71 //df.applyPattern("dd MMM yyyy HH:mm:ss,SSS z");
72 df.setLenient(true);
73 df.setLenient(true);
74 df.setTimeZone(TimeZone.getTimeZone("GMT"));
75
76 java.util.Date dt = new java.util.Date ();
77 String sd = df.format(dt);
78
79 Timestamp sdt = SybTimestamp.valueOf("1997-01-15 09:12:12");
80 sd = df.format(sdt);
81 */
82 }
83 }
84
85
86
This page was automatically generated by Maven