Skip to content

Commit 4602c3c

Browse files
committed
add support for local secure (and implicit from request) and cdn_subdomain
1 parent a530e5c commit 4602c3c

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

cloudinary-taglib/src/main/java/com/cloudinary/taglib/CloudinaryImageTag.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7+
import javax.servlet.ServletRequest;
78
import javax.servlet.jsp.JspException;
89
import javax.servlet.jsp.JspWriter;
10+
import javax.servlet.jsp.PageContext;
911
import javax.servlet.jsp.tagext.DynamicAttributes;
1012
import javax.servlet.jsp.tagext.SimpleTagSupport;
1113

@@ -37,6 +39,9 @@ public class CloudinaryImageTag extends SimpleTagSupport implements DynamicAttri
3739

3840
private String transformation = null;
3941

42+
private Boolean secure = null;
43+
private Boolean cdnSubdomain = null;
44+
4045
/** stores the dynamic attributes */
4146
private Map<String,Object> tagAttrs = new HashMap<String,Object>();
4247

@@ -64,6 +69,12 @@ public void doTag() throws JspException, IOException {
6469
if (format != null) url.format(format);
6570
if (type != null) url.type(type);
6671
if (resourceType != null) url.resourceType(resourceType);
72+
if (secure != null) {
73+
url.secure(secure.booleanValue());
74+
} else if(Boolean.TRUE.equals(isSecureRequest())) {
75+
url.secure(true);
76+
}
77+
if (cdnSubdomain != null) url.cdnSubdomain(cdnSubdomain.booleanValue());
6778

6879
out.println(url.imageTag(src, attributes));
6980
}
@@ -134,8 +145,31 @@ public void setTransformation(String transformation) {
134145
this.transformation = transformation.replaceAll("\\s+","/");
135146
}
136147

148+
public Boolean getSecure() {
149+
return secure;
150+
}
151+
152+
public void setSecure(Boolean secure) {
153+
this.secure = secure;
154+
}
155+
156+
public Boolean getCdnSubdomain() {
157+
return cdnSubdomain;
158+
}
159+
160+
public void setCdnSubdomain(Boolean cdnSubdomain) {
161+
this.cdnSubdomain = cdnSubdomain;
162+
}
163+
137164
@Override
138165
public void setDynamicAttribute(String uri, String name, Object value) throws JspException {
139166
tagAttrs.put(name, value);
140167
}
168+
169+
private Boolean isSecureRequest() {
170+
PageContext context = (PageContext) getJspContext();
171+
if (context == null) return null;
172+
ServletRequest request = context.getRequest();
173+
return request.getScheme().equals("https");
174+
}
141175
}

cloudinary-taglib/src/main/java/com/cloudinary/taglib/CloudinaryUrl.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7+
import javax.servlet.ServletRequest;
78
import javax.servlet.jsp.JspException;
89
import javax.servlet.jsp.JspWriter;
10+
import javax.servlet.jsp.PageContext;
911
import javax.servlet.jsp.tagext.DynamicAttributes;
1012
import javax.servlet.jsp.tagext.SimpleTagSupport;
1113

@@ -26,6 +28,9 @@ public class CloudinaryUrl extends SimpleTagSupport implements DynamicAttributes
2628

2729
private String transformation = null;
2830

31+
private Boolean secure = null;
32+
private Boolean cdnSubdomain = null;
33+
2934
/** stores the dynamic attributes */
3035
private Map<String,Object> tagAttrs = new HashMap<String,Object>();
3136

@@ -43,6 +48,12 @@ public void doTag() throws JspException, IOException {
4348
if (format != null) url.format(format);
4449
if (type != null) url.type(type);
4550
if (resourceType != null) url.resourceType(resourceType);
51+
if (secure != null) {
52+
url.secure(secure.booleanValue());
53+
} else if(Boolean.TRUE.equals(isSecureRequest())) {
54+
url.secure(true);
55+
}
56+
if (cdnSubdomain != null) url.cdnSubdomain(cdnSubdomain.booleanValue());
4657

4758
out.println(url.generate(src));
4859
}
@@ -88,8 +99,31 @@ public void setTransformation(String transformation) {
8899
this.transformation = transformation.replaceAll("\\s","/");
89100
}
90101

102+
public Boolean getSecure() {
103+
return secure;
104+
}
105+
106+
public void setSecure(Boolean secure) {
107+
this.secure = secure;
108+
}
109+
110+
public Boolean getCdnSubdomain() {
111+
return cdnSubdomain;
112+
}
113+
114+
public void setCdnSubdomain(Boolean cdnSubdomain) {
115+
this.cdnSubdomain = cdnSubdomain;
116+
}
117+
91118
@Override
92119
public void setDynamicAttribute(String uri, String name, Object value) throws JspException {
93120
tagAttrs.put(name, value);
94121
}
122+
123+
private Boolean isSecureRequest() {
124+
PageContext context = (PageContext) getJspContext();
125+
if (context == null) return null;
126+
ServletRequest request = context.getRequest();
127+
return request.getScheme().equals("https");
128+
}
95129
}

cloudinary-taglib/src/main/resources/META-INF/cloudinary.tld

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@
186186
<required>false</required>
187187
<rtexprvalue>true</rtexprvalue>
188188
</attribute>
189+
<attribute>
190+
<name>secure</name>
191+
<required>false</required>
192+
<rtexprvalue>true</rtexprvalue>
193+
</attribute>
194+
<attribute>
195+
<name>cdnSubdomain</name>
196+
<required>false</required>
197+
<rtexprvalue>true</rtexprvalue>
198+
</attribute>
189199
<dynamic-attributes>true</dynamic-attributes>
190200
</tag>
191201
<tag>
@@ -217,6 +227,16 @@
217227
<required>false</required>
218228
<rtexprvalue>true</rtexprvalue>
219229
</attribute>
230+
<attribute>
231+
<name>secure</name>
232+
<required>false</required>
233+
<rtexprvalue>true</rtexprvalue>
234+
</attribute>
235+
<attribute>
236+
<name>cdnSubdomain</name>
237+
<required>false</required>
238+
<rtexprvalue>true</rtexprvalue>
239+
</attribute>
220240
<dynamic-attributes>true</dynamic-attributes>
221241
</tag>
222242
<tag>

0 commit comments

Comments
 (0)