/** * DefaultFrameReader.java * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package org.expeditee.io; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.lang.reflect.Method; import java.util.LinkedHashMap; import java.util.List; import java.util.LinkedList; import org.expeditee.core.Colour; import org.expeditee.core.Font; import org.expeditee.core.Point; import org.expeditee.encryption.items.EncryptionPermissionTriple; import org.expeditee.gui.Frame; import org.expeditee.items.Constraint; import org.expeditee.items.Dot; import org.expeditee.items.DotType; import org.expeditee.items.Item; import org.expeditee.items.Justification; import org.expeditee.items.Line; import org.expeditee.items.PermissionTriple; import org.expeditee.items.Text; public abstract class DefaultFrameReader implements FrameReader { protected static LinkedHashMap _ItemTags = null; // IMPORTANT: keys in _ItemTagsExt must start with underscore as their first character protected static LinkedHashMap _ItemTagsExt = null; protected static List _DelayedItemTags = null; protected static LinkedHashMap _FrameTags = null; protected static Class[] pString = { String.class }; protected static Class[] pInt = { int.class }; protected static Class[] pIntO = { Integer.class }; protected static Class[] pFloat = { float.class }; protected static Class[] pFloatO = { Float.class }; protected static Class[] pDouble = { double.class }; protected static Class[] pColor = { Colour.class }; protected static Class[] pBool = { boolean.class }; protected static Class[] pFont = { Font.class }; protected static Class[] pPoint = { Point.class }; protected static Class[] pArrow = { float.class, double.class, double.class }; protected static Class[] pList = { List.class }; protected static Class[] pIntArray = { int[].class }; protected static Class[] pItem = { Item.class }; protected static Class[] pJustification = { Justification.class }; protected static Class[] pPermission = { PermissionTriple.class }; protected static Class[] pDotType = { DotType.class }; protected static Class[] pEncPermission = { EncryptionPermissionTriple.class }; public DefaultFrameReader(){ if (_ItemTags != null && _FrameTags != null) return; _ItemTags = new LinkedHashMap(); _ItemTagsExt = new LinkedHashMap(); _FrameTags = new LinkedHashMap(); _DelayedItemTags = new LinkedList(); try { /// C H I J L N P Q R S W X Y Z /// a b c f g h i j l m n o q r s t u v w x y z // Standard frame tags _FrameTags.put('A', Frame.class.getMethod("setName", pString)); _FrameTags.put('V', Frame.class.getMethod("setVersion", pInt)); _FrameTags.put('p', Frame.class.getMethod("setPermission", pPermission)); _FrameTags.put('U', Frame.class.getMethod("setOwner", pString)); _FrameTags.put('D', Frame.class.getMethod("setDateCreated", pString)); _FrameTags.put('M', Frame.class.getMethod("setLastModifyUser", pString)); _FrameTags.put('d', Frame.class.getMethod("setLastModifyDate", pString)); _FrameTags.put('F', Frame.class.getMethod("setFrozenDate", pString)); _FrameTags.put('O', Frame.class.getMethod("setForegroundColor", pColor)); _FrameTags.put('B', Frame.class.getMethod("setBackgroundColor", pColor)); _FrameTags.put('T', Frame.class.getMethod("addToData", pString)); _FrameTags.put('G', Frame.class.getMethod("setGroup", pString)); // Encryption frame tags _FrameTags.put('K', Frame.class.getMethod("setFrameEncryptionLabelOnLoad", pString)); _FrameTags.put('E', Frame.class.getMethod("setFrameEncryptionPermission", pEncPermission)); _FrameTags.put('k', Frame.class.getMethod("setHomogeneousEncryptionLabelOnLoad", pString)); _FrameTags.put('e', Frame.class.getMethod("setEncryptionPermission", pEncPermission)); _FrameTags.put('a', Frame.class.getMethod("addToHetrogeneousFrameOwnerLabels", pString)); // Note: As of 26/11/18 there are no unused letter item tags. Use other characters. _ItemTags.put(DefaultFrameWriter.TYPE_AND_ID, Item.class.getMethod("setID", pInt)); _ItemTags.put(DefaultFrameWriter.DATE_CREATED, Item.class.getMethod("setDateCreated", pString)); _ItemTags.put(DefaultFrameWriter.COLOR, Item.class.getMethod("setColor", pColor)); _ItemTags.put(DefaultFrameWriter.BACKGROUND_COLOR, Item.class.getMethod("setBackgroundColor", pColor)); _ItemTags.put(DefaultFrameWriter.BORDER_COLOR, Item.class.getMethod("setBorderColor", pColor)); _ItemTags.put(DefaultFrameWriter.ANCHOR_LEFT, Item.class.getMethod("setAnchorLeft", pIntO)); _ItemTags.put(DefaultFrameWriter.ANCHOR_RIGHT, Item.class.getMethod("setAnchorRight", pIntO)); _ItemTags.put(DefaultFrameWriter.ANCHOR_TOP, Item.class.getMethod("setAnchorTop", pIntO)); _ItemTags.put(DefaultFrameWriter.ANCHOR_BOTTOM, Item.class.getMethod("setAnchorBottom", pIntO)); _ItemTags.put(DefaultFrameWriter.POSITION, Item.class.getMethod("setPosition", pPoint)); _ItemTags.put(DefaultFrameWriter.LINK, Item.class.getMethod("setLink", pString)); _ItemTags.put(DefaultFrameWriter.FORMULA, Item.class.getMethod("setFormula", pString)); _ItemTags.put(DefaultFrameWriter.ACTION, Item.class.getMethod("setActions", pList)); _ItemTags.put(DefaultFrameWriter.ACTION_MARK, Item.class.getMethod("setActionMark", pBool)); _ItemTags.put(DefaultFrameWriter.ACTION_CURSOR_ENTER, Item.class.getMethod("setActionCursorEnter", pList)); _ItemTags.put(DefaultFrameWriter.ACTION_CURSOR_LEAVE, Item.class.getMethod("setActionCursorLeave", pList)); _ItemTags.put(DefaultFrameWriter.ACTION_ENTER_FRAME, Item.class.getMethod("setActionEnterFrame", pList)); _ItemTags.put(DefaultFrameWriter.ACTION_LEAVE_FRAME, Item.class.getMethod("setActionLeaveFrame", pList)); _ItemTags.put(DefaultFrameWriter.DATA, Item.class.getMethod("addToData", pString)); _ItemTags.put(DefaultFrameWriter.HIGHLIGHT, Item.class.getMethod("setHighlight", pBool)); _ItemTags.put(DefaultFrameWriter.FILL_COLOR, Item.class.getMethod("setFillColor", pColor)); _ItemTags.put(DefaultFrameWriter.GRADIENT_COLOR, Item.class.getMethod("setGradientColor", pColor)); _ItemTags.put(DefaultFrameWriter.GRADIENT_ANGLE, Item.class.getMethod("setGradientAngle", pDouble)); _ItemTags.put(DefaultFrameWriter.FILL_PATTERN, Item.class.getMethod("setFillPattern", pString)); _ItemTags.put(DefaultFrameWriter.OWNER, Item.class.getMethod("setOwner", pString)); _ItemTags.put(DefaultFrameWriter.LINK_MARK, Item.class.getMethod("setLinkMark", pBool)); _ItemTags .put(DefaultFrameWriter.LINK_FRAMESET, Item.class.getMethod("setLinkFrameset", pString)); _ItemTags .put(DefaultFrameWriter.LINK_TEMPLATE, Item.class.getMethod("setLinkTemplate", pString)); _ItemTags.put(DefaultFrameWriter.LINE_PATTERN, Item.class.getMethod("setLinePattern", pIntArray)); _ItemTags.put(DefaultFrameWriter.ARROW, Item.class.getMethod("setArrow", pArrow)); _ItemTags.put(DefaultFrameWriter.DOT_TYPE, Dot.class.getMethod("setDotType", pDotType)); _ItemTags.put(DefaultFrameWriter.FILLED, Dot.class.getMethod("setFilled", pBool)); _ItemTags.put(DefaultFrameWriter.FONT, Text.class.getMethod("setFont", pFont)); _ItemTags.put(DefaultFrameWriter.SPACING, Text.class.getMethod("setSpacing", pFloat)); _ItemTags.put(DefaultFrameWriter.TEXT, Text.class.getMethod("appendLine", pString)); _ItemTags.put(DefaultFrameWriter.WORD_SPACING, Text.class.getMethod("setWordSpacing", pInt)); _ItemTags.put(DefaultFrameWriter.LETTER_SPACING, Text.class.getMethod("setLetterSpacing", pFloat)); _ItemTags.put(DefaultFrameWriter.INITIAL_SPACING, Text.class.getMethod("setInitialSpacing", pFloat)); _ItemTags.put(DefaultFrameWriter.WIDTH_TO_SAVE, Text.class.getMethod("setWidth", pIntO)); _ItemTags.put(DefaultFrameWriter.MIN_WIDTH_TO_SAVE, Text.class.getMethod("setMinWidth", pIntO)); _ItemTags.put(DefaultFrameWriter.JUSTIFICATION, Text.class.getMethod("setJustification", pJustification)); _ItemTags.put(DefaultFrameWriter.AUTO_WRAP_TO_SAVE, Text.class.getMethod("setAutoWrap", pBool)); _ItemTags.put(DefaultFrameWriter.THICKNESS, Item.class.getMethod("setThickness", pFloat)); _ItemTags.put(DefaultFrameWriter.LINE_IDS, Item.class.getMethod("setLineIDs", pString)); _ItemTags.put(DefaultFrameWriter.CONSTRAINT_IDS, Item.class.getMethod("setConstraintIDs", pString)); _ItemTags.put(DefaultFrameWriter.TOOLTIP, Item.class.getMethod("setTooltip", pString)); _ItemTags.put(DefaultFrameWriter.LINK_HISTORY, Item.class.getMethod("setLinkHistory", pBool)); _ItemTags.put(DefaultFrameWriter.PERMISSION, Item.class.getMethod("setPermission", pPermission)); _ItemTags.put(DefaultFrameWriter.MASK, Text.class.getMethod("setMask", pIntO)); // Lines and constraints are created differently _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem)); _ItemTags.put('C', Constraint.class.getMethod("getID", (Class[]) null)); _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_LEFT, Item.class.getMethod("setMagnetizedItemLeft", pInt)); _DelayedItemTags.add('['); _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_RIGHT, Item.class.getMethod("setMagnetizedItemRight", pInt)); _DelayedItemTags.add(']'); _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_TOP, Item.class.getMethod("setMagnetizedItemTop", pInt)); _DelayedItemTags.add('^'); _ItemTags.put(DefaultFrameWriter.MAGNETIZED_ITEM_BOTTOM, Item.class.getMethod("setMagnetizedItemBottom", pInt)); _DelayedItemTags.add('/'); _ItemTagsExt.put(DefaultFrameWriter.ENCRYPTION_LABEL_STR, Item.class.getMethod("setEncryptionLabelOnLoad", pString)); _ItemTagsExt.put(DefaultFrameWriter.PLACEHOLDER_STR, Text.class.getMethod("setPlaceholder", pString)); _ItemTagsExt.put(DefaultFrameWriter.SINGLE_LINE_ONLY_STR, Text.class.getMethod("setSingleLineOnly", pBool)); _ItemTagsExt.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("setTabIndex", pInt)); _ItemTagsExt.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("setAcceptsEnter", pBool)); _ItemTagsExt.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("setAnchorCenterX", pIntO)); } catch (Exception e) { e.printStackTrace(); } } public Frame readFrame(String fullPath) throws IOException { File f = new File(fullPath); Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8"); Frame frame = readFrame(new BufferedReader(in)); frame.setLastModifyDate(frame.getLastModifyDate(), f.lastModified()); return frame; } }