1 19 20 package jxl.biff; 21 22 import common.Assert; 23 24 27 public abstract class BaseCompoundFile 28 { 29 32 protected static final byte[] IDENTIFIER = new byte[] 33 {(byte) 0xd0, 34 (byte) 0xcf, 35 (byte) 0x11, 36 (byte) 0xe0, 37 (byte) 0xa1, 38 (byte) 0xb1, 39 (byte) 0x1a, 40 (byte) 0xe1}; 41 43 protected static final int NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c; 44 46 protected static final int SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c; 47 49 protected static final int NUM_SMALL_BLOCK_DEPOT_BLOCKS_POS = 0x40; 50 52 protected static final int ROOT_START_BLOCK_POS = 0x30; 53 55 protected static final int BIG_BLOCK_SIZE = 0x200; 56 58 protected static final int SMALL_BLOCK_SIZE = 0x40; 59 61 protected static final int EXTENSION_BLOCK_POS = 0x44; 62 64 protected static final int NUM_EXTENSION_BLOCK_POS = 0x48; 65 67 protected static final int PROPERTY_STORAGE_BLOCK_SIZE = 0x80; 68 70 protected static final int BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c; 71 73 protected static final int SMALL_BLOCK_THRESHOLD = 0x1000; 74 75 78 private static final int SIZE_OF_NAME_POS = 0x40; 79 81 private static final int TYPE_POS = 0x42; 82 84 private static final int COLOUR_POS = 0x43; 85 87 private static final int PREVIOUS_POS = 0x44; 88 90 private static final int NEXT_POS = 0x48; 91 93 private static final int CHILD_POS = 0x4c; 94 96 private static final int START_BLOCK_POS = 0x74; 97 99 private static final int SIZE_POS = 0x78; 100 101 104 public final static String ROOT_ENTRY_NAME = "Root Entry"; 105 public final static String WORKBOOK_NAME = "Workbook"; 106 public final static String SUMMARY_INFORMATION_NAME = 107 "\u0005SummaryInformation"; 108 public final static String DOCUMENT_SUMMARY_INFORMATION_NAME = 109 "\u0005DocumentSummaryInformation"; 110 public final static String COMP_OBJ_NAME = 111 "\u0001CompObj"; 112 public final static String [] STANDARD_PROPERTY_SETS = 113 new String [] {ROOT_ENTRY_NAME, WORKBOOK_NAME, 114 SUMMARY_INFORMATION_NAME, 115 DOCUMENT_SUMMARY_INFORMATION_NAME}; 116 117 120 public final static int NONE_PS_TYPE = 0; 121 public final static int DIRECTORY_PS_TYPE = 1; 122 public final static int FILE_PS_TYPE = 2; 123 public final static int ROOT_ENTRY_PS_TYPE = 5; 124 125 126 130 public class PropertyStorage 131 { 132 135 public String name; 136 139 public int type; 140 143 public int colour; 144 147 public int startBlock; 148 151 public int size; 152 155 public int previous; 156 159 public int next; 160 163 public int child; 164 165 168 public byte[] data; 169 170 175 public PropertyStorage(byte[] d) 176 { 177 data = d; 178 int nameSize = IntegerHelper.getInt(data[SIZE_OF_NAME_POS], 179 data[SIZE_OF_NAME_POS + 1]); 180 type = data[TYPE_POS]; 181 colour = data[COLOUR_POS]; 182 183 startBlock = IntegerHelper.getInt 184 (data[START_BLOCK_POS], 185 data[START_BLOCK_POS + 1], 186 data[START_BLOCK_POS + 2], 187 data[START_BLOCK_POS + 3]); 188 size = IntegerHelper.getInt 189 (data[SIZE_POS], 190 data[SIZE_POS + 1], 191 data[SIZE_POS + 2], 192 data[SIZE_POS + 3]); 193 previous = IntegerHelper.getInt 194 (data[PREVIOUS_POS], 195 data[PREVIOUS_POS+1], 196 data[PREVIOUS_POS+2], 197 data[PREVIOUS_POS+3]); 198 next = IntegerHelper.getInt 199 (data[NEXT_POS], 200 data[NEXT_POS+1], 201 data[NEXT_POS+2], 202 data[NEXT_POS+3]); 203 child = IntegerHelper.getInt 204 (data[CHILD_POS], 205 data[CHILD_POS+1], 206 data[CHILD_POS+2], 207 data[CHILD_POS+3]); 208 209 int chars = 0; 210 if (nameSize > 2) 211 { 212 chars = (nameSize - 1) / 2; 213 } 214 215 StringBuffer n = new StringBuffer (""); 216 for (int i = 0; i < chars ; i++) 217 { 218 n.append( (char) data[i * 2]); 219 } 220 221 name = n.toString(); 222 } 223 224 229 public PropertyStorage(String name) 230 { 231 data = new byte[PROPERTY_STORAGE_BLOCK_SIZE]; 232 233 Assert.verify(name.length() < 32); 234 235 IntegerHelper.getTwoBytes((name.length() + 1) * 2, 236 data, 237 SIZE_OF_NAME_POS); 238 for (int i = 0; i < name.length(); i++) 241 { 242 data[i * 2] = (byte) name.charAt(i); 243 } 244 } 245 246 251 public void setType(int t) 252 { 253 type = t; 254 data[TYPE_POS] = (byte) t; 255 } 256 257 262 public void setStartBlock(int sb) 263 { 264 startBlock = sb; 265 IntegerHelper.getFourBytes(sb, data, START_BLOCK_POS); 266 } 267 268 273 public void setSize(int s) 274 { 275 size = s; 276 IntegerHelper.getFourBytes(s, data, SIZE_POS); 277 } 278 279 284 public void setPrevious(int prev) 285 { 286 previous = prev; 287 IntegerHelper.getFourBytes(prev, data, PREVIOUS_POS); 288 } 289 290 295 public void setNext(int nxt) 296 { 297 next = nxt; 298 IntegerHelper.getFourBytes(next, data, NEXT_POS); 299 } 300 301 306 public void setChild(int dir) 307 { 308 child = dir; 309 IntegerHelper.getFourBytes(child, data, CHILD_POS); 310 } 311 312 317 public void setColour(int col) 318 { 319 colour = col == 0 ? 0 : 1; 320 data[COLOUR_POS] = (byte) colour; 321 } 322 323 } 324 325 328 protected BaseCompoundFile() 329 { 330 } 331 332 } 333 334 335 336 337 | Popular Tags |