Author: jleroux
Date: Wed Feb 25 13:46:14 2009 New Revision: 747777 URL: http://svn.apache.org/viewvc?rev=747777&view=rev Log: A slightly modified patch from Eric De Maulde "Internationalize Image Transform errors" (https://issues.apache.org/jira/browse/OFBIZ-2210) - OFBIZ-2210 Modified: ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java Modified: ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml?rev=747777&r1=747776&r2=747777&view=diff ============================================================================== --- ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml (original) +++ ofbiz/trunk/applications/product/config/ProductErrorUiLabels.xml Wed Feb 25 13:46:14 2009 @@ -19,6 +19,74 @@ under the License. --> <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <property key="ImageTransform.error_occurs_during_reading"> + <value xml:lang="en">An error occurs during reading</value> + <value xml:lang="fr">Une erreur est survenue lors de la lecture</value> + </property> + <property key="ImageTransform.error_occurs_during_writing"> + <value xml:lang="en">An error occurs during writing</value> + <value xml:lang="fr">Une erreur est survenue lors de l'écriture</value> + </property> + <property key="ImageTransform.error_prevents_the document_from_being_fully_parsed"> + <value xml:lang="en">Error prevents the document from being fully parsed</value> + <value xml:lang="fr">Une erreur empêche que le document soit entièrement analysé</value> + </property> + <property key="ImageTransform.errors_occurs_in_parsing"> + <value xml:lang="en">Errors occur in parsing</value> + <value xml:lang="fr">Des erreurs sont survenues lors de l'analyse</value> + </property> + <property key="ImageTransform.final_scale_factor_is_null"> + <value xml:lang="en">Final scale factor is null</value> + <value xml:lang="fr">Le facteur final de redimensionnement est nul</value> + </property> + <property key="ImageTransform.height_scale_factor_is_null"> + <value xml:lang="en">Height scale factor is null</value> + <value xml:lang="fr">Le facteur 'hauteur' de redimensionnement est nul</value> + </property> + <property key="ImageTransform.input_is_null"> + <value xml:lang="en">Input is null</value> + <value xml:lang="fr">L'entrée est nulle</value> + </property> + <property key="ImageTransform.one_current_image_dimension_is_null"> + <value xml:lang="en">One current image dimension is null</value> + <value xml:lang="fr">Une des dimensions de l'image courrante est nulle</value> + </property> + <property key="ImageTransform.one_default_dimension_is_null"> + <value xml:lang="en">One default dimension is null</value> + <value xml:lang="fr">Une des dimensions par défaut est nulle</value> + </property> + <property key="ImageTransform.one_parameter_is_null"> + <value xml:lang="en">One parameter is null</value> + <value xml:lang="fr">Un des paramètres est nul</value> + </property> + <property key="ImageTransform.root_element_has_not_been_set"> + <value xml:lang="en">Root element has not been set</value> + <value xml:lang="fr">L'élement racine n'a pas pu être chargé</value> + </property> + <property key="ImageTransform.transform_is_non_invertible"> + <value xml:lang="en">Transform is non-invertible</value> + <value xml:lang="fr">La transformation n'est pas réversible</value> + </property> + <property key="ImageTransform.unable_to_create_target_directory"> + <value xml:lang="en">Unable to create target directory</value> + <value xml:lang="fr">Impossible de créer le dossier cible</value> + </property> + <property key="ImageTransform.unable_to_parse"> + <value xml:lang="en">Unable to parse</value> + <value xml:lang="fr">Impossible d'analyser</value> + </property> + <property key="ImageTransform.unable_to_scale_original_image"> + <value xml:lang="en">Unable to scale original image</value> + <value xml:lang="fr">Impossible de redimensionner l'image originale</value> + </property> + <property key="ImageTransform.unknown_buffered_image_type"> + <value xml:lang="en">Unknown buffered image type</value> + <value xml:lang="fr">Le type d'image bufferisée est inconnu</value> + </property> + <property key="ImageTransform.width_scale_factor_is_null"> + <value xml:lang="en">Width scale factor is null</value> + <value xml:lang="fr">Le facteur 'largeur' de redimensionnement est nul</value> + </property> <property key="ProductCreateCommunicationEventProductPermissionError"> <value xml:lang="en">Create Communication Event Product Permission Error</value> <value xml:lang="it">Errore di permesso durante la creazione evento comunicazione prodotto</value> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java?rev=747777&r1=747776&r2=747777&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/image/ImageTransform.java Wed Feb 25 13:46:14 2009 @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.imageio.ImageIO; @@ -52,7 +53,7 @@ public class ImageTransform { public static final String module = ImageTransform.class.getName(); - public static final String err_resource = "ProductErrorUiLabels"; + public static final String resource = "ProductErrorUiLabels"; public ImageTransform() {} @@ -67,7 +68,7 @@ * @throws IOException Error prevents the document from being fully parsed * @throws JDOMException Errors occur in parsing */ - public Map<String, Object> getBufferedImage(String fileLocation) + public Map<String, Object> getBufferedImage(String fileLocation, Locale locale) throws IllegalArgumentException, IOException { /* VARIABLES */ @@ -78,12 +79,12 @@ try{ bufImg = ImageIO.read(new File(fileLocation)); }catch(IllegalArgumentException e){ - String errMsg = "Input is null : " + fileLocation + " ; " + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.input_is_null", locale) + " : " + fileLocation + " ; " + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; }catch(IOException e){ - String errMsg = "Error occurs during reading : " + fileLocation + " ; " + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.error_occurs_during_reading", locale) + " : " + fileLocation + " ; " + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -115,6 +116,7 @@ throws IllegalArgumentException, ImagingOpException, IOException, JDOMException { /* VARIABLES */ + Locale locale = (Locale) context.get("locale"); List<String> sizeTypeList = UtilMisc.toList("small", "medium", "large", "detail"); List<String> extensionList = UtilMisc.toList("jpeg", "jpg", "png"); int index; @@ -130,11 +132,11 @@ /* ImageProperties.xml */ String imgPropertyFullPath = System.getProperty("ofbiz.home") + "/applications/product/config/ImageProperties.xml"; - resultXMLMap.putAll((Map<String, Object>) getXMLValue(imgPropertyFullPath)); + resultXMLMap.putAll((Map<String, Object>) getXMLValue(imgPropertyFullPath, locale)); if(resultXMLMap.containsKey("responseMessage") && resultXMLMap.get("responseMessage").equals("success")){ imgPropertyMap.putAll((Map<String, Map<String, String>>) resultXMLMap.get("xml")); }else{ - String errMsg = "Impossible to parse ImageProperties.xml "; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unable_to_parse", locale) + " : ImageProperties.xml"; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -171,7 +173,7 @@ /* get original BUFFERED IMAGE */ - resultBufImgMap.putAll(this.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse)); + resultBufImgMap.putAll(this.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse, locale)); if(resultBufImgMap.containsKey("responseMessage") && resultBufImgMap.get("responseMessage").equals("success")){ bufImg = (BufferedImage) resultBufImgMap.get("bufferedImage"); @@ -180,7 +182,7 @@ imgHeight = (double) bufImg.getHeight(); imgWidth = (double) bufImg.getWidth(); if(imgHeight == 0.0 || imgWidth == 0.0){ - String errMsg = "Any current image dimension is null : imgHeight = " + imgHeight + " ; imgWidth = " + imgWidth + ";"; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.one_current_image_dimension_is_null", locale) + " : imgHeight = " + imgHeight + " ; imgWidth = " + imgWidth; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -198,7 +200,7 @@ while(sizeIter.hasNext()){ String sizeType = sizeIter.next(); - resultScaleImgMap.putAll(this.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType)); + resultScaleImgMap.putAll(this.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType, locale)); if(resultScaleImgMap.containsKey("responseMessage") && resultScaleImgMap.get("responseMessage").equals("success")){ bufNewImg = (BufferedImage) resultScaleImgMap.get("bufferedImage"); @@ -226,7 +228,7 @@ try{ op = new AffineTransformOp(tx, rh); }catch(ImagingOpException e){ - String errMsg = "The transform is non-invertible" + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.transform_is_non_invertible", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -257,8 +259,9 @@ if (!targetDir.exists()) { boolean created = targetDir.mkdirs(); if (!created) { - Debug.logFatal("Unable to create target directory - " + targetDirectory, module); - return ServiceUtil.returnError("Unable to create target directory - " + targetDirectory); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unable_to_create_target_directory", locale) + " - " + targetDirectory; + Debug.logFatal(errMsg, module); + return ServiceUtil.returnError(errMsg); } } @@ -266,12 +269,12 @@ try{ ImageIO.write(op.filter(bufImg, bufNewImg), imgExtension, new File(imageServerPath + "/" + newFilePathPrefix + filenameToUse)); }catch(IllegalArgumentException e){ - String errMsg = "Any parameter is null" + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.one_parameter_is_null", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; }catch(IOException e){ - String errMsg = "An error occurs during writing" + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.error_occurs_during_writing", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -288,14 +291,16 @@ result.put("imageUrlMap", imgUrlMap); result.put("original", resultBufImgMap); return result; + }else{ - String errMsg = "Impossible to scale original image : " + filenameToUse; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unable_to_scale_original_image", locale) + " : " + filenameToUse; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return ServiceUtil.returnError(errMsg); } + } @@ -311,7 +316,7 @@ * @param sizeType Size type to scale * @return New scaled buffered image */ - private Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType){ + private Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType, Locale locale){ /* VARIABLES */ BufferedImage bufNewImg; @@ -322,7 +327,7 @@ defaultHeight = Double.parseDouble(dimensionMap.get(sizeType).get("height").toString()); defaultWidth = Double.parseDouble(dimensionMap.get(sizeType).get("width").toString()); if(defaultHeight == 0.0 || defaultWidth == 0.0){ - String errMsg = "Any default dimension is null : defaultHeight = " + defaultHeight + " ; defaultWidth = " + defaultWidth + ";"; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.one_default_dimension_is_null", locale) + " : defaultHeight = " + defaultHeight + " ; defaultWidth = " + defaultWidth; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -333,7 +338,7 @@ if(imgHeight > imgWidth){ scaleFactor = defaultHeight / imgHeight; if(scaleFactor == 0.0){ - String errMsg = "Height scaleFactor is null (defaultHeight = " + defaultHeight + "; imgHeight = " + imgHeight + ";"; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.height_scale_factor_is_null", locale) + " (defaultHeight = " + defaultHeight + "; imgHeight = " + imgHeight; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -345,7 +350,7 @@ }else{ scaleFactor = defaultWidth / imgWidth; if(scaleFactor == 0.0){ - String errMsg = "Width scaleFactor is null (defaultWidth = " + defaultWidth + "; imgWidth = " + imgWidth + ";"; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.width_scale_factor_is_null", locale) + " (defaultWidth = " + defaultWidth + "; imgWidth = " + imgWidth; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -357,13 +362,13 @@ } if(scaleFactor == 0.0){ - String errMsg = "Final scaleFactor is null = " + scaleFactor + ";"; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.final_scale_factor_is_null", locale) + " = " + scaleFactor; Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; } if (BufferedImage.TYPE_CUSTOM == bufImg.getType()) { - String errMsg = "Unknown BufferedImage type "; + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.unknown_buffered_image_type", locale); Debug.logError(errMsg, module); result.put("errorMessage", errMsg); return result; @@ -386,7 +391,7 @@ * @param fileFullPath File path to parse * @return Map contains asked attribute values by attribute name */ - private Map<String, Object> getXMLValue(String fileFullPath) + private Map<String, Object> getXMLValue(String fileFullPath, Locale locale) throws IllegalStateException, IOException, JDOMException { /* VARIABLES */ @@ -401,12 +406,12 @@ // JDOM document = sxb.build(new File(fileFullPath)); }catch(JDOMException e){ - String errMsg = "Errors occur in parsing ImageProperties.xml" + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.errors_occur_in parsing", locale) + " ImageProperties.xml " + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; }catch(IOException e){ - String errMsg = "Error prevents the document from being fully parsed" + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.error_prevents_the document_from_being_fully_parsed", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; @@ -415,7 +420,7 @@ try{ rootElt = document.getRootElement(); }catch(IllegalStateException e){ - String errMsg = "Root element hasn't been set" + e.toString(); + String errMsg = UtilProperties.getMessage(resource, "ImageTransform.root_element_has_not_been_set", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; |
Free forum by Nabble | Edit this page |