SetupProjectStep.java
4.14 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.xss.XSSAPI
* javax.jcr.ItemExistsException
* javax.jcr.Node
* javax.jcr.RepositoryException
* 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.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
*/
package com.day.cq.wcm.siteimporter.internal.steps;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.wcm.siteimporter.ImporterContext;
import com.day.cq.wcm.siteimporter.ImporterStep;
import com.day.cq.wcm.siteimporter.internal.steps.AbstractImporterStep;
import com.day.cq.wcm.siteimporter.internal.util.Utils;
import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
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.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
@Component(metatype=0)
@Service(value={ImporterStep.class})
@Properties(value={@Property(name="importerstep.order", intValue={100})})
public class SetupProjectStep
extends AbstractImporterStep {
@Reference
private XSSAPI xssApi;
@Override
public boolean execute(ImporterContext ctx) {
Node project;
ctx.output("Creating project " + this.xssApi.encodeForHTML(ctx.getProjectName()), "heading");
ctx.doIndent();
Resource appsRes = ctx.getResolver().getResource("/apps");
if (appsRes == null) {
ctx.error("Could not locate apps folder.");
ctx.undoIndent();
return false;
}
Node appsNode = (Node)appsRes.adaptTo(Node.class);
try {
project = Utils.createNode(appsNode, ctx.getProjectName(), "nt:folder", ctx);
}
catch (ItemExistsException e) {
if (ctx.isOverwrite()) {
try {
project = appsNode.getNode(ctx.getProjectName());
}
catch (RepositoryException ex) {
ctx.error("Repository failure: " + this.xssApi.encodeForHTML(ex.getMessage()), (Exception)e);
ctx.undoIndent();
return false;
}
}
ctx.error("Project folder already exists, remove or activate overwrite mode");
ctx.undoIndent();
return false;
}
catch (RepositoryException e) {
ctx.error("Repository failure: " + this.xssApi.encodeForHTML(e.getMessage()), (Exception)e);
ctx.undoIndent();
return false;
}
try {
ctx.addPath(project.getPath());
}
catch (RepositoryException e1) {
ctx.error("Could not add project path to context");
}
try {
Utils.createNode(project, "components", "nt:folder", ctx);
Utils.createNode(project, "templates", "nt:folder", ctx);
ctx.output("Created folder structure in " + this.xssApi.encodeForHTML(project.getPath()));
}
catch (ItemExistsException e) {
if (!ctx.isOverwrite()) {
ctx.error("Project folder already exists, remove or activate overwrite mode", (Exception)e);
ctx.undoIndent();
return false;
}
}
catch (RepositoryException e) {
ctx.error("Repository failure: " + this.xssApi.encodeForHTML(e.getMessage()), (Exception)e);
ctx.undoIndent();
return false;
}
ctx.output("Created folder structure in apps");
ctx.undoIndent();
return true;
}
protected void bindXssApi(XSSAPI xSSAPI) {
this.xssApi = xSSAPI;
}
protected void unbindXssApi(XSSAPI xSSAPI) {
if (this.xssApi == xSSAPI) {
this.xssApi = null;
}
}
}