PagePayloadInfoBuilder.java
3.45 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.workflow.exec.InboxItem
* com.adobe.granite.workflow.payload.PayloadInfo
* com.adobe.granite.workflow.payload.PayloadInfoBuilder
* com.adobe.granite.workflow.payload.PayloadInfoBuilderContext
* com.day.cq.wcm.api.Page
* javax.jcr.Node
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.workflow.impl;
import com.adobe.granite.workflow.exec.InboxItem;
import com.adobe.granite.workflow.payload.PayloadInfo;
import com.adobe.granite.workflow.payload.PayloadInfoBuilder;
import com.adobe.granite.workflow.payload.PayloadInfoBuilderContext;
import com.day.cq.wcm.api.Page;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={PayloadInfoBuilder.class})
@Property(name="service.ranking", intValue={-1000}, propertyPrivate=1)
public class PagePayloadInfoBuilder
implements PayloadInfoBuilder {
private static final Logger log = LoggerFactory.getLogger(PagePayloadInfoBuilder.class);
public static final String TYPE_JCR_PATH = "JCR_PATH";
public static final String CONTENT_FINDER_SHORTCUT = "/bin/wcmcommand?cmd=open&path=";
public static final String CHARSET = "_charset_=utf-8";
public static final String DIRECTORY_ADMIN_SHORTCUT = "/sites.html";
public PayloadInfo getPayloadInfo(PayloadInfoBuilderContext context) {
String payloadPath = null;
payloadPath = context.getInboxItem() != null ? context.getInboxItem().getContentPath() : context.getPayloadPath();
String browserPath = null;
Resource resource = context.getResourceResolver().getResource(payloadPath);
if (resource != null && resource.adaptTo(Node.class) != null && resource.getPath().startsWith("/content") && !resource.getPath().startsWith("/content/dam")) {
try {
if (((Node)resource.adaptTo(Node.class)).isNodeType("nt:folder")) {
browserPath = "/sites.html" + resource.getPath();
}
}
catch (RepositoryException e) {
log.warn("exception in buildpath", (Throwable)e);
}
}
if (resource != null && resource.adaptTo(Page.class) != null) {
browserPath = "/bin/wcmcommand?cmd=open&path=" + this.encodeURIComponent(resource.getPath()) + "&" + "_charset_=utf-8";
}
if (browserPath != null) {
PayloadInfo payloadInfo = context.createPayloadInfo();
payloadInfo.setPath(payloadPath).setBrowserPath(browserPath);
return payloadInfo;
}
return null;
}
private String encodeURIComponent(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}