|
9 | 9 | import com.cloudinary.Cloudinary; |
10 | 10 | import com.cloudinary.Singleton; |
11 | 11 |
|
12 | | -public class CloudinaryJsConfigTag extends SimpleTagSupport { |
13 | | - @SuppressWarnings("unused") |
| 12 | +public class CloudinaryJsConfigTag extends SimpleTagSupport { |
| 13 | + @SuppressWarnings("unused") |
14 | 14 | public void doTag() throws JspException, IOException { |
15 | 15 | Cloudinary cloudinary = Singleton.getCloudinary(); |
16 | 16 | if (cloudinary == null) { |
17 | 17 | throw new JspException("Cloudinary config could not be located"); |
18 | 18 | } |
19 | 19 | JspWriter out = getJspContext().getOut(); |
20 | 20 | 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 | + |
33 | 27 | out.println("});</script>"); |
34 | 28 | } |
35 | 29 |
|
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 | + } |
40 | 37 | } |
0 commit comments