diff --git a/.cvsignore b/.cvsignore index f1f65bf2c..0c93c5025 100644 --- a/.cvsignore +++ b/.cvsignore @@ -10,4 +10,5 @@ p1.log p2.log poi.ipr release-bin -POILogger.log \ No newline at end of file +POILogger.log +jakarta-poi.ipr \ No newline at end of file diff --git a/build.xml b/build.xml index d124561fc..37df3d57d 100644 --- a/build.xml +++ b/build.xml @@ -410,6 +410,23 @@ or target="${target.vm}"> + + + + + + + + + + + + + + + + diff --git a/src/java/org/apache/poi/hssf/dev/BiffViewer.java b/src/java/org/apache/poi/hssf/dev/BiffViewer.java index b44abf42f..3e689d845 100644 --- a/src/java/org/apache/poi/hssf/dev/BiffViewer.java +++ b/src/java/org/apache/poi/hssf/dev/BiffViewer.java @@ -587,6 +587,14 @@ public class BiffViewer retval = new MergeCellsRecord(rectype, size, data); break; + case AreaRecord.sid : + retval = new AreaRecord(rectype, size, data); + break; + + case DataFormatRecord.sid : + retval = new DataFormatRecord(rectype, size, data); + break; + default : retval = new UnknownRecord(rectype, size, data); } diff --git a/src/java/org/apache/poi/hssf/record/AreaRecord.java b/src/java/org/apache/poi/hssf/record/AreaRecord.java new file mode 100644 index 000000000..a43969bb5 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/AreaRecord.java @@ -0,0 +1,253 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * The area record is used to define a area chart. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class AreaRecord + extends Record +{ + public final static short sid = 0x101A; + private short field_1_formatFlags; + private BitField stacked = new BitField(0x1); + private BitField displayAsPercentage = new BitField(0x2); + private BitField shadow = new BitField(0x4); + + + public AreaRecord() + { + + } + + /** + * Constructs a Area record and sets its fields appropriately. + * + * @param id id must be 0x101A or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public AreaRecord(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a Area record and sets its fields appropriately. + * + * @param id id must be 0x101A or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public AreaRecord(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a Area record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + field_1_formatFlags = LittleEndian.getShort(data, 0 + offset); + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[Area]\n"); + + buffer.append(" .formatFlags = ") + .append("0x") + .append(HexDump.toHex((short)getFormatFlags())) + .append(" (").append(getFormatFlags()).append(" )\n"); + buffer.append(" .stacked = ").append(isStacked ()).append('\n'); + buffer.append(" .displayAsPercentage = ").append(isDisplayAsPercentage ()).append('\n'); + buffer.append(" .shadow = ").append(isShadow ()).append('\n'); + + buffer.append("[/Area]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putShort(data, 4 + offset, field_1_formatFlags); + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + return 4 + 2; + } + + public short getSid() + { + return this.sid; + } + + + /** + * Get the format flags field for the Area record. + */ + public short getFormatFlags() + { + return field_1_formatFlags; + } + + /** + * Set the format flags field for the Area record. + */ + public void setFormatFlags(short field_1_formatFlags) + { + this.field_1_formatFlags = field_1_formatFlags; + } + + /** + * Sets the stacked field value. + * series is stacked + */ + public void setStacked(boolean value) + { + field_1_formatFlags = stacked.setShortBoolean(field_1_formatFlags, value); + } + + /** + * series is stacked + * @return the stacked field value. + */ + public boolean isStacked() + { + return stacked.isSet(field_1_formatFlags); + } + + /** + * Sets the display as percentage field value. + * results displayed as percentages + */ + public void setDisplayAsPercentage(boolean value) + { + field_1_formatFlags = displayAsPercentage.setShortBoolean(field_1_formatFlags, value); + } + + /** + * results displayed as percentages + * @return the display as percentage field value. + */ + public boolean isDisplayAsPercentage() + { + return displayAsPercentage.isSet(field_1_formatFlags); + } + + /** + * Sets the shadow field value. + * display a shadow for the chart + */ + public void setShadow(boolean value) + { + field_1_formatFlags = shadow.setShortBoolean(field_1_formatFlags, value); + } + + /** + * display a shadow for the chart + * @return the shadow field value. + */ + public boolean isShadow() + { + return shadow.isSet(field_1_formatFlags); + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/record/BarRecord.java b/src/java/org/apache/poi/hssf/record/BarRecord.java new file mode 100644 index 000000000..b01368cd6 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/BarRecord.java @@ -0,0 +1,322 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * The bar record is used to define a bar chart. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class BarRecord + extends Record +{ + public final static short sid = 0x1017; + private short field_1_barSpace; + private short field_2_categorySpace; + private short field_3_formatFlags; + private BitField horizontal = new BitField(0x1); + private BitField stacked = new BitField(0x2); + private BitField displayAsPercentage = new BitField(0x4); + private BitField shadow = new BitField(0x8); + + + public BarRecord() + { + field_2_categorySpace = 50; + + } + + /** + * Constructs a Bar record and sets its fields appropriately. + * + * @param id id must be 0x1017 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public BarRecord(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a Bar record and sets its fields appropriately. + * + * @param id id must be 0x1017 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public BarRecord(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a Bar record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + field_1_barSpace = LittleEndian.getShort(data, 0 + offset); + field_2_categorySpace = LittleEndian.getShort(data, 2 + offset); + field_3_formatFlags = LittleEndian.getShort(data, 4 + offset); + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[Bar]\n"); + + buffer.append(" .barSpace = ") + .append("0x") + .append(HexDump.toHex((short)getBarSpace())) + .append(" (").append(getBarSpace()).append(" )\n"); + + buffer.append(" .categorySpace = ") + .append("0x") + .append(HexDump.toHex((short)getCategorySpace())) + .append(" (").append(getCategorySpace()).append(" )\n"); + + buffer.append(" .formatFlags = ") + .append("0x") + .append(HexDump.toHex((short)getFormatFlags())) + .append(" (").append(getFormatFlags()).append(" )\n"); + buffer.append(" .horizontal = ").append(isHorizontal ()).append('\n'); + buffer.append(" .stacked = ").append(isStacked ()).append('\n'); + buffer.append(" .displayAsPercentage = ").append(isDisplayAsPercentage ()).append('\n'); + buffer.append(" .shadow = ").append(isShadow ()).append('\n'); + + buffer.append("[/Bar]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putShort(data, 4 + offset, field_1_barSpace); + LittleEndian.putShort(data, 6 + offset, field_2_categorySpace); + LittleEndian.putShort(data, 8 + offset, field_3_formatFlags); + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + return 4 + 2 + 2 + 2; + } + + public short getSid() + { + return this.sid; + } + + + /** + * Get the bar space field for the Bar record. + */ + public short getBarSpace() + { + return field_1_barSpace; + } + + /** + * Set the bar space field for the Bar record. + */ + public void setBarSpace(short field_1_barSpace) + { + this.field_1_barSpace = field_1_barSpace; + } + + /** + * Get the category space field for the Bar record. + */ + public short getCategorySpace() + { + return field_2_categorySpace; + } + + /** + * Set the category space field for the Bar record. + */ + public void setCategorySpace(short field_2_categorySpace) + { + this.field_2_categorySpace = field_2_categorySpace; + } + + /** + * Get the format flags field for the Bar record. + */ + public short getFormatFlags() + { + return field_3_formatFlags; + } + + /** + * Set the format flags field for the Bar record. + */ + public void setFormatFlags(short field_3_formatFlags) + { + this.field_3_formatFlags = field_3_formatFlags; + } + + /** + * Sets the horizontal field value. + * true to display horizontal bar charts, false for vertical + */ + public void setHorizontal(boolean value) + { + field_3_formatFlags = horizontal.setShortBoolean(field_3_formatFlags, value); + } + + /** + * true to display horizontal bar charts, false for vertical + * @return the horizontal field value. + */ + public boolean isHorizontal() + { + return horizontal.isSet(field_3_formatFlags); + } + + /** + * Sets the stacked field value. + * stack displayed values + */ + public void setStacked(boolean value) + { + field_3_formatFlags = stacked.setShortBoolean(field_3_formatFlags, value); + } + + /** + * stack displayed values + * @return the stacked field value. + */ + public boolean isStacked() + { + return stacked.isSet(field_3_formatFlags); + } + + /** + * Sets the display as percentage field value. + * display chart values as a percentage + */ + public void setDisplayAsPercentage(boolean value) + { + field_3_formatFlags = displayAsPercentage.setShortBoolean(field_3_formatFlags, value); + } + + /** + * display chart values as a percentage + * @return the display as percentage field value. + */ + public boolean isDisplayAsPercentage() + { + return displayAsPercentage.isSet(field_3_formatFlags); + } + + /** + * Sets the shadow field value. + * display a shadow for the chart + */ + public void setShadow(boolean value) + { + field_3_formatFlags = shadow.setShortBoolean(field_3_formatFlags, value); + } + + /** + * display a shadow for the chart + * @return the shadow field value. + */ + public boolean isShadow() + { + return shadow.isSet(field_3_formatFlags); + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/record/DatRecord.java b/src/java/org/apache/poi/hssf/record/DatRecord.java new file mode 100644 index 000000000..9121ce3f5 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/DatRecord.java @@ -0,0 +1,273 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * The dat record is used to store options for the chart. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class DatRecord + extends Record +{ + public final static short sid = 0x1063; + private short field_1_options; + private BitField horizontalBorder = new BitField(0x1); + private BitField verticalBorder = new BitField(0x2); + private BitField border = new BitField(0x4); + private BitField showSeriesKey = new BitField(0x8); + + + public DatRecord() + { + + } + + /** + * Constructs a Dat record and sets its fields appropriately. + * + * @param id id must be 0x1063 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public DatRecord(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a Dat record and sets its fields appropriately. + * + * @param id id must be 0x1063 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public DatRecord(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a Dat record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + field_1_options = LittleEndian.getShort(data, 0 + offset); + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[Dat]\n"); + + buffer.append(" .options = ") + .append("0x") + .append(HexDump.toHex((short)getOptions())) + .append(" (").append(getOptions()).append(" )\n"); + buffer.append(" .horizontalBorder = ").append(isHorizontalBorder ()).append('\n'); + buffer.append(" .verticalBorder = ").append(isVerticalBorder ()).append('\n'); + buffer.append(" .border = ").append(isBorder ()).append('\n'); + buffer.append(" .showSeriesKey = ").append(isShowSeriesKey ()).append('\n'); + + buffer.append("[/Dat]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putShort(data, 4 + offset, field_1_options); + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + return 4 + 2; + } + + public short getSid() + { + return this.sid; + } + + + /** + * Get the options field for the Dat record. + */ + public short getOptions() + { + return field_1_options; + } + + /** + * Set the options field for the Dat record. + */ + public void setOptions(short field_1_options) + { + this.field_1_options = field_1_options; + } + + /** + * Sets the horizontal border field value. + * has a horizontal border + */ + public void setHorizontalBorder(boolean value) + { + field_1_options = horizontalBorder.setShortBoolean(field_1_options, value); + } + + /** + * has a horizontal border + * @return the horizontal border field value. + */ + public boolean isHorizontalBorder() + { + return horizontalBorder.isSet(field_1_options); + } + + /** + * Sets the vertical border field value. + * has vertical border + */ + public void setVerticalBorder(boolean value) + { + field_1_options = verticalBorder.setShortBoolean(field_1_options, value); + } + + /** + * has vertical border + * @return the vertical border field value. + */ + public boolean isVerticalBorder() + { + return verticalBorder.isSet(field_1_options); + } + + /** + * Sets the border field value. + * data table has a border + */ + public void setBorder(boolean value) + { + field_1_options = border.setShortBoolean(field_1_options, value); + } + + /** + * data table has a border + * @return the border field value. + */ + public boolean isBorder() + { + return border.isSet(field_1_options); + } + + /** + * Sets the show series key field value. + * shows the series key + */ + public void setShowSeriesKey(boolean value) + { + field_1_options = showSeriesKey.setShortBoolean(field_1_options, value); + } + + /** + * shows the series key + * @return the show series key field value. + */ + public boolean isShowSeriesKey() + { + return showSeriesKey.isSet(field_1_options); + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/record/DataFormatRecord.java b/src/java/org/apache/poi/hssf/record/DataFormatRecord.java new file mode 100644 index 000000000..6aa5c8a22 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/DataFormatRecord.java @@ -0,0 +1,285 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * The data format record is used to index into a series. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class DataFormatRecord + extends Record +{ + public final static short sid = 0x1006; + private short field_1_pointNumber; + private short field_2_seriesIndex; + private short field_3_seriesNumber; + private short field_4_formatFlags; + private BitField useExcel4Colors = new BitField(0x1); + + + public DataFormatRecord() + { + + } + + /** + * Constructs a DataFormat record and sets its fields appropriately. + * + * @param id id must be 0x1006 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public DataFormatRecord(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a DataFormat record and sets its fields appropriately. + * + * @param id id must be 0x1006 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public DataFormatRecord(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a DataFormat record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + field_1_pointNumber = LittleEndian.getShort(data, 0 + offset); + field_2_seriesIndex = LittleEndian.getShort(data, 2 + offset); + field_3_seriesNumber = LittleEndian.getShort(data, 4 + offset); + field_4_formatFlags = LittleEndian.getShort(data, 6 + offset); + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[DataFormat]\n"); + + buffer.append(" .pointNumber = ") + .append("0x") + .append(HexDump.toHex((short)getPointNumber())) + .append(" (").append(getPointNumber()).append(" )\n"); + + buffer.append(" .seriesIndex = ") + .append("0x") + .append(HexDump.toHex((short)getSeriesIndex())) + .append(" (").append(getSeriesIndex()).append(" )\n"); + + buffer.append(" .seriesNumber = ") + .append("0x") + .append(HexDump.toHex((short)getSeriesNumber())) + .append(" (").append(getSeriesNumber()).append(" )\n"); + + buffer.append(" .formatFlags = ") + .append("0x") + .append(HexDump.toHex((short)getFormatFlags())) + .append(" (").append(getFormatFlags()).append(" )\n"); + buffer.append(" .useExcel4Colors = ").append(isUseExcel4Colors ()).append('\n'); + + buffer.append("[/DataFormat]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putShort(data, 4 + offset, field_1_pointNumber); + LittleEndian.putShort(data, 6 + offset, field_2_seriesIndex); + LittleEndian.putShort(data, 8 + offset, field_3_seriesNumber); + LittleEndian.putShort(data, 10 + offset, field_4_formatFlags); + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + return 4 + 2 + 2 + 2 + 2; + } + + public short getSid() + { + return this.sid; + } + + + /** + * Get the point number field for the DataFormat record. + */ + public short getPointNumber() + { + return field_1_pointNumber; + } + + /** + * Set the point number field for the DataFormat record. + */ + public void setPointNumber(short field_1_pointNumber) + { + this.field_1_pointNumber = field_1_pointNumber; + } + + /** + * Get the series index field for the DataFormat record. + */ + public short getSeriesIndex() + { + return field_2_seriesIndex; + } + + /** + * Set the series index field for the DataFormat record. + */ + public void setSeriesIndex(short field_2_seriesIndex) + { + this.field_2_seriesIndex = field_2_seriesIndex; + } + + /** + * Get the series number field for the DataFormat record. + */ + public short getSeriesNumber() + { + return field_3_seriesNumber; + } + + /** + * Set the series number field for the DataFormat record. + */ + public void setSeriesNumber(short field_3_seriesNumber) + { + this.field_3_seriesNumber = field_3_seriesNumber; + } + + /** + * Get the format flags field for the DataFormat record. + */ + public short getFormatFlags() + { + return field_4_formatFlags; + } + + /** + * Set the format flags field for the DataFormat record. + */ + public void setFormatFlags(short field_4_formatFlags) + { + this.field_4_formatFlags = field_4_formatFlags; + } + + /** + * Sets the use excel 4 colors field value. + * set true to use excel 4 colors. + */ + public void setUseExcel4Colors(boolean value) + { + field_4_formatFlags = useExcel4Colors.setShortBoolean(field_4_formatFlags, value); + } + + /** + * set true to use excel 4 colors. + * @return the use excel 4 colors field value. + */ + public boolean isUseExcel4Colors() + { + return useExcel4Colors.isSet(field_4_formatFlags); + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/record/FrameRecord.java b/src/java/org/apache/poi/hssf/record/FrameRecord.java new file mode 100644 index 000000000..89cdbbb81 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/FrameRecord.java @@ -0,0 +1,268 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * The frame record indicates whether there is a border around the displayed text of a chart. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class FrameRecord + extends Record +{ + public final static short sid = 0x1032; + private short field_1_borderType; + public final static short BORDER_TYPE_REGULAR = 0; + public final static short BORDER_TYPE_SHADOW = 1; + private short field_2_options; + private BitField autoSize = new BitField(0x1); + private BitField autoPosition = new BitField(0x2); + + + public FrameRecord() + { + + } + + /** + * Constructs a Frame record and sets its fields appropriately. + * + * @param id id must be 0x1032 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public FrameRecord(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a Frame record and sets its fields appropriately. + * + * @param id id must be 0x1032 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public FrameRecord(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a Frame record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + field_1_borderType = LittleEndian.getShort(data, 0 + offset); + field_2_options = LittleEndian.getShort(data, 2 + offset); + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[Frame]\n"); + + buffer.append(" .borderType = ") + .append("0x") + .append(HexDump.toHex((short)getBorderType())) + .append(" (").append(getBorderType()).append(" )\n"); + + buffer.append(" .options = ") + .append("0x") + .append(HexDump.toHex((short)getOptions())) + .append(" (").append(getOptions()).append(" )\n"); + buffer.append(" .autoSize = ").append(isAutoSize ()).append('\n'); + buffer.append(" .autoPosition = ").append(isAutoPosition ()).append('\n'); + + buffer.append("[/Frame]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putShort(data, 4 + offset, field_1_borderType); + LittleEndian.putShort(data, 6 + offset, field_2_options); + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + return 4 + 2 + 2; + } + + public short getSid() + { + return this.sid; + } + + + /** + * Get the border type field for the Frame record. + * + * @return One of + * BORDER_TYPE_REGULAR + * BORDER_TYPE_SHADOW + */ + public short getBorderType() + { + return field_1_borderType; + } + + /** + * Set the border type field for the Frame record. + * + * @param field_1_borderType + * One of + * BORDER_TYPE_REGULAR + * BORDER_TYPE_SHADOW + */ + public void setBorderType(short field_1_borderType) + { + this.field_1_borderType = field_1_borderType; + } + + /** + * Get the options field for the Frame record. + */ + public short getOptions() + { + return field_2_options; + } + + /** + * Set the options field for the Frame record. + */ + public void setOptions(short field_2_options) + { + this.field_2_options = field_2_options; + } + + /** + * Sets the auto size field value. + * excel calculates the size automatically if true + */ + public void setAutoSize(boolean value) + { + field_2_options = autoSize.setShortBoolean(field_2_options, value); + } + + /** + * excel calculates the size automatically if true + * @return the auto size field value. + */ + public boolean isAutoSize() + { + return autoSize.isSet(field_2_options); + } + + /** + * Sets the auto position field value. + * excel calculates the position automatically + */ + public void setAutoPosition(boolean value) + { + field_2_options = autoPosition.setShortBoolean(field_2_options, value); + } + + /** + * excel calculates the position automatically + * @return the auto position field value. + */ + public boolean isAutoPosition() + { + return autoPosition.isSet(field_2_options); + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/record/LegendRecord.java b/src/java/org/apache/poi/hssf/record/LegendRecord.java new file mode 100644 index 000000000..5f5e73d69 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/LegendRecord.java @@ -0,0 +1,494 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * The legend record specifies the location of legend on a chart and it's overall size. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class LegendRecord + extends Record +{ + public final static short sid = 0x1015; + private int field_1_xPosition; + private int field_2_yPosition; + private int field_3_xSize; + private int field_4_ySize; + private byte field_5_type; + public final static byte TYPE_BOTTOM = 0; + public final static byte TYPE_CORNER = 1; + public final static byte TYPE_TOP = 2; + public final static byte TYPE_RIGHT = 3; + public final static byte TYPE_LEFT = 4; + public final static byte TYPE_NOT_DOCKED = 7; + private byte field_6_spacing; + public final static byte SPACING_CLOSE = 0; + public final static byte SPACING_MEDIUM = 1; + public final static byte SPACING_OPEN = 2; + private short field_7_options; + private BitField autoPosition = new BitField(0x1); + private BitField autoSeries = new BitField(0x2); + private BitField autoPosX = new BitField(0x4); + private BitField autoPosY = new BitField(0x8); + private BitField vert = new BitField(0x10); + private BitField containsDataTable = new BitField(0x20); + + + public LegendRecord() + { + + } + + /** + * Constructs a Legend record and sets its fields appropriately. + * + * @param id id must be 0x1015 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public LegendRecord(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a Legend record and sets its fields appropriately. + * + * @param id id must be 0x1015 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public LegendRecord(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a Legend record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + field_1_xPosition = LittleEndian.getInt(data, 0 + offset); + field_2_yPosition = LittleEndian.getInt(data, 4 + offset); + field_3_xSize = LittleEndian.getInt(data, 8 + offset); + field_4_ySize = LittleEndian.getInt(data, 12 + offset); + field_5_type = data[ 16 + offset ]; + field_6_spacing = data[ 17 + offset ]; + field_7_options = LittleEndian.getShort(data, 18 + offset); + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[Legend]\n"); + + buffer.append(" .xPosition = ") + .append("0x") + .append(HexDump.toHex((int)getXPosition())) + .append(" (").append(getXPosition()).append(" )\n"); + + buffer.append(" .yPosition = ") + .append("0x") + .append(HexDump.toHex((int)getYPosition())) + .append(" (").append(getYPosition()).append(" )\n"); + + buffer.append(" .xSize = ") + .append("0x") + .append(HexDump.toHex((int)getXSize())) + .append(" (").append(getXSize()).append(" )\n"); + + buffer.append(" .ySize = ") + .append("0x") + .append(HexDump.toHex((int)getYSize())) + .append(" (").append(getYSize()).append(" )\n"); + + buffer.append(" .type = ") + .append("0x") + .append(HexDump.toHex((byte)getType())) + .append(" (").append(getType()).append(" )\n"); + + buffer.append(" .spacing = ") + .append("0x") + .append(HexDump.toHex((byte)getSpacing())) + .append(" (").append(getSpacing()).append(" )\n"); + + buffer.append(" .options = ") + .append("0x") + .append(HexDump.toHex((short)getOptions())) + .append(" (").append(getOptions()).append(" )\n"); + buffer.append(" .autoPosition = ").append(isAutoPosition ()).append('\n'); + buffer.append(" .autoSeries = ").append(isAutoSeries ()).append('\n'); + buffer.append(" .autoPosX = ").append(isAutoPosX ()).append('\n'); + buffer.append(" .autoPosY = ").append(isAutoPosY ()).append('\n'); + buffer.append(" .vert = ").append(isVert ()).append('\n'); + buffer.append(" .containsDataTable = ").append(isContainsDataTable ()).append('\n'); + + buffer.append("[/Legend]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putInt(data, 4 + offset, field_1_xPosition); + LittleEndian.putInt(data, 8 + offset, field_2_yPosition); + LittleEndian.putInt(data, 12 + offset, field_3_xSize); + LittleEndian.putInt(data, 16 + offset, field_4_ySize); + data[ 20 + offset ] = field_5_type; + data[ 21 + offset ] = field_6_spacing; + LittleEndian.putShort(data, 22 + offset, field_7_options); + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2; + } + + public short getSid() + { + return this.sid; + } + + + /** + * Get the x position field for the Legend record. + */ + public int getXPosition() + { + return field_1_xPosition; + } + + /** + * Set the x position field for the Legend record. + */ + public void setXPosition(int field_1_xPosition) + { + this.field_1_xPosition = field_1_xPosition; + } + + /** + * Get the y position field for the Legend record. + */ + public int getYPosition() + { + return field_2_yPosition; + } + + /** + * Set the y position field for the Legend record. + */ + public void setYPosition(int field_2_yPosition) + { + this.field_2_yPosition = field_2_yPosition; + } + + /** + * Get the x size field for the Legend record. + */ + public int getXSize() + { + return field_3_xSize; + } + + /** + * Set the x size field for the Legend record. + */ + public void setXSize(int field_3_xSize) + { + this.field_3_xSize = field_3_xSize; + } + + /** + * Get the y size field for the Legend record. + */ + public int getYSize() + { + return field_4_ySize; + } + + /** + * Set the y size field for the Legend record. + */ + public void setYSize(int field_4_ySize) + { + this.field_4_ySize = field_4_ySize; + } + + /** + * Get the type field for the Legend record. + * + * @return One of + * TYPE_BOTTOM + * TYPE_CORNER + * TYPE_TOP + * TYPE_RIGHT + * TYPE_LEFT + * TYPE_NOT_DOCKED + */ + public byte getType() + { + return field_5_type; + } + + /** + * Set the type field for the Legend record. + * + * @param field_5_type + * One of + * TYPE_BOTTOM + * TYPE_CORNER + * TYPE_TOP + * TYPE_RIGHT + * TYPE_LEFT + * TYPE_NOT_DOCKED + */ + public void setType(byte field_5_type) + { + this.field_5_type = field_5_type; + } + + /** + * Get the spacing field for the Legend record. + * + * @return One of + * SPACING_CLOSE + * SPACING_MEDIUM + * SPACING_OPEN + */ + public byte getSpacing() + { + return field_6_spacing; + } + + /** + * Set the spacing field for the Legend record. + * + * @param field_6_spacing + * One of + * SPACING_CLOSE + * SPACING_MEDIUM + * SPACING_OPEN + */ + public void setSpacing(byte field_6_spacing) + { + this.field_6_spacing = field_6_spacing; + } + + /** + * Get the options field for the Legend record. + */ + public short getOptions() + { + return field_7_options; + } + + /** + * Set the options field for the Legend record. + */ + public void setOptions(short field_7_options) + { + this.field_7_options = field_7_options; + } + + /** + * Sets the auto position field value. + * set to true if legend is docked + */ + public void setAutoPosition(boolean value) + { + field_7_options = autoPosition.setShortBoolean(field_7_options, value); + } + + /** + * set to true if legend is docked + * @return the auto position field value. + */ + public boolean isAutoPosition() + { + return autoPosition.isSet(field_7_options); + } + + /** + * Sets the auto series field value. + * automatic series distribution + */ + public void setAutoSeries(boolean value) + { + field_7_options = autoSeries.setShortBoolean(field_7_options, value); + } + + /** + * automatic series distribution + * @return the auto series field value. + */ + public boolean isAutoSeries() + { + return autoSeries.isSet(field_7_options); + } + + /** + * Sets the auto pos x field value. + * x positioning is done automatically + */ + public void setAutoPosX(boolean value) + { + field_7_options = autoPosX.setShortBoolean(field_7_options, value); + } + + /** + * x positioning is done automatically + * @return the auto pos x field value. + */ + public boolean isAutoPosX() + { + return autoPosX.isSet(field_7_options); + } + + /** + * Sets the auto pos y field value. + * y positioning is done automatically + */ + public void setAutoPosY(boolean value) + { + field_7_options = autoPosY.setShortBoolean(field_7_options, value); + } + + /** + * y positioning is done automatically + * @return the auto pos y field value. + */ + public boolean isAutoPosY() + { + return autoPosY.isSet(field_7_options); + } + + /** + * Sets the vert field value. + * if true legend is vertical (otherwise it's horizonal) + */ + public void setVert(boolean value) + { + field_7_options = vert.setShortBoolean(field_7_options, value); + } + + /** + * if true legend is vertical (otherwise it's horizonal) + * @return the vert field value. + */ + public boolean isVert() + { + return vert.isSet(field_7_options); + } + + /** + * Sets the contains data table field value. + * true if the chart contains the data table + */ + public void setContainsDataTable(boolean value) + { + field_7_options = containsDataTable.setShortBoolean(field_7_options, value); + } + + /** + * true if the chart contains the data table + * @return the contains data table field value. + */ + public boolean isContainsDataTable() + { + return containsDataTable.isSet(field_7_options); + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/record/ProtectRecord.java b/src/java/org/apache/poi/hssf/record/ProtectRecord.java index d40f4bfcb..f35239503 100644 --- a/src/java/org/apache/poi/hssf/record/ProtectRecord.java +++ b/src/java/org/apache/poi/hssf/record/ProtectRecord.java @@ -80,9 +80,9 @@ public class ProtectRecord /** * Constructs a Protect record and sets its fields appropriately. * - * @param short id must be 0x12 or an exception will be throw upon validation - * @param short size the size of the data area of the record - * @param byte[] data of the record (should not contain sid/len) + * @param id id must be 0x12 or an exception will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) */ public ProtectRecord(short id, short size, byte [] data) @@ -93,9 +93,9 @@ public class ProtectRecord /** * Constructs a Protect record and sets its fields appropriately. * - * @param short id must be 0x12 or an exception will be throw upon validation - * @param short size the size of the data area of the record - * @param byte[] data of the record (should not contain sid/len) + * @param id id must be 0x12 or an exception will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) * @param offset of the data */ @@ -119,7 +119,7 @@ public class ProtectRecord /** * set whether the sheet is protected or not - * @param whether to protect the sheet or not + * @param protect whether to protect the sheet or not */ public void setProtect(boolean protect) diff --git a/src/java/org/apache/poi/hssf/record/SeriesRecord.java b/src/java/org/apache/poi/hssf/record/SeriesRecord.java index 3861b2861..6225b0e31 100644 --- a/src/java/org/apache/poi/hssf/record/SeriesRecord.java +++ b/src/java/org/apache/poi/hssf/record/SeriesRecord.java @@ -53,42 +53,59 @@ * . */ + package org.apache.poi.hssf.record; + + +import org.apache.poi.util.BitField; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; /** - * The series record defines the (graphing) series within a chart. - * This record is matched with a corresponding EndRecord. - * + * The series record describes the overall data for a series. + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) */ - public class SeriesRecord extends Record { - public static final short sid = 0x1003; - public static final short AXIS_TYPE_DATE = 0; - public static final short AXIS_TYPE_NUMERIC = 1; - public static final short AXIS_TYPE_SEQUENCE = 3; - public static final short AXIS_TYPE_TEXT = 4; - private short field_1_xAxisType; - private short field_2_yAxisType; - private short field_3_countOfXValues; - private short field_4_countOfYValues; - private short field_5_bubbleType; // type of data in "bubble size series" - private short field_6_countOfBubbleSeries; // count of bubble series values + public final static short sid = 0x1003; + private short field_1_categoryDataType; + public final static short CATEGORY_DATA_TYPE_DATES = 0; + public final static short CATEGORY_DATA_TYPE_NUMERIC = 1; + public final static short CATEGORY_DATA_TYPE_SEQUENCE = 2; + public final static short CATEGORY_DATA_TYPE_TEXT = 3; + private short field_2_valuesDataType; + public final static short VALUES_DATA_TYPE_DATES = 0; + public final static short VALUES_DATA_TYPE_NUMERIC = 1; + public final static short VALUES_DATA_TYPE_SEQUENCE = 2; + public final static short VALUES_DATA_TYPE_TEXT = 3; + private short field_3_numCategories; + private short field_4_numValues; + private short field_5_bubbleSeriesType; + public final static short BUBBLE_SERIES_TYPE_DATES = 0; + public final static short BUBBLE_SERIES_TYPE_NUMERIC = 1; + public final static short BUBBLE_SERIES_TYPE_SEQUENCE = 2; + public final static short BUBBLE_SERIES_TYPE_TEXT = 3; + private short field_6_numBubbleValues; + public SeriesRecord() { + } /** - * Constructs a SeriesRecord record and sets its fields appropriately. + * Constructs a Series record and sets its fields appropriately. * - * @param short id must be 0x1003 or an exception will be throw upon validation - * @param short size the size of the data area of the record - * @param byte[] data of the record (should not contain sid/len) + * @param id id must be 0x1003 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) */ public SeriesRecord(short id, short size, byte [] data) @@ -97,11 +114,12 @@ public class SeriesRecord } /** - * Constructs a SeriesRecord record and sets its fields appropriately. + * Constructs a Series record and sets its fields appropriately. * - * @param short id must be 0x1003 or an exception will be throw upon validation - * @param short size the size of the data area of the record - * @param byte[] data of the record (should not contain sid/len) + * @param id id must be 0x1003 or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) * @param offset of the record's data */ @@ -110,57 +128,91 @@ public class SeriesRecord super(id, size, data, offset); } + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ protected void validateSid(short id) { if (id != sid) { - throw new RecordFormatException("NOT A SERIES RECORD"); + throw new RecordFormatException("Not a Series record"); } } protected void fillFields(byte [] data, short size, int offset) { - field_1_xAxisType = LittleEndian.getShort(data, 0 + offset); - field_2_yAxisType = LittleEndian.getShort(data, 2 + offset); - field_3_countOfXValues = LittleEndian.getShort(data, 4 + offset); - field_4_countOfYValues = LittleEndian.getShort(data, 6 + offset); - field_5_bubbleType = LittleEndian.getShort(data, 8 + offset); - field_6_countOfBubbleSeries = LittleEndian.getShort(data, - 10 + offset); + field_1_categoryDataType = LittleEndian.getShort(data, 0 + offset); + field_2_valuesDataType = LittleEndian.getShort(data, 2 + offset); + field_3_numCategories = LittleEndian.getShort(data, 4 + offset); + field_4_numValues = LittleEndian.getShort(data, 6 + offset); + field_5_bubbleSeriesType = LittleEndian.getShort(data, 8 + offset); + field_6_numBubbleValues = LittleEndian.getShort(data, 10 + offset); + } public String toString() { StringBuffer buffer = new StringBuffer(); - buffer.append("[SERIES]\n"); - buffer.append(" .xAxisType = ") - .append(Integer.toHexString(getXAxisType())).append("\n"); - buffer.append(" .yAxisType = ") - .append(Integer.toHexString(getYAxisType())).append("\n"); - buffer.append(" .countOfXValues = ").append(getCountOfXValues()) - .append("\n"); - buffer.append(" .countOfYValues = ").append(getCountOfYValues()) - .append("\n"); - buffer.append("[/SERIES]\n"); + buffer.append("[Series]\n"); + + buffer.append(" .categoryDataType = ") + .append("0x") + .append(HexDump.toHex((short)getCategoryDataType())) + .append(" (").append(getCategoryDataType()).append(" )\n"); + + buffer.append(" .valuesDataType = ") + .append("0x") + .append(HexDump.toHex((short)getValuesDataType())) + .append(" (").append(getValuesDataType()).append(" )\n"); + + buffer.append(" .numCategories = ") + .append("0x") + .append(HexDump.toHex((short)getNumCategories())) + .append(" (").append(getNumCategories()).append(" )\n"); + + buffer.append(" .numValues = ") + .append("0x") + .append(HexDump.toHex((short)getNumValues())) + .append(" (").append(getNumValues()).append(" )\n"); + + buffer.append(" .bubbleSeriesType = ") + .append("0x") + .append(HexDump.toHex((short)getBubbleSeriesType())) + .append(" (").append(getBubbleSeriesType()).append(" )\n"); + + buffer.append(" .numBubbleValues = ") + .append("0x") + .append(HexDump.toHex((short)getNumBubbleValues())) + .append(" (").append(getNumBubbleValues()).append(" )\n"); + + buffer.append("[/Series]\n"); return buffer.toString(); } - public int serialize(int offset, byte [] data) + public int serialize(int offset, byte[] data) { LittleEndian.putShort(data, 0 + offset, sid); - LittleEndian.putShort(data, 2 + offset, - (( short ) 12)); // 12 byte length - LittleEndian.putShort(data, 4 + offset, getXAxisType()); - LittleEndian.putShort(data, 6 + offset, getYAxisType()); - LittleEndian.putShort(data, 8 + offset, getCountOfXValues()); - LittleEndian.putShort(data, 10 + offset, getCountOfYValues()); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + LittleEndian.putShort(data, 4 + offset, field_1_categoryDataType); + LittleEndian.putShort(data, 6 + offset, field_2_valuesDataType); + LittleEndian.putShort(data, 8 + offset, field_3_numCategories); + LittleEndian.putShort(data, 10 + offset, field_4_numValues); + LittleEndian.putShort(data, 12 + offset, field_5_bubbleSeriesType); + LittleEndian.putShort(data, 14 + offset, field_6_numBubbleValues); + return getRecordSize(); } + /** + * Size of record (exluding 4 byte header) + */ public int getRecordSize() { - return 12; + return 4 + 2 + 2 + 2 + 2 + 2 + 2; } public short getSid() @@ -168,75 +220,145 @@ public class SeriesRecord return this.sid; } - /** - * @return one of AXIS_TYPE_XXX - */ - public short getXAxisType() + /** + * Get the category data type field for the Series record. + * + * @return One of + * CATEGORY_DATA_TYPE_DATES + * CATEGORY_DATA_TYPE_NUMERIC + * CATEGORY_DATA_TYPE_SEQUENCE + * CATEGORY_DATA_TYPE_TEXT + */ + public short getCategoryDataType() { - return field_1_xAxisType; + return field_1_categoryDataType; } /** - * @param xAxisType one of AXIS_TYPE_XXX + * Set the category data type field for the Series record. + * + * @param field_1_categoryDataType + * One of + * CATEGORY_DATA_TYPE_DATES + * CATEGORY_DATA_TYPE_NUMERIC + * CATEGORY_DATA_TYPE_SEQUENCE + * CATEGORY_DATA_TYPE_TEXT */ - - public void setXAxisType(short xAxisType) + public void setCategoryDataType(short field_1_categoryDataType) { - this.field_1_xAxisType = xAxisType; + this.field_1_categoryDataType = field_1_categoryDataType; } /** - * @return one of AXIS_TYPE_XXX + * Get the values data type field for the Series record. + * + * @return One of + * VALUES_DATA_TYPE_DATES + * VALUES_DATA_TYPE_NUMERIC + * VALUES_DATA_TYPE_SEQUENCE + * VALUES_DATA_TYPE_TEXT */ - - public short getYAxisType() + public short getValuesDataType() { - return field_2_yAxisType; + return field_2_valuesDataType; } /** - * @param xAxisType one of AXIS_TYPE_XXX + * Set the values data type field for the Series record. + * + * @param field_2_valuesDataType + * One of + * VALUES_DATA_TYPE_DATES + * VALUES_DATA_TYPE_NUMERIC + * VALUES_DATA_TYPE_SEQUENCE + * VALUES_DATA_TYPE_TEXT */ - - public void setYAxisType(short yAxisType) + public void setValuesDataType(short field_2_valuesDataType) { - this.field_2_yAxisType = yAxisType; + this.field_2_valuesDataType = field_2_valuesDataType; } /** - * @return number of x values in the series. + * Get the num categories field for the Series record. */ - - public short getCountOfXValues() + public short getNumCategories() { - return field_3_countOfXValues; + return field_3_numCategories; } /** - * Sets the number of x values in the series. + * Set the num categories field for the Series record. */ - - public void setCountOfXValues(short countOfXValues) + public void setNumCategories(short field_3_numCategories) { - this.field_3_countOfXValues = countOfXValues; + this.field_3_numCategories = field_3_numCategories; } /** - * @return number of y values in the series. + * Get the num values field for the Series record. */ - - public short getCountOfYValues() + public short getNumValues() { - return field_4_countOfYValues; + return field_4_numValues; } /** - * @param countOfYValues sets the number of y values for the series. + * Set the num values field for the Series record. */ - - public void setCountOfYValues(short countOfYValues) + public void setNumValues(short field_4_numValues) { - this.field_4_countOfYValues = countOfYValues; + this.field_4_numValues = field_4_numValues; } -} + + /** + * Get the bubble series type field for the Series record. + * + * @return One of + * BUBBLE_SERIES_TYPE_DATES + * BUBBLE_SERIES_TYPE_NUMERIC + * BUBBLE_SERIES_TYPE_SEQUENCE + * BUBBLE_SERIES_TYPE_TEXT + */ + public short getBubbleSeriesType() + { + return field_5_bubbleSeriesType; + } + + /** + * Set the bubble series type field for the Series record. + * + * @param field_5_bubbleSeriesType + * One of + * BUBBLE_SERIES_TYPE_DATES + * BUBBLE_SERIES_TYPE_NUMERIC + * BUBBLE_SERIES_TYPE_SEQUENCE + * BUBBLE_SERIES_TYPE_TEXT + */ + public void setBubbleSeriesType(short field_5_bubbleSeriesType) + { + this.field_5_bubbleSeriesType = field_5_bubbleSeriesType; + } + + /** + * Get the num bubble values field for the Series record. + */ + public short getNumBubbleValues() + { + return field_6_numBubbleValues; + } + + /** + * Set the num bubble values field for the Series record. + */ + public void setNumBubbleValues(short field_6_numBubbleValues) + { + this.field_6_numBubbleValues = field_6_numBubbleValues; + } + + +} // END OF CLASS + + + + diff --git a/src/java/org/apache/poi/hssf/util/RecordGenerator.java b/src/java/org/apache/poi/hssf/util/RecordGenerator.java new file mode 100644 index 000000000..406dde9c0 --- /dev/null +++ b/src/java/org/apache/poi/hssf/util/RecordGenerator.java @@ -0,0 +1,133 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.poi.hssf.util; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; + +public class RecordGenerator +{ + public static void main(String[] args) + throws Exception + { + if (args.length != 4) + { + System.out.println("Usage:"); + System.out.println(" java org.apache.poi.hssf.util.RecordGenerator RECORD_DEFINTIONS RECORD_STYLES DEST_SRC_PATH TEST_SRC_PATH"); + } + else + { + generateRecords(args[0], args[1], args[2], args[3]); + } + } + + private static void generateRecords(String defintionsDir, String recordStyleDir, String destSrcPathDir, String testSrcPathDir) + throws Exception + { + File definitionsFile = new File(defintionsDir); + + for (int i = 0; i < definitionsFile.listFiles().length; i++) + { + File file = definitionsFile.listFiles()[i]; + if (file.isFile() && file.getName().endsWith("_record.xml")) + { + // Get record name and package + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(file); + Element record = document.getDocumentElement(); + String recordName = record.getAttributes().getNamedItem("name").getNodeValue(); + String packageName = record.getAttributes().getNamedItem("package").getNodeValue(); + packageName = packageName.replace('.','/'); + + // Generate record + String destinationPath = destSrcPathDir + "/" + packageName ; + File destinationPathFile = new File(destinationPath); + destinationPathFile.mkdirs(); + String destinationFilepath = destinationPath + "/" + recordName + "Record.java"; + String args[] = new String [] { "-in", file.getAbsolutePath(), "-xsl", recordStyleDir + "/record.xsl", + "-out", destinationFilepath, + "-TEXT"}; + org.apache.xalan.xslt.Process.main( args ); + System.out.println("Generated record: " + destinationFilepath); + + // Generate test (if not already generated) + destinationPath = testSrcPathDir + "/" + packageName ; + destinationPathFile = new File(destinationPath); + destinationPathFile.mkdirs(); + destinationFilepath = destinationPath + "/Test" + recordName + "Record.java"; + if (new File(destinationFilepath).exists() == false) + { + args = new String [] { "-in", file.getAbsolutePath(), "-xsl", recordStyleDir + "/record_test.xsl", + "-out", destinationFilepath, + "-TEXT"}; + org.apache.xalan.xslt.Process.main( args ); + System.out.println("Generated test: " + destinationFilepath); + } + else + { + System.out.println("Skipped test generation: " + destinationFilepath); + } + } + } + } +} diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java index d2d54e819..4eac10f37 100644 --- a/src/java/org/apache/poi/util/HexDump.java +++ b/src/java/org/apache/poi/util/HexDump.java @@ -59,9 +59,10 @@ import java.io.*; /** * dump data in hexadecimal format; derived from a HexDump utility I - * wrote in June 2001 + * wrote in June 2001. * * @author Marc Johnson + * @author Glen Stampoultzis (glens at apache.org) */ public class HexDump @@ -89,7 +90,7 @@ public class HexDump * null */ - public static void dump(final byte [] data, final long offset, + public synchronized static void dump(final byte [] data, final long offset, final OutputStream stream, final int index) throws IOException, ArrayIndexOutOfBoundsException, IllegalArgumentException @@ -181,4 +182,48 @@ public class HexDump } return _cbuffer; } + + /** + * Converts the parameter to a hex value. + * + * @param value The value to convert + * @return The result right padded with 0 + */ + public static String toHex(final short value) + { + return toHex(value, 4); + } + + /** + * Converts the parameter to a hex value. + * + * @param value The value to convert + * @return The result right padded with 0 + */ + public static String toHex(final byte value) + { + return toHex(value, 2); + } + + /** + * Converts the parameter to a hex value. + * + * @param value The value to convert + * @return The result right padded with 0 + */ + public static String toHex(final int value) + { + return toHex(value, 8); + } + + + private static String toHex(final long value, final int digits) + { + StringBuffer result = new StringBuffer(digits); + for (int j = 0; j < digits; j++) + { + result.append( _hexcodes[ (int) ((value >> _shifts[ j + (8 - digits) ]) & 15)]); + } + return result.toString(); + } } diff --git a/src/records/definitions/area_record.xml b/src/records/definitions/area_record.xml new file mode 100644 index 000000000..efb323926 --- /dev/null +++ b/src/records/definitions/area_record.xml @@ -0,0 +1,11 @@ + + The area record is used to define a area chart. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + diff --git a/src/records/definitions/bar_record.xml b/src/records/definitions/bar_record.xml new file mode 100644 index 000000000..41aff58ab --- /dev/null +++ b/src/records/definitions/bar_record.xml @@ -0,0 +1,14 @@ + + The bar record is used to define a bar chart. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + + + + diff --git a/src/records/definitions/dat_record.xml b/src/records/definitions/dat_record.xml new file mode 100644 index 000000000..2497eca85 --- /dev/null +++ b/src/records/definitions/dat_record.xml @@ -0,0 +1,12 @@ + + The dat record is used to store options for the chart. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + + diff --git a/src/records/definitions/dataformat_record.xml b/src/records/definitions/dataformat_record.xml new file mode 100644 index 000000000..a56f6102b --- /dev/null +++ b/src/records/definitions/dataformat_record.xml @@ -0,0 +1,12 @@ + + The data format record is used to index into a series. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + + diff --git a/src/records/definitions/font_example.xml b/src/records/definitions/font_example.xml new file mode 100644 index 000000000..f077ac973 --- /dev/null +++ b/src/records/definitions/font_example.xml @@ -0,0 +1,32 @@ + + Describes a font record. In Excel a font belongs in the font table. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/records/definitions/frame_record.xml b/src/records/definitions/frame_record.xml new file mode 100644 index 000000000..b7a63c41e --- /dev/null +++ b/src/records/definitions/frame_record.xml @@ -0,0 +1,14 @@ + + The frame record indicates whether there is a border around the displayed text of a chart. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + + + + diff --git a/src/records/definitions/legend_record.xml b/src/records/definitions/legend_record.xml new file mode 100644 index 000000000..732f6f35d --- /dev/null +++ b/src/records/definitions/legend_record.xml @@ -0,0 +1,31 @@ + + The legend record specifies the location of legend on a chart and it's overall size. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + ? + + + + + + + + + + + + + + + + + + + + diff --git a/src/records/definitions/series_record.xml b/src/records/definitions/series_record.xml new file mode 100644 index 000000000..eccf92c3e --- /dev/null +++ b/src/records/definitions/series_record.xml @@ -0,0 +1,27 @@ + + The series record describes the overall data for a series. + Glen Stampoultzis (gstamp at iprimus dot com dot au) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/records/styles/record.xsl b/src/records/styles/record.xsl new file mode 100644 index 000000000..4a5964d63 --- /dev/null +++ b/src/records/styles/record.xsl @@ -0,0 +1,263 @@ + + + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + + +package ; + + + +import org.apache.poi.util.BitField; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.StringUtil; +import org.apache.poi.util.HexDump; + +/** + * + * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/records/definitions. + + */ +public class Record + extends Record +{ + public final static short sid = ; + private ; + + + + public Record() + { + + + = ; + + } + + /** + * Constructs a record and sets its fields appropriately. + * + * @param id id must be or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + */ + + public Record(short id, short size, byte [] data) + { + super(id, size, data); + } + + /** + * Constructs a record and sets its fields appropriately. + * + * @param id id must be or an exception + * will be throw upon validation + * @param size size the size of the data area of the record + * @param data data of the record (should not contain sid/len) + * @param offset of the record's data + */ + + public Record(short id, short size, byte [] data, int offset) + { + super(id, size, data, offset); + } + + /** + * Checks the sid matches the expected side for this record + * + * @param id the expected sid. + */ + protected void validateSid(short id) + { + if (id != sid) + { + throw new RecordFormatException("Not a record"); + } + } + + protected void fillFields(byte [] data, short size, int offset) + { + + + = ; + + } + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + + buffer.append("[]\n"); + + buffer.append("[/]\n"); + return buffer.toString(); + } + + public int serialize(int offset, byte[] data) + { + LittleEndian.putShort(data, 0 + offset, sid); + LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); + + + + + + return getRecordSize(); + } + + /** + * Size of record (exluding 4 byte header) + */ + public int getRecordSize() + { + + return 4 + + + +; + } + + public short getSid() + { + return this.sid; + } + + + + +} // END OF CLASS + + + + + + + + + + /** + * Sets the field value. + * + */ + public void set(boolean value) + { + = .setBoolean(, value); + } + + /** + * + * @return the field value. + */ + public boolean is() + { + return .isSet(); + } + + + + private BitField = new BitField(); + + public final static = ; + + + + + * + + + /** + * Get the field for the record. + * + * @return One of + */ + public get() + { + return ; + } + + /** + * Set the field for the record. + * + * @param + * One of + */ + public void set( ) + { + this. = ; + } + + + + buffer.append(" . = ") + .append("0x") + .append(HexDump.toHex(()get())) + .append(" (").append(get()).append(" )\n"); + + + + buffer.append(" . = ").append(is()).append('\n'); + + + + * @author + + + diff --git a/src/records/styles/record_document.xsl b/src/records/styles/record_document.xsl new file mode 100644 index 000000000..a54bea8be --- /dev/null +++ b/src/records/styles/record_document.xsl @@ -0,0 +1,51 @@ + + + + +
+ <xsl:value-of select="@name"/> Record Documentation +
+ + + +

+

+
+ + + + + + + + + + +
NameSizeOffsetDescriptionDefault Value
+
+ +
+ + Copyright (c) @year@ The Poi Project All rights reserved. + $Revision$ $Date$ + +
+ +
+
+ + + + + + + + + + + +
\ No newline at end of file diff --git a/src/records/styles/record_test.xsl b/src/records/styles/record_test.xsl new file mode 100644 index 000000000..3b4c94b38 --- /dev/null +++ b/src/records/styles/record_test.xsl @@ -0,0 +1,130 @@ + + + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + + +package ; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the Record + * class works correctly. Test data taken directly from a real + * Excel file. + * + + */ +public class TestRecord + extends TestCase +{ + byte[] data = new byte[] { + // PASTE DATA HERE + }; + + public TestRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + Record record = new Record((short), (short)data.length, data); + assertEquals( XXX, record.get()); + + + + assertEquals( XXX, record.getRecordSize() ); + + record.validateSid((short)); + } + + public void testStore() + { + Record record = new Record(); + record.set( XXXX ); + + + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} + + + + * @author + + + + assertEquals( XXX, record.is() ); + + + + + record.set( XXX ); + + + + \ No newline at end of file diff --git a/src/scratchpad/src/org/apache/poi/generator/FieldIterator.java b/src/scratchpad/src/org/apache/poi/generator/FieldIterator.java new file mode 100644 index 000000000..f419f5af6 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/generator/FieldIterator.java @@ -0,0 +1,145 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.generator; + +/** + * For iterating through our fields. Todo: Change this to javascript in the style sheet. + * + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class FieldIterator +{ + int offset; + + public FieldIterator() + { + } + + public void init(org.apache.xalan.extensions.XSLProcessorContext context, + org.apache.xalan.templates.ElemExtensionCall extElem) + { + offset = 0; + } + + public String fillDecoder(String size, String type) + { + String javaType = RecordUtil.getType(size, type, 0); + + String result = ""; + if (javaType.equals("short")) + result = "LittleEndian.getShort(data, " + offset + " + offset)"; + else if (javaType.equals("int")) + result = "LittleEndian.getInt(data, " + offset + " + offset)"; + else if (javaType.equals("byte")) + result = "data[ " + offset + " + offset ]"; + else if (javaType.equals("ExcelString")) + result = "ExcelStringUtil.decodeExcelString(data, " + offset + " + offset)"; + + try + { + offset += Integer.parseInt(size); + } + catch (NumberFormatException ignore) + { + } + return result; + } + + //position(),@name,@size,@type + public String serialiseEncoder( int fieldNumber, String fieldName, String size, String type) + { + String javaType = RecordUtil.getType(size, type, 0); + String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0); + + String result = ""; + if (javaType.equals("short")) + result = "LittleEndian.putShort(data, " + (offset+4) + " + offset, " + javaFieldName + ");"; + else if (javaType.equals("int")) + result = "LittleEndian.putInt(data, " + (offset+4) + " + offset, " + javaFieldName + ");"; + else if (javaType.equals("byte")) + result = "data[ " + (offset+4) + " + offset ] = " + javaFieldName + ";"; + else if (javaType.equals("ExcelString")) + result = "StringUtil.putUncompressedUnicode(getFontName(), data, 20 + offset);"; + + try + { + offset += Integer.parseInt(size); + } + catch (NumberFormatException ignore) + { + } + return result; + + } + + public String calcSize( int fieldNumber, String fieldName, String size, String type) + { + String result = fieldNumber == 1 ? "" : " + "; + if ("var".equals(size)) + { + String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0); + return result + javaFieldName + ".sizeInBytes()"; + } + else + { + return result + size; + } + } + +} + + + diff --git a/src/scratchpad/src/org/apache/poi/generator/RecordUtil.java b/src/scratchpad/src/org/apache/poi/generator/RecordUtil.java new file mode 100644 index 000000000..64660e5a9 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/generator/RecordUtil.java @@ -0,0 +1,173 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.poi.generator; + + +/** + * Helper functions for the record transformations. TODO: Change this to + * javascript in the style sheet. + * + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class RecordUtil +{ + public static String getFieldName(int position, String name, int padTo) + { + StringBuffer fieldName = new StringBuffer("field_" + position + "_"); + toIdentifier(name, fieldName); + pad(fieldName, padTo); + + return fieldName.toString(); + } + + private static StringBuffer pad(StringBuffer fieldName, int padTo) + { + for (int i = fieldName.length(); i < padTo; i++) + fieldName.append(' '); + return fieldName; + } + + public static String getFieldName(String name, int padTo) + { + StringBuffer fieldName = new StringBuffer(); + toIdentifier(name, fieldName); + pad(fieldName, padTo); + + return fieldName.toString(); + } + + public static String getFieldName1stCap(String name, int padTo) + { + StringBuffer fieldName = new StringBuffer(); + toIdentifier(name, fieldName); + fieldName.setCharAt(0, Character.toUpperCase(fieldName.charAt(0))); + pad(fieldName, padTo); + + return fieldName.toString(); + } + + private static void toIdentifier(String name, StringBuffer fieldName) + { + for (int i = 0; i < name.length(); i++) + { + if (name.charAt(i) == ' ') + fieldName.append(Character.toUpperCase(name.charAt(++i))); + else + fieldName.append(name.charAt(i)); + } + } + + private static void toConstIdentifier(String name, StringBuffer fieldName) + { + for (int i = 0; i < name.length(); i++) + { + if (name.charAt(i) == ' ') + fieldName.append('_'); + else + fieldName.append(Character.toUpperCase(name.charAt(i))); + } + } + + public static String getType(String size, String type, int padTo) + { + boolean numeric = type.equals("bits") || type.equals("int"); + if (numeric && "1".equals(size)) + return pad(new StringBuffer("byte"), padTo).toString(); + else if (numeric && "2".equals(size)) + return pad(new StringBuffer("short"), padTo).toString(); + else if (numeric && "4".equals(size)) + return pad(new StringBuffer("int"), padTo).toString(); + else if (type.equals("string")) + return pad(new StringBuffer("ExcelString"), padTo).toString(); + + return ""; + } + + public static String getType1stCap(String size, String type, int padTo) + { + StringBuffer result; + boolean numeric = type.equals("bits") || type.equals("int"); + if (numeric && "1".equals(size)) + result = pad(new StringBuffer("byte"), padTo); + else if (numeric && "2".equals(size)) + result = pad(new StringBuffer("short"), padTo); + else if (type.equals("string")) + result = pad(new StringBuffer("ExcelString"), padTo); + else + return ""; + + result.setCharAt(0, Character.toUpperCase(result.charAt(0))); + + return result.toString(); + } + + public static String getMask(int bit) + { + int mask = (int)Math.pow(2, bit); + + return "0x" + Integer.toHexString(mask); + } + + public static String getConstName(String parentName, String constName, int padTo) + { + StringBuffer fieldName = new StringBuffer(); + toConstIdentifier(parentName, fieldName); + fieldName.append('_'); + toConstIdentifier(constName, fieldName); + pad(fieldName, padTo); + return fieldName.toString(); + } + +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestAreaRecord.java b/src/testcases/org/apache/poi/hssf/record/TestAreaRecord.java new file mode 100644 index 000000000..decbedc77 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestAreaRecord.java @@ -0,0 +1,111 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the AreaRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + * + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestAreaRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0x02,(byte)0x00 // format flags + }; + + public TestAreaRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + AreaRecord record = new AreaRecord((short)0x101A, (short)data.length, data); + assertEquals( 2, record.getFormatFlags()); + assertEquals( false, record.isStacked() ); + assertEquals( true, record.isDisplayAsPercentage() ); + assertEquals( false, record.isShadow() ); + + + assertEquals( 6, record.getRecordSize() ); + + record.validateSid((short)0x101A); + } + + public void testStore() + { + AreaRecord record = new AreaRecord(); + record.setStacked( false ); + record.setDisplayAsPercentage( true ); + record.setShadow( false ); + + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestBarRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBarRecord.java new file mode 100644 index 000000000..9d9b78cc7 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestBarRecord.java @@ -0,0 +1,119 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the BarRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestBarRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0x00,(byte)0x00, // bar space + (byte)0x96,(byte)0x00, // category space + (byte)0x00,(byte)0x00 // format flags + }; + + public TestBarRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + BarRecord record = new BarRecord((short)0x1017, (short)data.length, data); + assertEquals( 0, record.getBarSpace()); + assertEquals( 0x96, record.getCategorySpace()); + assertEquals( 0, record.getFormatFlags()); + assertEquals( false, record.isHorizontal() ); + assertEquals( false, record.isStacked() ); + assertEquals( false, record.isDisplayAsPercentage() ); + assertEquals( false, record.isShadow() ); + + + assertEquals( 10, record.getRecordSize() ); + + record.validateSid((short)0x1017); + } + + public void testStore() + { + BarRecord record = new BarRecord(); + record.setBarSpace( (short)0 ); + record.setCategorySpace( (short)0x96 ); + record.setHorizontal( false ); + record.setStacked( false ); + record.setDisplayAsPercentage( false ); + record.setShadow( false ); + + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestDatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDatRecord.java new file mode 100644 index 000000000..3c6bdc7ba --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestDatRecord.java @@ -0,0 +1,113 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the DatRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestDatRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0x0D,(byte)0x00 // options + }; + + public TestDatRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + DatRecord record = new DatRecord((short)0x1063, (short)data.length, data); + assertEquals( 0xD, record.getOptions()); + assertEquals( true, record.isHorizontalBorder() ); + assertEquals( false, record.isVerticalBorder() ); + assertEquals( true, record.isBorder() ); + assertEquals( true, record.isShowSeriesKey() ); + + + assertEquals( 6, record.getRecordSize() ); + + record.validateSid((short)0x1063); + } + + public void testStore() + { + DatRecord record = new DatRecord(); + record.setHorizontalBorder( true ); + record.setVerticalBorder( false ); + record.setBorder( true ); + record.setShowSeriesKey( true ); + + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestDataFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDataFormatRecord.java new file mode 100644 index 000000000..36f07c14f --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestDataFormatRecord.java @@ -0,0 +1,117 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the DataFormatRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestDataFormatRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0xFF,(byte)0xFF, // point number + (byte)0x00,(byte)0x00, // series index + (byte)0x00,(byte)0x00, // series number + (byte)0x00,(byte)0x00 // format flags + }; + + public TestDataFormatRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + DataFormatRecord record = new DataFormatRecord((short)0x1006, (short)data.length, data); + assertEquals( (short)0xFFFF, record.getPointNumber()); + assertEquals( 0, record.getSeriesIndex()); + assertEquals( 0, record.getSeriesNumber()); + assertEquals( 0, record.getFormatFlags()); + assertEquals( false, record.isUseExcel4Colors() ); + + + assertEquals( 12, record.getRecordSize() ); + + record.validateSid((short)0x1006); + } + + public void testStore() + { + DataFormatRecord record = new DataFormatRecord(); + record.setPointNumber( (short)0xFFFF ); + record.setSeriesIndex( (short)0 ); + record.setSeriesNumber( (short)0 ); + record.setFormatFlags( (short)0 ); + record.setUseExcel4Colors( false ); + + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestFrameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFrameRecord.java new file mode 100644 index 000000000..ffa47d41b --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestFrameRecord.java @@ -0,0 +1,113 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the FrameRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestFrameRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0x00,(byte)0x00, // border type + (byte)0x02,(byte)0x00 // options + }; + + public TestFrameRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + FrameRecord record = new FrameRecord((short)0x1032, (short)data.length, data); + assertEquals( FrameRecord.BORDER_TYPE_REGULAR, record.getBorderType()); + assertEquals( 2, record.getOptions()); + assertEquals( false, record.isAutoSize() ); + assertEquals( true, record.isAutoPosition() ); + + + assertEquals( 8, record.getRecordSize() ); + + record.validateSid((short)0x1032); + } + + public void testStore() + { + FrameRecord record = new FrameRecord(); + record.setBorderType( FrameRecord.BORDER_TYPE_REGULAR ); + record.setOptions( (short)2 ); + record.setAutoSize( false ); + record.setAutoPosition( true ); + + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestLegendRecord.java b/src/testcases/org/apache/poi/hssf/record/TestLegendRecord.java new file mode 100644 index 000000000..ca719e048 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestLegendRecord.java @@ -0,0 +1,129 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.poi.hssf.record; + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the LegendRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestLegendRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0xB2,(byte)0x0D,(byte)0x00,(byte)0x00, //field_1_xPosition + (byte)0x39,(byte)0x06,(byte)0x00,(byte)0x00, //field_2_yPosition + (byte)0xD9,(byte)0x01,(byte)0x00,(byte)0x00, //field_3_xSize + (byte)0x34,(byte)0x02,(byte)0x00,(byte)0x00, //field_4_ySize + (byte)0x03, //field_5_type + (byte)0x01, //field_6_spacing + (byte)0x1F,(byte)0x00 //field_7_options + }; + + public TestLegendRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + LegendRecord legendRecord = new LegendRecord((short)0x1015, (short)data.length, data); + assertEquals(3506, legendRecord.getXPosition()); + assertEquals(1593, legendRecord.getYPosition()); + assertEquals(473, legendRecord.getXSize()); + assertEquals(564, legendRecord.getYSize()); + assertEquals(LegendRecord.TYPE_RIGHT, legendRecord.getType()); + assertEquals(LegendRecord.SPACING_MEDIUM, legendRecord.getSpacing()); + assertEquals(31, legendRecord.getOptions()); + assertEquals(true, legendRecord.isAutoPosition()); + assertEquals(true, legendRecord.isAutoSeries()); + assertEquals(true, legendRecord.isAutoPosX()); + assertEquals(true, legendRecord.isAutoPosY()); + assertEquals(true, legendRecord.isVert()); + assertEquals(false, legendRecord.isContainsDataTable()); + + assertEquals(24, legendRecord.getRecordSize()); + + legendRecord.validateSid((short)0x1015); + } + + public void testStore() + { + LegendRecord legendRecord = new LegendRecord(); + legendRecord.setXPosition(3506); + legendRecord.setYPosition(1593); + legendRecord.setXSize(473); + legendRecord.setYSize(564); + legendRecord.setType(LegendRecord.TYPE_RIGHT); + legendRecord.setSpacing(LegendRecord.SPACING_MEDIUM); + legendRecord.setAutoPosition(true); + legendRecord.setAutoSeries(true); + legendRecord.setAutoPosX(true); + legendRecord.setAutoPosY(true); + legendRecord.setVert(true); + legendRecord.setContainsDataTable(false); + + byte [] recordBytes = legendRecord.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java new file mode 100644 index 000000000..2d1881f4e --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java @@ -0,0 +1,119 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the SeriesRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + * @author Glen Stampoultzis (gstamp at iprimus dot com dot au) + */ +public class TestSeriesRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0x01,(byte)0x00, // category data type + (byte)0x01,(byte)0x00, // values data type + (byte)0x1B,(byte)0x00, // num categories + (byte)0x1B,(byte)0x00, // num values + (byte)0x01,(byte)0x00, // bubble series type + (byte)0x00,(byte)0x00 // num bubble values + }; + + public TestSeriesRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + + SeriesRecord record = new SeriesRecord((short)0x1003, (short)data.length, data); + assertEquals( SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC, record.getCategoryDataType()); + assertEquals( SeriesRecord.VALUES_DATA_TYPE_NUMERIC, record.getValuesDataType()); + assertEquals( 27, record.getNumCategories()); + assertEquals( 27, record.getNumValues()); + assertEquals( SeriesRecord.BUBBLE_SERIES_TYPE_NUMERIC, record.getBubbleSeriesType()); + assertEquals( 0, record.getNumBubbleValues()); + + + assertEquals( 16, record.getRecordSize() ); + + record.validateSid((short)0x1003); + } + + public void testStore() + { + SeriesRecord record = new SeriesRecord(); + record.setCategoryDataType( SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC ); + record.setValuesDataType( SeriesRecord.VALUES_DATA_TYPE_NUMERIC ); + record.setNumCategories( (short)27 ); + record.setNumValues( (short)27 ); + record.setBubbleSeriesType( SeriesRecord.BUBBLE_SERIES_TYPE_NUMERIC ); + record.setNumBubbleValues( (short)0 ); + + byte [] recordBytes = record.serialize(); + assertEquals(recordBytes.length - 4, data.length); + for (int i = 0; i < data.length; i++) + assertEquals("At offset " + i, data[i], recordBytes[i+4]); + } +} diff --git a/src/testcases/org/apache/poi/util/TestHexDump.java b/src/testcases/org/apache/poi/util/TestHexDump.java index 841d66873..117028381 100644 --- a/src/testcases/org/apache/poi/util/TestHexDump.java +++ b/src/testcases/org/apache/poi/util/TestHexDump.java @@ -316,6 +316,17 @@ public class TestHexDump } } + public void testToHex() + throws Exception + { + assertEquals( "000A", HexDump.toHex((short)0xA)); + assertEquals( "0A", HexDump.toHex((byte)0xA)); + assertEquals( "0000000A", HexDump.toHex((int)0xA)); + + assertEquals( "FFFF", HexDump.toHex((short)0xFFFF)); + + } + private char toAscii(final int c) { char rval = '.';