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.Configuration;
8 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
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 Configuration getConfiguration();
37 public void run(IAction action) {
39 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
41 IWorkbenchPage page = window.getActivePage();
43 IViewPart part = page.findView(BrowserView.ID_BROWSER);
45 part = page.showView(BrowserView.ID_BROWSER);
47 page.bringToTop(part);
49 Configuration config = getConfiguration();
50 String templateString = generateUrl(config, config.getURL());
51 if (templateString != null && !templateString.equals("")) {
52 ((BrowserView) part).setUrl(templateString);
54 } catch (Exception e) {
59 public void selectionChanged(IAction action, ISelection selection) {
62 public String generateUrl(Configuration config, String template) {
64 /* first, we init the runtime engine. Defaults are fine. */
69 /* lets make a Context and put data into it */
71 VelocityContext context = new VelocityContext();
73 context.put("config", config);
75 context.put("text", text);
77 /* lets make our own string to render */
78 StringWriter w = new StringWriter();
79 w = new StringWriter();
80 Velocity.evaluate(context, w, "mystring", template);
83 } catch (Exception e) {
84 // TODO Auto-generated catch block