From 6dc39716fb9487373c7ed27312c8dd0d38e6a5fc Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 29 Oct 2015 15:30:07 +0000 Subject: [PATCH] Fixed Charset Export to UTF8 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@120101 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 11 +++ .../client/rpc/TDGWTServiceAsync.java | 3 +- .../gwtservice/server/TDGWTServiceImpl.java | 70 +++++++++++++------ .../server/encoding/EncodingPGSupported.java | 37 ++++++++++ 4 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/server/encoding/EncodingPGSupported.java diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index 017224e..fef7fff 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -750,6 +750,17 @@ public interface TDGWTService extends RemoteService { throws TDGWTServiceException; // Export CSV + /** + * Available charset for export + * + * @return + * @throws TDGWTServiceException + */ + public AvailableCharsetList getAvailableCharsetForExport() + throws TDGWTServiceException; + + + /** * Start CSV Export and invokes the client library * diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index 2ad8861..0e87df6 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -266,7 +266,6 @@ public interface TDGWTServiceAsync { AsyncCallback callback); // Import CSV - void setCSVSession(CSVImportSession csvImportSession, AsyncCallback callback); @@ -285,6 +284,8 @@ public interface TDGWTServiceAsync { AsyncCallback callback); // Export CSV + void getAvailableCharsetForExport(AsyncCallback callback); + void startCSVExport(CSVExportSession csvExportSession, AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 1d83217..932183f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -105,6 +105,7 @@ import org.gcube.data.analysis.tabulardata.service.tabular.metadata.ValidSinceMe import org.gcube.data.analysis.tabulardata.service.tabular.metadata.ValidUntilMetadata; import org.gcube.data.analysis.tabulardata.service.template.TemplateId; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTService; +import org.gcube.portlets.user.td.gwtservice.server.encoding.EncodingPGSupported; import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; @@ -4074,6 +4075,23 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements String defaultEncoding = Charset.defaultCharset().displayName(); ArrayList charsetList = new ArrayList(Charset .availableCharsets().keySet()); + + return new AvailableCharsetList(charsetList, defaultEncoding); + } + + @Override + public AvailableCharsetList getAvailableCharsetForExport() + throws TDGWTServiceException { + HttpSession session = this.getThreadLocalRequest().getSession(); + if (session == null) { + throw new TDGWTServiceException( + "Error retrieving the session: null"); + } + logger.info("Session:" + session.getId()); + ArrayList charsetList = EncodingPGSupported + .getEncodidingStringList(); + String defaultEncoding = EncodingPGSupported.getDefaultEncoding(); + return new AvailableCharsetList(charsetList, defaultEncoding); } @@ -4896,20 +4914,24 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements /** * * @param trId - * @param session TODO + * @param session + * TODO * @throws TDGWTServiceException */ - protected void checkTRId(TRId trId, HttpSession session) throws TDGWTServiceException { + protected void checkTRId(TRId trId, HttpSession session) + throws TDGWTServiceException { if (trId == null) { ResourceBundle messages = getResourceBundle(session); logger.error("TRId is null"); - throw new TDGWTServiceException(messages.getString(TDGWTServiceMessagesConstants.noValidTabularResourceIdPresent)); + throw new TDGWTServiceException( + messages.getString(TDGWTServiceMessagesConstants.noValidTabularResourceIdPresent)); } if (trId.getId() == null || trId.getId().isEmpty()) { ResourceBundle messages = getResourceBundle(session); logger.error("TRId not valid: " + trId); - throw new TDGWTServiceException(messages.getString(TDGWTServiceMessagesConstants.noValidTabularResourceIdPresent)); + throw new TDGWTServiceException( + messages.getString(TDGWTServiceMessagesConstants.noValidTabularResourceIdPresent)); } } @@ -4919,14 +4941,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * @param session * @throws TDGWTServiceException */ - protected void checkTabularResourceLocked(TabularResource tabularResource, HttpSession session) - throws TDGWTServiceException { + protected void checkTabularResourceLocked(TabularResource tabularResource, + HttpSession session) throws TDGWTServiceException { try { if (tabularResource.isLocked()) { ResourceBundle messages = getResourceBundle(session); logger.error("Tabular Resource Is Locked!"); - throw new TDGWTIsLockedException(messages.getString(TDGWTServiceMessagesConstants.tabularResourceIsLocked)); + throw new TDGWTIsLockedException( + messages.getString(TDGWTServiceMessagesConstants.tabularResourceIsLocked)); } } catch (TDGWTServiceException e) { throw e; @@ -4941,20 +4964,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements /** * * - * @param session TODO + * @param session + * TODO * @param service * @param trId * @throws TDGWTServiceException */ - protected void checkTabularResourceIsFinal(TabularResource tabularResource, HttpSession session) - throws TDGWTServiceException { + protected void checkTabularResourceIsFinal(TabularResource tabularResource, + HttpSession session) throws TDGWTServiceException { try { - - + if (tabularResource.isFinalized()) { ResourceBundle messages = getResourceBundle(session); logger.error("Tabular Resource Is Final!"); - throw new TDGWTIsFinalException(messages.getString(TDGWTServiceMessagesConstants.tabularResourceIsFinal)); + throw new TDGWTIsFinalException( + messages.getString(TDGWTServiceMessagesConstants.tabularResourceIsFinal)); } } catch (TDGWTServiceException e) { @@ -4969,13 +4993,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements /** * - * @param session TODO + * @param session + * TODO * @param service * @param trId * @throws TDGWTServiceException */ - protected void checkTabularResourceIsFlow(TabularResource tabularResource, HttpSession session) - throws TDGWTServiceException { + protected void checkTabularResourceIsFlow(TabularResource tabularResource, + HttpSession session) throws TDGWTServiceException { try { if (tabularResource.getTabularResourceType().compareTo( @@ -5542,7 +5567,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); - checkTRId(replaceColumnByExpressionSession.getColumn().getTrId(), null); + checkTRId(replaceColumnByExpressionSession.getColumn().getTrId(), + null); TabularResourceId tabularResourceId = new TabularResourceId( Long.valueOf(replaceColumnByExpressionSession.getColumn() @@ -9322,7 +9348,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements public String startChartTopRating( ChartTopRatingSession chartTopRatingSession) throws TDGWTServiceException { - HttpSession session=null; + HttpSession session = null; try { session = this.getThreadLocalRequest().getSession(); SessionUtil @@ -9388,7 +9414,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements @Override public void saveResource(SaveResourceSession saveResourceSession) throws TDGWTServiceException { - HttpSession session=null; + HttpSession session = null; try { session = this.getThreadLocalRequest().getSession(); SessionUtil.setSaveResourceSession(session, saveResourceSession); @@ -9578,7 +9604,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements public String startGeospatialCreateCoordinates( GeospatialCreateCoordinatesSession geospatialCreateCoordinatesSession) throws TDGWTServiceException { - HttpSession session=null; + HttpSession session = null; try { session = this.getThreadLocalRequest().getSession(); SessionUtil.setGeospatialCreateCoordinatesSession(session, @@ -9655,7 +9681,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements public String startGeospatialDownscaleCSquare( GeospatialDownscaleCSquareSession geospatialDownscaleCSquareSession) throws TDGWTServiceException { - HttpSession session=null; + HttpSession session = null; try { session = this.getThreadLocalRequest().getSession(); SessionUtil.setGeospatialDownscaleCSquareSession(session, @@ -9731,7 +9757,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements public String startGeometryCreatePoint( GeometryCreatePointSession geometryCreatePointSession) throws TDGWTServiceException { - HttpSession session=null; + HttpSession session = null; try { session = this.getThreadLocalRequest().getSession(); SessionUtil.setGeometryCreatePointSession(session, diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/encoding/EncodingPGSupported.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/encoding/EncodingPGSupported.java new file mode 100644 index 0000000..b4cd8e8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/encoding/EncodingPGSupported.java @@ -0,0 +1,37 @@ +package org.gcube.portlets.user.td.gwtservice.server.encoding; + +import java.util.ArrayList; + +/** + * + * @author giancarlo email: g.panichi@isti.cnr.it + * + */ +public enum EncodingPGSupported { + BIG5, EUC_CN, EUC_JP, EUC_JIS_2004, EUC_KR, EUC_TW, GB18030, + GBK, ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8, JOHAB, + KOI8R, KOI8U, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5, + LATIN6, LATIN7, LATIN8, LATIN9, LATIN10, MULE_INTERNAL, + SJIS, SHIFT_JIS_2004, SQL_ASCII, UHC, UTF8, + WIN866, WIN874, WIN1250, WIN1251, WIN1252, WIN1253, WIN1254, + WIN1255, WIN1256, WIN1257, WIN1258; + + private static ArrayList encodingStringList; + + static { + encodingStringList = new ArrayList(); + for (EncodingPGSupported r : values()) { + encodingStringList.add(r.toString()); + } + } + + public static ArrayList getEncodidingStringList() { + return encodingStringList; + } + + public static String getDefaultEncoding() { + return UTF8.toString(); + } + +}