CreateCampaignStep.java
2.4 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.WCMException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ResourceResolver
*/
package com.day.cq.wcm.siteimporter.internal.steps;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.siteimporter.ImporterContext;
import com.day.cq.wcm.siteimporter.ImporterStep;
import com.day.cq.wcm.siteimporter.internal.steps.AbstractImporterStep;
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.Service;
import org.apache.sling.api.resource.ResourceResolver;
@Component(metatype=0)
@Service(value={ImporterStep.class})
@Properties(value={@Property(name="importerstep.order", intValue={700})})
public class CreateCampaignStep
extends AbstractImporterStep {
@Override
public boolean execute(ImporterContext ctx) {
ctx.output("Creating Campaigns Folder", "heading");
ctx.doIndent();
PageManager pm = (PageManager)ctx.getResolver().adaptTo(PageManager.class);
try {
String name = JcrUtil.createValidName((String)ctx.getProjectName());
Page campaign = pm.getPage("/content/campaigns/" + name);
if (campaign != null) {
if (ctx.isOverwrite()) {
pm.delete(campaign, false);
} else {
ctx.error("Campaign already exists, maybe tick overwrite option");
return false;
}
}
campaign = pm.create("/content/campaigns", name, "/libs/cq/personalization/templates/campaign", ctx.getProjectName());
ctx.addPath(campaign.getPath());
}
catch (WCMException e) {
ctx.error("Couldn't create campaign: " + e.getMessage(), (Exception)e);
ctx.undoIndent();
return false;
}
ctx.output("Created campaigns folder");
ctx.undoIndent();
return true;
}
}