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.InputStream; 27 import java.io.OutputStream; 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 * Reperesent a BIFF Record descibing a cell containing a string 37 */ 38 public class LabelCell extends CellValue { 39 40 private byte[] cch = new byte[2]; 41 private byte[] rgch; 42 43 /** 44 * Constructs a <code>LabelCell</code> using specified attributes 45 * 46 * @param row row number 47 * @param column column number 48 * @param cellContents contents of the cell 49 * @param ixfe font index 50 */ LabelCell(int row, int column, String cellContents, int ixfe)51 public LabelCell(int row, int column, String cellContents, int ixfe) 52 throws IOException { 53 54 setLabel(cellContents); 55 setRow(row); 56 setCol(column); 57 setIxfe(ixfe); 58 } 59 60 /** 61 * Reads a LabelCell from the <code>InputStream</code> 62 * 63 * @param is the <code>Inputstream</code> to read from 64 */ LabelCell(InputStream is)65 public LabelCell(InputStream is) throws IOException { 66 read(is); 67 } 68 69 /** 70 * Writes a <code>LabelCell</code> to the specified <code>Outputstream</code> 71 * 72 * @param output the <code>OutputStream</code> to write to 73 */ write(OutputStream output)74 public void write(OutputStream output) throws IOException { 75 76 output.write(getBiffType()); 77 78 super.write(output); 79 80 output.write(cch); 81 output.write(rgch); 82 83 Debug.log(Debug.TRACE,"Writing Label record"); 84 } 85 86 /** 87 * Get the hex code for this particular <code>BIFFRecord</code> 88 * 89 * @return the hex code for <code>LabelCell</code> 90 */ getBiffType()91 public short getBiffType() { 92 return PocketExcelConstants.LABEL_CELL; 93 } 94 95 /** 96 * Reads a<code>LabelCell</code> from the specified <code>InputStream</code> 97 * 98 * @param input the <code>InputStram</code> to read from 99 */ read(InputStream input)100 public int read(InputStream input) throws IOException { 101 102 int numOfBytesRead = super.read(input); 103 104 numOfBytesRead += input.read(cch); 105 106 int strLen = EndianConverter.readShort(cch)*2; 107 rgch = new byte[strLen]; 108 input.read(rgch, 0, strLen); 109 110 Debug.log(Debug.TRACE, " cch : " + EndianConverter.readShort(cch) + 111 " rgch : " + new String(rgch, "UTF-16LE")); 112 113 return numOfBytesRead; 114 } 115 116 117 /** 118 * Gets the <code>String</code> representing the cells contents 119 * 120 * @return the <code>String</code> representing the cells contents 121 */ getString()122 public String getString() throws IOException { 123 return (new String(rgch,"UTF-16LE")); 124 } 125 126 /** 127 * Sets the <code>String</code> representing the cells contents 128 * 129 * @return the <code>String</code> representing the cells contents 130 */ setLabel(String cellContents)131 private void setLabel(String cellContents) throws IOException { 132 rgch = cellContents.getBytes("UTF-16LE"); 133 cch = EndianConverter.writeShort((short)cellContents.length()); 134 } 135 } 136