Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 950729e

Browse filesBrowse files
authored
Merge pull request zaproxy#5 from thc202/expose-data-resp-set
Allow to obtain all data of an ApiResponseSet
2 parents 2d077eb + fe9e97f commit 950729e
Copy full SHA for 950729e

File tree

Expand file treeCollapse file tree

1 file changed

+90
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+90
-6
lines changed

‎subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ApiResponseSet.java

Copy file name to clipboardExpand all lines: subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ApiResponseSet.java
+90-6Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,128 @@
1717
*/
1818
package org.zaproxy.clientapi.core;
1919

20+
import java.util.Collection;
21+
import java.util.Collections;
2022
import java.util.HashMap;
2123
import java.util.Map;
2224
import java.util.Map.Entry;
25+
import java.util.Set;
2326

2427
import org.w3c.dom.Node;
2528

2629
public class ApiResponseSet extends ApiResponse {
2730

2831
private String[] attributes = null;
29-
private Map<String, String> values = null;
32+
private final Map<String, String> valuesMap;
3033

34+
/**
35+
* Constructs an {@code ApiResponseSet} with the given name and attributes.
36+
*
37+
* @param name the name of the API response
38+
* @param attributes the attributes
39+
* @deprecated (TODO add version) Unused, there's no replacement.
40+
*/
41+
@Deprecated
3142
public ApiResponseSet(String name, String[] attributes) {
3243
super(name);
3344
this.attributes = attributes;
45+
this.valuesMap = Collections.emptyMap();
3446
}
3547

3648
public ApiResponseSet(String name, Map<String, String> values) {
3749
super(name);
38-
this.values = values;
50+
this.valuesMap = Collections.unmodifiableMap(new HashMap<>(values));
3951
}
4052

4153
public ApiResponseSet(Node node) throws ClientApiException {
4254
super(node.getNodeName());
4355
Node child = node.getFirstChild();
44-
this.values = new HashMap<String, String>();
56+
Map<String, String> values = new HashMap<>();
4557
while (child != null) {
4658
ApiResponseElement elem = (ApiResponseElement) ApiResponseFactory.getResponse(child);
4759
values.put(elem.getName(), elem.getValue());
4860
child = child.getNextSibling();
4961
}
62+
this.valuesMap = Collections.unmodifiableMap(values);
5063
}
5164

65+
/**
66+
* Gets the attributes.
67+
*
68+
* @return the attributes, might be {@code null}.
69+
* @deprecated (TODO add version) Unused, there's no replacement.
70+
* @see #getValues()
71+
*/
72+
@Deprecated
5273
public String[] getAttributes() {
5374
return attributes;
5475
}
5576

56-
public String getAttribute(String name) {
57-
return this.values.get(name);
77+
/**
78+
* Gets the value for the given {@code key}.
79+
*
80+
* @param key the key of the value
81+
* @return the value, or {@code null} if no value exists for the given {@code key}.
82+
* @deprecated (TODO add version) Use {@link #getValue(String)} instead.
83+
*/
84+
@Deprecated
85+
public String getAttribute(String key) {
86+
return getValue(key);
87+
}
88+
89+
/**
90+
* Gets the value for the given {@code key}.
91+
*
92+
* @param key the key of the value
93+
* @return the value, or {@code null} if no value exists for the given {@code key}.
94+
* @since TODO add version
95+
* @see #getKeys()
96+
*/
97+
public String getValue(String key) {
98+
return valuesMap.get(key);
99+
}
100+
101+
/**
102+
* Gets a {@code Map} with the keys and values.
103+
* <p>
104+
* The returned {@code Map} is unmodifiable, any attempt to modify it will result in an
105+
* {@code UnsupportedOperationException}.
106+
*
107+
* @return the map with the keys/values, never {@code null}.
108+
* @since TODO add version
109+
*/
110+
public Map<String, String> getValuesMap() {
111+
return valuesMap;
112+
}
113+
114+
/**
115+
* Gets the keys of the values.
116+
* <p>
117+
* The returned {@code Set} is unmodifiable, any attempt to modify it will result in an
118+
* {@code UnsupportedOperationException}.
119+
*
120+
* @return the keys, never {@code null}.
121+
* @since TODO add version
122+
* @see #getValue(String)
123+
* @see #getValues()
124+
* @see #getValuesMap()
125+
*/
126+
public Set<String> getKeys() {
127+
return valuesMap.keySet();
128+
}
129+
130+
/**
131+
* Gets the values.
132+
* <p>
133+
* The returned {@code Collection} is unmodifiable, any attempt to modify it will result in an
134+
* {@code UnsupportedOperationException}.
135+
*
136+
* @return the values, never {@code null}.
137+
* @since TODO add version
138+
* @see #getValue(String)
139+
*/
140+
public Collection<String> getValues() {
141+
return valuesMap.values();
58142
}
59143

60144
@Override
@@ -66,7 +150,7 @@ public String toString(int indent) {
66150
sb.append("ApiResponseSet ");
67151
sb.append(this.getName());
68152
sb.append(" : [\n");
69-
for (Entry<String, String> val : values.entrySet()) {
153+
for (Entry<String, String> val : valuesMap.entrySet()) {
70154
for (int i=0 ; i < indent+1; i++) {
71155
sb.append("\t");
72156
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.