* added a first PDF Exporter (menu File->Export...)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / export / html / WikiHTMLExporter.java
1 package net.sourceforge.phpeclipse.wiki.export.html;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.FileReader;
7 import java.io.FileWriter;
8 import java.io.IOException;
9 import java.nio.MappedByteBuffer;
10 import java.nio.channels.FileChannel;
11 import java.util.TreeSet;
12
13 import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
14 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
15 import net.sourceforge.phpeclipse.wiki.preferences.Util;
16
17 import org.eclipse.core.resources.IContainer;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IFolder;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IProgressMonitor;
23
24 //import de.java2html.converter.JavaSource2HTMLConverter;
25 //import de.java2html.javasource.JavaSource;
26 //import de.java2html.javasource.JavaSourceParser;
27 //import de.java2html.options.Java2HtmlConversionOptions;
28
29 public final class WikiHTMLExporter {
30
31   public static final String HTML_EXTENSION = ".html";
32
33   public static final String WORKSPACE = "workspace";
34
35   //  private File exportDirectory;
36
37   //    private ExportLinkMaker exportLinkMaker;
38   private TreeSet index;
39
40   public WikiHTMLExporter() {
41     //        exportLinkMaker = new ExportLinkMaker();
42     index = new TreeSet(String.CASE_INSENSITIVE_ORDER);
43   }
44
45   public void export(IContainer folder, String exportDirectoryName, String srcBasePath, IProgressMonitor monitor) throws IOException, CoreException,
46       InstantiationException, IllegalAccessException, ClassNotFoundException {
47     //    exportDirectory = new File(exportDirectoryName);
48     IResource[] resources = folder.members(IResource.FILE);
49     String templateFileName = Util.getExportTemplate(folder);
50 //    monitor.beginTask(WikiEditorPlugin.getResourceString("Export.wikiPages"), resources.length + 1);
51     for (int i = 0; i < resources.length; i++) {
52       if (resources[i] instanceof IFile) {
53         monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFile")+resources[i].getLocation());
54         CreatePageAction.createPage(templateFileName, (IFile) resources[i], exportDirectoryName, srcBasePath);
55         monitor.worked(1);
56       } else if (resources[i] instanceof IFolder) {
57         monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFolder")+resources[i].getLocation());
58         export((IFolder) resources[i], exportDirectoryName, srcBasePath, monitor);
59         monitor.worked(1);
60       }
61     }
62   }
63
64   private void copy(File source, File dest) throws IOException {
65     FileChannel in = null;
66     FileChannel out = null;
67     try {
68       in = new FileInputStream(source).getChannel();
69       out = new FileOutputStream(dest).getChannel();
70       long size = in.size();
71       MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
72       out.write(buf);
73     } finally {
74       if (in != null) {
75         in.close();
76       }
77       if (out != null) {
78         out.close();
79       }
80     }
81   }
82
83   private boolean isWikiFile(IResource resource) {
84     return resource instanceof IFile && resource.getFileExtension().equals("wp");
85   }
86
87   //  private File createHtmlFile(String name) {
88   //    return new File(exportDirectory, name + WikiPDFExporter.HTML_EXTENSION);
89   //  }
90 }