1 package net.sourceforge.phpeclipse.wiki.actions.httpquery;
3 import java.io.StringWriter;
6 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
7 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
8 import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
9 import net.sourceforge.phpeclipse.wiki.velocity.EditorText;
11 import org.apache.velocity.VelocityContext;
12 import org.apache.velocity.app.Velocity;
13 import org.eclipse.jface.action.IAction;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.ui.IEditorActionDelegate;
16 import org.eclipse.ui.IEditorPart;
17 import org.eclipse.ui.IViewPart;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.PlatformUI;
22 public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate {
24 private IEditorPart targetEditor;
25 private EditorText text;
26 public AbstractHTTPQueryAction() {
30 public void setActiveEditor(IAction action, IEditorPart targetEditor) {
31 this.targetEditor = targetEditor;
32 text = new EditorText(targetEditor);
35 abstract protected IConfiguration getUrl();
37 public void run(IAction action) {
38 // String selection = findSelectedText();
39 // if (selection == null || selection.trim().length() == 0) {
43 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
45 IWorkbenchPage page = window.getActivePage();
47 IViewPart part = page.findView(BrowserView.ID_BROWSER);
49 part = page.showView(BrowserView.ID_BROWSER);
51 page.bringToTop(part);
53 IConfiguration config = getUrl();
54 String templateString = generateUrl(config.getURL());
55 if (templateString != null && !templateString.equals("")) {
56 ((BrowserView) part).setUrl(templateString);
58 } catch (Exception e) {
63 public void selectionChanged(IAction action, ISelection selection) {
66 public String generateUrl(String template) {
68 /* first, we init the runtime engine. Defaults are fine. */
73 /* lets make a Context and put data into it */
75 VelocityContext context = new VelocityContext();
77 ConfigurationWorkingCopy config = new ConfigurationWorkingCopy();
78 config.setName("test");
79 config.setPassword("pw");
81 context.put("config", config);
83 context.put("text", text);
85 /* lets make our own string to render */
86 StringWriter w = new StringWriter();
87 w = new StringWriter();
88 Velocity.evaluate(context, w, "mystring", template);
91 } catch (Exception e) {
92 // TODO Auto-generated catch block