1 package net.sourceforge.phpdt.sql.actions;
4 import java.io.FileNotFoundException;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
8 import org.apache.crimson.tree.XmlDocument;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.jface.viewers.ISelection;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.widgets.FileDialog;
13 import org.eclipse.ui.IViewActionDelegate;
14 import org.eclipse.ui.IViewPart;
15 import org.w3c.dom.Element;
17 import net.sourceforge.phpdt.sql.Messages;
18 import net.sourceforge.phpdt.sql.view.BookmarkView;
19 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
23 * Asks the user for a file name and saves there the bookmarks in xml format
25 public class ExportBookmarksAction
26 implements IViewActionDelegate {
32 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
34 public void init(IViewPart view) {
35 this.view = (BookmarkView) view;
36 dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
37 dialog.setFilterExtensions(new String[]{"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
38 dialog.setFilterNames(new String[]{Messages.getString("filedialog.xmlFiles"),Messages.getString("filedialog.xmlFiles")}); //$NON-NLS-1$ //$NON-NLS-2$
42 * @see org.eclipse.ui.IActionDelegate#run(IAction)
44 public void run(IAction action) {
45 String filename = dialog.open();
46 if (filename != null) {
47 /*Check for the presence of a "." - either indicates an
48 * extension has been provided or that a filename with a '.'
49 * has been specified - if the latter, it is assumed the user
50 * knows what they're doing - could be dangerous! :-)
52 if (filename.indexOf(".") ==0) filename += ".xml";
54 File target = new File(filename);
55 XmlDocument doc = new XmlDocument();
56 FileOutputStream out = null;
58 out = new FileOutputStream(target);
59 } catch (FileNotFoundException e1) {
63 Element root = (Element) doc.appendChild(doc.createElement(Messages.getString("ExportXMLAction.SavedData"))); //$NON-NLS-1$
65 BookmarkContentProvider.getInstance().exportXML(root);
70 } catch (IOException e) {
79 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
81 public void selectionChanged(IAction action, ISelection selection) {