ClientLib.java
3.64 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.widget.ClientLibrary
* com.day.cq.widget.HtmlLibrary
* com.day.cq.widget.HtmlLibraryManager
* com.day.cq.widget.LibraryType
* org.apache.commons.io.IOUtils
* org.apache.commons.lang3.StringUtils
*/
package com.adobe.granite.contexthub.impl;
import com.day.cq.widget.ClientLibrary;
import com.day.cq.widget.HtmlLibrary;
import com.day.cq.widget.HtmlLibraryManager;
import com.day.cq.widget.LibraryType;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class ClientLib {
private LibraryType libraryType;
private boolean debugMode;
private HtmlLibraryManager htmlLibraryManager;
private boolean minified;
public ClientLib(HtmlLibraryManager htmlLibraryManager, LibraryType libraryType, boolean debugMode) {
this.htmlLibraryManager = htmlLibraryManager;
this.libraryType = libraryType;
this.debugMode = debugMode;
this.minified = false;
}
public HtmlLibraryManager getHtmlLibraryManager() {
return this.htmlLibraryManager;
}
public Collection<ClientLibrary> getLibraries(List<String> categories) {
return this.getLibraries(categories.toArray(new String[categories.size()]));
}
public Collection<ClientLibrary> getLibraries(String[] categories) {
return this.htmlLibraryManager.getLibraries(categories, this.libraryType, false, true);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public String getContent(ClientLibrary clientLibrary) {
StringBuilder content;
block9 : {
content = new StringBuilder();
if (clientLibrary == null) {
return content.toString();
}
HtmlLibrary htmlLibrary = this.htmlLibraryManager.getLibrary(this.libraryType, clientLibrary.getPath());
if (htmlLibrary != null) {
InputStream is = null;
StringWriter writer = new StringWriter();
try {
is = htmlLibrary.getInputStream(this.minified);
IOUtils.copy((InputStream)is, (Writer)writer);
content.append(writer.toString().trim());
content.append("\n");
}
catch (IOException err) {
if (this.debugMode) {
content.append(String.format("\n/* Error while preparing library '%s' */\n", clientLibrary.getPath()));
}
break block9;
}
finally {
IOUtils.closeQuietly((InputStream)is);
}
}
if (this.debugMode) {
content.append(String.format("\n/* Can't find library '%s' */\n", clientLibrary.getPath()));
}
}
return content.toString();
}
protected long getLastModified(ClientLibrary clientLibrary) {
return this.getLibraryInfo(clientLibrary).getLastModified(this.minified);
}
public HtmlLibrary getLibraryInfo(ClientLibrary clientLibrary) {
return this.htmlLibraryManager.getLibrary(this.libraryType, clientLibrary.getPath());
}
public static /* varargs */ String buildClientlibName(String ... parts) {
return "contexthub." + StringUtils.join((Object[])parts, (String)".");
}
}