X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui.workbench%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fworkbench%2Finternal%2Fjcr%2Fcommands%2FDumpNode.java;h=ae23f1d542c5dd1caa9f8cb31ac3c4a6d4a6a66a;hb=5b444174cd13680f99944026877f6cac2e1faba1;hp=2414f042b95ae830e3391cce3ef868919de65b91;hpb=23b7a170cae60b500e9d45551f26b5075eba73a4;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/DumpNode.java b/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/DumpNode.java index 2414f042b..ae23f1d54 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/DumpNode.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/DumpNode.java @@ -15,6 +15,9 @@ */ package org.argeo.cms.ui.workbench.internal.jcr.commands; +import static org.argeo.eclipse.ui.utils.SingleSourcingConstants.FILE_SCHEME; +import static org.argeo.eclipse.ui.utils.SingleSourcingConstants.SCHEME_HOST_SEPARATOR; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -27,13 +30,12 @@ import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; -import javax.jcr.Session; +import org.argeo.cms.ui.jcr.model.SingleJcrNodeElem; import org.argeo.cms.ui.workbench.WorkbenchUiPlugin; -import org.argeo.cms.ui.workbench.commands.OpenFile; -import org.argeo.cms.ui.workbench.internal.jcr.model.SingleJcrNodeElem; import org.argeo.cms.ui.workbench.util.CommandUtils; import org.argeo.eclipse.ui.EclipseUiException; +import org.argeo.eclipse.ui.specific.OpenFile; import org.argeo.jcr.JcrUtils; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -43,10 +45,10 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.handlers.HandlerUtil; /** - * Canonically call JCR {@link Session#exportSystemView()} on the first element - * returned by {@link HandlerUtil#getActiveWorkbenchWindow()} + * Canonically call JCR Session#exportSystemView() on the first element returned + * by HandlerUtil#getActiveWorkbenchWindow() * (...getActivePage().getSelection()), if it is a {@link SingleJcrNodeElem}, - * with both skipBinary & noRecurse boolean flags set to false. + * with both skipBinary and noRecurse boolean flags set to false. * * Resulting stream is saved in a tmp file and opened via the {@link OpenFile} * single-sourced command. @@ -54,12 +56,10 @@ import org.eclipse.ui.handlers.HandlerUtil; public class DumpNode extends AbstractHandler { public final static String ID = WorkbenchUiPlugin.PLUGIN_ID + ".dumpNode"; - private final static DateFormat df = new SimpleDateFormat( - "yyyy-MM-dd_HH-mm"); + private final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); public Object execute(ExecutionEvent event) throws ExecutionException { - ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event) - .getActivePage().getSelection(); + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); if (selection == null || !(selection instanceof IStructuredSelection)) return null; @@ -73,8 +73,8 @@ public class DumpNode extends AbstractHandler { // TODO add a dialog to configure the export and ask for // confirmation // Boolean ok = MessageDialog.openConfirm( - // HandlerUtil.getActiveShell(event), "Confirm deletion", - // "Do you want to delete " + buf + "?"); + // HandlerUtil.getActiveShell(event), "Confirm dump", + // "Do you want to dump " + buf + "?"); File tmpFile; FileOutputStream fos; @@ -82,19 +82,14 @@ public class DumpNode extends AbstractHandler { tmpFile = File.createTempFile("JcrExport", ".xml"); tmpFile.deleteOnExit(); fos = new FileOutputStream(tmpFile); - String dateVal = df.format(new GregorianCalendar() - .getTime()); - node.getSession().exportSystemView(node.getPath(), fos, - true, false); - openGeneratedFile(tmpFile.getAbsolutePath(), "Dump-" - + JcrUtils.replaceInvalidChars(node.getName()) - + "-" + dateVal + ".xml"); + String dateVal = df.format(new GregorianCalendar().getTime()); + node.getSession().exportSystemView(node.getPath(), fos, true, false); + openGeneratedFile(tmpFile.getAbsolutePath(), + "Dump-" + JcrUtils.replaceInvalidChars(node.getName()) + "-" + dateVal + ".xml"); } catch (RepositoryException e) { - throw new EclipseUiException( - "Unable to perform SystemExport on " + node, e); + throw new EclipseUiException("Unable to perform SystemExport on " + node, e); } catch (IOException e) { - throw new EclipseUiException("Unable to SystemExport " - + node, e); + throw new EclipseUiException("Unable to SystemExport " + node, e); } } } @@ -104,7 +99,7 @@ public class DumpNode extends AbstractHandler { private synchronized void openGeneratedFile(String path, String fileName) { Map params = new HashMap(); params.put(OpenFile.PARAM_FILE_NAME, fileName); - params.put(OpenFile.PARAM_FILE_URI, "file://" + path); + params.put(OpenFile.PARAM_FILE_URI, FILE_SCHEME + SCHEME_HOST_SEPARATOR + path); CommandUtils.callCommand(OpenFile.ID, params); } }