details:   https://code.openbravo.com/erp/devel/pi/rev/efa403a3f675
changeset: 13296:efa403a3f675
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Wed Jul 27 11:24:11 2011 +0200
summary:   Related to issue 18082. Improved saving of MIME type in ShowImageLogo

diffstat:

 src/org/openbravo/erpCommon/utility/ShowImageLogo.java |  34 ++++++++++++++---
 1 files changed, 28 insertions(+), 6 deletions(-)

diffs (63 lines):

diff -r 111e6fc5762c -r efa403a3f675 
src/org/openbravo/erpCommon/utility/ShowImageLogo.java
--- a/src/org/openbravo/erpCommon/utility/ShowImageLogo.java    Wed Jul 27 
10:45:34 2011 +0200
+++ b/src/org/openbravo/erpCommon/utility/ShowImageLogo.java    Wed Jul 27 
11:24:11 2011 +0200
@@ -21,6 +21,8 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -28,7 +30,6 @@
 
 import org.openbravo.base.HttpBaseServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
-import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.ad.utility.Image;
 
@@ -67,11 +68,7 @@
       mimeType = MimeTypeUtil.getInstance().getMimeTypeName(img);
       if (image != null) {
         // If there is an OBContext, we attempt to save the MIME type of the 
image
-        if (OBContext.getOBContext() != null) {
-          image.setMimetype(mimeType);
-          OBDal.getInstance().save(image);
-          OBDal.getInstance().flush();
-        }
+        updateMimeType(image.getId(), mimeType);
       }
     }
     if (!mimeType.equals("")) {
@@ -84,4 +81,29 @@
     out.write(img);
     out.close();
   }
+
+  /**
+   * This method updates the MIME type of an image, using SQL. DAL cannot be 
used because there is
+   * no OBContext in the Login page
+   */
+  private void updateMimeType(String id, String mimeType) {
+    PreparedStatement ps = null;
+    try {
+      ps = OBDal.getInstance().getConnection()
+          .prepareStatement("UPDATE ad_image SET mimetype=? WHERE 
ad_image_id=?");
+      ps.setString(1, mimeType);
+      ps.setString(2, id);
+      ps.executeUpdate();
+    } catch (SQLException e) {
+      log4j.error("Couldn't update mime information of image");
+    } finally {
+      try {
+        if (ps != null) {
+          ps.close();
+        }
+      } catch (SQLException e) {
+        // ignore
+      }
+    }
+  }
 }

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to