details: /erp/devel/pi/rev/9afb041e5d7f
changeset: 11907:9afb041e5d7f
user: Iván Perdomo <ivan.perdomo <at> openbravo.com>
date: Tue May 03 20:22:48 2011 +0200
summary: Fixes deprecation warning in Apache Tika related code
diffstat:
src-test/org/openbravo/test/mimetypes/MimeTypeTest.java | 3 +--
src/org/openbravo/erpCommon/utility/MimeTypeUtil.java | 15 ++++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)
diffs (79 lines):
diff -r 384b14cb12a0 -r 9afb041e5d7f
src-test/org/openbravo/test/mimetypes/MimeTypeTest.java
--- a/src-test/org/openbravo/test/mimetypes/MimeTypeTest.java Tue May 03
20:06:59 2011 +0200
+++ b/src-test/org/openbravo/test/mimetypes/MimeTypeTest.java Tue May 03
20:22:48 2011 +0200
@@ -18,7 +18,6 @@
*/
package org.openbravo.test.mimetypes;
-import org.apache.tika.mime.MimeType;
import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.MimeTypeUtil;
@@ -40,7 +39,7 @@
byte[] imageBytes = img.getBindaryData();
if (imageBytes != null) {
try {
- MimeType t = MimeTypeUtil.getInstance().getMimeType(imageBytes);
+ String t = MimeTypeUtil.getInstance().getMimeTypeName(imageBytes);
System.out.println(t);
} catch (Exception e) {
e.printStackTrace();
diff -r 384b14cb12a0 -r 9afb041e5d7f
src/org/openbravo/erpCommon/utility/MimeTypeUtil.java
--- a/src/org/openbravo/erpCommon/utility/MimeTypeUtil.java Tue May 03
20:06:59 2011 +0200
+++ b/src/org/openbravo/erpCommon/utility/MimeTypeUtil.java Tue May 03
20:22:48 2011 +0200
@@ -18,9 +18,8 @@
*/
package org.openbravo.erpCommon.utility;
-import org.apache.tika.config.TikaConfig;
+import org.apache.tika.Tika;
import org.apache.tika.mime.MimeType;
-import org.apache.tika.mime.MimeTypes;
/**
* Utility class to detect MIME type based on data array. This class is based
on Apache Tika part of
@@ -30,11 +29,11 @@
*
*/
public class MimeTypeUtil {
- private static MimeTypes mimeTypes;
private static MimeTypeUtil instance = new MimeTypeUtil();
+ private static Tika tika;
private static void init() {
- mimeTypes = TikaConfig.getDefaultConfig().getMimeRepository();
+ tika = new Tika();
}
/**
@@ -43,7 +42,7 @@
* @return MimeTypeUtil instance
*/
public static MimeTypeUtil getInstance() {
- if (mimeTypes == null) {
+ if (tika == null) {
init();
}
return instance;
@@ -59,9 +58,11 @@
* @param data
* byte array from which we want to detect the MIME type
* @return MimeType representation
+ * @deprecated This method will always return <b>null</b>
*/
+ @Deprecated
public MimeType getMimeType(byte[] data) {
- return mimeTypes.getMimeType(data);
+ return null;
}
/**
@@ -73,7 +74,7 @@
* @return A MIME type name, e.g. "image/png"
*/
public String getMimeTypeName(byte[] data) {
- return mimeTypes.getMimeType(data).getName();
+ return tika.detect(data);
}
}
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits