From a99d11e0c2696ff1a4a258adaa94d137440c8d6c Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Fri, 11 Mar 2011 18:42:25 +0000 Subject: [PATCH] + Implementation of file handlers for both RCP & RAP, finalisation. + Use case CSV parser, clean of the test git-svn-id: https://svn.argeo.org/commons/trunk@4288 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../argeo/util/CsvParserParseFileTest.java | 5 - .../eclipse/ui/jcr/utils/JcrFileProvider.java | 80 ++++++---- .../ui/jcr/views/GenericJcrBrowser.java | 73 ++------- .../jcr/wizards/ImportFileSystemWizard.java | 15 +- .../eclipse/ui/specific/FileHandler.java | 143 ++---------------- .../eclipse/ui/specific/FileProvider.java | 3 + .../ui/specific/ImportFileSystemHandler.java | 7 - ...age.java => ImportToServerWizardPage.java} | 19 ++- .../eclipse/ui/specific/FileHandler.java | 38 ++--- .../eclipse/ui/specific/FileProvider.java | 4 + .../ui/specific/ImportFileSystemHandler.java | 10 -- ...age.java => ImportToServerWizardPage.java} | 20 ++- .../argeo_security_rap.properties | 24 --- 13 files changed, 132 insertions(+), 309 deletions(-) delete mode 100644 eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java rename eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/{ImportFileSystemWizardPage.java => ImportToServerWizardPage.java} (80%) delete mode 100644 eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java rename eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/{ImportFileSystemWizardPage.java => ImportToServerWizardPage.java} (73%) delete mode 100644 security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties diff --git a/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java b/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java index 811758a13..f703d54ee 100644 --- a/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java +++ b/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/CsvParserParseFileTest.java @@ -22,11 +22,6 @@ public class CsvParserParseFileTest extends TestCase { parser.parse(in); in.close(); - for (Integer i : lines.keySet()) { - Map curLine = lines.get(i); - System.out.println("i : " + i.toString() + " - ID :" - + curLine.get("ID")); - } assertEquals(5, lines.size()); } diff --git a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java index f8de5f3b5..6cf4d29c5 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java @@ -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); } } diff --git a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/views/GenericJcrBrowser.java b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/views/GenericJcrBrowser.java index cf7092315..4685fbb21 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/views/GenericJcrBrowser.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/views/GenericJcrBrowser.java @@ -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); } - } - } }); diff --git a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/wizards/ImportFileSystemWizard.java b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/wizards/ImportFileSystemWizard.java index e52fa6768..bbc20fe70 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/wizards/ImportFileSystemWizard.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/wizards/ImportFileSystemWizard.java @@ -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; diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java index 289cd2b90..f873f1a52 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java @@ -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()); diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java index ba4946d8f..c63088bc9 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java @@ -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 index 607d113d9..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java +++ /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/ImportToServerWizardPage.java similarity index 80% rename from eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java rename to eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java index e0a008991..5a1669cbe 100644 --- 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/ImportToServerWizardPage.java @@ -13,14 +13,18 @@ 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); +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 ImportFileSystemWizardPage() { + public ImportToServerWizardPage() { super("Import from file system"); - setDescription("Import files from the local file system into the JCR repository"); + setDescription("Import files from the local file system to the server"); } public void createControl(Composite parent) { @@ -48,7 +52,7 @@ public class ImportFileSystemWizardPage extends WizardPage { } public String getObjectType() { - return "nt:file"; + return FILE_ITEM_TYPE; } public void performFinish() { @@ -64,4 +68,9 @@ public class ImportFileSystemWizardPage extends WizardPage { public InputStream getFileInputStream() { return uploadFile.getUploadItem().getFileInputStream(); } + + public boolean getNeedsProgressMonitor() { + return false; + } + } diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java index e9d7d23d4..53285b4f0 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java @@ -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; } - } diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java index ba4946d8f..d12d3d790 100644 --- a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java +++ b/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java @@ -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 index 0316c3950..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemHandler.java +++ /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/ImportToServerWizardPage.java similarity index 73% rename from eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportFileSystemWizardPage.java rename to eclipse/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java index 27f081172..e37fb9155 100644 --- 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/ImportToServerWizardPage.java @@ -6,10 +6,14 @@ import org.eclipse.jface.preference.DirectoryFieldEditor; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.widgets.Composite; -public class ImportFileSystemWizardPage extends WizardPage { +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 ImportFileSystemWizardPage() { + public ImportToServerWizardPage() { super("Import from file system"); setDescription("Import files from the local file system into the JCR repository"); } @@ -20,12 +24,15 @@ public class ImportFileSystemWizardPage extends WizardPage { } public String getObjectPath() { - System.out.println("dfe.getStringValue() : " + dfe.getStringValue()); return dfe.getStringValue(); } public String getObjectType() { - return "nt:folder"; + return FOLDER_ITEM_TYPE; + } + + public boolean getNeedsProgressMonitor() { + return true; } // Dummy methods : useless in RCP context but useful for RAP @@ -34,7 +41,7 @@ public class ImportFileSystemWizardPage extends WizardPage { return null; } - /** WARNING : di nothing in RCP context */ + /** WARNING : do nothing in RCP context */ public void performFinish() { } @@ -42,5 +49,4 @@ public class ImportFileSystemWizardPage extends WizardPage { 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 index 355774942..000000000 --- a/security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties +++ /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 -- 2.30.2