Add predefined Velocity and CSS templates if wiki builder is assigned to a project
authoraxelcl <axelcl>
Wed, 15 Dec 2004 22:55:31 +0000 (22:55 +0000)
committeraxelcl <axelcl>
Wed, 15 Dec 2004 22:55:31 +0000 (22:55 +0000)
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/AddBuilderAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/export.vm
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/main.vm
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/Messages.properties
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/Util.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/WikiProjectPreferences.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/renderer/WikipediaContentRenderer.java

index e615b20..7a3b3f2 100644 (file)
@@ -100,7 +100,7 @@ public class AddBuilderAction implements IObjectActionDelegate {
         desc.setBuildSpec(newCommands);
         project.setDescription(desc, null);
         // add some default wiki project settings
-        Util.setWikiTextsPath(project);
+        Util.setWikiBuilderPreferences(project);
 
         createVelocityFile(project, "main.vm");
         createVelocityFile(project, "export.vm");
@@ -114,6 +114,8 @@ public class AddBuilderAction implements IObjectActionDelegate {
   private void createVelocityFile(IProject project, String filename) throws CoreException {
     InputStream is = AddBuilderAction.class.getResourceAsStream(filename);
     final IFile file = project.getFile(new Path("wpsrc/" + filename));
-    file.create(is, true, null);
+    if (!file.exists()) {
+      file.create(is, true, null);
+    }
   }
 }
\ No newline at end of file
index c1590a8..e2b3408 100644 (file)
@@ -89,6 +89,7 @@ public class CreatePageAction implements IObjectActionDelegate {
 
   public static void createPage(IFile file) {
     String templateFileName = Util.getLocalTemplate(file);
+    String cssUrl = Util.getLocalCssUrl(file);
     String srcBasePath = Util.getWikiTextsPath(file);
     String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
     createPage(templateFileName, file, binBasePath, srcBasePath);
index 9ca51b9..5c6cdb3 100644 (file)
@@ -1,6 +1,6 @@
 <html>\r
 <head>\r
-<link rel="STYLESHEET" type="text/css" href="file://C:\eclipse3\runtime-workbench-workspace\wikibook\wpsrc\main.css" />\r
+<link rel="STYLESHEET" type="text/css" href="$exportcss" />\r
 </head>\r
 <body class="ns-0">\r
 <div id="column-content">\r
index 9ca51b9..f4c5fc8 100644 (file)
@@ -1,6 +1,6 @@
 <html>\r
 <head>\r
-<link rel="STYLESHEET" type="text/css" href="file://C:\eclipse3\runtime-workbench-workspace\wikibook\wpsrc\main.css" />\r
+<link rel="STYLESHEET" type="text/css" href="$localcss" />\r
 </head>\r
 <body class="ns-0">\r
 <div id="column-content">\r
index b49e15f..6e7669b 100644 (file)
@@ -56,8 +56,9 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
   
   public final static String LOCAL_TEMPLATE_FILE_NAME = "__local_template_file_name";
   public final static String EXPORT_TEMPLATE_FILE_NAME = "__export_template_file_name";
-  
-  public final static String  PREF_STRING_CONFIGURATIONS ="configurations";
+  public final static String LOCAL_CSS_URL = "__local_css_url"; 
+  public final static String EXPORT_CSS_URL = "__export_css_url";
+  public final static String PREF_STRING_CONFIGURATIONS = "configurations";
   public final static String CONFIG_MEMENTO = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<configurations>"+
 "<config name=\"Google Search\" type-id=\"HTTP Query\" url=\"http://www.google.com/search?q=$text.selection\"/>" +
index 273da4f..4815ec0 100644 (file)
@@ -1,7 +1,9 @@
 WikiProjectPreferences.StaticWikiFolder=Projects Wikipedia to HTML output path:  
 WikiProjectPreferences.WikiTextsFolder=Projects associated Wikipedia texts path: 
 WikiProjectPreferences.LocalTemplateFile=Preview renderer template file name: 
+WikiProjectPreferences.LocalCssUrl=CSS Url for browser preview: 
 WikiProjectPreferences.ExportTemplateFile=Export template file name: 
+WikiProjectPreferences.ExportCssUrl=CSS Url for exported wikis: 
 
 OverlayPage.Use_Workspace_Settings=Use &workspace settings
 OverlayPage.Use_Project_Settings=Use pr&oject settings
index b8d41f4..241867a 100644 (file)
@@ -110,7 +110,7 @@ public class Util {
     return "true".equals(use);
   }
 
-  public static void setWikiTextsPath(IProject project) {
+  public static void setWikiBuilderPreferences(IProject project) {
     String value = project.getLocation().toString();
     IPreferenceStore store = WikiEditorPlugin.getDefault().getPreferenceStore();
     String globalBasePath = store.getString(WikiEditorPlugin.WIKI_TEXTS_BASE_PATH);
@@ -118,6 +118,8 @@ public class Util {
       store.setValue(WikiEditorPlugin.WIKI_TEXTS_BASE_PATH, value + "/wpsrc");
       store.setValue(WikiEditorPlugin.LOCAL_TEMPLATE_FILE_NAME, value + "/wpsrc/main.vm");
       store.setValue(WikiEditorPlugin.EXPORT_TEMPLATE_FILE_NAME, value + "/wpsrc/export.vm");
+      store.setValue(WikiEditorPlugin.LOCAL_CSS_URL, "file://"+value+"/wpsrc/main.css");
+      store.setValue(WikiEditorPlugin.EXPORT_CSS_URL, "file://"+value+"/wpsrc/main.css");
     }
     String htmlFolder = store.getString(WikiEditorPlugin.HTML_OUTPUT_PATH);
     if (htmlFolder == null || htmlFolder.equals("")) {  
@@ -129,6 +131,8 @@ public class Util {
     setProperty(project, WikiProjectPreferences.PREF_ID, WikiEditorPlugin.HTML_OUTPUT_PATH, value + "/wpbin");
     setProperty(project, WikiProjectPreferences.PREF_ID, WikiEditorPlugin.LOCAL_TEMPLATE_FILE_NAME, value + "/wpsrc/main.vm");
     setProperty(project, WikiProjectPreferences.PREF_ID, WikiEditorPlugin.EXPORT_TEMPLATE_FILE_NAME, value + "/wpsrc/export.vm");
+    setProperty(project, WikiProjectPreferences.PREF_ID, WikiEditorPlugin.LOCAL_CSS_URL, "file://"+value+"/wpsrc/main.css");
+    setProperty(project, WikiProjectPreferences.PREF_ID, WikiEditorPlugin.EXPORT_CSS_URL, "file://"+value+"/wpsrc/main.css");
     //    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
     //    IResource resource = root.findMember(project.getLocation());
     NullProgressMonitor _monitor = new NullProgressMonitor();
@@ -159,11 +163,15 @@ public class Util {
   public static String getLocalTemplate(IResource file) {
     return Util.getPreferenceValue(file.getProject(), WikiEditorPlugin.LOCAL_TEMPLATE_FILE_NAME);
   }
-  
+  public static String getLocalCssUrl(IResource file) {
+    return Util.getPreferenceValue(file.getProject(), WikiEditorPlugin.LOCAL_CSS_URL);
+  }
   public static String getExportTemplate(IResource file) {
     return Util.getPreferenceValue(file.getProject(), WikiEditorPlugin.EXPORT_TEMPLATE_FILE_NAME);
   }
-  
+  public static String getExportCssUrl(IResource file) {
+    return Util.getPreferenceValue(file.getProject(), WikiEditorPlugin.EXPORT_CSS_URL);
+  }
   public static String getProjectsWikiTextsPath(IProject project) {
     return Util.getPreferenceValue(project, WikiEditorPlugin.WIKI_TEXTS_BASE_PATH);
   }
index fd11f1b..267ba92 100644 (file)
@@ -5,6 +5,7 @@ import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
 import org.eclipse.jface.preference.DirectoryFieldEditor;
 import org.eclipse.jface.preference.FileFieldEditor;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -36,10 +37,11 @@ public class WikiProjectPreferences extends FieldEditorOverlayPage implements IW
     addField(new DirectoryFieldEditor(WikiEditorPlugin.HTML_OUTPUT_PATH, Messages.getString("WikiProjectPreferences.StaticWikiFolder"), composite));
     addField(new DirectoryFieldEditor(WikiEditorPlugin.WIKI_TEXTS_BASE_PATH, Messages.getString("WikiProjectPreferences.WikiTextsFolder"), composite));
     addField(new FileFieldEditor(WikiEditorPlugin.LOCAL_TEMPLATE_FILE_NAME, Messages.getString("WikiProjectPreferences.LocalTemplateFile"), composite));
+    addField(new StringFieldEditor(WikiEditorPlugin.LOCAL_CSS_URL, Messages.getString("WikiProjectPreferences.LocalCssUrl"), composite));
     addField(new FileFieldEditor(WikiEditorPlugin.EXPORT_TEMPLATE_FILE_NAME, Messages.getString("WikiProjectPreferences.ExportTemplateFile"), composite));  
-  
+    addField(new StringFieldEditor(WikiEditorPlugin.EXPORT_CSS_URL, Messages.getString("WikiProjectPreferences.ExportCssUrl"), composite));
     }
-
   /*
    * (non-Javadoc)
    * 
index 9f3d428..439110e 100644 (file)
@@ -9,10 +9,10 @@ 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.Velocity;
 import org.apache.velocity.app.VelocityEngine;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IPath;
@@ -127,7 +127,7 @@ public final class WikipediaContentRenderer extends AbstractContentRenderer {
     try {
       if (templateFileName == null||templateFileName.equals("")) {
         if (completeHTMLPage) {
-          appendHeader(buf);
+          appendHeader(buf); 
         }
         StringWriter writer = new StringWriter();
         try {
@@ -166,6 +166,10 @@ public final class WikipediaContentRenderer extends AbstractContentRenderer {
         
         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();