JCRExplorerServlet.java
8.04 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.crx.i18n.LanguageManager
* javax.jcr.Credentials
* javax.jcr.PropertyType
* javax.jcr.Repository
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.nodetype.NodeType
* javax.servlet.ServletContext
* javax.servlet.ServletException
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* javax.servlet.http.HttpSession
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Reference
* org.apache.jackrabbit.util.Text
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.framework.Bundle
* org.osgi.framework.BundleContext
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.crx.explorer.impl.j2ee;
import com.day.crx.explorer.impl.j2ee.CRXContext;
import com.day.crx.explorer.impl.j2ee.CRXSessionCache;
import com.day.crx.explorer.impl.j2ee.LoginServlet;
import com.day.crx.explorer.impl.j2ee.RelaxedUTF8Decoder;
import com.day.crx.i18n.LanguageManager;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import javax.jcr.Credentials;
import javax.jcr.PropertyType;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.jackrabbit.util.Text;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1)
public class JCRExplorerServlet {
private static JCRExplorerServlet instance;
private static Logger log;
public static final String CTX_ATTR_TMP_DIRECTORY = "crx.explorer.tmpdir";
public static final String CTX_ATTR_CHECKER_UPDATE_URL = "crx.explorer.checker.updateurl";
public static final String CTX_ATTR_SUPPORT_EMAIL = "crx.explorer.support.email";
public static final String PARAM_USER = "UserId";
public static final String S_ATTR_CRX_SESSION_ID = "CRX_SESSION_ID";
public static final String NT_PREFIX = "/imgs/nodetypes/";
public static final String PT_PREFIX = "/imgs/pt/";
public static final String REP_VERSION_DISPLAY_DESC = "jcr.repository.version.display";
@Reference
private SlingRepository repository = null;
private final CRXSessionCache sessionCache;
public JCRExplorerServlet() {
this.sessionCache = new CRXSessionCache(this);
}
@Activate
protected void activate(ComponentContext ctx) {
instance = this;
LoginServlet.initRepositoryId((Repository)this.repository);
try {
URL url = ctx.getBundleContext().getBundle().getResource("/languages/en.properties");
LanguageManager.getInstance().addTranslation(Locale.ENGLISH, url);
}
catch (IOException e) {
log.error("Error while adding languages:" + e.toString());
}
LanguageManager.getInstance();
}
@Deactivate
protected void deactivate() {
this.sessionCache.logoutAll();
instance = null;
}
public Repository getRepository() {
if (this.repository == null) {
log.warn("Repository not available yet.");
}
return this.repository;
}
public CRXSessionCache getSessionCache() {
return this.sessionCache;
}
public static File getTempDirectory(ServletContext ctx) {
return (File)ctx.getAttribute("crx.explorer.tmpdir");
}
public static String getVersion() {
try {
return JCRExplorerServlet.getInstance().getRepository().getDescriptor("jcr.repository.version");
}
catch (IllegalStateException e) {
return "";
}
}
public static String getProductVersion() {
try {
String ret = JCRExplorerServlet.getInstance().getRepository().getDescriptor("jcr.repository.version.display");
if (ret == null) {
ret = JCRExplorerServlet.getVersion();
}
return ret;
}
catch (Exception e) {
return "";
}
}
public static String getCrxUpdateUrl(ServletContext ctx) {
return (String)ctx.getAttribute("crx.explorer.checker.updateurl");
}
public static String getCrxSupportEmail(ServletContext ctx) {
return (String)ctx.getAttribute("crx.explorer.support.email");
}
public static JCRExplorerServlet getInstance() {
return instance;
}
public static Session login(HttpServletRequest req, Credentials creds, String workspace) throws RepositoryException {
return JCRExplorerServlet.getInstance().sessionCache.login(req, creds, workspace);
}
public static Session login(CRXContext ctx, HttpServletResponse response) throws RepositoryException, ServletException {
return JCRExplorerServlet.getInstance().sessionCache.login(ctx, response);
}
public static Session switchWorkspace(HttpServletRequest req, String workspace) throws RepositoryException {
return JCRExplorerServlet.getInstance().sessionCache.switchWorkspace(req, workspace);
}
public static Session impersonate(HttpServletRequest req, String userId) throws RepositoryException {
return JCRExplorerServlet.getInstance().sessionCache.impersonate(req, userId);
}
public static void logout(HttpServletRequest req, HttpServletResponse response) {
LoginServlet.setLoginCookies(null, req, response);
HttpSession httpSession = req.getSession(false);
if (httpSession != null) {
httpSession.removeAttribute("CRX_SESSION_ID");
}
}
public static Session getDefaultSession(HttpServletRequest req) {
return JCRExplorerServlet.getInstance().sessionCache.getDefaultSession(req);
}
public static Session getSession(HttpServletRequest req) {
return JCRExplorerServlet.getInstance().sessionCache.getSession(req);
}
public static String getNTIcon(NodeType nt) {
return JCRExplorerServlet.getNTIcon(nt.getName());
}
public static String getNTIcon(String ntName) {
return "/imgs/nodetypes/" + Text.encodeIllegalXMLCharacters((String)ntName).replace(':', '/') + ".gif";
}
public static String getPTIcon(int propertyType) {
return "/imgs/pt/" + PropertyType.nameFromValue((int)propertyType).toLowerCase() + ".gif";
}
public static String getPTIcon(String propertyType) {
return "/imgs/pt/" + propertyType.toLowerCase() + ".gif";
}
public ServletContext getServletContext() {
return null;
}
public static String getServletPath(HttpServletRequest request) {
String ctx;
String path = RelaxedUTF8Decoder.unescape(request.getRequestURI());
if (path.startsWith(ctx = request.getContextPath())) {
path = path.substring(ctx.length());
}
return path;
}
public static String getDocrootPrefix(HttpServletRequest request) {
String prefix = request.getContextPath();
if (prefix.equals("/")) {
prefix = "";
}
return prefix + "/crx/explorer";
}
static {
log = LoggerFactory.getLogger(JCRExplorerServlet.class);
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
}