Author: bibryam
Date: Sun Mar 15 23:55:19 2009 New Revision: 754795 URL: http://svn.apache.org/viewvc?rev=754795&view=rev Log: Moved repeating method from EventHandlers to UtilHttp class Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/AbstractJSONEventHandler.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java?rev=754795&r1=754794&r2=754795&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java Sun Mar 15 23:55:19 2009 @@ -253,7 +253,28 @@ return paramValue; } } + + /** + * Create a map from a HttpRequest (attributes) object used in JSON requests + * @return The resulting Map + */ + public static Map<String, Object> getJSONAttributeMap(HttpServletRequest request) { + Map<String, Object> returnMap = FastMap.newInstance(); + Map<String, Object> attrMap = getAttributeMap(request); + for (String key: attrMap.keySet()) { + Object val = attrMap.get(key); + if (val instanceof java.sql.Timestamp) { + val = val.toString(); + } + if (val instanceof String || val instanceof Number || val instanceof Map || val instanceof List) { + if (Debug.verboseOn()) Debug.logVerbose("Adding attribute to JSON output: " + key, module); + returnMap.put(key, val); + } + } + return returnMap; + } + /** * Create a map from a HttpRequest (attributes) object * @return The resulting Map Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/AbstractJSONEventHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/AbstractJSONEventHandler.java?rev=754795&r1=754794&r2=754795&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/AbstractJSONEventHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/AbstractJSONEventHandler.java Sun Mar 15 23:55:19 2009 @@ -23,18 +23,15 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.Enumeration; -import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javolution.util.FastMap; import net.sf.json.JSONObject; -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilHttp; import org.ofbiz.webapp.control.ConfigXMLReader.Event; import org.ofbiz.webapp.control.ConfigXMLReader.RequestMap; @@ -50,7 +47,7 @@ // call into the java handler for parameters parsing and invocation String respCode = service.invoke(null, requestMap, request, response); // pull out the service response from the request attribute - Map<String, Object> attrMap = getAttributesAsMap(request); + Map<String, Object> attrMap = UtilHttp.getJSONAttributeMap(request); // create a JSON Object for return JSONObject json = JSONObject.fromObject(attrMap); @@ -80,22 +77,4 @@ return respCode; } - private Map<String, Object> getAttributesAsMap(HttpServletRequest request) { - Map<String, Object> attrMap = FastMap.newInstance(); - Enumeration<String> en = request.getAttributeNames(); - while (en.hasMoreElements()) { - String name = (String) en.nextElement(); - Object val = request.getAttribute(name); - if (val instanceof java.sql.Timestamp) { - val = val.toString(); - } - if (val instanceof String || val instanceof Number || val instanceof Map || val instanceof List) { - if (Debug.verboseOn()) Debug.logVerbose("Adding attribute to JSON output: " + name, module); - attrMap.put(name, val); - } - } - - return attrMap; - } - } Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java?rev=754795&r1=754794&r2=754795&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/DojoJSONServiceEventHandler.java Sun Mar 15 23:55:19 2009 @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.Enumeration; import java.util.List; import java.util.Locale; import java.util.Map; @@ -35,7 +34,6 @@ import javolution.util.FastMap; import net.sf.json.JSONObject; -import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; @@ -69,7 +67,7 @@ String respCode = service.invoke(null, requestMap, request, response); // pull out the service response from the request attribute - Map<String, Object> attrMap = getAttributesAsMap(request); + Map<String, Object> attrMap = UtilHttp.getJSONAttributeMap(request); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); if (dispatcher == null) { @@ -138,21 +136,4 @@ return respCode; } - private Map<String, Object> getAttributesAsMap(HttpServletRequest request) { - Map<String, Object> attrMap = FastMap.newInstance(); - Enumeration<String> en = request.getAttributeNames(); - while (en.hasMoreElements()) { - String name = (String) en.nextElement(); - Object val = request.getAttribute(name); - if (val instanceof java.sql.Timestamp) { - val = val.toString(); - } - if (val instanceof String || val instanceof Number || val instanceof Map || val instanceof List) { - if (Debug.verboseOn()) Debug.logVerbose("Adding attribute to JSON output: " + name, module); - attrMap.put(name, val); - } - } - - return attrMap; - } } Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java?rev=754795&r1=754794&r2=754795&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONJavaEventHandler.java Sun Mar 15 23:55:19 2009 @@ -21,18 +21,15 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.Enumeration; -import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javolution.util.FastMap; import net.sf.json.JSONObject; -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilHttp; import org.ofbiz.webapp.control.ConfigXMLReader.Event; import org.ofbiz.webapp.control.ConfigXMLReader.RequestMap; @@ -54,7 +51,7 @@ String respCode = service.invoke(event, requestMap, request, response); // pull out the service response from the request attribute - Map<String, Object> attrMap = getAttributesAsMap(request); + Map<String, Object> attrMap = UtilHttp.getJSONAttributeMap(request); // create a JSON Object for return JSONObject json = JSONObject.fromObject(attrMap); @@ -85,21 +82,4 @@ return respCode; } - private Map<String, Object> getAttributesAsMap(HttpServletRequest request) { - Map<String, Object> attrMap = FastMap.newInstance(); - Enumeration<String> en = request.getAttributeNames(); - while (en.hasMoreElements()) { - String name = (String) en.nextElement(); - Object val = request.getAttribute(name); - if (val instanceof java.sql.Timestamp) { - val = val.toString(); - } - if (val instanceof String || val instanceof Number || val instanceof Map || val instanceof List) { - if (Debug.verboseOn()) Debug.logVerbose("Adding attribute to JSON output: " + name, module); - attrMap.put(name, val); - } - } - - return attrMap; - } } Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java?rev=754795&r1=754794&r2=754795&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONServiceEventHandler.java Sun Mar 15 23:55:19 2009 @@ -21,18 +21,15 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.Enumeration; -import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javolution.util.FastMap; import net.sf.json.JSONObject; -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilHttp; import org.ofbiz.webapp.control.ConfigXMLReader.Event; import org.ofbiz.webapp.control.ConfigXMLReader.RequestMap; @@ -54,7 +51,7 @@ String respCode = service.invoke(event, requestMap, request, response); // pull out the service response from the request attribute - Map<String, Object> attrMap = getAttributesAsMap(request); + Map<String, Object> attrMap = UtilHttp.getJSONAttributeMap(request); // create a JSON Object for return JSONObject json = JSONObject.fromObject(attrMap); @@ -85,21 +82,4 @@ return respCode; } - private Map<String, Object> getAttributesAsMap(HttpServletRequest request) { - Map<String, Object> attrMap = FastMap.newInstance(); - Enumeration<String> en = request.getAttributeNames(); - while (en.hasMoreElements()) { - String name = (String) en.nextElement(); - Object val = request.getAttribute(name); - if (val instanceof java.sql.Timestamp) { - val = val.toString(); - } - if (val instanceof String || val instanceof Number || val instanceof Map || val instanceof List) { - if (Debug.verboseOn()) Debug.logVerbose("Adding attribute to JSON output: " + name, module); - attrMap.put(name, val); - } - } - - return attrMap; - } } |
Free forum by Nabble | Edit this page |