AbstractComment.java
3.96 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* aQute.bnd.annotation.ConsumerType
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.granite.comments;
import aQute.bnd.annotation.ConsumerType;
import com.adobe.granite.comments.AbstractCommentCollection;
import com.adobe.granite.comments.AbstractCommentingProvider;
import com.adobe.granite.comments.Comment;
import com.adobe.granite.comments.CommentCollection;
import com.adobe.granite.comments.CommentException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@ConsumerType
public abstract class AbstractComment
implements Comment {
private final AbstractCommentCollection collection;
private final Resource resource;
private final AbstractCommentingProvider provider;
private final ValueMap properties;
protected AbstractComment(AbstractCommentCollection collection, Resource resource, AbstractCommentingProvider provider) {
this.collection = collection;
this.resource = resource;
this.provider = provider;
this.properties = (ValueMap)resource.adaptTo(ValueMap.class);
}
@Override
public final Resource addAttachment(String name, InputStream inputStream, String mimeType) throws CommentException {
if (null == inputStream) {
throw new IllegalArgumentException("input stream may not be null");
}
if (StringUtils.isBlank((String)name)) {
throw new IllegalArgumentException("name may not be null or empty");
}
if (StringUtils.isBlank((String)mimeType)) {
throw new IllegalArgumentException("mimetype may not be null or empty");
}
return this.provider.createAttachmentResource(this.getResource(), name, inputStream, mimeType);
}
@Override
public final String getAnnotationData() {
return (String)this.properties.get("annotationData", String.class);
}
@Override
public final Resource getAttachment(String name) {
return this.provider.getAttachmentResource(this.getResource(), name);
}
@Override
public final String getAuthorName() {
String author = (String)this.properties.get("author", String.class);
return null != author ? author : this.getCreatedBy();
}
@Override
public final Map<String, Resource> getAttachmentMap() {
return Collections.unmodifiableMap(this.provider.getAttachmentMap(this.getResource()));
}
private final String getCreatedBy() {
return (String)this.properties.get("jcr:createdBy", String.class);
}
@Override
public final Calendar getCreated() {
return (Calendar)this.properties.get("jcr:created", Calendar.class);
}
@Override
public final Calendar getLastModified() {
return (Calendar)this.properties.get("jcr:lastModified", Calendar.class);
}
@Override
public final String getMessage() {
return (String)this.properties.get("jcr:description", String.class);
}
@Override
public final CommentCollection getCollection() {
return this.collection;
}
@Override
public final String getPath() {
return this.getResource().getPath();
}
@Override
public final ValueMap getProperties() {
return this.properties;
}
@Override
public final void removeAttachment(String name) throws CommentException {
this.provider.removeAttachmentResource(this.getResource(), name);
}
@Override
public final void remove() {
this.collection.removeComment(this);
}
protected Resource getResource() {
return this.resource;
}
}