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 package info.magnolia.templating.imaging.parameters;
35
36 import info.magnolia.cms.beans.runtime.FileProperties;
37 import info.magnolia.jcr.util.PropertyUtil;
38 import info.magnolia.module.site.SiteModule;
39 import info.magnolia.objectfactory.Components;
40 import info.magnolia.templating.imaging.VariationAwareImagingSupport;
41 import info.magnolia.templating.imaging.variation.ImageOperationProvidingVariation;
42
43 import javax.jcr.Binary;
44 import javax.jcr.Node;
45 import javax.jcr.RepositoryException;
46
47 import org.apache.jackrabbit.JcrConstants;
48
49
50
51
52 public class ThemeAwareParameter {
53
54 private final String themeName;
55
56 private final String variationName;
57
58 private final Node node;
59
60 public ThemeAwareParameter(String themeName, String variationName, Node node) {
61 this.themeName = themeName;
62 this.variationName = variationName;
63 this.node = node;
64 }
65
66 public ImageOperationProvidingVariation getImageVariation() {
67 final VariationAwareImagingSupport imaging = (VariationAwareImagingSupport) Components.getComponent(SiteModule.class).getTheme(themeName).getImaging();
68 return (ImageOperationProvidingVariation) imaging.getVariations().get(variationName);
69 }
70
71 public Node getNode() {
72 return node;
73 }
74
75 public Binary getBinary() throws RepositoryException {
76 return node.getProperty(JcrConstants.JCR_DATA).getBinary();
77 }
78
79 public String getExtension() {
80
81 return PropertyUtil.getString(node, FileProperties.EXTENSION, "");
82 }
83
84
85
86
87
88
89 public String getCachePath() {
90 try {
91 return "/" + themeName + "/" + variationName + "/" + node.getSession().getWorkspace().getName() + node.getPath();
92 } catch (RepositoryException e) {
93
94 return "";
95 }
96 }
97
98 @Override
99 public boolean equals(Object o) {
100 if (this == o) return true;
101 if (o == null || getClass() != o.getClass()) return false;
102
103 ThemeAwareParameter that = (ThemeAwareParameter) o;
104
105 if (!node.equals(that.node)) return false;
106 if (!themeName.equals(that.themeName)) return false;
107 if (!variationName.equals(that.variationName)) return false;
108
109 return true;
110 }
111
112 @Override
113 public int hashCode() {
114 int result = themeName.hashCode();
115 result = 31 * result + variationName.hashCode();
116 result = 31 * result + node.hashCode();
117 return result;
118 }
119 }