use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class BaseParams method getRequestBody.
public RequestBody getRequestBody() throws IOException {
checkBodyParams();
if (this.requestBody != null) {
return this.requestBody;
}
RequestBody result = null;
if (!TextUtils.isEmpty(bodyContent)) {
result = new StringBody(bodyContent, charset);
} else if (multipart || fileParams.size() > 0) {
if (!multipart && fileParams.size() == 1) {
for (KeyValue kv : fileParams) {
String contentType = null;
Object value = kv.value;
if (value instanceof BodyItemWrapper) {
BodyItemWrapper wrapper = (BodyItemWrapper) value;
value = wrapper.getValue();
contentType = wrapper.getContentType();
}
if (value instanceof File) {
result = new FileBody((File) value, contentType);
} else if (value instanceof InputStream) {
result = new InputStreamBody((InputStream) value, contentType);
} else if (value instanceof byte[]) {
result = new InputStreamBody(new ByteArrayInputStream((byte[]) value), contentType);
} else if (value instanceof String) {
// invoke addBodyParameter(key, stringValue, contentType)
result = new StringBody((String) value, charset);
result.setContentType(contentType);
} else {
LogUtil.w("Some params will be ignored for: " + this.toString());
}
break;
}
} else {
multipart = true;
result = new MultipartBody(fileParams, charset);
}
} else if (bodyParams.size() > 0) {
result = new UrlEncodedParamsBody(bodyParams, charset);
}
return result;
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class BaseParams method removeParameter.
public void removeParameter(String name) {
if (!TextUtils.isEmpty(name)) {
Iterator<KeyValue> it = queryStringParams.iterator();
while (it.hasNext()) {
KeyValue kv = it.next();
if (name.equals(kv.key)) {
it.remove();
}
}
it = bodyParams.iterator();
while (it.hasNext()) {
KeyValue kv = it.next();
if (name.equals(kv.key)) {
it.remove();
}
}
it = fileParams.iterator();
while (it.hasNext()) {
KeyValue kv = it.next();
if (name.equals(kv.key)) {
it.remove();
}
}
} else {
bodyContent = null;
}
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class BaseParams method toJSONString.
public String toJSONString() {
List<KeyValue> list = new ArrayList<KeyValue>(queryStringParams.size() + bodyParams.size());
list.addAll(queryStringParams);
list.addAll(bodyParams);
try {
JSONObject jsonObject = null;
if (!TextUtils.isEmpty(bodyContent)) {
jsonObject = new JSONObject(bodyContent);
} else {
jsonObject = new JSONObject();
}
params2Json(jsonObject, list);
return jsonObject.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class BaseParams method params2Json.
private void params2Json(final JSONObject jsonObject, final List<KeyValue> paramList) throws JSONException {
HashSet<String> arraySet = new HashSet<String>(paramList.size());
LinkedHashMap<String, JSONArray> tempData = new LinkedHashMap<String, JSONArray>(paramList.size());
for (int i = 0; i < paramList.size(); i++) {
KeyValue kv = paramList.get(i);
final String key = kv.key;
if (TextUtils.isEmpty(key))
continue;
JSONArray ja = null;
if (tempData.containsKey(key)) {
ja = tempData.get(key);
} else {
ja = new JSONArray();
tempData.put(key, ja);
}
ja.put(RequestParamsHelper.parseJSONObject(kv.value));
if (kv instanceof ArrayItem) {
arraySet.add(key);
}
}
for (Map.Entry<String, JSONArray> entry : tempData.entrySet()) {
String key = entry.getKey();
JSONArray ja = entry.getValue();
if (ja.length() > 1 || arraySet.contains(key)) {
jsonObject.put(key, ja);
} else {
Object value = ja.get(0);
jsonObject.put(key, value);
}
}
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class SqlInfoBuilder method buildUpdateSqlInfo.
public static SqlInfo buildUpdateSqlInfo(TableEntity<?> table, WhereBuilder whereBuilder, KeyValue... nameValuePairs) throws DbException {
if (nameValuePairs == null || nameValuePairs.length == 0)
return null;
SqlInfo result = new SqlInfo();
StringBuilder builder = new StringBuilder("UPDATE ");
builder.append("\"").append(table.getName()).append("\"");
builder.append(" SET ");
for (KeyValue kv : nameValuePairs) {
builder.append("\"").append(kv.key).append("\"").append("=?,");
result.addBindArg(kv);
}
builder.deleteCharAt(builder.length() - 1);
if (whereBuilder != null && whereBuilder.getWhereItemSize() > 0) {
builder.append(" WHERE ").append(whereBuilder.toString());
}
result.setSql(builder.toString());
return result;
}
Aggregations