Moved Google and Koders Search to the wiki plugin
authoraxelcl <axelcl>
Sat, 11 Dec 2004 14:57:31 +0000 (14:57 +0000)
committeraxelcl <axelcl>
Sat, 11 Dec 2004 14:57:31 +0000 (14:57 +0000)
archive/net.sourceforge.phpeclipse.wiki/lib/velocity-dep-1.4.jar [new file with mode: 0644]
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/velocity/EditorText.java [new file with mode: 0644]
net.sourceforge.phpeclipse.webbrowser/plugin.xml

diff --git a/archive/net.sourceforge.phpeclipse.wiki/lib/velocity-dep-1.4.jar b/archive/net.sourceforge.phpeclipse.wiki/lib/velocity-dep-1.4.jar
new file mode 100644 (file)
index 0000000..375712b
Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.wiki/lib/velocity-dep-1.4.jar differ
index 9cce801..56770b6 100644 (file)
@@ -17,6 +17,7 @@
       <library name="lib/commons-httpclient-2.0.2.jar"/>
       <library name="lib/java2html_4.1.jar"/>
       <library name="lib/plog4u.jar"/>
+      <library name="lib/velocity-dep-1.4.jar"/>
    </runtime>
    <requires>
       <import plugin="org.eclipse.core.runtime.compatibility"/>
                        path="rest">
                 </menu>
                 <action
+               label="Koders.com Search"
+               class="net.sourceforge.phpeclipse.wiki.actions.httpquery.KodersAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.httpquery.KodersAction">
+         </action>
+                <action
+               label="Google Search"
+               class="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
+         </action>
+                <action
                label="Run HTTP Query"
                class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
                menubarPath="httpqueryMenu/additions"
                        path="rest">
                 </menu>
                 <action
+               label="Koders.com Search"
+               class="net.sourceforge.phpeclipse.wiki.actions.httpquery.KodersAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.httpquery.KodersAction">
+         </action>
+                <action
+               label="Google Search"
+               class="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
+         </action>
+                <action
                label="Run HTTP Query"
                class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
                menubarPath="httpqueryMenu/additions"
                        label="%HTTPQuery.label"
                        path="rest">
                 </menu>
-         <action
+                <action
+               label="Koders.com Search"
+               class="net.sourceforge.phpeclipse.wiki.actions.httpquery.KodersAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.httpquery.KodersAction">
+         </action>
+                <action
+               label="Google Search"
+               class="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction"
+               menubarPath="httpqueryMenu/additions"
+               id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
+         </action>
+                <action
                label="Run HTTP Query"
                class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
                menubarPath="httpqueryMenu/additions"
index db83d2c..1aaad74 100644 (file)
@@ -1,14 +1,16 @@
 package net.sourceforge.phpeclipse.wiki.actions.httpquery;
 
+import java.io.StringWriter;
 import java.net.URL;
-import java.text.BreakIterator;
 
 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
+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;
+import org.apache.velocity.app.Velocity;
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IEditorActionDelegate;
 import org.eclipse.ui.IEditorPart;
@@ -16,28 +18,27 @@ import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
 
 public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
 
   private IEditorPart targetEditor;
-
+  private EditorText text;
   public AbstractHTTPQueryAction() {
     super();
   }
 
   public void setActiveEditor(IAction action, IEditorPart targetEditor) {
     this.targetEditor = targetEditor;
+    text = new EditorText(targetEditor);
   }
 
-  abstract protected String getUrl(String selection);
+  abstract protected IConfiguration getUrl();
 
   public void run(IAction action) {
-    String selection = findSelectedText();
-    if (selection == null || selection.trim().length() == 0) {
-      selection = "";
-    }
+//    String selection = findSelectedText();
+//    if (selection == null || selection.trim().length() == 0) {
+//      selection = "";
+//    }
     URL url;
     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     if (window != null) {
@@ -49,9 +50,10 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
         } else {
           page.bringToTop(part);
         }
-        String urlStr = getUrl(selection);
-        if (urlStr != null && !urlStr.equals("")) {
-          ((BrowserView) part).setUrl(urlStr);
+        IConfiguration config = getUrl();
+        String templateString = generateUrl(config.getURL());
+        if (templateString != null && !templateString.equals("")) {
+          ((BrowserView) part).setUrl(templateString);
         }
       } catch (Exception e) {
       }
@@ -61,37 +63,35 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
   public void selectionChanged(IAction action, ISelection selection) {
   }
 
-  protected String findSelectedText() {
-    String selectedText = null;
-    ITextSelection textSelection = (ITextSelection) targetEditor.getEditorSite().getSelectionProvider().getSelection();
+  public String generateUrl(String template) {
 
-    selectedText = textSelection.getText();
-    if (selectedText == null || selectedText.trim().length() == 0) {
-      selectedText = findWord(textSelection);
-    }
-    return selectedText;
-  }
+    /* first, we init the runtime engine. Defaults are fine. */
 
-  private String findWord(ITextSelection textSelection) {
-    IDocumentProvider documentProvider = ((ITextEditor) targetEditor).getDocumentProvider();
-    IDocument document = documentProvider.getDocument(targetEditor.getEditorInput());
-    int caretPosition = textSelection.getOffset();
     try {
-      IRegion line = document.getLineInformation(document.getLineOfOffset(caretPosition));
-      String currentLine = document.get(line.getOffset(), line.getLength());
-      int positionInLine = caretPosition - line.getOffset();
-      return findWordAt(positionInLine, currentLine);
+      Velocity.init();
+
+      /* lets make a Context and put data into it */
+
+      VelocityContext context = new VelocityContext();
+      
+      ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
+      config.setName("test");
+      config.setPassword("pw");
+      
+      context.put("config", config);
+      text.clear();
+      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 null;
+    return template;
   }
-
-  private String findWordAt(int pos, String source) {
-    BreakIterator boundary = BreakIterator.getWordInstance();
-    boundary.setText(source);
-    int end = boundary.following(pos);
-    int start = boundary.previous();
-    return source.substring(start, end);
-  }
-
 }
\ No newline at end of file
index 0b293c4..d44a588 100644 (file)
@@ -1,5 +1,9 @@
 package net.sourceforge.phpeclipse.wiki.actions.httpquery;
 
+import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
+import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
+
 
 public class GoogleAction extends AbstractHTTPQueryAction {
 
@@ -7,8 +11,12 @@ public class GoogleAction extends AbstractHTTPQueryAction {
     super();
   }
 
-  protected String getUrl(String selection) {
-    return "http://www.google.com/search?q=" + selection;
+  protected IConfiguration getUrl() {
+    ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
+    config.setName("Google Search");
+    config.setURL("http://www.google.com/search?q=$text.selection");
+    config.setType(WikiEditorPlugin.HTTP_QUERY);
+    return config;
   }
 
 }
\ No newline at end of file
index 0cdfd38..1c41e37 100644 (file)
@@ -19,13 +19,13 @@ public class HTTPQueryAction extends AbstractHTTPQueryAction {
     super();
   }
 
-  protected String getUrl(String selection) {
+  protected IConfiguration getUrl() {
     String selectedURL = null;
-    
+
     List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
     ArrayList configsList = new ArrayList();
-    for (int i=0;i<allConfigsList.size();i++) {
-      IConfiguration temp = (IConfiguration)allConfigsList.get(i);
+    for (int i = 0; i < allConfigsList.size(); i++) {
+      IConfiguration temp = (IConfiguration) allConfigsList.get(i);
       if (temp.getType().equals(WikiEditorPlugin.HTTP_QUERY)) {
         configsList.add(temp);
       }
@@ -33,19 +33,17 @@ public class HTTPQueryAction extends AbstractHTTPQueryAction {
     Collections.sort(configsList);
 
     ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
-        .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(),
-        "Select URL");
+        .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(), "Select URL");
     listSelectionDialog.setTitle("Multiple configuration found");
     if (listSelectionDialog.open() == Window.OK) {
       Object[] configurations = listSelectionDialog.getResult();
       if (configurations != null) {
         for (int i = 0; i < configurations.length; i++) {
-          selectedURL = ((IConfiguration) configurations[i]).getURL();
-          break;
+          return ((IConfiguration) configurations[i]); // .getURL();
         }
       }
     }
-    return selectedURL;
+    return null;
   }
 
 }
\ No newline at end of file
index 0492d21..909f29c 100644 (file)
@@ -1,5 +1,9 @@
 package net.sourceforge.phpeclipse.wiki.actions.httpquery;
 
+import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
+import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
+
 
 public class KodersAction extends AbstractHTTPQueryAction {
 
@@ -7,7 +11,11 @@ public class KodersAction extends AbstractHTTPQueryAction {
     super();
   }
 
-  protected String getUrl(String selection) {
-    return "http://koders.com/?s=" + selection;
+  protected IConfiguration getUrl() {
+    ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
+    config.setName("Koders.com Search");
+    config.setURL("http://koders.com/?s=$text.selection");
+    config.setType(WikiEditorPlugin.HTTP_QUERY);
+    return config;
   }
 }
\ No newline at end of file
diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java
new file mode 100644 (file)
index 0000000..c1d58a2
--- /dev/null
@@ -0,0 +1,96 @@
+package net.sourceforge.phpeclipse.wiki.velocity;
+
+import java.text.BreakIterator;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+public class EditorText {
+  private IEditorPart targetEditor = null;
+
+  String selection = null;
+
+  String text = null;
+
+  public EditorText(IEditorPart targetEditor) {
+    this.targetEditor = targetEditor;
+  }
+
+  public void clear() {
+    selection = null;
+    text = null;
+  }
+
+  /**
+   * @return Returns the selection.
+   */
+  public String getSelection() {
+    if (selection == null) {
+      selection = findSelectedText();
+      if (selection == null) {
+        selection = "";
+      }
+    }
+    return selection;
+  }
+
+  /**
+   * @param selection
+   *          The selection to set.
+   */
+  public void setSelection(String selection) {
+    this.selection = selection;
+  }
+
+  /**
+   * @return Returns the text.
+   */
+  public String getText() {
+    return text;
+  }
+
+  /**
+   * @param text
+   *          The text to set.
+   */
+  public void setText(String text) {
+    this.text = text;
+  }
+
+  public String findSelectedText() {
+    String selectedText = null;
+    ITextSelection textSelection = (ITextSelection) targetEditor.getEditorSite().getSelectionProvider().getSelection();
+
+    selectedText = textSelection.getText();
+    if (selectedText == null || selectedText.trim().length() == 0) {
+      selectedText = findWord(textSelection);
+    }
+    return selectedText;
+  }
+
+  private String findWord(ITextSelection textSelection) {
+    IDocumentProvider documentProvider = ((ITextEditor) targetEditor).getDocumentProvider();
+    IDocument document = documentProvider.getDocument(targetEditor.getEditorInput());
+    int caretPosition = textSelection.getOffset();
+    try {
+      IRegion line = document.getLineInformation(document.getLineOfOffset(caretPosition));
+      String currentLine = document.get(line.getOffset(), line.getLength());
+      int positionInLine = caretPosition - line.getOffset();
+      return findWordAt(positionInLine, currentLine);
+    } catch (Exception e) {
+    }
+    return null;
+  }
+
+  private String findWordAt(int pos, String source) {
+    BreakIterator boundary = BreakIterator.getWordInstance();
+    boundary.setText(source);
+    int end = boundary.following(pos);
+    int start = boundary.previous();
+    return source.substring(start, end);
+  }
+}
\ No newline at end of file
index 89f484f..bafd633 100644 (file)
@@ -3,16 +3,18 @@
 
 <plugin id="net.sourceforge.phpeclipse.webbrowser"
   name="%pluginName"
-  version="1.1.1"
+  version="1.1.2"
   provider-name="%providerName"
   class="net.sourceforge.phpeclipse.webbrowser.internal.WebBrowserUIPlugin">
 
   <requires>
     <import plugin="org.eclipse.core.resources" version="3.0.0" match="greaterOrEqual"/>
     <import plugin="org.eclipse.core.runtime" version="3.0.0" match="greaterOrEqual"/>
+    <import plugin="org.eclipse.ui.workbench.texteditor" version="3.0.0" match="greaterOrEqual"/>
     <import plugin="org.eclipse.ui" version="3.0.0" match="greaterOrEqual"/>
     <import plugin="org.eclipse.ui.ide" version="3.0.0" match="greaterOrEqual"/>
     <import plugin="org.eclipse.ui.editors" version="3.0.0" match="greaterOrEqual"/>
+    <import plugin="org.eclipse.jface.text" version="3.0.0" match="greaterOrEqual"/>
   </requires>
 
   <runtime>
             id="net.sourceforge.phpeclipse.webbrowser.views">
       </view>
    </extension>
-
+   
 </plugin>
\ No newline at end of file