Changeset 1408 for trunk


Ignore:
Timestamp:
06/21/19 12:12:55 (5 years ago)
Author:
bln4
Message:

Implementation of the surrogate system.
When you set an item to have a encryption label, a surrogate for that item is generated.
The newly updated EncryptedExpReader/Writer has been updated to maintain the connection between the item and its surrogate.

Coming up next:
Surrogate mode. The ability to simulate viewing and editing an encrypted frame with a limited set of labels.

Location:
trunk/src/org/expeditee
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/encryption/Actions.java

    r1389 r1408  
    2323import org.expeditee.gui.Frame;
    2424import org.expeditee.gui.FrameIO;
     25import org.expeditee.items.Item;
    2526import org.expeditee.items.Text;
    2627import org.expeditee.settings.UserSettings;
     
    2930
    3031public class Actions implements CryptographyConstants {
     32       
     33        public static void TestSurrogate(Item classic) {
     34                System.out.println("Test surrogates: ");
     35        }
    3136       
    3237        public static Text GenerateSecret(String label) {
  • trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java

    r1401 r1408  
    77import java.io.InputStreamReader;
    88import java.io.Reader;
    9 import java.io.UnsupportedEncodingException;
     9import java.lang.reflect.Method;
    1010import java.security.InvalidKeyException;
    1111import java.security.NoSuchAlgorithmException;
     12import java.util.ArrayList;
    1213import java.util.Arrays;
    1314import java.util.Base64;
    14 import java.util.Collection;
     15import java.util.List;
     16import java.util.function.Predicate;
    1517
    1618import javax.crypto.BadPaddingException;
     
    2426import org.expeditee.encryption.Label;
    2527import org.expeditee.encryption.Label.LabelResult;
     28import org.expeditee.encryption.items.surrogates.EncryptionDetail;
     29import org.expeditee.encryption.items.surrogates.Surrogate;
    2630import org.expeditee.gui.Frame;
     31import org.expeditee.gui.FrameIO;
     32import org.expeditee.io.Conversion;
    2733import org.expeditee.io.ExpReader;
    2834import org.expeditee.items.Item;
     
    3137
    3238public class EncryptedExpReader extends ExpReader implements CryptographyConstants {
    33         static final String ENCRYPTED_EXP_FLAG = "EncryptedExp";
     39        private static final String ENCRYPTED_EXP_FLAG = "EncryptedExp";
     40        private static final String labelProfile = "Profile";
     41        private static final String labelNone = "None";
    3442        private SecretKey personalKey;
    3543        private boolean accessDenied = false;
    3644
    37         public EncryptedExpReader(final String frameName) throws UnsupportedEncodingException {
     45        public EncryptedExpReader(String frameName) {
    3846                super(frameName);
    3947        }
    40        
     48
    4149        public static boolean isEncryptedExpediteeFile(final String path) throws IOException {
    4250                final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
     
    7482       
    7583        @Override
    76         public Frame readFrame(final BufferedReader reader) throws IOException {
     84        public Frame readFrame(BufferedReader reader) throws IOException {
    7785                if (accessDenied) { return null; }
    78                 else {
    79                         Frame unencryptedFrame = super.readFrame(reader);
    80                         individualItemDecryption(unencryptedFrame);
    81                         return unencryptedFrame;
    82                 }
    83         }
    84        
    85         private void individualItemDecryption(Frame frame) {
    86                 // Find items with their own encryption label.
    87                 Collection<Item> itemsWithEncryptionLabel = frame.getAllItems();
    88                 itemsWithEncryptionLabel.removeIf(i -> i.getEncryptionLabel() == null || i.getEncryptionLabel().isEmpty());
    89                
    90                 for (Item i: itemsWithEncryptionLabel) {
    91                         // Decrypt the Text Items
    92                         if (i instanceof Text) {
    93                                 LabelResult res = Label.resolveKey(i.getEncryptionLabel());
    94                                 if (res == LabelResult.SuccessResolveLabelToKey) {
    95                                         byte[] keyBytes = res.key;
    96                                         if (keyBytes == null) { continue; }
    97                                         SecretKeySpec key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
    98                                         byte[] decryptedBytes = DecryptSymmetric(Base64.getDecoder().decode(i.getText()), key);
    99                                         i.setText(new String(decryptedBytes));
    100                                 }
    101                         }
     86               
     87                _reader = reader;
     88                String next = "";
     89                Frame newFrame = new Frame();
     90                List<DelayedAction> delayedActions = new ArrayList<DelayedAction>();
     91                newFrame.setName(_frameName);
     92               
     93                try {
     94                        // First read all the header lines
     95                        next = readTheHeader(newFrame);
     96                       
     97                        // Now read all the items
     98                        next = readTheItems(newFrame, delayedActions);
     99                       
     100                        // Read the lines
     101                        next = readTheLines(newFrame);
     102
     103                        // Read the constraints
     104                        next = readTheConstraints();
     105                       
     106                        for(DelayedAction action: delayedActions) {
     107                                action.exec();
     108                        }
     109
     110                        // Read the stats
     111                        next = readTheStats(newFrame);
     112                } catch (Exception e) {
     113                        e.printStackTrace();
     114                        System.out.println("Error reading frame file line: " + next + " " + e.getMessage());
     115                }
     116               
     117                _reader.close();
     118                FrameIO.setSavedProperties(newFrame);
     119                newFrame.setChanged(false);
     120
     121                return newFrame;
     122        }
     123       
     124        @Override
     125        protected String readTheItems(Frame newFrame, List<DelayedAction> delayedActions) throws IOException {
     126                String next = null;
     127                Item currentItem = null;
     128               
     129                Predicate<String> endOfSection = s -> s.equals("Z") || s.equals("Z...");
     130                while (_reader.ready() && !endOfSection.test(next = _reader.readLine())) {
     131                        if (!isValidLine(next)) {
     132                                continue;
     133                        }
     134                        String tag = getTagEnc(next);
     135                        if (tag.equals("S")) {
     136                                currentItem = newItem(next);
     137                                _linePoints.put(currentItem.getID(), currentItem);
     138                                newFrame.addItem(currentItem);
     139                                currentItem.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave);
     140                        } else if (currentItem != null && actionShouldBeDelayed(tag.charAt(0))) {
     141                                delayedActions.add(new DelayedAction(currentItem, next));
     142                        } else if (currentItem != null) {
     143                                processBodyLine(currentItem, next);
     144                        } else {
     145                                System.err.println("Error while reading in frame (ExpReader): Found body line but no current item to apply it to.");
     146                        }
     147                }
     148               
     149                if (next.equals("Z...")) {
     150                        next = readTheSurrogateItems(newFrame, delayedActions);
     151                }
     152               
     153                return next;
     154        }
     155       
     156        @Override
     157        protected void processBodyLine(Item item, String line) {
     158                // separate the tag from the value
     159                String tag = getTagEnc(line);
     160                String value = getValue(line);
     161               
     162                // Attempt to decrypt the line if necessary.
     163                if (isEncryptedLine(line)) {
     164                        LabelResult res = Label.resolveKey(item.getEncryptionLabel());
     165                        if (res == LabelResult.SuccessResolveLabelToKey) {
     166                                item.setEncryptionDetailForTag(tag, EncryptionDetail.ReencryptOnSave);
     167                                SecretKey key = new SecretKeySpec(res.key, SymmetricAlgorithm);
     168                                byte[] decryptedBytes = DecryptSymmetric(Base64.getDecoder().decode(value), key);
     169                                value = new String(decryptedBytes);                             
     170                        } else {
     171                                EncryptionDetail encryptionDetail = EncryptionDetail.UseUndecipheredValueOnSave.setUndecipheredValue(getValue(line));
     172                                item.setEncryptionDetailForTag(tag, encryptionDetail);
     173                                return;
     174                        }
     175                } else {
     176                        item.setEncryptionDetailForTag(tag, EncryptionDetail.UnencryptedOnSave);
     177                }
     178               
     179                // Process the line
     180                Method toRun = tag.startsWith("_") ? _ItemTagsExt.get(tag) : _ItemTags.get(tag.charAt(0));
     181                if (toRun == null) {
     182                        System.out.println("Error accessing tag method: " + tag);
     183                }
     184                Object[] vals = Conversion.Convert(toRun, value);
     185                try {
     186                        if (vals != null) {
     187                                toRun.invoke(item, vals);
     188                        }
     189                } catch (Exception e) {
     190                        System.out.println("Error running tag method: " + tag);
     191                        e.printStackTrace();
     192                }
     193        }
     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       
     240        protected static String getValue(String line) {
     241                String[] split = line.split(" ");
     242                if (split.length >= 2) {
     243                        return line.substring(split[0].length()).trim();
     244                } else {
     245                        return null;
     246                }
     247        }
     248       
     249        protected static boolean isEncryptedLine(String line) {
     250                if (line.startsWith("S") || line.startsWith("_el")) {
     251                        return false;
     252                }               
     253                if (line.length() > 2) {
     254                        return line.charAt(1) == 'E';
     255                } else {
     256                        return false;
    102257                }
    103258        }
     
    125280       
    126281        private class EncryptedLineReader extends BufferedReader {
     282                private boolean noneMode = false;
     283               
    127284                public EncryptedLineReader(Reader in) {
    128285                        super(in);
     
    140297                                return "";
    141298                        }
     299                       
     300                        if (noneMode) {
     301                                return line;
     302                        }
     303                       
    142304                        if (line.startsWith(ENCRYPTED_EXP_FLAG)) {
    143305                                String label = line.replace(ENCRYPTED_EXP_FLAG, "");
    144306                                // if using Profile label, use personal key
    145                                 if (label.startsWith("Profile")) {
     307                                if (label.equals(labelProfile)) {
    146308                                        Text text = KeyList.PersonalKey.get();
    147309                                        byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0));
    148310                                        personalKey = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
     311                                        return readLine();
     312                                } else if (label.equals(labelNone)) {
     313                                        noneMode = true;
    149314                                        return readLine();
    150315                                } else {
  • trunk/src/org/expeditee/encryption/io/EncryptedExpWriter.java

    r1401 r1408  
    22
    33import java.io.IOException;
     4import java.lang.reflect.InvocationTargetException;
     5import java.lang.reflect.Method;
    46import java.security.InvalidKeyException;
    57import java.security.NoSuchAlgorithmException;
     8import java.util.ArrayList;
    69import java.util.Arrays;
    710import java.util.Base64;
    8 import java.util.Collection;
     11import java.util.LinkedHashMap;
    912import java.util.List;
     13import java.util.function.Consumer;
    1014
    1115import javax.crypto.BadPaddingException;
     
    1923import org.expeditee.encryption.Label;
    2024import org.expeditee.encryption.Label.LabelResult;
     25import org.expeditee.encryption.items.surrogates.EncryptionDetail;
     26import org.expeditee.encryption.items.surrogates.Surrogate;
    2127import org.expeditee.gui.Frame;
    2228import org.expeditee.gui.MessageBay;
     29import org.expeditee.io.Conversion;
    2330import org.expeditee.io.ExpWriter;
    2431import org.expeditee.items.Item;
     32import org.expeditee.items.Line;
    2533import org.expeditee.items.Text;
    2634import org.expeditee.settings.identity.secrets.KeyList;
     35import org.expeditee.stats.SessionStats;
    2736
    2837public class EncryptedExpWriter extends ExpWriter implements CryptographyConstants {
    2938        private SecretKey key;
    30         private String label;
     39       
     40        private final String label;
     41       
     42        private static final String ENCRYPTED_EXP_FLAG = "EncryptedExp";
    3143        private static final String nl = "\n";
    32        
    33         public EncryptedExpWriter(String encryptionLabel) throws IOException {
    34                 if (encryptionLabel.compareTo("Profile") == 0) {
     44        private static final String labelProfile = "Profile";
     45        private static final String labelNone = "None";
     46        protected static final String SURROGATE_TERMINATOR = TERMINATOR + "...";
     47
     48        public EncryptedExpWriter(String encryptionLabel) {
     49                label = encryptionLabel;
     50                if (label.equals(labelNone)) {
     51                        return;
     52                }
     53               
     54                if (label.equals(labelProfile)) {
    3555                        // obtain personal key
    3656                        Text text = KeyList.PersonalKey.get();
     
    4060                                key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
    4161                        }
    42                         label = "Profile";
    4362                } else {
    44                         LabelResult res = Label.resolveKey(encryptionLabel);
     63                        LabelResult res = Label.resolveKey(label);
    4564                        if (res == LabelResult.SuccessResolveLabelToKey) {
    4665                                byte[] keyBytes = res.key;
    4766                                key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
    48                                 label = encryptionLabel;
    4967                        } else if (res == LabelResult.ErrorUnableToFindLabel) {
    5068                                MessageBay.errorMessage(res.toString() + encryptionLabel);
     69                                key = null;
    5170                        } else {
    5271                                MessageBay.errorMessage(res.toString());
     
    5473                }
    5574        }
    56 
     75       
     76        @Override
     77        public void outputFrame(Frame frame) throws IOException {
     78                if (_writer == null) { return; }
     79               
     80                preOutputFrame();
     81                writeHeader(frame);
     82               
     83                // write item
     84                writeItemData(frame);
     85                writeTerminator();
     86               
     87                // write lines and constraints
     88                writeLineData();
     89                writeTerminator();
     90                writeConstraintData();
     91                writeTerminator();
     92               
     93                writeLine(SessionStats.getFrameEventList(frame));
     94        }
     95       
    5796        @Override
    5897        protected void preOutputFrame() {
    5998                try {
    60                         String line = EncryptedExpReader.ENCRYPTED_EXP_FLAG + label + nl;
     99                        String line = ENCRYPTED_EXP_FLAG + label + nl;
    61100                        _writer.write(line);
    62101                        _stringWriter.append(line);
     
    67106       
    68107        @Override
    69         public void outputFrame(Frame frame) throws IOException {
    70                 individualItemEncryption(frame);
    71                 super.outputFrame(frame);
    72         }
    73        
    74         @Override
    75108        protected void writeLine(String line) throws IOException {
    76109                // do not write empty lines
    77110                if (line == null) { return; }
    78111               
    79                 // prepare line to write out
    80                 byte[] encrypted = EncryptSymmetric(line.getBytes(), key);
    81                 String toWrite = Base64.getEncoder().encodeToString(encrypted) + nl;
    82                
     112                String toWrite;
     113                if (key == null && label.equals(labelNone)) {
     114                        toWrite = line + nl;
     115                } else {
     116                        // prepare line to write out
     117                        byte[] encrypted = EncryptSymmetric(line.getBytes(), key);
     118                        toWrite = Base64.getEncoder().encodeToString(encrypted) + nl;
     119                }
     120                               
    83121                // output
    84122                _writer.write(toWrite);
     
    86124        }
    87125       
    88         private void individualItemEncryption(Frame frame) {
    89                 // Find items with their own encryption label.
    90                 Collection<Item> itemsWithEncryptionLabel = frame.getAllItems();
    91                 itemsWithEncryptionLabel.removeIf(i -> i.getEncryptionLabel() == null || i.getEncryptionLabel().isEmpty());
    92                
    93                 for (Item i: itemsWithEncryptionLabel) {
    94                         // Encrypt the Text Items
    95                         if (i instanceof Text) {
    96                                 LabelResult res = Label.resolveKey(i.getEncryptionLabel());
    97                                 if (res == LabelResult.SuccessResolveLabelToKey) {
    98                                         byte[] keyBytes = res.key;
    99                                         if (keyBytes == null) { continue; }
    100                                         SecretKeySpec key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
    101                                         byte[] encryptedBytes = EncryptSymmetric(i.getText().getBytes(), key);
    102                                         i.setText(Base64.getEncoder().encodeToString(encryptedBytes));
     126        @Override
     127        protected void writeLineData() throws IOException {
     128                super.writeLineData();
     129               
     130                writeSurrogateLineData();
     131        }
     132       
     133        @Override
     134        protected void writeClass(Item toWrite) throws IOException {
     135                LinkedHashMap<Character,Method> itemTags = new LinkedHashMap<Character, Method>(getItemTags());
     136                LinkedHashMap<String,Method> itemTagsExt = new LinkedHashMap<String, Method>(getItemTagsExt());
     137               
     138                writeTag(toWrite, new Object[] {}, itemTags, 'S');
     139                writeTag(toWrite, new Object[] {}, itemTagsExt, "_el");
     140               
     141                itemTags.remove('S');
     142                itemTagsExt.remove("_el");
     143               
     144                writeTags(toWrite, new Object[] {}, itemTags);
     145                writeTags(toWrite, new Object[] {}, itemTagsExt);
     146        }
     147       
     148        @Override
     149        protected <T> void writeTag(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags, T tag) {
     150                EncryptionDetail encryptionDetail = toWrite.getEncryptionDetailForTag(tag + "");
     151                switch (encryptionDetail) {
     152                case UnencryptedOnSave:
     153                        super.writeTag(toWrite, param, tags, tag);
     154                        break;
     155                case ReencryptOnSave:
     156                        Method toRun = tags.get(tag);
     157                        Class<?> declarer = toRun.getDeclaringClass();
     158                        LabelResult res = Label.resolveKey(toWrite.getEncryptionLabel());
     159                        if (declarer.isAssignableFrom(toWrite.getClass()) && res == LabelResult.SuccessResolveLabelToKey) {
     160                                SecretKey key = new SecretKeySpec(res.key, SymmetricAlgorithm);
     161                                try {
     162                                        Object o = toRun.invoke(toWrite, new Object[] {});
     163                                        o = Conversion.ConvertToExpeditee(toRun, o);
     164                                        if (o != null) {
     165                                                if (o instanceof List) {
     166                                                        for (Object line: (List<?>)o) {
     167                                                                byte[] encryptedBytes = EncryptSymmetric(line.toString().getBytes(), key);
     168                                                                writeLine(tag + "E", Base64.getEncoder().encodeToString(encryptedBytes));
     169                                                        }
     170                                                } else {
     171                                                        byte[] encryptedBytes = EncryptSymmetric(o.toString().getBytes(), key);
     172                                                        writeLine(tag + "E", Base64.getEncoder().encodeToString(encryptedBytes));
     173                                                }
     174                                        }
     175                                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
     176                                        e.printStackTrace();
     177                                } catch (IOException e) {
     178                                        e.printStackTrace();
    103179                                }
    104180                        }
    105                 }
    106         }
    107        
    108 //      protected static byte[] resolveKeyFromLabel(String label, String framename) {
    109 //              String credentialsFrameName = UserSettings.ProfileName.get() + AuthenticatorBrowser.CREDENTIALS_FRAME;
    110 //              Frame credentialsFrame = FrameIO.LoadFrame(credentialsFrameName);
    111 //              Collection<Text> textItems = credentialsFrame.getTextItems();
    112 //              textItems.removeIf(t -> !t.getText().equals("Secrets"));
    113 //              textItems.removeIf(t -> !t.hasLink());
    114 //              if (textItems.isEmpty()) {
    115 //                      MessageBay.errorMessage("Unable to find label " + label + " to encrypt frame " + framename + ".");
    116 //                      return null;
    117 //              } else {
    118 //                      Text linkToSecretsFrame = textItems.iterator().next();
    119 //                      Frame secretsFrame = FrameIO.LoadFrame(linkToSecretsFrame.getParent().getFramesetName() + linkToSecretsFrame.getLink());
    120 //                      Collection<Text> labels = secretsFrame.getTextItems();
    121 //                      labels.removeIf(lbl -> !lbl.getText().equals(label));
    122 //                      labels.removeIf(lbl -> lbl.getData() == null || lbl.getData().size() == 0);
    123 //                      if (labels.isEmpty()) {
    124 //                              MessageBay.errorMessage("Unable to find label " + label + " to encrypt frame " + framename + ".");
    125 //                              return null;
    126 //                      }
    127 //                     
    128 //                      Text labelItem = labels.iterator().next();
    129 //                      String data = labelItem.getData().get(0);
    130 //                      if (data.contains("{")) {
    131 //                              MessageBay.errorMessage("You only have a fraction of the required key to access " + framename + ".");
    132 //                              return null;
    133 //                      } else {
    134 //                              try {
    135 //                                      return Base64.getDecoder().decode(data);
    136 //                              } catch (IllegalArgumentException e) {
    137 //                                      MessageBay.errorMessage("Unable to create key out of data stored in label " + label + ".");
    138 //                                      return null;
    139 //                              }
    140 //                      }
    141 //              }
    142 //      }
     181                        break;
     182                case UseUndecipheredValueOnSave:
     183                        try {
     184                                writeLine(tag + "E", encryptionDetail.getUndecipheredValue());
     185                        } catch (IOException e) {
     186                                e.printStackTrace();
     187                        }
     188                        break;
     189                }
     190        }
     191       
     192        private void writeItemData(Frame frame) throws IOException {
     193                // write each item in the frame
     194                for (Item i : frame.getItemsToSave()) {
     195                        assert (!(i instanceof Line));
     196                        writeItem(i);
     197                }
     198               
     199                for (final Item i: frame.getBodyItemsWithInsufficientPermissions()) {
     200                        assert (!(i instanceof Line));
     201                        writeItem(i);
     202                }
     203               
     204                writeSurrogateItemsData(frame);
     205        }
     206       
     207        private void writeSurrogateItemsData(Frame frame) throws IOException {
     208                List<Surrogate> surrogates = new ArrayList<Surrogate>();
     209               
     210                Consumer<? super Item> store = item -> surrogates.addAll(item.getSurrogates());
     211                frame.getItemsToSave().forEach(store);
     212                frame.getBodyItemsWithInsufficientPermissions().forEach(store);
     213               
     214                if (!surrogates.isEmpty()) {
     215                        // If there is some surrogates, write the surrogate
     216                        // terminator, then write out the surrogates.
     217                        writeSurrogateTerminator();
     218                       
     219                        for (Surrogate surrogate: surrogates) {
     220                                String output = surrogate.toString();
     221                                writeLine(output);
     222                        }
     223                }
     224        }
     225
     226        private void writeSurrogateLineData() throws IOException {
     227                List<Surrogate> surrogateLines = new ArrayList<Surrogate>();
     228               
     229                for(Item lineEnd: _lineEnds) {
     230                        List<Line> lines = lineEnd.getLines();
     231                        for (Line line: lines) {
     232                                surrogateLines.addAll(line.getSurrogates());
     233                        }
     234                }
     235               
     236                if (!surrogateLines.isEmpty()) {
     237                        // If there is some surrogates, write the surrogate
     238                        // terminator, then write out the surrogates.
     239                        writeSurrogateTerminator();
     240                       
     241                        for (Surrogate surrogate: surrogateLines) {
     242                                String output = surrogate.toString();
     243                                writeLine(output);
     244                        }
     245                }
     246        }
     247       
     248        private void writeSurrogateTerminator() throws IOException {
     249                writeLine(SURROGATE_TERMINATOR + nl);
     250        }
    143251       
    144252        private static byte[] EncryptSymmetric(byte[] toEncrypt, SecretKey key) {
     
    156264                        return null;
    157265                }
    158         }
     266        }       
    159267}
  • trunk/src/org/expeditee/gui/Frame.java

    r1407 r1408  
    7777 *
    7878 */
    79 public class Frame {
     79public class Frame /*implements Cloneable*/ {
    8080       
    8181        /** The frame number to indicate this is a virtual frame. */
     
    187187        public Frame() {
    188188        }
     189       
     190//      public Frame clone() {
     191//              Frame clone = new Frame();
     192//              for (Item i: this._body) {
     193//                      Item copy = i.copy();
     194//                      copy.setID(i.getID()); 
     195//                      clone._body.add(copy);
     196//              }
     197//              for(Item i: this._bodyHiddenDueToPermissions) {
     198//                      Item copy = i.copy();
     199//                      copy.setID(i.getID());
     200//                      clone._bodyHiddenDueToPermissions.add(i);
     201//              }
     202//              if (this._frameName != null) {
     203//                      clone._frameName = this._frameName.copy();
     204//              }
     205//              for(Overlay key: this._overlays.keySet()) {
     206//                      clone._overlays.put(key, this._overlays.get(key));
     207//              }
     208//              for(Vector v: this._vectors) {
     209//                      clone._vectors.add(v);
     210//              }
     211//              for (Item i: this._interactableItems) {
     212//                      clone._interactableItems.add(i.copy());
     213//              }
     214//              for (Item i: this._overlayItems) {
     215//                      clone._overlayItems.add(i.copy());
     216//              }
     217//              for (Item i: this._vectorItems) {
     218//                      clone._vectorItems.add(i.copy());
     219//              }
     220//              clone._frameData = this._frameData;
     221//              clone._frameset = this._frameset;
     222//              clone._number = this._number;
     223//              clone._version = this._version;
     224//              clone._permissionTriple = this._permissionTriple;
     225//              clone._owner = this._owner;
     226//              clone._creationDate = this._creationDate;
     227//              clone._modifiedUser = this._modifiedUser;
     228//              clone._modifiedDate = this._modifiedDate;
     229//              clone._modifiedDatePrecise = this._modifiedDatePrecise;
     230//              clone._frozenDate = this._frozenDate;
     231//              clone._background = this._background;
     232//              clone._foreground = this._foreground;
     233//              clone.path = this.path;
     234//              clone._isLocal = this._isLocal;
     235//              clone._sorted = this._sorted;
     236//              clone._change = this._change;
     237//              clone._saved = this._saved;
     238//              clone._lineCount = this._lineCount;
     239//              clone._itemCount = this._itemCount;
     240//              clone._buffer = this._buffer;
     241//              clone._validBuffer = this._validBuffer;
     242//              clone._activeTime = (Time) this._activeTime.clone();
     243//              clone._darkTime = (Time) this._darkTime.clone();
     244//              clone._dotTemplate = this._dotTemplate.copy();
     245//             
     246//              return clone;
     247//      }
    189248
    190249        public boolean isReadOnly()
     
    233292                return _validBuffer;
    234293        }
    235 
     294       
    236295        private void setBufferValid(boolean newValue)
    237296        {
  • trunk/src/org/expeditee/io/DefaultFrameReader.java

    r1405 r1408  
    181181                        _DelayedItemTags.add('/');
    182182                       
    183                         _ItemTagsExt.put("_el", Item.class.getMethod("setEncryptionLabel", pString));
     183                        _ItemTagsExt.put("_el", Item.class.getMethod("setEncryptionLabelOnLoad", pString));
    184184                       
    185185                        _ItemTagsExt.put("_ph", Text.class.getMethod("setPlaceholder", pString));
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r1405 r1408  
    5555
    5656        // keep track of methods that are put on the same line
    57         protected static LinkedHashMap<Character, Method> _ItemTags = null;
     57        private static LinkedHashMap<Character, Method> _ItemTags = null;
    5858        // IMPORTANT: keys in _ItemTagsExt must start with underscore as their first character
    59         protected static LinkedHashMap<String, Method> _ItemTagsExt = null;
     59        private static LinkedHashMap<String, Method> _ItemTagsExt = null;
    6060
    6161        protected static LinkedHashMap<Character, Method> _FrameTags = null;
     
    319319        }
    320320
     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
    321335}
  • trunk/src/org/expeditee/io/ExpReader.java

    r1321 r1408  
    4848        public static final String EXTENTION = ".exp";
    4949
    50         private BufferedReader _reader = null;
    51 
    52         private String _frameName;
     50        protected BufferedReader _reader = null;
     51
     52        protected String _frameName;
    5353
    5454        /**
     
    128128                        newFrame.setName(_frameName);
    129129
    130                         final List<DelayedAction> delayedActions = new LinkedList<DelayedAction>();
     130                        List<DelayedAction> delayedActions = new LinkedList<DelayedAction>();
    131131                       
    132132                        // 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);
    138134
    139135                        // 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);
    174137
    175138                        // 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);
    198140
    199141                        // 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();
    216143                       
    217144                        for(DelayedAction action: delayedActions) {
     
    220147
    221148                        // 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);
    239150
    240151                } catch (Exception e) {
     
    252163        }
    253164
    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 {
    255284                private Item theItem;
    256285                private String theLine;
    257286
    258                 DelayedAction(final Item theItem, final String theLine) {
     287                public DelayedAction(final Item theItem, final String theLine) {
    259288                        this.theItem = theItem;
    260289                        this.theLine = theLine;
    261290                }
    262291               
    263                 void exec() {
     292                public void exec() {
    264293                        processBodyLine(theItem, theLine);
    265294                }
     
    267296       
    268297        // Stores points used when constructing lines
    269         private HashMap<Integer, Item> _linePoints = new HashMap<Integer, Item>();
     298        protected HashMap<Integer, Item> _linePoints = new HashMap<Integer, Item>();
    270299
    271300        /**
  • trunk/src/org/expeditee/io/ExpWriter.java

    r1326 r1408  
    2828import java.lang.reflect.Method;
    2929import java.util.Iterator;
     30import java.util.LinkedHashMap;
    3031import java.util.LinkedList;
    3132import java.util.List;
     
    5354        protected String _framename;
    5455
    55         private static final char TERMINATOR = 'Z';
     56        protected static final char TERMINATOR = 'Z';
    5657
    5758        public ExpWriter() {
     
    8788                try {
    8889                        _FrameTags.remove('A');
    89                         _ItemTags.put('S', Item.class.getMethod("getTypeAndID",
     90                        getItemTags().put('S', Item.class.getMethod("getTypeAndID",
    9091                                        new Class[] {}));
    9192                } catch (Exception e) {
     
    130131                writeTerminator();
    131132                writeLine(SessionStats.getFrameEventList(frame));
    132 
    133                 return;
    134133        }
    135134
     
    137136        }
    138137
    139         private void writeHeader(Frame toWrite) throws IOException {
     138        protected void writeHeader(Frame toWrite) throws IOException {
    140139                Iterator<Character> it = _FrameTags.keySet().iterator();
    141140                Object[] param = {};
     
    185184//      }
    186185
    187         private void writeLine(String tag, String line) throws IOException {
     186        protected void writeLine(String tag, String line) throws IOException {
    188187                writeLine(tag + " " + line);
    189188        }
     
    227226        }
    228227
    229         private List<Item> _lineEnds = new LinkedList<Item>();
     228        protected List<Item> _lineEnds = new LinkedList<Item>();
    230229
    231230        // Writes out a LineEnd to the file
     
    306305        }
    307306
    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();
    313314                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());
    331334                                }
    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();
    354337                        }
    355338                }
  • trunk/src/org/expeditee/io/KMSWriter.java

    r919 r1408  
    8181                try {
    8282                        _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[] {}));
    8484                } catch (Exception e) {
    8585
     
    258258
    259259        private void writeClass(Object toWrite) throws IOException {
    260                 Iterator<Character> it = _ItemTags.keySet().iterator();
     260                Iterator<Character> it = getItemTags().keySet().iterator();
    261261                Object[] param = {};
    262262
    263263                while (it.hasNext()) {
    264264                        Character tag = it.next();
    265                         Method toRun = _ItemTags.get(tag);
     265                        Method toRun = getItemTags().get(tag);
    266266                        Class<?> declarer = toRun.getDeclaringClass();
    267267                        if (declarer.isAssignableFrom(toWrite.getClass())) {
  • trunk/src/org/expeditee/items/Item.java

    r1407 r1408  
    2222import java.util.Collection;
    2323import java.util.ConcurrentModificationException;
     24import java.util.HashMap;
    2425import java.util.HashSet;
    2526import java.util.LinkedHashSet;
    2627import java.util.LinkedList;
    2728import java.util.List;
     29import java.util.Map;
     30import java.util.Set;
    2831
    2932import org.expeditee.actions.Actions;
     
    4447import org.expeditee.core.bounds.EllipticalBounds;
    4548import org.expeditee.core.bounds.PolygonBounds;
     49import org.expeditee.encryption.items.surrogates.EncryptionDetail;
     50import org.expeditee.encryption.items.surrogates.Surrogate;
    4651import org.expeditee.gio.EcosystemManager;
    4752import org.expeditee.gio.GraphicsManager;
     
    5762import org.expeditee.gui.Vector;
    5863import org.expeditee.io.Conversion;
     64import org.expeditee.io.DefaultFrameWriter;
    5965import org.expeditee.settings.UserSettings;
    6066import org.expeditee.settings.legacy.LegacyFeatures;
     
    312318        private Data _data = new Data();
    313319
     320        private Item surrogateFor = null;
     321        private Set<Surrogate> surrogateItems = new HashSet<Surrogate>();
     322        private Map<String, EncryptionDetail> propertyEncryption = new HashMap<String, EncryptionDetail>();
     323       
    314324        /** Just calls source.duplicateOnto(dest). */
    315325        public static void DuplicateItem(Item source, Item dest)
     
    34593469        public void setEncryptionLabel(String label) {
    34603470                this._encryptionLabel = label;
     3471                if (this.getSurrogates().isEmpty()) {
     3472                        Surrogate surrogate = Surrogate.forItem(this);
     3473                        this.addToSurrogates(surrogate);
     3474                }
     3475               
     3476                for (Character tag: DefaultFrameWriter.getItemTags().keySet()) {
     3477                        if (tag == 'S') {
     3478                                propertyEncryption.put(tag + "", EncryptionDetail.UnencryptedOnSave);
     3479                        } else {
     3480                                propertyEncryption.put(tag + "", EncryptionDetail.ReencryptOnSave);
     3481                        }
     3482                }
     3483               
     3484                for (String tag: DefaultFrameWriter.getItemTagsExt().keySet()) {
     3485                        if (tag == "_el") {
     3486                                propertyEncryption.put(tag, EncryptionDetail.UnencryptedOnSave);
     3487                        } else {
     3488                                propertyEncryption.put(tag, EncryptionDetail.ReencryptOnSave);
     3489                        }
     3490                }
     3491        }
     3492       
     3493        public void setEncryptionLabelOnLoad(String label) {
     3494                this._encryptionLabel = label;
     3495               
     3496                for (Character tag: DefaultFrameWriter.getItemTags().keySet()) {
     3497                        if (tag == 'S') {
     3498                                propertyEncryption.put(tag + "", EncryptionDetail.UnencryptedOnSave);
     3499                        } else {
     3500                                propertyEncryption.put(tag + "", EncryptionDetail.ReencryptOnSave);
     3501                        }
     3502                }
     3503               
     3504                for (String tag: DefaultFrameWriter.getItemTagsExt().keySet()) {
     3505                        if (tag == "_el") {
     3506                                propertyEncryption.put(tag, EncryptionDetail.UnencryptedOnSave);
     3507                        } else {
     3508                                propertyEncryption.put(tag, EncryptionDetail.ReencryptOnSave);
     3509                        }
     3510                }
    34613511        }
    34623512
     
    35113561                return dot;
    35123562        }
     3563
     3564        public Set<Surrogate> getSurrogates() {
     3565                return surrogateItems;
     3566        }
     3567               
     3568        public void setAsSurrogateFor(Item classic) {
     3569                this.surrogateFor = classic;
     3570        }
     3571
     3572        public void addToSurrogates(Surrogate surrogate) {
     3573                this.surrogateItems.add(surrogate);
     3574        }
     3575       
     3576        public boolean isSurrogate() {
     3577                return this.surrogateFor != null;
     3578        }
     3579       
     3580        public Item getClassic() {
     3581                return this.surrogateFor;
     3582        }
     3583       
     3584        public EncryptionDetail getEncryptionDetailForTag(String tag) {
     3585                EncryptionDetail encryptionDetail = propertyEncryption.get(tag);
     3586               
     3587                if (encryptionDetail == null) {
     3588                        return EncryptionDetail.UnencryptedOnSave;
     3589                } else {
     3590                        return encryptionDetail;
     3591                }
     3592        }
     3593       
     3594        public void setEncryptionDetailForTag(String tag, EncryptionDetail encryptionDetail) {
     3595                propertyEncryption.put(tag, encryptionDetail);
     3596        }
    35133597}
Note: See TracChangeset for help on using the changeset viewer.