X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExportBookmarksAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExportBookmarksAction.java index dfaf550..b709b76 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExportBookmarksAction.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExportBookmarksAction.java @@ -1,24 +1,26 @@ 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 { @@ -32,8 +34,8 @@ public class ExportBookmarksAction 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$ } /** @@ -42,8 +44,34 @@ public class ExportBookmarksAction 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(); + } + + } }