]> source.dussan.org Git - poi.git/commitdiff
Bug 52583 - Conversion to html : Problem with combobox
authorSergey Vladimirov <sergey@apache.org>
Tue, 6 Nov 2012 16:26:43 +0000 (16:26 +0000)
committerSergey Vladimirov <sergey@apache.org>
Tue, 6 Nov 2012 16:26:43 +0000 (16:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1406208 13f79535-47bb-0310-9956-ffa450edef68

18 files changed:
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hwpf/model/FFDataBase.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java
src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hwpf/model/SttbUtils.java
src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hwpf/model/types/FFDataBaseAbstractType.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java
src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
src/types/definitions/FFData_type.xml [new file with mode: 0644]
src/types/styles/hdftype.xsl
test-data/document/Bug52583.doc [new file with mode: 0644]

index ad3b0f62b96ac0ae3d4f53c84790a05d7953df13..f297c506126afaa7e6d7c7b57e0c4bb5fd7bd831 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="add">52583 - add support for drop-down lists in doc to html convertion</action>
           <action dev="poi-developers" type="add">52863 - add workaround for files with broken CHP SPRMs</action>
           <action dev="poi-developers" type="fix">53182 - Reading combined character styling and direct formatting of a character run</action>
           <action dev="poi-developers" type="fix">52311 - Conversion to html : Problem in titles number </action>
index 64a1900abe52da517fcf7f57bbfacb9a3b98568e..95da85020063344474047b7df160dec75cc763c9 100644 (file)
@@ -167,6 +167,7 @@ public abstract class AbstractWordConverter
         }
         structures.add( structure );
     }
+
     private final Set<Bookmark> bookmarkStack = new LinkedHashSet<Bookmark>();
 
     private FontReplacer fontReplacer = new DefaultFontReplacer();
@@ -778,6 +779,12 @@ public abstract class AbstractWordConverter
             CharacterRun characterRun, OfficeDrawing officeDrawing,
             String path, Element block );
 
+    protected void processDropDownList( Element block,
+            CharacterRun characterRun, String[] values, int defaultIndex )
+    {
+        outputCharacters( block, characterRun, values[defaultIndex] );
+    }
+
     protected abstract void processEndnoteAutonumbered(
             HWPFDocument wordDocument, int noteIndex, Element block,
             Range endnoteTextRange );
@@ -835,6 +842,22 @@ public abstract class AbstractWordConverter
 
             break;
         }
+        case 83: // drop down
+        {
+            Range fieldContent = field.firstSubrange( parentRange );
+            CharacterRun cr = fieldContent.getCharacterRun( fieldContent
+                    .numCharacterRuns() - 1 );
+            String[] values = cr.getDropDownListValues();
+            Integer defIndex = cr.getDropDownListDefaultItemIndex();
+
+            if ( values != null )
+            {
+                processDropDownList( currentBlock, cr, values,
+                        defIndex == null ? -1 : defIndex.intValue() );
+                return;
+            }
+            break;
+        }
         case 88: // hyperlink
         {
             final Range firstSubrange = field.firstSubrange( parentRange );
@@ -1010,12 +1033,6 @@ public abstract class AbstractWordConverter
             return false;
         }
     }
-    
-    protected void processSymbol( HWPFDocument doc, CharacterRun characterRun,
-            Element block )
-    {
-        
-    }
 
     @SuppressWarnings( "unused" )
     protected boolean processOle2( HWPFDocument wordDocument, Element block,
@@ -1109,6 +1126,12 @@ public abstract class AbstractWordConverter
         processSection( wordDocument, section, 0 );
     }
 
+    protected void processSymbol( HWPFDocument doc, CharacterRun characterRun,
+            Element block )
+    {
+
+    }
+
     protected abstract void processTable( HWPFDocumentCore wordDocument,
             Element flow, Table table );
 
index b405b2cb6ac0bdbb6c4f7beeb83dc7e7f26a357e..67f6ea1cd80245bb33c4b2b811298da5f8fdf6ca 100644 (file)
@@ -161,11 +161,28 @@ public class HtmlDocumentFacade
         return document.createElement( "li" );
     }
 
+    public Element createOption( String value, boolean selected )
+    {
+        Element result = document.createElement( "option" );
+        result.appendChild( createText( value ) );
+        if ( selected )
+        {
+            result.setAttribute( "selected", "selected" );
+        }
+        return result;
+    }
+
     public Element createParagraph()
     {
         return document.createElement( "p" );
     }
 
+    public Element createSelect()
+    {
+        Element result = document.createElement( "select" );
+        return result;
+    }
+
     public Element createTable()
     {
         return document.createElement( "table" );
index 3092625e8c6b7164bfc4c4d4ba6dc11d95da90ce..d5314c9e7be9bdaa3450b9da4f255a7d937c0a7e 100644 (file)
@@ -82,6 +82,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
     private static final POILogger logger = POILogFactory
             .getLogger( WordToHtmlConverter.class );
 
+    
     private static String getSectionStyle( Section section )
     {
         float leftMargin = section.getMarginLeft() / TWIPS_PER_INCH;
@@ -280,6 +281,19 @@ public class WordToHtmlConverter extends AbstractWordConverter
         afterProcess();
     }
 
+    @Override
+    protected void processDropDownList( Element block,
+            CharacterRun characterRun, String[] values, int defaultIndex )
+    {
+        Element select = htmlDocumentFacade.createSelect();
+        for ( int i = 0; i < values.length; i++ )
+        {
+            select.appendChild( htmlDocumentFacade.createOption( values[i],
+                    defaultIndex == i ) );
+        }
+        block.appendChild( select );
+    }
+
     @Override
     protected void processDrawnObject( HWPFDocument doc,
             CharacterRun characterRun, OfficeDrawing officeDrawing,
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java
new file mode 100644 (file)
index 0000000..7ea4b79
--- /dev/null
@@ -0,0 +1,214 @@
+package org.apache.poi.hwpf.model;\r
+\r
+import org.apache.poi.util.Internal;\r
+import org.apache.poi.util.LittleEndian;\r
+\r
+/**\r
+ * The FFData structure specifies form field data for a text box, check box, or\r
+ * drop-down list box.\r
+ * <p>\r
+ * Class and fields descriptions are quoted from [MS-DOC] -- v20121003 Word\r
+ * (.doc) Binary File Format; Copyright (c) 2012 Microsoft Corporation; Release:\r
+ * October 8, 2012\r
+ * <p>\r
+ * This class is internal. It content or properties may change without notice\r
+ * due to changes in our knowledge of internal Microsoft Word binary structures.\r
+ * \r
+ * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word (.doc)\r
+ *         Binary File Format; Copyright (c) 2012 Microsoft Corporation;\r
+ *         Release: October 8, 2012\r
+ */\r
+@Internal\r
+public class FFData\r
+{\r
+    private FFDataBase _base;\r
+\r
+    /**\r
+     * An optional STTB that specifies the entries in the dropdown list box.\r
+     * This MUST exist if and only if bits.iType is iTypeDrop (2). The entries\r
+     * are Unicode strings and do not have extra data. This MUST NOT exceed 25\r
+     * elements.\r
+     */\r
+    private Sttb _hsttbDropList;\r
+\r
+    /**\r
+     * An optional unsigned integer that specifies the default state of the\r
+     * checkbox or dropdown list box. This value MUST exist if and only if\r
+     * bits.iType is iTypeChck (1) or iTypeDrop (2). If bits.iType is iTypeChck\r
+     * (1), wDef MUST be 0 or 1 and specify the default state of the checkbox as\r
+     * unchecked or checked, respectively. If bits.iType is iTypeDrop (2), wDef\r
+     * MUST be less than the number of items in the dropdown list box and\r
+     * specify the default item selected (zero-based index).\r
+     */\r
+    private Integer _wDef;\r
+\r
+    private Xstz _xstzEntryMcr;\r
+\r
+    private Xstz _xstzExitMcr;\r
+\r
+    private Xstz _xstzHelpText;\r
+\r
+    /**\r
+     * An Xstz that specifies the name of this form field. xstzName.cch MUST NOT\r
+     * exceed 20.\r
+     */\r
+    private Xstz _xstzName;\r
+\r
+    private Xstz _xstzStatText;\r
+\r
+    /**\r
+     * An optional Xstz that specifies the default text of this textbox. This\r
+     * structure MUST exist if and only if bits.iType is iTypeTxt (0).\r
+     * xstzTextDef.cch MUST NOT exceed 255. If bits.iTypeTxt is either\r
+     * iTypeTxtCurDate (3) or iTypeTxtCurTime (4), xstzTextDef MUST be an empty\r
+     * string. If bits.iTypeTxt is iTypeTxtCalc (5), xstzTextDef specifies an\r
+     * expression to calculate.\r
+     */\r
+    private Xstz _xstzTextDef;\r
+\r
+    private Xstz _xstzTextFormat;\r
+\r
+    public FFData( byte[] std, int offset )\r
+    {\r
+        fillFields( std, offset );\r
+    }\r
+\r
+    public void fillFields( final byte[] std, final int startOffset )\r
+    {\r
+        int offset = startOffset;\r
+\r
+        this._base = new FFDataBase( std, offset );\r
+        offset += FFDataBase.getSize();\r
+\r
+        this._xstzName = new Xstz( std, offset );\r
+        offset += this._xstzName.getSize();\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_TEXT )\r
+        {\r
+            _xstzTextDef = new Xstz( std, offset );\r
+            offset += this._xstzTextDef.getSize();\r
+        }\r
+        else\r
+        {\r
+            this._xstzTextDef = null;\r
+        }\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_CHCK\r
+                || _base.getIType() == FFDataBase.ITYPE_DROP )\r
+        {\r
+            this._wDef = Integer\r
+                    .valueOf( LittleEndian.getUShort( std, offset ) );\r
+            offset += LittleEndian.SHORT_SIZE;\r
+        }\r
+        else\r
+        {\r
+            this._wDef = null;\r
+        }\r
+\r
+        _xstzTextFormat = new Xstz( std, offset );\r
+        offset += this._xstzTextFormat.getSize();\r
+\r
+        _xstzHelpText = new Xstz( std, offset );\r
+        offset += this._xstzHelpText.getSize();\r
+\r
+        _xstzStatText = new Xstz( std, offset );\r
+        offset += this._xstzStatText.getSize();\r
+\r
+        _xstzEntryMcr = new Xstz( std, offset );\r
+        offset += this._xstzEntryMcr.getSize();\r
+\r
+        _xstzExitMcr = new Xstz( std, offset );\r
+        offset += this._xstzExitMcr.getSize();\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_DROP )\r
+        {\r
+            _hsttbDropList = new Sttb( std, offset );\r
+            offset += _hsttbDropList.getSize();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * specify the default item selected (zero-based index).\r
+     */\r
+    public int getDefaultDropDownItemIndex()\r
+    {\r
+        return _wDef.intValue();\r
+    }\r
+\r
+    public String[] getDropList()\r
+    {\r
+        return _hsttbDropList.getData();\r
+    }\r
+\r
+    public int getSize()\r
+    {\r
+        int size = FFDataBase.getSize();\r
+\r
+        size += _xstzName.getSize();\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_TEXT )\r
+        {\r
+            size += _xstzTextDef.getSize();\r
+        }\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_CHCK\r
+                || _base.getIType() == FFDataBase.ITYPE_DROP )\r
+        {\r
+            size += LittleEndian.SHORT_SIZE;\r
+        }\r
+\r
+        size += _xstzTextFormat.getSize();\r
+        size += _xstzHelpText.getSize();\r
+        size += _xstzStatText.getSize();\r
+        size += _xstzEntryMcr.getSize();\r
+        size += _xstzExitMcr.getSize();\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_DROP )\r
+        {\r
+            size += _hsttbDropList.getSize();\r
+        }\r
+\r
+        return size;\r
+    }\r
+\r
+    public String getTextDef()\r
+    {\r
+        return _xstzTextDef.getAsJavaString();\r
+    }\r
+\r
+    public byte[] serialize()\r
+    {\r
+        byte[] buffer = new byte[getSize()];\r
+        int offset = 0;\r
+\r
+        _base.serialize( buffer, offset );\r
+        offset += FFDataBase.getSize();\r
+\r
+        offset += _xstzName.serialize( buffer, offset );\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_TEXT )\r
+        {\r
+            offset += _xstzTextDef.serialize( buffer, offset );\r
+        }\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_CHCK\r
+                || _base.getIType() == FFDataBase.ITYPE_DROP )\r
+        {\r
+            LittleEndian.putUShort( buffer, offset, _wDef );\r
+            offset += LittleEndian.SHORT_SIZE;\r
+        }\r
+\r
+        offset += _xstzTextFormat.serialize( buffer, offset );\r
+        offset += _xstzHelpText.serialize( buffer, offset );\r
+        offset += _xstzStatText.serialize( buffer, offset );\r
+        offset += _xstzEntryMcr.serialize( buffer, offset );\r
+        offset += _xstzExitMcr.serialize( buffer, offset );\r
+\r
+        if ( _base.getIType() == FFDataBase.ITYPE_DROP )\r
+        {\r
+            offset += _hsttbDropList.serialize( buffer, offset );\r
+        }\r
+\r
+        return buffer;\r
+    }\r
+}\r
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FFDataBase.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FFDataBase.java
new file mode 100644 (file)
index 0000000..999dca5
--- /dev/null
@@ -0,0 +1,33 @@
+package org.apache.poi.hwpf.model;\r
+\r
+import org.apache.poi.hwpf.model.types.FFDataBaseAbstractType;\r
+import org.apache.poi.util.Internal;\r
+\r
+/**\r
+ * The FFData structure specifies form field data for a text box, check box, or\r
+ * drop-down list box.\r
+ * <p>\r
+ * Class and fields descriptions are quoted from [MS-DOC] -- v20121003 Word\r
+ * (.doc) Binary File Format; Copyright (c) 2012 Microsoft Corporation; Release:\r
+ * October 8, 2012\r
+ * <p>\r
+ * This class is internal. It content or properties may change without notice\r
+ * due to changes in our knowledge of internal Microsoft Word binary structures.\r
+ * \r
+ * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word (.doc)\r
+ *         Binary File Format; Copyright (c) 2012 Microsoft Corporation;\r
+ *         Release: October 8, 2012\r
+ */\r
+@Internal\r
+public class FFDataBase extends FFDataBaseAbstractType\r
+{\r
+    public FFDataBase()\r
+    {\r
+        super();\r
+    }\r
+\r
+    public FFDataBase( byte[] std, int offset )\r
+    {\r
+        fillFields( std, offset );\r
+    }\r
+}\r
index 9d61d8abbc8e88ed926642376766fd97985516dc..ff55082afd71d8feb58343e7c61739aa56214767 100644 (file)
@@ -90,7 +90,8 @@ public final class FIBFieldHandler
     public static final int PLCFATNBKL = 43;
     // 506 == 0x01FA; 510 == 0x01FE
     public static final int PMS = 44;
-  public static final int FORMFLDSTTBS = 45;
+    // 514 == 0x0202; 518 == 0x0206
+    public static final int FORMFLDSTTBS = 45;
   public static final int PLCFENDREF = 46;
   public static final int PLCFENDTXT = 47;
   public static final int PLCFFLDEDN = 48;
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java
new file mode 100644 (file)
index 0000000..ea98db5
--- /dev/null
@@ -0,0 +1,59 @@
+package org.apache.poi.hwpf.model;\r
+\r
+import org.apache.poi.util.ArrayUtil;\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.POILogFactory;\r
+import org.apache.poi.util.POILogger;\r
+\r
+public class NilPICFAndBinData\r
+{\r
+\r
+    private static final POILogger log = POILogFactory\r
+            .getLogger( NilPICFAndBinData.class );\r
+\r
+    private byte[] _binData;\r
+\r
+    public NilPICFAndBinData( byte[] data, int offset )\r
+    {\r
+        fillFields( data, offset );\r
+    }\r
+\r
+    public void fillFields( byte[] data, int offset )\r
+    {\r
+        int lcb = LittleEndian.getInt( data, offset );\r
+        int cbHeader = LittleEndian.getUShort( data, offset\r
+                + LittleEndian.INT_SIZE );\r
+\r
+        if ( cbHeader != 0x44 )\r
+        {\r
+            log.log( POILogger.WARN, "NilPICFAndBinData at offset ", offset,\r
+                    " cbHeader 0x" + Integer.toHexString( cbHeader )\r
+                            + " != 0x44" );\r
+        }\r
+\r
+        // skip the 62 ignored bytes\r
+        int binaryLength = lcb - cbHeader;\r
+        this._binData = ArrayUtil.copyOfRange( data, offset + cbHeader,\r
+                offset + cbHeader + binaryLength );\r
+    }\r
+\r
+    public byte[] getBinData()\r
+    {\r
+        return _binData;\r
+    }\r
+\r
+    public byte[] serialize()\r
+    {\r
+        byte[] bs = new byte[_binData.length + 0x44];\r
+        LittleEndian.putInt( bs, 0, _binData.length + 0x44 );\r
+        System.arraycopy( _binData, 0, bs, 0x44, _binData.length );\r
+        return bs;\r
+    }\r
+\r
+    public int serialize( byte[] data, int offset )\r
+    {\r
+        LittleEndian.putInt( data, offset, _binData.length + 0x44 );\r
+        System.arraycopy( _binData, 0, data, offset + 0x44, _binData.length );\r
+        return 0x44 + _binData.length;\r
+    }\r
+}\r
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java
new file mode 100644 (file)
index 0000000..fabd1e2
--- /dev/null
@@ -0,0 +1,232 @@
+package org.apache.poi.hwpf.model;\r
+\r
+import org.apache.poi.util.ArrayUtil;\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.StringUtil;\r
+\r
+/**\r
+ * The STTB is a string table that is made up of a header that is followed by an\r
+ * array of elements. The cData value specifies the number of elements that are\r
+ * contained in the array.\r
+ * <p>\r
+ * Class and fields descriptions are quoted from [MS-DOC] -- v20121003 Word\r
+ * (.doc) Binary File Format; Copyright (c) 2012 Microsoft Corporation; Release:\r
+ * October 8, 2012\r
+ * <p>\r
+ * This class is internal. It content or properties may change without notice\r
+ * due to changes in our knowledge of internal Microsoft Word binary structures.\r
+ * \r
+ * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word (.doc)\r
+ *         Binary File Format; Copyright (c) 2012 Microsoft Corporation;\r
+ *         Release: October 8, 2012\r
+ */\r
+public class Sttb\r
+{\r
+\r
+    private int _cbExtra;\r
+\r
+    private final int _cDataLength;\r
+\r
+    private String[] _data;\r
+\r
+    private byte[][] _extraData;\r
+\r
+    private final boolean _fExtend = true;\r
+\r
+    public Sttb( byte[] buffer, int startOffset )\r
+    {\r
+        this( 2, buffer, startOffset );\r
+    }\r
+\r
+    public Sttb( int cDataLength, byte[] buffer, int startOffset )\r
+    {\r
+        this._cDataLength = cDataLength;\r
+        fillFields( buffer, startOffset );\r
+    }\r
+\r
+    public Sttb( int cDataLength, String[] data )\r
+    {\r
+        this._cDataLength = cDataLength;\r
+\r
+        this._data = ArrayUtil.copyOf( data, new String[data.length] );\r
+\r
+        this._cbExtra = 0;\r
+        this._extraData = null;\r
+    }\r
+\r
+    public void fillFields( byte[] buffer, int startOffset )\r
+    {\r
+        short ffff = LittleEndian.getShort( buffer, startOffset );\r
+        int offset = startOffset + LittleEndian.SHORT_SIZE;\r
+\r
+        if ( ffff != (short) 0xffff )\r
+        {\r
+            // Non-extended character Pascal strings\r
+            throw new UnsupportedOperationException(\r
+                    "Non-extended character Pascal strings are not supported right now. "\r
+                            + "Please, contact POI developers for update." );\r
+        }\r
+        // strings are extended character strings\r
+\r
+        int cData = _cDataLength == 2 ? LittleEndian.getUShort( buffer, offset )\r
+                : LittleEndian.getInt( buffer, offset );\r
+        offset += _cDataLength;\r
+\r
+        this._cbExtra = LittleEndian.getUShort( buffer, offset );\r
+        offset += 2;\r
+\r
+        _data = new String[cData];\r
+        _extraData = new byte[cData][];\r
+\r
+        for ( int i = 0; i < cData; i++ )\r
+        {\r
+            int cchData = LittleEndian.getShort( buffer, offset );\r
+            offset += 2;\r
+\r
+            if ( cchData < 0 )\r
+                continue;\r
+\r
+            _data[i] = StringUtil.getFromUnicodeLE( buffer, offset, cchData );\r
+            offset += cchData * 2;\r
+\r
+            _extraData[i] = LittleEndian\r
+                    .getByteArray( buffer, offset, _cbExtra );\r
+            offset += _cbExtra;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * The definition of each STTB specifies the meaning of this field. If this\r
+     * STTB uses extended characters, the size of this field is 2*cchData bytes\r
+     * and it is a Unicode string unless otherwise specified by the STTB\r
+     * definition. If this STTB does not use extended characters, then the size\r
+     * of this field is cchData bytes and it is an ANSI string, unless otherwise\r
+     * specified by the STTB definition.\r
+     */\r
+    public String[] getData()\r
+    {\r
+        return _data;\r
+    }\r
+\r
+    public int getSize()\r
+    {\r
+        // ffff\r
+        int size = LittleEndian.SHORT_SIZE;\r
+\r
+        // cData\r
+        size += _cDataLength;\r
+\r
+        // cbExtra\r
+        size += LittleEndian.SHORT_SIZE;\r
+\r
+        if ( this._fExtend )\r
+        {\r
+            for ( String data : _data )\r
+            {\r
+                // cchData\r
+                size += LittleEndian.SHORT_SIZE;\r
+                // data\r
+                size += 2 * data.length();\r
+            }\r
+        }\r
+        else\r
+        {\r
+            for ( String data : _data )\r
+            {\r
+                // cchData\r
+                size += LittleEndian.BYTE_SIZE;\r
+                // data\r
+                size += 1 * data.length();\r
+            }\r
+        }\r
+\r
+        // extraData\r
+        if ( _extraData != null )\r
+        {\r
+            size += _cbExtra * _data.length;\r
+        }\r
+\r
+        return size;\r
+    }\r
+\r
+    public byte[] serialize()\r
+    {\r
+        final byte[] buffer = new byte[getSize()];\r
+\r
+        LittleEndian.putShort( buffer, 0, (short) 0xffff );\r
+\r
+        if ( _data == null || _data.length == 0 )\r
+        {\r
+            if ( _cDataLength == 4 )\r
+            {\r
+                LittleEndian.putInt( buffer, 2, 0 );\r
+                LittleEndian.putUShort( buffer, 6, _cbExtra );\r
+                return buffer;\r
+            }\r
+\r
+            LittleEndian.putUShort( buffer, 2, 0 );\r
+            LittleEndian.putUShort( buffer, 4, _cbExtra );\r
+            return buffer;\r
+        }\r
+\r
+        int offset;\r
+        if ( _cDataLength == 4 )\r
+        {\r
+            LittleEndian.putInt( buffer, 2, _data.length );\r
+            LittleEndian.putUShort( buffer, 6, _cbExtra );\r
+            offset = 2 + LittleEndian.INT_SIZE + LittleEndian.SHORT_SIZE;\r
+        }\r
+        else\r
+        {\r
+            LittleEndian.putUShort( buffer, 2, _data.length );\r
+            LittleEndian.putUShort( buffer, 4, _cbExtra );\r
+            offset = 2 + LittleEndian.SHORT_SIZE + LittleEndian.SHORT_SIZE;\r
+        }\r
+\r
+        for ( int i = 0; i < _data.length; i++ )\r
+        {\r
+            String entry = _data[i];\r
+            if ( entry == null )\r
+            {\r
+                // is it correct?\r
+                buffer[offset] = -1;\r
+                buffer[offset + 1] = 0;\r
+                offset += 2;\r
+                continue;\r
+            }\r
+\r
+            if ( _fExtend )\r
+            {\r
+                LittleEndian.putUShort( buffer, offset, (int) entry.length() );\r
+                offset += LittleEndian.SHORT_SIZE;\r
+\r
+                StringUtil.putUnicodeLE( entry, buffer, offset );\r
+                offset += 2 * entry.length();\r
+            }\r
+            else\r
+            {\r
+                throw new UnsupportedOperationException(\r
+                        "ANSI STTB is not supported yet" );\r
+            }\r
+\r
+            if ( _cbExtra != 0 )\r
+            {\r
+                if ( _extraData[i] != null && _extraData[i].length != 0 )\r
+                {\r
+                    System.arraycopy( _extraData[i], 0, buffer, offset,\r
+                            Math.min( _extraData[i].length, _cbExtra ) );\r
+                }\r
+                offset += _cbExtra;\r
+            }\r
+        }\r
+\r
+        return buffer;\r
+    }\r
+\r
+    public int serialize( byte[] buffer, int offset )\r
+    {\r
+        byte[] bs = serialize();\r
+        System.arraycopy( bs, 0, buffer, offset, bs.length );\r
+        return bs.length;\r
+    }\r
+}\r
index 1cc11e0cdaa347561d753ec5049d364a8e0b9cf4..fba473f9cf0a751dca643342ac37f92b616c031f 100644 (file)
@@ -20,8 +20,6 @@ import java.io.IOException;
 
 import org.apache.poi.hwpf.model.io.HWPFOutputStream;
 import org.apache.poi.util.Internal;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.StringUtil;
 
 /**
  * Utils class for storing and reading "STring TaBle stored in File"
@@ -32,180 +30,47 @@ import org.apache.poi.util.StringUtil;
 class SttbUtils
 {
 
-    static class Sttb
-    {
-        public int cbExtra;
-
-        public int cDataLength;
-
-        public String[] data;
-
-        public byte[][] extraData;
-    }
-
-    private static final int CBEXTRA_STTB_SAVED_BY = 0; // bytes
-
-    private static final int CBEXTRA_STTBF_BKMK = 0; // bytes
-
-    private static final int CBEXTRA_STTBF_R_MARK = 0; // bytes
-
     private static final int CDATA_SIZE_STTB_SAVED_BY = 2; // bytes
 
     private static final int CDATA_SIZE_STTBF_BKMK = 2; // bytes
 
     private static final int CDATA_SIZE_STTBF_R_MARK = 2; // bytes
 
-    static Sttb read( int cDataLength, byte[] buffer, int startOffset )
-    {
-        short ffff = LittleEndian.getShort( buffer, startOffset );
-        int offset = startOffset + 2;
-
-        if ( ffff != (short) 0xffff )
-        {
-            // Non-extended character Pascal strings
-            throw new UnsupportedOperationException(
-                    "Non-extended character Pascal strings are not supported right now. "
-                            + "Please, contact POI developers for update." );
-        }
-        // strings are extended character strings
-
-        int cData = cDataLength == 2 ? LittleEndian.getUShort( buffer, offset )
-                : LittleEndian.getInt( buffer, offset );
-        offset += cDataLength;
-
-        Sttb sttb = new Sttb();
-        sttb.cDataLength = cDataLength;
-        sttb.cbExtra = LittleEndian.getUShort( buffer, offset );
-        offset += 2;
-
-        sttb.data = new String[cData];
-        sttb.extraData = new byte[cData][];
-
-        for ( int i = 0; i < cData; i++ )
-        {
-            int cchData = LittleEndian.getShort( buffer, offset );
-            offset += 2;
-
-            if ( cchData < 0 )
-                continue;
-
-            sttb.data[i] = StringUtil
-                    .getFromUnicodeLE( buffer, offset, cchData );
-            offset += cchData * 2;
-
-            sttb.extraData[i] = LittleEndian.getByteArray( buffer, offset,
-                    sttb.cbExtra );
-            offset += sttb.cbExtra;
-        }
-
-        return sttb;
-    }
-
     static String[] readSttbfBkmk( byte[] buffer, int startOffset )
     {
-        return read( CDATA_SIZE_STTBF_BKMK, buffer, startOffset ).data;
+        return new Sttb( CDATA_SIZE_STTBF_BKMK, buffer, startOffset ).getData();
     }
 
     static String[] readSttbfRMark( byte[] buffer, int startOffset )
     {
-        return read( CDATA_SIZE_STTBF_R_MARK, buffer, startOffset ).data;
+        return new Sttb( CDATA_SIZE_STTBF_R_MARK, buffer, startOffset )
+                .getData();
     }
 
     static String[] readSttbSavedBy( byte[] buffer, int startOffset )
     {
-        return read( CDATA_SIZE_STTB_SAVED_BY, buffer, startOffset ).data;
-    }
-
-    static void write( Sttb sttb, HWPFOutputStream tableStream )
-            throws IOException
-    {
-        final int headerSize = sttb.cDataLength == 2 ? 6 : 8;
-
-        byte[] header = new byte[headerSize];
-        LittleEndian.putShort( header, 0, (short) 0xffff );
-
-        if ( sttb.data == null || sttb.data.length == 0 )
-        {
-            if ( sttb.cDataLength == 4 )
-            {
-                LittleEndian.putInt( header, 2, 0 );
-                LittleEndian.putUShort( header, 6, sttb.cbExtra );
-                tableStream.write( header );
-                return;
-            }
-
-            LittleEndian.putUShort( header, 2, 0 );
-            LittleEndian.putUShort( header, 4, sttb.cbExtra );
-            tableStream.write( header );
-            return;
-        }
-
-        if ( sttb.cDataLength == 4 )
-        {
-            LittleEndian.putInt( header, 2, sttb.data.length );
-            LittleEndian.putUShort( header, 6, sttb.cbExtra );
-            tableStream.write( header );
-        }
-        else
-        {
-            LittleEndian.putUShort( header, 2, sttb.data.length );
-            LittleEndian.putUShort( header, 4, sttb.cbExtra );
-            tableStream.write( header );
-        }
-
-        for ( int i = 0; i < sttb.data.length; i++ )
-        {
-            String entry = sttb.data[i];
-            if ( entry == null )
-            {
-                // is it correct?
-                tableStream.write( new byte[] { -1, 0 } );
-                continue;
-            }
-
-            byte[] buf = new byte[entry.length() * 2 + sttb.cbExtra + 2];
-
-            LittleEndian.putShort( buf, 0, (short) entry.length() );
-            StringUtil.putUnicodeLE( entry, buf, 2 );
-
-            if ( sttb.extraData != null && i < sttb.extraData.length
-                    && sttb.extraData[i] != null )
-                System.arraycopy( sttb.extraData[i], 0, buf,
-                        entry.length() * 2,
-                        Math.min( sttb.extraData[i].length, sttb.cbExtra ) );
-
-            tableStream.write( buf );
-        }
+        return new Sttb( CDATA_SIZE_STTB_SAVED_BY, buffer, startOffset )
+                .getData();
     }
 
     static void writeSttbfBkmk( String[] data, HWPFOutputStream tableStream )
             throws IOException
     {
-        Sttb sttb = new Sttb();
-        sttb.cDataLength = CDATA_SIZE_STTBF_BKMK;
-        sttb.data = data;
-        sttb.cbExtra = CBEXTRA_STTBF_BKMK;
-        write( sttb, tableStream );
+        tableStream.write( new Sttb( CDATA_SIZE_STTBF_BKMK, data ).serialize() );
     }
 
     static void writeSttbfRMark( String[] data, HWPFOutputStream tableStream )
             throws IOException
     {
-        Sttb sttb = new Sttb();
-        sttb.cDataLength = CDATA_SIZE_STTBF_R_MARK;
-        sttb.data = data;
-        sttb.cbExtra = CBEXTRA_STTBF_R_MARK;
-        write( sttb, tableStream );
+        tableStream.write( new Sttb( CDATA_SIZE_STTBF_R_MARK, data )
+                .serialize() );
     }
 
     static void writeSttbSavedBy( String[] data, HWPFOutputStream tableStream )
             throws IOException
     {
-        Sttb sttb = new Sttb();
-        sttb.cDataLength = CDATA_SIZE_STTB_SAVED_BY;
-        sttb.data = data;
-        sttb.cbExtra = CBEXTRA_STTB_SAVED_BY;
-        write( sttb, tableStream );
+        tableStream.write( new Sttb( CDATA_SIZE_STTB_SAVED_BY, data )
+                .serialize() );
     }
 
 }
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Xstz.java
new file mode 100644 (file)
index 0000000..fb351e9
--- /dev/null
@@ -0,0 +1,69 @@
+package org.apache.poi.hwpf.model;\r
+\r
+import org.apache.poi.util.Internal;\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.POILogFactory;\r
+import org.apache.poi.util.POILogger;\r
+\r
+@Internal\r
+public class Xstz\r
+{\r
+    private static final POILogger log = POILogFactory.getLogger( Xstz.class );\r
+\r
+    private final short _chTerm = 0;\r
+    private Xst _xst;\r
+\r
+    public Xstz()\r
+    {\r
+        _xst = new Xst();\r
+    }\r
+\r
+    public Xstz( byte[] data, int startOffset )\r
+    {\r
+        fillFields( data, startOffset );\r
+    }\r
+\r
+    public void fillFields( byte[] data, int startOffset )\r
+    {\r
+        int offset = startOffset;\r
+\r
+        _xst = new Xst( data, offset );\r
+        offset += _xst.getSize();\r
+\r
+        short term = LittleEndian.getShort( data, offset );\r
+        if ( term != 0 )\r
+        {\r
+            log.log( POILogger.WARN, "chTerm at the end of Xstz at offset ",\r
+                    offset, " is not 0" );\r
+        }\r
+    }\r
+\r
+    public String getAsJavaString()\r
+    {\r
+        return _xst.getAsJavaString();\r
+    }\r
+\r
+    public int getSize()\r
+    {\r
+        return _xst.getSize() + LittleEndian.SHORT_SIZE;\r
+    }\r
+\r
+    public int serialize( byte[] data, int startOffset )\r
+    {\r
+        int offset = startOffset;\r
+\r
+        _xst.serialize( data, offset );\r
+        offset += _xst.getSize();\r
+\r
+        LittleEndian.putUShort( data, offset, _chTerm );\r
+        offset += LittleEndian.SHORT_SIZE;\r
+\r
+        return offset - startOffset;\r
+    }\r
+\r
+    @Override\r
+    public String toString()\r
+    {\r
+        return "[Xstz]" + _xst.getAsJavaString() + "[/Xstz]";\r
+    }\r
+}\r
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FFDataBaseAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FFDataBaseAbstractType.java
new file mode 100644 (file)
index 0000000..f582018
--- /dev/null
@@ -0,0 +1,428 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hwpf.model.types;\r
+\r
+\r
+import org.apache.poi.util.BitField;\r
+import org.apache.poi.util.Internal;\r
+import org.apache.poi.util.LittleEndian;\r
+\r
+/**\r
+ * The FFData structure specifies form field data for a text\r
+        box, check box, or drop-down list box. <p>Class and fields\r
+        descriptions are quoted from [MS-DOC] -- v20121003 Word (.doc) Binary\r
+        File Format; Copyright (c) 2012 Microsoft Corporation; Release:\r
+        October 8, 2012\r
+    \r
+ * <p>\r
+ * NOTE: This source is automatically generated please do not modify this file.  Either subclass or\r
+ *       remove the record in src/types/definitions.\r
+ * <p>\r
+ * This class is internal. It content or properties may change without notice \r
+ * due to changes in our knowledge of internal Microsoft Word binary structures.\r
+\r
+ * @author Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word\r
+        (.doc) Binary File Format; Copyright (c) 2012 Microsoft Corporation;\r
+        Release: October 8, 2012\r
+    \r
+ */\r
+@Internal\r
+public abstract class FFDataBaseAbstractType\r
+{\r
+\r
+    protected long field_1_version;\r
+    protected short field_2_bits;\r
+    /**/private static final BitField iType = new BitField(0x0003);\r
+    /**   Specifies that the form field is a textbox. */\r
+    /*  */public final static byte ITYPE_TEXT = 0;\r
+    /**   Specifies that the form field is a checkbox. */\r
+    /*  */public final static byte ITYPE_CHCK = 1;\r
+    /**   Specifies that the form field is a dropdown list box. */\r
+    /*  */public final static byte ITYPE_DROP = 2;\r
+    /**/private static final BitField iRes = new BitField(0x007C);\r
+    /**/private static final BitField fOwnHelp = new BitField(0x0080);\r
+    /**/private static final BitField fOwnStat = new BitField(0x0100);\r
+    /**/private static final BitField fProt = new BitField(0x0200);\r
+    /**/private static final BitField iSize = new BitField(0x0400);\r
+    /**/private static final BitField iTypeTxt = new BitField(0x3800);\r
+    /**   Specifies that the textbox value is regular text. */\r
+    /*  */public final static byte ITYPETXT_REG = 0;\r
+    /**   Specifies that the textbox value is a number. */\r
+    /*  */public final static byte ITYPETXT_NUM = 0;\r
+    /**   Specifies that the textbox value is a date or time. */\r
+    /*  */public final static byte ITYPETXT_DATE = 0;\r
+    /**   Specifies that the textbox value is the current date. */\r
+    /*  */public final static byte ITYPETXT_CURDATE = 0;\r
+    /**   Specifies that the textbox value is the current time. */\r
+    /*  */public final static byte ITYPETXT_CURTIME = 0;\r
+    /**   Specifies that the textbox value is calculated from an expression. The expression is given by FFData.xstzTextDef. */\r
+    /*  */protected final static byte ITYPETXT_CALC = 0;\r
+    /**/private static final BitField fRecalc = new BitField(0x4000);\r
+    /**/private static final BitField fHasListBox = new BitField(0x8000);\r
+    protected int field_3_cch;\r
+    protected int field_4_hps;\r
+\r
+    protected FFDataBaseAbstractType()\r
+    {\r
+    }\r
+\r
+    protected void fillFields( byte[] data, int offset )\r
+    {\r
+        field_1_version                = LittleEndian.getUInt( data, 0x0 + offset );\r
+        field_2_bits                   = LittleEndian.getShort( data, 0x4 + offset );\r
+        field_3_cch                    = LittleEndian.getShort( data, 0x6 + offset );\r
+        field_4_hps                    = LittleEndian.getShort( data, 0x8 + offset );\r
+    }\r
+\r
+    public void serialize( byte[] data, int offset )\r
+    {\r
+        LittleEndian.putUInt( data, 0x0 + offset, field_1_version );\r
+        LittleEndian.putShort( data, 0x4 + offset, field_2_bits );\r
+        LittleEndian.putUShort( data, 0x6 + offset, field_3_cch );\r
+        LittleEndian.putUShort( data, 0x8 + offset, field_4_hps );\r
+    }\r
+\r
+    public byte[] serialize()\r
+    {\r
+        final byte[] result = new byte[ getSize() ];\r
+        serialize( result, 0 );\r
+        return result;\r
+    }\r
+\r
+    /**\r
+     * Size of record\r
+     */\r
+    public static int getSize()\r
+    {\r
+        return 0 + 4 + 2 + 2 + 2;\r
+    }\r
+\r
+    @Override\r
+    public boolean equals( Object obj )\r
+    {\r
+        if ( this == obj )\r
+            return true;\r
+        if ( obj == null )\r
+            return false;\r
+        if ( getClass() != obj.getClass() )\r
+            return false;\r
+        FFDataBaseAbstractType other = (FFDataBaseAbstractType) obj;\r
+        if ( field_1_version != other.field_1_version )\r
+            return false;\r
+        if ( field_2_bits != other.field_2_bits )\r
+            return false;\r
+        if ( field_3_cch != other.field_3_cch )\r
+            return false;\r
+        if ( field_4_hps != other.field_4_hps )\r
+            return false;\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode()\r
+    {\r
+        final int prime = 31;\r
+        int result = 1;\r
+        result = prime * result\r
+                 + (int) ( field_1_version ^ ( field_1_version >>> 32 ) );\r
+        result = prime * result + field_2_bits;\r
+        result = prime * result + field_3_cch;\r
+        result = prime * result + field_4_hps;\r
+        return result;\r
+    }\r
+\r
+    public String toString()\r
+    {\r
+        StringBuilder builder = new StringBuilder();\r
+\r
+        builder.append("[FFDataBase]\n");\r
+        builder.append( "    .version              = " );\r
+        builder.append(" ( ").append( field_1_version ).append( " )\n" );\r
+        builder.append( "    .bits                 = " );\r
+        builder.append(" ( ").append( field_2_bits ).append( " )\n" );\r
+        builder.append("         .iType                    = ").append(getIType()).append('\n');\r
+        builder.append("         .iRes                     = ").append(getIRes()).append('\n');\r
+        builder.append("         .fOwnHelp                 = ").append(isFOwnHelp()).append('\n');\r
+        builder.append("         .fOwnStat                 = ").append(isFOwnStat()).append('\n');\r
+        builder.append("         .fProt                    = ").append(isFProt()).append('\n');\r
+        builder.append("         .iSize                    = ").append(isISize()).append('\n');\r
+        builder.append("         .iTypeTxt                 = ").append(getITypeTxt()).append('\n');\r
+        builder.append("         .fRecalc                  = ").append(isFRecalc()).append('\n');\r
+        builder.append("         .fHasListBox              = ").append(isFHasListBox()).append('\n');\r
+        builder.append( "    .cch                  = " );\r
+        builder.append(" ( ").append( field_3_cch ).append( " )\n" );\r
+        builder.append( "    .hps                  = " );\r
+        builder.append(" ( ").append( field_4_hps ).append( " )\n" );\r
+\r
+        builder.append("[/FFDataBase]");\r
+        return builder.toString();\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer that MUST be 0xFFFFFFFF.\r
+     */\r
+    @Internal\r
+    public long getVersion()\r
+    {\r
+        return field_1_version;\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer that MUST be 0xFFFFFFFF.\r
+     */\r
+    @Internal\r
+    public void setVersion( long field_1_version )\r
+    {\r
+        this.field_1_version = field_1_version;\r
+    }\r
+\r
+    /**\r
+     * An FFDataBits that specifies the type and state of this form field.\r
+     */\r
+    @Internal\r
+    public short getBits()\r
+    {\r
+        return field_2_bits;\r
+    }\r
+\r
+    /**\r
+     * An FFDataBits that specifies the type and state of this form field.\r
+     */\r
+    @Internal\r
+    public void setBits( short field_2_bits )\r
+    {\r
+        this.field_2_bits = field_2_bits;\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer that specifies the maximum length, in characters, of the value of the textbox. This value MUST NOT exceed 32767. A value of 0 means there is no maximum length of the value of the textbox. If bits.iType is not iTypeText (0), this value MUST be 0..\r
+     */\r
+    @Internal\r
+    public int getCch()\r
+    {\r
+        return field_3_cch;\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer that specifies the maximum length, in characters, of the value of the textbox. This value MUST NOT exceed 32767. A value of 0 means there is no maximum length of the value of the textbox. If bits.iType is not iTypeText (0), this value MUST be 0..\r
+     */\r
+    @Internal\r
+    public void setCch( int field_3_cch )\r
+    {\r
+        this.field_3_cch = field_3_cch;\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer. If bits.iType is iTypeChck (1), hps specifies the size, in half-points, of the checkbox and MUST be between 2 and 3168, inclusive. If bits.iType is not iTypeChck (1), hps is undefined and MUST be ignored..\r
+     */\r
+    @Internal\r
+    public int getHps()\r
+    {\r
+        return field_4_hps;\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer. If bits.iType is iTypeChck (1), hps specifies the size, in half-points, of the checkbox and MUST be between 2 and 3168, inclusive. If bits.iType is not iTypeChck (1), hps is undefined and MUST be ignored..\r
+     */\r
+    @Internal\r
+    public void setHps( int field_4_hps )\r
+    {\r
+        this.field_4_hps = field_4_hps;\r
+    }\r
+\r
+    /**\r
+     * Sets the iType field value.\r
+     * An unsigned integer that specifies the type of the form field. \r
+     */\r
+    @Internal\r
+    public void setIType( byte value )\r
+    {\r
+        field_2_bits = (short)iType.setValue(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer that specifies the type of the form field. \r
+     * @return  the iType field value.\r
+     */\r
+    @Internal\r
+    public byte getIType()\r
+    {\r
+        return ( byte )iType.getValue(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the iRes field value.\r
+     * An unsigned integer. If iType is iTypeText (0), then iRes MUST be 0. If iType is iTypeChck (1), iRes specifies the state of the checkbox and MUST be 0 (unchecked), 1 (checked), or 25 (undefined). Undefined checkboxes are treated as unchecked. If iType is iTypeDrop (2), iRes specifies the current selected list box item. A value of 25 specifies the selection is undefined. Otherwise, iRes is a zero-based index into FFData.hsttbDropList.\r
+     */\r
+    @Internal\r
+    public void setIRes( byte value )\r
+    {\r
+        field_2_bits = (short)iRes.setValue(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer. If iType is iTypeText (0), then iRes MUST be 0. If iType is iTypeChck (1), iRes specifies the state of the checkbox and MUST be 0 (unchecked), 1 (checked), or 25 (undefined). Undefined checkboxes are treated as unchecked. If iType is iTypeDrop (2), iRes specifies the current selected list box item. A value of 25 specifies the selection is undefined. Otherwise, iRes is a zero-based index into FFData.hsttbDropList.\r
+     * @return  the iRes field value.\r
+     */\r
+    @Internal\r
+    public byte getIRes()\r
+    {\r
+        return ( byte )iRes.getValue(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the fOwnHelp field value.\r
+     * A bit that specifies whether the form field has custom help text in FFData.xstzHelpText. If fOwnHelp is 0, FFData.xstzHelpText contains an empty or auto-generated string.\r
+     */\r
+    @Internal\r
+    public void setFOwnHelp( boolean value )\r
+    {\r
+        field_2_bits = (short)fOwnHelp.setBoolean(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * A bit that specifies whether the form field has custom help text in FFData.xstzHelpText. If fOwnHelp is 0, FFData.xstzHelpText contains an empty or auto-generated string.\r
+     * @return  the fOwnHelp field value.\r
+     */\r
+    @Internal\r
+    public boolean isFOwnHelp()\r
+    {\r
+        return fOwnHelp.isSet(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the fOwnStat field value.\r
+     * A bit that specifies whether the form field has custom status bar text in FFData.xstzStatText. If fOwnStat is 0, FFData.xstzStatText contains an empty or auto-generated string.\r
+     */\r
+    @Internal\r
+    public void setFOwnStat( boolean value )\r
+    {\r
+        field_2_bits = (short)fOwnStat.setBoolean(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * A bit that specifies whether the form field has custom status bar text in FFData.xstzStatText. If fOwnStat is 0, FFData.xstzStatText contains an empty or auto-generated string.\r
+     * @return  the fOwnStat field value.\r
+     */\r
+    @Internal\r
+    public boolean isFOwnStat()\r
+    {\r
+        return fOwnStat.isSet(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the fProt field value.\r
+     * A bit that specifies whether the form field is protected and its value cannot be changed.\r
+     */\r
+    @Internal\r
+    public void setFProt( boolean value )\r
+    {\r
+        field_2_bits = (short)fProt.setBoolean(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * A bit that specifies whether the form field is protected and its value cannot be changed.\r
+     * @return  the fProt field value.\r
+     */\r
+    @Internal\r
+    public boolean isFProt()\r
+    {\r
+        return fProt.isSet(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the iSize field value.\r
+     * A bit that specifies whether the size of a checkbox is automatically determined by the text size where the checkbox is located. This value MUST be 0 if iType is not iTypeChck (1).\r
+     */\r
+    @Internal\r
+    public void setISize( boolean value )\r
+    {\r
+        field_2_bits = (short)iSize.setBoolean(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * A bit that specifies whether the size of a checkbox is automatically determined by the text size where the checkbox is located. This value MUST be 0 if iType is not iTypeChck (1).\r
+     * @return  the iSize field value.\r
+     */\r
+    @Internal\r
+    public boolean isISize()\r
+    {\r
+        return iSize.isSet(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the iTypeTxt field value.\r
+     * An unsigned integer that specifies the type of the textbox. If iType is not iTypeText (0), iTypeTxt MUST be 0 and MUST be ignored.\r
+     */\r
+    @Internal\r
+    public void setITypeTxt( byte value )\r
+    {\r
+        field_2_bits = (short)iTypeTxt.setValue(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * An unsigned integer that specifies the type of the textbox. If iType is not iTypeText (0), iTypeTxt MUST be 0 and MUST be ignored.\r
+     * @return  the iTypeTxt field value.\r
+     */\r
+    @Internal\r
+    public byte getITypeTxt()\r
+    {\r
+        return ( byte )iTypeTxt.getValue(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the fRecalc field value.\r
+     * A bit that specifies whether the value of the field is automatically calculated after the field is modified.\r
+     */\r
+    @Internal\r
+    public void setFRecalc( boolean value )\r
+    {\r
+        field_2_bits = (short)fRecalc.setBoolean(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * A bit that specifies whether the value of the field is automatically calculated after the field is modified.\r
+     * @return  the fRecalc field value.\r
+     */\r
+    @Internal\r
+    public boolean isFRecalc()\r
+    {\r
+        return fRecalc.isSet(field_2_bits);\r
+    }\r
+\r
+    /**\r
+     * Sets the fHasListBox field value.\r
+     * A bit that specifies that the form field has a list box. This value MUST be 1 if iType is iTypeDrop (2). Otherwise, this value MUST be 0.\r
+     */\r
+    @Internal\r
+    public void setFHasListBox( boolean value )\r
+    {\r
+        field_2_bits = (short)fHasListBox.setBoolean(field_2_bits, value);\r
+    }\r
+\r
+    /**\r
+     * A bit that specifies that the form field has a list box. This value MUST be 1 if iType is iTypeDrop (2). Otherwise, this value MUST be 0.\r
+     * @return  the fHasListBox field value.\r
+     */\r
+    @Internal\r
+    public boolean isFHasListBox()\r
+    {\r
+        return fHasListBox.isSet(field_2_bits);\r
+    }\r
+\r
+}  // END OF CLASS\r
index 6bb3785f4c0bbaff9f290cac032b480804d1f0e7..d3fe6613a69b2db9a980a676a1e1943ed9230e7a 100644 (file)
@@ -180,16 +180,13 @@ public final class CharacterSprmUncompressor extends SprmUncompressor
         case 0x3:
             // sprmCPicLocation -- 0x6A03
             /*
-             * Microsoft Office Word 97-2007 Binary File Format (.doc)
-             * Specification
+             * [MS-DOC]
              * 
-             * Page 75 of 210
+             * Page 104 of 622
              * 
-             * sprmCPicLocation (opcode 0x6A03) is used ONLY IN CHPX FKPs. This
-             * sprm moves the 4-byte operand of the sprm into the chp.fcPic
-             * field. It simultaneously sets chp.fSpec to 1. This sprm is also
-             * used when the chp.lTagObj field that is unioned with chp.fcPic is
-             * to be set for OLE objects.
+             * A signed 32-bit integer that specifies either the position in the
+             * Data Stream of a picture or binary data or the name of an OLE
+             * object storage.
              */
             newCHP.setFcPic( sprm.getOperand() );
             newCHP.setFSpec( true );
index 77ec0ecd3311aed18bc19687cbd6db9fadaefcd3..97875ee2480f7fe5e204928d8b0f1c57884aaa8b 100644 (file)
 
 package org.apache.poi.hwpf.usermodel;
 
+import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.model.CHPX;
+import org.apache.poi.hwpf.model.FFData;
 import org.apache.poi.hwpf.model.Ffn;
+import org.apache.poi.hwpf.model.NilPICFAndBinData;
 import org.apache.poi.hwpf.model.StyleSheet;
 import org.apache.poi.hwpf.sprm.SprmBuffer;
 
@@ -631,4 +634,42 @@ public final class CharacterRun
      String text = text();
      return "CharacterRun of " + text.length() + " characters - " + text; 
   }
+
+    public String[] getDropDownListValues()
+    {
+        if ( getDocument() instanceof HWPFDocument )
+        {
+            char c = _text.charAt( _start );
+            if ( c == 0x01 )
+            {
+                NilPICFAndBinData data = new NilPICFAndBinData(
+                        ( (HWPFDocument) getDocument() ).getDataStream(),
+                        getPicOffset() );
+                FFData ffData = new FFData( data.getBinData(), 0 );
+
+                String[] values = ffData.getDropList();
+                return values;
+            }
+        }
+        return null;
+    }
+
+    public Integer getDropDownListDefaultItemIndex()
+    {
+        if ( getDocument() instanceof HWPFDocument )
+        {
+            char c = _text.charAt( _start );
+            if ( c == 0x01 )
+            {
+                NilPICFAndBinData data = new NilPICFAndBinData(
+                        ( (HWPFDocument) getDocument() ).getDataStream(),
+                        getPicOffset() );
+                FFData ffData = new FFData( data.getBinData(), 0 );
+
+                return Integer.valueOf( ffData.getDefaultDropDownItemIndex() );
+            }
+        }
+        return null;
+    }
+
 }
index 74be67b28d77c02dc6527ccb162f1adc9f6e1c2c..6d748cd3cdb8f36e8b06b61ad169e010a2cecf4e 100644 (file)
@@ -141,6 +141,14 @@ public class TestWordToHtmlConverter extends TestCase
         getHtmlText( "Bug48075.doc" );
     }
 
+    public void testBug52583() throws Exception
+    {
+        String result = getHtmlText( "Bug52583.doc" );
+        assertContains(
+                result,
+                "<select><option selected>riri</option><option>fifi</option><option>loulou</option></select>" );
+    }
+
     public void testBug53182() throws Exception
     {
         String result = getHtmlText( "Bug53182.doc" );
diff --git a/src/types/definitions/FFData_type.xml b/src/types/definitions/FFData_type.xml
new file mode 100644 (file)
index 0000000..2016adb
--- /dev/null
@@ -0,0 +1,81 @@
+<?xml version="1.0"?>
+<!--
+    ====================================================================
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements. See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+    ====================================================================
+-->
+<record fromfile="true" name="FFDataBase" package="org.apache.poi.hwpf.model.types">
+       <suffix>AbstractType</suffix>
+       <description>The FFData structure specifies form field data for a text
+               box, check box, or drop-down list box. &lt;p&gt;Class and fields
+               descriptions are quoted from [MS-DOC] -- v20121003 Word (.doc) Binary
+               File Format; Copyright (c) 2012 Microsoft Corporation; Release:
+               October 8, 2012
+       </description>
+       <author>Sergey Vladimirov; according to [MS-DOC] -- v20121003 Word
+               (.doc) Binary File Format; Copyright (c) 2012 Microsoft Corporation;
+               Release: October 8, 2012
+       </author>
+       <fields>
+               <field type="long" size="4" name="version"
+                       description="An unsigned integer that MUST be 0xFFFFFFFF" />
+               <field type="short" size="2" name="bits"
+                       description="An FFDataBits that specifies the type and state of this form field">
+                       <bit mask="0x0003" name="iType"
+                               description="An unsigned integer that specifies the type of the form field. ">
+                               <const type="byte" value="0" name="Text"
+                                       description="Specifies that the form field is a textbox." />
+                               <const type="byte" value="1" name="Chck"
+                                       description="Specifies that the form field is a checkbox." />
+                               <const type="byte" value="2" name="Drop"
+                                       description="Specifies that the form field is a dropdown list box." />
+                       </bit>
+                       <bit mask="0x007C" name="iRes"
+                               description="An unsigned integer. If iType is iTypeText (0), then iRes MUST be 0. If iType is iTypeChck (1), iRes specifies the state of the checkbox and MUST be 0 (unchecked), 1 (checked), or 25 (undefined). Undefined checkboxes are treated as unchecked. If iType is iTypeDrop (2), iRes specifies the current selected list box item. A value of 25 specifies the selection is undefined. Otherwise, iRes is a zero-based index into FFData.hsttbDropList." />
+                       <bit mask="0x0080" name="fOwnHelp"
+                               description="A bit that specifies whether the form field has custom help text in FFData.xstzHelpText. If fOwnHelp is 0, FFData.xstzHelpText contains an empty or auto-generated string." />
+                       <bit mask="0x0100" name="fOwnStat"
+                               description="A bit that specifies whether the form field has custom status bar text in FFData.xstzStatText. If fOwnStat is 0, FFData.xstzStatText contains an empty or auto-generated string." />
+                       <bit mask="0x0200" name="fProt"
+                               description="A bit that specifies whether the form field is protected and its value cannot be changed." />
+                       <bit mask="0x0400" name="iSize"
+                               description="A bit that specifies whether the size of a checkbox is automatically determined by the text size where the checkbox is located. This value MUST be 0 if iType is not iTypeChck (1)." />
+                       <bit mask="0x3800" name="iTypeTxt"
+                               description="An unsigned integer that specifies the type of the textbox. If iType is not iTypeText (0), iTypeTxt MUST be 0 and MUST be ignored." >
+                               <const type="byte" value="0" name="Reg"
+                                       description="Specifies that the textbox value is regular text." />
+                               <const type="byte" value="0" name="Num"
+                                       description="Specifies that the textbox value is a number." />
+                               <const type="byte" value="0" name="Date"
+                                       description="Specifies that the textbox value is a date or time." />
+                               <const type="byte" value="0" name="CurDate"
+                                       description="Specifies that the textbox value is the current date." />
+                               <const type="byte" value="0" name="CurTime"
+                                       description="Specifies that the textbox value is the current time." />
+                               <const type="byte" value="0" name="Calc"
+                                       description="Specifies that the textbox value is calculated from an expression. The expression is given by FFData.xstzTextDef." />
+                       </bit>
+                       <bit mask="0x4000" name="fRecalc"
+                               description="A bit that specifies whether the value of the field is automatically calculated after the field is modified." />
+                       <bit mask="0x8000" name="fHasListBox"
+                               description="A bit that specifies that the form field has a list box. This value MUST be 1 if iType is iTypeDrop (2). Otherwise, this value MUST be 0." />
+               </field>
+               <field type="int" size="2" name="cch"
+                       description="An unsigned integer that specifies the maximum length, in characters, of the value of the textbox. This value MUST NOT exceed 32767. A value of 0 means there is no maximum length of the value of the textbox. If bits.iType is not iTypeText (0), this value MUST be 0." />
+               <field type="int" size="2" name="hps"
+                       description="An unsigned integer. If bits.iType is iTypeChck (1), hps specifies the size, in half-points, of the checkbox and MUST be between 2 and 3168, inclusive. If bits.iType is not iTypeChck (1), hps is undefined and MUST be ignored." />
+       </fields>
+</record>
index ab923d1921ca7d9e4249192b33ab68881554b0fc..d8c90e7523cd4ff39a7174c83bb72cf89adb4131 100644 (file)
@@ -352,10 +352,22 @@ public abstract class </xsl:text><xsl:call-template name="outputClassName"/><xsl
                 <xsl:value-of select="$fieldName"/>
                 <xsl:text>? 1231 : 1237 )</xsl:text>
             </xsl:when>
-            <xsl:when test="@type='byte' or @type='double' or @type='int' or @type='long' or @type='short'">
+            <xsl:when test="@type='byte' or @type='double' or @type='int' or @type='short'">
                        <xsl:text> + </xsl:text>
                 <xsl:value-of select="$fieldName"/>
             </xsl:when>
+            <xsl:when test="@type='long'">
+                               <xsl:call-template name="linebreak" />
+                               <xsl:call-template name="indent" />
+                               <xsl:call-template name="indent" />
+                               <xsl:call-template name="indent" />
+                               <xsl:call-template name="indent" />
+                       <xsl:text> + (int) ( </xsl:text>
+                <xsl:value-of select="$fieldName"/>
+                       <xsl:text> ^ ( </xsl:text>
+                <xsl:value-of select="$fieldName"/>
+                       <xsl:text> >>> 32 ) )</xsl:text>
+            </xsl:when>
             <xsl:otherwise>
                                <xsl:call-template name="linebreak" />
                                <xsl:call-template name="indent" />
@@ -440,27 +452,42 @@ public abstract class </xsl:text><xsl:call-template name="outputClassName"/><xsl
         <xsl:value-of select="@mask"/>
         <xsl:text>);</xsl:text>
         <xsl:call-template name="linebreak"/>
+        <xsl:apply-templates select="const"/>
     </xsl:template>
 
-    <xsl:template match="const">
-        <xsl:if test="@description">
-            <xsl:call-template name="indent"/>
-            <xsl:text>/** </xsl:text>
-            <xsl:value-of select="@description"/>
-            <xsl:text> */</xsl:text>
-            <xsl:call-template name="linebreak"/>
-        </xsl:if>
-        <xsl:call-template name="indent"/>
-        <xsl:text>/**/</xsl:text>
-        <xsl:text>protected final static </xsl:text>
-        <xsl:value-of select="@type"/>
-        <xsl:text> </xsl:text>
-        <xsl:value-of select="recutil:getConstName(../@name,@name,0)"/>
-        <xsl:text> = </xsl:text>
-        <xsl:value-of select="@value"/>
-        <xsl:text>;</xsl:text>
-        <xsl:call-template name="linebreak"/>
-    </xsl:template>
+       <xsl:template match="const">
+               <xsl:if test="@description">
+                       <xsl:call-template name="indent" />
+                       <xsl:choose>
+                               <xsl:when test="name(..) = 'bit'">
+                                       <xsl:text>/**   </xsl:text>
+                               </xsl:when>
+                               <xsl:otherwise>
+                                       <xsl:text>/** </xsl:text>
+                               </xsl:otherwise>
+                       </xsl:choose>
+                       <xsl:value-of select="@description" />
+                       <xsl:text> */</xsl:text>
+                       <xsl:call-template name="linebreak" />
+               </xsl:if>
+               <xsl:call-template name="indent" />
+               <xsl:choose>
+                       <xsl:when test="name(..) = 'bit'">
+                               <xsl:text>/*  */</xsl:text>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <xsl:text>/**/</xsl:text>
+                       </xsl:otherwise>
+               </xsl:choose>
+               <xsl:text>protected final static </xsl:text>
+               <xsl:value-of select="@type" />
+               <xsl:text> </xsl:text>
+               <xsl:value-of select="recutil:getConstName(../@name,@name,0)" />
+               <xsl:text> = </xsl:text>
+               <xsl:value-of select="@value" />
+               <xsl:text>;</xsl:text>
+               <xsl:call-template name="linebreak" />
+       </xsl:template>
 
     <xsl:template match="const" mode="listconsts">
         <xsl:call-template name="linebreak"/>
diff --git a/test-data/document/Bug52583.doc b/test-data/document/Bug52583.doc
new file mode 100644 (file)
index 0000000..b6e8646
Binary files /dev/null and b/test-data/document/Bug52583.doc differ