From 52c63296e94459e950d5d5926d72d737b0400a1a Mon Sep 17 00:00:00 2001 From: Marco Risaliti Date: Sat, 8 Jan 2011 12:21:51 +0000 Subject: [PATCH] Internationalization of ServiceUtil.returnSuccess, ServiceUtil.returnFailure, ServiceUtil.returnError (OFBIZ-4091) git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1056697 13f79535-47bb-0310-9956-ffa450edef68 --- .../product/config/ProductUiLabels.xml | 28 ++++++ .../ImageManagementServices.java | 22 +++-- .../product/product/ProductServices.java | 95 ++++++++++++------- 3 files changed, 104 insertions(+), 41 deletions(-) diff --git a/applications/product/config/ProductUiLabels.xml b/applications/product/config/ProductUiLabels.xml index def836fcc8..5ca043781d 100644 --- a/applications/product/config/ProductUiLabels.xml +++ b/applications/product/config/ProductUiLabels.xml @@ -13353,6 +13353,14 @@ 特征组收费 特性群組收費 + + Empty list of features passed + Lista delle caratteristiche passate è vuota + + + Error calling the isStoreInventoryRequired when building the variant product tree. + Errore durante la chiamata al servizio isStoreInventoryRequired mentre costruivo l'albero dei prodotti varianti + Merkmaltyp Feature Type @@ -14133,6 +14141,22 @@ 样例:/images/categories/linkOne/100.jpg 範例: /images/categories/linkOne/100.jpg + + Errors occur in parsing ImageProperties.xml: ${errorString} + Errore durante il parsing di ImageProperties.xml: ${errorString} + + + Scale additional image in all different sizes is impossible: ${errorString} + Scalare immagini aggiuntive in tutte le differenze ampiezze non è possibile: ${errorString} + + + Unable to write binary data to: ${fileName} + Non è possibile scrivere dati binari in: ${fileName} + + + Unable to open file for writing: ${fileName} + Non è possibile aprire il file in scrittura: ${fileName} + View Type : ${viewType} is wrong Tipo vista : ${viewType} è errata @@ -24468,6 +24492,10 @@ 虚拟的多样化方法 虛擬變體方式 + + Error creating a virtual with variants: the ID ${variantProductId} is not a valid Product.productId or a GoodIdentification.idValue + Errore durante la creazione del virtuale dalle varianti: variante prodotto ${variantProductId} non è valido Product.productId o un GoodIdentification.idValue + Void UPS Shipment Envío vacío de UPS diff --git a/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java b/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java index f051c93533..64d63b4d8e 100644 --- a/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java +++ b/applications/product/src/org/ofbiz/product/imagemanagement/ImageManagementServices.java @@ -97,6 +97,7 @@ public class ImageManagementServices { ByteBuffer imageData = (ByteBuffer) context.get("uploadedFile"); String uploadFileName = (String) context.get("_uploadedFile_fileName"); String imageResize = (String) context.get("imageResize"); + Locale locale = (Locale) context.get("locale"); if (UtilValidate.isNotEmpty(uploadFileName)) { String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format"); @@ -208,10 +209,12 @@ public class ImageManagementServices { out.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to write binary data to: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteBinaryData", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } // Scale Image in different sizes @@ -223,10 +226,12 @@ public class ImageManagementServices { outFile.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to write binary data to: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteBinaryData", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } Map resultResize = FastMap.newInstance(); @@ -543,6 +548,7 @@ public class ImageManagementServices { Map result = FastMap.newInstance(); LocalDispatcher dispatcher = dctx.getDispatcher(); Delegator delegator = dctx.getDelegator(); + Locale locale = (Locale) context.get("locale"); String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format"); String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.server.path"), context); String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix"); @@ -600,10 +606,14 @@ public class ImageManagementServices { outFileThumb.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to open file for writing: " + fileOriginalThumb.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteFile", + UtilMisc.toMap("fileName", fileOriginalThumb.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to write binary data to: " + fileOriginalThumb.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteBinaryData", + UtilMisc.toMap("fileName", fileOriginalThumb.getAbsolutePath()), locale)); } Map resultResizeThumb = FastMap.newInstance(); diff --git a/applications/product/src/org/ofbiz/product/product/ProductServices.java b/applications/product/src/org/ofbiz/product/product/ProductServices.java index 2db533c706..cae31343ba 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductServices.java +++ b/applications/product/src/org/ofbiz/product/product/ProductServices.java @@ -67,7 +67,8 @@ import org.ofbiz.service.ServiceUtil; public class ProductServices { public static final String module = ProductServices.class.getName(); - public static final String resource = "ProductErrorUiLabels"; + public static final String resource = "ProductUiLabels"; + public static final String resourceError = "ProductErrorUiLabels"; /** * Creates a Collection of product entities which are variant products from the specified product ID. @@ -121,7 +122,7 @@ public class ProductServices { products.add(delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", oneVariant.getString("productIdTo")))); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errProductFeatures", e.toString()); - String errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features_errors", messageMap, locale); + String errMsg = UtilProperties.getMessage(resourceError,"productservices.problem_reading_product_features_errors", messageMap, locale); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } @@ -139,7 +140,8 @@ public class ProductServices { public static Map prodFindDistinctVariants(DispatchContext dctx, Map context) { // * String productId -- Parent (virtual) product ID // * String feature -- Distinct feature name - return ServiceUtil.returnError("This service has not yet been implemented."); + //TODO This service has not yet been implemented. + return ServiceUtil.returnFailure(); } /** @@ -167,13 +169,13 @@ public class ProductServices { //if (Debug.infoOn()) Debug.logInfo("" + featureSet, module); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errProductFeatures", e.toString()); - errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features_errors", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError,"productservices.problem_reading_product_features_errors", messageMap, locale); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } if (featureSet.size() == 0) { - errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features", locale); + errMsg = UtilProperties.getMessage(resourceError,"productservices.problem_reading_product_features", locale); // ToDo DO 2004-02-23 Where should the errMsg go? Debug.logWarning(errMsg + " for product " + productId, module); //return ServiceUtil.returnError(errMsg); @@ -200,7 +202,8 @@ public class ProductServices { List featureOrder = UtilMisc.makeListWritable(UtilGenerics.checkCollection(context.get("featureOrder"))); if (UtilValidate.isEmpty(featureOrder)) { - return ServiceUtil.returnError("Empty list of features passed"); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductFeatureTreeCannotFindFeaturesList", locale)); } List variants = UtilGenerics.checkList(prodFindAllVariants(dctx, context).get("assocProducts")); @@ -223,7 +226,8 @@ public class ProductServices { } catch (GenericEntityException e) { Debug.logError(e, module); Map messageMap = UtilMisc.toMap("productIdTo", productIdTo, "errMessage", e.toString()); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "productservices.error_finding_associated_variant_with_ID_error", messageMap, locale)); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "productservices.error_finding_associated_variant_with_ID_error", messageMap, locale)); } if (productTo == null) { Debug.logWarning("Could not find associated variant with ID " + productIdTo + ", not showing in list", module); @@ -260,7 +264,8 @@ public class ProductServices { if (checkInventory) { Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", BigDecimal.ONE)); if (ServiceUtil.isError(invReqResult)) { - return ServiceUtil.returnError("Error calling the isStoreInventoryRequired when building the variant product tree.", null, null, invReqResult); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductFeatureTreeCannotCallIsStoreInventoryRequired", locale), null, null, invReqResult); } else if ("Y".equals(invReqResult.get("availableOrNotRequired"))) { items.add(productIdTo); if (productTo.getString("isVirtual") != null && productTo.getString("isVirtual").equals("Y")) { @@ -276,9 +281,9 @@ public class ProductServices { } } } catch (GenericServiceException e) { - String errMsg = "Error calling the isStoreInventoryRequired when building the variant product tree: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error calling the isStoreInventoryRequired when building the variant product tree: " + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductFeatureTreeCannotCallIsStoreInventoryRequired", locale)); } } @@ -294,7 +299,8 @@ public class ProductServices { selectableFeatures = EntityUtil.filterByDate(selectableFeatures, true); } catch (GenericEntityException e) { Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource,"productservices.empty_list_of_selectable_features_found", locale)); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "productservices.empty_list_of_selectable_features_found", locale)); } Map> features = FastMap.newInstance(); for (GenericValue v: selectableFeatures) { @@ -321,7 +327,8 @@ public class ProductServices { } if (UtilValidate.isEmpty(tree)) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); - result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resource,"productservices.feature_grouping_came_back_empty", locale)); + result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resourceError, + "productservices.feature_grouping_came_back_empty", locale)); } else { result.put("variantTree", tree); result.put("virtualVariant", virtualVariant); @@ -371,7 +378,8 @@ public class ProductServices { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errMessage", e.toString()); - errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_feature_entity", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.problem_reading_product_feature_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); } @@ -390,7 +398,8 @@ public class ProductServices { String errMsg = null; if (UtilValidate.isEmpty(productId)) { - errMsg = UtilProperties.getMessage(resource,"productservices.invalid_productId_passed", locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.invalid_productId_passed", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; @@ -419,7 +428,8 @@ public class ProductServices { } catch (GenericEntityException e) { e.printStackTrace(); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); - errMsg = UtilProperties.getMessage(resource,"productservices.problems_reading_product_entity", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); } @@ -450,14 +460,16 @@ public class ProductServices { sortDescending = sortDescending == null ? false : sortDescending; if (productId == null && productIdTo == null) { - errMsg = UtilProperties.getMessage(resource,"productservices.both_productId_and_productIdTo_cannot_be_null", locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.both_productId_and_productIdTo_cannot_be_null", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } if (productId != null && productIdTo != null) { - errMsg = UtilProperties.getMessage(resource,"productservices.both_productId_and_productIdTo_cannot_be_defined", locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.both_productId_and_productIdTo_cannot_be_defined", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; @@ -470,14 +482,16 @@ public class ProductServices { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); - errMsg = UtilProperties.getMessage(resource,"productservices.problems_reading_product_entity", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; } if (product == null) { - errMsg = UtilProperties.getMessage(resource,"productservices.problems_getting_product_entity", locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.problems_getting_product_entity", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; @@ -527,7 +541,8 @@ public class ProductServices { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); - errMsg = UtilProperties.getMessage(resource,"productservices.problems_product_association_relation_error", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.problems_product_association_relation_error", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; @@ -689,7 +704,8 @@ public class ProductServices { GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); if (product == null) { Map messageMap = UtilMisc.toMap("productId", productId); - errMsg = UtilProperties.getMessage(resource,"productservices.product_not_found_with_ID", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.product_not_found_with_ID", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; @@ -754,7 +770,8 @@ public class ProductServices { } catch (GenericEntityException e) { Debug.logError(e, "Entity error creating quick add variant data", module); Map messageMap = UtilMisc.toMap("errMessage", e.toString()); - errMsg = UtilProperties.getMessage(resource,"productservices.entity_error_quick_add_variant_data", messageMap, locale); + errMsg = UtilProperties.getMessage(resourceError, + "productservices.entity_error_quick_add_variant_data", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); return result; @@ -776,7 +793,8 @@ public class ProductServices { String productFeatureIdOne = (String) context.get("productFeatureIdOne"); String productFeatureIdTwo = (String) context.get("productFeatureIdTwo"); String productFeatureIdThree = (String) context.get("productFeatureIdThree"); - + Locale locale = (Locale) context.get("locale"); + Map successResult = ServiceUtil.returnSuccess(); try { @@ -828,7 +846,8 @@ public class ProductServices { List goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId)); if (UtilValidate.isEmpty(goodIdentificationList)) { // whoops, nothing found... return error - return ServiceUtil.returnError("Error creating a virtual with variants: the ID [" + variantProductId + "] is not a valid Product.productId or a GoodIdentification.idValue"); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductVirtualVariantCreation", UtilMisc.toMap("variantProductId", variantProductId), locale)); } if (goodIdentificationList.size() > 1) { @@ -958,6 +977,7 @@ public class ProductServices { String productId = (String) context.get("productId"); String productContentTypeId = (String) context.get("productContentTypeId"); ByteBuffer imageData = (ByteBuffer) context.get("uploadedFile"); + Locale locale = (Locale) context.get("locale"); if (UtilValidate.isNotEmpty(context.get("_uploadedFile_fileName"))) { String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format"); @@ -995,10 +1015,12 @@ public class ProductServices { out.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to write binary data to: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteBinaryData", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } /* scale Image in different sizes */ @@ -1007,13 +1029,13 @@ public class ProductServices { try { resultResize.putAll(ScaleImage.scaleImageInAllSize(context, filenameToUse, "additional", viewNumber)); } catch (IOException e) { - String errMsg = "Scale additional image in all different sizes is impossible : " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Scale additional image in all different sizes is impossible : " + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewScaleImpossible", UtilMisc.toMap("errorString", e.toString()), locale)); } catch (JDOMException e) { - String errMsg = "Errors occur in parsing ImageProperties.xml : " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Errors occur in parsing ImageProperties.xml : " + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewParsingError", UtilMisc.toMap("errorString", e.toString()), locale)); } String imageUrl = imageUrlPrefix + "/" + filePathPrefix + filenameToUse; @@ -1201,6 +1223,7 @@ public class ProductServices { String productPromoContentTypeId = (String) context.get("productPromoContentTypeId"); ByteBuffer imageData = (ByteBuffer) context.get("uploadedFile"); String contentId = (String) context.get("contentId"); + Locale locale = (Locale) context.get("locale"); if (UtilValidate.isNotEmpty(context.get("_uploadedFile_fileName"))) { String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format"); @@ -1243,10 +1266,12 @@ public class ProductServices { out.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to write binary data to: " + file.getAbsolutePath()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductImageViewUnableWriteBinaryData", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } String imageUrl = imageUrlPrefix + "/" + filePathPrefix + filenameToUse;