* added a first PDF Exporter (menu File->Export...)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / export / html / WikiHTMLExporter.java
diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/html/WikiHTMLExporter.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/html/WikiHTMLExporter.java
new file mode 100644 (file)
index 0000000..a3ea0c6
--- /dev/null
@@ -0,0 +1,90 @@
+package net.sourceforge.phpeclipse.wiki.export.html;
+
+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 WikiHTMLExporter {
+
+  public static final String HTML_EXTENSION = ".html";
+
+  public static final String WORKSPACE = "workspace";
+
+  //  private File exportDirectory;
+
+  //    private ExportLinkMaker exportLinkMaker;
+  private TreeSet index;
+
+  public WikiHTMLExporter() {
+    //        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);
+      }
+    }
+  }
+
+  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 + WikiPDFExporter.HTML_EXTENSION);
+  //  }
+}
\ No newline at end of file