1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.handler.commons.editcontext;
21
22 import java.util.Collections;
23 import java.util.Map;
24
25 import org.apache.sling.commons.json.JSONException;
26 import org.apache.sling.commons.json.io.JSONWriter;
27 import org.jetbrains.annotations.NotNull;
28 import org.osgi.annotation.versioning.ProviderType;
29
30 import com.day.cq.wcm.api.components.DropTarget;
31
32
33
34
35 @ProviderType
36
37
38
39
40 @SuppressWarnings("deprecation")
41 public final class DropTargetImpl implements DropTarget {
42
43 private final String name;
44 private final String id;
45 private final String propertyName;
46 private String[] groups = new String[0];
47 private String[] accept = new String[] {
48 "*"
49 };
50 private Map<String, String> parameters = Collections.emptyMap();
51
52
53
54
55
56 public DropTargetImpl(@NotNull String name, @NotNull String propertyName) {
57 this.name = name;
58 this.id = CSS_CLASS_PREFIX + this.name;
59 this.propertyName = propertyName;
60 }
61
62
63
64
65
66 @Override
67 public String getName() {
68 return this.name;
69 }
70
71
72
73
74
75
76 @Override
77 public String getId() {
78 return this.id;
79 }
80
81
82
83
84
85 @Override
86 public String getPropertyName() {
87 return this.propertyName;
88 }
89
90
91
92
93
94 @Override
95 public String[] getGroups() {
96 return this.groups;
97 }
98
99
100
101
102
103 public DropTargetImpl setGroups(String @NotNull [] values) {
104 this.groups = values;
105 return this;
106 }
107
108
109
110
111
112 @Override
113 public String[] getAccept() {
114 return this.accept;
115 }
116
117
118
119
120
121 public DropTargetImpl setAccept(String @NotNull [] values) {
122 this.accept = values;
123 return this;
124 }
125
126
127
128
129
130 @Override
131 public Map<String, String> getParameters() {
132 return this.parameters;
133 }
134
135
136
137
138
139 public DropTargetImpl setParameters(@NotNull Map<String, String> value) {
140 this.parameters = value;
141 return this;
142 }
143
144 @Override
145 public void write(JSONWriter out) throws JSONException {
146 out.object();
147 out.key("id").value(this.name);
148 out.key("name").value(this.propertyName);
149 out.key("accept").array();
150 for (String a : this.accept) {
151 out.value(a);
152 }
153 out.endArray();
154 out.key("groups").array();
155 for (String group : this.groups) {
156 out.value(group);
157 }
158 out.endArray();
159 if (!this.parameters.isEmpty()) {
160 out.key("params");
161 out.object();
162 for (Map.Entry<String, String> e : this.parameters.entrySet()) {
163 out.key(e.getKey()).value(e.getValue());
164 }
165 out.endObject();
166 }
167 out.endObject();
168 }
169
170 }