+ Implementation of file handlers for both RCP & RAP, finalisation.
authorBruno Sinou <bsinou@argeo.org>
Fri, 11 Mar 2011 18:42:25 +0000 (18:42 +0000)
committerBruno Sinou <bsinou@argeo.org>
Fri, 11 Mar 2011 18:42:25 +0000 (18:42 +0000)
+ Use case CSV parser, clean of the test

git-svn-id: https://svn.argeo.org/commons/trunk@4288 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

15 files changed:
basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java
eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java
eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/views/GenericJcrBrowser.java
eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/wizards/ImportFileSystemWizard.java
eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java
eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java
eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java [new file with mode: 0644]
eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java
eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java
eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java [deleted file]
eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties [deleted file]

index 811758a1375d7465b9618af9ddf03647c0cf250b..f703d54ee42bc9491026700e1e9449bb70633948 100644 (file)
@@ -22,11 +22,6 @@ public class CsvParserParseFileTest extends TestCase {
                parser.parse(in);
                in.close();
 
-               for (Integer i : lines.keySet()) {
-                       Map<String, String> curLine = lines.get(i);
-                       System.out.println("i : " + i.toString() + " - ID :"
-                                       + curLine.get("ID"));
-               }
                assertEquals(5, lines.size());
        }
 
index f8de5f3b54a8ecee9da1900b86d1de0d4d8b1d1c..6cf4d29c58ba058d0b5a6181de67eeab2d8cda33 100644 (file)
@@ -38,48 +38,74 @@ public class JcrFileProvider implements FileProvider {
        }
 
        public byte[] getByteArrayFileFromId(String fileId) {
+               InputStream fis = null;
+               byte[] ba = null;
+               Node child = getFileNodeFromId(fileId);
                try {
-                       Object[] nodes = repositoryNode.getChildren();
+                       fis = (InputStream) child.getProperty("jcr:data").getBinary()
+                                       .getStream();
+                       ba = IOUtils.toByteArray(fis);
+
+               } catch (Exception e) {
+                       throw new ArgeoException("Stream error while opening file", e);
+               } finally {
+                       IOUtils.closeQuietly(fis);
+               }
+               return ba;
+       }
+
+       public InputStream getInputStreamFromFileId(String fileId) {
+               try {
+                       InputStream fis = null;
+
+                       Node child = getFileNodeFromId(fileId);
+                       fis = (InputStream) child.getProperty("jcr:data").getBinary()
+                                       .getStream();
+                       return fis;
+               } catch (RepositoryException re) {
+                       throw new ArgeoException("Cannot get stream from file node for Id "
+                                       + fileId, re);
+               }
+       }
+
+       /**
+        * Throws an exception if the node is not found in the current repository (a
+        * bit like a FileNotFoundException)
+        * 
+        * @param fileId
+        * @return Returns the child node of the nt:file node. It is the child node
+        *         that have the jcr:data property where actual file is stored.
+        *         never null
+        */
+       private Node getFileNodeFromId(String fileId) {
+               Object[] nodes = repositoryNode.getChildren();
+               try {
+                       Node result = null;
 
                        repos: for (int i = 0; i < nodes.length; i++) {
                                WorkspaceNode wNode = (WorkspaceNode) nodes[i];
-                               Node node = null;
-                               node = wNode.getSession().getNodeByIdentifier(fileId);
+                               result = wNode.getSession().getNodeByIdentifier(fileId);
 
-                               if (node == null)
+                               if (result == null)
                                        continue repos;
 
-                               if (!node.isNodeType("nt:file"))
+                               // Ensure that the node have the correct type.
+                               if (!result.isNodeType("nt:file"))
                                        throw new ArgeoException(
                                                        "Cannot open file children Node that are not of 'nt:resource' type.");
 
-                               Node child = node.getNodes().nextNode();
-                               if (!child.isNodeType("nt:resource"))
+                               Node child = result.getNodes().nextNode();
+                               if (child == null || !child.isNodeType("nt:resource"))
                                        throw new ArgeoException(
-                                                       "Cannot open file children Node that are not of 'nt:resource' type.");
+                                                       "ERROR: IN the current implemented model, nt:file file node must have one and only one child of the nt:ressource, where actual data is stored");
 
-                               InputStream fis = null;
-                               byte[] ba = null;
-                               try {
-                                       fis = (InputStream) child.getProperty("jcr:data")
-                                                       .getBinary().getStream();
-                                       ba = IOUtils.toByteArray(fis);
-
-                               } catch (Exception e) {
-                                       throw new ArgeoException("Stream error while opening file",
-                                                       e);
-                               } finally {
-                                       IOUtils.closeQuietly(fis);
-                               }
-                               if (ba != null)
-                                       return ba;
+                               return child;
                        }
-
                } catch (RepositoryException re) {
-                       throw new ArgeoException("RepositoryException while reading file ",
-                                       re);
+                       throw new ArgeoException("Erreur while getting file node of ID "
+                                       + fileId, re);
                }
 
-               throw new ArgeoException("File not found for ID " + fileId);
+               throw new ArgeoException("File node not found for ID" + fileId);
        }
 }
index cf70923158629d960737d83f9e8db655ae87eb7d..4685fbb2131fc7af0d40645e5e2d7af6edc19d60 100644 (file)
@@ -1,6 +1,5 @@
 package org.argeo.eclipse.ui.jcr.views;
 
-import java.io.InputStream;
 import java.util.Arrays;
 
 import javax.jcr.Node;
@@ -8,11 +7,9 @@ import javax.jcr.Property;
 import javax.jcr.PropertyType;
 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.argeo.eclipse.ui.jcr.browser.NodeLabelProvider;
 import org.argeo.eclipse.ui.jcr.browser.PropertiesContentProvider;
@@ -52,9 +49,6 @@ public class GenericJcrBrowser extends ViewPart {
 
        @Override
        public void createPartControl(Composite parent) {
-               /*
-                * TEST
-                */
 
                // Instantiate the generic object that fits for
                // both RCP & RAP, must be final to be accessed in the double click
@@ -65,10 +59,6 @@ public class GenericJcrBrowser extends ViewPart {
                final JcrFileProvider jfp = new JcrFileProvider();
                final FileHandler fh = new FileHandler(jfp);
 
-               /*
-                * TEST END
-                */
-
                parent.setLayout(new FillLayout());
 
                SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
@@ -109,74 +99,31 @@ public class GenericJcrBrowser extends ViewPart {
                                if (obj instanceof RepositoryNode) {
                                        RepositoryNode rpNode = (RepositoryNode) obj;
                                        rpNode.login();
-                                       // For the file provider to be able to browse the repo.
+                                       // For the file provider to be able to browse the various
+                                       // repository.
                                        // TODO : enhanced that.
                                        jfp.setRepositoryNode(rpNode);
-                                       
                                        nodesViewer.refresh(obj);
+
                                } else if (obj instanceof WorkspaceNode) {
                                        ((WorkspaceNode) obj).login();
                                        nodesViewer.refresh(obj);
-                               } // call the openFile commands on node
-                               else if (obj instanceof Node) {
-                                       // Shell shell =
-                                       // aup.getWorkbench().getActiveWorkbenchWindow()
-                                       // .getShell();
-                                       // we can also do
-                                       // event.getViewer().getControl().getShell();
-
-                                       // Browser browser = new Browser(shell, SWT.NONE);
-                                       // browser.setText(encodedURL);
-                                       // boolean check = browser.setUrl(encodedURL);
-                                       // System.out.println("soo ?? : " + check);
-                                       // System.out.println("script : " + browser.executeScript);
-
-                                       // try {
-                                       // RWT.getResponse().sendRedirect(encodedURL);
-                                       // } catch (IOException e1) {
-                                       // // TODO Auto-generated catch block
-                                       // e1.printStackTrace();
-                                       // }
-
-                                       // final Browser browser = new Browser(parent, SWT.NONE);
-                                       // browser.setText(createDownloadHtml("test.pdf",
-                                       // "Download file"));
-
+                               } else if (obj instanceof Node) {
                                        Node node = (Node) obj;
+                                       
+                                       // double clic on a file node triggers its opening
                                        try {
                                                if (node.isNodeType("nt:file")) {
                                                        String name = node.getName();
                                                        String id = node.getIdentifier();
-
-                                                       Node child = node.getNodes().nextNode();
-                                                       if (!child.isNodeType("nt:resource")) {
-                                                               Error.show("Cannot open file children Node that are not of 'nt:resource' type.");
-                                                               return;
-                                                       }
-
-                                                       InputStream fis = null;
-
-                                                       try {
-                                                               fis = (InputStream) child
-                                                                               .getProperty("jcr:data").getBinary()
-                                                                               .getStream();
-                                                               // Instantiate the generic object that fits for
-                                                               // both RCP & RAP.
-                                                               fh.openFile(name, id, fis);
-                                                       } catch (Exception e) {
-                                                               throw new ArgeoException(
-                                                                               "Stream error while opening file", e);
-                                                       } finally {
-                                                               IOUtils.closeQuietly(fis);
-                                                       }
+                                                       fh.openFile(name, id);
                                                }
                                        } catch (RepositoryException re) {
-                                               re.printStackTrace();
-
+                                               throw new ArgeoException(
+                                                               "Repository error while getting Node file info",
+                                                               re);
                                        }
-
                                }
-
                        }
                });
 
index e52fa6768aba927a95b0b2d6b54d3fc567f5c33e..bbc20fe702682a29d9b9fad0087b039d00afc3aa 100644 (file)
@@ -14,8 +14,7 @@ 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.argeo.eclipse.ui.specific.ImportToServerWizardPage;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -25,21 +24,19 @@ public class ImportFileSystemWizard extends Wizard {
        private final static Log log = LogFactory
                        .getLog(ImportFileSystemWizard.class);
 
-       private ImportFileSystemWizardPage page1;
+       private ImportToServerWizardPage page1;
        private final Node folder;
 
-       private ImportFileSystemHandler ifsh = new ImportFileSystemHandler();
-
        public ImportFileSystemWizard(Node folder) {
                this.folder = folder;
-               setNeedsProgressMonitor(ifsh.getNeedsProgressMonitor());
+               setNeedsProgressMonitor(page1.getNeedsProgressMonitor());
                setWindowTitle("Import from file system");
        }
 
        @Override
        public void addPages() {
                try {
-                       page1 = new ImportFileSystemWizardPage();
+                       page1 = new ImportToServerWizardPage();
                        addPage(page1);
                } catch (Exception e) {
                        e.printStackTrace();
@@ -58,7 +55,7 @@ public class ImportFileSystemWizard extends Wizard {
                final String objectPath = page1.getObjectPath();
 
                // We do not display a progress bar for one file only
-               if ("nt:file".equals(objectType)) {
+               if (page1.FILE_ITEM_TYPE.equals(objectType)) {
                        // In Rap we must force the "real" upload of the file
                        page1.performFinish();
                        try {
@@ -82,7 +79,7 @@ public class ImportFileSystemWizard extends Wizard {
                                return false;
                        }
                        return true;
-               } else if ("nt:folder".equals(objectType)) {
+               } else if (page1.FOLDER_ITEM_TYPE.equals(objectType)) {
                        if (objectPath == null || !new File(objectPath).exists()) {
                                Error.show("Directory " + objectPath + " does not exist");
                                return false;
index 289cd2b903c412cf762aee3e3a7c050dc1430200..f873f1a524cf0c078dfa73a120f929cde74916df 100644 (file)
@@ -1,6 +1,5 @@
 package org.argeo.eclipse.ui.specific;
 
-import java.io.InputStream;
 import java.net.URL;
 
 import org.apache.commons.logging.Log;
@@ -32,10 +31,15 @@ public class FileHandler {
                IServiceManager manager = RWT.getServiceManager();
                IServiceHandler handler = new DownloadServiceHandler(provider);
                manager.registerServiceHandler("downloadServiceHandler", handler);
-
        }
 
-       public void openFile(String fileName, String fileId, InputStream is) {
+       public void openFile(String fileName, String fileId) {
+
+               // See RAP FAQ:
+               // http://wiki.eclipse.org/RAP/FAQ#How_to_provide_download_link.3F
+               // And forum discussion :
+               // http://www.eclipse.org/forums/index.php?t=msg&th=205487&start=0&S=43d85dacc88b505402420592109c7240
+
                try {
                        if (log.isDebugEnabled())
                                log.debug("URL : " + createFullDownloadUrl(fileName, fileId));
@@ -43,138 +47,19 @@ public class FileHandler {
                        URL url = new URL(createFullDownloadUrl(fileName, fileId));
                        PlatformUI.getWorkbench().getBrowserSupport()
                                        .createBrowser("DownloadDialog").openURL(url);
-
-                       /*
-                        * // New try : must define a service handler for the current file,
-                        * // register it and redirect the URL to it.
-                        * 
-                        * // 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);
-                        * HttpServletResponse response = RWT.getResponse();
-                        * 
-                        * DownloadHandler dh = new DownloadHandler(tmpFile.getName(),
-                        * tmpFile, "application/pdf", fileName);
-                        * 
-                        * log.debug("Got a DH : " + dh.toString());
-                        * 
-                        * // TODO : should try with that. // String encodedURL =
-                        * RWT.getResponse().encodeURL(url.toString());
-                        * response.sendRedirect(dh.getURL());
-                        */
-
-                       // final Browser browser = new Browser(parent, SWT.NONE);
-                       // browser.setText(createDownloadHtml("test.pdf", "Download file"));
-
                } catch (Exception e) {
                        e.printStackTrace();
                }
 
-               // // 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);
-                * 
-                * long l = tmpFile.length();
-                * 
-                * if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) throw new
-                * ArgeoException("IllegalArgumentException : " + l +
-                * " cannot be cast to int without changing its value.");
-                * response.setContentLength((int) l);
-                * 
-                * // 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); }
-                */
-
+               // 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 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;
-       // }
-
        private String createFullDownloadUrl(String fileName, String fileId) {
                StringBuilder url = new StringBuilder();
                url.append(RWT.getRequest().getRequestURL());
index ba4946d8fa8db52aef38437b2330f0bd2d9f2fae..c63088bc9e75f7edeffab237b20658b31d8a9c7e 100644 (file)
@@ -1,5 +1,7 @@
 package org.argeo.eclipse.ui.specific;
 
+import java.io.InputStream;
+
 /**
  * Used for file download : subclasses must implement model specific methods to
  * get a byte array representing a file given is ID.
@@ -10,5 +12,6 @@ package org.argeo.eclipse.ui.specific;
 public interface FileProvider {
 
        public byte[] getByteArrayFileFromId(String fileId);
+       public InputStream getInputStreamFromFileId(String fileId);
 
 }
diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java
deleted file mode 100644 (file)
index 607d113..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.argeo.eclipse.ui.specific;
-
-public class ImportFileSystemHandler {
-       public boolean getNeedsProgressMonitor() {
-               return false;
-       }
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java
deleted file mode 100644 (file)
index e0a0089..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-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.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 ImportFileSystemWizardPage extends WizardPage {
-       private final static 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...");
-               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) {
-       }
-
-       public InputStream getFileInputStream() {
-               return uploadFile.getUploadItem().getFileInputStream();
-       }
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java
new file mode 100644 (file)
index 0000000..5a1669c
--- /dev/null
@@ -0,0 +1,76 @@
+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.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 uploadFile.getPath();
+       }
+
+       public String getObjectName() {
+               return uploadFile.getUploadItem().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 uploadFile.getUploadItem().getFileInputStream();
+       }
+
+       public boolean getNeedsProgressMonitor() {
+               return false;
+       }
+
+}
index e9d7d23d415a24173e1baaea944a283bb2a7f93f..53285b4f03f2a2f020654f21350a25fdc73a067f 100644 (file)
@@ -17,13 +17,14 @@ import org.argeo.ArgeoException;
  */
 public class FileHandler {
 
-       // unused file provider : collateral effects of single sourcing, this File
-       // provider is compulsory for RAP file handler
-       public FileHandler(FileProvider jfp) {
-       }
+       private FileProvider provider;
 
-       public void openFile(String fileName, String fileId, InputStream is) {
+       public FileHandler(FileProvider provider) {
+               this.provider = provider;
+       }
 
+       public void openFile(String fileName, String fileId) {
+               String tmpFileName = fileName;
                String prefix = "", extension = "";
                if (fileName != null) {
                        int ind = fileName.lastIndexOf('.');
@@ -33,30 +34,22 @@ public class FileHandler {
                        }
                }
 
-               File file = createTmpFile(prefix, extension, is);
-
+               InputStream is = null;
                try {
+                       is = provider.getInputStreamFromFileId(fileId);
+                       File file = createTmpFile(prefix, extension, is);
+                       tmpFileName = file.getName();
                        Desktop desktop = null;
                        if (Desktop.isDesktopSupported()) {
                                desktop = Desktop.getDesktop();
                        }
                        desktop.open(file);
                } catch (IOException e) {
-                       throw new ArgeoException("Cannot open file " + file.getName(), e);
-               }
-       }
-
-       private void openFile(File file) {
-               try {
-                       Desktop desktop = null;
-                       if (Desktop.isDesktopSupported()) {
-                               desktop = Desktop.getDesktop();
-                               desktop.open(file);
-                       } else {
-                               throw new ArgeoException("Desktop integration not supported.");
-                       }
-               } catch (IOException e) {
-                       throw new ArgeoException("Cannot open file " + file.getName(), e);
+                       // Note : tmpFileName = fileName if the error has been thrown while
+                       // creating the tmpFile.
+                       throw new ArgeoException("Cannot open file " + tmpFileName, e);
+               } finally {
+                       IOUtils.closeQuietly(is);
                }
        }
 
@@ -75,5 +68,4 @@ public class FileHandler {
                }
                return tmpFile;
        }
-
 }
index ba4946d8fa8db52aef38437b2330f0bd2d9f2fae..d12d3d79060b3b7d86b5e702769a2333e64234f1 100644 (file)
@@ -1,5 +1,7 @@
 package org.argeo.eclipse.ui.specific;
 
+import java.io.InputStream;
+
 /**
  * Used for file download : subclasses must implement model specific methods to
  * get a byte array representing a file given is ID.
@@ -10,5 +12,7 @@ package org.argeo.eclipse.ui.specific;
 public interface FileProvider {
 
        public byte[] getByteArrayFileFromId(String fileId);
+       
+       public InputStream getInputStreamFromFileId(String fileId);
 
 }
diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java
deleted file mode 100644 (file)
index 0316c39..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.argeo.eclipse.ui.specific;
-
-public class ImportFileSystemHandler {
-       public boolean getNeedsProgressMonitor() {
-               return true;
-       }
-
-       
-       
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java
deleted file mode 100644 (file)
index 27f0811..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-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;
-       }
-
-}
diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java
new file mode 100644 (file)
index 0000000..e37fb91
--- /dev/null
@@ -0,0 +1,52 @@
+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 ImportToServerWizardPage extends WizardPage {
+
+       public final static String FILE_ITEM_TYPE = "FILE";
+       public final static String FOLDER_ITEM_TYPE = "FOLDER";
+
+       private DirectoryFieldEditor dfe;
+
+       public ImportToServerWizardPage() {
+               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() {
+               return dfe.getStringValue();
+       }
+
+       public String getObjectType() {
+               return FOLDER_ITEM_TYPE;
+       }
+
+       public boolean getNeedsProgressMonitor() {
+               return true;
+       }
+
+       // Dummy methods : useless in RCP context but useful for RAP
+       /** WARNING : always return null in RCP context */
+       public String getObjectName() {
+               return null;
+       }
+
+       /** WARNING : do nothing in RCP context */
+       public void performFinish() {
+       }
+
+       /** WARNING : always return null in RCP context */
+       public InputStream getFileInputStream() {
+               return null;
+       }
+}
\ No newline at end of file
diff --git a/security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties b/security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties
deleted file mode 100644 (file)
index 3557749..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-argeo.osgi.start=\
-com.springsource.javax.servlet,\
-org.eclipse.core.runtime,\
-org.eclipse.equinox.common,\
-org.eclipse.equinox.http.jetty,\
-org.eclipse.equinox.http.registry,\
-org.eclipse.equinox.launcher,\
-org.eclipse.rap.demo,\
-org.mortbay.jetty.server,\
-org.springframework.osgi.extender,\
-org.argeo.server.ads.server,\
-org.argeo.security.manager.ldap,\
-org.argeo.security.services,\
-org.argeo.security.equinox,\
-org.argeo.security.ui,\
-org.argeo.security.ui.rcp,\
-
-eclipse.ignoreApp=true
-osgi.noShutdown=true
-
-log4j.configuration=file:../../log4j.properties
-
-org.eclipse.equinox.http.jetty.log.stderr.threshold=debug
-org.osgi.service.http.port=9090