You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/10/14 19:18:09 UTC

[77/81] [abbrv] git commit: updated refs/heads/ui-restyle to e901b82

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 <la...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/87c1b357
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/87c1b357
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/87c1b357

Branch: refs/heads/ui-restyle
Commit: 87c1b357f254d6c7869bb2f367493f3a89aa175c
Parents: 5f497b9
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Sat Oct 12 21:12:36 2013 +0200
Committer: Laszlo Hornyak <la...@gmail.com>
Committed: Sat Oct 12 23:26:20 2013 +0200

----------------------------------------------------------------------
 api/src/org/apache/cloudstack/api/BaseCmd.java | 109 --------------------
 1 file changed, 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/87c1b357/api/src/org/apache/cloudstack/api/BaseCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java
index 4f4d0db..01d9b53 100644
--- a/api/src/org/apache/cloudstack/api/BaseCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseCmd.java
@@ -21,7 +21,6 @@ import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
 
@@ -77,7 +76,6 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountService;
 import com.cloud.user.DomainService;
 import com.cloud.user.ResourceLimitService;
-import com.cloud.utils.Pair;
 import com.cloud.utils.db.EntityManager;
 import com.cloud.vm.UserVmService;
 import com.cloud.vm.snapshot.VMSnapshotService;
@@ -302,113 +300,6 @@ public abstract class BaseCmd {
         return lowercaseParams;
     }
 
-    private void writeNameValuePair(StringBuffer sb, String tagName, Object tagValue, String responseType, int propertyCount) {
-        if (tagValue == null) {
-            return;
-        }
-
-        if (tagValue instanceof Object[]) {
-            Object[] subObjects = (Object[]) tagValue;
-            if (subObjects.length < 1) {
-                return;
-            }
-            writeObjectArray(responseType, sb, propertyCount, tagName, subObjects);
-        } else {
-            if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
-                String seperator = ((propertyCount > 0) ? ", " : "");
-                sb.append(seperator + "\"" + tagName + "\" : \"" + escapeJSON(tagValue.toString()) + "\"");
-            } else {
-                sb.append("<" + tagName + ">" + escapeXml(tagValue.toString()) + "</" + tagName + ">");
-            }
-        }
-    }
-
-    @SuppressWarnings("rawtypes")
-    private void writeObjectArray(String responseType, StringBuffer sb, int propertyCount, String tagName, Object[] subObjects) {
-        if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
-            String separator = ((propertyCount > 0) ? ", " : "");
-            sb.append(separator);
-        }
-        int j = 0;
-        for (Object subObject : subObjects) {
-            if (subObject instanceof List) {
-                List subObjList = (List) subObject;
-                writeSubObject(sb, tagName, subObjList, responseType, j++);
-            }
-        }
-
-        if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
-            sb.append("]");
-        }
-    }
-
-    @SuppressWarnings("rawtypes")
-    private void writeSubObject(StringBuffer sb, String tagName, List tagList, String responseType, int objectCount) {
-        if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
-            sb.append(((objectCount == 0) ? "\"" + tagName + "\" : [  { " : ", { "));
-        } else {
-            sb.append("<" + tagName + ">");
-        }
-
-        int i = 0;
-        for (Object tag : tagList) {
-            if (tag instanceof Pair) {
-                Pair nameValuePair = (Pair) tag;
-                writeNameValuePair(sb, (String) nameValuePair.first(), nameValuePair.second(), responseType, i++);
-            }
-        }
-
-        if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
-            sb.append("}");
-        } else {
-            sb.append("</" + tagName + ">");
-        }
-    }
-
-    /**
-     * Escape xml response set to false by default. API commands to override this method to allow escaping
-     */
-    public boolean requireXmlEscape() {
-        return true;
-    }
-
-    private String escapeXml(String xml) {
-        if (!requireXmlEscape()) {
-            return xml;
-        }
-        int iLen = xml.length();
-        if (iLen == 0) {
-            return xml;
-        }
-        StringBuffer sOUT = new StringBuffer(iLen + 256);
-        int i = 0;
-        for (; i < iLen; i++) {
-            char c = xml.charAt(i);
-            if (c == '<') {
-                sOUT.append("&lt;");
-            } else if (c == '>') {
-                sOUT.append("&gt;");
-            } else if (c == '&') {
-                sOUT.append("&amp;");
-            } else if (c == '"') {
-                sOUT.append("&quot;");
-            } else if (c == '\'') {
-                sOUT.append("&apos;");
-            } else {
-                sOUT.append(c);
-            }
-        }
-        return sOUT.toString();
-    }
-
-    private static String escapeJSON(String str) {
-        if (str == null) {
-            return str;
-        }
-
-        return str.replace("\"", "\\\"");
-    }
-
     protected long getInstanceIdFromJobSuccessResult(String result) {
         s_logger.debug("getInstanceIdFromJobSuccessResult not overridden in subclass " + this.getClass().getName());
         return 0;