Skip to content

Commit 87c1b35

Browse files
committed
BaseCmd not used methods
These private methods were only calling each other: - writeNameValuePair - writeObjectArray - writeSubObject - escapeXml - escapeJSON public method requireXmlEscape was only called from these methods, it was never overridden Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
1 parent 5f497b9 commit 87c1b35

1 file changed

Lines changed: 0 additions & 109 deletions

File tree

api/src/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.text.SimpleDateFormat;
2222
import java.util.Date;
2323
import java.util.HashMap;
24-
import java.util.List;
2524
import java.util.Map;
2625
import java.util.regex.Pattern;
2726

@@ -77,7 +76,6 @@
7776
import com.cloud.user.AccountService;
7877
import com.cloud.user.DomainService;
7978
import com.cloud.user.ResourceLimitService;
80-
import com.cloud.utils.Pair;
8179
import com.cloud.utils.db.EntityManager;
8280
import com.cloud.vm.UserVmService;
8381
import com.cloud.vm.snapshot.VMSnapshotService;
@@ -302,113 +300,6 @@ public Map<String, Object> unpackParams(Map<String, String> params) {
302300
return lowercaseParams;
303301
}
304302

305-
private void writeNameValuePair(StringBuffer sb, String tagName, Object tagValue, String responseType, int propertyCount) {
306-
if (tagValue == null) {
307-
return;
308-
}
309-
310-
if (tagValue instanceof Object[]) {
311-
Object[] subObjects = (Object[]) tagValue;
312-
if (subObjects.length < 1) {
313-
return;
314-
}
315-
writeObjectArray(responseType, sb, propertyCount, tagName, subObjects);
316-
} else {
317-
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
318-
String seperator = ((propertyCount > 0) ? ", " : "");
319-
sb.append(seperator + "\"" + tagName + "\" : \"" + escapeJSON(tagValue.toString()) + "\"");
320-
} else {
321-
sb.append("<" + tagName + ">" + escapeXml(tagValue.toString()) + "</" + tagName + ">");
322-
}
323-
}
324-
}
325-
326-
@SuppressWarnings("rawtypes")
327-
private void writeObjectArray(String responseType, StringBuffer sb, int propertyCount, String tagName, Object[] subObjects) {
328-
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
329-
String separator = ((propertyCount > 0) ? ", " : "");
330-
sb.append(separator);
331-
}
332-
int j = 0;
333-
for (Object subObject : subObjects) {
334-
if (subObject instanceof List) {
335-
List subObjList = (List) subObject;
336-
writeSubObject(sb, tagName, subObjList, responseType, j++);
337-
}
338-
}
339-
340-
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
341-
sb.append("]");
342-
}
343-
}
344-
345-
@SuppressWarnings("rawtypes")
346-
private void writeSubObject(StringBuffer sb, String tagName, List tagList, String responseType, int objectCount) {
347-
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
348-
sb.append(((objectCount == 0) ? "\"" + tagName + "\" : [ { " : ", { "));
349-
} else {
350-
sb.append("<" + tagName + ">");
351-
}
352-
353-
int i = 0;
354-
for (Object tag : tagList) {
355-
if (tag instanceof Pair) {
356-
Pair nameValuePair = (Pair) tag;
357-
writeNameValuePair(sb, (String) nameValuePair.first(), nameValuePair.second(), responseType, i++);
358-
}
359-
}
360-
361-
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
362-
sb.append("}");
363-
} else {
364-
sb.append("</" + tagName + ">");
365-
}
366-
}
367-
368-
/**
369-
* Escape xml response set to false by default. API commands to override this method to allow escaping
370-
*/
371-
public boolean requireXmlEscape() {
372-
return true;
373-
}
374-
375-
private String escapeXml(String xml) {
376-
if (!requireXmlEscape()) {
377-
return xml;
378-
}
379-
int iLen = xml.length();
380-
if (iLen == 0) {
381-
return xml;
382-
}
383-
StringBuffer sOUT = new StringBuffer(iLen + 256);
384-
int i = 0;
385-
for (; i < iLen; i++) {
386-
char c = xml.charAt(i);
387-
if (c == '<') {
388-
sOUT.append("&lt;");
389-
} else if (c == '>') {
390-
sOUT.append("&gt;");
391-
} else if (c == '&') {
392-
sOUT.append("&amp;");
393-
} else if (c == '"') {
394-
sOUT.append("&quot;");
395-
} else if (c == '\'') {
396-
sOUT.append("&apos;");
397-
} else {
398-
sOUT.append(c);
399-
}
400-
}
401-
return sOUT.toString();
402-
}
403-
404-
private static String escapeJSON(String str) {
405-
if (str == null) {
406-
return str;
407-
}
408-
409-
return str.replace("\"", "\\\"");
410-
}
411-
412303
protected long getInstanceIdFromJobSuccessResult(String result) {
413304
s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName());
414305
return 0;

0 commit comments

Comments
 (0)