A bit of refactoring + update of Jdom

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@747085 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2009-02-23 17:06:57 +00:00
parent 0cf21cecd4
commit df5dbc4cc9
6 changed files with 47 additions and 63 deletions
+1 -1
View File
@@ -144,7 +144,7 @@
<classpathentry kind="lib" path="specialpurpose/ldap/lib/cas-server-core-3.3.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/xmlgraphics-commons-1.2.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/rome-0.9.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/jdom-1.0.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/jdom-1.1.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/barcode4j-fop-ext-0.93.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/ws-commons-java5-1.0.1.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/ws-commons-util-1.0.1.jar"/>
+1 -1
View File
@@ -366,7 +366,7 @@ Illinois, Urbana-Champaign.
=========================================================================
The following libraries distributed with Apache OFBiz are licensed under the
JDOM (Modified Apache) License:
ofbiz/trunk/framework/webapp/lib/jdom-1.0.jar
ofbiz/trunk/framework/webapp/lib/jdom-1.1.jar
=========================================================================
The JDOM License
Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
@@ -18,54 +18,43 @@
*******************************************************************************/
package org.ofbiz.image;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ImagingOpException;
import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.io.File;
import java.io.IOException;
import java.lang.IllegalArgumentException;
import java.lang.Double;
import java.lang.Object;
import java.lang.String;
import java.lang.System;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javolution.util.FastList;
import javolution.util.FastMap;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.filter.Filter;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.service.ServiceUtil;
/**
* ImageTransform Class
* <p>
* Services to apply tranformation for images
* Services to apply transformation to images
*/
public class ImageTransform {
public static final String module = ImageTransform.class.getName();
// public static final String err_resource = "ContentErrorUiLabels";
public static final String err_resource = "ProductErrorUiLabels";
public ImageTransform() {}
public ImageTransform() {}
/**
* getBufferedImage
@@ -73,17 +62,17 @@ public class ImageTransform {
* Set a buffered image
*
* @param context
* @param fileLocation Full file Path or Url
* @return Url images for all different size types
* @param fileLocation Full file Path or URL
* @return URL images for all different size types
* @throws IOException Error prevents the document from being fully parsed
* @throws JDOMException Errors occur in parsing
*/
public Map getBufferedImage(String fileLocation)
public Map<String, Object> getBufferedImage(String fileLocation)
throws IllegalArgumentException, IOException {
/* VARIABLES */
BufferedImage bufImg;
FastMap result = new FastMap();
Map<String, Object> result = FastMap.newInstance();
/* BUFFERED IMAGE */
try{
@@ -104,7 +93,7 @@ public class ImageTransform {
result.put("bufferedImage", bufImg);
return result;
} // getBufferedImage
}
/**
@@ -116,34 +105,34 @@ public class ImageTransform {
* @param filenameToUse Filename of future image files
* @param viewType "Main" view or "additional" view
* @param viewNumber If it's the main view, viewNumber = "0"
* @return Url images for all different size types
* @return URL images for all different size types
* @throws IllegalArgumentException Any parameter is null
* @throws ImagingOpException The transform is non-invertible
* @throws IOException Error prevents the document from being fully parsed
* @throws JDOMException Errors occur in parsing
*/
public Map scaleImageInAllSize(Map<String, ? extends Object> context, String filenameToUse, String viewType, String viewNumber)
public Map<String, Object> scaleImageInAllSize(Map<String, ? extends Object> context, String filenameToUse, String viewType, String viewNumber)
throws IllegalArgumentException, ImagingOpException, IOException, JDOMException {
/* VARIABLES */
List<String> sizeTypeList = UtilMisc.toList("small", "medium", "large", "detail");
List<String> extensionList = UtilMisc.toList("jpeg", "jpg", "png");
int index;
LinkedHashMap<String, LinkedHashMap<String, String>> imgPropertyMap = new LinkedHashMap<String, LinkedHashMap<String, String>>();
Map<String, Map<String, String>> imgPropertyMap = FastMap.newInstance();
BufferedImage bufImg, bufNewImg;
double imgHeight, imgWidth, defaultHeight, defaultWidth, scaleFactor;
double imgHeight, imgWidth, scaleFactor;
AffineTransformOp op;
LinkedHashMap<String, String> imgUrlMap = new LinkedHashMap<String, String>();
LinkedHashMap resultXMLMap = new LinkedHashMap();
LinkedHashMap resultBufImgMap = new LinkedHashMap();
LinkedHashMap resultScaleImgMap = new LinkedHashMap();
FastMap result = new FastMap();
Map<String, String> imgUrlMap = FastMap.newInstance();
Map<String, Object> resultXMLMap = FastMap.newInstance();
Map<String, Object> resultBufImgMap = FastMap.newInstance();
Map<String, Object> resultScaleImgMap = FastMap.newInstance();
Map<String, Object> result = FastMap.newInstance();
/* ImageProperties.xml */
String imgPropertyFullPath = System.getProperty("ofbiz.home") + "/applications/product/config/ImageProperties.xml";
resultXMLMap.putAll(getXMLValue(imgPropertyFullPath));
resultXMLMap.putAll((Map<String, Object>) getXMLValue(imgPropertyFullPath));
if(resultXMLMap.containsKey("responseMessage") && resultXMLMap.get("responseMessage").equals("success")){
imgPropertyMap.putAll((LinkedHashMap) resultXMLMap.get("xml"));
imgPropertyMap.putAll((Map<String, Map<String, String>>) resultXMLMap.get("xml"));
}else{
String errMsg = "Impossible to parse ImageProperties.xml ";
Debug.logError(errMsg, module);
@@ -161,8 +150,8 @@ public class ImageTransform {
String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.server.path"), context);
String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
String id = new String();
String type = new String();
String id = null;
String type = null;
if(viewType.toLowerCase().contains("main")){
type = "original";
id = imgName;
@@ -217,7 +206,7 @@ public class ImageTransform {
scaleFactor = scaleFactorDb.doubleValue();
// define Interpolation
LinkedHashMap<RenderingHints.Key, Object> rhMap = new LinkedHashMap<RenderingHints.Key, Object>();
Map<RenderingHints.Key, Object> rhMap = FastMap.newInstance();
rhMap.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
rhMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
rhMap.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
@@ -244,7 +233,7 @@ public class ImageTransform {
}
// write the New Scaled Image
String newFileLocation = new String();
String newFileLocation = null;
if(viewType.toLowerCase().contains("main")){
newFileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", sizeType, "id", id));
}else if(viewType.toLowerCase().contains("additional")){
@@ -256,7 +245,7 @@ public class ImageTransform {
}
// choose final extension
String finalExtension = new String();
String finalExtension = null;
if(!extensionList.contains(imgExtension.toLowerCase())){
finalExtension = imgPropertyMap.get("format").get("extension");
}else{
@@ -307,7 +296,7 @@ public class ImageTransform {
return ServiceUtil.returnError(errMsg);
}
} // scaleImageInAllSize
}
/**
@@ -322,12 +311,12 @@ public class ImageTransform {
* @param sizeType Size type to scale
* @return New scaled buffered image
*/
private Map scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, LinkedHashMap<String, LinkedHashMap<String, String>> dimensionMap, String sizeType){
private Map<String, Object> scaleImage(BufferedImage bufImg, double imgHeight, double imgWidth, Map<String, Map<String, String>> dimensionMap, String sizeType){
/* VARIABLES */
BufferedImage bufNewImg;
double defaultHeight, defaultWidth, scaleFactor;
FastMap result = new FastMap();
Map<String, Object> result = FastMap.newInstance();
/* DIMENSIONS from ImageProperties */
defaultHeight = Double.parseDouble(dimensionMap.get(sizeType).get("height").toString());
@@ -381,7 +370,7 @@ public class ImageTransform {
result.put("scaleFactor", scaleFactor);
return result;
} // scaleImage
}
/**
@@ -392,15 +381,14 @@ public class ImageTransform {
* @param fileFullPath File path to parse
* @return Map contains asked attribute values by attribute name
*/
private Map getXMLValue(String fileFullPath)
private Map<String, Object> getXMLValue(String fileFullPath)
throws IllegalStateException, IOException, JDOMException {
/* VARIABLES */
Document document;
Element rootElt;
List<Element> eltList;
LinkedHashMap<String, LinkedHashMap> valueMap = new LinkedHashMap<String, LinkedHashMap>();
FastMap result = new FastMap();
Map<String, Map<String, String>> valueMap = FastMap.newInstance();
Map<String, Object> result = FastMap.newInstance();
/* PARSING */
SAXBuilder sxb = new SAXBuilder();
@@ -429,16 +417,14 @@ public class ImageTransform {
}
/* get NAME and VALUE */
Iterator<Element> eltIter = rootElt.getChildren().iterator();
while(eltIter.hasNext()){
Element currentElt = eltIter.next();
LinkedHashMap<String, String> eltMap = new LinkedHashMap<String, String>();
List<Element> children = rootElt.getChildren(); // FIXME : despite upgrading to jdom 1.1, it seems that getChildren is pre 1.5 java code (ie getChildren does not retun List<Element> but only List)
for (Element currentElt : children) {
Map<String, String> eltMap = FastMap.newInstance();
if(currentElt.getContentSize() > 0){
LinkedHashMap<String, String> childMap = new LinkedHashMap<String, String>();
Map<String, String> childMap = FastMap.newInstance();
// loop over Children 1st level
Iterator<Element> childrenIter = currentElt.getChildren().iterator();
while(childrenIter.hasNext()){
Element currentChild = childrenIter.next();
List<Element> children2 = currentElt.getChildren();
for (Element currentChild : children2) {
childMap.put(currentChild.getAttributeValue("name"), currentChild.getAttributeValue("value"));
}
valueMap.put(currentElt.getAttributeValue("name"), childMap);
@@ -446,12 +432,11 @@ public class ImageTransform {
eltMap.put(currentElt.getAttributeValue("name"), currentElt.getAttributeValue("value"));
valueMap.put(currentElt.getName(), eltMap);
}
} // eltIter
}
result.put("responseMessage", "success");
result.put("xml", valueMap);
return result;
} // getXMLValue
} // ImageTransform Class
}
}
@@ -960,10 +960,9 @@ public class ProductServices {
}
/* scale Image in different sizes */
String viewNumber = new String();
viewNumber = String.valueOf(productContentTypeId.charAt(productContentTypeId.length() - 1));
String viewNumber = String.valueOf(productContentTypeId.charAt(productContentTypeId.length() - 1));
ImageTransform imageTransform = new ImageTransform();
FastMap resultResize = new FastMap();
Map<String, Object> resultResize = FastMap.newInstance();
try{
resultResize.putAll(imageTransform.scaleImageInAllSize(context, filenameToUse, "additional", viewNumber));
}catch(IOException e){
Binary file not shown.
Binary file not shown.