DynamicMediaHelper.java
2.72 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.dam.dm.delivery.api.ImageDelivery
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
* org.osgi.framework.Bundle
* org.osgi.framework.BundleContext
* org.osgi.framework.BundleReference
* org.osgi.framework.ServiceReference
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.commons.util;
import com.adobe.cq.dam.dm.delivery.api.ImageDelivery;
import java.util.Collections;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleReference;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DynamicMediaHelper {
private static final String DYNAMIC_MEDIA_CONFIG_PATH = "/etc/dam/dynamicmediaconfig";
private static final String PN_DYNAMIC_MEDIA_ENABLED = "dynamicMediaEnabled";
private static final Logger LOG = LoggerFactory.getLogger(DynamicMediaHelper.class);
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Deprecated
public static boolean isDynamicMediaEnabled(ResourceResolver resolver) {
BundleContext ctx = BundleReference.class.cast(ImageDelivery.class.getClassLoader()).getBundle().getBundleContext();
ServiceReference serviceReference = ctx.getServiceReference(ImageDelivery.class.getName());
ImageDelivery service = ImageDelivery.class.cast(ctx.getService(serviceReference));
try {
boolean bl = service != null && service.isEnabled();
return bl;
}
finally {
ctx.ungetService(serviceReference);
}
}
private static ValueMap getDynamicMediaConfigurationProperties(ResourceResolver resolver) {
ValueMap configProps = null;
try {
Resource dmConfigResource = resolver.getResource("/etc/dam/dynamicmediaconfig");
if (dmConfigResource != null) {
configProps = (ValueMap)dmConfigResource.adaptTo(ValueMap.class);
}
}
catch (Exception e) {
LOG.error("Could not read the Dynamic Media configuration from node /etc/dam/dynamicmediaconfig", (Throwable)e);
}
if (configProps == null) {
configProps = new ValueMapDecorator(Collections.emptyMap());
}
return configProps;
}
}