+++ /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
+++ /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 net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.preference.StringFieldEditor;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.dialogs.ContainerSelectionDialog;
-
-public final class WikiExportWizardPage extends WizardPage implements IPropertyChangeListener, SelectionListener {
- private StringFieldEditor folderText;
-
- private StringFieldEditor exportDirectoryText;
-
- private ISelection selection;
-
- public WikiExportWizardPage(ISelection selection) {
- super(WikiEditorPlugin.getResourceString("Export.wizardTitle"));
- setTitle(WikiEditorPlugin.getResourceString("Export.wizardTitle"));
- setDescription(WikiEditorPlugin.getResourceString("Export.wizardDescription"));
- this.selection = selection;
- }
-
- public void createControl(Composite parent) {
- Composite rootComposite = createControlsContainer(parent);
-
- try {
- initialize();
- } catch (RuntimeException rex) {
- throw rex;
- } catch (CoreException cex) {
- WikiEditorPlugin.getDefault().log("", cex);
- throw new RuntimeException("Caught CoreException. See log for details.");
- }
- dialogChanged();
- setControl(rootComposite);
- }
-
- private Composite createControlsContainer(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- layout.verticalSpacing = 20;
- container.setLayout(layout);
- container.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
-
- createCommonControls(container);
- return container;
- }
-
- private void createCommonControls(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- layout.numColumns = 3;
- layout.verticalSpacing = 9;
- container.setLayout(layout);
- container.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
-
- createFolderControls(container);
- createExportDirectoryControls(container);
- }
-
- private void createExportDirectoryControls(Composite container) {
- exportDirectoryText = addStringFieldEditor(container, WikiEditorPlugin.getResourceString("Export.wizardExportDirectory"));
-
- Button button = new Button(container, SWT.PUSH);
- button.setText(WikiEditorPlugin.getResourceString("Export.wizardBrowse"));
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- handleBrowseHtmlExportLocation();
- }
- });
- }
-
- private void createFolderControls(Composite container) {
- folderText = addStringFieldEditor(container, WikiEditorPlugin.getResourceString("Export.wizardFolder"));
-
- Button button = new Button(container, SWT.PUSH);
- button.setText(WikiEditorPlugin.getResourceString("Export.wizardBrowse"));
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- try {
- handleBrowseFolders();
- } catch (CoreException cex) {
- WikiEditorPlugin.getDefault().log("", cex);
- throw new RuntimeException("Caught CoreException. See log for details.");
- }
- }
- });
- }
-
- private StringFieldEditor addStringFieldEditor(Composite container, String labelText) {
- Label label = new Label(container, SWT.NULL);
- label.setText(labelText);
-
- Composite editorComposite = new Composite(container, SWT.NULL);
- editorComposite.setLayout(new GridLayout());
- editorComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
- StringFieldEditor editor = new StringFieldEditor("", "", editorComposite);
-
- editor.setPropertyChangeListener(this);
-
- return editor;
- }
-
- private void initialize() throws CoreException {
- if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
- return;
- }
-
- IStructuredSelection ssel = (IStructuredSelection) selection;
- if (ssel.size() == 1) {
- initialiseFromSelectedObject(ssel.getFirstElement());
- }
- }
-
- private void initialiseFromSelectedObject(Object obj) throws CoreException {
- if (obj instanceof IFolder || obj instanceof IProject) {
- initialiseFolder(((IResource) obj));
- }
- }
-
- private void initialiseFolder(IResource resource) throws CoreException {
- folderText.setStringValue(resource.getFullPath().toString());
- initialiseExportDirectoryText(resource);
- }
-
- private void initialiseExportDirectoryText(IResource resource) throws CoreException {
- String exportDir = resource.getProject().getPersistentProperty(WikiExportWizard.DIRECTORY_QUALIFIED_NAME);
- if (exportDir != null) {
- exportDirectoryText.setStringValue(exportDir);
- } else {
- exportDirectoryText.setStringValue("");
- }
- }
-
- private void handleBrowseHtmlExportLocation() {
- DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SINGLE | SWT.OPEN);
- String path = dialog.open();
- if (path != null) {
- exportDirectoryText.setStringValue(path);
- }
- }
-
- private void handleBrowseFolders() throws CoreException {
- ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
- WikiEditorPlugin.getResourceString("Export.wizardSelectFolder"));
- if (dialog.open() == Window.OK) {
- Object[] result = dialog.getResult();
- if (result != null && result.length == 1) {
- IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) result[0]);
- if (resource instanceof IFile) {
- return;
- }
- initialiseFolder(resource);
- }
- }
- }
-
- private void dialogChanged() {
- if (getFolderText().length() == 0) {
- updateStatus("Folder must be specified");
- } else if (getExportDirectoryPath().length() == 0) {
- updateStatus("Directory must be specified");
- } else {
- updateStatus(null);
- }
- }
-
- private void updateStatus(String message) {
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-
- public String getExportDirectoryPath() {
- return exportDirectoryText.getStringValue();
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- dialogChanged();
- }
-
- public void widgetSelected(SelectionEvent e) {
- dialogChanged();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- dialogChanged();
- }
-
- String getFolderText() {
- return folderText.getStringValue();
- }
-
- public IContainer getFolder() {
- return (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getFolderText()));
- }
-}
\ No newline at end of file
+++ /dev/null
-package net.sourceforge.phpeclipse.wiki.export;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.util.TreeSet;
-
-import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
-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.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-//import de.java2html.converter.JavaSource2HTMLConverter;
-//import de.java2html.javasource.JavaSource;
-//import de.java2html.javasource.JavaSourceParser;
-//import de.java2html.options.Java2HtmlConversionOptions;
-
-public final class WikiExporter {
-
- public static final String HTML_EXTENSION = ".html";
-
- public static final String WORKSPACE = "workspace";
-
- // private File exportDirectory;
-
- // private ExportLinkMaker exportLinkMaker;
- private TreeSet index;
-
- public WikiExporter() {
- // exportLinkMaker = new ExportLinkMaker();
- index = new TreeSet(String.CASE_INSENSITIVE_ORDER);
- }
-
- public void export(IContainer folder, String exportDirectoryName, String srcBasePath, IProgressMonitor monitor) throws IOException, CoreException,
- InstantiationException, IllegalAccessException, ClassNotFoundException {
- // exportDirectory = new File(exportDirectoryName);
- IResource[] resources = folder.members(IResource.FILE);
- String templateFileName = Util.getExportTemplate(folder);
-// monitor.beginTask(WikiEditorPlugin.getResourceString("Export.wikiPages"), resources.length + 1);
- for (int i = 0; i < resources.length; i++) {
- if (resources[i] instanceof IFile) {
- monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFile")+resources[i].getLocation());
- CreatePageAction.createPage(templateFileName, (IFile) resources[i], exportDirectoryName, srcBasePath);
- monitor.worked(1);
- } else if (resources[i] instanceof IFolder) {
- monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFolder")+resources[i].getLocation());
- export((IFolder) resources[i], exportDirectoryName, srcBasePath, monitor);
- monitor.worked(1);
- }
- }
- // monitor.subTask(WikiEditorPlugin.getResourceString("Export.linkedResources"));
- // exportLinkedResources();
- // createIndex();
-// monitor.worked(1);
- }
-
- /**
- * TODO: This is a horrible hack for a quick solution.
- */
- // private void createIndex() throws IOException {
- // File indexFile = createHtmlFile("index");
- //
- // PrintWriter writer = new PrintWriter(new FileWriter(indexFile));
- // writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- // writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
- // writer.println("<html>");
- // writer.println(" <head>");
- // writer.print(" <title>Index</title>");
- // writer.println(" </head>");
- // writer.println(" <body>");
- //
- // Iterator iterator = index.iterator();
- // while (iterator.hasNext()) {
- // String name = (String) iterator.next();
- // writer.print(" <br/>");
- // writer.println("<a href=\"" + name + ".html\">" + name + "</a>");
- // }
- //
- // writer.println(" </body>");
- // writer.println(" </html>");
- // writer.flush();
- // writer.close();
- // }
- // private void exportLinkedResources() throws IOException {
- // if (!exportLinkMaker.hasLinkedDocuments()) {
- // return;
- // }
- // File workspaceExport = new File(exportDirectory, WikiExporter.WORKSPACE);
- // if (!workspaceExport.exists()) {
- // workspaceExport.mkdir();
- // }
- // HashMap map = exportLinkMaker.getLinkedResources();
- // Iterator iterator = map.keySet().iterator();
- // while (iterator.hasNext()) {
- // IResource resource = (IResource) iterator.next();
- // String location = (String) map.get(resource);
- // export(resource, location);
- // }
- // }
- // private void export(IResource resource, String location) throws IOException {
- // File destination = new File(exportDirectory, location);
- //
- // if (destination.isDirectory()) {
- // return;
- // }
- // if (!destination.exists()) {
- // destination.getParentFile().mkdirs();
- // }
- // File source = new File(resource.getLocation().toString());
- // if (isJavaResource(resource)) {
- // javaToHtml(source, new File(destination.getParentFile(), destination.getName()));
- // } else {
- // copy(source, destination);
- // }
- // }
- private boolean isJavaResource(IResource resource) {
- return "java".equals(resource.getFileExtension());
- }
-
-// private void javaToHtml(File source, File destination) throws IOException {
-// JavaSource java = new JavaSourceParser().parse(new FileReader(source));
-// JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter(java);
-// Java2HtmlConversionOptions options = Java2HtmlConversionOptions.getDefault();
-// options.setShowLineNumbers(true);
-// options.setShowFileName(true);
-// options.setShowJava2HtmlLink(true);
-// converter.setConversionOptions(options);
-// FileWriter writer = new FileWriter(destination);
-// converter.convert(writer);
-// writer.flush();
-// writer.close();
-// }
-
- private void copy(File source, File dest) throws IOException {
- FileChannel in = null;
- FileChannel out = null;
- try {
- in = new FileInputStream(source).getChannel();
- out = new FileOutputStream(dest).getChannel();
- long size = in.size();
- MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
- out.write(buf);
- } finally {
- if (in != null) {
- in.close();
- }
- if (out != null) {
- out.close();
- }
- }
- }
-
- private boolean isWikiFile(IResource resource) {
- return resource instanceof IFile && resource.getFileExtension().equals("wp");
- }
-
- // private File createHtmlFile(String name) {
- // return new File(exportDirectory, name + WikiExporter.HTML_EXTENSION);
- // }
-}
\ No newline at end of file