Skip to content

Commit 887b084

Browse files
authored
Merge pull request #107 from cloudinary/fix/jsconfigtag-boolean-value
Fix boolean config values in tag generation
2 parents afcda7f + fe17b05 commit 887b084

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,29 @@
99
import com.cloudinary.Cloudinary;
1010
import com.cloudinary.Singleton;
1111

12-
public class CloudinaryJsConfigTag extends SimpleTagSupport {
13-
@SuppressWarnings("unused")
12+
public class CloudinaryJsConfigTag extends SimpleTagSupport {
13+
@SuppressWarnings("unused")
1414
public void doTag() throws JspException, IOException {
1515
Cloudinary cloudinary = Singleton.getCloudinary();
1616
if (cloudinary == null) {
1717
throw new JspException("Cloudinary config could not be located");
1818
}
1919
JspWriter out = getJspContext().getOut();
2020
out.println("<script language='javascript' type='text/javascript'>$.cloudinary.config({");
21-
String[] keys = {"api_key", "cloud_name", "cdn_subdomain"};
22-
String[] boolKeys = {"private_cdn", "secure_distribution"};
23-
24-
print(out,"api_key",cloudinary.config.apiKey);
25-
print(out,"cloud_name",cloudinary.config.cloudName);
26-
print(out,"cdn_subdomain",cloudinary.config.cdnSubdomain);
27-
28-
print(out,"private_cdn",cloudinary.config.privateCdn);
29-
print(out,"secure_distribution",cloudinary.config.secureDistribution);
30-
31-
32-
21+
print(out, "api_key", cloudinary.config.apiKey);
22+
print(out, "cloud_name", cloudinary.config.cloudName);
23+
print(out, "cdn_subdomain", cloudinary.config.cdnSubdomain);
24+
print(out, "private_cdn", cloudinary.config.privateCdn);
25+
print(out, "secure_distribution", cloudinary.config.secureDistribution);
26+
3327
out.println("});</script>");
3428
}
3529

36-
private void print(JspWriter out, String key,Object value) throws IOException {
37-
out.println(key + ": \""+value + "\",");
38-
39-
}
30+
private void print(JspWriter out, String key, Object value) throws IOException {
31+
if (value instanceof Boolean) {
32+
out.println(key + ": " + ((Boolean) value ? "true" : "false") + ",");
33+
} else {
34+
out.println(key + ": \"" + value + "\",");
35+
}
36+
}
4037
}

0 commit comments

Comments
 (0)