HtmlLibraryImpl.java
5 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.http.HttpServletResponse
* org.apache.jackrabbit.util.Text
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.request.RequestPathInfo
*/
package com.adobe.granite.ui.clientlibs.impl;
import com.adobe.granite.ui.clientlibs.HtmlLibrary;
import com.adobe.granite.ui.clientlibs.LibraryType;
import com.adobe.granite.ui.clientlibs.impl.ClientLibraryImpl;
import com.adobe.granite.ui.clientlibs.impl.FileBundle;
import com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl;
import com.adobe.granite.ui.clientlibs.impl.ProcessorConfig;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestPathInfo;
public class HtmlLibraryImpl
implements HtmlLibrary {
private final String path;
private final String minifiedPath;
private final String rootPath;
private final LibraryType type;
private final FileBundle bundle;
private final FileBundle[] embedded;
private final HtmlLibraryManagerImpl mgr;
private final List<ProcessorConfig> processorConfigs;
protected HtmlLibraryImpl(HtmlLibraryManagerImpl mgr, ClientLibraryImpl library, LibraryType type, FileBundle bundle, FileBundle[] embedded) {
this.type = type;
this.rootPath = bundle.getRootPath();
this.path = library.getIncludePath(type);
this.minifiedPath = library.getIncludePath(type, true);
this.bundle = bundle;
this.embedded = embedded;
this.mgr = mgr;
this.processorConfigs = library.getProcessorConfig(type);
}
@Override
public String getPath() {
return this.path;
}
@Override
public String getPath(boolean minified) {
return minified ? this.minifiedPath : this.path;
}
@Override
public String getName() {
return Text.getName((String)this.path);
}
@Override
public String getName(boolean minified) {
return minified ? Text.getName((String)this.minifiedPath) : Text.getName((String)this.path);
}
@Override
public String getLibraryPath() {
return this.rootPath;
}
@Override
public LibraryType getType() {
return this.type;
}
@Override
public long getLastModified() {
return this.getLastModified(false);
}
@Override
public long getLastModified(boolean minified) {
return this.mgr.getLastModified(this, minified);
}
@Override
public void send(HttpServletResponse response, boolean gzip) throws IOException {
this.mgr.send(this, response, gzip, false);
}
@Override
public void send(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
this.mgr.send(this, request, response, HtmlLibraryImpl.hasMinificationSelector(request.getRequestPathInfo().getSelectors()));
}
protected static boolean hasMinificationSelector(String[] selectors) {
return selectors != null && selectors.length > 0 && ("min".equals(selectors[0]) || "min".equals(selectors[selectors.length - 1]));
}
protected List<ProcessorConfig> getProcessorConfigs() {
return this.processorConfigs;
}
@Override
public InputStream getInputStream() throws IOException {
return this.getInputStream(false);
}
@Override
public InputStream getInputStream(boolean minified) throws IOException {
return this.mgr.getInputStream(this, minified);
}
public FileBundle getBundle() {
return this.bundle;
}
public long getBundleLastModified() {
long lm = this.bundle.getLastModified();
if (this.embedded != null) {
for (FileBundle e : this.embedded) {
if (e.getLastModified() <= lm) continue;
lm = e.getLastModified();
}
}
return lm;
}
public FileBundle[] getEmbedded() {
return this.embedded;
}
@Override
public List<String> getScripts() {
LinkedList<String> list = new LinkedList<String>();
if (this.embedded != null) {
for (FileBundle bundle : this.embedded) {
for (String path : bundle.getFiles()) {
list.add(path);
}
}
}
for (String path : this.bundle.getFiles()) {
list.add(path);
}
return list;
}
@Override
public String getScripts(String delimiter) {
String d = "";
StringBuilder scripts = new StringBuilder();
for (String path : this.getScripts()) {
scripts.append(d).append("\"").append(path).append("\"");
d = delimiter;
}
return scripts.toString();
}
}