--- /dev/null
+/*
+ * Copyright (c) 2002 Team in a Box Ltd. All rights reserved. This file is made available under the terms and conditions of the
+ * Common Public License v 1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/cpl-v1.0.html
+ *
+ * Contributors: Team in a Box Ltd http://www.teaminabox.co.uk/
+ */
+
+package net.sourceforge.phpeclipse.wiki.export;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.preferences.Util;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+public final class WikiExportWizard extends Wizard implements INewWizard {
+ static final QualifiedName DIRECTORY_QUALIFIED_NAME = new QualifiedName(WikiEditorPlugin.PLUGIN_ID, "exportDirectory");
+
+ private WikiExportWizardPage page;
+
+ private ISelection selection;
+
+ public WikiExportWizard() {
+ super();
+ setNeedsProgressMonitor(true);
+ }
+
+ public void addPages() {
+ page = new WikiExportWizardPage(selection);
+ addPage(page);
+ }
+
+ public boolean performFinish() {
+ persistExportProperties();
+
+ final IContainer folder = page.getFolder();
+ final String exportDirectory = page.getExportDirectoryPath();
+
+ return runOperationForContainer(new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ startExport(monitor, folder, exportDirectory);
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ });
+ }
+
+ private boolean runOperationForContainer(IRunnableWithProgress op) {
+ try {
+ getContainer().run(true, true, op);
+ } catch (InterruptedException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ WikiEditorPlugin.getDefault().log("", e);
+ MessageDialog.openError(getShell(), "Error", e.getTargetException().getMessage());
+ return false;
+ }
+
+ return true;
+ }
+
+ private void startExport(IProgressMonitor monitor, IContainer folder, String exportDirectory) throws CoreException {
+ try {
+ final String srcBasePath = Util.getWikiTextsPath(folder);
+ new WikiExporter().export(folder, exportDirectory, srcBasePath, monitor);
+ } catch (Exception ioex) {
+ throw new CoreException(new Status(IStatus.ERROR, "Failed to write Wiki Documents", IStatus.OK, ioex.getMessage(), ioex));
+ }
+ }
+
+ private void persistExportProperties() {
+ IProject project = page.getFolder().getProject();
+ try {
+ project.setPersistentProperty(WikiExportWizard.DIRECTORY_QUALIFIED_NAME, new File(page.getExportDirectoryPath())
+ .getAbsolutePath());
+ } catch (CoreException cex) {
+ noteException(cex);
+ }
+ }
+
+ private void noteException(CoreException cex) {
+ WikiEditorPlugin.getDefault().log("Export Error", cex);
+ throw new RuntimeException("An error occurred. Please see the log for details.");
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ }
+}
\ No newline at end of file