<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"
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;
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) {
} 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) {
}
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
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 {
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
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);
}
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
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 {
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
--- /dev/null
+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
<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