KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > DrawingRecord


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16 package org.apache.poi.hssf.record;
17
18 import org.apache.poi.util.LittleEndian;
19
20 public class DrawingRecord extends Record
21 {
22     public static final short sid = 0xEC;
23
24     private byte[] recordData;
25
26     public DrawingRecord()
27     {
28     }
29
30     public DrawingRecord( short id, short size, byte[] data )
31     {
32         super( id, size, data );
33     }
34
35     public DrawingRecord( short id, short size, byte[] data, int offset )
36     {
37         super( id, size, data, offset );
38     }
39
40     /**
41      * Checks the sid matches the expected side for this record
42      *
43      * @param id the expected sid.
44      */

45     protected void validateSid(short id)
46     {
47         if (id != sid)
48         {
49             throw new RecordFormatException("Not a MSODRAWING record");
50         }
51     }
52
53     protected void fillFields( byte[] data, short size, int offset )
54     {
55         if (offset == 0 && size == data.length)
56         {
57             recordData = data;
58         }
59         else
60         {
61             recordData = new byte[size];
62             System.arraycopy(data, offset, recordData, 0, size);
63         }
64     }
65
66     protected void fillFields( byte[] data, short size )
67     {
68         recordData = data;
69     }
70
71     public int serialize( int offset, byte[] data )
72     {
73         if (recordData == null)
74         {
75             recordData = new byte[ 0 ];
76         }
77         LittleEndian.putShort(data, 0 + offset, sid);
78         LittleEndian.putShort(data, 2 + offset, ( short ) (recordData.length));
79         if (recordData.length > 0)
80         {
81             System.arraycopy(recordData, 0, data, 4 + offset, recordData.length);
82         }
83         return getRecordSize();
84     }
85
86     public int getRecordSize()
87     {
88         int retval = 4;
89
90         if (recordData != null)
91         {
92             retval += recordData.length;
93         }
94         return retval;
95     }
96
97     public short getSid()
98     {
99         return sid;
100     }
101
102     public byte[] getData()
103     {
104         return recordData;
105     }
106
107     public void setData( byte[] thedata )
108     {
109         this.recordData = thedata;
110     }
111
112 }
113
Popular Tags