- Timestamp:
- 06/25/19 13:57:37 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/items/surrogates/Label.java
r1409 r1413 1 1 package org.expeditee.encryption.items.surrogates; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Base64; 4 5 import java.util.Collection; 6 import java.util.List; 7 import java.util.Set; 8 import java.util.stream.Collectors; 5 9 6 10 import org.expeditee.auth.AuthenticatorBrowser; 11 import org.expeditee.gui.DisplayController; 7 12 import org.expeditee.gui.Frame; 8 13 import org.expeditee.gui.FrameIO; 14 import org.expeditee.gui.MessageBay; 15 import org.expeditee.items.Item; 9 16 import org.expeditee.items.Text; 10 17 import org.expeditee.settings.UserSettings; … … 12 19 public class Label { 13 20 21 private static List<LabelResult> labelCache = new ArrayList<LabelResult>(); 22 private static List<String> forbiddenLabels = new ArrayList<String>(); 23 14 24 public static LabelResult resolveKey(String label) { 25 26 if (forbiddenLabels.contains(label)) { 27 return LabelResult.ErrorUnableToFindLabel; 28 } 29 30 LabelResult fromCache = getFromCache(label); 31 if (fromCache != null) { 32 return fromCache; 33 } 34 35 15 36 String credentialsFrameName = UserSettings.ProfileName.get() + 16 37 AuthenticatorBrowser.CREDENTIALS_FRAME; … … 44 65 LabelResult res = LabelResult.SuccessResolveLabelToKey; 45 66 res.key = Base64.getDecoder().decode(data); 67 res.name = label; 68 labelCache.add(res); 46 69 return res; 47 70 } catch (IllegalArgumentException e) { … … 50 73 } 51 74 } 75 76 public static void progressSurrogateMode() { 77 Collection<Item> allItems = DisplayController.getCurrentFrame().getAllItems(); 78 allItems.removeIf(item -> item.getEncryptionLabel() == null); 79 MessageBay.displayMessage("Encryption labels found on items on current frame: "); 80 Set<String> allLabels = allItems.stream().map(i -> i.getEncryptionLabel()).collect(Collectors.toSet()); 81 StringBuilder sb = new StringBuilder(); 82 for (String label: allLabels) { 83 sb.append(label + ","); 84 } 85 MessageBay.displayMessage(sb.deleteCharAt(sb.length() - 1).toString()); 86 } 87 88 public static void resetSurrogateMode() { 89 // TODO Auto-generated method stub 90 91 } 92 93 private static LabelResult getFromCache(String label) { 94 List<LabelResult> cacheCanditates = labelCache.stream().filter(labelResult -> labelResult.name.equals(label)).collect(Collectors.toList()); 95 if (!cacheCanditates.isEmpty()) { 96 return cacheCanditates.get(0); 97 } else { 98 return null; 99 } 100 } 101 102 // private static List<List<String>> permutation(List<String> strings, List<List<String>> acc) { 103 // for (int i = 0; i < strings.size(); i++) { 104 // 105 // } 106 // } 52 107 53 108 public enum LabelResult { … … 58 113 59 114 public byte[] key; 115 public String name; 60 116 61 117 @Override
Note:
See TracChangeset
for help on using the changeset viewer.