From 298dbab9d061ae3333e830e657d69426d4fab2b8 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 24 Jul 2021 07:06:53 +0200 Subject: [PATCH] IDEMPIERE-4801 Add IMediaView interface and Keikai implementation (#792) Add preview for CSV on attachment window --- org.adempiere.base/src/org/compiere/util/MimeType.java | 1 + .../src/org/idempiere/keikai/view/CSVMediaView.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/util/MimeType.java b/org.adempiere.base/src/org/compiere/util/MimeType.java index c7f9dfc425..0f521fce30 100644 --- a/org.adempiere.base/src/org/compiere/util/MimeType.java +++ b/org.adempiere.base/src/org/compiere/util/MimeType.java @@ -218,6 +218,7 @@ public class MimeType { ".csh", "text/x-script.csh"}, // { ".css", "application/x-pointplus"}, { ".css", "text/css"}, + { ".csv", MediaType.CSV_UTF_8.toString()}, { ".cvs", "application/vnd.ms-excel"}, { ".cxx", "text/plain"}, diff --git a/org.idempiere.keikai/src/org/idempiere/keikai/view/CSVMediaView.java b/org.idempiere.keikai/src/org/idempiere/keikai/view/CSVMediaView.java index 782d099394..8bcba9a62d 100644 --- a/org.idempiere.keikai/src/org/idempiere/keikai/view/CSVMediaView.java +++ b/org.idempiere.keikai/src/org/idempiere/keikai/view/CSVMediaView.java @@ -27,6 +27,8 @@ package org.idempiere.keikai.view; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.List; import org.idempiere.ui.zk.media.IMediaView; @@ -83,7 +85,12 @@ public class CSVMediaView implements IMediaView { Book book = importer.imports(bais, media.getName()); spreadsheet.setBook(book); Sheet sheet = book.getSheetAt(0); - ICsvListReader csvListReader = new CsvListReader(media.getReaderData(), CsvPreference.STANDARD_PREFERENCE); + Reader reader; + if (media.isBinary()) + reader = new InputStreamReader(new ByteArrayInputStream(media.getByteData())); + else + reader = media.getReaderData(); + ICsvListReader csvListReader = new CsvListReader(reader, CsvPreference.STANDARD_PREFERENCE); List headers = csvListReader.read(); if (headers != null) { for(int i = 0; i < headers.size(); i++) {