Record definition changes
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353503 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4401c16af6
commit
72e833700e
52
src/records/definitions/common_object_data_record.xml
Normal file
52
src/records/definitions/common_object_data_record.xml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<record id="0x15" name="CommonObjectData" excel-record-id="ftCmo"
|
||||||
|
package="org.apache.poi.hssf.record">
|
||||||
|
<suffix>SubRecord</suffix>
|
||||||
|
<extends>SubRecord</extends>
|
||||||
|
<description>The common object data record is used to store all common preferences for an excel object.</description>
|
||||||
|
<author>Glen Stampoultzis (glens at apache.org)</author>
|
||||||
|
<fields>
|
||||||
|
<field type="int" size="2" name="object type">
|
||||||
|
<const value="0" name="group" description="group"/>
|
||||||
|
<const value="1" name="line" description="line"/>
|
||||||
|
<const value="2" name="rectangle" description="rectangle"/>
|
||||||
|
<const value="3" name="oval" description="oval"/>
|
||||||
|
<const value="4" name="arc" description="arc"/>
|
||||||
|
<const value="5" name="chart" description="chart"/>
|
||||||
|
<const value="6" name="text" description="text"/>
|
||||||
|
<const value="7" name="button" description="button"/>
|
||||||
|
<const value="8" name="picture" description="picture"/>
|
||||||
|
<const value="9" name="polygon" description="polygon"/>
|
||||||
|
<const value="10" name="reserved1" description="reserved1"/>
|
||||||
|
<const value="11" name="checkbox" description="checkbox"/>
|
||||||
|
<const value="12" name="option button" description="option button"/>
|
||||||
|
<const value="13" name="edit box" description="edit box"/>
|
||||||
|
<const value="14" name="label" description="label"/>
|
||||||
|
<const value="15" name="dialog box" description="dialog box"/>
|
||||||
|
<const value="16" name="spinner" description="spinner"/>
|
||||||
|
<const value="17" name="scroll bar" description="scroll bar"/>
|
||||||
|
<const value="18" name="list box" description="list box"/>
|
||||||
|
<const value="19" name="group box" description="group box"/>
|
||||||
|
<const value="20" name="combo box" description="combo box"/>
|
||||||
|
<const value="21" name="reserved2" description="reserved2"/>
|
||||||
|
<const value="22" name="reserved3" description="reserved3"/>
|
||||||
|
<const value="23" name="reserved4" description="reserved4"/>
|
||||||
|
<const value="24" name="reserved5" description="reserved5"/>
|
||||||
|
<const value="25" name="comment" description="comment"/>
|
||||||
|
<const value="26" name="reserved6" description="reserved6"/>
|
||||||
|
<const value="27" name="reserved7" description="reserved7"/>
|
||||||
|
<const value="28" name="reserved8" description="reserved8"/>
|
||||||
|
<const value="29" name="reserved9" description="reserved9"/>
|
||||||
|
<const value="30" name="microsoft office drawing" description="microsoft office drawing"/>
|
||||||
|
</field>
|
||||||
|
<field type="int" size="2" name="object id"/>
|
||||||
|
<field type="int" size="2" name="option">
|
||||||
|
<bit number="0" name="locked" description="true if object is locked when sheet has been protected"/>
|
||||||
|
<bit number="4" name="printable" description="object appears when printed"/>
|
||||||
|
<bit number="13" name="autofill" description="whether object uses an automatic fill style"/>
|
||||||
|
<bit number="14" name="autoline" description="whether object uses an automatic line style"/>
|
||||||
|
</field>
|
||||||
|
<field type="int" size="4" name="reserved1" description="Should always be 0"/>
|
||||||
|
<field type="int" size="4" name="reserved2" description="Should always be 0"/>
|
||||||
|
<field type="int" size="4" name="reserved3" description="Should always be 0"/>
|
||||||
|
</fields>
|
||||||
|
</record>
|
9
src/records/definitions/ftend_record.xml
Normal file
9
src/records/definitions/ftend_record.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<record id="0x00" name="End" excel-record-id="ftEnd"
|
||||||
|
package="org.apache.poi.hssf.record">
|
||||||
|
<suffix>SubRecord</suffix>
|
||||||
|
<extends>SubRecord</extends>
|
||||||
|
<description>The end data record is used to denote the end of the subrecords.</description>
|
||||||
|
<author>Glen Stampoultzis (glens at apache.org)</author>
|
||||||
|
<fields>
|
||||||
|
</fields>
|
||||||
|
</record>
|
41
src/records/definitions/textobject_record.xml
Normal file
41
src/records/definitions/textobject_record.xml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<record id="0x1B6" name="TextObjectBase" excel-record-id="TXO"
|
||||||
|
package="org.apache.poi.hssf.record">
|
||||||
|
<suffix>Record</suffix>
|
||||||
|
<extends>Record</extends>
|
||||||
|
<description>The TXO record is used to define the properties of a text box. It is followed
|
||||||
|
by two continue records unless there is no actual text. The first continue record contains
|
||||||
|
the text data and the next continue record contains the formatting runs.</description>
|
||||||
|
<author>Glen Stampoultzis (glens at apache.org)</author>
|
||||||
|
<fields>
|
||||||
|
<field type="int" size="2" name="options" description="option flags">
|
||||||
|
<bit number="0" name="reserved1" description="reserved field"/>
|
||||||
|
<bit mask="0x000E" name="Horizontal text alignment">
|
||||||
|
<const name="left aligned" value="1"/>
|
||||||
|
<const name="centered" value="2"/>
|
||||||
|
<const name="right aligned" value="3"/>
|
||||||
|
<const name="justified" value="4"/>
|
||||||
|
</bit>
|
||||||
|
<bit mask="0x0070" name="Vertical text alignment">
|
||||||
|
<const name="top" value="1"/>
|
||||||
|
<const name="center" value="2"/>
|
||||||
|
<const name="bottom" value="3"/>
|
||||||
|
<const name="justify" value="4"/>
|
||||||
|
</bit>
|
||||||
|
<bit mask="0x0180" name="reserved2"/>
|
||||||
|
<bit number="9" name="text locked" description="Text has been locked"/>
|
||||||
|
<bit mask="0xFC00" name="reserved3"/>
|
||||||
|
</field>
|
||||||
|
<field type="int" size="2" name="text orientation" description="specifies whether the text is rotated">
|
||||||
|
<const name="none" value="0"/>
|
||||||
|
<const name="top_to_bottom" value="1"/>
|
||||||
|
<const name="rot_right" value="2"/>
|
||||||
|
<const name="rot_left" value="3"/>
|
||||||
|
</field>
|
||||||
|
<field type="int" size="2" name="reserved4" description="reserved field"/>
|
||||||
|
<field type="int" size="2" name="reserved5" description="reserved field"/>
|
||||||
|
<field type="int" size="2" name="reserved6" description="reserved field"/>
|
||||||
|
<field type="int" size="2" name="text length" description="the left of the text string"/>
|
||||||
|
<field type="int" size="2" name="formatting run length" description="the length of the formatting runs."/>
|
||||||
|
<field type="int" size="4" name="reserved7" description="reserved field"/>
|
||||||
|
</fields>
|
||||||
|
</record>
|
326
src/records/styles/subrecord.xsl
Normal file
326
src/records/styles/subrecord.xsl
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
<xsl:stylesheet version="1.0"
|
||||||
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
xmlns:recutil="org.apache.poi.generator.RecordUtil"
|
||||||
|
xmlns:field="org.apache.poi.generator.FieldIterator"
|
||||||
|
xmlns:java="java" >
|
||||||
|
|
||||||
|
<xsl:template match="record">
|
||||||
|
/* ====================================================================
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
<xsl:if test="@package">
|
||||||
|
package <xsl:value-of select="@package"/>;
|
||||||
|
</xsl:if>
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.poi.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xsl:value-of select="/record/description"/>
|
||||||
|
* NOTE: This source is automatically generated please do not modify this file. Either subclass or
|
||||||
|
* remove the record in src/records/definitions.
|
||||||
|
<xsl:apply-templates select="author"/>
|
||||||
|
*/
|
||||||
|
public class <xsl:value-of select="@name"/>SubRecord
|
||||||
|
extends SubRecord
|
||||||
|
{
|
||||||
|
public final static short sid = <xsl:value-of select="@id"/>;
|
||||||
|
<xsl:for-each select="//fields/field"> private <xsl:value-of select="recutil:getType(@size,@type,10)"/><xsl:text> </xsl:text><xsl:value-of select="recutil:getFieldName(position(),@name,0)"/><xsl:value-of select="recutil:initializeText(@size,@type)"/>;
|
||||||
|
<xsl:apply-templates select="./bit|./const|./bit/const"/>
|
||||||
|
</xsl:for-each>
|
||||||
|
|
||||||
|
public <xsl:value-of select="@name"/>SubRecord()
|
||||||
|
{
|
||||||
|
<xsl:for-each select="//fields/field"><xsl:if test="@default">
|
||||||
|
<xsl:text> </xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName(position(),@name,0)"/> = <xsl:value-of select="@default"/>;
|
||||||
|
</xsl:if></xsl:for-each>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a <xsl:value-of select="@name"/> record and sets its fields appropriately.
|
||||||
|
*
|
||||||
|
* @param id id must be <xsl:value-of select="@id"/> 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 <xsl:value-of select="@name"/>SubRecord(short id, short size, byte [] data)
|
||||||
|
{
|
||||||
|
super(id, size, data);
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:if test="@default">
|
||||||
|
<xsl:text> </xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName(position(),@name,0)"/> =
|
||||||
|
<xsl:value-of select="@default"/>;
|
||||||
|
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:for-each>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a <xsl:value-of select="@name"/> record and sets its fields appropriately.
|
||||||
|
*
|
||||||
|
* @param id id must be <xsl:value-of select="@id"/> 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 <xsl:value-of select="@name"/>SubRecord(short id, short size, byte [] data, int offset)
|
||||||
|
{
|
||||||
|
super(id, size, data, offset);
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:if test="@default">
|
||||||
|
<xsl:text> </xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName(position(),@name,0)"/> =
|
||||||
|
<xsl:value-of select="@default"/>;
|
||||||
|
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:for-each>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 <xsl:value-of select="@name"/> record");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillFields(byte [] data, short size, int offset)
|
||||||
|
{
|
||||||
|
|
||||||
|
<xsl:text> int pos = 0;
|
||||||
|
</xsl:text>
|
||||||
|
|
||||||
|
<xsl:variable name="fieldIterator" select="field:new()"/>
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:text> </xsl:text><xsl:value-of select="field:fillDecoder2($fieldIterator,position(),@name,@size,@type)"/>;
|
||||||
|
</xsl:for-each>
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
buffer.append("[<xsl:value-of select="recutil:getRecordId(@name,@excel-record-id)"/>]\n");
|
||||||
|
<xsl:apply-templates select="//field" mode="tostring"/>
|
||||||
|
buffer.append("[/<xsl:value-of select="recutil:getRecordId(@name,@excel-record-id)"/>]\n");
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int serialize(int offset, byte[] data)
|
||||||
|
{
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
LittleEndian.putShort(data, 0 + offset, sid);
|
||||||
|
LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
|
||||||
|
<xsl:variable name="fieldIterator" select="field:new()"/>
|
||||||
|
<xsl:for-each select="//fields/field"><xsl:text>
|
||||||
|
</xsl:text><xsl:value-of select="field:serialiseEncoder($fieldIterator,position(),@name,@size,@type)"/>
|
||||||
|
</xsl:for-each>
|
||||||
|
|
||||||
|
return getRecordSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Size of record (exluding 4 byte header)
|
||||||
|
*/
|
||||||
|
public int getRecordSize()
|
||||||
|
{
|
||||||
|
<xsl:variable name="fieldIterator" select="field:new()"/>
|
||||||
|
<xsl:text> return 4 </xsl:text>
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:value-of select="field:calcSize($fieldIterator,position(),@name,@size,@type)"/>
|
||||||
|
</xsl:for-each>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getSid()
|
||||||
|
{
|
||||||
|
return this.sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object clone() {
|
||||||
|
<xsl:value-of select="@name"/>SubRecord rec = new <xsl:value-of select="@name"/>SubRecord();
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:text>
|
||||||
|
</xsl:text><xsl:value-of select="recutil:clone(@name,@type,position())"/><xsl:text>;</xsl:text>
|
||||||
|
</xsl:for-each>
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
<xsl:apply-templates select="//field" mode="getset"/>
|
||||||
|
<xsl:apply-templates select="//field" mode="bits"/>
|
||||||
|
|
||||||
|
} // END OF CLASS
|
||||||
|
|
||||||
|
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match = "field" mode="bits">
|
||||||
|
<xsl:variable name="fieldNum" select="position()"/>
|
||||||
|
<xsl:for-each select="bit">
|
||||||
|
<xsl:if test="not (@mask)">
|
||||||
|
/**
|
||||||
|
* Sets the <xsl:value-of select="@name"/> field value.
|
||||||
|
* <xsl:value-of select="@description"/>
|
||||||
|
*/
|
||||||
|
public void set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>(boolean value)
|
||||||
|
{
|
||||||
|
<xsl:value-of select="recutil:getFieldName($fieldNum,../@name,0)"/> = <xsl:value-of select="recutil:getFieldName(@name,0)"/>.set<xsl:value-of select="recutil:getType1stCap(../@size,../@type,0)"/>Boolean(<xsl:value-of select="recutil:getFieldName($fieldNum,../@name,0)"/>, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xsl:value-of select="@description"/>
|
||||||
|
* @return the <xsl:value-of select="@name"/> field value.
|
||||||
|
*/
|
||||||
|
public boolean is<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>()
|
||||||
|
{
|
||||||
|
return <xsl:value-of select="recutil:getFieldName(@name,0)"/>.isSet(<xsl:value-of select="recutil:getFieldName($fieldNum,../@name,0)"/>);
|
||||||
|
}
|
||||||
|
</xsl:if>
|
||||||
|
<xsl:if test="@mask">
|
||||||
|
/**
|
||||||
|
* Sets the <xsl:value-of select="@name"/> field value.
|
||||||
|
* <xsl:value-of select="@description"/>
|
||||||
|
*/
|
||||||
|
public void set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>(short value)
|
||||||
|
{
|
||||||
|
<xsl:value-of select="recutil:getFieldName($fieldNum,../@name,0)"/> = <xsl:value-of select="recutil:getFieldName(@name,0)"/>.set<xsl:value-of select="recutil:getType1stCap(../@size,../@type,0)"/>Value(<xsl:value-of select="recutil:getFieldName($fieldNum,../@name,0)"/>, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xsl:value-of select="@description"/>
|
||||||
|
* @return the <xsl:value-of select="@name"/> field value.
|
||||||
|
*/
|
||||||
|
public short get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>()
|
||||||
|
{
|
||||||
|
return <xsl:value-of select="recutil:getFieldName(@name,0)"/>.getShortValue(<xsl:value-of select="recutil:getFieldName($fieldNum,../@name,0)"/>);
|
||||||
|
}
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:for-each>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match = "bit" ><xsl:if test="not (@mask)"> private BitField <xsl:value-of select="recutil:getFieldName(@name,42)"/> = new BitField(<xsl:value-of select="recutil:getMask(@number)"/>);
|
||||||
|
</xsl:if><xsl:if test="@mask"> private BitField <xsl:value-of select="recutil:getFieldName(@name,42)"/> = new BitField(<xsl:value-of select="@mask"/>);
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:template>
|
||||||
|
<xsl:template match = "const"> public final static <xsl:value-of select="recutil:getType(../@size,../@type,10)"/><xsl:text> </xsl:text><xsl:value-of select="recutil:getConstName(../@name,@name,30)"/> = <xsl:value-of select="@value"/>;
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match = "const" mode="listconsts">
|
||||||
|
<xsl:text>
|
||||||
|
* </xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getConstName(../@name,@name,0)"/></xsl:template>
|
||||||
|
<xsl:template match="field" mode="getset">
|
||||||
|
/**
|
||||||
|
* Get the <xsl:value-of select="@name"/> field for the <xsl:value-of select="../../@name"/> record.<xsl:if test="./const">
|
||||||
|
*
|
||||||
|
* @return One of <xsl:apply-templates select="./const" mode="listconsts"/></xsl:if>
|
||||||
|
*/
|
||||||
|
public <xsl:value-of select="recutil:getType(@size,@type,0)"/> get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>()
|
||||||
|
{
|
||||||
|
return <xsl:value-of select="recutil:getFieldName(position(),@name,0)"/>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the <xsl:value-of select="@name"/> field for the <xsl:value-of select="../../@name"/> record.<xsl:if test="./const">
|
||||||
|
*
|
||||||
|
* @param <xsl:value-of select="recutil:getFieldName(position(),@name,0)"/>
|
||||||
|
* One of <xsl:apply-templates select="./const" mode="listconsts"/></xsl:if>
|
||||||
|
*/
|
||||||
|
public void set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>(<xsl:value-of select="recutil:getType(@size,@type,0)"/><xsl:text> </xsl:text><xsl:value-of select="recutil:getFieldName(position(),@name,0)"/>)
|
||||||
|
{
|
||||||
|
this.<xsl:value-of select="recutil:getFieldName(position(),@name,0)"/> = <xsl:value-of select="recutil:getFieldName(position(),@name,0)"/>;
|
||||||
|
}
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="field" mode="tostring">
|
||||||
|
<xsl:value-of select="recutil:getToString(@name,@type,@size)"/>
|
||||||
|
<xsl:text>
|
||||||
|
buffer.append(System.getProperty("line.separator")); </xsl:text>
|
||||||
|
<xsl:apply-templates select="bit" mode="bittostring"/>
|
||||||
|
<xsl:text> </xsl:text>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="bit" mode="bittostring">
|
||||||
|
<xsl:if test="not (@mask)">
|
||||||
|
<xsl:text> buffer.append(" .</xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName(@name,20)"/>
|
||||||
|
<xsl:text> = ").append(is</xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>
|
||||||
|
<xsl:text>()).append('\n'); </xsl:text>
|
||||||
|
</xsl:if>
|
||||||
|
<xsl:if test="@mask">
|
||||||
|
<xsl:text> buffer.append(" .</xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName(@name,20)"/>
|
||||||
|
<xsl:text> = ").append(get</xsl:text>
|
||||||
|
<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>
|
||||||
|
<xsl:text>()).append('\n'); </xsl:text>
|
||||||
|
</xsl:if>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="author">
|
||||||
|
* @author <xsl:value-of select="."/>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
155
src/records/styles/subrecord_test.xsl
Normal file
155
src/records/styles/subrecord_test.xsl
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
<xsl:stylesheet version="1.0"
|
||||||
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
|
xmlns:recutil="org.apache.poi.generator.RecordUtil"
|
||||||
|
xmlns:field="org.apache.poi.generator.FieldIterator"
|
||||||
|
xmlns:java="java" >
|
||||||
|
|
||||||
|
<xsl:template match="record">
|
||||||
|
/* ====================================================================
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
<xsl:if test="@package">
|
||||||
|
package <xsl:value-of select="@package"/>;
|
||||||
|
</xsl:if>
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the serialization and deserialization of the <xsl:value-of select="@name"/>SubRecord
|
||||||
|
* class works correctly. Test data taken directly from a real
|
||||||
|
* Excel file.
|
||||||
|
*
|
||||||
|
<xsl:apply-templates select="author"/>
|
||||||
|
*/
|
||||||
|
public class Test<xsl:value-of select="@name"/>SubRecord
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
byte[] data = new byte[] {
|
||||||
|
<xsl:value-of select="recutil:getByteArrayString(testdata)"/>
|
||||||
|
};
|
||||||
|
|
||||||
|
public Test<xsl:value-of select="@name"/>SubRecord(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLoad()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
<xsl:value-of select="@name"/>SubRecord record = new <xsl:value-of select="@name"/>SubRecord((short)<xsl:value-of select="@id"/>, (short)data.length, data);
|
||||||
|
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:choose><xsl:when test="@type='string' or @type='hbstring'">
|
||||||
|
assertEquals( "<xsl:value-of select="./testresult/@value"/>", record.get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>());
|
||||||
|
</xsl:when><xsl:when test="@size='1'">
|
||||||
|
assertEquals( (byte)<xsl:value-of select="./testresult/@value"/>, record.get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>());
|
||||||
|
</xsl:when><xsl:when test="@size='2'">
|
||||||
|
assertEquals( (short)<xsl:value-of select="./testresult/@value"/>, record.get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>());
|
||||||
|
</xsl:when><xsl:when test="@size='4'">
|
||||||
|
assertEquals( (int)<xsl:value-of select="./testresult/@value"/>, record.get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>());
|
||||||
|
</xsl:when><xsl:otherwise>
|
||||||
|
assertEquals( (double)<xsl:value-of select="./testresult/@value"/>, record.get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>());
|
||||||
|
</xsl:otherwise></xsl:choose>
|
||||||
|
<xsl:apply-templates select="./bit" mode="get"/>
|
||||||
|
</xsl:for-each>
|
||||||
|
|
||||||
|
assertEquals( <xsl:value-of select="./testsize"/>, record.getRecordSize() );
|
||||||
|
|
||||||
|
record.validateSid((short)<xsl:value-of select="@id"/>);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStore()
|
||||||
|
{
|
||||||
|
<xsl:value-of select="@name"/>SubRecord record = new <xsl:value-of select="@name"/>SubRecord();
|
||||||
|
|
||||||
|
|
||||||
|
<xsl:for-each select="//fields/field">
|
||||||
|
<xsl:choose><xsl:when test="@type='string' or @type='hbstring'">
|
||||||
|
record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( "<xsl:value-of select="./testresult/@value"/>" );
|
||||||
|
</xsl:when><xsl:when test="@size='1'">
|
||||||
|
record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( (byte)<xsl:value-of select="./testresult/@value"/> );
|
||||||
|
</xsl:when><xsl:when test="@size='2'">
|
||||||
|
record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( (short)<xsl:value-of select="./testresult/@value"/> );
|
||||||
|
</xsl:when><xsl:when test="@size='4'">
|
||||||
|
record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( (int)<xsl:value-of select="./testresult/@value"/> );
|
||||||
|
</xsl:when><xsl:otherwise>
|
||||||
|
record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( (double)<xsl:value-of select="./testresult/@value"/> );
|
||||||
|
</xsl:otherwise></xsl:choose>
|
||||||
|
|
||||||
|
<xsl:apply-templates select="./bit" mode="set"/>
|
||||||
|
</xsl:for-each>
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="author">
|
||||||
|
* @author <xsl:value-of select="."/>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="bit" mode="get">
|
||||||
|
<xsl:text> </xsl:text>assertEquals( <xsl:value-of select="./testresult/@value"/>, record.is<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>() );<xsl:text>
|
||||||
|
</xsl:text>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="bit" mode="set">
|
||||||
|
<xsl:text> </xsl:text>record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( <xsl:value-of select="./testresult/@value"/> );<xsl:text>
|
||||||
|
</xsl:text>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
Loading…
Reference in New Issue
Block a user