xref: /trunk/main/xmerge/java/pexcel/src/main/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Row.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.xmerge.converter.xml.sxc.pexcel.records;
25 
26 import java.io.OutputStream;
27 import java.io.InputStream;
28 import java.io.IOException;
29 
30 import org.openoffice.xmerge.util.Debug;
31 import org.openoffice.xmerge.util.EndianConverter;
32 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants;
33 
34 
35 /**
36  * Represents s BIFF Record that describes the format of a column
37  */
38 public class Row implements BIFFRecord {
39 
40     private byte[] rw       = new byte[2];
41     private byte[] miyRw    = new byte[2];
42     private byte[] grbit    = new byte[2];
43     private byte[] ixfe     = new byte[2];
44     private float  scale = (float) 1;
45 
46     /**
47      * Constructs a pocket Excel Document from the
48      * <code>InputStream</code> and assigns it the document name passed in
49      *
50      * @param   rw Zero based row number
51      * @param   miyRw row height
52      */
Row(int rw, int miyRw, boolean userDefined)53     public Row(int rw, int miyRw, boolean userDefined) {
54         this.rw     = EndianConverter.writeShort((short) rw);
55         miyRw *= scale;
56         this.miyRw  = EndianConverter.writeShort((short) miyRw);
57         if(userDefined) {
58             grbit   = EndianConverter.writeShort((short) 2);
59         } else {
60             grbit   = EndianConverter.writeShort((short) 0);
61         }
62         ixfe    = EndianConverter.writeShort((short) 0);
63     }
64 
65     /**
66      * Constructs a Row fro man <code>InputStream</code>
67      *
68      * @param   is InputStream containing a Pane Record
69      */
Row(InputStream is)70     public Row(InputStream is) throws IOException {
71         read(is);
72     }
73 
74     /**
75      * Get the hex code for this particular <code>BIFFRecord</code>
76      *
77      * @return the hex code for <code>Row</code>
78      */
getBiffType()79     public short getBiffType() {
80         return PocketExcelConstants.ROW_DESCRIPTION;
81     }
82 
83     /**
84      * Get the height of this row
85      *
86      * @return the height of this row
87      */
getRowHeight()88     public short getRowHeight() {
89         return EndianConverter.readShort(miyRw);
90     }
91 
92     /**
93      * Get the rown number for this style
94      *
95      * @return the row this style applies to
96      */
getRowNumber()97     public short getRowNumber() {
98         return EndianConverter.readShort(rw);
99     }
100 
101     /**
102      * Reads a Row from an <code>InputStream</code>
103      *
104      * @param   input InputStream containing a Pane Record
105      */
read(InputStream input)106     public int read(InputStream input) throws IOException {
107 
108         int numOfBytesRead  = input.read(rw);
109         numOfBytesRead      += input.read(miyRw);
110         short scaledHeight = (short) (EndianConverter.readShort(miyRw) / scale);
111         miyRw = EndianConverter.writeShort(scaledHeight);
112         numOfBytesRead      += input.read(grbit);
113         numOfBytesRead      += input.read(ixfe);
114 
115         Debug.log(Debug.TRACE,"\trw : "+ EndianConverter.readShort(rw) +
116                             " miyRw : " + EndianConverter.readShort(miyRw) +
117                             " grbit : " + EndianConverter.readShort(grbit) +
118                             " ixfe : " + EndianConverter.readShort(ixfe));
119         return numOfBytesRead;
120     }
121 
write(OutputStream output)122     public void write(OutputStream output) throws IOException {
123 
124         output.write(getBiffType());
125         output.write(rw);
126         output.write(miyRw);
127         output.write(grbit);
128         output.write(ixfe);
129 
130         Debug.log(Debug.TRACE,"Writing Row record");
131 
132     }
133 
134 }
135