|
21 | 21 | import java.text.SimpleDateFormat; |
22 | 22 | import java.util.Date; |
23 | 23 | import java.util.HashMap; |
24 | | -import java.util.List; |
25 | 24 | import java.util.Map; |
26 | 25 | import java.util.regex.Pattern; |
27 | 26 |
|
|
77 | 76 | import com.cloud.user.AccountService; |
78 | 77 | import com.cloud.user.DomainService; |
79 | 78 | import com.cloud.user.ResourceLimitService; |
80 | | -import com.cloud.utils.Pair; |
81 | 79 | import com.cloud.utils.db.EntityManager; |
82 | 80 | import com.cloud.vm.UserVmService; |
83 | 81 | import com.cloud.vm.snapshot.VMSnapshotService; |
@@ -302,113 +300,6 @@ public Map<String, Object> unpackParams(Map<String, String> params) { |
302 | 300 | return lowercaseParams; |
303 | 301 | } |
304 | 302 |
|
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("<"); |
389 | | - } else if (c == '>') { |
390 | | - sOUT.append(">"); |
391 | | - } else if (c == '&') { |
392 | | - sOUT.append("&"); |
393 | | - } else if (c == '"') { |
394 | | - sOUT.append("""); |
395 | | - } else if (c == '\'') { |
396 | | - sOUT.append("'"); |
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 | | - |
412 | 303 | protected long getInstanceIdFromJobSuccessResult(String result) { |
413 | 304 | s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName()); |
414 | 305 | return 0; |
|
0 commit comments