package net.sourceforge.phpdt.sql.actions;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import org.apache.crimson.tree.XmlDocument;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import org.w3c.dom.Element;
+import net.sourceforge.phpdt.sql.Messages;
import net.sourceforge.phpdt.sql.view.BookmarkView;
import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
/**
* @author root
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
+ * Asks the user for a file name and saves there the bookmarks in xml format
*/
public class ExportBookmarksAction
implements IViewActionDelegate {
public void init(IViewPart view) {
this.view = (BookmarkView) view;
dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
- dialog.setFilterExtensions(new String[]{"*.ini","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
- dialog.setFilterNames(new String[]{Messages.getString("filedialog.preferences"),Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterExtensions(new String[]{"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[]{Messages.getString("filedialog.xmlFiles"),Messages.getString("filedialog.xmlFiles")}); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
public void run(IAction action) {
String filename = dialog.open();
if (filename != null) {
- File exportFile = new File(filename);
- BookmarkContentProvider.getInstance().save(exportFile);
+ /*Check for the presence of a "." - either indicates an
+ * extension has been provided or that a filename with a '.'
+ * has been specified - if the latter, it is assumed the user
+ * knows what they're doing - could be dangerous! :-)
+ */
+ if (filename.indexOf(".") ==0) filename += ".xml";
+
+ File target = new File(filename);
+ XmlDocument doc = new XmlDocument();
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(target);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ return;
+ }
+ Element root = (Element) doc.appendChild(doc.createElement(Messages.getString("ExportXMLAction.SavedData"))); //$NON-NLS-1$
+
+ BookmarkContentProvider.getInstance().exportXML(root);
+
+ try {
+ doc.write(out);
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
}
}