CreateBlueprintStep.java
6.64 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.ImageHelper
* com.day.image.Layer
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Workspace
* 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.request.RequestParameter
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
*/
package com.day.cq.wcm.siteimporter.internal.steps;
import com.day.cq.commons.ImageHelper;
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 com.day.image.Layer;
import java.awt.Color;
import java.awt.Paint;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
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.request.RequestParameter;
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={600})})
public class CreateBlueprintStep
extends AbstractImporterStep {
private static final String SHADOW_RESOURCE = "/libs/wcm/siteimporter/resources/shadow.png";
private static final String BLUEPRINT_RESOURCE = "/libs/wcm/siteimporter/resources/blueprintlogo.png";
@Override
public boolean execute(ImporterContext ctx) {
ctx.output("Creating Blueprint", "heading");
ctx.doIndent();
try {
Node rootNode = (Node)ctx.getResolver().getResource("/etc/blueprints").adaptTo(Node.class);
if (rootNode.hasNode(ctx.getProjectName())) {
if (ctx.isOverwrite()) {
rootNode.getNode(ctx.getProjectName()).remove();
rootNode.getSession().save();
} else {
ctx.error("Could not create template, maybe tick overwrite option");
ctx.undoIndent();
return false;
}
}
rootNode.getSession().getWorkspace().copy("/etc/blueprints/geometrixx", "/etc/blueprints/" + ctx.getProjectName());
}
catch (Exception e) {
ctx.error("Couldn't copy geometrixx blueprint: " + e.getMessage(), e);
ctx.undoIndent();
return false;
}
ctx.output("Copied Geometrixx Blueprint as foundation");
Resource blueprintRes = ctx.getResolver().getResource("/etc/blueprints/" + ctx.getProjectName());
ctx.addPath(blueprintRes.getPath());
Resource contentRes = ctx.getResolver().getResource("/etc/blueprints/" + ctx.getProjectName() + "/" + "jcr:content");
if (contentRes == null) {
ctx.error("Couldn't access Blueprint Content");
ctx.undoIndent();
return false;
}
Node content = (Node)contentRes.adaptTo(Node.class);
try {
content.setProperty("jcr:description", "Blueprint that uses the " + ctx.getTitle() + " Site as original.");
content.setProperty("jcr:title", ctx.getTitle() + " Site");
content.setProperty("sitePath", "/content/" + ctx.getProjectName());
content.getNode("dialog").setProperty("title", ctx.getTitle() + " Blueprint");
content.getNode("thumbnail").remove();
content.getParent().getSession().save();
}
catch (Exception e) {
ctx.error("Couldn't adapt properties of new Blueprint: " + e.getMessage(), e);
ctx.undoIndent();
return false;
}
ctx.output("Adapted Blueprint Properties");
if (!"".equals(ctx.getThumbnail().getString())) {
Layer bg = new Layer(200, 167, (Paint)new Color(33554431, true));
int y = 46;
for (int x = 5; x < 60; x += 23) {
Layer shadow = ImageHelper.createLayer((Resource)ctx.getResolver().getResource("/libs/wcm/siteimporter/resources/shadow.png"));
if (shadow == null) {
ctx.error("Couldn't read shadow file; skipped thumbnail creation");
ctx.undoIndent();
return true;
}
shadow.setX(x);
shadow.setY(y);
bg.merge(shadow);
Resource thumbnail = ctx.getResolver().getResource("/apps/" + ctx.getProjectName() + "/templates/contentpage/thumbnail.png");
Layer preview = ImageHelper.createLayer((Resource)thumbnail);
if (preview == null) {
ctx.error("Couldn't read preview file; skipped thumbnail creation");
ctx.undoIndent();
return true;
}
preview.setX(x + 5);
preview.setY(y + 5);
bg.merge(preview);
y -= 18;
}
Layer logo = ImageHelper.createLayer((Resource)ctx.getResolver().getResource("/libs/wcm/siteimporter/resources/blueprintlogo.png"));
if (logo == null) {
ctx.error("Couldn't read logo file; skipped thumbnail creation");
ctx.undoIndent();
return true;
}
logo.setX(138);
logo.setY(104);
bg.merge(logo);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
bg.write("images/png", 1.0, (OutputStream)out);
byte[] bytes = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Utils.createFile(content, "thumbnail", in, "image/png", ctx);
}
catch (RepositoryException e) {
ctx.error("Repository Exception during storage of Thumbnail: " + e.getMessage(), (Exception)e);
}
catch (Exception e) {
ctx.error("Couldn't store Thumbnail: " + e.getMessage(), e);
}
ctx.output("Created Preview image");
} else {
ctx.output("No preview image available", "skip");
}
ctx.undoIndent();
return true;
}
}