integrated velocity engine for URL templates
authoraxelcl <axelcl>
Sat, 11 Dec 2004 17:56:11 +0000 (17:56 +0000)
committeraxelcl <axelcl>
Sat, 11 Dec 2004 17:56:11 +0000 (17:56 +0000)
12 files changed:
archive/net.sourceforge.phpeclipse.wiki/plugin.xml
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/AbstractHTTPQueryAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/GoogleAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/HTTPQueryAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/KodersAction.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java [new file with mode: 0644]
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java [moved from archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshWikiTextEditorAction.java with 72% similarity]
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java [new file with mode: 0644]
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationManager.java
archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java

index 56770b6..de70df9 100644 (file)
                        path="rest">
                 </menu>
                 <action
-               label="Refresh Current Wiki Text (Wikibooks.org)"
-               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction"
+               label="Refresh Wikibooks-en"
+               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction"
                menubarPath="mediawikiMenu/additions"
-               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction">
+               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction">
          </action>
-         <action
+                <action
+               label="Refresh Wikipedia-en"
+               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction"
+               menubarPath="mediawikiMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction">
+         </action>
+<!--         <action
                label="Download Link's Wiki Text (Wikibooks.org)"
                class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction"
                menubarPath="mediawikiMenu/additions"
                id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction">
+         </action> -->
+         <action
+               label="Refresh Wikipedia..."
+               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction"
+               menubarPath="mediawikiMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction">
          </action>
       </viewerContribution>
       <viewerContribution
                        label="%MediaWiki.label"
                        path="rest">
                 </menu>
-         <action
-               label="Refresh Current Wiki Text (Wikibooks.org)"
-               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction"
+                <action
+               label="Refresh Wikibooks-en"
+               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction"
                menubarPath="mediawikiMenu/additions"
-               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction">
+               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction">
          </action>
          <action
+               label="Refresh Wikipedia-en"
+               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction"
+               menubarPath="mediawikiMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction">
+         </action>
+  <!--       <action 
                label="Download Link's Wiki Text (Wikibooks.org)"
                class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction"
                menubarPath="mediawikiMenu/additions"
                id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction">
+         </action> -->
+         <action
+               label="Refresh Wikipedia..."
+               class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction"
+               menubarPath="mediawikiMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction">
          </action>
       </viewerContribution>   
       <viewerContribution
                id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
          </action>
                 <action
-               label="Run HTTP Query"
+               label="HTTP Query..."
                class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
                menubarPath="httpqueryMenu/additions"
                id="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction">
                id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
          </action>
                 <action
-               label="Run HTTP Query"
+               label="HTTP Query..."
                class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
                menubarPath="httpqueryMenu/additions"
                id="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction">
                id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
          </action>
                 <action
-               label="Run HTTP Query"
+               label="HTTP Query..."
                class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
                menubarPath="httpqueryMenu/additions"
                id="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction">
index 1aaad74..c721086 100644 (file)
@@ -4,8 +4,8 @@ import java.io.StringWriter;
 import java.net.URL;
 
 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
-import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
 import net.sourceforge.phpeclipse.wiki.velocity.EditorText;
 
 import org.apache.velocity.VelocityContext;
@@ -32,13 +32,9 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
     text = new EditorText(targetEditor);
   }
 
-  abstract protected IConfiguration getUrl();
+  abstract protected Configuration getConfiguration();
 
   public void run(IAction action) {
-//    String selection = findSelectedText();
-//    if (selection == null || selection.trim().length() == 0) {
-//      selection = "";
-//    }
     URL url;
     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     if (window != null) {
@@ -50,8 +46,8 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
         } else {
           page.bringToTop(part);
         }
-        IConfiguration config = getUrl();
-        String templateString = generateUrl(config.getURL());
+        Configuration config = getConfiguration();
+        String templateString = generateUrl(config, config.getURL());
         if (templateString != null && !templateString.equals("")) {
           ((BrowserView) part).setUrl(templateString);
         }
@@ -63,7 +59,7 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
   public void selectionChanged(IAction action, ISelection selection) {
   }
 
-  public String generateUrl(String template) {
+  public String generateUrl(Configuration config, String template) {
 
     /* first, we init the runtime engine. Defaults are fine. */
 
@@ -74,10 +70,6 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
 
       VelocityContext context = new VelocityContext();
       
-      ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
-      config.setName("test");
-      config.setPassword("pw");
-      
       context.put("config", config);
       text.clear();
       context.put("text", text);  
index d44a588..5eab038 100644 (file)
@@ -1,8 +1,8 @@
 package net.sourceforge.phpeclipse.wiki.actions.httpquery;
 
 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
-import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
 
 
 public class GoogleAction extends AbstractHTTPQueryAction {
@@ -11,7 +11,7 @@ public class GoogleAction extends AbstractHTTPQueryAction {
     super();
   }
 
-  protected IConfiguration getUrl() {
+  protected Configuration getConfiguration() {
     ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
     config.setName("Google Search");
     config.setURL("http://www.google.com/search?q=$text.selection");
index 1c41e37..d18f979 100644 (file)
@@ -5,7 +5,9 @@ import java.util.Collections;
 import java.util.List;
 
 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
 import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
 
 import org.eclipse.jface.viewers.LabelProvider;
@@ -19,7 +21,7 @@ public class HTTPQueryAction extends AbstractHTTPQueryAction {
     super();
   }
 
-  protected IConfiguration getUrl() {
+  protected Configuration getConfiguration() {
     String selectedURL = null;
 
     List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
@@ -39,7 +41,7 @@ public class HTTPQueryAction extends AbstractHTTPQueryAction {
       Object[] configurations = listSelectionDialog.getResult();
       if (configurations != null) {
         for (int i = 0; i < configurations.length; i++) {
-          return ((IConfiguration) configurations[i]); // .getURL();
+          return ((Configuration) configurations[i]); // .getURL();
         }
       }
     }
index 909f29c..365d4fa 100644 (file)
@@ -1,8 +1,8 @@
 package net.sourceforge.phpeclipse.wiki.actions.httpquery;
 
 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
-import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
 
 
 public class KodersAction extends AbstractHTTPQueryAction {
@@ -11,7 +11,7 @@ public class KodersAction extends AbstractHTTPQueryAction {
     super();
   }
 
-  protected IConfiguration getUrl() {
+  protected Configuration getConfiguration() {
     ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
     config.setName("Koders.com Search");
     config.setURL("http://koders.com/?s=$text.selection");
diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java
new file mode 100644 (file)
index 0000000..495db99
--- /dev/null
@@ -0,0 +1,12 @@
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
+
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
+
+public final class DownloadWikibooksENAction extends DownloadWikipediaAction {
+  protected Configuration getConfiguration(){
+    ConfigurationWorkingCopy configuration = new ConfigurationWorkingCopy();
+    configuration.setURL("http://en.wikibooks.org/w/wiki.phtml?title=$text.wikiname&action=edit");
+    return configuration;
+  }
+}
\ No newline at end of file
@@ -1,13 +1,22 @@
 package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
 
 import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
+import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
 import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import net.sourceforge.phpeclipse.wiki.velocity.EditorText;
 
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -33,163 +42,196 @@ import org.eclipse.ui.internal.dialogs.ListContentProvider;
 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
 import org.eclipse.ui.texteditor.AbstractTextEditor;
 
-public final class RefreshWikiTextEditorAction implements IEditorActionDelegate {
-
-  private IWorkbenchWindow window;
+public class DownloadWikipediaAction implements IEditorActionDelegate {
 
   private AbstractTextEditor fEditor;
 
-  public void dispose() {
-  }
+  private EditorText text;
 
-  public void init(IWorkbenchWindow window) {
-    this.window = window;
-  }
+  private IWorkbenchWindow window;
 
-  public void selectionChanged(IAction action, ISelection selection) {
-    if (selection.isEmpty()) {
-      return;
-    }
-    if (selection instanceof TextSelection) {
-      action.setEnabled(true);
-      return;
-    }
-    if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
-      action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
+  private void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
+    try {
+      // Create the folder resource in the workspace
+      // Recursive to create any folders which do not exist already
+      if (!folderHandle.exists()) {
+        IContainer parent = folderHandle.getParent();
+        if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
+          createFolder((IFolder) parent, monitor);
+        }
+        folderHandle.create(false, true, monitor);
+      }
+    } catch (CoreException e) {
+      // If the folder already existed locally, just refresh to get contents
+      if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
+        folderHandle.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
+      else
+        throw e;
     }
   }
 
-  public void run(IAction action) {
-    if (fEditor == null) {
-      IEditorPart targetEditor = window.getActivePage().getActiveEditor();
-      if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
-        fEditor = (AbstractTextEditor) targetEditor;
-      }
-    }
-    if (fEditor != null) {
-      openWikiLinkOnSelection();
-    }
+  /**
+   * Creates a folder resource handle for the folder with the given workspace path. This method does not create the folder resource;
+   * this is the responsibility of <code>createFolder</code>.
+   * 
+   * @param folderPath
+   *          the path of the folder resource to create a handle for
+   * @return the new folder resource handle
+   * @see #createFolder
+   */
+  private IFolder createFolderHandle(IPath folderPath) {
+    return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath);
   }
 
-  public void setActiveEditor(IAction action, IEditorPart targetEditor) {
-    if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
-      fEditor = (AbstractTextEditor) targetEditor;
+  private void createNewFileIfNeeded(IFile file, String word) throws CoreException {
+    if (!file.exists()) {
+      createWikiFile(file, word);
     }
   }
 
-  public IDocument getDocument() {
-    IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
-    return doc;
+  private void createWikiFile(IFile file, String word) throws CoreException {
+    IContainer parent = file.getParent();
+    if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
+      createFolder((IFolder) parent, null);
+    }
+    String newText = "<!--" + word + "-->";
+    byte[] buffer = newText.getBytes();
+    ByteArrayInputStream source = new ByteArrayInputStream(buffer);
+    file.create(source, true, null);
   }
 
-  public void openWikiLinkOnSelection() {
-    IDocument doc = getDocument();
-    ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
-    int pos = selection.getOffset();
-    //    String textRegion = getWikiString(fEditor, doc, pos);
-    IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
-    openWikiFile(ei.getFile());
+  public void dispose() {
   }
 
-  void openWikiFile(IFile cfile) {
-    String wikiName = getWikiFile(cfile);
+  public String generateUrl(Configuration config, String template, String wikiname) {
+
+    /* first, we init the runtime engine. Defaults are fine. */
+
     try {
-      if (fEditor != null) {
-        selectWiki(wikiName);
-      }
-    } catch (Exception e) {
-    }
+      Velocity.init();
 
-  }
+      /* lets make a Context and put data into it */
 
-  private void selectWiki(String wikiName) {
-    String exampleWikiURL = "http://en.wikibooks.org/w/wiki.phtml";
-    String selectedWikiURL = null;
-    ArrayList locationsList = new ArrayList();
-    locationsList.add(exampleWikiURL);
+      VelocityContext context = new VelocityContext();
 
-    Collections.sort(locationsList);
+      context.put("config", config);
+      text.clear();
+      text.setWikiname(wikiname);
+      context.put("text", text);
 
+      /* lets make our own string to render */
+      StringWriter w = new StringWriter();
+      w = new StringWriter();
+      Velocity.evaluate(context, w, "mystring", template);
+      return w.toString();
+
+    } catch (Exception e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+    return template;
+  }
+
+  protected Configuration getConfiguration(){
+    List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
+    ArrayList configsList = new ArrayList();
+    for (int i = 0; i < allConfigsList.size(); i++) {
+      IConfiguration temp = (IConfiguration) allConfigsList.get(i);
+      if (temp.getType().equals(WikiEditorPlugin.WIKIPEDIA_GET_TEXT)) {
+        configsList.add(temp);
+      }
+    }
+    Collections.sort(configsList);
+    Configuration configuration = null;
     ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
-        .getActiveWorkbenchWindow().getShell(), locationsList, new ListContentProvider(), new LabelProvider(),
+        .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(),
         "Select the refresh URL.");
     listSelectionDialog.setTitle("Multiple active configuration found");
     if (listSelectionDialog.open() == Window.OK) {
       Object[] locations = listSelectionDialog.getResult();
       if (locations != null) {
         for (int i = 0; i < locations.length; i++) {
-          selectedWikiURL = (String) locations[i];
+          configuration = (Configuration) locations[i];
           break;
         }
       }
     }
-
-    if (selectedWikiURL != null && !selectedWikiURL.equals("")) {
-      String wikiContent = MediaWikiConnector.getWikiText(wikiName, selectedWikiURL);
-      if (wikiContent != null) {
-        IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
-        doc.set(wikiContent);
-      }
-    }
+    return configuration;
   }
 
-  private void createNewFileIfNeeded(IFile file, String word) throws CoreException {
-    if (!file.exists()) {
-      createWikiFile(file, word);
-    }
+  public IDocument getDocument() {
+    IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+    return doc;
   }
 
   private String getWikiFile(IFile file) {
     return Util.getFileWikiName(file, WikiEditorPlugin.HTML_OUTPUT_PATH);
-    //    IPath path = new Path(wikiFileName);
-    //    return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
   }
 
-  /**
-   * Creates a folder resource handle for the folder with the given workspace path. This method does not create the folder resource;
-   * this is the responsibility of <code>createFolder</code>.
-   * 
-   * @param folderPath
-   *          the path of the folder resource to create a handle for
-   * @return the new folder resource handle
-   * @see #createFolder
-   */
-  private IFolder createFolderHandle(IPath folderPath) {
-    return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath);
+  public void init(IWorkbenchWindow window) {
+    this.window = window;
   }
 
-  private void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
+  void openWikiFile(IFile cfile) {
+    String wikiName = getWikiFile(cfile);
     try {
-      // Create the folder resource in the workspace
-      // Recursive to create any folders which do not exist already
-      if (!folderHandle.exists()) {
-        IContainer parent = folderHandle.getParent();
-        if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
-          createFolder((IFolder) parent, monitor);
-        }
-        //                 if (linkTargetPath != null)
-        //                             folderHandle.createLink(linkTargetPath, IResource.ALLOW_MISSING_LOCAL, monitor);
-        //                 else
-        folderHandle.create(false, true, monitor);
+      if (fEditor != null) {
+        selectWiki(wikiName);
       }
-    } catch (CoreException e) {
-      // If the folder already existed locally, just refresh to get contents
-      if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
-        folderHandle.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
-      else
-        throw e;
+    } catch (Exception e) {
     }
+
   }
 
-  private void createWikiFile(IFile file, String word) throws CoreException {
-    IContainer parent = file.getParent();
-    if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
-      createFolder((IFolder) parent, null);
+  public void openWikiLinkOnSelection() {
+    IDocument doc = getDocument();
+    ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+    int pos = selection.getOffset();
+    IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
+    openWikiFile(ei.getFile());
+  }
+
+  public void run(IAction action) {
+    if (fEditor == null) {
+      IEditorPart targetEditor = window.getActivePage().getActiveEditor();
+      if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+        fEditor = (AbstractTextEditor) targetEditor;
+      }
+    }
+    if (fEditor != null) {
+      openWikiLinkOnSelection();
     }
-    String newText = "<!--" + word + "-->";
-    byte[] buffer = newText.getBytes();
-    ByteArrayInputStream source = new ByteArrayInputStream(buffer);
-    file.create(source, true, null);
   }
 
+  public void selectionChanged(IAction action, ISelection selection) {
+    if (selection.isEmpty()) {
+      return;
+    }
+    if (selection instanceof TextSelection) {
+      action.setEnabled(true);
+      return;
+    }
+    if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
+      action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
+    }
+  }
+  
+  private void selectWiki(String wikiName) {
+    Configuration configuration = getConfiguration();
+    if (configuration != null && !configuration.equals("")) {
+      String url = generateUrl(configuration, configuration.getURL(), wikiName);
+      String wikiContent = MediaWikiConnector.getWikiText(wikiName, url);
+      if (wikiContent != null) {
+        IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+        doc.set(wikiContent);
+      }
+    }
+  }
+
+  public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+    if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+      fEditor = (AbstractTextEditor) targetEditor;
+      text = new EditorText(targetEditor);
+    }
+  }
 }
\ No newline at end of file
diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java
new file mode 100644 (file)
index 0000000..14dd2ae
--- /dev/null
@@ -0,0 +1,12 @@
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
+
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
+
+public final class DownloadWikipediaENAction extends DownloadWikipediaAction {
+  protected Configuration getConfiguration(){
+    ConfigurationWorkingCopy configuration = new ConfigurationWorkingCopy();
+    configuration.setURL("http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&action=edit");
+    return configuration;
+  }
+}
\ No newline at end of file
index c9d2bda..b2e845e 100644 (file)
@@ -35,7 +35,7 @@ public class MediaWikiConnector {
    * Get the text of a wikimedia Wiki-Description
    *  
    */
-  public static String getWikiText(String wikiDescriptor, String urlStr) {
+  public static String getWikiText(String wikiname, String urlStr) {
     // examples
     // http://en.wikipedia.org/w/wiki.phtml?title=Main_Page&action=edit
     // http://en.wikibooks.org/w/wiki.phtml?title=Programming:PHP:SQL_Injection&action=edit
@@ -43,10 +43,11 @@ public class MediaWikiConnector {
     HttpMethod method = null;
     try {
       if (urlStr == null) {
-        urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiDescriptor + "&action=edit";
-      } else {
-        urlStr = urlStr + "?title=" + wikiDescriptor + "&action=edit";
-      }
+        urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiname + "&action=edit";
+      } 
+//      else {
+//        urlStr = urlStr + "?title=" + wikiname + "&action=edit";
+//      }
       URI uri = new URI(urlStr.toCharArray());
 
       String schema = uri.getScheme();
index 3e5c839..b67d095 100644 (file)
@@ -53,7 +53,15 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
   public final static String HTML_OUTPUT_PATH = "__static_wiki_folder";
 
   public final static String WIKI_TEXTS_BASE_PATH = "__wiki_texts_base_path";
-
+  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\"/>" +
+"<config name=\"Koders.com Search\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>" +
+"<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>" +
+"<config name=\"Wikipedia-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&amp;action=edit\"/>" +
+"<config name=\"Wikibooks-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikibooks.org/w/wiki.phtml?title=$text.wikiname&amp;action=edit\"/>" +
+"</configurations>";
   private static ConfigurationManager manager;
 //
 //  public static final String IMG_MONITOR_ON = "monitorOn";
@@ -212,6 +220,7 @@ public class WikiEditorPlugin extends AbstractUIPlugin {
    * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
    */
   protected void initializeDefaultPreferences(IPreferenceStore store) {
+    store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
   }
 
   /*
index 3713a9b..146dae7 100644 (file)
@@ -143,7 +143,7 @@ public class ConfigurationManager {
                
                configurations = new ArrayList();
                Preferences prefs = WikiEditorPlugin.getDefault().getPluginPreferences();
-               String xmlString = prefs.getString("configurations");
+               String xmlString = prefs.getString(WikiEditorPlugin.PREF_STRING_CONFIGURATIONS);
                if (xmlString != null && xmlString.length() > 0) {
                        try {
                                ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes());
index c1d58a2..092a7bc 100644 (file)
@@ -16,6 +16,8 @@ public class EditorText {
 
   String text = null;
 
+  String wikiname = null;
+
   public EditorText(IEditorPart targetEditor) {
     this.targetEditor = targetEditor;
   }
@@ -23,6 +25,7 @@ public class EditorText {
   public void clear() {
     selection = null;
     text = null;
+    wikiname = null;
   }
 
   /**
@@ -93,4 +96,19 @@ public class EditorText {
     int start = boundary.previous();
     return source.substring(start, end);
   }
+
+  /**
+   * @return Returns the wikiname.
+   */
+  public String getWikiname() {
+    return wikiname;
+  }
+
+  /**
+   * @param wikiname
+   *          The wikiname to set.
+   */
+  public void setWikiname(String wikiname) {
+    this.wikiname = wikiname;
+  }
 }
\ No newline at end of file