name="Delete nodes">
</command>
<command
- defaultHandler="org.argeo.cms.ui.workbench.internal.jcr.commands.ImportFileSystem"
- id="org.argeo.cms.ui.workbench.importFileSystem"
- name="Import files...">
+ defaultHandler="org.argeo.cms.ui.workbench.internal.jcr.commands.UploadFiles"
+ id="org.argeo.cms.ui.workbench.uploadFiles"
+ name="Upload files">
</command>
<!-- <command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
</visibleWhen>
</command>
<command
- commandId="org.argeo.cms.ui.workbench.importFileSystem"
+ commandId="org.argeo.cms.ui.workbench.uploadFiles"
icon="icons/import_fs.png"
style="push"
- tooltip="Import files from the files sytem">
+ tooltip="Upload files from the local file sytem">
<visibleWhen>
<iterate>
<and>
*
* <p>
* The parameter "URI" is used to determine the correct file service, the path
- * and the file name. An optional file name can be precized to present a
+ * and the file name. An optional file name can be precised to present a
* different file name as the one used to retrieve it to the end user.
* </p>
*
*/
public class OpenFile extends AbstractHandler {
// private final static Log log = LogFactory.getLog(OpenFile.class);
-
- /* DEPENDENCY INJECTION */
- private String openFileServiceId;
-
public final static String ID = WorkbenchUiPlugin.PLUGIN_ID + ".openFile";
+
public final static String PARAM_FILE_NAME = OpenFileService.PARAM_FILE_NAME;
public final static String PARAM_FILE_URI = OpenFileService.PARAM_FILE_URI; // "param.fileURI";
+ /* DEPENDENCY INJECTION */
+ private String openFileServiceId;
public Object execute(ExecutionEvent event) throws ExecutionException {
*/
package org.argeo.cms.ui.workbench.internal.jcr;
+import static javax.jcr.Node.JCR_CONTENT;
+import static javax.jcr.Property.JCR_DATA;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
+import org.apache.commons.io.IOUtils;
import org.argeo.cms.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.cms.ui.workbench.commands.OpenFile;
import org.argeo.cms.ui.workbench.internal.jcr.model.RepositoryElem;
import org.argeo.cms.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
import org.argeo.cms.ui.workbench.internal.jcr.model.WorkspaceElem;
import org.argeo.cms.ui.workbench.internal.jcr.parts.GenericNodeEditorInput;
import org.argeo.cms.ui.workbench.jcr.DefaultNodeEditor;
+import org.argeo.cms.ui.workbench.util.CommandUtils;
import org.argeo.eclipse.ui.EclipseUiException;
+import org.argeo.eclipse.ui.specific.SingleSourcingException;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
public void doubleClick(DoubleClickEvent event) {
if (event.getSelection() == null || event.getSelection().isEmpty())
return;
- Object obj = ((IStructuredSelection) event.getSelection())
- .getFirstElement();
+ Object obj = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (obj instanceof RepositoryElem) {
RepositoryElem rpNode = (RepositoryElem) obj;
if (!rpNode.isConnected()) {
Node node = sjn.getNode();
try {
if (node.isNodeType(NodeType.NT_FILE)) {
- // double click on a file node triggers its opening
- // String name = node.getName();
- // String id = node.getIdentifier();
+ // Also open it
+
+ String name = node.getName();
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(OpenFile.PARAM_FILE_NAME, name);
- // TODO add integration of direct retrieval of the binary in
- // a JCR repo.
- // Map<String, String> params = new HashMap<String,
- // String>();
- // params.put(OpenFile.PARAM_FILE_NAME, name);
- // params.put(OpenFile.PARAM_FILE_URI, "jcr://" + id);
- // CommandUtils
- // .callCommand("org.argeo.security.ui.specific.openFile",
- // params);
+ // TODO rather directly transmit the path to the node, once
+ // we have defined convention to provide an Absolute URI to
+ // a node in a multi repo / workspace / user context
+ // params.put(OpenFile.PARAM_FILE_URI,
+ // OpenFileService.JCR_SCHEME + node.getPath());
- // For the file provider to be able to browse the
- // various
- // repository.
- // TODO : enhanced that.
- // ITreeContentProvider itcp = (ITreeContentProvider)
- // nodeViewer
- // .getContentProvider();
- // jfp.setReferenceNode(node);
- // if (fileHandler != null)
- // fileHandler.openFile(name, id);
+ // we copy the node to a tmp file to be opened as a dirty
+ // workaround
+ File tmpFile = null;
+ OutputStream os = null;
+ InputStream is = null;
+ int i = name.lastIndexOf('.');
+ String prefix, suffix;
+ if (i == -1) {
+ prefix = name;
+ suffix = null;
+ } else {
+ prefix = name.substring(0, i);
+ suffix = name.substring(i);
+ }
+ try {
+ tmpFile = File.createTempFile(prefix, suffix);
+ tmpFile.deleteOnExit();
+ os = new FileOutputStream(tmpFile);
+ Binary binary = node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary();
+ is = binary.getStream();
+ IOUtils.copy(is, os);
+ } catch (IOException e) {
+ throw new SingleSourcingException("Cannot open file " + prefix + "." + suffix, e);
+ } finally {
+ IOUtils.closeQuietly(is);
+ IOUtils.closeQuietly(os);
+ }
+ Path path = Paths.get(tmpFile.getAbsolutePath());
+ String uri = path.toUri().toString();
+ params.put(OpenFile.PARAM_FILE_URI, uri);
+ CommandUtils.callCommand(OpenFile.ID, params);
}
GenericNodeEditorInput gnei = new GenericNodeEditorInput(node);
- WorkbenchUiPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage()
+ WorkbenchUiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
.openEditor(gnei, DefaultNodeEditor.ID);
} catch (RepositoryException re) {
- throw new EclipseUiException(
- "Repository error while getting node info", re);
+ throw new EclipseUiException("Repository error while getting node info", re);
} catch (PartInitException pie) {
- throw new EclipseUiException(
- "Unexepected exception while opening node editor", pie);
+ throw new EclipseUiException("Unexepected exception while opening node editor", pie);
}
}
}
Node rootNode = (Node) inputElement;
List<Node> result = new ArrayList<Node>();
NodeIterator ni = rootNode.getNodes();
- while (ni.hasNext()) {
+ while (ni.hasNext())
result.add(ni.nextNode());
- }
-
return result.toArray();
} catch (RepositoryException re) {
- throw new EclipseUiException(
- "Unexpected error while getting child nodes for children editor page ",
- re);
+ throw new EclipseUiException("Unable to retrieve elements for " + inputElement, re);
}
}
try {
return ((Node) element).hasNodes();
} catch (RepositoryException e) {
- throw new EclipseUiException("Cannot check children of " + element, e);
+ throw new EclipseUiException("Cannot check children existence on " + element, e);
}
}
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
protected Object[] childrenNodes(Node parentNode) {
try {
List<Node> children = new ArrayList<Node>();
NodeIterator nit = parentNode.getNodes();
- while (nit.hasNext()) {
- Node node = nit.nextNode();
- children.add(node);
- }
- Node[] arr = children.toArray(new Node[children.size()]);
+ while (nit.hasNext())
+ children.add(nit.nextNode());
+ Node[] arr = children.toArray(new Node[0]);
Arrays.sort(arr, itemComparator);
return arr;
} catch (RepositoryException e) {
throw new EclipseUiException("Cannot list children of " + parentNode, e);
}
}
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.cms.ui.workbench.internal.jcr.commands;
-
-import javax.jcr.Node;
-
-import org.argeo.cms.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.cms.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
-import org.argeo.cms.ui.workbench.internal.jcr.model.WorkspaceElem;
-import org.argeo.cms.ui.workbench.internal.jcr.parts.ImportFileSystemWizard;
-import org.argeo.cms.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/** Import a local file system directory tree. */
-public class ImportFileSystem extends AbstractHandler {
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
- .getActivePage().getSelection();
- JcrBrowserView view = (JcrBrowserView) HandlerUtil
- .getActiveWorkbenchWindow(event).getActivePage()
- .findView(HandlerUtil.getActivePartId(event));
- if (selection != null && !selection.isEmpty()
- && selection instanceof IStructuredSelection) {
- Object obj = ((IStructuredSelection) selection).getFirstElement();
- try {
- Node folder = null;
- if (obj instanceof SingleJcrNodeElem) {
- folder = ((SingleJcrNodeElem) obj).getNode();
- } else if (obj instanceof WorkspaceElem) {
- folder = ((WorkspaceElem) obj).getRootNode();
- } else {
- ErrorFeedback.show(WorkbenchUiPlugin
- .getMessage("warningInvalidNodeToImport"));
- }
- if (folder != null) {
- ImportFileSystemWizard wizard = new ImportFileSystemWizard(
- folder);
- WizardDialog dialog = new WizardDialog(
- HandlerUtil.getActiveShell(event), wizard);
- dialog.open();
- view.nodeAdded((TreeParent) obj);
- }
- } catch (Exception e) {
- ErrorFeedback.show("Cannot import files to " + obj, e);
- }
- }
- return null;
- }
-}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.cms.ui.workbench.internal.jcr.commands;
+
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.cms.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.cms.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.cms.ui.workbench.internal.jcr.model.WorkspaceElem;
+import org.argeo.cms.ui.workbench.jcr.JcrBrowserView;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Upload local file(s) under the currently selected node */
+public class UploadFiles extends AbstractHandler {
+ // private final static Log log = LogFactory.getLog(ImportFileSystem.class);
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
+ JcrBrowserView view = (JcrBrowserView) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
+ .findView(HandlerUtil.getActivePartId(event));
+ if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+ try {
+ Node folder = null;
+ if (obj instanceof SingleJcrNodeElem) {
+ folder = ((SingleJcrNodeElem) obj).getNode();
+ } else if (obj instanceof WorkspaceElem) {
+ folder = ((WorkspaceElem) obj).getRootNode();
+ } else {
+ ErrorFeedback.show(WorkbenchUiPlugin.getMessage("warningInvalidNodeToImport"));
+ }
+ if (folder != null) {
+ FileDialog dialog = new FileDialog(HandlerUtil.getActiveShell(event), SWT.MULTI);
+ dialog.setText("Choose one or more files to upload");
+
+ if (EclipseUiUtils.notEmpty(dialog.open())) {
+ String[] names = dialog.getFileNames();
+ // Workaround small differences between RAP and RCP
+ // 1. returned names are absolute path on RAP and
+ // relative in RCP
+ // 2. in RCP we must use getFilterPath that does not
+ // exists on RAP
+ Method filterMethod = null;
+ Path parPath = null;
+
+ try {
+ filterMethod = dialog.getClass().getDeclaredMethod("getFilterPath");
+ String filterPath = (String) filterMethod.invoke(dialog);
+ parPath = Paths.get(filterPath);
+ } catch (NoSuchMethodException nsme) { // RAP
+ }
+ if (names.length == 0)
+ return null;
+ else {
+ loop: for (String name : names) {
+ Path path = Paths.get(name);
+ if (parPath != null)
+ path = parPath.resolve(path);
+ if (Files.exists(path)) {
+ URI uri = path.toUri();
+ String uriStr = uri.toString();
+ System.out.println(uriStr);
+
+ if (Files.isDirectory(path)) {
+ MessageDialog.openError(HandlerUtil.getActiveShell(event),
+ "Unimplemented directory import",
+ "Upload of directories in the system is not yet implemented");
+ continue loop;
+ }
+ Node fileNode = folder.addNode(path.getFileName().toString(), NodeType.NT_FILE);
+ Node resNode = fileNode.addNode(Property.JCR_CONTENT, NodeType.NT_RESOURCE);
+ Binary binary = null;
+ try (InputStream is = Files.newInputStream(path)) {
+ binary = folder.getSession().getValueFactory().createBinary(is);
+ resNode.setProperty(Property.JCR_DATA, binary);
+ }
+ folder.getSession().save();
+ } else {
+ String msg = "Cannot upload file at " + path.toString();
+ if (parPath != null)
+ msg += "\nPlease remember that file upload fails when choosing files from the \"Recently Used\" bookmarks on some OS";
+ MessageDialog.openError(HandlerUtil.getActiveShell(event), "Missing file", msg);
+ continue loop;
+ }
+ }
+ view.nodeAdded((TreeParent) obj);
+ return true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ ErrorFeedback.show("Cannot import files to " + obj, e);
+ }
+ }
+ return null;
+ }
+}
import java.io.File;
import java.io.FileInputStream;
-import java.io.InputStream;
import javax.jcr.Binary;
import javax.jcr.Node;
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.cms.CmsException;
import org.argeo.eclipse.ui.EclipseUiException;
-import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.eclipse.ui.specific.UploadFileWizardPage;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
public class ImportFileSystemWizard extends Wizard {
- private final static Log log = LogFactory
- .getLog(ImportFileSystemWizard.class);
+ private final static Log log = LogFactory.getLog(ImportFileSystemWizard.class);
private UploadFileWizardPage importPage;
private final Node folder;
public ImportFileSystemWizard(Node folder) {
this.folder = folder;
setWindowTitle("Import from file system");
+ throw new CmsException("Deprecated wizard, cannot be used");
}
@Override
public void addPages() {
- importPage = new UploadFileWizardPage();
- addPage(importPage);
- setNeedsProgressMonitor(importPage.getNeedsProgressMonitor());
+ // importPage = new UploadFileWizardPage();
+ // addPage(importPage);
+ // setNeedsProgressMonitor(importPage.getNeedsProgressMonitor());
}
/**
@Override
public boolean performFinish() {
- // Initialization
- final String objectType = importPage.getObjectType();
- final String objectPath = importPage.getObjectPath();
-
- // We do not display a progress bar for one file only
- if (UploadFileWizardPage.FILE_ITEM_TYPE.equals(objectType)) {
- // In Rap we must force the "real" upload of the file
- // importPage.performFinish();
- try {
- Node fileNode = folder.addNode(importPage.getObjectName(),
- NodeType.NT_FILE);
- Node resNode = fileNode.addNode(Property.JCR_CONTENT,
- NodeType.NT_RESOURCE);
- Binary binary = null;
- InputStream is = null;
- try {
- is = importPage.getFileInputStream();
- binary = folder.getSession().getValueFactory()
- .createBinary(is);
- resNode.setProperty(Property.JCR_DATA, binary);
- } finally {
- if (binary != null)
- binary.dispose();
- IOUtils.closeQuietly(is);
- }
- folder.getSession().save();
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return true;
- } else if (UploadFileWizardPage.FOLDER_ITEM_TYPE.equals(objectType)) {
- if (objectPath == null || !new File(objectPath).exists()) {
- ErrorFeedback.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 EclipseUiException("Cannot import "
- + objectPath, e);
- }
- }
- });
- } catch (Exception e) {
- ErrorFeedback.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;
- }
+ // // Initialization
+ // final String objectType = importPage.getObjectType();
+ // final String objectPath = importPage.getObjectPath();
+ //
+ // // We do not display a progress bar for one file only
+ // if (UploadFileWizardPage.FILE_ITEM_TYPE.equals(objectType)) {
+ // // In Rap we must force the "real" upload of the file
+ // // importPage.performFinish();
+ // try {
+ // Node fileNode = folder.addNode(importPage.getObjectName(),
+ // NodeType.NT_FILE);
+ // Node resNode = fileNode.addNode(Property.JCR_CONTENT,
+ // NodeType.NT_RESOURCE);
+ // Binary binary = null;
+ // InputStream is = null;
+ // try {
+ // is = importPage.getFileInputStream();
+ // binary = folder.getSession().getValueFactory()
+ // .createBinary(is);
+ // resNode.setProperty(Property.JCR_DATA, binary);
+ // } finally {
+ // if (binary != null)
+ // binary.dispose();
+ // IOUtils.closeQuietly(is);
+ // }
+ // folder.getSession().save();
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // return false;
+ // }
+ // return true;
+ // } else if (UploadFileWizardPage.FOLDER_ITEM_TYPE.equals(objectType))
+ // {
+ // if (objectPath == null || !new File(objectPath).exists()) {
+ // ErrorFeedback.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 EclipseUiException("Cannot import "
+ // + objectPath, e);
+ // }
+ // }
+ // });
+ // } catch (Exception e) {
+ // ErrorFeedback.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;
}
/**
* Import recursively a directory and its content to the repository.
*/
- protected void importDirectory(Node folder, File dir,
- IProgressMonitor monitor, Stats stats) {
+ protected void importDirectory(Node folder, File dir, IProgressMonitor monitor, Stats stats) {
try {
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
- Node childFolder = folder.addNode(file.getName(),
- NodeType.NT_FOLDER);
+ Node childFolder = folder.addNode(file.getName(), NodeType.NT_FOLDER);
importDirectory(childFolder, file, monitor, stats);
folder.getSession().save();
stats.dirCount++;
// we skip temporary files that are created by apps when a
// file is being edited.
// TODO : make this configurable.
- if (file.getName().lastIndexOf('~') != file.getName()
- .length() - 1) {
+ if (file.getName().lastIndexOf('~') != file.getName().length() - 1) {
- monitor.subTask(file.getName() + " ("
- + FileUtils.byteCountToDisplaySize(fileSize)
- + ") " + file.getCanonicalPath());
+ 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);
+ 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));
+ binary = folder.getSession().getValueFactory().createBinary(new FileInputStream(file));
resNode.setProperty(Property.JCR_DATA, binary);
} finally {
if (binary != null)
stats.fileCount++;
stats.sizeB = stats.sizeB + fileSize;
} catch (Exception e) {
- log.warn("Import of "
- + file
- + " ("
- + FileUtils
- .byteCountToDisplaySize(fileSize)
+ log.warn("Import of " + file + " (" + FileUtils.byteCountToDisplaySize(fileSize)
+ ") failed: " + e);
folder.getSession().refresh(false);
}
}
}
} catch (Exception e) {
- throw new EclipseUiException("Cannot import " + dir + " to " + folder,
- e);
+ throw new EclipseUiException("Cannot import " + dir + " to " + folder, e);
}
}