From: Mathieu Baudier Date: Tue, 25 Nov 2014 12:59:51 +0000 (+0000) Subject: New project conventions X-Git-Tag: argeo-commons-2.1.30~521 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=e71b1737815da9f0fdaff1ee1c69773a8c073ef1;p=lgpl%2Fargeo-commons.git New project conventions git-svn-id: https://svn.argeo.org/commons/trunk@7527 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.eclipse.ui.rap/.classpath b/org.argeo.eclipse.ui.rap/.classpath index 8cf7f48a0..d2953a684 100644 --- a/org.argeo.eclipse.ui.rap/.classpath +++ b/org.argeo.eclipse.ui.rap/.classpath @@ -1,7 +1,9 @@ - - - - + + + + diff --git a/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs b/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index ffba01eed..000000000 --- a/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Wed Mar 02 13:27:08 CET 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.argeo.eclipse.ui.rap/bnd.bnd b/org.argeo.eclipse.ui.rap/bnd.bnd new file mode 100644 index 000000000..3e0cb3cab --- /dev/null +++ b/org.argeo.eclipse.ui.rap/bnd.bnd @@ -0,0 +1,12 @@ +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.argeo.eclipse.ui.ArgeoUiPlugin +Require-Bundle: org.eclipse.rap.ui,org.eclipse.core.runtime +Import-Package: org.apache.commons.io,\ +org.argeo,\ +org.springframework.beans.factory,\ +org.springframework.core.io.support,\ +!org.eclipse.rwt.widgets,\ +!org.eclipse.core.runtime,\ +!org.eclipse.core.commands,\ +!org.eclipse.ui.plugin,\ +* diff --git a/org.argeo.eclipse.ui.rap/build.properties b/org.argeo.eclipse.ui.rap/build.properties index 7cc98e7f8..fd806ca05 100644 --- a/org.argeo.eclipse.ui.rap/build.properties +++ b/org.argeo.eclipse.ui.rap/build.properties @@ -1,4 +1,2 @@ -source.. = src/main/java/ -output.. = target/classes/ -bin.includes = META-INF/,\ - .,\ \ No newline at end of file +source.. = src/ +output.. = bin/ diff --git a/org.argeo.eclipse.ui.rap/pom.xml b/org.argeo.eclipse.ui.rap/pom.xml index 0a8cb97a4..d2795efe6 100644 --- a/org.argeo.eclipse.ui.rap/pom.xml +++ b/org.argeo.eclipse.ui.rap/pom.xml @@ -11,52 +11,6 @@ org.argeo.eclipse.ui.rap Commons Eclipse UI RAP jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - - - - lazy - org.argeo.eclipse.ui.ArgeoUiPlugin - org.eclipse.rap.ui,org.eclipse.core.runtime - - - org.apache.commons.io, - org.argeo, - org.springframework.beans.factory, - org.springframework.core.io.support, - !org.eclipse.rwt.widgets, - !org.eclipse.core.runtime, - !org.eclipse.core.commands, - !org.eclipse.ui.plugin, - * - - - - - - - - org.argeo.commons @@ -68,6 +22,11 @@ org.argeo.eclipse.ui 2.1.12-SNAPSHOT + + + org.argeo.tp + slf4j.org.apache.commons.logging + @@ -77,10 +36,5 @@ 2.1.12-SNAPSHOT - - - org.argeo.tp - slf4j.org.apache.commons.logging - \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java deleted file mode 100644 index 4173b966b..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.argeo.ArgeoException; -import org.argeo.eclipse.ui.FileProvider; -import org.eclipse.rap.rwt.service.ServiceHandler; - -@Deprecated -public class DownloadServiceHandler implements ServiceHandler { - - private FileProvider provider; - - public DownloadServiceHandler(FileProvider provider) { - this.provider = provider; - } - - public void service(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - // Which file to download? - String fileName = request.getParameter("filename"); - String fileId = request.getParameter("fileid"); - - // Get the file content - byte[] download = provider.getByteArrayFileFromId(fileId); - - // Send the file in the response - response.setContentType("application/octet-stream"); - response.setContentLength(download.length); - String contentDisposition = "attachment; filename=\"" + fileName + "\""; - response.setHeader("Content-Disposition", contentDisposition); - - // Various header fields that can be set to solve some issues with some - // old browsers. - // Unused. - // String contentType = "application/force-download; name=\"" + fileName - // + "\""; - // response.setContentType(contentType); - // response.setHeader("Content-Transfer-Encoding", "binary"); - // response.setHeader("Pragma", "no-cache"); - // response.setHeader("Cache-Control", "no-cache, must-revalidate"); - // response.setHeader("Expires", "0"); - // response.setHeader("Connection", "Keep-Alive"); - // response.setHeader("Keep-Alive", "timeout=5, max=86"); - // response.setHeader("transfer-Encoding", "chunked"); - - try { - response.getOutputStream().write(download); - } catch (IOException ioe) { - throw new ArgeoException("Error while writing the file " + fileName - + " to the servlet response", ioe); - } - } -} diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java deleted file mode 100644 index c7ab28aaf..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import org.eclipse.jface.viewers.AbstractTableViewer; -import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; -import org.eclipse.jface.viewers.Viewer; - -/** Static utilities to bridge differences between RCP and RAP */ -public class EclipseUiSpecificUtils { - /** - * TootlTip support is supported only for {@link AbstractTableViewer} in RAP - * - * @see ColumnViewerToolTipSupport#enableFor(AbstractTableViewer) - */ - public static void enableToolTipSupport(Viewer viewer) { - if (viewer instanceof AbstractTableViewer) - ColumnViewerToolTipSupport.enableFor((AbstractTableViewer) viewer); - } - - private EclipseUiSpecificUtils() { - } - -} diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java deleted file mode 100644 index 6a28c0ae4..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; -import org.argeo.eclipse.ui.FileProvider; -import org.eclipse.rap.rwt.RWT; -import org.eclipse.rap.rwt.client.service.UrlLauncher; -import org.eclipse.rap.rwt.service.ServiceHandler; - -/** - * RAP SPECIFIC handler to enable the opening of a download dialog box triggered - * by whatever action in the UI - * - * Manages the registration of the effective DownloadServiceHandler at - * instantiation time. - * - * Manages the process of forwarding the request to the handler at runtime to - * open the dialog box encodedURL - */ -@Deprecated -public class FileHandler { - public final static String DOWNLOAD_SERVICE_NAME = "argeo.rap.download.service"; - private final static Log log = LogFactory.getLog(FileHandler.class); - - public FileHandler(FileProvider provider) { - ServiceHandler handler = new DownloadServiceHandler(provider); - try { - RWT.getServiceManager().registerServiceHandler( - DOWNLOAD_SERVICE_NAME, handler); - } catch (IllegalArgumentException iae) { - log.warn("Handler is already registered, clean this registering process"); - } - } - - public void openFile(String fileName, String fileId) { - try { - String downloadUrl = RWT.getServiceManager().getServiceHandlerUrl( - DOWNLOAD_SERVICE_NAME) - + createParamUrl(fileName, fileId); - if (log.isTraceEnabled()) - log.debug("URL : " + downloadUrl); - UrlLauncher launcher = RWT.getClient() - .getService(UrlLauncher.class); - launcher.openURL(downloadUrl); - } catch (Exception e) { - throw new ArgeoException("Unable to open file " + fileName, e); - } - // These lines are useless in the current use case but might be - // necessary with new browsers. Stored here for memo - // response.setContentType("application/force-download"); - // response.setHeader("Content-Disposition", contentDisposition); - // response.setHeader("Content-Transfer-Encoding", "binary"); - // response.setHeader("Pragma", "no-cache"); - // response.setHeader("Cache-Control", "no-cache, must-revalidate"); - } - - private String createParamUrl(String filename, String fileId) { - StringBuilder url = new StringBuilder(); - url.append("&filename="); - url.append(filename); - url.append("&fileid="); - url.append(fileId); - return url.toString(); - } -} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java deleted file mode 100644 index e3b319862..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; -//import org.eclipse.rap.rwt.widgets.Upload; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; - -public class GenericUploadControl extends Composite { - private final static Log log = LogFactory - .getLog(GenericUploadControl.class); - - //private Upload upload; - - public GenericUploadControl(Composite parent, int style, String browseLabel) { - super(parent, style); - createControl(this, browseLabel); - - } - - private void createControl(Composite parent, String browseLabel) { - parent.setLayout(new GridLayout(1, false)); - parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - -// upload = new Upload(parent, SWT.BORDER); -// upload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); -// upload.setBrowseButtonText(browseLabel); - // upload.addModifyListener(new UploadListener()); - parent.pack(); - } - - /** - * Wrap upload.getLastFileUploaded(). Gets the name of the last uploaded - * file. This method can be called even if the upload has not finished yet. - */ - public String getLastFileUploadedName() { - return ""; - } - - public boolean isControlEmpty() { - String path = ""; - if (log.isTraceEnabled()) - log.trace("UploadControl chosen path : " + path); - if (path == null || "".equals(path.trim())) - return true; - else - return false; - } - - public byte[] performUpload() { -// boolean success = upload.performUpload(); -// if (success) { -// if (upload.getUploadItem().getFileSize() == -1) -// throw new ArgeoException("File " -// + upload.getUploadItem().getFileName() -// + " has not been uploaded, its size is -1"); -// -// InputStream inStream = null; -// byte[] fileBA = null; -// try { -// inStream = upload.getUploadItem().getFileInputStream(); -// fileBA = IOUtils.toByteArray(inStream); -// } catch (Exception e) { -// throw new ArgeoException("Cannot read uploaded data", e); -// } finally { -// IOUtils.closeQuietly(inStream); -// } -// return fileBA; -// } - return null; - } - - public void addModifyListener(ModifyListener listener) { -// upload.addModifyListener(listener); - } - - // private class UploadManager extends UploadAdapter { - // private Upload upload; - // - // public UploadManager(Upload upload) { - // super(); - // this.upload = upload; - // } - // - // public void uploadFinished(UploadEvent uploadEvent) { - // handleUploadFinished(upload); - // } - // - // public void uploadInProgress(UploadEvent uploadEvent) { - // } - // - // public void uploadException(UploadEvent uploadEvent) { - // Exception exc = uploadEvent.getUploadException(); - // if (exc != null) { - // MessageDialog.openError(Display.getCurrent().getActiveShell(), - // "Error", exc.getMessage()); - // } - // } - // - // } - // - -} diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java deleted file mode 100644 index f66a279c6..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import java.io.InputStream; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; -import org.eclipse.jface.wizard.WizardPage; -//import org.eclipse.rap.rwt.widgets.Upload; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; - -public class ImportToServerWizardPage extends WizardPage { - private final static Log log = LogFactory - .getLog(ImportToServerWizardPage.class); - - public final static String FILE_ITEM_TYPE = "FILE"; - public final static String FOLDER_ITEM_TYPE = "FOLDER"; - - //private Upload uploadFile; - - public ImportToServerWizardPage() { - super("Import from file system"); - setDescription("Import files from the local file system to the server"); - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - new Label(composite, SWT.NONE).setText("Pick up a file"); -// uploadFile = new Upload(composite, SWT.BORDER); -// uploadFile.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); -// uploadFile.setBrowseButtonText("Open..."); - setControl(composite); - } - - public String getObjectPath() { - // NOTE Returns the full file name of the last uploaded file including - // the file path as selected by the user on his local machine. - // The full path including the directory and file drive are only - // returned, if the browser supports reading this properties. In Firefox - // 3, only the filename is returned. - return null; - } - - public String getObjectName() { - return null; - } - - public String getObjectType() { - return FILE_ITEM_TYPE; - } - - public void performFinish() { -// boolean success = uploadFile.performUpload(); -// if (!success) -// throw new ArgeoException("Cannot upload file named " -// + uploadFile.getPath()); - } - -// protected void handleUploadFinished(final Upload upload) { -// } - - public InputStream getFileInputStream() { - return null; - } - - public boolean getNeedsProgressMonitor() { - return false; - } - -} diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFile.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFile.java deleted file mode 100644 index b55521b12..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFile.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.rap.rwt.RWT; -import org.eclipse.rap.rwt.client.service.UrlLauncher; - -/** - * Rap specific command handler to open a file retrieved from the server. It - * forwards the request to the correct service after encoding file name and path - * in the request URI. - * - * The parameter "URI" is used to determine the correct file service, the path - * and the file name. An optional file name can be precised to present a - * different file name as the one used to retrieve it to the end user/ - * - * Various instances of this handler with different command ID might coexist in - * order to provide context specific download service. - * - * The instance specific service is called by its ID and must have been - * externally created - */ -public class OpenFile extends AbstractHandler { - private final static Log log = LogFactory.getLog(OpenFile.class); - - /* DEPENDENCY INJECTION */ - private String openFileServiceId; - - public final static String PARAM_FILE_NAME = OpenFileService.PARAM_FILE_NAME; - public final static String PARAM_FILE_URI = OpenFileService.PARAM_FILE_URI; // "param.fileURI"; - - public Object execute(ExecutionEvent event) throws ExecutionException { - String fileName = event.getParameter(PARAM_FILE_NAME); - String fileUri = event.getParameter(PARAM_FILE_URI); - - // sanity check - if (fileUri == null || "".equals(fileUri.trim()) - || openFileServiceId == null - || "".equals(openFileServiceId.trim())) - return null; - - StringBuilder url = new StringBuilder(); - url.append(RWT.getServiceManager().getServiceHandlerUrl( - openFileServiceId)); - - url.append("&").append(PARAM_FILE_NAME).append("="); - url.append(fileName); - url.append("&").append(PARAM_FILE_URI).append("="); - url.append(fileUri); - - String downloadUrl = url.toString(); - if (log.isTraceEnabled()) - log.debug("URL : " + downloadUrl); - - UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class); - launcher.openURL(downloadUrl); - - // These lines are useless in the current use case but might be - // necessary with new browsers. Stored here for memo - // response.setContentType("application/force-download"); - // response.setHeader("Content-Disposition", contentDisposition); - // response.setHeader("Content-Transfer-Encoding", "binary"); - // response.setHeader("Pragma", "no-cache"); - // response.setHeader("Cache-Control", "no-cache, must-revalidate"); - return null; - } - - /* DEPENDENCY INJECTION */ - public void setOpenFileServiceId(String openFileServiceId) { - this.openFileServiceId = openFileServiceId; - } -} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFileService.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFileService.java deleted file mode 100644 index e48babf0b..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFileService.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import java.io.File; -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.FileUtils; -import org.argeo.ArgeoException; -import org.eclipse.rap.rwt.service.ServiceHandler; - -/** - * Basic Default service handler that retrieves a file on the server file system - * using its absolute path and forwards it to the end user browser. Rap - * specific. - * - * Clients might extend to provide context specific services (to open files from - * a JCR repository for instance) - */ -public class OpenFileService implements ServiceHandler { - public final static String PARAM_FILE_NAME = "param.fileName"; - public final static String PARAM_FILE_URI = "param.fileURI"; - - public final static String SCHEME_HOST_SEPARATOR = "://"; - public final static String FILE_SCHEME = "file"; - - public OpenFileService() { - } - - public void service(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - String fileName = request.getParameter(PARAM_FILE_NAME); - String uri = request.getParameter(PARAM_FILE_URI); - - // Set the Metadata - response.setContentType("application/octet-stream"); - response.setContentLength((int) getFileLength(uri)); - if (fileName == null || "".equals(fileName.trim())) - fileName = getFileName(uri); - String contentDisposition = "attachment; filename=\"" + fileName + "\""; - response.setHeader("Content-Disposition", contentDisposition); - - response.getOutputStream().write(getFileAsByteArray(uri)); - // FileUtils.readFileToByteArray(new File(path)) - } - - protected byte[] getFileAsByteArray(String uri) { - if (uri.startsWith(FILE_SCHEME)) { - try { - return FileUtils.readFileToByteArray(new File( - getFilePathFromUri(uri))); - } catch (IOException ioe) { - throw new ArgeoException("Error while getting the file at " - + uri, ioe); - } - } - return null; - } - - protected long getFileLength(String uri) { - if (uri.startsWith(FILE_SCHEME)) { - return new File(getFilePathFromUri(uri)).length(); - } - return -1l; - } - - protected String getFileName(String uri) { - if (uri.startsWith(FILE_SCHEME)) { - return new File(getFilePathFromUri(uri)).getName(); - } - return null; - } - - private String getFilePathFromUri(String uri) { - return uri.substring((FILE_SCHEME + SCHEME_HOST_SEPARATOR).length()); - } - -} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ThreadNLS.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ThreadNLS.java deleted file mode 100644 index 8b8837f2e..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ThreadNLS.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import org.eclipse.osgi.util.NLS; -import org.eclipse.rap.rwt.RWT; - -/** NLS attached to a given thread */ -public class ThreadNLS extends InheritableThreadLocal { - public final static String DEFAULT_BUNDLE_LOCATION = "/properties/plugin"; - - private final String bundleLocation; - - private Class type; - private Boolean utf8 = false; - - public ThreadNLS(String bundleLocation, Class type, Boolean utf8) { - this.bundleLocation = bundleLocation; - this.type = type; - this.utf8 = utf8; - } - - public ThreadNLS(Class type) { - this(DEFAULT_BUNDLE_LOCATION, type, false); - } - - @SuppressWarnings("unchecked") - @Override - protected T initialValue() { - if (utf8) - return (T) RWT.NLS.getUTF8Encoded(bundleLocation, type); - else - return (T) RWT.NLS.getISO8859_1Encoded(bundleLocation, type); - } -} diff --git a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/UploadFileWizardPage.java b/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/UploadFileWizardPage.java deleted file mode 100644 index 17d4e22f3..000000000 --- a/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/UploadFileWizardPage.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.eclipse.ui.specific; - -import java.io.InputStream; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.rap.rwt.widgets.FileUpload; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; - -public class UploadFileWizardPage extends WizardPage { - // private final static Log log = LogFactory - // .getLog(UploadFileWizardPage.class); - private static final long serialVersionUID = 8251354244542973179L; - public final static String FILE_ITEM_TYPE = "FILE"; - public final static String FOLDER_ITEM_TYPE = "FOLDER"; - - private FileUpload fileUpload; - - public UploadFileWizardPage() { - super("Import from file system"); - setDescription("Import files from the local file system to the server"); - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - new Label(composite, SWT.NONE).setText("Pick up a file"); - fileUpload = new FileUpload(composite, SWT.BORDER); - fileUpload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - fileUpload.setText("Browse"); - setControl(composite); - } - - public String getObjectPath() { - // NOTE Returns the full file name of the last uploaded file including - // the file path as selected by the user on his local machine. - // The full path including the directory and file drive are only - // returned, if the browser supports reading this properties. In Firefox - // 3, only the filename is returned. - return null; - } - - public String getObjectName() { - return fileUpload.getFileName(); - } - - public String getObjectType() { - return FILE_ITEM_TYPE; - } - - public void performFinish() { - // boolean success = uploadFile.performUpload(); - // if (!success) - // throw new ArgeoException("Cannot upload file named " - // + uploadFile.getPath()); - } - - // protected void handleUploadFinished(final Upload upload) { - // } - - public InputStream getFileInputStream() { - return null; - } - - public boolean getNeedsProgressMonitor() { - return false; - } - -} diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java new file mode 100644 index 000000000..4173b966b --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.FileProvider; +import org.eclipse.rap.rwt.service.ServiceHandler; + +@Deprecated +public class DownloadServiceHandler implements ServiceHandler { + + private FileProvider provider; + + public DownloadServiceHandler(FileProvider provider) { + this.provider = provider; + } + + public void service(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + // Which file to download? + String fileName = request.getParameter("filename"); + String fileId = request.getParameter("fileid"); + + // Get the file content + byte[] download = provider.getByteArrayFileFromId(fileId); + + // Send the file in the response + response.setContentType("application/octet-stream"); + response.setContentLength(download.length); + String contentDisposition = "attachment; filename=\"" + fileName + "\""; + response.setHeader("Content-Disposition", contentDisposition); + + // Various header fields that can be set to solve some issues with some + // old browsers. + // Unused. + // String contentType = "application/force-download; name=\"" + fileName + // + "\""; + // response.setContentType(contentType); + // response.setHeader("Content-Transfer-Encoding", "binary"); + // response.setHeader("Pragma", "no-cache"); + // response.setHeader("Cache-Control", "no-cache, must-revalidate"); + // response.setHeader("Expires", "0"); + // response.setHeader("Connection", "Keep-Alive"); + // response.setHeader("Keep-Alive", "timeout=5, max=86"); + // response.setHeader("transfer-Encoding", "chunked"); + + try { + response.getOutputStream().write(download); + } catch (IOException ioe) { + throw new ArgeoException("Error while writing the file " + fileName + + " to the servlet response", ioe); + } + } +} diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java new file mode 100644 index 000000000..c7ab28aaf --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import org.eclipse.jface.viewers.AbstractTableViewer; +import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; +import org.eclipse.jface.viewers.Viewer; + +/** Static utilities to bridge differences between RCP and RAP */ +public class EclipseUiSpecificUtils { + /** + * TootlTip support is supported only for {@link AbstractTableViewer} in RAP + * + * @see ColumnViewerToolTipSupport#enableFor(AbstractTableViewer) + */ + public static void enableToolTipSupport(Viewer viewer) { + if (viewer instanceof AbstractTableViewer) + ColumnViewerToolTipSupport.enableFor((AbstractTableViewer) viewer); + } + + private EclipseUiSpecificUtils() { + } + +} diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileHandler.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileHandler.java new file mode 100644 index 000000000..6a28c0ae4 --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/FileHandler.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.FileProvider; +import org.eclipse.rap.rwt.RWT; +import org.eclipse.rap.rwt.client.service.UrlLauncher; +import org.eclipse.rap.rwt.service.ServiceHandler; + +/** + * RAP SPECIFIC handler to enable the opening of a download dialog box triggered + * by whatever action in the UI + * + * Manages the registration of the effective DownloadServiceHandler at + * instantiation time. + * + * Manages the process of forwarding the request to the handler at runtime to + * open the dialog box encodedURL + */ +@Deprecated +public class FileHandler { + public final static String DOWNLOAD_SERVICE_NAME = "argeo.rap.download.service"; + private final static Log log = LogFactory.getLog(FileHandler.class); + + public FileHandler(FileProvider provider) { + ServiceHandler handler = new DownloadServiceHandler(provider); + try { + RWT.getServiceManager().registerServiceHandler( + DOWNLOAD_SERVICE_NAME, handler); + } catch (IllegalArgumentException iae) { + log.warn("Handler is already registered, clean this registering process"); + } + } + + public void openFile(String fileName, String fileId) { + try { + String downloadUrl = RWT.getServiceManager().getServiceHandlerUrl( + DOWNLOAD_SERVICE_NAME) + + createParamUrl(fileName, fileId); + if (log.isTraceEnabled()) + log.debug("URL : " + downloadUrl); + UrlLauncher launcher = RWT.getClient() + .getService(UrlLauncher.class); + launcher.openURL(downloadUrl); + } catch (Exception e) { + throw new ArgeoException("Unable to open file " + fileName, e); + } + // These lines are useless in the current use case but might be + // necessary with new browsers. Stored here for memo + // response.setContentType("application/force-download"); + // response.setHeader("Content-Disposition", contentDisposition); + // response.setHeader("Content-Transfer-Encoding", "binary"); + // response.setHeader("Pragma", "no-cache"); + // response.setHeader("Cache-Control", "no-cache, must-revalidate"); + } + + private String createParamUrl(String filename, String fileId) { + StringBuilder url = new StringBuilder(); + url.append("&filename="); + url.append(filename); + url.append("&fileid="); + url.append(fileId); + return url.toString(); + } +} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/GenericUploadControl.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/GenericUploadControl.java new file mode 100644 index 000000000..e3b319862 --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/GenericUploadControl.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.ArgeoException; +//import org.eclipse.rap.rwt.widgets.Upload; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +public class GenericUploadControl extends Composite { + private final static Log log = LogFactory + .getLog(GenericUploadControl.class); + + //private Upload upload; + + public GenericUploadControl(Composite parent, int style, String browseLabel) { + super(parent, style); + createControl(this, browseLabel); + + } + + private void createControl(Composite parent, String browseLabel) { + parent.setLayout(new GridLayout(1, false)); + parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + +// upload = new Upload(parent, SWT.BORDER); +// upload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); +// upload.setBrowseButtonText(browseLabel); + // upload.addModifyListener(new UploadListener()); + parent.pack(); + } + + /** + * Wrap upload.getLastFileUploaded(). Gets the name of the last uploaded + * file. This method can be called even if the upload has not finished yet. + */ + public String getLastFileUploadedName() { + return ""; + } + + public boolean isControlEmpty() { + String path = ""; + if (log.isTraceEnabled()) + log.trace("UploadControl chosen path : " + path); + if (path == null || "".equals(path.trim())) + return true; + else + return false; + } + + public byte[] performUpload() { +// boolean success = upload.performUpload(); +// if (success) { +// if (upload.getUploadItem().getFileSize() == -1) +// throw new ArgeoException("File " +// + upload.getUploadItem().getFileName() +// + " has not been uploaded, its size is -1"); +// +// InputStream inStream = null; +// byte[] fileBA = null; +// try { +// inStream = upload.getUploadItem().getFileInputStream(); +// fileBA = IOUtils.toByteArray(inStream); +// } catch (Exception e) { +// throw new ArgeoException("Cannot read uploaded data", e); +// } finally { +// IOUtils.closeQuietly(inStream); +// } +// return fileBA; +// } + return null; + } + + public void addModifyListener(ModifyListener listener) { +// upload.addModifyListener(listener); + } + + // private class UploadManager extends UploadAdapter { + // private Upload upload; + // + // public UploadManager(Upload upload) { + // super(); + // this.upload = upload; + // } + // + // public void uploadFinished(UploadEvent uploadEvent) { + // handleUploadFinished(upload); + // } + // + // public void uploadInProgress(UploadEvent uploadEvent) { + // } + // + // public void uploadException(UploadEvent uploadEvent) { + // Exception exc = uploadEvent.getUploadException(); + // if (exc != null) { + // MessageDialog.openError(Display.getCurrent().getActiveShell(), + // "Error", exc.getMessage()); + // } + // } + // + // } + // + +} diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java new file mode 100644 index 000000000..f66a279c6 --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import java.io.InputStream; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.ArgeoException; +import org.eclipse.jface.wizard.WizardPage; +//import org.eclipse.rap.rwt.widgets.Upload; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class ImportToServerWizardPage extends WizardPage { + private final static Log log = LogFactory + .getLog(ImportToServerWizardPage.class); + + public final static String FILE_ITEM_TYPE = "FILE"; + public final static String FOLDER_ITEM_TYPE = "FOLDER"; + + //private Upload uploadFile; + + public ImportToServerWizardPage() { + super("Import from file system"); + setDescription("Import files from the local file system to the server"); + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + new Label(composite, SWT.NONE).setText("Pick up a file"); +// uploadFile = new Upload(composite, SWT.BORDER); +// uploadFile.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); +// uploadFile.setBrowseButtonText("Open..."); + setControl(composite); + } + + public String getObjectPath() { + // NOTE Returns the full file name of the last uploaded file including + // the file path as selected by the user on his local machine. + // The full path including the directory and file drive are only + // returned, if the browser supports reading this properties. In Firefox + // 3, only the filename is returned. + return null; + } + + public String getObjectName() { + return null; + } + + public String getObjectType() { + return FILE_ITEM_TYPE; + } + + public void performFinish() { +// boolean success = uploadFile.performUpload(); +// if (!success) +// throw new ArgeoException("Cannot upload file named " +// + uploadFile.getPath()); + } + +// protected void handleUploadFinished(final Upload upload) { +// } + + public InputStream getFileInputStream() { + return null; + } + + public boolean getNeedsProgressMonitor() { + return false; + } + +} diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFile.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFile.java new file mode 100644 index 000000000..b55521b12 --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFile.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.rap.rwt.RWT; +import org.eclipse.rap.rwt.client.service.UrlLauncher; + +/** + * Rap specific command handler to open a file retrieved from the server. It + * forwards the request to the correct service after encoding file name and path + * in the request URI. + * + * The parameter "URI" is used to determine the correct file service, the path + * and the file name. An optional file name can be precised to present a + * different file name as the one used to retrieve it to the end user/ + * + * Various instances of this handler with different command ID might coexist in + * order to provide context specific download service. + * + * The instance specific service is called by its ID and must have been + * externally created + */ +public class OpenFile extends AbstractHandler { + private final static Log log = LogFactory.getLog(OpenFile.class); + + /* DEPENDENCY INJECTION */ + private String openFileServiceId; + + public final static String PARAM_FILE_NAME = OpenFileService.PARAM_FILE_NAME; + public final static String PARAM_FILE_URI = OpenFileService.PARAM_FILE_URI; // "param.fileURI"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + String fileName = event.getParameter(PARAM_FILE_NAME); + String fileUri = event.getParameter(PARAM_FILE_URI); + + // sanity check + if (fileUri == null || "".equals(fileUri.trim()) + || openFileServiceId == null + || "".equals(openFileServiceId.trim())) + return null; + + StringBuilder url = new StringBuilder(); + url.append(RWT.getServiceManager().getServiceHandlerUrl( + openFileServiceId)); + + url.append("&").append(PARAM_FILE_NAME).append("="); + url.append(fileName); + url.append("&").append(PARAM_FILE_URI).append("="); + url.append(fileUri); + + String downloadUrl = url.toString(); + if (log.isTraceEnabled()) + log.debug("URL : " + downloadUrl); + + UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class); + launcher.openURL(downloadUrl); + + // These lines are useless in the current use case but might be + // necessary with new browsers. Stored here for memo + // response.setContentType("application/force-download"); + // response.setHeader("Content-Disposition", contentDisposition); + // response.setHeader("Content-Transfer-Encoding", "binary"); + // response.setHeader("Pragma", "no-cache"); + // response.setHeader("Cache-Control", "no-cache, must-revalidate"); + return null; + } + + /* DEPENDENCY INJECTION */ + public void setOpenFileServiceId(String openFileServiceId) { + this.openFileServiceId = openFileServiceId; + } +} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFileService.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFileService.java new file mode 100644 index 000000000..e48babf0b --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFileService.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; +import org.argeo.ArgeoException; +import org.eclipse.rap.rwt.service.ServiceHandler; + +/** + * Basic Default service handler that retrieves a file on the server file system + * using its absolute path and forwards it to the end user browser. Rap + * specific. + * + * Clients might extend to provide context specific services (to open files from + * a JCR repository for instance) + */ +public class OpenFileService implements ServiceHandler { + public final static String PARAM_FILE_NAME = "param.fileName"; + public final static String PARAM_FILE_URI = "param.fileURI"; + + public final static String SCHEME_HOST_SEPARATOR = "://"; + public final static String FILE_SCHEME = "file"; + + public OpenFileService() { + } + + public void service(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String fileName = request.getParameter(PARAM_FILE_NAME); + String uri = request.getParameter(PARAM_FILE_URI); + + // Set the Metadata + response.setContentType("application/octet-stream"); + response.setContentLength((int) getFileLength(uri)); + if (fileName == null || "".equals(fileName.trim())) + fileName = getFileName(uri); + String contentDisposition = "attachment; filename=\"" + fileName + "\""; + response.setHeader("Content-Disposition", contentDisposition); + + response.getOutputStream().write(getFileAsByteArray(uri)); + // FileUtils.readFileToByteArray(new File(path)) + } + + protected byte[] getFileAsByteArray(String uri) { + if (uri.startsWith(FILE_SCHEME)) { + try { + return FileUtils.readFileToByteArray(new File( + getFilePathFromUri(uri))); + } catch (IOException ioe) { + throw new ArgeoException("Error while getting the file at " + + uri, ioe); + } + } + return null; + } + + protected long getFileLength(String uri) { + if (uri.startsWith(FILE_SCHEME)) { + return new File(getFilePathFromUri(uri)).length(); + } + return -1l; + } + + protected String getFileName(String uri) { + if (uri.startsWith(FILE_SCHEME)) { + return new File(getFilePathFromUri(uri)).getName(); + } + return null; + } + + private String getFilePathFromUri(String uri) { + return uri.substring((FILE_SCHEME + SCHEME_HOST_SEPARATOR).length()); + } + +} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/ThreadNLS.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/ThreadNLS.java new file mode 100644 index 000000000..8b8837f2e --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/ThreadNLS.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.rap.rwt.RWT; + +/** NLS attached to a given thread */ +public class ThreadNLS extends InheritableThreadLocal { + public final static String DEFAULT_BUNDLE_LOCATION = "/properties/plugin"; + + private final String bundleLocation; + + private Class type; + private Boolean utf8 = false; + + public ThreadNLS(String bundleLocation, Class type, Boolean utf8) { + this.bundleLocation = bundleLocation; + this.type = type; + this.utf8 = utf8; + } + + public ThreadNLS(Class type) { + this(DEFAULT_BUNDLE_LOCATION, type, false); + } + + @SuppressWarnings("unchecked") + @Override + protected T initialValue() { + if (utf8) + return (T) RWT.NLS.getUTF8Encoded(bundleLocation, type); + else + return (T) RWT.NLS.getISO8859_1Encoded(bundleLocation, type); + } +} diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/UploadFileWizardPage.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/UploadFileWizardPage.java new file mode 100644 index 000000000..17d4e22f3 --- /dev/null +++ b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/UploadFileWizardPage.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.specific; + +import java.io.InputStream; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.rap.rwt.widgets.FileUpload; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class UploadFileWizardPage extends WizardPage { + // private final static Log log = LogFactory + // .getLog(UploadFileWizardPage.class); + private static final long serialVersionUID = 8251354244542973179L; + public final static String FILE_ITEM_TYPE = "FILE"; + public final static String FOLDER_ITEM_TYPE = "FOLDER"; + + private FileUpload fileUpload; + + public UploadFileWizardPage() { + super("Import from file system"); + setDescription("Import files from the local file system to the server"); + } + + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + new Label(composite, SWT.NONE).setText("Pick up a file"); + fileUpload = new FileUpload(composite, SWT.BORDER); + fileUpload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + fileUpload.setText("Browse"); + setControl(composite); + } + + public String getObjectPath() { + // NOTE Returns the full file name of the last uploaded file including + // the file path as selected by the user on his local machine. + // The full path including the directory and file drive are only + // returned, if the browser supports reading this properties. In Firefox + // 3, only the filename is returned. + return null; + } + + public String getObjectName() { + return fileUpload.getFileName(); + } + + public String getObjectType() { + return FILE_ITEM_TYPE; + } + + public void performFinish() { + // boolean success = uploadFile.performUpload(); + // if (!success) + // throw new ArgeoException("Cannot upload file named " + // + uploadFile.getPath()); + } + + // protected void handleUploadFinished(final Upload upload) { + // } + + public InputStream getFileInputStream() { + return null; + } + + public boolean getNeedsProgressMonitor() { + return false; + } + +}