ProjectWizard.java
5.29 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.projects.api.Project
* com.adobe.granite.ui.components.ComponentHelper
* com.adobe.granite.ui.components.Config
* com.adobe.granite.ui.components.ExpressionHelper
* com.day.cq.wcm.api.Template
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.request.RequestPathInfo
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
*/
package com.adobe.cq.projects.ui;
import com.adobe.cq.projects.api.Project;
import com.adobe.granite.ui.components.ComponentHelper;
import com.adobe.granite.ui.components.Config;
import com.adobe.granite.ui.components.ExpressionHelper;
import com.day.cq.wcm.api.Template;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
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.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
public class ProjectWizard {
private SlingHttpServletRequest slingRequest;
private ComponentHelper helper;
private ValueMap values = null;
public static final String PROJECT_VALUES_ATTRIBUTE = "cq.ui.project.values";
private static final String WIZARD_PAGE_RT = "cq/gui/components/projects/admin/wizard/page";
private static final String PARAM_PROJECT = "project";
public ProjectWizard(SlingHttpServletRequest slingRequest, ComponentHelper helper) {
this.slingRequest = slingRequest;
this.helper = helper;
if (slingRequest == null || helper == null) {
throw new IllegalArgumentException("A valid SlingHttpServletRequest and ComponentHelper must be provided.");
}
ValueMap projectValues = (ValueMap)slingRequest.getAttribute("cq.ui.project.values");
if (projectValues == null) {
Project project;
projectValues = new ValueMapDecorator(new HashMap());
ResourceResolver resolver = this.slingRequest.getResourceResolver();
String projectPath = slingRequest.getParameter("project");
if (StringUtils.isBlank((CharSequence)projectPath)) {
projectPath = slingRequest.getRequestPathInfo().getSuffix();
}
Resource projectResource = null;
if (StringUtils.isNotBlank((CharSequence)projectPath)) {
projectResource = resolver.getResource(projectPath);
}
if (projectResource != null && (project = (Project)projectResource.adaptTo(Project.class)) != null) {
Template projectTemplate;
Resource assetFolder;
projectValues.put((Object)"project", (Object)((Resource)project.adaptTo(Resource.class)).getPath());
projectValues.put((Object)"projectTitle", (Object)project.getTitle());
Resource projectCover = project.getProjectCover();
if (projectCover != null && !ResourceUtil.isNonExistingResource((Resource)projectCover)) {
projectValues.put((Object)"projectCover", (Object)projectCover.getParent());
}
if ((assetFolder = project.getAssetFolder()) != null && !ResourceUtil.isNonExistingResource((Resource)assetFolder)) {
projectValues.put((Object)"projectAssetFolderPath", (Object)assetFolder.getPath());
}
if ((projectTemplate = (Template)project.adaptTo(Template.class)) != null) {
projectValues.put((Object)"projectTemplatePath", (Object)projectTemplate.getPath());
}
this.slingRequest.setAttribute("cq.ui.project.values", (Object)projectValues);
}
}
this.values = projectValues;
}
public ValueMap getWizardValues(Resource resource) {
Resource wizardPage;
for (wizardPage = resource; wizardPage != null && !wizardPage.isResourceType("cq/gui/components/projects/admin/wizard/page"); wizardPage = wizardPage.getParent()) {
}
if (wizardPage == null) {
return null;
}
Config wizardCfg = new Config(wizardPage);
String[] wizardParams = (String[])wizardCfg.get("params", String[].class);
ValueMapDecorator wizardValues = new ValueMapDecorator(new HashMap());
if (wizardParams != null) {
for (String param : wizardParams) {
String[] p = param.replaceAll("[${}]", "").split("\\.");
if (p == null || p.length != 2) continue;
String paramValue = this.helper.getExpressionHelper().getString(param);
if (StringUtils.isBlank((CharSequence)paramValue)) {
paramValue = (String)this.values.get(p[1], String.class);
}
wizardValues.put((Object)p[1], (Object)paramValue);
}
}
return wizardValues;
}
public ValueMap getProjectValues() {
return this.values;
}
}