CSSUtils.java
2.37 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang.StringUtils
*/
package com.adobe.aemds.guide.internal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
public class CSSUtils {
private Pattern urlFunctionPattern = Pattern.compile("(\\burl\\(\\s*['\"]?)(.*?)(\\s*['\"]?\\))", 2);
private Pattern absolutePathPattern = Pattern.compile("^[a-z]*?:?//.*|^/.*", 2);
private Pattern urlPattern = Pattern.compile("^[a-z]*?:?//.*");
public String processUrls(String CSS, String contextPath, String absolutePath) {
if (StringUtils.isNotBlank((String)CSS) && StringUtils.isNotBlank((String)absolutePath)) {
StringBuffer updatedUrlString = new StringBuffer();
Matcher matcher = this.urlFunctionPattern.matcher(CSS);
while (matcher.find()) {
String url_prefix = matcher.group(1);
String path = matcher.group(2);
String absolute_path = this.prependContextPath(this.makePathAbsolute(path, absolutePath), contextPath);
String url_suffix = matcher.group(3);
matcher.appendReplacement(updatedUrlString, url_prefix + absolute_path + url_suffix);
}
matcher.appendTail(updatedUrlString);
return updatedUrlString.toString();
}
return CSS;
}
public boolean isAbsolutePath(String path) {
if (StringUtils.isEmpty((String)path)) {
return true;
}
path = path.trim();
Matcher matcher = this.absolutePathPattern.matcher(path);
return matcher.find();
}
public String makePathAbsolute(String path, String relativeTo) {
if (this.isAbsolutePath(path)) {
return path;
}
return relativeTo + "/" + path;
}
public String prependContextPath(String absolutePath, String contextPath) {
if (!StringUtils.isEmpty((String)contextPath) && !this.isAbsoluteURL(absolutePath)) {
return contextPath + "" + absolutePath;
}
return absolutePath;
}
public boolean isAbsoluteURL(String path) {
if (StringUtils.isEmpty((String)path)) {
return true;
}
path = path.trim();
Matcher matcher = this.urlPattern.matcher(path);
return matcher.find();
}
}