1 11 12 package org.eclipse.debug.ui.actions; 13 14 import java.io.FileOutputStream ; 15 import java.io.IOException ; 16 import java.io.OutputStreamWriter ; 17 import java.lang.reflect.InvocationTargetException ; 18 19 import org.eclipse.core.resources.IMarker; 20 import org.eclipse.core.resources.IResource; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.debug.core.model.IBreakpoint; 24 import org.eclipse.debug.internal.ui.importexport.breakpoints.IImportExportConstants; 25 import org.eclipse.debug.internal.ui.importexport.breakpoints.ImportExportMessages; 26 import org.eclipse.jface.operation.IRunnableWithProgress; 27 import org.eclipse.ui.IMemento; 28 import org.eclipse.ui.XMLMemento; 29 30 37 public class ExportBreakpointsOperation implements IRunnableWithProgress { 38 39 private IBreakpoint[] fBreakpoints = null; 40 private String fFileName = null; 41 42 49 public ExportBreakpointsOperation(IBreakpoint[] breakpoints, String fileName) { 50 fBreakpoints = breakpoints; 51 fFileName = fileName; 52 } 53 54 57 public void run(IProgressMonitor monitor) throws InvocationTargetException { 58 XMLMemento memento = XMLMemento.createWriteRoot(IImportExportConstants.IE_NODE_BREAKPOINTS); 59 monitor.beginTask(ImportExportMessages.ExportOperation_0, fBreakpoints.length); 60 try { 61 for (int i = 0; i < fBreakpoints.length; i++) { 62 IBreakpoint breakpoint = fBreakpoints[i]; 63 IMarker marker = breakpoint.getMarker(); 66 IMemento root = memento.createChild(IImportExportConstants.IE_NODE_BREAKPOINT); 67 root.putString(IImportExportConstants.IE_BP_ENABLED, Boolean.toString(breakpoint.isEnabled())); 68 root.putString(IImportExportConstants.IE_BP_REGISTERED, Boolean.toString(breakpoint.isRegistered())); 69 root.putString(IImportExportConstants.IE_BP_PERSISTANT, Boolean.toString(breakpoint.isPersisted())); 70 IResource resource = marker.getResource(); 72 IMemento child = root.createChild(IImportExportConstants.IE_NODE_RESOURCE); 73 child.putString(IImportExportConstants.IE_NODE_PATH, resource.getFullPath().toPortableString()); 74 child.putInteger(IImportExportConstants.IE_NODE_TYPE, resource.getType()); 75 root = root.createChild(IImportExportConstants.IE_NODE_MARKER); 77 root.putString(IImportExportConstants.IE_NODE_TYPE, marker.getType()); 78 Object val = marker.getAttribute(IMarker.LINE_NUMBER); 79 root.putString(IMarker.LINE_NUMBER, (val != null) ? val.toString() : null); 80 val = marker.getAttribute(IImportExportConstants.CHARSTART); 81 root.putString(IImportExportConstants.CHARSTART, (val != null) ? val.toString() : null); 82 for(java.util.Iterator iter = marker.getAttributes().keySet().iterator(); iter.hasNext();) { 83 String iterval = iter.next().toString(); 84 if(!iterval.equals(IMarker.LINE_NUMBER)) { 85 child = root.createChild(IImportExportConstants.IE_NODE_ATTRIB); 86 child.putString(IImportExportConstants.IE_NODE_NAME, iterval); 87 child.putString(IImportExportConstants.IE_NODE_VALUE, marker.getAttribute(iterval).toString()); 88 } 89 } 90 } 91 OutputStreamWriter osw = new OutputStreamWriter (new FileOutputStream (fFileName), "UTF-8"); memento.save(osw); 93 osw.close(); 94 } catch (CoreException e) { 95 throw new InvocationTargetException (e); 96 } catch (IOException e) { 97 throw new InvocationTargetException (e); 98 } 99 } 100 101 102 } 103 | Popular Tags |