Author: jacopoc
Date: Sat Nov 1 09:06:42 2014 New Revision: 1635901 URL: http://svn.apache.org/r1635901 Log: Merged json-integration-refactoring into trunk: * moved the json-lib jar (json-lib-2.2.3-jdk15.jar) from the framework/webapp to the framework/base component * removed the SQL select Parser.jj (parser definition) and its unit tests: it was not used (and never used) by any OFBiz code * removed the JSON.jj (parser definition) and its unit tests: it was not used (and never used) by any OFBiz code apart from the JSON Converters (now migrated to json-lib, see next items in this list) some utility methods in UtilIO.java (that have been removed too because they have never been used in OFBiz) * removed the JavaCC jar and related ant scripts because no more needed after the removal of Parser.jj and JSON.jj * converted the JSONConverter code that was based on JSON.jj to Jackson * added a new class org.ofbiz.base.lang.JSON that have been contributed by Adrian Crum that is a facade for simplifying the client code and for hiding the specific JSON library being used * removed an unused method: ImageManagementServices.toJsonObject(...) * added TestBooleanConverters to the list of tests * new unit tests for the new JSON converters * refactored Ajax code in applications to use the common request json response rather than a custom method * OFBIZ-5790 Implemented ability to call a service event by passing its input parameters in the request body as JSON data. These classes provide a simple mechanism, based on the request's content type, that can be extended to support other formats (e.g. XML). This commit resolves OFBIZ-4572, OFBIZ-3365, OFBIZ-5751, OFBIZ-5790 Added: ofbiz/trunk/framework/base/lib/jackson-annotations-2.4.0.jar - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/base/lib/jackson-annotations-2.4.0.jar ofbiz/trunk/framework/base/lib/jackson-core-2.4.2.jar - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/base/lib/jackson-core-2.4.2.jar ofbiz/trunk/framework/base/lib/jackson-databind-2.4.2.jar - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/base/lib/jackson-databind-2.4.2.jar ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/TestJSONConverters.java - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/base/src/org/ofbiz/base/conversion/test/TestJSONConverters.java ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/JSON.java - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/base/src/org/ofbiz/base/lang/JSON.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/JSONRequestBodyMapHandler.java - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/webapp/src/org/ofbiz/webapp/event/JSONRequestBodyMapHandler.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/RequestBodyMapHandler.java - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/webapp/src/org/ofbiz/webapp/event/RequestBodyMapHandler.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/RequestBodyMapHandlerFactory.java - copied unchanged from r1635900, ofbiz/branches/json-integration-refactoring/framework/webapp/src/org/ofbiz/webapp/event/RequestBodyMapHandlerFactory.java Removed: ofbiz/trunk/framework/base/ant-scripts/ofbiz-jjtree.groovy ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONResult.java ofbiz/trunk/framework/base/src/org/ofbiz/base/json/ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLUtil.java ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Main.java ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SQLTest.java ofbiz/trunk/framework/webapp/lib/json-lib-2.2.3-jdk15.jar ofbiz/trunk/lib/ Modified: ofbiz/trunk/ (props changed) ofbiz/trunk/.classpath ofbiz/trunk/LICENSE ofbiz/trunk/NOTICE ofbiz/trunk/applications/humanres/src/org/ofbiz/humanres/HumanResEvents.java ofbiz/trunk/applications/humanres/webapp/humanres/WEB-INF/controller.xml ofbiz/trunk/applications/humanres/webapp/humanres/humanres/category/CategoryTree.ftl ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java (props changed) ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java ofbiz/trunk/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml ofbiz/trunk/applications/product/webapp/catalog/category/CategoryTree.ftl ofbiz/trunk/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl ofbiz/trunk/framework/base/build.xml ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java ofbiz/trunk/framework/base/testdef/basetests.xml ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java ofbiz/trunk/framework/sql/build.xml ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SelectTest.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java ofbiz/trunk/macros.xml ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/StoreSetting.ftl ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl Propchange: ofbiz/trunk/ ------------------------------------------------------------------------------ Merged /ofbiz/branches/json-integration-refactoring:r1634077-1635900 Modified: ofbiz/trunk/.classpath URL: http://svn.apache.org/viewvc/ofbiz/trunk/.classpath?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/.classpath (original) +++ ofbiz/trunk/.classpath Sat Nov 1 09:06:42 2014 @@ -29,6 +29,9 @@ <classpathentry kind="lib" path="framework/base/lib/ical4j-1.0-rc2.jar"/> <classpathentry kind="lib" path="framework/base/lib/icu4j-52_1.jar"/> <classpathentry kind="lib" path="framework/base/lib/ivy-2.2.0.jar"/> + <classpathentry kind="lib" path="framework/base/lib/jackson-annotations-2.4.0.jar"/> + <classpathentry kind="lib" path="framework/base/lib/jackson-core-2.4.2.jar"/> + <classpathentry kind="lib" path="framework/base/lib/jackson-databind-2.4.2.jar"/> <classpathentry kind="lib" path="framework/base/lib/javolution-5.4.3.jar"/> <classpathentry kind="lib" path="framework/base/lib/jdbm-1.0-SNAPSHOT.jar"/> <classpathentry kind="lib" path="framework/base/lib/jdom-1.1.jar"/> @@ -130,7 +133,6 @@ <classpathentry kind="lib" path="framework/testtools/lib/org.springframework.core-3.1.0.M2.jar"/> <classpathentry kind="lib" path="framework/webapp/lib/ezmorph-0.9.1.jar"/> <classpathentry kind="lib" path="framework/webapp/lib/iText-2.1.7.jar"/> - <classpathentry kind="lib" path="framework/webapp/lib/json-lib-2.2.3-jdk15.jar"/> <classpathentry kind="lib" path="framework/webapp/lib/rome-0.9.jar"/> <classpathentry kind="lib" path="specialpurpose/googlecheckout/lib/checkout-sdk-0.8.8.jar"/> <classpathentry kind="lib" path="specialpurpose/ldap/lib/cas-server-core-3.3.jar"/> @@ -157,7 +159,6 @@ <classpathentry kind="src" path="applications/humanres/src"/> <classpathentry kind="src" path="applications/workeffort/src"/> <classpathentry kind="src" path="specialpurpose/appserver/src"/> - <classpathentry kind="src" path="framework/base/build/gen-src/javacc"/> <classpathentry excluding="org/ofbiz/base/config/CoberturaInstrumenter.java" kind="src" path="framework/base/src"/> <classpathentry kind="src" path="framework/bi/src"/> <classpathentry kind="src" path="specialpurpose/birt/src"/> @@ -172,7 +173,6 @@ <classpathentry kind="src" path="framework/security/src"/> <classpathentry kind="src" path="framework/service/src"/> <classpathentry kind="src" path="framework/sql/src"/> - <classpathentry kind="src" path="framework/sql/build/gen-src/javacc"/> <classpathentry kind="src" path="framework/start/src"/> <classpathentry kind="src" path="framework/testtools/src"/> <classpathentry excluding="org/ofbiz/webapp/view/JasperReportsPdfViewHandler.java|org/ofbiz/webapp/view/JasperReportsXmlViewHandler.java|org/ofbiz/webapp/view/JasperReportsJXlsViewHandler.java|org/ofbiz/webapp/view/JasperReportsPoiXlsViewHandler.java" kind="src" path="framework/webapp/src"/> Modified: ofbiz/trunk/LICENSE URL: http://svn.apache.org/viewvc/ofbiz/trunk/LICENSE?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/LICENSE (original) +++ ofbiz/trunk/LICENSE Sat Nov 1 09:06:42 2014 @@ -23,6 +23,9 @@ framework/base/lib/httpclient-4.2.1.jar framework/base/lib/httpclient-cache-4.2.1.jar framework/base/lib/httpcore-4.2.1.jar framework/base/lib/ivy-2.2.0.jar +framework/base/lib/jackson-annotations-2.4.0.jar +framework/base/lib/jackson-core-2.4.2.jar +framework/base/lib/jackson-databind-2.4.2.jar framework/base/lib/jakarta-regexp-1.5.jar framework/base/lib/jpim-0.1.jar framework/base/lib/juel-impl-2.2.7.jar @@ -92,7 +95,6 @@ framework/service/lib/neethi-2.0.4.jar framework/service/lib/XmlSchema-1.4.3.jar framework/webapp/lib/fop-1.1.jar framework/webapp/lib/xmlgraphics-commons-1.5.jar -framework/webapp/lib/json-lib-2.2.3-jdk15.jar framework/webapp/lib/ezmorph-0.9.1.jar framework/webapp/lib/rome-0.9.jar framework/webapp/lib/serializer-2.7.0.jar @@ -439,7 +441,6 @@ framework/base/lib/bsh-engine-modified.j framework/base/lib/hamcrest-all-1.2.jar framework/base/lib/httpunit-1.7.jar framework/base/lib/ical4j-1.0-rc2.jar -lib/build/javacc/javacc.jar (5.0) framework/base/lib/javolution-5.4.3.jar framework/base/lib/xpp3-1.1.4c.jar framework/base/lib/xstream-1.4.6.jar Modified: ofbiz/trunk/NOTICE URL: http://svn.apache.org/viewvc/ofbiz/trunk/NOTICE?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/NOTICE (original) +++ ofbiz/trunk/NOTICE Sat Nov 1 09:06:42 2014 @@ -253,12 +253,6 @@ jpim is released under a modified BSD st Java PIM Library (jpim) Copyright (c) 2001-2003 jpim development team. ========================================================================= -== JavaCC Notice == -========================================================================= - -This product includes software developed by the javacc team -(http://javacc.dev.java.net/). The included version is 4.1. -========================================================================= == XPP3 Notice == ========================================================================= Modified: ofbiz/trunk/applications/humanres/src/org/ofbiz/humanres/HumanResEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/humanres/src/org/ofbiz/humanres/HumanResEvents.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/humanres/src/org/ofbiz/humanres/HumanResEvents.java (original) +++ ofbiz/trunk/applications/humanres/src/org/ofbiz/humanres/HumanResEvents.java Sat Nov 1 09:06:42 2014 @@ -18,18 +18,14 @@ *******************************************************************************/ package org.ofbiz.humanres; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.io.Writer; +import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javolution.util.FastList; import javolution.util.FastMap; -import net.sf.json.JSONObject; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; @@ -46,7 +42,7 @@ public class HumanResEvents { // Please note : the structure of map in this function is according to the JSON data map of the jsTree @SuppressWarnings("unchecked") - public static void getChildHRCategoryTree(HttpServletRequest request, HttpServletResponse response){ + public static String getChildHRCategoryTree(HttpServletRequest request, HttpServletResponse response){ Delegator delegator = (Delegator) request.getAttribute("delegator"); String partyId = request.getParameter("partyId"); String onclickFunction = request.getParameter("onclickFunction"); @@ -54,7 +50,7 @@ public class HumanResEvents { String hrefString = request.getParameter("hrefString"); String hrefString2 = request.getParameter("hrefString2"); - List categoryList = FastList.newInstance(); + List categoryList = new ArrayList(); List<GenericValue> childOfComs; //check employee position try { @@ -107,11 +103,11 @@ public class HumanResEvents { categoryList.add(josonMap); } - toJsonObjectList(categoryList,response); } } } catch (Exception e) { e.printStackTrace(); + return "error"; } try { @@ -235,41 +231,12 @@ public class HumanResEvents { categoryList.add(emplMap); } } - - toJsonObjectList(categoryList,response); } } catch (Exception e) { e.printStackTrace(); + return "error"; } - } - - @SuppressWarnings("unchecked") - public static void toJsonObjectList(List attrList, HttpServletResponse response){ - String jsonStr = "["; - for (Object attrMap : attrList) { - JSONObject json = JSONObject.fromObject(attrMap); - jsonStr = jsonStr + json.toString() + ','; - } - jsonStr = jsonStr + "{ } ]"; - if (UtilValidate.isEmpty(jsonStr)) { - Debug.logError("JSON Object was empty; fatal error!",module); - } - // set the X-JSON content type - response.setContentType("application/json"); - // jsonStr.length is not reliable for unicode characters - try { - response.setContentLength(jsonStr.getBytes("UTF8").length); - } catch (UnsupportedEncodingException e) { - Debug.logError("Problems with Json encoding",module); - } - // return the JSON String - Writer out; - try { - out = response.getWriter(); - out.write(jsonStr); - out.flush(); - } catch (IOException e) { - Debug.logError("Unable to get response writer",module); - } + request.setAttribute("hrTree", categoryList); + return "success"; } } Modified: ofbiz/trunk/applications/humanres/webapp/humanres/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/humanres/webapp/humanres/WEB-INF/controller.xml?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/humanres/webapp/humanres/WEB-INF/controller.xml (original) +++ ofbiz/trunk/applications/humanres/webapp/humanres/WEB-INF/controller.xml Sat Nov 1 09:06:42 2014 @@ -1051,7 +1051,8 @@ under the License. <request-map uri="getHRChild"> <security auth="false" https="true"/> <event type="java" path="org.ofbiz.humanres.HumanResEvents" invoke="getChildHRCategoryTree"/> - <response name="success" type="none"/> + <response name="success" type="request" value="json"/> + <response name="error" type="request" value="json"/> </request-map> <request-map uri="createInternalOrg"> <security https="true" auth="true"/> Modified: ofbiz/trunk/applications/humanres/webapp/humanres/humanres/category/CategoryTree.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/humanres/webapp/humanres/humanres/category/CategoryTree.ftl?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/humanres/webapp/humanres/humanres/category/CategoryTree.ftl (original) +++ ofbiz/trunk/applications/humanres/webapp/humanres/humanres/category/CategoryTree.ftl Sat Nov 1 09:06:42 2014 @@ -69,7 +69,10 @@ var rawdata = [ "hrefString" : "viewprofile?partyId=" , "onclickFunction" : "callDocument" }; - } + }, + success : function(data) { + return data.hrTree; + } } }, "types" : { Propchange: ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java ------------------------------------------------------------------------------ Merged /ofbiz/branches/json-integration-refactoring/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java:r1634077-1635900 Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java Sat Nov 1 09:06:42 2014 @@ -18,9 +18,6 @@ *******************************************************************************/ package org.ofbiz.product.category; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.io.Writer; import java.sql.Timestamp; import java.util.List; import java.util.Locale; @@ -31,7 +28,6 @@ import javax.servlet.http.HttpServletRes import javolution.util.FastList; import javolution.util.FastMap; -import net.sf.json.JSONObject; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; @@ -434,7 +430,7 @@ public class CategoryServices { // Please note : the structure of map in this function is according to the JSON data map of the jsTree @SuppressWarnings("unchecked") - public static void getChildCategoryTree(HttpServletRequest request, HttpServletResponse response){ + public static String getChildCategoryTree(HttpServletRequest request, HttpServletResponse response){ Delegator delegator = (Delegator) request.getAttribute("delegator"); String productCategoryId = request.getParameter("productCategoryId"); String isCatalog = request.getParameter("isCatalog"); @@ -528,42 +524,13 @@ public class CategoryServices { categoryList.add(josonMap); } List<Map<Object, Object>> sortedCategoryList = UtilMisc.sortMaps(categoryList, sortList); - toJsonObjectList(sortedCategoryList,response); + request.setAttribute("treeData", sortedCategoryList); } } } catch (GenericEntityException e) { e.printStackTrace(); + return "error"; } - } - - public static void toJsonObjectList(List attrList, HttpServletResponse response){ - StringBuilder jsonBuilder = new StringBuilder("["); - for (Object attrMap : attrList) { - JSONObject json = JSONObject.fromObject(attrMap); - jsonBuilder.append(json.toString()); - jsonBuilder.append(','); - } - jsonBuilder.append("{ } ]"); - String jsonStr = jsonBuilder.toString(); - if (UtilValidate.isEmpty(jsonStr)) { - Debug.logError("JSON Object was empty; fatal error!",module); - } - // set the X-JSON content type - response.setContentType("application/json"); - // jsonStr.length is not reliable for unicode characters - try { - response.setContentLength(jsonStr.getBytes("UTF8").length); - } catch (UnsupportedEncodingException e) { - Debug.logError("Problems with Json encoding",module); - } - // return the JSON String - Writer out; - try { - out = response.getWriter(); - out.write(jsonStr); - out.flush(); - } catch (IOException e) { - Debug.logError("Unable to get response writer",module); - } + return "success"; } } Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java Sat Nov 1 09:06:42 2014 @@ -26,30 +26,17 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; -import java.io.UnsupportedEncodingException; -import java.io.Writer; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; import javax.imageio.ImageIO; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import javolution.util.FastList; import javolution.util.FastMap; -import net.sf.json.JSONObject; - -import org.apache.commons.fileupload.FileItem; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.disk.DiskFileItemFactory; -import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.jdom.JDOMException; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.FileUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; @@ -66,8 +53,6 @@ import org.ofbiz.service.DispatchContext import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; -import org.ofbiz.webapp.event.EventHandlerException; - /** * Product Services @@ -76,7 +61,6 @@ public class ImageManagementServices { public static final String module = ImageManagementServices.class.getName(); public static final String resource = "ProductErrorUiLabels"; - private static List<Map<String,Object>> josonMap = null; private static int imageCount = 0; private static String imagePath; @@ -649,131 +633,7 @@ public class ImageManagementServices { result.put("scaleFactor", scaleFactor); return result; } - - public static String multipleUploadImage(HttpServletRequest request, HttpServletResponse response) throws IOException, JDOMException { - HttpSession session = request.getSession(true); - GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); - LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - - Map<String, String> formInput = FastMap.newInstance(); - ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, FileUtil.getFile("runtime/tmp"))); - List<FileItem> lst = null; - try { - lst = UtilGenerics.checkList(fu.parseRequest(request)); - } catch (FileUploadException e4) { - return e4.getMessage(); - } - - FileItem fi = null; - FileItem imageFi = null; - byte[] imageBytes = {}; - for (int i=0; i < lst.size(); i++) { - fi = lst.get(i); - String fieldName = fi.getFieldName(); - if (fi.isFormField()) { - String fieldStr = fi.getString(); - formInput.put(fieldName, fieldStr); - } else if (fieldName.startsWith("imageData")) { - Map<String, Object> passedParams = FastMap.newInstance(); - Map<String, Object> contentLength = FastMap.newInstance(); - if(josonMap == null){ - josonMap = FastList.newInstance(); - } - imageFi = fi; - String fileName = fi.getName(); - String contentType = fi.getContentType(); - imageBytes = imageFi.get(); - ByteBuffer byteWrap = ByteBuffer.wrap(imageBytes); - passedParams.put("userLogin", userLogin); - passedParams.put("productId", formInput.get("productId")); - passedParams.put("productContentTypeId", "IMAGE"); - passedParams.put("_uploadedFile_fileName", fileName); - passedParams.put("_uploadedFile_contentType", contentType); - passedParams.put("uploadedFile", byteWrap); - passedParams.put("imageResize", formInput.get("imageResize")); - contentLength.put("imageSize", imageFi.getSize()); - josonMap.add(contentLength); - - if (passedParams.get("productId") != null) { - try { - dispatcher.runSync("addMultipleuploadForProduct", passedParams); - } catch (GenericServiceException e) { - Debug.logError(e, module); - return e.getMessage(); - } - } - - } - } - return "success"; - } - - public static String progressUploadImage(HttpServletRequest request, HttpServletResponse response) throws EventHandlerException{ - toJsonObjectList(josonMap,response); - josonMap.clear(); - return "success"; - } - - public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response){ - JSONObject json = JSONObject.fromObject(attrMap); - String jsonStr = json.toString(); - if (jsonStr == null) { - Debug.logError("JSON Object was empty; fatal error!",module); - } - // set the X-JSON content type - response.setContentType("application/json"); - // jsonStr.length is not reliable for unicode characters - try { - response.setContentLength(jsonStr.getBytes("UTF8").length); - } catch (UnsupportedEncodingException e) { - Debug.logError("Problems with Json encoding",module); - } - // return the JSON String - Writer out; - try { - out = response.getWriter(); - out.write(jsonStr); - out.flush(); - } catch (IOException e) { - Debug.logError("Unable to get response writer",module); - } - } - - public static void toJsonObjectList(List<Map<String,Object>> list, HttpServletResponse response) throws EventHandlerException { - JSONObject json = null; - List<JSONObject> jsonList = new ArrayList<JSONObject>(); - if (list != null) { - for (Map<String,Object> val : list) { - json = new JSONObject(); - for (String rowKey: val.keySet()) { - json.put(rowKey, val.get(rowKey)); - } - jsonList.add(json); - } - String jsonStr = jsonList.toString(); - if (jsonStr == null) { - throw new EventHandlerException("JSON Object was empty; fatal error!"); - } - // set the X-JSON content type - response.setContentType("application/json"); - // jsonStr.length is not reliable for unicode characters - try { - response.setContentLength(jsonStr.getBytes("UTF8").length); - } catch (UnsupportedEncodingException e) { - throw new EventHandlerException("Problems with Json encoding", e); - } - // return the JSON String - Writer out; - try { - out = response.getWriter(); - out.write(jsonStr); - out.flush(); - } catch (IOException e) { - throw new EventHandlerException("Unable to get response writer", e); - } - } - } - + public static File checkExistsImage(File file) { if (!file.exists()) { imageCount = 0; Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java Sat Nov 1 09:06:42 2014 @@ -18,9 +18,6 @@ *******************************************************************************/ package org.ofbiz.product.store; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.io.Writer; import java.util.List; import java.util.Map; @@ -30,9 +27,6 @@ import javax.servlet.http.HttpServletRes import javolution.util.FastList; import javolution.util.FastMap; -import net.sf.json.JSONObject; - -import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; @@ -47,7 +41,7 @@ public class ProductStoreEvents { // Please note : the structure of map in this function is according to the JSON data map of the jsTree @SuppressWarnings("unchecked") - public static void getChildProductStoreGroupTree(HttpServletRequest request, HttpServletResponse response){ + public static String getChildProductStoreGroupTree(HttpServletRequest request, HttpServletResponse response){ Delegator delegator = (Delegator) request.getAttribute("delegator"); String parentGroupId = request.getParameter("parentGroupId"); String onclickFunction = request.getParameter("onclickFunction"); @@ -92,41 +86,13 @@ public class ProductStoreEvents { productStoreGroupList.add(josonMap); } List<Map<Object, Object>> sortedProductStoreGroupList = UtilMisc.sortMaps(productStoreGroupList, sortList); - toJsonObjectList(sortedProductStoreGroupList,response); + request.setAttribute("storeGroupTree", sortedProductStoreGroupList); } } } catch (GenericEntityException e) { e.printStackTrace(); + return "error"; } - } - - @SuppressWarnings("unchecked") - public static void toJsonObjectList(List attrList, HttpServletResponse response){ - String jsonStr = "["; - for (Object attrMap : attrList) { - JSONObject json = JSONObject.fromObject(attrMap); - jsonStr = jsonStr + json.toString() + ','; - } - jsonStr = jsonStr + "{ } ]"; - if (UtilValidate.isEmpty(jsonStr)) { - Debug.logError("JSON Object was empty; fatal error!",module); - } - // set the X-JSON content type - response.setContentType("application/json"); - // jsonStr.length is not reliable for unicode characters - try { - response.setContentLength(jsonStr.getBytes("UTF8").length); - } catch (UnsupportedEncodingException e) { - Debug.logError("Problems with Json encoding",module); - } - // return the JSON String - Writer out; - try { - out = response.getWriter(); - out.write(jsonStr); - out.flush(); - } catch (IOException e) { - Debug.logError("Unable to get response writer",module); - } + return "success"; } } Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml (original) +++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml Sat Nov 1 09:06:42 2014 @@ -1457,7 +1457,8 @@ under the License. <request-map uri="getProductStoreGroupRollupHierarchy"> <security auth="false" https="true"/> <event type="java" path="org.ofbiz.product.store.ProductStoreEvents" invoke="getChildProductStoreGroupTree"/> - <response name="success" type="none"/> + <response name="success" type="request" value="json"/> + <response name="error" type="request" value="json"/> </request-map> <request-map uri="AddProductStoreToGroup"> <security auth="true" https="true"/> @@ -2900,17 +2901,6 @@ under the License. <response name="success" type="view" value="viewPreviewImage"/> <response name="error" type="view" value="viewPreviewImage"/> </request-map> - <request-map uri="multipleUploadImage"> - <security https="true" auth="true"/> - <event type="java" path="org.ofbiz.product.imagemanagement.ImageManagementServices" invoke="multipleUploadImage"/> - <response name="success" type="view" value="ImageUpload"/> - <response name="error" type="view" value="ImageUpload"/> - </request-map> - <request-map uri="progressUploadImage"> - <security https="true" auth="true"/> - <event type="java" path="org.ofbiz.virtualvillage.imagemanagement.ImageManagementServices" invoke="progressUploadImage"/> - <response name="success" type="view" value="main"/> - </request-map> <request-map uri="chooseFrameImage"> <security https="true" auth="true"/> <event type="java" path="org.ofbiz.product.imagemanagement.FrameImage" invoke="chooseFrameImage"/> @@ -3022,7 +3012,8 @@ under the License. <request-map uri="getChild"> <security auth="false" https="true"/> <event type="java" path="org.ofbiz.product.category.CategoryServices" invoke="getChildCategoryTree"/> - <response name="success" type="none"/> + <response name="success" type="request" value="json"/> + <response name="error" type="request" value="json"/> </request-map> <request-map uri="listMiniproduct"> <security auth="false" https="true"/> Modified: ofbiz/trunk/applications/product/webapp/catalog/category/CategoryTree.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/category/CategoryTree.ftl?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/category/CategoryTree.ftl (original) +++ ofbiz/trunk/applications/product/webapp/catalog/category/CategoryTree.ftl Sat Nov 1 09:06:42 2014 @@ -62,20 +62,24 @@ var rawdata = [ $.cookie('jstree_select', "<#if productCategoryId??>${productCategoryId}<#elseif prodCatalogId??>${prodCatalogId}<#elseif showProductCategoryId??>${showProductCategoryId}</#if>"); </#if> jQuery("#tree").jstree({ - "plugins" : [ "themes", "json_data","ui" ,"cookies", "types"], + "plugins" : [ "themes", "json_data","ui" ,"cookies", "types"], "json_data" : { "data" : rawdata, - "ajax" : { "url" : "<@ofbizUrl>getChild</@ofbizUrl>", "type" : "POST", - "data" : function (n) { - return { - "isCategoryType" : n.attr ? n.attr("isCatalog").replace("node_","") : 1 , - "isCatalog" : n.attr ? n.attr("isCatalog").replace("node_","") : 1 , - "productCategoryId" : n.attr ? n.attr("id").replace("node_","") : 1 , - "additionParam" : "','category" , - "hrefString" : "EditCategory?productCategoryId=" , - "onclickFunction" : "callDocument" - }; - } + "ajax" : { "url" : "<@ofbizUrl>getChild</@ofbizUrl>", + "type" : "POST", + "data" : function (n) { + return { + "isCategoryType" : n.attr ? n.attr("isCatalog").replace("node_","") : 1 , + "isCatalog" : n.attr ? n.attr("isCatalog").replace("node_","") : 1 , + "productCategoryId" : n.attr ? n.attr("id").replace("node_","") : 1 , + "additionParam" : "','category" , + "hrefString" : "EditCategory?productCategoryId=" , + "onclickFunction" : "callDocument" + }; + }, + success : function(data) { + return data.treeData; + } } }, "types" : { Modified: ofbiz/trunk/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl (original) +++ ofbiz/trunk/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl Sat Nov 1 09:06:42 2014 @@ -49,17 +49,21 @@ var rawdata = [ "plugins" : [ "themes", "json_data","ui" ,"cookies", "types"], "json_data" : { "data" : rawdata, - "ajax" : { "url" : "<@ofbizUrl>getProductStoreGroupRollupHierarchy</@ofbizUrl>", "type" : "POST", - "data" : function (n) { - return { - "parentGroupId" : n.attr ? n.attr("parentGroupId").replace("node_","") : 1, - "onclickFunction" : "callDocument" - }; - } + "ajax" : { "url" : "<@ofbizUrl>getProductStoreGroupRollupHierarchy</@ofbizUrl>", + "type" : "POST", + "data" : function (n) { + return { + "parentGroupId" : n.attr ? n.attr("parentGroupId").replace("node_","") : 1, + "onclickFunction" : "callDocument" + }; + }, + success : function (data) { + return data.storeGroupTree; + } } }, "types" : { - "valid_children" : [ "root" ] + "valid_children" : [ "root" ] } }); }); Modified: ofbiz/trunk/framework/base/build.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/build.xml?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/base/build.xml (original) +++ ofbiz/trunk/framework/base/build.xml Sat Nov 1 09:06:42 2014 @@ -51,6 +51,7 @@ under the License. <file name="org/ofbiz/base/conversion/test/TestBooleanConverters.java"/> <file name="org/ofbiz/base/conversion/test/DateTimeTests.java"/> <file name="org/ofbiz/base/conversion/test/MiscTests.java"/> + <file name="org/ofbiz/base/conversion/test/TestJSONConverters.java"/> <file name="org/ofbiz/base/util/test/UtilIOTests.java"/> <file name="org/ofbiz/base/test/BaseUnitTests.java"/> <file name="org/ofbiz/base/util/collections/test/GenericMapTest.java"/> @@ -80,20 +81,6 @@ under the License. </patternset> </target> - <target name="gen-src"> - <ofbiz-javacc dir="org/ofbiz/base/json" file="JSON"/> - </target> - - <target name="classes" depends="prepare,gen-src"> - <javac17> - <sourcepath> - <dirset dir="build/gen-src"> - <include name="javacc"/> - </dirset> - </sourcepath> - </javac17> - </target> - <target name="jar" depends="classes"> <main-jar> <main-elements> Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java Sat Nov 1 09:06:42 2014 @@ -18,124 +18,15 @@ *******************************************************************************/ package org.ofbiz.base.conversion; -import java.util.Collection; +import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Set; -import javolution.util.FastSet; - -import org.ofbiz.base.json.JSON; +import org.ofbiz.base.lang.JSON; import org.ofbiz.base.util.UtilGenerics; /** JSON Converter classes. */ public class JSONConverters implements ConverterLoader { - public static class ObjectToJSONResultCreator<R extends JSONResult> implements ConverterCreator, ConverterLoader { - public void loadConverters() { - Converters.registerCreator(this); - } - - public <S, T> Converter<S, T> createConverter(Class<S> sourceClass, Class<T> targetClass) { - if (!JSONResult.class.isAssignableFrom(targetClass)) { - return null; - } - if (Collection.class.isAssignableFrom(sourceClass)) { - } else if (Map.class.isAssignableFrom(sourceClass)) { - } else if (Byte.class == sourceClass) { - } else if (Character.class == sourceClass) { - } else if (Double.class == sourceClass) { - } else if (Float.class == sourceClass) { - } else if (Integer.class == sourceClass) { - } else if (Long.class == sourceClass) { - } else if (Short.class == sourceClass) { - } else { - return null; - } - return UtilGenerics.cast(new ObjectToJSONWriterResult<S, JSONResult>(sourceClass, UtilGenerics.<Class<JSONResult>>cast(targetClass))); - } - } - - private static class ObjectToJSONWriterResult<S, T extends JSONResult> extends AbstractConverter<S, T> { - public ObjectToJSONWriterResult(Class<S> sourceClass, Class<T> targetClass) { - super(sourceClass, targetClass); - } - - public T convert(S obj) throws ConversionException { - try { - T result = UtilGenerics.<T>cast(getTargetClass().newInstance()); - result.getWriter().write(obj); - return result; - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new ConversionException(e); - } - } - } - - public static class JSONToByte extends AbstractConverter<JSON, Byte> { - public JSONToByte() { - super(JSON.class, Byte.class); - } - - public Byte convert(JSON obj) throws ConversionException { - try { - return obj.JSONLong().byteValue(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new ConversionException(e); - } - } - } - - public static class JSONToDouble extends AbstractConverter<JSON, Double> { - public JSONToDouble() { - super(JSON.class, Double.class); - } - - public Double convert(JSON obj) throws ConversionException { - try { - return obj.JSONFloat(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new ConversionException(e); - } - } - } - - public static class JSONToFloat extends AbstractConverter<JSON, Float> { - public JSONToFloat() { - super(JSON.class, Float.class); - } - - public Float convert(JSON obj) throws ConversionException { - try { - return obj.JSONFloat().floatValue(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new ConversionException(e); - } - } - } - - public static class JSONToInteger extends AbstractConverter<JSON, Integer> { - public JSONToInteger() { - super(JSON.class, Integer.class); - } - - public Integer convert(JSON obj) throws ConversionException { - try { - return obj.JSONLong().intValue(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new ConversionException(e); - } - } - } public static class JSONToList extends AbstractConverter<JSON, List<Object>> { public JSONToList() { @@ -144,26 +35,8 @@ public class JSONConverters implements C public List<Object> convert(JSON obj) throws ConversionException { try { - return obj.JSONArray(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new ConversionException(e); - } - } - } - - public static class JSONToLong extends AbstractConverter<JSON, Long> { - public JSONToLong() { - super(JSON.class, Long.class); - } - - public Long convert(JSON obj) throws ConversionException { - try { - return obj.JSONLong(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { + return UtilGenerics.<List<Object>>cast(obj.toObject(List.class)); + } catch (IOException e) { throw new ConversionException(e); } } @@ -176,44 +49,36 @@ public class JSONConverters implements C public Map<String, Object> convert(JSON obj) throws ConversionException { try { - return obj.JSONObject(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { + return UtilGenerics.<Map<String, Object>>cast(obj.toObject(Map.class)); + } catch (IOException e) { throw new ConversionException(e); } } } - public static class JSONToShort extends AbstractConverter<JSON, Short> { - public JSONToShort() { - super(JSON.class, Short.class); + public static class ListToJSON extends AbstractConverter<List<Object>, JSON> { + public ListToJSON() { + super(List.class, JSON.class); } - public Short convert(JSON obj) throws ConversionException { + public JSON convert(List<Object> obj) throws ConversionException { try { - return obj.JSONLong().shortValue(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { + return JSON.from(obj); + } catch (IOException e) { throw new ConversionException(e); } } } - public static class JSONToSet extends AbstractConverter<JSON, Set<Object>> { - public JSONToSet() { - super(JSON.class, Set.class); + public static class MapToJSON extends AbstractConverter<Map<String, Object>, JSON> { + public MapToJSON() { + super(Map.class, JSON.class); } - public Set<Object> convert(JSON obj) throws ConversionException { + public JSON convert(Map<String, Object> obj) throws ConversionException { try { - Set<Object> set = FastSet.newInstance(); - set.addAll(obj.JSONArray()); - return set; - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { + return JSON.from(obj); + } catch (IOException e) { throw new ConversionException(e); } } Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java Sat Nov 1 09:06:42 2014 @@ -21,7 +21,6 @@ package org.ofbiz.base.conversion.test; import java.math.BigDecimal; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,12 +31,10 @@ import javolution.util.FastMap; import org.ofbiz.base.conversion.Converter; import org.ofbiz.base.conversion.ConverterLoader; import org.ofbiz.base.conversion.Converters; -import org.ofbiz.base.conversion.JSONResult; import org.ofbiz.base.lang.SourceMonitored; import org.ofbiz.base.test.GenericTestCaseBase; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.collections.LRUMap; @SourceMonitored public class MiscTests extends GenericTestCaseBase { @@ -46,12 +43,6 @@ public class MiscTests extends GenericTe super(name); } - private static <S, T extends JSONResult.Indenting> void assertConversion(String label, String wanted, Class<T> targetClass, Object source, Class<S> sourceClass) throws Exception { - Converter<S, T> converter = Converters.getConverter(sourceClass, targetClass); - assertTrue(label + " can convert", converter.canConvert(sourceClass, targetClass)); - assertEquals(label, wanted, converter.convert(UtilGenerics.<S>cast(source)).getResult()); - } - public void testStaticHelperClass() throws Exception { assertStaticHelperClass(Converters.class); } @@ -66,22 +57,6 @@ public class MiscTests extends GenericTe Converters.loadContainedConverters(MiscTests.class); } - public void testExtendsImplements() throws Exception { - List<String> arraysList = Arrays.asList("a", "b", "c"); - assertConversion("", "[\n \"a\",\n \"b\",\n \"c\"\n]", JSONResult.Indenting.class, arraysList, arraysList.getClass()); - Exception caught = null; - try { - Converters.getConverter(MiscTests.class, String.class); - } catch (ClassNotFoundException e) { - caught = e; - } finally { - assertNotNull("ClassNotFoundException thrown for MiscTests.class", caught); - } - LRUMap<String, String> map = new LRUMap<String, String>(); - map.put("a", "1"); - assertConversion("", "{\n \"a\": \"1\"\n}", JSONResult.Indenting.class, map, LRUMap.class); - } - public static <S> void assertPassThru(Object wanted, Class<S> sourceClass) throws Exception { assertPassThru(wanted, sourceClass, sourceClass); } Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java Sat Nov 1 09:06:42 2014 @@ -19,34 +19,20 @@ package org.ofbiz.base.util; import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.Reader; -import java.io.Serializable; -import java.io.StringReader; -import java.io.StringWriter; import java.io.Writer; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.ofbiz.base.conversion.Converter; -import org.ofbiz.base.conversion.Converters; -import org.ofbiz.base.json.JSON; -import org.ofbiz.base.json.JSONWriter; public final class UtilIO { public static final Charset UTF8 = Charset.forName("UTF-8"); @@ -329,141 +315,4 @@ public final class UtilIO { writer.write(value.substring(r)); writer.close(); } - - public static Object readObject(File file) throws ClassNotFoundException, IOException { - return readObject(new FileInputStream(file), false); - } - - public static Object readObject(File file, boolean allowJsonResolve) throws ClassNotFoundException, IOException { - return readObject(new FileInputStream(file), allowJsonResolve); - } - - public static Object readObject(InputStream in) throws ClassNotFoundException, IOException { - return readObject(in, false); - } - - public static Object readObject(InputStream in, boolean allowJsonResolve) throws ClassNotFoundException, IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - IOUtils.copy(in, baos); - in.close(); - byte[] bytes = baos.toByteArray(); - try { - char[] buffer = StringUtils.chomp(readString(bytes)).toCharArray(); - return parseObject(buffer, 0, buffer.length, allowJsonResolve); - } catch (Exception e) { - } - ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bytes)); - Serializable value = (Serializable) oin.readObject(); - oin.close(); - return value; - } - - public static Object readObject(char[] buffer) throws ClassNotFoundException, IOException { - return parseObject(buffer, 0, buffer.length, false); - } - - public static Object readObject(char[] buffer, int offset, int length) throws ClassNotFoundException, IOException { - return parseObject(buffer, offset, length, false); - } - - private static <S, T> T convertObject(Class<S> sourceClass, S value, Class<T> targetClass) throws Exception { - Converter<S, T> converter = Converters.getConverter(sourceClass, targetClass); - return converter.convert(targetClass, value); - } - - private static Object parseObject(char[] buffer, int offset, int length, boolean allowJsonResolve) throws ClassNotFoundException, IOException { - try { - int i; - for (i = offset; i < length && buffer[i] != ':'; i++); - if (i > offset && i < length) { - String className = new String(buffer, offset, i); - Class<?> type = Class.forName(className); - if (buffer[length - 1] == '\n') { - length--; - } - if (buffer[length - 1] == '\r') { - length--; - } - return convertObject(String.class, new String(buffer, i + 1, length - i - 1), type); - } - } catch (Exception e) { - } - try { - return new JSON(new StringReader(new String(buffer, offset, length))).allowResolve(allowJsonResolve).JSONValue(); - } catch (Error e) { - } catch (Exception e) { - } - throw new IOException("Can't read (" + new String(buffer, offset, length) + ")"); - } - - public static void writeObject(File file, Object value) throws IOException { - writeObject(new FileOutputStream(file), value, false); - } - - public static void writeObject(File file, Object value, boolean allowJsonResolve) throws IOException { - writeObject(new FileOutputStream(file), value, allowJsonResolve); - } - - public static void writeObject(OutputStream out, Object value) throws IOException { - writeObject(out, value, false); - } - - public static void writeObject(OutputStream out, Object value, boolean allowJsonResolve) throws IOException { - try { - PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, UTF8)); - if (encodeObject(writer, value, allowJsonResolve)) { - writer.println(); - writer.close(); - return; - } - } catch (Exception e) { - } - ObjectOutputStream oout = new ObjectOutputStream(out); - oout.writeObject(value); - oout.close(); - out.close(); - } - - private static <T> boolean encodeObject(Writer writer, T value, boolean allowJsonResolve) throws Exception { - Converter<T, String> converter = UtilGenerics.cast(Converters.getConverter(value.getClass(), String.class)); - if (converter != null) { - Class<?> clz = converter.getSourceClass(); - String str = converter.convert(value); - if (clz != null) { - writer.write(clz.getName()); - } else { - writer.write(value.getClass().getName()); - } - writer.write(':'); - writer.write(str); - return true; - } else { - StringWriter sw = new StringWriter(); - IndentingWriter indenting = new IndentingWriter(writer, true, false); - JSONWriter jsonWriter; - if (allowJsonResolve) { - jsonWriter = new JSONWriter(indenting, JSONWriter.ResolvingFallbackHandler); - } else { - jsonWriter = new JSONWriter(indenting); - } - jsonWriter.write(value); - writer.write(sw.toString()); - return true; - } - } - - public static void writeObject(StringBuilder sb, Object value) throws IOException { - writeObject(sb, value, false); - } - - public static void writeObject(StringBuilder sb, Object value, boolean allowJsonResolve) throws IOException { - try { - StringWriter writer = new StringWriter(); - if (encodeObject(writer, value, allowJsonResolve)) { - sb.append(writer.toString()); - return; - } - } catch (Exception e) {} //Empty catch because writeObject() calls encodeObject(), which *always* returns true, unless an error occurs. - throw new IOException("Can't write (" + value + ")"); - } } Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/UtilIOTests.java Sat Nov 1 09:06:42 2014 @@ -129,53 +129,4 @@ public class UtilIOTests extends Generic UtilIO.writeString(baos, UtilIO.UTF8, toWrite); assertEquals("writeString UTF8:" + label, wanted, baos.toByteArray()); } - - protected void checkBasicReadObject(Object value, String text) throws Exception { - byte[] bytes = text.getBytes("UTF-8"); - assertEquals("read bytes " + value.getClass().getName(), value, UtilIO.readObject(new ByteArrayInputStream(bytes))); - assertEquals("read chars " + value.getClass().getName(), value, UtilIO.readObject(text.toCharArray())); - assertEquals("read chars offset " + value.getClass().getName(), value, UtilIO.readObject(text.toCharArray(), 0, text.length())); - } - - protected void checkBasicReadWriteObject(Object value, String text) throws Exception { - String lineEnding = System.getProperty("line.separator"); - text = text.replaceAll("\n", lineEnding); - byte[] bytes = text.getBytes("UTF-8"); - assertEquals("read bytes " + value.getClass().getName(), value, UtilIO.readObject(new ByteArrayInputStream(bytes))); - assertEquals("read chars " + value.getClass().getName(), value, UtilIO.readObject(text.toCharArray())); - assertEquals("read chars offset " + value.getClass().getName(), value, UtilIO.readObject(text.toCharArray(), 0, text.length())); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - UtilIO.writeObject(baos, value); - assertEquals("write stream " + value.getClass().getName(), text, new String(baos.toByteArray(), "UTF-8")); - StringBuilder sb = new StringBuilder(); - UtilIO.writeObject(sb, value); - sb.append(lineEnding); - assertEquals("write builder " + value.getClass().getName(), text, sb.toString()); - } - - public void testReadWriteObject() throws Exception { - checkBasicReadWriteObject(Boolean.TRUE, "java.lang.Boolean:true\n"); - checkBasicReadWriteObject(Byte.valueOf("1"), "java.lang.Byte:1\n"); - checkBasicReadWriteObject(Double.valueOf("1.0"), "java.lang.Double:1.0\n"); - checkBasicReadWriteObject(Float.valueOf("1.0"), "java.lang.Float:1.0\n"); - checkBasicReadWriteObject(Integer.valueOf("1"), "java.lang.Integer:1\n"); - checkBasicReadWriteObject(Long.valueOf("1"), "java.lang.Long:1\n"); - checkBasicReadWriteObject(Short.valueOf("1"), "java.lang.Short:1\n"); - checkBasicReadWriteObject(BigDecimal.valueOf(500.5), "java.math.BigDecimal:500.5\n"); - checkBasicReadWriteObject(BigInteger.valueOf(500), "java.math.BigInteger:500\n"); - checkBasicReadWriteObject("1", "java.lang.String:1\n"); - checkBasicReadObject(Arrays.asList(new Object[] {"a", UtilMisc.toMap("b", Long.valueOf(1))}), "[\n \"a\",\n {\n \"b\": 1\n }\n]\n"); - checkBasicReadWriteObject(MemoryType.HEAP, "java.lang.management.MemoryType:HEAP\n"); - checkBasicReadWriteObject(MemoryType.NON_HEAP, "java.lang.management.MemoryType:NON_HEAP\n"); - checkBasicReadWriteObject(UtilIO.UTF8, "java.nio.charset.Charset:UTF-8\n"); - checkBasicReadWriteObject(InetAddress.getByAddress("localhost", new byte[] {127, 0, 0, 1}), "java.net.InetAddress:localhost\n"); - //checkBasicReadWriteObject(Pattern.compile("^([a-z]{3}.*?):$"), "java.util.regex.Pattern:^([a-z]{3}.*?):$\n"); - checkBasicReadWriteObject(Time.valueOf("12:34:56"), "java.sql.Time:12:34:56\n"); - //checkBasicReadWriteObject(new Timestamp(1234567890), "java.sql.Timestamp:1234567890 00:00:00\n"); - //checkBasicReadWriteObject(new java.util.Date(1234567890), "java.util.Date:1234567890\n"); - checkBasicReadWriteObject(UUID.fromString("c3241927-9f77-43e1-be16-bd71d245ef64"), "java.util.UUID:c3241927-9f77-43e1-be16-bd71d245ef64\n"); - checkBasicReadWriteObject(TimeZone.getTimeZone("America/Chicago"), "java.util.TimeZone:America/Chicago\n"); - checkBasicReadWriteObject(new SimpleDateFormat("MM/dd/yyyy hh:mm a"), "java.text.SimpleDateFormat:MM/dd/yyyy hh:mm a\n"); - checkBasicReadWriteObject(new Locale("en", "us"), "java.util.Locale:en_US\n"); - } } Modified: ofbiz/trunk/framework/base/testdef/basetests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/testdef/basetests.xml?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/base/testdef/basetests.xml (original) +++ ofbiz/trunk/framework/base/testdef/basetests.xml Sat Nov 1 09:06:42 2014 @@ -32,7 +32,8 @@ <junit-test-suite class-name="org.ofbiz.base.util.cache.test.UtilCacheTests"/> <junit-test-suite class-name="org.ofbiz.base.conversion.test.DateTimeTests"/> <junit-test-suite class-name="org.ofbiz.base.conversion.test.MiscTests"/> - <junit-test-suite class-name="org.ofbiz.base.json.test.JSONTests"/> + <junit-test-suite class-name="org.ofbiz.base.conversion.test.TestBooleanConverters"/> + <junit-test-suite class-name="org.ofbiz.base.conversion.test.TestJSONConverters"/> <!--junit-test-suite class-name="org.ofbiz.base.util.test.UtilIOTests"/--> <junit-test-suite class-name="org.ofbiz.base.test.BaseUnitTests"/> <junit-test-suite class-name="org.ofbiz.base.util.test.UtilPropertiesTests"/> Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java Sat Nov 1 09:06:42 2014 @@ -28,8 +28,8 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -41,13 +41,10 @@ import javax.servlet.http.HttpServletReq import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import net.sf.json.JSON; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; -import net.sf.json.JSONSerializer; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.StringUtils; +import org.ofbiz.base.lang.JSON; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilGenerics; @@ -289,15 +286,16 @@ public class CommonEvents { attrMap.remove(ignoreAttr); } } - - // create a JSON Object for return - JSONObject json = JSONObject.fromObject(attrMap); - writeJSONtoResponse(json, request.getMethod(), response); - + try { + JSON json = JSON.from(attrMap); + writeJSONtoResponse(json, request.getMethod(), response); + } catch (Exception e) { + return "error"; + } return "success"; } - private static void writeJSONtoResponse(JSON json, String httpMethod, HttpServletResponse response) { + private static void writeJSONtoResponse(JSON json, String httpMethod, HttpServletResponse response) throws UnsupportedEncodingException { String jsonStr = json.toString(); if (jsonStr == null) { Debug.logError("JSON Object was empty; fatal error!", module); @@ -307,21 +305,17 @@ public class CommonEvents { // This was added for security reason (OFBIZ-5409), you might need to remove the "//" prefix when handling the JSON response // Though normally you simply have to access the data you want, so should not be annoyed by the "//" prefix if ("GET".equalsIgnoreCase(httpMethod)) { - Debug.logWarning("for security reason (OFBIZ-5409) the the '//' prefix was added handling the JSON response. " + - "Normally you simply have to access the data you want, so should not be annoyed by the '//' prefix." + - "You might need to remove it if you use Ajax GET responses (not recommended)." + - "In case, the util.js scrpt is there to help you", module); + Debug.logWarning("for security reason (OFBIZ-5409) the the '//' prefix was added handling the JSON response. " + + "Normally you simply have to access the data you want, so should not be annoyed by the '//' prefix." + + "You might need to remove it if you use Ajax GET responses (not recommended)." + + "In case, the util.js scrpt is there to help you", module); jsonStr = "//" + jsonStr; } // set the X-JSON content type response.setContentType("application/x-json"); // jsonStr.length is not reliable for unicode characters - try { - response.setContentLength(jsonStr.getBytes("UTF8").length); - } catch (UnsupportedEncodingException e) { - Debug.logError("Problems with Json encoding: " + e, module); - } + response.setContentLength(jsonStr.getBytes("UTF8").length); // return the JSON String Writer out; @@ -334,81 +328,65 @@ public class CommonEvents { } } - - public static String getJSONuiLabelArray(HttpServletRequest request, HttpServletResponse response) { - String requiredLabels = request.getParameter("requiredLabels"); - - JSONObject uiLabelObject = null; - if (UtilValidate.isNotEmpty(requiredLabels)) { - // Transform JSON String to Object - uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels); + public static String getJSONuiLabelArray(HttpServletRequest request, HttpServletResponse response) + throws UnsupportedEncodingException, IOException { + // Format - {resource1 : [key1, key2 ...], resource2 : [key1, key2, ...], ...} + String jsonString = request.getParameter("requiredLabels"); + Map<String, List<String>> uiLabelObject = null; + if (UtilValidate.isNotEmpty(jsonString)) { + JSON json = JSON.from(jsonString); + uiLabelObject = UtilGenerics.<Map<String, List<String>>> cast(json.toObject(Map.class)); + } + if (UtilValidate.isEmpty(uiLabelObject)) { + Debug.logError("No resource and labels found in JSON string: " + jsonString, module); + return "error"; } - - JSONObject jsonUiLabel = new JSONObject(); Locale locale = request.getLocale(); - if(!uiLabelObject.isEmpty()) { - Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet()); - // Iterate over the resouce set - for (String resource : resourceSet) { - JSONArray labels = uiLabelObject.getJSONArray(resource); - if (labels.isEmpty() || labels == null) { - continue; + Map<String, List<String>> uiLabelMap = new HashMap<String, List<String>>(); + Set<Map.Entry<String, List<String>>> entrySet = uiLabelObject.entrySet(); + for (Map.Entry<String, List<String>> entry : entrySet) { + String resource = entry.getKey(); + List<String> resourceKeys = entry.getValue(); + if (resourceKeys != null) { + List<String> labels = new ArrayList<String>(resourceKeys.size()); + for (String resourceKey : resourceKeys) { + String label = UtilProperties.getMessage(resource, resourceKey, locale); + labels.add(label); } - - // Iterate over the uiLabel List - Iterator<String> jsonLabelIterator = UtilGenerics.cast(labels.iterator()); - JSONArray resourceLabelList = new JSONArray(); - while(jsonLabelIterator.hasNext()) { - String label = jsonLabelIterator.next(); - String receivedLabel = UtilProperties.getMessage(resource, label, locale); - if (UtilValidate.isNotEmpty(receivedLabel)) { - resourceLabelList.add(receivedLabel); - } - } - jsonUiLabel.element(resource, resourceLabelList); + uiLabelMap.put(resource, labels); } } - - writeJSONtoResponse(jsonUiLabel, request.getMethod(), response); + writeJSONtoResponse(JSON.from(uiLabelMap), request.getMethod(), response); return "success"; } - public static String getJSONuiLabel(HttpServletRequest request, HttpServletResponse response) { - String requiredLabels = request.getParameter("requiredLabel"); - - JSONObject uiLabelObject = null; - if (UtilValidate.isNotEmpty(requiredLabels)) { - // Transform JSON String to Object - uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels); + public static String getJSONuiLabel(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + // Format - {resource : key} + String jsonString = request.getParameter("requiredLabel"); + Map<String, String> uiLabelObject = null; + if (UtilValidate.isNotEmpty(jsonString)) { + JSON json = JSON.from(jsonString); + uiLabelObject = UtilGenerics.<Map<String, String>>cast(json.toObject(Map.class)); + } + if (UtilValidate.isEmpty(uiLabelObject)) { + Debug.logError("No resource and labels found in JSON string: " + jsonString, module); + return "error"; + } else if (uiLabelObject.size() > 1) { + Debug.logError("More than one resource found, please use the method: getJSONuiLabelArray", module); + return "error"; } - - JSONArray jsonUiLabel = new JSONArray(); Locale locale = request.getLocale(); - if(!uiLabelObject.isEmpty()) { - Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet()); - // Iterate over the resource set - // here we need a keySet because we don't now which label resource to load - // the key set should have the size one, if greater or empty error should returned - if (UtilValidate.isEmpty(resourceSet)) { - Debug.logError("No resource and labels found", module); - return "error"; - } else if (resourceSet.size() > 1) { - Debug.logError("More than one resource found, please use the method: getJSONuiLabelArray", module); - return "error"; - } - - for (String resource : resourceSet) { - String label = uiLabelObject.getString(resource); - if (UtilValidate.isEmail(label)) { - continue; - } - - String receivedLabel = UtilProperties.getMessage(resource, label, locale); - jsonUiLabel.add(receivedLabel); + Map<String, String> uiLabelMap = new HashMap<String, String>(); + Set<Map.Entry<String, String>> entrySet = uiLabelObject.entrySet(); + for (Map.Entry<String, String> entry : entrySet) { + String resource = entry.getKey(); + String resourceKey = entry.getValue(); + if (resourceKey != null) { + String label = UtilProperties.getMessage(resource, resourceKey, locale); + uiLabelMap.put(resource, label); } } - - writeJSONtoResponse(jsonUiLabel, request.getMethod(), response); + writeJSONtoResponse(JSON.from(uiLabelMap), request.getMethod(), response); return "success"; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Sat Nov 1 09:06:42 2014 @@ -37,7 +37,9 @@ import java.util.concurrent.atomic.Atomi import javax.sql.rowset.serial.SerialBlob; import org.ofbiz.base.concurrent.ExecutionPool; +import org.ofbiz.base.lang.JSON; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.Observable; import org.ofbiz.base.util.Observer; import org.ofbiz.base.util.UtilDateTime; @@ -1209,6 +1211,23 @@ public class EntityTestSuite extends Ent assertTrue("One big transaction was not faster than several small ones", totalTimeOneTransaction < totalTimeSeveralSmallTransactions); } + public void testConverters() throws Exception { + // Must use the default delegator because the deserialized GenericValue can't + // find the randomized one. + Delegator localDelegator = DelegatorFactory.getDelegator("default"); + GenericValue testValue = localDelegator.create("Testing", "testingId", "JSON_TEST", "testingTypeId", "TEST-UPDATE-1", + "description", "Testing JSON Converters", "testingSize", (long) 123, "testingDate", + new Timestamp(System.currentTimeMillis())); + assertNotNull("Created GenericValue not null", testValue); + JSON json = (JSON) ObjectType.simpleTypeConvert(testValue, "org.ofbiz.base.lang.JSON", null, null); + assertNotNull("JSON instance not null", json); + GenericValue convertedValue = (GenericValue) ObjectType.simpleTypeConvert(json, "org.ofbiz.entity.GenericValue", null, + null); + assertNotNull("GenericValue converted from JSON not null", convertedValue); + assertEquals("GenericValue converted from JSON equals original value", testValue, convertedValue); + testValue.remove(); + } + private final class TestObserver implements Observer { private Observable observable; private Object arg; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/Converters.java Sat Nov 1 09:06:42 2014 @@ -18,19 +18,79 @@ *******************************************************************************/ package org.ofbiz.entity.util; +import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import org.ofbiz.base.conversion.AbstractConverter; import org.ofbiz.base.conversion.ConversionException; import org.ofbiz.base.conversion.ConverterLoader; +import org.ofbiz.base.lang.JSON; +import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.DelegatorFactory; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.model.ModelFieldType; /** Entity Engine <code>Converter</code> classes. */ public class Converters implements ConverterLoader { + + public static class JSONToGenericValue extends AbstractConverter<JSON, GenericValue> { + public JSONToGenericValue() { + super(JSON.class, GenericValue.class); + } + + public GenericValue convert(JSON obj) throws ConversionException { + Map<String, Object> fieldMap; + try { + fieldMap = UtilGenerics.<Map<String, Object>>cast(obj.toObject(Map.class)); + String delegatorName = (String) fieldMap.remove("_DELEGATOR_NAME_"); + String entityName = (String) fieldMap.remove("_ENTITY_NAME_"); + if (delegatorName == null || entityName == null) { + throw new ConversionException("Invalid JSON object"); + } + Delegator delegator = DelegatorFactory.getDelegator(delegatorName); + GenericValue value = delegator.makeValue(entityName); + for (Map.Entry<String, Object> entry : fieldMap.entrySet()) { + String fieldName = entry.getKey(); + Object fieldValue = entry.getValue(); + ModelField field = value.getModelEntity().getField(fieldName); + ModelFieldType type = delegator.getEntityFieldType(value.getModelEntity(), field.getType()); + value.set(fieldName, ObjectType.simpleTypeConvert(fieldValue, type.getJavaType(), null, null)); + } + return value; + } catch (ConversionException e) { + throw e; + } catch (Exception e) { + throw new ConversionException(e); + } + } + } + + public static class GenericValueToJSON extends AbstractConverter<GenericValue, JSON> { + public GenericValueToJSON() { + super(GenericValue.class, JSON.class); + } + + public JSON convert(GenericValue obj) throws ConversionException { + Map<String, Object> fieldMap = new HashMap<String, Object>(obj); + fieldMap.put("_DELEGATOR_NAME_", obj.getDelegator().getDelegatorName()); + fieldMap.put("_ENTITY_NAME_", obj.getEntityName()); + try { + return JSON.from(fieldMap); + } catch (IOException e) { + throw new ConversionException(e); + } + } + } + public static class GenericValueToList extends AbstractConverter<GenericValue, List<GenericValue>> { public GenericValueToList() { super(GenericValue.class, List.class); Modified: ofbiz/trunk/framework/sql/build.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/build.xml?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/sql/build.xml (original) +++ ofbiz/trunk/framework/sql/build.xml Sat Nov 1 09:06:42 2014 @@ -45,11 +45,8 @@ under the License. <file name="org/ofbiz/sql/test/ValuesTest.java"/> <file name="org/ofbiz/sql/test/ConditionsTest.java"/> <file name="org/ofbiz/sql/test/SelectTest.java"/> - <file name="org/ofbiz/sql/test/SQLTest.java"/> </filelist> <patternset id="cobertura-src-dirs"> - <include name="build/gen-src/javacc"/> - <include name="build/gen-src/jjtree"/> <include name="src"/> </patternset> @@ -57,21 +54,6 @@ under the License. <!-- Compilation of the source files --> <!-- ================================================================== --> - <target name="gen-src"> - <ofbiz-javacc dir="org/ofbiz/sql" file="Parser"/> - </target> - - <target name="classes" depends="prepare,gen-src"> - <javac17> - <sourcepath> - <dirset dir="build/gen-src"> - <include name="javacc"/> - <include name="jjtree"/> - </dirset> - </sourcepath> - </javac17> - </target> - <target name="jar" depends="classes"> <main-jar/> <test-jar/> @@ -83,10 +65,6 @@ under the License. <target name="docs" depends="prepare-docs"> <default-javadoc> - <fileset dir="build/gen-src/javacc" defaultexcludes="yes"> - <patternset refid="src.inc.set"/> - <patternset refid="src.exc.set"/> - </fileset> <fileset dir="${src.dir}" defaultexcludes="yes"> <patternset refid="src.inc.set"/> <patternset refid="src.exc.set"/> Modified: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SelectTest.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SelectTest.java?rev=1635901&r1=1635900&r2=1635901&view=diff ============================================================================== --- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SelectTest.java (original) +++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/test/SelectTest.java Sat Nov 1 09:06:42 2014 @@ -18,7 +18,6 @@ */ package org.ofbiz.sql.test; -import java.io.StringReader; import java.util.Collections; import java.util.Set; @@ -30,7 +29,6 @@ import org.ofbiz.sql.FieldDef; import org.ofbiz.sql.FieldValue; import org.ofbiz.sql.FunctionCall; import org.ofbiz.sql.OrderByItem; -import org.ofbiz.sql.Parser; import org.ofbiz.sql.StaticValue; import org.ofbiz.sql.Value; @@ -44,10 +42,6 @@ public class SelectTest extends GenericT super(name); } - private static Parser parser(Object v) { - return new Parser(new StringReader(v.toString())); - } - private static <V> void basicTest(String label, Class<V> clz, V v, V o, boolean matches) { assertNotEquals(label + ":not-equals-this", v, SelectTest.class); if (o != null) { @@ -62,7 +56,6 @@ public class SelectTest extends GenericT private static void fieldAllTest(String label, FieldAll v, String alias, Set<String> exclude, FieldAll o, boolean matches) throws Exception { assertEquals(label + ":alias", alias, v.getAlias()); assertEquals(label + ":exclude", exclude, set(v)); - assertEquals(label + ":parse", v, parser(v).parse_FieldAll()); basicTest(label, FieldAll.class, v, o, matches); } @@ -83,7 +76,6 @@ public class SelectTest extends GenericT assertEquals(label + ":value", value, v.getValue()); assertEquals(label + ":alias", alias, v.getAlias()); assertEquals(label + ":default-name", defaultName, v.getDefaultName()); - assertEquals(label + ":parse", v, parser(v).parse_FieldDef()); basicTest(label, FieldDef.class, v, o, matches); } @@ -104,7 +96,6 @@ public class SelectTest extends GenericT assertEquals(label + ":order", order, v.getOrder()); assertEquals(label + ":nulls", nulls, v.getNulls()); assertEquals(label + ":value", value, v.getValue()); - assertEquals(label + ":parse", v, parser(v).parse_OrderByItem()); basicTest(label, OrderByItem.class, v, o, matches); } |
Free forum by Nabble | Edit this page |