source: trunk/src/org/expeditee/io/DefaultFrameReader.java@ 1505

Last change on this file since 1505 was 1505, checked in by bnemhaus, 4 years ago

New Attributes (and repurposed old ones) to be used for encryption of frames:

  • FrameEncryptionLabel. Used to be EncryptionLabel, which is still the case for items. When applied to a frame, it determines the label used to encrypt the entire frame.
  • HomogeneousEncryptionLabel. Does not yet actually do anything. The future point of this attribute is to provide the label that must be used to encrypt items on the frame when the user has only homogeneous encryption permissions.
  • EncryptionFramePermission. Does not yet actually do anything. The future point of this attribute isto determine if a user is able to change the FrameEncryptionLabel on a frame. Level 0 (none), no they cannot. Level 1 (homogeneous), they can only change it to HomogeneousEncryptionLabel. Level 2 (Hetrogeneous Owner), they can change it to any label as long as the owner of the Frame has that label. Level 3 (Hetrogeneous), they can change it to anything.
  • EncryptionPermission. Does not yet actually do anything. The future point of this attribute is to determine what encryption labels can be applied to items on the frame. Level 0 (none), cannot apply an encryption label. Level 1 (homogeneous), they can only used the label specified in HomogeneousEncryptionLabel. Level 2 (Hetrogeneous Owner), they can only use encryption labels that the owner of the frame has. Level 3 (Hetrogeneous) they can use any labels to encrypt an item.
File size: 11.1 KB
Line 
1/**
2 * DefaultFrameReader.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io;
20
21import java.io.BufferedReader;
22import java.io.File;
23import java.io.FileInputStream;
24import java.io.IOException;
25import java.io.InputStreamReader;
26import java.io.Reader;
27import java.lang.reflect.Method;
28import java.util.LinkedHashMap;
29import java.util.List;
30import java.util.LinkedList;
31
32import org.expeditee.core.Colour;
33import org.expeditee.core.Font;
34import org.expeditee.core.Point;
35import org.expeditee.encryption.items.EncryptionPermissionTriple;
36import org.expeditee.gui.Frame;
37import org.expeditee.items.Constraint;
38import org.expeditee.items.Dot;
39import org.expeditee.items.DotType;
40import org.expeditee.items.Item;
41import org.expeditee.items.Justification;
42import org.expeditee.items.Line;
43import org.expeditee.items.PermissionTriple;
44import org.expeditee.items.Text;
45
46public abstract class DefaultFrameReader implements FrameReader {
47
48 protected static LinkedHashMap<Character, Method> _ItemTags = null;
49 // IMPORTANT: keys in _ItemTagsExt must start with underscore as their first character
50 protected static LinkedHashMap<String, Method> _ItemTagsExt = null;
51
52 protected static List<Character> _DelayedItemTags = null;
53
54 protected static LinkedHashMap<Character, Method> _FrameTags = null;
55
56 protected static Class[] pString = { String.class };
57 protected static Class[] pInt = { int.class };
58 protected static Class[] pIntO = { Integer.class };
59 protected static Class[] pFloat = { float.class };
60 protected static Class[] pFloatO = { Float.class };
61 protected static Class[] pDouble = { double.class };
62 protected static Class[] pColor = { Colour.class };
63 protected static Class[] pBool = { boolean.class };
64 protected static Class[] pFont = { Font.class };
65 protected static Class[] pPoint = { Point.class };
66 protected static Class[] pArrow = { float.class, double.class, double.class };
67 protected static Class[] pList = { List.class };
68 protected static Class[] pIntArray = { int[].class };
69 protected static Class[] pItem = { Item.class };
70 protected static Class[] pJustification = { Justification.class };
71 protected static Class[] pPermission = { PermissionTriple.class };
72 protected static Class[] pDotType = { DotType.class };
73 protected static Class[] pEncPermission = { EncryptionPermissionTriple.class };
74
75 public DefaultFrameReader(){
76 if (_ItemTags != null && _FrameTags != null)
77 return;
78
79 _ItemTags = new LinkedHashMap<Character, Method>();
80 _ItemTagsExt = new LinkedHashMap<String, Method>();
81 _FrameTags = new LinkedHashMap<Character, Method>();
82 _DelayedItemTags = new LinkedList<Character>();
83
84 try {
85 /// C H I J L N P Q R S W X Y Z
86 /// a b c f g h i j l m n o q r s t u v w x y z
87 // Standard frame tags
88 _FrameTags.put('A', Frame.class.getMethod("setName", pString));
89 _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt));
90 _FrameTags.put('p', Frame.class.getMethod("setPermission", pPermission));
91 _FrameTags.put('U', Frame.class.getMethod("setOwner", pString));
92 _FrameTags.put('D', Frame.class.getMethod("setDateCreated", pString));
93 _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser", pString));
94 _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate", pString));
95 _FrameTags.put('F', Frame.class.getMethod("setFrozenDate", pString));
96 _FrameTags.put('O', Frame.class.getMethod("setForegroundColor", pColor));
97 _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor", pColor));
98 _FrameTags.put('T', Frame.class.getMethod("addToData", pString));
99 _FrameTags.put('G', Frame.class.getMethod("setGroup", pString));
100
101 // Encryption frame tags
102 _FrameTags.put('K', Frame.class.getMethod("setFrameEncryptionLabel", pString));
103 _FrameTags.put('E', Frame.class.getMethod("setFrameEncryptionPermission", pEncPermission));
104 _FrameTags.put('k', Frame.class.getMethod("setHomogeneousEncryptionLabel", pString));
105 _FrameTags.put('e', Frame.class.getMethod("setEncryptionPermission", pEncPermission));
106
107 // Note: As of 26/11/18 there are no unused letter item tags. Use other characters.
108 _ItemTags.put(DefaultFrameWriter.TYPE_AND_ID, Item.class.getMethod("setID", pInt));
109 _ItemTags.put(DefaultFrameWriter.DATE_CREATED, Item.class.getMethod("setDateCreated", pString));
110 _ItemTags.put(DefaultFrameWriter.COLOR, Item.class.getMethod("setColor", pColor));
111 _ItemTags.put(DefaultFrameWriter.BACKGROUND_COLOR, Item.class.getMethod("setBackgroundColor",
112 pColor));
113 _ItemTags.put(DefaultFrameWriter.BORDER_COLOR, Item.class.getMethod("setBorderColor",
114 pColor));
115
116 _ItemTags.put(DefaultFrameWriter.ANCHOR_LEFT, Item.class.getMethod("setAnchorLeft", pIntO));
117 _ItemTags.put(DefaultFrameWriter.ANCHOR_RIGHT, Item.class.getMethod("setAnchorRight", pIntO));
118 _ItemTags.put(DefaultFrameWriter.ANCHOR_TOP, Item.class.getMethod("setAnchorTop", pIntO));
119 _ItemTags.put(DefaultFrameWriter.ANCHOR_BOTTOM, Item.class.getMethod("setAnchorBottom", pIntO));
120
121 _ItemTags.put(DefaultFrameWriter.POSITION, Item.class.getMethod("setPosition", pPoint));
122 _ItemTags.put(DefaultFrameWriter.LINK, Item.class.getMethod("setLink", pString));
123 _ItemTags.put(DefaultFrameWriter.FORMULA, Item.class.getMethod("setFormula", pString));
124
125 _ItemTags.put(DefaultFrameWriter.ACTION, Item.class.getMethod("setActions", pList));
126 _ItemTags.put(DefaultFrameWriter.ACTION_MARK, Item.class.getMethod("setActionMark", pBool));
127 _ItemTags.put(DefaultFrameWriter.ACTION_CURSOR_ENTER, Item.class.getMethod("setActionCursorEnter",
128 pList));
129 _ItemTags.put(DefaultFrameWriter.ACTION_CURSOR_LEAVE, Item.class.getMethod("setActionCursorLeave",
130 pList));
131 _ItemTags.put(DefaultFrameWriter.ACTION_ENTER_FRAME, Item.class.getMethod("setActionEnterFrame",
132 pList));
133 _ItemTags.put(DefaultFrameWriter.ACTION_LEAVE_FRAME, Item.class.getMethod("setActionLeaveFrame",
134 pList));
135 _ItemTags.put(DefaultFrameWriter.DATA, Item.class.getMethod("addToData", pString));
136 _ItemTags.put(DefaultFrameWriter.HIGHLIGHT, Item.class.getMethod("setHighlight", pBool));
137 _ItemTags.put(DefaultFrameWriter.FILL_COLOR, Item.class.getMethod("setFillColor", pColor));
138 _ItemTags.put(DefaultFrameWriter.GRADIENT_COLOR, Item.class.getMethod("setGradientColor", pColor));
139 _ItemTags.put(DefaultFrameWriter.GRADIENT_ANGLE, Item.class.getMethod("setGradientAngle", pDouble));
140
141 _ItemTags.put(DefaultFrameWriter.FILL_PATTERN, Item.class.getMethod("setFillPattern", pString));
142 _ItemTags.put(DefaultFrameWriter.OWNER, Item.class.getMethod("setOwner", pString));
143 _ItemTags.put(DefaultFrameWriter.LINK_MARK, Item.class.getMethod("setLinkMark", pBool));
144 _ItemTags
145 .put(DefaultFrameWriter.LINK_FRAMESET, Item.class.getMethod("setLinkFrameset", pString));
146 _ItemTags
147 .put(DefaultFrameWriter.LINK_TEMPLATE, Item.class.getMethod("setLinkTemplate", pString));
148 _ItemTags.put(DefaultFrameWriter.LINE_PATTERN, Item.class.getMethod("setLinePattern", pIntArray));
149
150 _ItemTags.put(DefaultFrameWriter.ARROW, Item.class.getMethod("setArrow", pArrow));
151
152 _ItemTags.put(DefaultFrameWriter.DOT_TYPE, Dot.class.getMethod("setDotType", pDotType));
153 _ItemTags.put(DefaultFrameWriter.FILLED, Dot.class.getMethod("setFilled", pBool));
154
155 _ItemTags.put(DefaultFrameWriter.FONT, Text.class.getMethod("setFont", pFont));
156 _ItemTags.put(DefaultFrameWriter.SPACING, Text.class.getMethod("setSpacing", pFloat));
157 _ItemTags.put(DefaultFrameWriter.TEXT, Text.class.getMethod("appendLine", pString));
158 _ItemTags.put(DefaultFrameWriter.WORD_SPACING, Text.class.getMethod("setWordSpacing", pInt));
159 _ItemTags.put(DefaultFrameWriter.LETTER_SPACING, Text.class.getMethod("setLetterSpacing", pFloat));
160 _ItemTags.put(DefaultFrameWriter.INITIAL_SPACING, Text.class.getMethod("setInitialSpacing", pFloat));
161 _ItemTags.put(DefaultFrameWriter.WIDTH_TO_SAVE, Text.class.getMethod("setWidth", pIntO));
162 _ItemTags.put(DefaultFrameWriter.MIN_WIDTH_TO_SAVE, Text.class.getMethod("setMinWidth", pIntO));
163 _ItemTags.put(DefaultFrameWriter.JUSTIFICATION, Text.class.getMethod("setJustification", pJustification));
164 _ItemTags.put(DefaultFrameWriter.AUTO_WRAP_TO_SAVE, Text.class.getMethod("setAutoWrap", pBool));
165
166 _ItemTags.put(DefaultFrameWriter.THICKNESS, Item.class.getMethod("setThickness", pFloat));
167 _ItemTags.put(DefaultFrameWriter.LINE_IDS, Item.class.getMethod("setLineIDs", pString));
168 _ItemTags.put(DefaultFrameWriter.CONSTRAINT_IDS, Item.class.getMethod("setConstraintIDs", pString));
169
170 _ItemTags.put(DefaultFrameWriter.TOOLTIP, Item.class.getMethod("setTooltip", pString));
171 _ItemTags.put(DefaultFrameWriter.LINK_HISTORY, Item.class.getMethod("setLinkHistory", pBool));
172
173 _ItemTags.put(DefaultFrameWriter.PERMISSION, Item.class.getMethod("setPermission", pPermission));
174
175 _ItemTags.put(DefaultFrameWriter.MASK, Text.class.getMethod("setMask", pIntO));
176
177 // Lines and constraints are created differently
178 _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
179 _ItemTags.put('C', Constraint.class.getMethod("getID", (Class[]) null));
180
181 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_LEFT, Item.class.getMethod("setMagnetizedItemLeft", pInt));
182 _DelayedItemTags.add('[');
183 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_RIGHT, Item.class.getMethod("setMagnetizedItemRight", pInt));
184 _DelayedItemTags.add(']');
185 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_TOP, Item.class.getMethod("setMagnetizedItemTop", pInt));
186 _DelayedItemTags.add('^');
187 _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_BOTTOM, Item.class.getMethod("setMagnetizedItemBottom", pInt));
188 _DelayedItemTags.add('/');
189
190 _ItemTagsExt.put(DefaultFrameWriter.ENCRYPTION_LABEL_STR, Item.class.getMethod("setEncryptionLabelOnLoad", pString));
191
192 _ItemTagsExt.put(DefaultFrameWriter.PLACEHOLDER_STR, Text.class.getMethod("setPlaceholder", pString));
193 _ItemTagsExt.put(DefaultFrameWriter.SINGLE_LINE_ONLY_STR, Text.class.getMethod("setSingleLineOnly", pBool));
194 _ItemTagsExt.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("setTabIndex", pInt));
195 _ItemTagsExt.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("setAcceptsEnter", pBool));
196 } catch (Exception e) {
197 e.printStackTrace();
198 }
199
200 }
201
202 public Frame readFrame(String fullPath) throws IOException {
203 File f = new File(fullPath);
204 Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8");
205 Frame frame = readFrame(new BufferedReader(in));
206 frame.setLastModifyDate(frame.getLastModifyDate(), f.lastModified());
207 return frame;
208 }
209}
Note: See TracBrowser for help on using the repository browser.