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.module.templatingkit.dam;
35
36 import info.magnolia.dam.api.Asset;
37 import info.magnolia.dam.api.AssetProvider;
38 import info.magnolia.dam.api.AssetProviderCapability;
39 import info.magnolia.dam.api.AssetRenderer;
40 import info.magnolia.dam.api.AssetRendition;
41 import info.magnolia.dam.api.DamException;
42 import info.magnolia.dam.api.RenditionAwareAssetProvider;
43 import info.magnolia.dam.asset.LegacyAssetWrapper;
44 import info.magnolia.module.templatingkit.functions.STKTemplatingFunctions;
45
46 import java.io.InputStream;
47
48 import javax.inject.Inject;
49
50 import com.google.common.net.MediaType;
51
52
53
54
55
56
57 @Deprecated
58 public class STKAssetRenderer implements AssetRenderer {
59
60 private STKTemplatingFunctions stkTemplatingFunctions;
61
62 @Inject
63 public STKAssetRenderer(STKTemplatingFunctions stkTemplatingFunctions) {
64 this.stkTemplatingFunctions = stkTemplatingFunctions;
65 }
66
67
68
69
70
71
72
73
74 @Deprecated
75 private static class STKAssetRendition extends LegacyAssetWrapper implements AssetRendition {
76 private final Asset asset;
77 private final String url;
78 private final String renditionName;
79
80 public STKAssetRendition(Asset asset, String url, String renditionName) {
81 super(asset);
82 this.asset = asset;
83 this.url = url;
84 this.renditionName = renditionName;
85 }
86
87 @Override
88 public String getLink() {
89 return this.url;
90 }
91
92 @Override
93 public String getRenditionName() {
94 return this.renditionName;
95 }
96
97 @Override
98 public String getMimeType() {
99 return this.asset.getMimeType();
100 }
101
102 @Override
103 public InputStream getStream() {
104 return this.asset.getContentStream();
105 }
106
107 @Override
108 public Asset getAsset() {
109 return this.asset;
110 }
111
112 }
113
114 @Override
115 public boolean supports(MediaType from, MediaType to) {
116 return true;
117 }
118
119 @Override
120 public boolean canRender(Asset asset, MediaType to) {
121 return true;
122 }
123
124 @Override
125 public AssetRendition render(Asset asset, MediaType to, String renditionName) {
126 try {
127 String link;
128
129 AssetProvider assetProvider = asset.getAssetProvider();
130 if (assetProvider.supports(AssetProviderCapability.rendition)) {
131 if (asset instanceof STKAssetWrapper) {
132 asset = assetProvider.getAsset(asset.getItemKey());
133 }
134 link = ((RenditionAwareAssetProvider) assetProvider).getLink(asset, renditionName);
135 } else {
136 link = asset.getLink();
137 }
138 return new STKAssetRendition(asset, link, renditionName);
139
140 } catch (Exception e) {
141 throw new DamException("AssetRendition exception", e) {
142 };
143 }
144 }
145
146 }