External.java
4.81 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
156
157
158
159
160
161
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.xss.XSSAPI
* com.day.cq.wcm.api.Page
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.foundation;
import com.adobe.granite.xss.XSSAPI;
import com.day.cq.wcm.api.Page;
import java.io.IOException;
import java.io.PrintWriter;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class External {
private static final Logger log = LoggerFactory.getLogger(External.class);
public static final String PN_TARGET = "target";
public static final String PN_INCLUSION = "inclusion";
public static final String PN_LIMIT = "limit";
public static final String PN_PASSPARAMS = "passparams";
public static final String PN_WIDTH = "width";
public static final String PN_HEIGHT = "height";
public static final String PV_FIXED = "fixed";
protected final Resource resource;
protected final ValueMap properties;
protected final Node node;
protected final String pagePath;
protected final String resourcePath;
protected final String postSelector;
protected final String targetParam;
protected String target;
public External(Resource resource, Page page, String spoolSelector, String postSelector, String targetParam) {
if (null == resource) {
throw new IllegalArgumentException("resource may not be null");
}
this.resource = resource;
this.properties = (ValueMap)resource.adaptTo(ValueMap.class);
this.node = (Node)resource.adaptTo(Node.class);
this.pagePath = page.getPath();
this.resourcePath = resource.getPath() + "." + spoolSelector;
this.postSelector = postSelector;
this.targetParam = targetParam;
}
public Resource getResource() {
return this.resource;
}
public boolean hasContent() {
return this.getTarget() != null;
}
public String getTarget() {
if (this.target != null) {
return this.target;
}
return this.getStringProperty("target");
}
public void setTarget(String target) {
this.target = target;
}
public boolean passParameters() {
return "true".equals(this.getStringProperty("passparams"));
}
public boolean isFixed() {
return "fixed".equals(this.getStringProperty("inclusion"));
}
public String getWidth() {
return this.getStringProperty("width", "100%");
}
public String getHeight() {
return this.getStringProperty("height", "100%");
}
public Limit getLimit() {
String s = this.getStringProperty("limit");
if (s != null) {
try {
return Limit.valueOf(s.toUpperCase());
}
catch (IllegalArgumentException e) {
log.warn("Value of limit illegal: " + s);
}
}
return Limit.NO;
}
private String getStringProperty(String name) {
return this.getStringProperty(name, null);
}
private String getStringProperty(String name, String defaultValue) {
try {
if (this.node.hasProperty(name)) {
return this.node.getProperty(name).getString();
}
}
catch (RepositoryException e) {
log.warn("Unable to retrieve property " + name, (Throwable)e);
}
return defaultValue;
}
public void draw(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
String target = this.getTarget();
if (target == null) {
return;
}
XSSAPI xssapi = (XSSAPI)request.adaptTo(XSSAPI.class);
PrintWriter writer = response.getWriter();
writer.println("<iframe src=\"");
writer.println(xssapi.getValidHref(target));
writer.println("\" width=\"");
writer.println(this.getWidth());
writer.println("\" height=\"");
writer.println(this.getHeight());
writer.println("\"></iframe>");
}
public static enum Limit {
NO("no"),
HOST("host"),
OFF("off");
private final String value;
private Limit(String value) {
this.value = value;
}
public String toString() {
return this.value;
}
}
}