<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.commons.eclipse</groupId>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.security</artifactId>
</dependency>
+
+
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.commons.eclipse</groupId>
<artifactId>org.argeo.eclipse.dep.common</artifactId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
+
+ <!-- Dependency to enable file upload. Should be included directly in coming
+ rap distribution -->
+ <dependency>
+ <groupId>org.argeo.dep.rap</groupId>
+ <artifactId>org.eclipse.rwt.widgets.upload</artifactId>
+ </dependency>
+ <!-- Needed by the bundle above -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.io</artifactId>
+ </dependency>
+
<!-- RAP Specific Dependencies -->
<dependency>
<groupId>org.eclipse.rap</groupId>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
</dependency>
-<!-- <dependency>-->
-<!-- <groupId>org.eclipse.equinox</groupId>-->
-<!-- <artifactId>org.eclipse.equinox.http.jetty</artifactId>-->
-<!-- </dependency>-->
<dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.http.registry</artifactId>
<groupId>org.eclipse.rap</groupId>
<artifactId>org.eclipse.rap.ui.views</artifactId>
</dependency>
-<!-- <dependency>-->
-<!-- <groupId>org.mortbay.jetty</groupId>-->
-<!-- <artifactId>org.mortbay.jetty.server</artifactId>-->
-<!-- </dependency>-->
-<!-- <dependency>-->
-<!-- <groupId>org.mortbay.jetty</groupId>-->
-<!-- <artifactId>org.mortbay.jetty.util</artifactId>-->
-<!-- </dependency>-->
+ <!-- Eclipse -->
<dependency>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.core.databinding</artifactId>
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
public class JcrUiPlugin extends AbstractUIPlugin {
public final static String ID = "org.argeo.eclipse.ui.jcr";
+ private static JcrUiPlugin plugin;
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ public static JcrUiPlugin getDefault() {
+ return plugin;
+ }
+
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(ID, path);
}
import javax.jcr.Node;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.eclipse.ui.dialogs.Error;
import org.argeo.eclipse.ui.jcr.views.GenericJcrBrowser;
import org.eclipse.core.commands.AbstractHandler;
/** Deletes the selected nodes */
public class DeleteNode extends AbstractHandler {
+ private static Log log = LogFactory.getLog(DeleteNode.class);
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
.findView(HandlerUtil.getActivePartId(event));
if (selection != null && selection instanceof IStructuredSelection) {
Iterator<?> it = ((IStructuredSelection) selection).iterator();
-
Object obj = null;
try {
while (it.hasNext()) {
if (obj instanceof Node) {
Node node = (Node) obj;
Node parentNode = node.getParent();
+ log.debug("Node ids : node :" + node.getIdentifier()
+ + " - pNode : " + parentNode.getIdentifier());
node.remove();
- view.nodeRemoved(parentNode);
+
+ // Postpone the refresh after the session.save
+ // view.nodeRemoved(parentNode);
+
node.getSession().save();
+ if (log.isDebugEnabled())
+ log.debug("session saved");
+ view.nodeRemoved(parentNode);
}
}
} catch (Exception e) {
}
return null;
}
-
}
package org.argeo.eclipse.ui.jcr.views;
-import java.io.BufferedInputStream;
-import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.dialogs.Error;
import org.argeo.eclipse.ui.jcr.browser.NodeContentProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.part.ViewPart;
public class GenericJcrBrowser extends ViewPart {
+ private static Log log = LogFactory.getLog(GenericJcrBrowser.class);
+
private TreeViewer nodesViewer;
private TableViewer propertiesViewer;
Error.show("Cannot open file children Node that are not of 'nt:resource' type.");
return;
}
- BufferedInputStream fis = null;
+ InputStream fis = null;
try {
- fis = (BufferedInputStream) child
+ fis = (InputStream) child
.getProperty("jcr:data").getBinary()
.getStream();
String name = node.getName();
-
+
// Instantiate the generic object that fits for
// both
// RCP & RAP.
FileHandler fh = new FileHandler();
- fh.openFile(name,
- fis);
- //fh.openFile(file);
+ fh.openFile(name, fis);
+ // fh.openFile(file);
} catch (Exception e) {
throw new ArgeoException(
"Stream error while opening file", e);
}
public void nodeRemoved(Node parentNode) {
- nodesViewer.refresh(parentNode);
+
+ List<Node> al = new ArrayList<Node>();
+ al.add(parentNode);
+
+ IStructuredSelection newSel = new StructuredSelection(al);
+ // IStructuredSelection newSel = new StructuredSelection(parentNode);
+
+ if (log.isDebugEnabled())
+ log.debug("new selection size = " + newSel.size());
+
+ nodesViewer.setSelection(newSel, true);
+ IStructuredSelection tmpSel = (IStructuredSelection) nodesViewer
+ .getSelection();
+
+ if (log.isDebugEnabled())
+ log.debug("set selection size = " + tmpSel.size());
+
+ nodesViewer.refresh();
+
+ //
+ // log.debug(" Class selected (Parent 1ST element) : "
+ // + tmpSel.getFirstElement().getClass());
+ // setFocus();
+ //
+ // nodesViewer.refresh(parentNode);
+
+ // // Call the refresh node command
+ // try {
+ // IWorkbench iw = JcrUiPlugin.getDefault().getWorkbench();
+ // IHandlerService handlerService = (IHandlerService) iw
+ // .getService(IHandlerService.class);
+ //
+ // // get the command from plugin.xml
+ // IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
+ // ICommandService cmdService = (ICommandService) window
+ // .getService(ICommandService.class);
+ // Command cmd = cmdService
+ // .getCommand(OpenEbiDetailsEditor.COMMAND_NAME);
+ //
+ // // log.debug("cmd : " + cmd);
+ // ArrayList<Parameterization> parameters = new
+ // ArrayList<Parameterization>();
+ //
+ // // get the parameter
+ // IParameter iparam = cmd
+ // .getParameter(OpenEbiDetailsEditor.PARAM_UUID);
+ //
+ // Parameterization params = new Parameterization(iparam,
+ // ((String[]) obj)[0]);
+ // parameters.add(params);
+ //
+ // // build the parameterized command
+ // ParameterizedCommand pc = new ParameterizedCommand(cmd,
+ // parameters.toArray(new Parameterization[parameters.size()]));
+ //
+ // // execute the command
+ // handlerService = (IHandlerService) window
+ // .getService(IHandlerService.class);
+ // handlerService.executeCommand(pc, null);
+ //
+ // } catch (Exception e) {
+ // throw new ArgeoException("Error opening EBI", e);
+ // }
}
public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
import javax.jcr.nodetype.NodeType;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.dialogs.Error;
+import org.argeo.eclipse.ui.specific.ImportFileSystemHandler;
+import org.argeo.eclipse.ui.specific.ImportFileSystemWizardPage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.widgets.Composite;
public class ImportFileSystemWizard extends Wizard {
private final static Log log = LogFactory
private ImportFileSystemWizardPage page1;
private final Node folder;
+ private ImportFileSystemHandler ifsh = new ImportFileSystemHandler();
+
public ImportFileSystemWizard(Node folder) {
this.folder = folder;
- setNeedsProgressMonitor(true);
+ setNeedsProgressMonitor(ifsh.getNeedsProgressMonitor());
setWindowTitle("Import from file system");
}
addPage(page1);
}
+ /**
+ * Called when the user click on 'Finish' in the wizard. The real upload to
+ * the JCR repository is done here.
+ */
@Override
public boolean performFinish() {
- final String directory = page1.getDirectory();
- if (directory == null || !new File(directory).exists()) {
- Error.show("Directory " + directory + " does not exist");
- return false;
- }
- Boolean failed = false;
- final File dir = new File(directory).getAbsoluteFile();
- final Long sizeB = directorySize(dir, 0l);
- final Stats stats = new Stats();
- Long begin = System.currentTimeMillis();
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) {
- try {
- Integer sizeKB = (int) (sizeB / FileUtils.ONE_KB);
- monitor.beginTask("", sizeKB);
- importDirectory(folder, dir, monitor, stats);
- monitor.done();
- } catch (Exception e) {
- if (e instanceof RuntimeException)
- throw (RuntimeException) e;
- else
- throw new ArgeoException("Cannot import "
- + directory, e);
- }
+ // Initialization
+ final String objectType = page1.getObjectType();
+ final String objectPath = page1.getObjectPath();
+
+ // We do not display a progress bar for one file only
+ if ("nt:file".equals(objectType)) {
+ // In Rap we must force the "real" upload of the file
+ page1.performFinish();
+ try {
+ Node fileNode = folder.addNode(page1.getObjectName(),
+ NodeType.NT_FILE);
+ Node resNode = fileNode.addNode(Property.JCR_CONTENT,
+ NodeType.NT_RESOURCE);
+ Binary binary = null;
+ try {
+ binary = folder.getSession().getValueFactory()
+ .createBinary(page1.getFileInputStream());
+ resNode.setProperty(Property.JCR_DATA, binary);
+ } finally {
+ if (binary != null)
+ binary.dispose();
+ IOUtils.closeQuietly(page1.getFileInputStream());
}
- });
- } catch (Exception e) {
- Error.show("Cannot import " + directory, e);
- failed = true;
+ folder.getSession().save();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ } else if ("nt:folder".equals(objectType)) {
+ if (objectPath == null || !new File(objectPath).exists()) {
+ Error.show("Directory " + objectPath + " does not exist");
+ return false;
+ }
+
+ Boolean failed = false;
+ final File dir = new File(objectPath).getAbsoluteFile();
+ final Long sizeB = directorySize(dir, 0l);
+ final Stats stats = new Stats();
+ Long begin = System.currentTimeMillis();
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ try {
+ Integer sizeKB = (int) (sizeB / FileUtils.ONE_KB);
+ monitor.beginTask("", sizeKB);
+ importDirectory(folder, dir, monitor, stats);
+ monitor.done();
+ } catch (Exception e) {
+ if (e instanceof RuntimeException)
+ throw (RuntimeException) e;
+ else
+ throw new ArgeoException("Cannot import "
+ + objectPath, e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ Error.show("Cannot import " + objectPath, e);
+ failed = true;
+ }
+
+ Long duration = System.currentTimeMillis() - begin;
+ Long durationS = duration / 1000l;
+ String durationStr = (durationS / 60) + " min " + (durationS % 60)
+ + " s";
+ StringBuffer message = new StringBuffer("Imported\n");
+ message.append(stats.fileCount).append(" files\n");
+ message.append(stats.dirCount).append(" directories\n");
+ message.append(FileUtils.byteCountToDisplaySize(stats.sizeB));
+ if (failed)
+ message.append(" of planned ").append(
+ FileUtils.byteCountToDisplaySize(sizeB));
+ message.append("\n");
+ message.append("in ").append(durationStr).append("\n");
+ if (failed)
+ MessageDialog.openError(getShell(), "Import failed",
+ message.toString());
+ else
+ MessageDialog.openInformation(getShell(), "Import successful",
+ message.toString());
+
+ return true;
}
+ return false;
- Long duration = System.currentTimeMillis() - begin;
- Long durationS = duration / 1000l;
- String durationStr = (durationS / 60) + " min " + (durationS % 60)
- + " s";
- StringBuffer message = new StringBuffer("Imported\n");
- message.append(stats.fileCount).append(" files\n");
- message.append(stats.dirCount).append(" directories\n");
- message.append(FileUtils.byteCountToDisplaySize(stats.sizeB));
- if (failed)
- message.append(" of planned ").append(
- FileUtils.byteCountToDisplaySize(sizeB));
- message.append("\n");
- message.append("in ").append(durationStr).append("\n");
- if (failed)
- MessageDialog.openError(getShell(), "Import failed",
- message.toString());
- else
- MessageDialog.openInformation(getShell(), "Import successful",
- message.toString());
-
- return true;
}
/** Recursively computes the size of the directory in bytes. */
return size;
}
- /** Recursively computes the size of the directory in bytes. */
+ /**
+ * Import recursively a directory and its content to the repository.
+ */
protected void importDirectory(Node folder, File dir,
IProgressMonitor monitor, Stats stats) {
try {
stats.dirCount++;
} else {
Long fileSize = file.length();
- monitor.subTask(file.getName() + " ("
- + FileUtils.byteCountToDisplaySize(fileSize) + ") "
- + file.getCanonicalPath());
- try {
- Node fileNode = folder.addNode(file.getName(),
- NodeType.NT_FILE);
- Node resNode = fileNode.addNode(Property.JCR_CONTENT,
- NodeType.NT_RESOURCE);
- Binary binary = null;
+
+ // we skip tempory files that are created by apps when a
+ // file is being edited.
+ // TODO : make this configurable.
+ if (file.getName().lastIndexOf('~') != file.getName()
+ .length() - 1) {
+
+ monitor.subTask(file.getName() + " ("
+ + FileUtils.byteCountToDisplaySize(fileSize)
+ + ") " + file.getCanonicalPath());
try {
- binary = folder.getSession().getValueFactory()
- .createBinary(new FileInputStream(file));
- resNode.setProperty(Property.JCR_DATA, binary);
- } finally {
- if (binary != null)
- binary.dispose();
+ Node fileNode = folder.addNode(file.getName(),
+ NodeType.NT_FILE);
+ Node resNode = fileNode.addNode(
+ Property.JCR_CONTENT, NodeType.NT_RESOURCE);
+ Binary binary = null;
+ try {
+ binary = folder
+ .getSession()
+ .getValueFactory()
+ .createBinary(new FileInputStream(file));
+ resNode.setProperty(Property.JCR_DATA, binary);
+ } finally {
+ if (binary != null)
+ binary.dispose();
+ }
+ folder.getSession().save();
+ stats.fileCount++;
+ stats.sizeB = stats.sizeB + fileSize;
+ } catch (Exception e) {
+ log.warn("Import of "
+ + file
+ + " ("
+ + FileUtils
+ .byteCountToDisplaySize(fileSize)
+ + ") failed: " + e);
+ folder.getSession().refresh(false);
}
- folder.getSession().save();
- stats.fileCount++;
- stats.sizeB = stats.sizeB + fileSize;
- } catch (Exception e) {
- log.warn("Import of " + file + " ("
- + FileUtils.byteCountToDisplaySize(fileSize)
- + ") failed: " + e);
- folder.getSession().refresh(false);
+ monitor.worked((int) (fileSize / FileUtils.ONE_KB));
}
- monitor.worked((int) (fileSize / FileUtils.ONE_KB));
}
}
} catch (Exception e) {
}
}
- protected class ImportFileSystemWizardPage extends WizardPage {
- private DirectoryFieldEditor dfe;
-
- public ImportFileSystemWizardPage() {
- super("Import from file system");
- setDescription("Import files from the local file system into the JCR repository");
- }
-
- public void createControl(Composite parent) {
- dfe = new DirectoryFieldEditor("directory", "From",
- parent);
- setControl(dfe.getTextControl(parent));
- }
-
- public String getDirectory() {
- return dfe.getStringValue();
- }
-
- }
-
static class Stats {
public Long fileCount = 0l;
public Long dirCount = 0l;
<Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
<Require-Bundle>org.eclipse.rap.ui,org.eclipse.core.runtime</Require-Bundle>
<Import-Package>
- org.springframework.beans.factory,
- org.springframework.core.io.support,
org.apache.commons.io,
org.argeo,
- org.argeo.eclipse.ui.dialogs,
+ org.springframework.beans.factory,
+ org.springframework.core.io.support,
!org.eclipse.core.runtime,
!org.eclipse.core.commands,
!org.eclipse.ui.plugin,
</plugin>
</plugins>
</build>
+
+ <!-- deleted from import package : javax.servlet, javax.servlet.http,org.argeo.eclipse.ui.dialogs,
+ org.eclipse.jface.dialogs, -->
<dependencies>
<!-- Argeo Commons for Eclipse (not specific) -->
<dependency>
<artifactId>org.argeo.eclipse.ui</artifactId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
+
+ <!-- Argeo common distribution for RAP projects -->
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.io</artifactId>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.rap</artifactId>
+ <version>${version.argeo-commons}</version>
</dependency>
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
</dependencies>
</project>
package org.argeo.eclipse.ui.specific;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
-//import org.argeo.eclipse.ui.dialogs.Error;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.io.FileUtils;
+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.rwt.RWT;
public class FileHandler {
+ private static Log log = LogFactory.getLog(FileHandler.class);
+
public FileHandler() {
}
public void openFile(String fileName, InputStream is) {
- // org.argeo.eclipse.ui.dialogs.Error.show("In Open File for RAP.");
+
+ // // Which file to download?
+ // String fileName = RWT.getRequest().getParameter( "filename" );
+ // // Get the file content
+ // byte[] download = MyDataStore.getByteArrayData( fileName );
+ // // Send the file in the response
+ // HttpServletResponse response = RWT.getResponse();
+ // response.setContentType( "application/octet-stream" );
+ // response.setContentLength( download.length );
+ // String contentDisposition = "attachment; filename=\"" + fileName +
+ // "\"";
+ // response.setHeader( "Content-Disposition", contentDisposition );
+ // try {
+ // response.getOutputStream().write( download );
+ // } catch( IOException e1 ) {
+ // e1.printStackTrace();
+ // }
+ //
+ //
+
+ try {
+
+ // / workaround : create a tmp file.
+ String prefix = "", suffix = "";
+ if (fileName != null) {
+ int ind = fileName.lastIndexOf('.');
+ if (ind > 0) {
+ prefix = fileName.substring(0, ind);
+ suffix = fileName.substring(ind);
+ }
+ }
+
+ File tmpFile = createTmpFile(prefix, suffix, is);
+
+ // Send the file in the response
+ HttpServletResponse response = RWT.getResponse();
+ byte[] ba = null;
+ ba = FileUtils.readFileToByteArray(tmpFile);
+
+ response.setContentLength(ba.length);
+
+ // String contentDisposition = "attachment; filename=\"" + fileName
+ // + "\"";
+ String contentDisposition = "attachment; filename=\"" + fileName
+ + "\"";
+ 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");
+
+ // must-revalidate");
+
+ if (log.isDebugEnabled()) {
+ log.debug("Header Set ");
+ }
+
+ // header("Content-Type: application/force-download; name=\"".$localName."\"");
+ // 852 header("Content-Transfer-Encoding: binary");
+ // 853 if($gzip){
+ // 854 header("Content-Encoding: gzip");
+ // 855 // If gzip, recompute data size!
+ // 856 $gzippedData =
+ // ($data?gzencode($filePathOrData,9):gzencode(file_get_contents($filePathOrData),
+ // 9));
+ // 857 $size = strlen($gzippedData);
+ // 858 }
+ // 859 header("Content-Length: ".$size);
+ // 860 if ($isFile && ($size != 0)) header("Content-Range: bytes 0-"
+ // . ($size - 1) . "/" . $size . ";");
+ // 861
+ // header("Content-Disposition: attachment; filename=\"".$localName."\"");
+ // 862 header("Expires: 0");
+ // 863 header("Cache-Control: no-cache, must-revalidate");
+ // 864 header("Pragma: no-cache");
+
+ // IOUtils.copy(is, response.getOutputStream());
+ response.getOutputStream().write(ba);
+ // Error.show("In Open File for RAP.");
+ } catch (IOException ioe) {
+
+ throw new ArgeoException("Cannot copy input stream from file "
+ + fileName + " to HttpServletResponse", ioe);
+ }
+
}
private File createTmpFile(String prefix, String suffix, InputStream is) {
File tmpFile = null;
+ OutputStream os = null;
+ try {
+ tmpFile = File.createTempFile(prefix, suffix);
+ os = new FileOutputStream(tmpFile);
+ IOUtils.copy(is, os);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + prefix + "."
+ + suffix, e);
+ } finally {
+ IOUtils.closeQuietly(os);
+ }
return tmpFile;
}
--- /dev/null
+package org.argeo.eclipse.ui.specific;
+
+public class ImportFileSystemHandler {
+ public boolean getNeedsProgressMonitor() {
+ return false;
+ }
+}
--- /dev/null
+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.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.rwt.widgets.Upload;
+import org.eclipse.rwt.widgets.UploadAdapter;
+import org.eclipse.rwt.widgets.UploadEvent;
+import org.eclipse.rwt.widgets.UploadItem;
+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.Display;
+import org.eclipse.swt.widgets.Label;
+
+public class ImportFileSystemWizardPage extends WizardPage {
+ private Log log = LogFactory.getLog(ImportFileSystemWizardPage.class);
+
+ private Upload uploadFile;
+
+ public ImportFileSystemWizardPage() {
+ super("Import from file system");
+ setDescription("Import files from the local file system into the JCR repository");
+ }
+
+ 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...");
+ uploadFile.addUploadListener(new UploadManager(uploadFile));
+
+ 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 uploadFile.getPath();
+ }
+
+ public String getObjectName() {
+ return uploadFile.getUploadItem().getFileName();
+ }
+
+ public String getObjectType() {
+ return "nt:file";
+ }
+
+ public void performFinish() {
+ boolean success = uploadFile.performUpload();
+ if (!success)
+ throw new ArgeoException("Cannot upload file named "
+ + uploadFile.getPath());
+ }
+
+ protected void handleUploadFinished(final Upload upload) {
+ if (log.isTraceEnabled()) {
+ UploadItem uploadItem = upload.getUploadItem();
+ log.trace("filename : " + uploadItem.getFileName());
+ log.trace("content-type : " + uploadItem.getContentType());
+ }
+ }
+
+ public InputStream getFileInputStream() {
+ return uploadFile.getUploadItem().getFileInputStream();
+ }
+
+ 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());
+ }
+ }
+ }
+}
<version>0.2.3-SNAPSHOT</version>
</dependency>
+ <!-- Argeo Commons third party distribution for RCP projects -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
+
+
<dependency>
<groupId>org.argeo.commons.basic</groupId>
<artifactId>org.argeo.basic.nodeps</artifactId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
+ <!-- Others. -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.io</artifactId>
</dependency>
+
</dependencies>
</project>
\ No newline at end of file
--- /dev/null
+package org.argeo.eclipse.ui.specific;
+
+public class ImportFileSystemHandler {
+ public boolean getNeedsProgressMonitor() {
+ return true;
+ }
+
+
+
+}
--- /dev/null
+package org.argeo.eclipse.ui.specific;
+
+import java.io.InputStream;
+
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+public class ImportFileSystemWizardPage extends WizardPage {
+ private DirectoryFieldEditor dfe;
+
+ public ImportFileSystemWizardPage() {
+ super("Import from file system");
+ setDescription("Import files from the local file system into the JCR repository");
+ }
+
+ public void createControl(Composite parent) {
+ dfe = new DirectoryFieldEditor("directory", "From", parent);
+ setControl(dfe.getTextControl(parent));
+ }
+
+ public String getObjectPath() {
+ System.out.println("dfe.getStringValue() : " + dfe.getStringValue());
+ return dfe.getStringValue();
+ }
+
+ public String getObjectType() {
+ return "nt:folder";
+ }
+
+ // Dummy methods : useless in RCP context but useful for RAP
+ /** WARNING : always return null in RCP context */
+ public String getObjectName() {
+ return null;
+ }
+
+ /** WARNING : di nothing in RCP context */
+ public void performFinish() {
+ }
+
+ /** WARNING : always return null in RCP context */
+ public InputStream getFileInputStream() {
+ return null;
+ }
+
+}