1) Added missing strings for italic, underline and strike through.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ExportBookmarksAction.java
1 package net.sourceforge.phpdt.sql.actions;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7
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;
16
17 import net.sourceforge.phpdt.sql.Messages;
18 import net.sourceforge.phpdt.sql.view.BookmarkView;
19 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
20
21 /**
22  * @author root
23  * Asks the user for a file name and saves there the bookmarks in xml format 
24  */
25 public class ExportBookmarksAction
26         implements IViewActionDelegate {
27                 
28         BookmarkView view;
29         FileDialog dialog;
30
31         /**
32          * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
33          */
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$
39         }
40
41         /**
42          * @see org.eclipse.ui.IActionDelegate#run(IAction)
43          */
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! :-)
51                          */
52                         if (filename.indexOf(".") ==0) filename += ".xml";
53                                                 
54                         File target = new File(filename);
55                         XmlDocument doc = new XmlDocument();
56                         FileOutputStream out = null;
57                         try {
58                                 out = new FileOutputStream(target);
59                         } catch (FileNotFoundException e1) {
60                                 e1.printStackTrace();
61                                 return;
62                         }
63                         Element root = (Element) doc.appendChild(doc.createElement(Messages.getString("ExportXMLAction.SavedData"))); //$NON-NLS-1$
64                 
65                         BookmarkContentProvider.getInstance().exportXML(root);
66                 
67                         try {
68                                 doc.write(out);
69                                 out.close();
70                         } catch (IOException e) {
71                                 e.printStackTrace();
72                         }
73
74
75                 }
76         }
77         
78         /**
79          * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
80          */
81         public void selectionChanged(IAction action, ISelection selection) {
82         }
83
84 }