Changeset 1408 for trunk/src/org/expeditee/io
- Timestamp:
- 06/21/19 12:12:55 (5 years ago)
- Location:
- trunk/src/org/expeditee/io
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/DefaultFrameReader.java
r1405 r1408 181 181 _DelayedItemTags.add('/'); 182 182 183 _ItemTagsExt.put("_el", Item.class.getMethod("setEncryptionLabel ", pString));183 _ItemTagsExt.put("_el", Item.class.getMethod("setEncryptionLabelOnLoad", pString)); 184 184 185 185 _ItemTagsExt.put("_ph", Text.class.getMethod("setPlaceholder", pString)); -
trunk/src/org/expeditee/io/DefaultFrameWriter.java
r1405 r1408 55 55 56 56 // keep track of methods that are put on the same line 57 pr otectedstatic LinkedHashMap<Character, Method> _ItemTags = null;57 private static LinkedHashMap<Character, Method> _ItemTags = null; 58 58 // IMPORTANT: keys in _ItemTagsExt must start with underscore as their first character 59 pr otectedstatic LinkedHashMap<String, Method> _ItemTagsExt = null;59 private static LinkedHashMap<String, Method> _ItemTagsExt = null; 60 60 61 61 protected static LinkedHashMap<Character, Method> _FrameTags = null; … … 319 319 } 320 320 321 /** 322 * @return the _ItemTags 323 */ 324 public static LinkedHashMap<Character, Method> getItemTags() { 325 return _ItemTags; 326 } 327 328 /** 329 * @return the _ItemTagsExt 330 */ 331 public static LinkedHashMap<String, Method> getItemTagsExt() { 332 return _ItemTagsExt; 333 } 334 321 335 } -
trunk/src/org/expeditee/io/ExpReader.java
r1321 r1408 48 48 public static final String EXTENTION = ".exp"; 49 49 50 pr ivateBufferedReader _reader = null;51 52 pr ivateString _frameName;50 protected BufferedReader _reader = null; 51 52 protected String _frameName; 53 53 54 54 /** … … 128 128 newFrame.setName(_frameName); 129 129 130 finalList<DelayedAction> delayedActions = new LinkedList<DelayedAction>();130 List<DelayedAction> delayedActions = new LinkedList<DelayedAction>(); 131 131 132 132 // First read all the header lines 133 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 134 if (isValidLine(next)) { 135 processHeaderLine(newFrame, next); 136 } 137 } 133 next = readTheHeader(newFrame); 138 134 139 135 // Now read all the items 140 Item currentItem = null; 141 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 142 // if this is the start of a new item add a new item 143 if (isValidLine(next)) { 144 if (getTag(next) == 'S') { 145 String value = getValue(next); 146 int id = Integer.parseInt(value.substring(2)); 147 148 switch (value.charAt(0)) { 149 case 'P': // check if its a point 150 currentItem = new Dot(id); 151 break; 152 default: 153 currentItem = new Text(id); 154 break; 155 } 156 _linePoints.put(currentItem.getID(), currentItem); 157 newFrame.addItem(currentItem); 158 } else if (currentItem != null && actionShouldBeDelayed(getTag(next))) { 159 delayedActions.add(new DelayedAction(currentItem, next)); 160 } else if (currentItem != null) { 161 processBodyLine(currentItem, next); 162 // final boolean hasSpecifiedPermission = currentItem.getPermission() != null; 163 // final boolean hasSpecifiedOwner = currentItem.getOwner() != null; 164 // if (hasSpecifiedPermission && hasSpecifiedOwner && currentItem.getPermission().getPermission(currentItem.getOwner()) == UserAppliedPermission.denied) { 165 // newFrame.removeItem(currentItem); 166 // newFrame.addItemHidden(currentItem); 167 // continue; 168 // } 169 } else { 170 System.err.println("Error while reading in frame (ExpReader): Found body line but no current item to apply it to."); 171 } 172 } 173 } 136 next = readTheItems(newFrame, delayedActions); 174 137 175 138 // Read the lines 176 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 177 if (isValidLine(next)) { 178 Point idtype = separateValues(next.substring(2)); 179 // The next line must be the endpoints 180 if (!_reader.ready()) { 181 throw new Exception("Unexpected end of file"); 182 } 183 next = _reader.readLine(); 184 Point startend = separateValues(next.substring(2)); 185 int start = startend.getX(); 186 int end = startend.getY(); 187 188 if (_linePoints.get(start) != null 189 && _linePoints.get(end) != null) { 190 newFrame.addItem(new Line(_linePoints.get(start), 191 _linePoints.get(end), idtype.getX())); 192 } else { 193 System.out 194 .println("Error reading line with unknown end points"); 195 } 196 } 197 } 139 next = readTheLines(newFrame); 198 140 199 141 // Read the constraints 200 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 201 if (isValidLine(next)) { 202 Point idtype = separateValues(next.substring(2)); 203 // The next line must be the endpoints 204 if (!_reader.ready()) { 205 throw new Exception("Unexpected end of file"); 206 } 207 next = _reader.readLine(); 208 Point startend = separateValues(next.substring(2)); 209 210 Item a = _linePoints.get(startend.getX()); 211 Item b = _linePoints.get(startend.getY()); 212 213 new Constraint(a, b, idtype.getX(), idtype.getY()); 214 } 215 } 142 next = readTheConstraints(); 216 143 217 144 for(DelayedAction action: delayedActions) { … … 220 147 221 148 // Read the stats 222 while (_reader.ready() && ((next = _reader.readLine()) != null)) { 223 if (next.startsWith(SessionStats.ACTIVE_TIME_ATTRIBUTE)) { 224 try { 225 String value = next.substring(SessionStats.ACTIVE_TIME_ATTRIBUTE.length()).trim(); 226 newFrame.setActiveTime(value); 227 } catch (Exception e) { 228 } 229 230 } else if (next.startsWith(SessionStats.DARK_TIME_ATTRIBUTE)) { 231 try { 232 String value = next.substring(SessionStats.DARK_TIME_ATTRIBUTE.length()).trim(); 233 newFrame.setDarkTime(value); 234 } catch (Exception e) { 235 } 236 237 } 238 } 149 next = readTheStats(newFrame); 239 150 240 151 } catch (Exception e) { … … 252 163 } 253 164 254 private class DelayedAction { 165 protected String readTheStats(Frame newFrame) throws IOException { 166 String next = null; 167 while (_reader.ready() && ((next = _reader.readLine()) != null)) { 168 if (next.startsWith(SessionStats.ACTIVE_TIME_ATTRIBUTE)) { 169 try { 170 String value = next.substring(SessionStats.ACTIVE_TIME_ATTRIBUTE.length()).trim(); 171 newFrame.setActiveTime(value); 172 } catch (Exception e) { 173 } 174 175 } else if (next.startsWith(SessionStats.DARK_TIME_ATTRIBUTE)) { 176 try { 177 String value = next.substring(SessionStats.DARK_TIME_ATTRIBUTE.length()).trim(); 178 newFrame.setDarkTime(value); 179 } catch (Exception e) { 180 } 181 182 } 183 } 184 return next; 185 } 186 187 protected String readTheConstraints() throws IOException, Exception { 188 String next = null; 189 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 190 if (isValidLine(next)) { 191 Point idtype = separateValues(next.substring(2)); 192 // The next line must be the endpoints 193 if (!_reader.ready()) { 194 throw new Exception("Unexpected end of file"); 195 } 196 next = _reader.readLine(); 197 Point startend = separateValues(next.substring(2)); 198 199 Item a = _linePoints.get(startend.getX()); 200 Item b = _linePoints.get(startend.getY()); 201 202 new Constraint(a, b, idtype.getX(), idtype.getY()); 203 } 204 } 205 return next; 206 } 207 208 protected String readTheLines(Frame newFrame) throws IOException, Exception { 209 String next = null; 210 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 211 if (isValidLine(next)) { 212 Point idtype = separateValues(next.substring(2)); 213 // The next line must be the endpoints 214 if (!_reader.ready()) { 215 throw new Exception("Unexpected end of file"); 216 } 217 next = _reader.readLine(); 218 Point startend = separateValues(next.substring(2)); 219 int start = startend.getX(); 220 int end = startend.getY(); 221 222 if (_linePoints.get(start) != null 223 && _linePoints.get(end) != null) { 224 newFrame.addItem(new Line(_linePoints.get(start), 225 _linePoints.get(end), idtype.getX())); 226 } else { 227 System.out 228 .println("Error reading line with unknown end points"); 229 } 230 } 231 } 232 return next; 233 } 234 235 protected String readTheItems(Frame newFrame, final List<DelayedAction> delayedActions) throws IOException { 236 String next = null; 237 Item currentItem = null; 238 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 239 // if this is the start of a new item add a new item 240 if (isValidLine(next)) { 241 if (getTag(next) == 'S') { 242 currentItem = newItem(next); 243 _linePoints.put(currentItem.getID(), currentItem); 244 newFrame.addItem(currentItem); 245 } else if (currentItem != null && actionShouldBeDelayed(getTag(next))) { 246 delayedActions.add(new DelayedAction(currentItem, next)); 247 } else if (currentItem != null) { 248 processBodyLine(currentItem, next); 249 } else { 250 System.err.println("Error while reading in frame (ExpReader): Found body line but no current item to apply it to."); 251 } 252 } 253 } 254 return next; 255 } 256 257 protected Item newItem(String line) { 258 Item currentItem; 259 String value = getValue(line); 260 int id = Integer.parseInt(value.substring(2)); 261 262 switch (value.charAt(0)) { 263 case 'P': // check if its a point 264 currentItem = new Dot(id); 265 break; 266 default: 267 currentItem = new Text(id); 268 break; 269 } 270 return currentItem; 271 } 272 273 protected String readTheHeader(Frame newFrame) throws IOException { 274 String next = null; 275 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 276 if (isValidLine(next)) { 277 processHeaderLine(newFrame, next); 278 } 279 } 280 return next; 281 } 282 283 public class DelayedAction { 255 284 private Item theItem; 256 285 private String theLine; 257 286 258 DelayedAction(final Item theItem, final String theLine) {287 public DelayedAction(final Item theItem, final String theLine) { 259 288 this.theItem = theItem; 260 289 this.theLine = theLine; 261 290 } 262 291 263 void exec() {292 public void exec() { 264 293 processBodyLine(theItem, theLine); 265 294 } … … 267 296 268 297 // Stores points used when constructing lines 269 pr ivateHashMap<Integer, Item> _linePoints = new HashMap<Integer, Item>();298 protected HashMap<Integer, Item> _linePoints = new HashMap<Integer, Item>(); 270 299 271 300 /** -
trunk/src/org/expeditee/io/ExpWriter.java
r1326 r1408 28 28 import java.lang.reflect.Method; 29 29 import java.util.Iterator; 30 import java.util.LinkedHashMap; 30 31 import java.util.LinkedList; 31 32 import java.util.List; … … 53 54 protected String _framename; 54 55 55 pr ivatestatic final char TERMINATOR = 'Z';56 protected static final char TERMINATOR = 'Z'; 56 57 57 58 public ExpWriter() { … … 87 88 try { 88 89 _FrameTags.remove('A'); 89 _ItemTags.put('S', Item.class.getMethod("getTypeAndID",90 getItemTags().put('S', Item.class.getMethod("getTypeAndID", 90 91 new Class[] {})); 91 92 } catch (Exception e) { … … 130 131 writeTerminator(); 131 132 writeLine(SessionStats.getFrameEventList(frame)); 132 133 return;134 133 } 135 134 … … 137 136 } 138 137 139 pr ivatevoid writeHeader(Frame toWrite) throws IOException {138 protected void writeHeader(Frame toWrite) throws IOException { 140 139 Iterator<Character> it = _FrameTags.keySet().iterator(); 141 140 Object[] param = {}; … … 185 184 // } 186 185 187 pr ivatevoid writeLine(String tag, String line) throws IOException {186 protected void writeLine(String tag, String line) throws IOException { 188 187 writeLine(tag + " " + line); 189 188 } … … 227 226 } 228 227 229 pr ivateList<Item> _lineEnds = new LinkedList<Item>();228 protected List<Item> _lineEnds = new LinkedList<Item>(); 230 229 231 230 // Writes out a LineEnd to the file … … 306 305 } 307 306 308 private void writeClass(Object toWrite) throws IOException { 309 Iterator<Character> it = _ItemTags.keySet().iterator(); 310 Iterator<String> itExt = _ItemTagsExt.keySet().iterator(); 311 Object[] param = {}; 312 307 protected void writeClass(Item toWrite) throws IOException { 308 writeTags(toWrite, new Object[] {}, getItemTags()); 309 writeTags(toWrite, new Object[] {}, getItemTagsExt()); 310 } 311 312 protected <T> void writeTags(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags) { 313 Iterator<T> it = tags.keySet().iterator(); 313 314 while (it.hasNext()) { 314 Character tag = it.next(); 315 Method toRun = _ItemTags.get(tag); 316 Class<?> declarer = toRun.getDeclaringClass(); 317 if (declarer.isAssignableFrom(toWrite.getClass())) { 318 try { 319 Object o = toRun.invoke(toWrite, param); 320 o = Conversion.ConvertToExpeditee(toRun, o); 321 if (o != null) { 322 if (o instanceof List) { 323 for (Object line : (List) o) { 324 writeLine(tag.toString(), line.toString()); 325 } 326 } else 327 writeLine(tag.toString(), o.toString()); 328 } 329 } catch (Exception e) { 330 e.printStackTrace(); 315 T tag = it.next(); 316 writeTag(toWrite, param, tags, tag); 317 } 318 } 319 320 protected <T> void writeTag(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags, T tag) { 321 Method toRun = tags.get(tag); 322 Class<?> declarer = toRun.getDeclaringClass(); 323 if (declarer.isAssignableFrom(toWrite.getClass())) { 324 try { 325 Object o = toRun.invoke(toWrite, param); 326 o = Conversion.ConvertToExpeditee(toRun, o); 327 if (o != null) { 328 if (o instanceof List) { 329 for (Object line : (List) o) { 330 writeLine(tag.toString(), line.toString()); 331 } 332 } else 333 writeLine(tag.toString(), o.toString()); 331 334 } 332 } 333 } 334 335 while (itExt.hasNext()) { 336 String tag = itExt.next(); 337 Method toRun = _ItemTagsExt.get(tag); 338 Class<?> declarer = toRun.getDeclaringClass(); 339 if (declarer.isAssignableFrom(toWrite.getClass())) { 340 try { 341 Object o = toRun.invoke(toWrite, param); 342 o = Conversion.ConvertToExpeditee(toRun, o); 343 if (o != null) { 344 if (o instanceof List) { 345 for (Object line : (List) o) { 346 writeLine(tag.toString(), line.toString()); 347 } 348 } else 349 writeLine(tag.toString(), o.toString()); 350 } 351 } catch (Exception e) { 352 e.printStackTrace(); 353 } 335 } catch (Exception e) { 336 e.printStackTrace(); 354 337 } 355 338 } -
trunk/src/org/expeditee/io/KMSWriter.java
r919 r1408 81 81 try { 82 82 _FrameTags.put('A', Frame.class.getMethod("getName", new Class[] {})); 83 _ItemTags.put('S', Item.class.getMethod("getID", new Class[] {}));83 getItemTags().put('S', Item.class.getMethod("getID", new Class[] {})); 84 84 } catch (Exception e) { 85 85 … … 258 258 259 259 private void writeClass(Object toWrite) throws IOException { 260 Iterator<Character> it = _ItemTags.keySet().iterator();260 Iterator<Character> it = getItemTags().keySet().iterator(); 261 261 Object[] param = {}; 262 262 263 263 while (it.hasNext()) { 264 264 Character tag = it.next(); 265 Method toRun = _ItemTags.get(tag);265 Method toRun = getItemTags().get(tag); 266 266 Class<?> declarer = toRun.getDeclaringClass(); 267 267 if (declarer.isAssignableFrom(toWrite.getClass())) {
Note:
See TracChangeset
for help on using the changeset viewer.