1 19 20 package jxl.biff.drawing; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 25 import common.Logger; 26 27 import jxl.biff.IntegerHelper; 28 import jxl.biff.StringHelper; 29 30 33 class Opt extends EscherAtom 34 { 35 38 private static Logger logger = Logger.getLogger(Opt.class); 39 40 private byte[] data; 41 private int numProperties; 42 43 46 private ArrayList properties; 47 48 final static class Property 49 { 50 int id; 51 boolean blipId; 52 boolean complex; 53 int value; 54 String stringValue; 55 56 public Property(int i, boolean bl, boolean co, int v) 57 { 58 id = i; 59 blipId = bl; 60 complex = co; 61 value = v; 62 } 65 66 public Property(int i, boolean bl, boolean co, int v, String s) 67 { 68 id = i; 69 blipId = bl; 70 complex = co; 71 value = v; 72 stringValue = s; 73 } 74 } 75 76 public Opt(EscherRecordData erd) 77 { 78 super(erd); 79 numProperties = getInstance(); 80 readProperties(); 81 } 82 83 private void readProperties() 84 { 85 properties = new ArrayList (); 86 int pos = 0; 87 byte[] bytes = getBytes(); 88 89 for (int i = 0 ; i < numProperties ; i++) 90 { 91 int val = IntegerHelper.getInt(bytes[pos], bytes[pos+1]); 92 int id = val & 0x3fff; 93 int value = IntegerHelper.getInt(bytes[pos+2], bytes[pos+3], 94 bytes[pos+4], bytes[pos+5]); 95 Property p = new Property(id, 96 (val & 0x4000) != 0, 97 (val & 0x8000) != 0, 98 value); 99 pos += 6; 100 properties.add(p); 101 } 102 103 for (Iterator i = properties.iterator(); i.hasNext() ; ) 104 { 105 Property p = (Property) i.next(); 106 if (p.complex) 107 { 108 p.stringValue = StringHelper.getUnicodeString(bytes, p.value/2, 109 pos); 110 pos += p.value; 111 } 112 } 113 } 114 115 public Opt() 116 { 117 super(EscherRecordType.OPT); 118 properties = new ArrayList (); 119 setVersion(3); 120 } 121 122 byte[] getData() 123 { 124 numProperties = properties.size(); 125 setInstance(numProperties); 126 127 data = new byte[numProperties * 6]; 128 int pos = 0; 129 130 for (Iterator i = properties.iterator() ; i.hasNext() ; ) 132 { 133 Property p = (Property) i.next(); 134 int val = p.id & 0x3fff; 135 136 if (p.blipId) 137 { 138 val |= 0x4000; 139 } 140 141 if (p.complex) 142 { 143 val |= 0x8000; 144 } 145 146 IntegerHelper.getTwoBytes(val, data, pos); 147 IntegerHelper.getFourBytes(p.value, data, pos+2); 148 pos += 6 ; 149 } 150 151 for (Iterator i = properties.iterator() ; i.hasNext() ; ) 153 { 154 Property p = (Property) i.next(); 155 156 if (p.complex && p.stringValue != null) 157 { 158 byte[] newData = 159 new byte[data.length + p.stringValue.length() * 2]; 160 System.arraycopy(data, 0, newData, 0, data.length); 161 StringHelper.getUnicodeBytes(p.stringValue, newData, data.length); 162 data = newData; 163 } 164 } 165 166 return setHeaderData(data); 167 } 168 169 void addProperty(int id, boolean blip, boolean complex, int val) 170 { 171 Property p = new Property(id, blip, complex, val); 172 properties.add(p); 173 } 174 175 void addProperty(int id, boolean blip, boolean complex, int val, String s) 176 { 177 Property p = new Property(id, blip, complex, val, s); 178 properties.add(p); 179 } 180 181 Property getProperty(int id) 182 { 183 boolean found = false; 184 Property p = null; 185 for (Iterator i = properties.iterator() ; i.hasNext() && !found ; ) 186 { 187 p = (Property) i.next(); 188 if (p.id == id) 189 { 190 found = true; 191 } 192 } 193 return found ? p : null; 194 } 195 196 } 197 | Popular Tags |