1 21 22 package org.armedbear.j; 23 24 import java.util.Iterator ; 25 26 public final class SessionBufferEntry 27 { 28 private static final String lineSeparator = 29 System.getProperty("line.separator"); 30 31 private Buffer buffer; 32 private String path; 33 private String modeName; 34 private int dotLineNumber; 35 private int dotOffset; 36 private long lastActivated; 37 38 public SessionBufferEntry() 39 { 40 } 41 42 public SessionBufferEntry(Buffer buffer, int index) 43 { 44 this.buffer = buffer; 45 if (buffer.getFile() != null) 46 path = buffer.getFile().netPath(); 47 else 48 path = ""; 49 if (buffer.getMode() != null) 50 modeName = buffer.getMode().toString(); 51 else 52 modeName = ""; 53 lastActivated = buffer.getLastActivated(); 54 View view = buffer.getLastView(); 55 if (view != null) { 56 dotLineNumber = view.lineNumber; 57 dotOffset = view.offs; 58 } 59 } 60 61 public final String getPath() 62 { 63 return path; 64 } 65 66 public final void setPath(String path) 67 { 68 this.path = path; 69 } 70 71 public final Mode getMode() 72 { 73 return Editor.getModeList().getModeFromModeName(modeName); 74 } 75 76 public final void setMode(String modeName) 77 { 78 this.modeName = modeName; 79 } 80 81 public final int getModeId() 82 { 83 return Editor.getModeList().getModeIdFromModeName(modeName); 84 } 85 86 public final int getDotLineNumber() 87 { 88 return dotLineNumber; 89 } 90 91 public final void setDotLineNumber(int lineNumber) 92 { 93 dotLineNumber = lineNumber; 94 } 95 96 public final int getDotOffset() 97 { 98 return dotOffset; 99 } 100 101 public final void setDotOffset(int offset) 102 { 103 dotOffset = offset; 104 } 105 106 public final long getLastActivated() 107 { 108 return lastActivated; 109 } 110 111 public final void setLastActivated(long l) 112 { 113 lastActivated = l; 114 } 115 116 public String toXml() 117 { 118 FastStringBuffer sb = new FastStringBuffer(); 119 sb.append(" <buffer"); 120 sb.append(" path=\""); 121 sb.append(path); 122 sb.append('"'); 123 sb.append(" mode=\""); 124 sb.append(modeName); 125 sb.append('"'); 126 sb.append(" dot=\""); 127 sb.append(String.valueOf(dotLineNumber)); 128 sb.append(','); 129 sb.append(String.valueOf(dotOffset)); 130 sb.append('"'); 131 sb.append(" when=\""); 132 sb.append(String.valueOf(lastActivated)); 133 sb.append('"'); 134 PropertyList properties = buffer.getProperties(); 135 if (properties.size() > 0) { 136 sb.append(">"); 137 sb.append(lineSeparator); 138 Iterator it = properties.keyIterator(); 139 if (it != null) { 140 while (it.hasNext()) { 141 Property property = (Property) it.next(); 142 Object value = properties.getProperty(property); 143 sb.append(propertyToXml(property.getDisplayName(), 144 value.toString())); 145 } 146 } 147 sb.append(" </buffer>"); 148 } else 149 sb.append("/>"); 150 return sb.toString(); 151 } 152 153 private static String propertyToXml(String name, String value) 154 { 155 FastStringBuffer sb = new FastStringBuffer(" <property name=\""); 156 sb.append(name); 157 sb.append("\" value=\""); 158 sb.append(value); 159 sb.append("\"/>"); 160 sb.append(lineSeparator); 161 return sb.toString(); 162 } 163 } 164 | Popular Tags |