<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="src" path="src" />
+ <classpathentry kind="con"
+ path="org.eclipse.pde.core.requiredPlugins" />
+ <classpathentry kind="con"
+ path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6" />
+ <classpathentry kind="output" path="bin" />
</classpath>
+++ /dev/null
-#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
--- /dev/null
+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,\
+*
-source.. = src/main/java/
-output.. = target/classes/
-bin.includes = META-INF/,\
- .,\
\ No newline at end of file
+source.. = src/
+output.. = bin/
<artifactId>org.argeo.eclipse.ui.rap</artifactId>
<name>Commons Eclipse UI RAP</name>
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
-
- <configuration>
- <instructions>
- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
- <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
- <Require-Bundle>org.eclipse.rap.ui,org.eclipse.core.runtime</Require-Bundle>
- <!-- IMPORTANT : Note that we must exclude certain packages that are
- provided by dependencies to be sure that packages used in the current workspace
- are those provided by the require-bundles. Especially rwt.widgets.upload
- by instance. -->
- <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,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <!-- deleted from import package : javax.servlet, javax.servlet.http,org.argeo.eclipse.ui.dialogs,
- org.eclipse.jface.dialogs, -->
<dependencies>
<dependency>
<groupId>org.argeo.commons</groupId>
<artifactId>org.argeo.eclipse.ui</artifactId>
<version>2.1.12-SNAPSHOT</version>
</dependency>
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.argeo.tp</groupId>
+ <artifactId>slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
<!-- Argeo common distribution for RAP projects -->
<dependency>
<version>2.1.12-SNAPSHOT</version>
</dependency>
- <!-- Logging -->
- <dependency>
- <groupId>org.argeo.tp</groupId>
- <artifactId>slf4j.org.apache.commons.logging</artifactId>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
+++ /dev/null
-/*
- * 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);
- }
- }
-}
+++ /dev/null
-/*
- * 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() {
- }
-
-}
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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());
- // }
- // }
- //
- // }
- //
-
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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<T extends NLS> extends InheritableThreadLocal<T> {
- public final static String DEFAULT_BUNDLE_LOCATION = "/properties/plugin";
-
- private final String bundleLocation;
-
- private Class<T> type;
- private Boolean utf8 = false;
-
- public ThreadNLS(String bundleLocation, Class<T> type, Boolean utf8) {
- this.bundleLocation = bundleLocation;
- this.type = type;
- this.utf8 = utf8;
- }
-
- public ThreadNLS(Class<T> 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);
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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() {
+ }
+
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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());
+ // }
+ // }
+ //
+ // }
+ //
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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<T extends NLS> extends InheritableThreadLocal<T> {
+ public final static String DEFAULT_BUNDLE_LOCATION = "/properties/plugin";
+
+ private final String bundleLocation;
+
+ private Class<T> type;
+ private Boolean utf8 = false;
+
+ public ThreadNLS(String bundleLocation, Class<T> type, Boolean utf8) {
+ this.bundleLocation = bundleLocation;
+ this.type = type;
+ this.utf8 = utf8;
+ }
+
+ public ThreadNLS(Class<T> 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);
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}