From: Sergey Vladimirov Date: Sat, 1 Oct 2011 15:46:26 +0000 (+0000) Subject: replace FIBShortHandler with FibRgW97 X-Git-Tag: REL_3_8_BETA5~114 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=66e8ec4ef74e3cd9c1dea83383ce1506f68b21ac;p=poi.git replace FIBShortHandler with FibRgW97 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1178030 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java deleted file mode 100644 index ce1731e58a..0000000000 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBShortHandler.java +++ /dev/null @@ -1,77 +0,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. -==================================================================== */ - -package org.apache.poi.hwpf.model; - -import org.apache.poi.util.Internal; -import org.apache.poi.util.LittleEndian; - -/** - * Handles the fibRgW / FibRgW97 part of - * the FIB (File Information Block) - */ -@Internal -public final class FIBShortHandler { - public final static int MAGICCREATED = 0; - public final static int MAGICREVISED = 1; - public final static int MAGICCREATEDPRIVATE = 2; - public final static int MAGICREVISEDPRIVATE = 3; - public final static int LIDFE = 13; - - final static int START = 0x20; - - short[] _shorts; - - public FIBShortHandler(byte[] mainStream) - { - int offset = START; - int shortCount = LittleEndian.getShort(mainStream, offset); - offset += LittleEndian.SHORT_SIZE; - _shorts = new short[shortCount]; - - for (int x = 0; x < shortCount; x++) - { - _shorts[x] = LittleEndian.getShort(mainStream, offset); - offset += LittleEndian.SHORT_SIZE; - } - } - - public short getShort(int shortCode) - { - return _shorts[shortCode]; - } - - int sizeInBytes() - { - return (_shorts.length * LittleEndian.SHORT_SIZE) + LittleEndian.SHORT_SIZE; - } - - void serialize(byte[] mainStream) { - int offset = START; - LittleEndian.putShort(mainStream, offset, (short)_shorts.length); - offset += LittleEndian.SHORT_SIZE; - //mainStream.write(holder); - - for (int x = 0; x < _shorts.length; x++) - { - LittleEndian.putShort(mainStream, offset, _shorts[x]); - offset += LittleEndian.SHORT_SIZE; - } - } - - -} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FibRgW97.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FibRgW97.java new file mode 100644 index 0000000000..ec15c8e65a --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FibRgW97.java @@ -0,0 +1,110 @@ +/* ==================================================================== + 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. +==================================================================== */ +package org.apache.poi.hwpf.model; + +import org.apache.poi.hwpf.model.types.FibRgW97AbstractType; +import org.apache.poi.util.Internal; + +/** + * The FibRgW97 structure is a variable-length portion of the Fib. + *

+ * Class and fields descriptions are quoted from Microsoft Office Word 97-2007 + * Binary File Format and [MS-DOC] - v20110608 Word (.doc) Binary File Format. + * + * @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary + * File Format Specification [*.doc] and [MS-DOC] - v20110608 Word + * (.doc) Binary File Format + */ +@Internal +class FibRgW97 extends FibRgW97AbstractType +{ + + public FibRgW97() + { + } + + public FibRgW97( byte[] std, int offset ) + { + fillFields( std, offset ); + } + + @Override + @SuppressWarnings( "deprecation" ) + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + FibRgW97 other = (FibRgW97) obj; + if ( field_10_reserved10 != other.field_10_reserved10 ) + return false; + if ( field_11_reserved11 != other.field_11_reserved11 ) + return false; + if ( field_12_reserved12 != other.field_12_reserved12 ) + return false; + if ( field_13_reserved13 != other.field_13_reserved13 ) + return false; + if ( field_14_lidFE != other.field_14_lidFE ) + return false; + if ( field_1_reserved1 != other.field_1_reserved1 ) + return false; + if ( field_2_reserved2 != other.field_2_reserved2 ) + return false; + if ( field_3_reserved3 != other.field_3_reserved3 ) + return false; + if ( field_4_reserved4 != other.field_4_reserved4 ) + return false; + if ( field_5_reserved5 != other.field_5_reserved5 ) + return false; + if ( field_6_reserved6 != other.field_6_reserved6 ) + return false; + if ( field_7_reserved7 != other.field_7_reserved7 ) + return false; + if ( field_8_reserved8 != other.field_8_reserved8 ) + return false; + if ( field_9_reserved9 != other.field_9_reserved9 ) + return false; + return true; + } + + @Override + @SuppressWarnings( "deprecation" ) + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + field_10_reserved10; + result = prime * result + field_11_reserved11; + result = prime * result + field_12_reserved12; + result = prime * result + field_13_reserved13; + result = prime * result + field_14_lidFE; + result = prime * result + field_1_reserved1; + result = prime * result + field_2_reserved2; + result = prime * result + field_3_reserved3; + result = prime * result + field_4_reserved4; + result = prime * result + field_5_reserved5; + result = prime * result + field_6_reserved6; + result = prime * result + field_7_reserved7; + result = prime * result + field_8_reserved8; + result = prime * result + field_9_reserved9; + return result; + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index f07f791fce..fcec36f795 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -24,14 +24,15 @@ import java.util.HashSet; import org.apache.poi.hwpf.model.io.HWPFOutputStream; import org.apache.poi.util.Internal; +import org.apache.poi.util.LittleEndian; /** * The File Information Block (FIB). Holds pointers * to various bits of the file, and lots of flags which * specify properties of the document. * - * The parent class, {@link FIBAbstractType}, holds the - * first 32 bytes, which make up the FibBase. + * The {@link FibBase} class, holds the + * first 32 bytes. * The next part, the fibRgW / FibRgW97, is handled * by {@link FIBShortHandler}. * The next part, the fibRgLw / The FibRgLw97, is @@ -42,26 +43,37 @@ import org.apache.poi.util.Internal; * @author andy */ @Internal -public final class FileInformationBlock implements Cloneable +public final class FileInformationBlock implements Cloneable { private FibBase _fibBase; - + private int _csw; + private FibRgW97 _fibRgW97; + FIBLongHandler _longHandler; - FIBShortHandler _shortHandler; FIBFieldHandler _fieldHandler; /** Creates a new instance of FileInformationBlock */ - public FileInformationBlock(byte[] mainDocument) + public FileInformationBlock( byte[] mainDocument ) { - _fibBase = new FibBase(mainDocument, 0); + int offset = 0; + + _fibBase = new FibBase( mainDocument, offset ); + offset = FibBase.getSize(); + assert offset == 32; + + _csw = LittleEndian.getUShort( mainDocument, offset ); + offset += 2; + assert offset == 34; + + _fibRgW97 = new FibRgW97( mainDocument, 34 ); + offset += FibRgW97.getSize(); + assert offset == 62; } public void fillVariableFields( byte[] mainDocument, byte[] tableStream ) { - _shortHandler = new FIBShortHandler( mainDocument ); - _longHandler = new FIBLongHandler( mainDocument, FIBShortHandler.START - + _shortHandler.sizeInBytes() ); + _longHandler = new FIBLongHandler( mainDocument, 62 ); /* * Listed fields won't be treat as UnhandledDataStructure. For all other @@ -102,9 +114,8 @@ public final class FileInformationBlock implements Cloneable knownFieldSet.add( Integer.valueOf( FIBFieldHandler.MODIFIED ) ); _fieldHandler = new FIBFieldHandler( mainDocument, - FIBShortHandler.START + _shortHandler.sizeInBytes() - + _longHandler.sizeInBytes(), tableStream, - knownFieldSet, true ); + 62 + _longHandler.sizeInBytes(), tableStream, knownFieldSet, + true ); } @Override @@ -964,8 +975,11 @@ public final class FileInformationBlock implements Cloneable _fibBase.serialize( mainStream, 0 ); int offset = FibBase.getSize(); - _shortHandler.serialize( mainStream ); - offset += _shortHandler.sizeInBytes(); + LittleEndian.putUShort( mainStream, offset, _csw ); + offset += 2; + + _fibRgW97.serialize( mainStream, offset ); + offset += FibRgW97.getSize(); _longHandler.serialize( mainStream, offset ); offset += _longHandler.sizeInBytes(); @@ -975,7 +989,7 @@ public final class FileInformationBlock implements Cloneable public int getSize() { - return FibBase.getSize() + _shortHandler.sizeInBytes() + return FibBase.getSize() + 2 + FibRgW97.getSize() + _longHandler.sizeInBytes() + _fieldHandler.sizeInBytes(); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FibRgW97AbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FibRgW97AbstractType.java new file mode 100644 index 0000000000..6dbc944670 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FibRgW97AbstractType.java @@ -0,0 +1,415 @@ +/* ==================================================================== + 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. +==================================================================== */ +package org.apache.poi.hwpf.model.types; + + +import org.apache.poi.util.Internal; +import org.apache.poi.util.LittleEndian; + +/** + * The FibRgW97 structure is a variable-length portion of the Fib.

Class and + fields descriptions are quoted from Microsoft Office Word 97-2007 Binary File Format and + [MS-DOC] - v20110608 Word (.doc) Binary File Format + + *

+ * NOTE: This source is automatically generated please do not modify this file. Either subclass or + * remove the record in src/types/definitions. + *

+ * This class is internal. It content or properties may change without notice + * due to changes in our knowledge of internal Microsoft Word binary structures. + + * @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format + Specification [*.doc] and [MS-DOC] - v20110608 Word (.doc) Binary File Format + + */ +@Internal +public abstract class FibRgW97AbstractType +{ + + @Deprecated + protected short field_1_reserved1; + @Deprecated + protected short field_2_reserved2; + @Deprecated + protected short field_3_reserved3; + @Deprecated + protected short field_4_reserved4; + @Deprecated + protected short field_5_reserved5; + @Deprecated + protected short field_6_reserved6; + @Deprecated + protected short field_7_reserved7; + @Deprecated + protected short field_8_reserved8; + @Deprecated + protected short field_9_reserved9; + @Deprecated + protected short field_10_reserved10; + @Deprecated + protected short field_11_reserved11; + @Deprecated + protected short field_12_reserved12; + @Deprecated + protected short field_13_reserved13; + protected short field_14_lidFE; + + protected FibRgW97AbstractType() + { + } + + protected void fillFields( byte[] data, int offset ) + { + field_1_reserved1 = LittleEndian.getShort( data, 0x0 + offset ); + field_2_reserved2 = LittleEndian.getShort( data, 0x2 + offset ); + field_3_reserved3 = LittleEndian.getShort( data, 0x4 + offset ); + field_4_reserved4 = LittleEndian.getShort( data, 0x6 + offset ); + field_5_reserved5 = LittleEndian.getShort( data, 0x8 + offset ); + field_6_reserved6 = LittleEndian.getShort( data, 0xa + offset ); + field_7_reserved7 = LittleEndian.getShort( data, 0xc + offset ); + field_8_reserved8 = LittleEndian.getShort( data, 0xe + offset ); + field_9_reserved9 = LittleEndian.getShort( data, 0x10 + offset ); + field_10_reserved10 = LittleEndian.getShort( data, 0x12 + offset ); + field_11_reserved11 = LittleEndian.getShort( data, 0x14 + offset ); + field_12_reserved12 = LittleEndian.getShort( data, 0x16 + offset ); + field_13_reserved13 = LittleEndian.getShort( data, 0x18 + offset ); + field_14_lidFE = LittleEndian.getShort( data, 0x1a + offset ); + } + + public void serialize( byte[] data, int offset ) + { + LittleEndian.putShort( data, 0x0 + offset, field_1_reserved1 ); + LittleEndian.putShort( data, 0x2 + offset, field_2_reserved2 ); + LittleEndian.putShort( data, 0x4 + offset, field_3_reserved3 ); + LittleEndian.putShort( data, 0x6 + offset, field_4_reserved4 ); + LittleEndian.putShort( data, 0x8 + offset, field_5_reserved5 ); + LittleEndian.putShort( data, 0xa + offset, field_6_reserved6 ); + LittleEndian.putShort( data, 0xc + offset, field_7_reserved7 ); + LittleEndian.putShort( data, 0xe + offset, field_8_reserved8 ); + LittleEndian.putShort( data, 0x10 + offset, field_9_reserved9 ); + LittleEndian.putShort( data, 0x12 + offset, field_10_reserved10 ); + LittleEndian.putShort( data, 0x14 + offset, field_11_reserved11 ); + LittleEndian.putShort( data, 0x16 + offset, field_12_reserved12 ); + LittleEndian.putShort( data, 0x18 + offset, field_13_reserved13 ); + LittleEndian.putShort( data, 0x1a + offset, field_14_lidFE ); + } + + public byte[] serialize() + { + final byte[] result = new byte[ getSize() ]; + serialize( result, 0 ); + return result; + } + + /** + * Size of record + */ + public static int getSize() + { + return 0 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2; + } + + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("[FibRgW97]\n"); + builder.append(" .reserved1 = "); + builder.append(" (").append(getReserved1()).append(" )\n"); + builder.append(" .reserved2 = "); + builder.append(" (").append(getReserved2()).append(" )\n"); + builder.append(" .reserved3 = "); + builder.append(" (").append(getReserved3()).append(" )\n"); + builder.append(" .reserved4 = "); + builder.append(" (").append(getReserved4()).append(" )\n"); + builder.append(" .reserved5 = "); + builder.append(" (").append(getReserved5()).append(" )\n"); + builder.append(" .reserved6 = "); + builder.append(" (").append(getReserved6()).append(" )\n"); + builder.append(" .reserved7 = "); + builder.append(" (").append(getReserved7()).append(" )\n"); + builder.append(" .reserved8 = "); + builder.append(" (").append(getReserved8()).append(" )\n"); + builder.append(" .reserved9 = "); + builder.append(" (").append(getReserved9()).append(" )\n"); + builder.append(" .reserved10 = "); + builder.append(" (").append(getReserved10()).append(" )\n"); + builder.append(" .reserved11 = "); + builder.append(" (").append(getReserved11()).append(" )\n"); + builder.append(" .reserved12 = "); + builder.append(" (").append(getReserved12()).append(" )\n"); + builder.append(" .reserved13 = "); + builder.append(" (").append(getReserved13()).append(" )\n"); + builder.append(" .lidFE = "); + builder.append(" (").append(getLidFE()).append(" )\n"); + + builder.append("[/FibRgW97]\n"); + return builder.toString(); + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved1() + { + return field_1_reserved1; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved1( short field_1_reserved1 ) + { + this.field_1_reserved1 = field_1_reserved1; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved2() + { + return field_2_reserved2; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved2( short field_2_reserved2 ) + { + this.field_2_reserved2 = field_2_reserved2; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved3() + { + return field_3_reserved3; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved3( short field_3_reserved3 ) + { + this.field_3_reserved3 = field_3_reserved3; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved4() + { + return field_4_reserved4; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved4( short field_4_reserved4 ) + { + this.field_4_reserved4 = field_4_reserved4; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved5() + { + return field_5_reserved5; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved5( short field_5_reserved5 ) + { + this.field_5_reserved5 = field_5_reserved5; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved6() + { + return field_6_reserved6; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved6( short field_6_reserved6 ) + { + this.field_6_reserved6 = field_6_reserved6; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved7() + { + return field_7_reserved7; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved7( short field_7_reserved7 ) + { + this.field_7_reserved7 = field_7_reserved7; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved8() + { + return field_8_reserved8; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved8( short field_8_reserved8 ) + { + this.field_8_reserved8 = field_8_reserved8; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved9() + { + return field_9_reserved9; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved9( short field_9_reserved9 ) + { + this.field_9_reserved9 = field_9_reserved9; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved10() + { + return field_10_reserved10; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved10( short field_10_reserved10 ) + { + this.field_10_reserved10 = field_10_reserved10; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved11() + { + return field_11_reserved11; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved11( short field_11_reserved11 ) + { + this.field_11_reserved11 = field_11_reserved11; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved12() + { + return field_12_reserved12; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved12( short field_12_reserved12 ) + { + this.field_12_reserved12 = field_12_reserved12; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public short getReserved13() + { + return field_13_reserved13; + } + + /** + * This value is undefined and MUST be ignored. + */ + @Internal + public void setReserved13( short field_13_reserved13 ) + { + this.field_13_reserved13 = field_13_reserved13; + } + + /** + * A LID whose meaning depends on the nFib value. + */ + @Internal + public short getLidFE() + { + return field_14_lidFE; + } + + /** + * A LID whose meaning depends on the nFib value. + */ + @Internal + public void setLidFE( short field_14_lidFE ) + { + this.field_14_lidFE = field_14_lidFE; + } + +} // END OF CLASS diff --git a/src/types/definitions/FibRgW97_type.xml b/src/types/definitions/FibRgW97_type.xml new file mode 100644 index 0000000000..f0782db427 --- /dev/null +++ b/src/types/definitions/FibRgW97_type.xml @@ -0,0 +1,58 @@ + + + + AbstractType + The FibRgW97 structure is a variable-length portion of the Fib. <p>Class and + fields descriptions are quoted from Microsoft Office Word 97-2007 Binary File Format and + [MS-DOC] - v20110608 Word (.doc) Binary File Format + + Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format + Specification [*.doc] and [MS-DOC] - v20110608 Word (.doc) Binary File Format + + + + + + + + + + + + + + + + + +