CLIDownloadServlet.java
6.6 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.ui.components.HtmlResponse
* com.adobe.granite.xss.XSSAPI
* com.day.cq.contentsync.config.Config
* com.day.cq.i18n.I18n
* javax.jcr.Session
* javax.servlet.ServletException
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.request.RequestPathInfo
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.platform.impl.servlets;
import com.adobe.cq.mobile.appcache.impl.AppCacheManager;
import com.adobe.cq.mobile.appcache.impl.AppCacheManagerAdapterFactory;
import com.adobe.cq.mobile.platform.MobileResource;
import com.adobe.cq.mobile.platform.MobileResourceType;
import com.adobe.cq.mobile.platform.impl.utils.MobileUtil;
import com.adobe.granite.ui.components.HtmlResponse;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.contentsync.config.Config;
import com.day.cq.i18n.I18n;
import java.io.IOException;
import java.util.Locale;
import javax.jcr.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, label="AEM Mobile Generate CLI Servlet")
@Service
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"cq:Page"}, propertyPrivate=1), @Property(name="sling.servlet.methods", value={"GET"}, propertyPrivate=1), @Property(name="sling.servlet.extensions", value={"zip"}, propertyPrivate=1), @Property(name="sling.servlet.selectors", value={"cli", "cli-dev"}, propertyPrivate=1)})
public class CLIDownloadServlet
extends SlingAllMethodsServlet {
@Reference
private XSSAPI xssAPI;
@Reference
private AppCacheManagerAdapterFactory appCacheManagerAdapterFactory;
protected static final Logger log = LoggerFactory.getLogger(CLIDownloadServlet.class);
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String configPath;
I18n i18n = new I18n((HttpServletRequest)request);
HtmlResponse htmlResponse = new HtmlResponse(this.xssAPI, i18n, request.getLocale());
Resource resource = request.getResource();
MobileResource mobileResource = (MobileResource)resource.adaptTo(MobileResource.class);
if (!mobileResource.isA(MobileResourceType.INSTANCE.getType())) {
String message = i18n.get("The resource {0} must be of type pge-instance", null, new Object[]{resource.getPath()});
htmlResponse.setPath(resource.getPath());
htmlResponse.setStatus(500, message);
htmlResponse.send((HttpServletResponse)response, true);
return;
}
String configProperty = "phonegap-build-exportTemplate";
String selector = request.getRequestPathInfo().getSelectorString();
if ("cli-dev".equals(selector)) {
configProperty = "phonegap-build-exportTemplate-dev";
}
if (StringUtils.isBlank((CharSequence)(configPath = (String)mobileResource.getProperties().get(configProperty, String.class)))) {
Object[] args = new String[]{resource.getPath(), configProperty};
String message = i18n.get("The resource {0} does not have property {1} set", null, args);
htmlResponse.setPath(resource.getPath());
htmlResponse.setStatus(500, message);
htmlResponse.send((HttpServletResponse)response, true);
return;
}
Resource contentResource = request.getResourceResolver().getResource(mobileResource.getPath() + "/" + "jcr:content");
configPath = MobileUtil.normalizePath(configPath, contentResource);
try {
ResourceResolver resourceResolver = request.getResourceResolver();
Session session = (Session)resourceResolver.adaptTo(Session.class);
AppCacheManager appCacheManager = this.appCacheManagerAdapterFactory.getAdapter((Object)session, AppCacheManager.class);
Resource configResource = resourceResolver.getResource(configPath);
Config buildConfig = (Config)configResource.adaptTo(Config.class);
appCacheManager.clearCache(buildConfig);
appCacheManager.fillCache(buildConfig);
}
catch (Exception ex) {
String message = i18n.get("Failed to clear and fill build cache", null);
log.error(message, (Throwable)ex);
htmlResponse.setPath(resource.getPath());
htmlResponse.setStatus(500, message);
htmlResponse.send((HttpServletResponse)response, true);
return;
}
response.sendRedirect(request.getContextPath() + configPath + ".zip");
}
protected void bindXssAPI(XSSAPI xSSAPI) {
this.xssAPI = xSSAPI;
}
protected void unbindXssAPI(XSSAPI xSSAPI) {
if (this.xssAPI == xSSAPI) {
this.xssAPI = null;
}
}
protected void bindAppCacheManagerAdapterFactory(AppCacheManagerAdapterFactory appCacheManagerAdapterFactory) {
this.appCacheManagerAdapterFactory = appCacheManagerAdapterFactory;
}
protected void unbindAppCacheManagerAdapterFactory(AppCacheManagerAdapterFactory appCacheManagerAdapterFactory) {
if (this.appCacheManagerAdapterFactory == appCacheManagerAdapterFactory) {
this.appCacheManagerAdapterFactory = null;
}
}
}