1 21 22 package org.gjt.sp.jedit.bufferio; 23 24 import java.io.*; 26 import java.util.Vector ; 27 import org.gjt.sp.jedit.*; 28 import org.gjt.sp.jedit.io.*; 29 import org.gjt.sp.util.*; 30 32 39 40 public class MarkersSaveRequest extends WorkRequest 41 { 42 public static final String ERROR_OCCURRED = "MarkersSaveRequest__error"; 44 46 55 public MarkersSaveRequest(View view, Buffer buffer, 56 Object session, VFS vfs, String path) 57 { 58 this.view = view; 59 this.buffer = buffer; 60 this.session = session; 61 this.vfs = vfs; 62 this.path = path; 63 this.markersPath = buffer.getMarkersPath(vfs); 64 65 } 67 public void run() 69 { 70 OutputStream out = null; 71 72 try 73 { 74 setAbortable(true); 76 try 77 { 78 if((vfs.getCapabilities() & VFS.DELETE_CAP) != 0) 81 { 82 if(buffer.getMarkers().isEmpty()) 83 vfs._delete(session,markersPath,view); 84 else 85 { 86 String [] args = { vfs.getFileName(path) }; 87 setStatus(jEdit.getProperty("vfs.status.save-markers",args)); 88 setValue(0); 89 out = vfs._createOutputStream(session,markersPath,view); 90 if(out != null) 91 writeMarkers(out); 92 } 93 } 94 } 95 catch(IOException io) 96 { 97 Log.log(Log.ERROR,this,io); 98 buffer.setBooleanProperty(ERROR_OCCURRED,true); 99 } 100 } 101 catch(WorkThread.Abort a) 102 { 103 if(out != null) 104 { 105 try 106 { 107 out.close(); 108 } 109 catch(IOException io) 110 { 111 } 112 } 113 114 buffer.setBooleanProperty(ERROR_OCCURRED,true); 115 } 116 } 118 private void writeMarkers(OutputStream out) 120 throws IOException 121 { 122 Writer o = new BufferedWriter(new OutputStreamWriter(out)); 123 try 124 { 125 Vector markers = buffer.getMarkers(); 126 for(int i = 0; i < markers.size(); i++) 127 { 128 Marker marker = (Marker)markers.elementAt(i); 129 o.write('!'); 130 o.write(marker.getShortcut()); 131 o.write(';'); 132 133 String pos = String.valueOf(marker.getPosition()); 134 o.write(pos); 135 o.write(';'); 136 o.write(pos); 137 o.write('\n'); 138 } 139 } 140 finally 141 { 142 o.close(); 143 } 144 } 146 protected View view; 148 protected Buffer buffer; 149 protected Object session; 150 protected VFS vfs; 151 protected String path; 152 protected String markersPath; 153 155 } 156 | Popular Tags |