1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 import org.apache.poi.util.StringUtil; 23 24 33 34 public class WriteAccessRecord 35 extends Record 36 { 37 public final static short sid = 0x5c; 38 private String field_1_username; 39 40 public WriteAccessRecord() 41 { 42 } 43 44 51 52 public WriteAccessRecord(short id, short size, byte [] data) 53 { 54 super(id, size, data); 55 } 56 57 65 66 public WriteAccessRecord(short id, short size, byte [] data, int offset) 67 { 68 super(id, size, data, offset); 69 } 70 71 protected void validateSid(short id) 72 { 73 if (id != sid) 74 { 75 throw new RecordFormatException("NOT A WRITEACCESS RECORD"); 76 } 77 } 78 79 protected void fillFields(byte [] data, short size, int offset) 80 { 81 field_1_username = StringUtil.getFromCompressedUnicode(data, 3 + offset, data.length - 4); 82 } 83 84 88 89 public void setUsername(String username) 90 { 91 field_1_username = username; 92 } 93 94 100 101 public String getUsername() 102 { 103 return field_1_username; 104 } 105 106 public String toString() 107 { 108 StringBuffer buffer = new StringBuffer (); 109 110 buffer.append("[WRITEACCESS]\n"); 111 buffer.append(" .name = ") 112 .append(field_1_username.toString()).append("\n"); 113 buffer.append("[/WRITEACCESS]\n"); 114 return buffer.toString(); 115 } 116 117 public int serialize(int offset, byte [] data) 118 { 119 String username = getUsername(); 120 StringBuffer temp = new StringBuffer (0x70 - (0x3)); 121 122 temp.append(username); 123 while (temp.length() < 0x70 - 0x3) 124 { 125 temp.append( 126 " "); } 128 username = temp.toString(); 129 UnicodeString str = new UnicodeString(); 130 131 str.setString(username); 132 str.setOptionFlags(( byte ) 0x0); 133 str.setCharCount(( short ) 0x4); 134 byte[] stringbytes = str.serialize(); 135 136 LittleEndian.putShort(data, 0 + offset, sid); 137 LittleEndian.putShort(data, 2 + offset, 138 ( short ) (stringbytes 139 .length)); System.arraycopy(stringbytes, 0, data, 4 + offset, 141 stringbytes.length); 142 return getRecordSize(); 143 } 144 145 public int getRecordSize() 146 { 147 return 116; 148 } 149 150 public short getSid() 151 { 152 return this.sid; 153 } 154 } 155 | Popular Tags |