CommentResourceConverter.java
2.66 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.rest.converter.ResourceConverterContext
* com.adobe.granite.rest.converter.ResourceConverterException
* com.adobe.granite.rest.converter.siren.AbstractSirenConverter
* com.adobe.reef.siren.Action
* com.adobe.reef.siren.Action$Method
* com.adobe.reef.siren.Field
* com.adobe.reef.siren.Link
* com.adobe.reef.siren.builder.ActionBuilder
* com.adobe.reef.siren.builder.BuilderException
* com.adobe.reef.siren.builder.FieldBuilder
* org.apache.sling.api.resource.Resource
*/
package com.adobe.granite.rest.assets.impl;
import com.adobe.granite.rest.assets.impl.AttachmentResource;
import com.adobe.granite.rest.assets.impl.CommentResource;
import com.adobe.granite.rest.converter.ResourceConverterContext;
import com.adobe.granite.rest.converter.ResourceConverterException;
import com.adobe.granite.rest.converter.siren.AbstractSirenConverter;
import com.adobe.reef.siren.Action;
import com.adobe.reef.siren.Field;
import com.adobe.reef.siren.Link;
import com.adobe.reef.siren.builder.ActionBuilder;
import com.adobe.reef.siren.builder.BuilderException;
import com.adobe.reef.siren.builder.FieldBuilder;
import java.util.List;
import org.apache.sling.api.resource.Resource;
public class CommentResourceConverter
extends AbstractSirenConverter {
public CommentResourceConverter(Resource resource) {
super(resource);
}
protected String[] getClazz() {
return new String[]{"assets/asset/comments/comment"};
}
protected List<Link> getLinks(ResourceConverterContext context) throws BuilderException, ResourceConverterException {
AttachmentResource attachment;
List links = super.getLinks(context);
if (this.resource instanceof CommentResource && (attachment = ((CommentResource)this.resource).getAttachment("preview.png")) != null) {
links.add(this.getLink("attachment", this.buildURL(context, attachment.getPath(), null), null));
}
return links;
}
protected List<Action> getActions(ResourceConverterContext context) throws BuilderException, ResourceConverterException {
List actions = super.getActions(context);
actions.add(new ActionBuilder().setName("update").setHref(this.buildURL(context, this.resource.getPath(), null)).setMethod(Action.Method.PUT).setTitle("Update").setType("application/vnd.siren+json").addField((Field)new FieldBuilder().setName("data").build()).build());
actions.add(new ActionBuilder().setName("delete").setHref(this.buildURL(context, this.resource.getPath(), null)).setMethod(Action.Method.DELETE).setTitle("Delete").build());
return actions;
}
}