PTiffRenditionImpl.java
4.79 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.dam.dm.process.api.PTiffMetadata
* com.adobe.cq.dam.dm.process.api.PTiffRendition
* com.adobe.granite.asset.api.Rendition
* com.day.cq.dam.api.Asset
* com.day.cq.dam.commons.util.DamUtil
* com.scene7.is.util.collections.CollectionUtil
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceWrapper
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
* org.jetbrains.annotations.NotNull
* org.jetbrains.annotations.Nullable
*/
package com.adobe.cq.dam.dm.process.image;
import com.adobe.cq.dam.dm.process.api.PTiffMetadata;
import com.adobe.cq.dam.dm.process.api.PTiffRendition;
import com.adobe.cq.dam.dm.process.image.FileFormatDetect;
import com.adobe.cq.dam.dm.process.image.PTiffMetadataImpl;
import com.adobe.granite.asset.api.Rendition;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.commons.util.DamUtil;
import com.scene7.is.util.collections.CollectionUtil;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceWrapper;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class PTiffRenditionImpl
extends ResourceWrapper
implements PTiffRendition {
private final Rendition delegate;
private final ValueMap props;
private final PTiffMetadata metadata;
@Nullable
public static PTiffRendition getPTiffRendition(@NotNull Resource resource) {
if (!DamUtil.isRendition((Resource)resource)) {
return null;
}
if (!resource.getName().equals("cqdam.pyramid.tiff")) {
return null;
}
Rendition delegate = (Rendition)resource.adaptTo(Rendition.class);
if (delegate == null) {
return null;
}
Resource content = resource.getChild("jcr:content");
if (content == null) {
return null;
}
ValueMap props = content.getValueMap();
if (props == null) {
return null;
}
PTiffMetadata metadata = PTiffRenditionImpl.readPTiffMetadata(content);
if (metadata == null) {
return null;
}
return new PTiffRenditionImpl(resource, delegate, props, metadata);
}
@NotNull
public PTiffMetadata getMetadata() {
return this.metadata;
}
public String getMimeType() {
return this.delegate.getMimeType();
}
public long getSize() {
return this.delegate.getSize();
}
public InputStream getStream() {
return this.delegate.getStream();
}
public ValueMap getProperties() {
return this.props;
}
public Asset getAsset() {
return DamUtil.resolveToAsset((Resource)this.getResource());
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (type == Resource.class) {
return (AdapterType)this.getResource();
}
if (type == PTiffRendition.class) {
return (AdapterType)((Object)this);
}
return (AdapterType)super.adaptTo(type);
}
private PTiffRenditionImpl(@NotNull Resource resource, @NotNull Rendition delegate, @NotNull ValueMap props, @NotNull PTiffMetadata metadata) {
super(resource);
this.delegate = delegate;
this.props = props;
this.metadata = metadata;
}
@Nullable
private static PTiffMetadata readPTiffMetadata(@NotNull Resource content) {
ValueMap map;
Resource renditionMetadata = content.getChild("metadata");
if (renditionMetadata != null && PTiffMetadataImpl.isPTiffMetadata(map = renditionMetadata.getValueMap())) {
return PTiffMetadataImpl.createPTiffMetadata(map);
}
Asset asset = DamUtil.resolveToAsset((Resource)content);
if (asset == null) {
return null;
}
String assetMimeType = asset.getMimeType();
if (assetMimeType == null) {
return null;
}
ValueMapDecorator assetMetadata = new ValueMapDecorator(asset.getMetadata());
HashMap map2 = CollectionUtil.hashMap();
map2.put("ptiff.original", FileFormatDetect.detectImageFormat(assetMimeType).isDefined());
if (assetMetadata.containsKey((Object)"tiff:ImageWidth")) {
map2.put("ptiff.width", assetMetadata.get("tiff:ImageWidth", Integer.class));
}
if (assetMetadata.containsKey((Object)"tiff:ImageLength")) {
map2.put("ptiff.height", assetMetadata.get("tiff:ImageLength", Integer.class));
}
return PTiffMetadataImpl.createPTiffMetadata(map2);
}
}