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 33 public abstract class CellValue implements BIFFRecord { 34 35 protected byte[] rw = new byte[2]; 36 protected byte col; 37 protected byte[] ixfe = new byte[2]; 38 39 /** 40 * Get the row number of this cell 41 * 42 * @return the row number of this cell 43 */ getRow()44 public int getRow() { 45 return EndianConverter.readShort(rw) + 1; 46 } 47 48 /** 49 * Set the row number of this cell 50 * 51 * @param row sets the row number for this cell 52 */ setRow(int row)53 public void setRow(int row) { 54 this.rw = EndianConverter.writeShort((short) (row - 1)); 55 } 56 /** 57 * Get the Index to the <code>ExtendedFormat</code> 58 * 59 * @return the index number of this cell's <code>ExtendedFormat</code> 60 */ getIxfe()61 public int getIxfe() { 62 return EndianConverter.readShort(ixfe); 63 } 64 65 /** 66 * Sets the Index to the <code>ExtendedFormat</code> 67 * 68 * @param ixfe sets the index number for this cell's <code>ExtendedFormat</code> 69 */ setIxfe(int ixfe)70 public void setIxfe(int ixfe) { 71 this.ixfe = EndianConverter.writeShort((short) (ixfe)); 72 } 73 74 /** 75 * Get the column number of this cell 76 * 77 * @return the column number of this cell 78 */ getCol()79 public int getCol() { 80 return col + 1; // The cols start at 1 81 } 82 83 /** 84 * Set the row number of this cell 85 * 86 * @param col sets the row number for this cell 87 */ setCol(int col)88 public void setCol(int col) { 89 this.col = (byte) (col - 1); // The cols start at 1 90 } 91 92 /** 93 * Writes basic cell value attributes to the specified <code>Outputstream</code> 94 * 95 * @param output the <code>OutputStream</code> to write to 96 */ write(OutputStream output)97 public void write(OutputStream output) throws IOException { 98 99 output.write(rw); 100 output.write(col); 101 output.write(ixfe); 102 } 103 104 /** 105 * Read a <code>LabelCell</code> from the specified <code>InputStream</code> 106 * 107 * @param input the <code>InputStream</code> to read from 108 */ read(InputStream input)109 public int read(InputStream input) throws IOException { 110 111 int numOfBytesRead = input.read(rw); 112 col += input.read(); 113 numOfBytesRead++; 114 numOfBytesRead += input.read(ixfe); 115 116 Debug.log(Debug.TRACE, "\tRow : "+ EndianConverter.readShort(rw) + 117 " Column : " + col + 118 " ixfe : " + EndianConverter.readShort(ixfe)); 119 120 return numOfBytesRead; 121 } 122 123 124 /** 125 * Returns the contents of the cell as a String 126 * 127 * @return the contents of the cell 128 */ getString()129 abstract public String getString() throws IOException; 130 131 } 132 133