import java.io.IOException;
import java.io.StringWriter;
+import java.util.Properties;
import net.sourceforge.phpeclipse.wiki.builder.BuilderRenderEngine;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
import org.eclipse.core.resources.IProject;
-import org.radeox.api.engine.RenderEngine;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.radeox.api.engine.context.InitialRenderContext;
import org.radeox.engine.context.BaseInitialRenderContext;
import org.radeox.macro.MacroRepository;
}
- protected void appendHeader(String line) {
- String header = getHeaderText(line);
- String headerStartTag = "<h1 " + getHeaderCss(getHeaderSize(line)) + ">";
- getBuffer().append(headerStartTag);
- getBuffer().append(header);
- getBuffer().append("</h1>");
- }
-
- private int getHeaderSize(String line) {
- int size = 0;
- int index = 0;
- while (index < line.length() && line.charAt(index) != ' ') {
- if (line.charAt(index) == '1') {
- size++;
- }
- index++;
- }
- return size;
- }
-
- private String getHeaderCss(int size) {
- int max = Math.min(3, size);
- StringBuffer css = new StringBuffer();
- css.append("class=\"").append("heading");
- for (int i = 0; i < max; i++) {
- css.append("-1");
- }
- css.append("\"");
- return css.toString();
- }
-
- protected String getHeaderText(String line) {
- return line.substring(line.indexOf(' ')).trim();
- }
+// protected void appendHeader(String line) {
+// String header = getHeaderText(line);
+// String headerStartTag = "<h1 " + getHeaderCss(getHeaderSize(line)) + ">";
+// getBuffer().append(headerStartTag);
+// getBuffer().append(header);
+// getBuffer().append("</h1>");
+// }
+
+// private int getHeaderSize(String line) {
+// int size = 0;
+// int index = 0;
+// while (index < line.length() && line.charAt(index) != ' ') {
+// if (line.charAt(index) == '1') {
+// size++;
+// }
+// index++;
+// }
+// return size;
+// }
+//
+// private String getHeaderCss(int size) {
+// int max = Math.min(3, size);
+// StringBuffer css = new StringBuffer();
+// css.append("class=\"").append("heading");
+// for (int i = 0; i < max; i++) {
+// css.append("-1");
+// }
+// css.append("\"");
+// return css.toString();
+// }
+
+// protected String getHeaderText(String line) {
+// return line.substring(line.indexOf(' ')).trim();
+// }
protected int getListDepth(String line) {
char bullet = getBullet(line);
return "<table class=\"wiki-table\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
}
- public final void render(String content, StringBuffer buf, int level, boolean completeHTMLPage) {
+ public final void render(String templateFileName, String content, StringBuffer buf, int level, boolean completeHTMLPage) {
try {
- buffer = buf;
- if (completeHTMLPage) {
- appendHeader();
- }
- StringWriter writer = new StringWriter();
- try {
+ if (templateFileName == null||templateFileName.equals("")) {
+ if (completeHTMLPage) {
+ appendHeader(buf);
+ }
+ StringWriter writer = new StringWriter();
+ try {
+ engine.setLevel(level);
+ engine.render(writer, content, context);
+ buf.append(writer);
+ } catch (IOException e) {
+ // never reach
+ }
+ if (completeHTMLPage) {
+ appendFooter(buf);
+ }
+ } else {
+ StringWriter writer = new StringWriter();
engine.setLevel(level);
engine.render(writer, content, context);
- buffer.append(writer);
- } catch (IOException e) {
- // never reach
- }
- if (completeHTMLPage) {
- appendFooter();
+
+ int index = 0;
+ IPath path = new Path(templateFileName);
+ String fileName = path.toString();
+ String pathName = fileName;
+ index = fileName.lastIndexOf('/');
+ if (index>=0) {
+ pathName = new Path(fileName.substring(0,index)).toOSString();
+ fileName = fileName.substring(index+1);
+ }
+ Properties p = new Properties();
+ p.setProperty("resource.loader", "file");
+ p.setProperty("file.resource.loader.description", "Default Wikipedia Plugin Loader");
+ p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+ p.setProperty("file.resource.loader.path", pathName);
+ p.setProperty("file.resource.loader.cache", "false");
+ p.setProperty("file.resource.loader.modificationCheckInterval", "0");
+ VelocityEngine ve = new VelocityEngine();
+ ve.init(p);
+
+ VelocityContext velocityContext = new VelocityContext();
+ velocityContext.put("content", String.valueOf(writer) );
+ String localCssUrl = Util.getLocalCssUrl(fProject);
+ velocityContext.put("localcss", localCssUrl );
+ String exportCssUrl = Util.getExportCssUrl(fProject);
+ velocityContext.put("exportcss", exportCssUrl );
+ Template template = ve.getTemplate(fileName);
+
+ StringWriter sw = new StringWriter();
+ template.merge(velocityContext, sw);
+ buf.append(sw);
}
- // return buffer.toString();
} catch (Exception e) {
- WikiEditorPlugin.getDefault().log(buffer.toString());
+ WikiEditorPlugin.getDefault().log(buf.toString());
WikiEditorPlugin.getDefault().log(e.getLocalizedMessage(), e);
// return "<html><body><p>" + e.getLocalizedMessage() + "</p></body></html>";
}