1 package net.sourceforge.phpdt.sql.actions;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.io.PrintWriter;
7 import java.util.StringTokenizer;
8 import java.util.Vector;
10 import org.eclipse.jface.action.Action;
11 import org.eclipse.jface.action.IAction;
12 import org.eclipse.jface.viewers.ISelection;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.FileDialog;
15 import org.eclipse.ui.IViewActionDelegate;
16 import org.eclipse.ui.IViewPart;
18 import net.sourceforge.phpdt.sql.Messages;
19 import net.sourceforge.phpdt.sql.utils.PHPStringThing;
20 import net.sourceforge.phpdt.sql.view.BookmarkView;
21 import net.sourceforge.phpdt.sql.view.LogProxy;
22 import net.sourceforge.phpdt.sql.view.SQLLogView;
23 import net.sourceforge.phpdt.sql.view.SQLQueryView;
24 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
26 public class GeneratePHPAction extends Action implements IViewActionDelegate {
30 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
32 public void init(IViewPart view) {
33 this.view = (SQLQueryView) view;
34 dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
35 dialog.setFilterExtensions(new String[] { "*.php", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
36 dialog.setFilterNames(new String[] { Messages.getString("filedialog.phpFiles"), //$NON-NLS-1$
37 Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
41 * @see org.eclipse.ui.IActionDelegate#run(IAction)
43 public void run(IAction action) {
49 /* String filename = dialog.open();
50 if (filename != null) {
52 /*Check for the presence of a "." - either indicates an
53 * extension has been provided or that a filename with a '.'
54 * has been specified - if the latter, it is assumed the user
55 * knows what they're doing - could be dangerous! :-)
57 /* if (filename.indexOf(".") == -1)
59 File exportFile = new File(filename);
60 FileWriter fileWriter = new FileWriter(exportFile);
61 PrintWriter writer = new PrintWriter(fileWriter);
62 String query = view.getQuery();
63 Vector phpStrings = PHPStringThing.toPHP(query);
65 while (!phpStrings.isEmpty()) {
66 String buffer = (String) phpStrings.remove(0);
67 BookmarkNode current =
68 BookmarkView.getInstance().getCurrentBookmark();
74 + current.getUsername()
76 + current.getPassword());
77 buffer.replaceAll("%%DBNAME%%", current.getName());
79 /*Find the %%NL%% templates and substitute in the correct
80 * newline character for the platform - println does this
83 /* StringTokenizer tokenizer =
84 new StringTokenizer(buffer, "%%NL%%");
85 while (tokenizer.hasMoreElements()) {
86 String line = (String) tokenizer.nextElement();
91 } catch (IOException e) {
92 LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
99 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
101 public void selectionChanged(IAction action, ISelection selection) {