- Timestamp:
- 06/25/19 13:57:37 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java
r1409 r1413 26 26 import org.expeditee.encryption.items.surrogates.EncryptionDetail; 27 27 import org.expeditee.encryption.items.surrogates.Label; 28 import org.expeditee.encryption.items.surrogates.Surrogate;29 28 import org.expeditee.encryption.items.surrogates.Label.LabelResult; 30 29 import org.expeditee.gui.Frame; … … 37 36 38 37 public class EncryptedExpReader extends ExpReader implements CryptographyConstants { 38 39 39 private static final String ENCRYPTED_EXP_FLAG = "EncryptedExp"; 40 40 private static final String labelProfile = "Profile"; … … 43 43 private boolean accessDenied = false; 44 44 45 public EncryptedExpReader(String frameName) {46 super(frameName);47 }48 49 45 public static boolean isEncryptedExpediteeFile(final String path) throws IOException { 50 46 final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8")); … … 52 48 in.close(); 53 49 return firstLine.startsWith(ENCRYPTED_EXP_FLAG); 50 } 51 52 public EncryptedExpReader(String frameName) { 53 super(frameName); 54 54 } 55 55 … … 132 132 continue; 133 133 } 134 134 135 String tag = getTagEnc(next); 135 if ( tag.equals("S")) {136 if (next.startsWith("S ")) { 136 137 currentItem = newItem(next); 137 138 _linePoints.put(currentItem.getID(), currentItem); 138 139 newFrame.addItem(currentItem); 139 140 currentItem.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave); 141 } else if (next.startsWith("SurrogateFor")) { 142 int parentID = Integer.parseInt(next.split(" ")[1]); 143 newFrame.getItemWithID(parentID).addToSurrogates(currentItem); 140 144 } else if (currentItem != null && actionShouldBeDelayed(tag.charAt(0))) { 141 145 delayedActions.add(new DelayedAction(currentItem, next)); … … 147 151 } 148 152 149 if (next.equals( "Z...")) {150 next = readThe SurrogateItems(newFrame, delayedActions);153 if (next.equals(EncryptedExpWriter.SURROGATE_TERMINATOR)) { 154 next = readTheItems(newFrame, delayedActions); 151 155 } 152 156 … … 159 163 String tag = getTagEnc(line); 160 164 String value = getValue(line); 165 166 if (item.isSurrogate() && item.isTagInherited(tag)) { 167 return; 168 } 161 169 162 170 // Attempt to decrypt the line if necessary. … … 192 200 } 193 201 } 194 195 private String readTheSurrogateItems(Frame newFrame, List<DelayedAction> delayedActions) throws IOException {196 String next = null;197 Item currentItem = null;198 199 Predicate<String> endOfSection = s -> s.equals("Z") || s.equals("Z...");200 while (_reader.ready() && !endOfSection.test(next = _reader.readLine())) {201 if (!isValidLine(next)) {202 continue;203 }204 205 String tag = getTagEnc(next);206 if (tag.equals("S") && !next.startsWith("SurrogateFor")) {207 currentItem = newItem(next);208 currentItem.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave);209 } else if (next.startsWith("SurrogateFor")) {210 String id = next.split(" ")[1];211 Item classic = newFrame.getItemWithID(Integer.parseInt(id));212 if (id == null) {213 System.err.println("WARNING: Attempted to create surrogate for classic ID " +214 id + " but was no item on frame " + newFrame.getName() + " exists.");215 continue;216 }217 currentItem.setAsSurrogateFor(classic);218 classic.addToSurrogates(new Surrogate(currentItem));219 } else if (currentItem != null && actionShouldBeDelayed(getTag(next))) {220 delayedActions.add(new DelayedAction(currentItem, next));221 } else if (currentItem != null) {222 processBodyLine(currentItem, next);223 } else {224 System.err.println("Error while reading in frame (ExpReader): Found body line but no current item to apply it to.");225 }226 }227 228 return next;229 }230 231 protected static String getTagEnc(String line) {232 char charAtZero = line.charAt(0);233 if (charAtZero == '_') {234 return line.split(" ")[0];235 } else {236 return charAtZero + "";237 }238 }239 202 240 203 protected static String getValue(String line) { … … 247 210 } 248 211 249 protected static boolean isEncryptedLine(String line) { 212 private static String getTagEnc(String line) { 213 char charAtZero = line.charAt(0); 214 if (charAtZero == '_') { 215 return line.split(" ")[0]; 216 } else { 217 return charAtZero + ""; 218 } 219 } 220 221 private static boolean isEncryptedLine(String line) { 250 222 if (line.startsWith("S") || line.startsWith("_el")) { 251 223 return false; … … 278 250 } 279 251 } 280 252 281 253 private class EncryptedLineReader extends BufferedReader { 282 254 private boolean noneMode = false;
Note:
See TracChangeset
for help on using the changeset viewer.