You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.7 KiB
82 lines
2.7 KiB
7 years ago
|
package com.fr.plugin.form.widget;
|
||
|
|
||
|
import com.fr.third.org.apache.http.NameValuePair;
|
||
|
import com.fr.third.org.apache.http.message.BasicNameValuePair;
|
||
|
import com.fr.third.org.apache.http.message.ParserCursor;
|
||
|
import com.fr.third.org.apache.http.message.TokenParser;
|
||
|
import com.fr.third.org.apache.http.util.Args;
|
||
|
import com.fr.third.org.apache.http.util.CharArrayBuffer;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.BitSet;
|
||
|
import java.util.Collections;
|
||
|
import java.util.List;
|
||
|
|
||
|
/**
|
||
|
* 参照{@link com.fr.third.org.apache.http.client.utils.URLEncodedUtils}
|
||
|
* 的代码,但是不进行解码操作,传入的 url 可以是未编码的
|
||
|
*
|
||
|
* @see com.fr.third.org.apache.http.client.utils.URLEncodedUtils
|
||
|
*/
|
||
|
@SuppressWarnings("ALL")
|
||
|
public class URLUtils {
|
||
|
|
||
|
public static List<NameValuePair> parse(String s) {
|
||
|
if (s == null) {
|
||
|
return Collections.emptyList();
|
||
|
} else {
|
||
|
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
|
||
|
buffer.append(s);
|
||
|
return parse(buffer, '&', ';');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static List<NameValuePair> parse(String s, char... separators) {
|
||
|
if (s == null) {
|
||
|
return Collections.emptyList();
|
||
|
} else {
|
||
|
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
|
||
|
buffer.append(s);
|
||
|
return parse(buffer, separators);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static List<NameValuePair> parse(CharArrayBuffer buf, char... separators) {
|
||
|
Args.notNull(buf, "Char array buffer");
|
||
|
TokenParser tokenParser = TokenParser.INSTANCE;
|
||
|
BitSet delimSet = new BitSet();
|
||
|
int var6 = separators.length;
|
||
|
|
||
|
for (int var7 = 0; var7 < var6; ++var7) {
|
||
|
char separator = separators[var7];
|
||
|
delimSet.set(separator);
|
||
|
}
|
||
|
|
||
|
ParserCursor cursor = new ParserCursor(0, buf.length());
|
||
|
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
|
||
|
|
||
|
while (!cursor.atEnd()) {
|
||
|
delimSet.set(61);
|
||
|
String name = tokenParser.parseToken(buf, cursor, delimSet);
|
||
|
String value = null;
|
||
|
if (!cursor.atEnd()) {
|
||
|
int delim = buf.charAt(cursor.getPos());
|
||
|
cursor.updatePos(cursor.getPos() + 1);
|
||
|
if (delim == '=') {
|
||
|
delimSet.clear(61);
|
||
|
value = tokenParser.parseValue(buf, cursor, delimSet);
|
||
|
if (!cursor.atEnd()) {
|
||
|
cursor.updatePos(cursor.getPos() + 1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!name.isEmpty()) {
|
||
|
list.add(new BasicNameValuePair(name, value));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
}
|