ImagePathUtils.java
1.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.framework.util;
import java.util.HashMap;
import java.util.Map;
public class ImagePathUtils {
private static Map<String, ImageSizeConfig> imageSizeConfig;
static {
imageSizeConfig = new HashMap<String, ImageSizeConfig>();
String imageConfig = PropertiesLoader.get("IMAGE_SIZE");
if (imageConfig != null) {
String[] p = imageConfig.split(";");
for (int i = 0; i < p.length; i++) {
String m = p[i];
m = m.replace("[", "");
m = m.replace("]", "");
String[] y = m.split(",");
imageSizeConfig.put(y[0].replace("\"", ""),
new ImageSizeConfig(y[0], Integer.parseInt(y[1].replace("\"", "")), Integer.parseInt(y[2].replace("\"", ""))));
}
}
}
private static int[] getImageSizeConfig(String name) {
int[] result = new int[2];
ImageSizeConfig config = imageSizeConfig.get(name);
if (config != null) {
result[0] = config.getW();
result[1] = config.getH();
}
return result;
}
public static String getImageURL(String url, String name) {
if (null == url || url.indexOf(".") < 0) {
return url;
}
int[] size = getImageSizeConfig(name);
if (size == null || !FileUtils.isImageFile(url)) {
return url;
} else {
String suffix = FileUtils.getSuffixName(url);
return url.substring(0, url.lastIndexOf(".")) + "%5F" + size[0] + "%5F" + size[1] + suffix;
}
}
}
class ImageSizeConfig {
private String name;
private int w;
private int h;
public ImageSizeConfig(String name, int w, int h) {
this.name = name;
this.w = w;
this.h = h;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getW() {
return w;
}
public void setW(int w) {
this.w = w;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
}