ImageUtil.java
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.topdraw.sohu.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ImageUtil {
public static Map<String, Integer> mapImageType = new HashMap<>();
static {
mapImageType.put("normal", -1);
mapImageType.put("thumbnail", 0);
mapImageType.put("poster", 1);
mapImageType.put("stills", 2);
mapImageType.put("icon", 3);
mapImageType.put("title", 4);
mapImageType.put("ad", 5);
mapImageType.put("sketch", 6);
mapImageType.put("background", 7);
mapImageType.put("channel", 9);
mapImageType.put("channel_bw", 10);
mapImageType.put("channel_logo", 11);
mapImageType.put("channel_name", 12);
mapImageType.put("other", 99);
}
public static String convertStrImages2SpecialFormatJSON(String strImages) {
JSONArray jsonArr;
if (strImages != null) {
jsonArr = JSONArray.parseArray(strImages);
} else {
jsonArr = new JSONArray();
}
Map<String, Object> mapImages = new HashMap<String, Object>();
mapImages.put("map", new HashMap<String, Object>());
mapImages.put("list", new ArrayList<Map<String, Object>>());
for (int i = 0; i < jsonArr.size(); i++) {
JSONObject jsonObj = jsonArr.getJSONObject(i);
String strKey = ResourceUtil.getImageKeyByType(jsonObj.containsKey("type") ? jsonObj.getIntValue("type") : -1);
if (((Map<String, Object>) mapImages.get("map")).containsKey(strKey)) {
((ArrayList<Integer>) ((Map<String, Object>) mapImages.get("map")).get(strKey)).add(i);
} else {
List<Integer> listIndex = new ArrayList<Integer>();
listIndex.add(i);
((Map<String, Object>) mapImages.get("map")).put(strKey, listIndex);
}
Map<String, Object> mapImageDetail = new HashMap<String, Object>();
mapImageDetail.put("id", jsonObj.getLong("id"));
mapImageDetail.put("fileUrl", jsonObj.getString("fileUrl"));
mapImageDetail.put("height", jsonObj.getInteger("height"));
mapImageDetail.put("width", jsonObj.getInteger("width"));
mapImageDetail.put("size", jsonObj.getInteger("size"));
mapImageDetail.put("extension", jsonObj.getString("extension"));
mapImageDetail.put("enable", jsonObj.getBoolean("enable"));
mapImageDetail.put("name", jsonObj.getString("name"));
mapImageDetail.put("csp_code", jsonObj.getString("csp_code"));
((ArrayList<Map<String, Object>>) mapImages.get("list")).add(mapImageDetail);
}
return JSON.toJSONString(mapImages);
}
}