1 57 58 package org.apache.soap.util.mime; 59 60 import java.io.*; 61 import java.util.*; 62 import java.net.*; 63 import org.apache.soap.*; 64 import javax.mail.internet.*; 65 66 71 72 public class MimeUtils { 73 82 public static String getUniqueValue() { 83 String host = null; 84 try { 85 host = InetAddress.getLocalHost().getHostName(); 86 } catch (UnknownHostException uhe) { 87 host = "localhost"; 88 } 89 90 StringBuffer s = new StringBuffer (); 91 92 s.append(s.hashCode()).append('.').append(System.currentTimeMillis()). 94 append(".apache-soap.").append(host); 95 return s.toString(); 96 } 97 98 101 public static String getEncoding(String type, String defaultEncoding) { 102 String encoding = null; 103 try { 104 if (type != null && !type.equals("")) 105 encoding = new ContentType(type).getParameter("charset"); 106 } catch(ParseException pe) { 107 } 108 if (encoding == null) 109 encoding = defaultEncoding; 110 else 111 encoding = MimeUtility.javaCharset(encoding); 112 113 return encoding; 114 } 115 116 119 private static final String hexmap = "0123456789ABCDEF"; 120 public static String decode(String s) { 121 StringBuffer ret = new StringBuffer (); 122 char c; 123 for (int i = 0; i < s.length(); i++) { 124 c = s.charAt(i); 125 switch(c) { 126 case '+': 127 ret.append(' '); 128 break; 129 case '%': 130 ret.append((char)((hexmap.indexOf(s.charAt(++i)) << 4) 131 + hexmap.indexOf(s.charAt(++i)))); 132 break; 133 default: 134 ret.append(c); 135 } 136 } 137 return ret.toString(); 138 } 139 } 140 | Popular Tags |