mman 01/11/27 02:16:52 Modified: src/org/apache/cocoon/components/language/markup/xsp Tag: cocoon_20_branch XSPUtil.java Log: PR: 4878 form(Encode|Decode) converted to use standard java.net.URL(Encoder|Decoder) Revision Changes Path No revision No revision 1.2.2.6 +5 -43 xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java Index: XSPUtil.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -u -r1.2.2.5 -r1.2.2.6 --- XSPUtil.java 2001/10/11 08:56:07 1.2.2.5 +++ XSPUtil.java 2001/11/27 10:16:51 1.2.2.6 @@ -20,6 +20,8 @@ import org.xml.sax.SAXException; import java.io.*; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -28,7 +30,7 @@ * The XSP <code>Utility</code> object helper * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]>Berin Loritsch</a> - * @version $Revision: 1.2.2.5 $ $Date: 2001/10/11 08:56:07 $ + * @version $Revision: 1.2.2.6 $ $Date: 2001/11/27 10:16:51 $ */ public class XSPUtil { public static String pathComponent(String filename) { @@ -137,52 +139,12 @@ } public static String formEncode(String text) throws Exception { - char[] c = text.toCharArray(); - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < c.length; i++) { - if (isAlphaNumeric(c[i])) { - buffer.append(c[i]); - } else if (c[i] == ' ') { - buffer.append('+'); - } else { - buffer.append('%'); - String hex = Integer.toHexString((byte)c[i]).toUpperCase(); - if (hex.length() < 2) { - buffer.append('0'); - } - buffer.append(hex); - } - } - return buffer.toString(); + return URLEncoder.encode (text); } // Shameless, ain't it? public static String formDecode(String s) throws Exception { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - switch (c) { - case '+': - sb.append(' '); - break; - case '%': - try { - sb.append((char)Integer.parseInt(s.substring(i + 1, i + 3), 16)); - } - catch (NumberFormatException e) { - throw new IllegalArgumentException(); - } - i += 2; - break; - default: - sb.append(c); - break; - } - } - // Undo conversion to external encoding - String result = sb.toString(); - byte[] inputBytes = result.getBytes("8859_1"); - return new String(inputBytes); + return URLDecoder.decode (s); } /* Logicsheet Utility Methods */
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]