From: Sergey Vladimirov Date: Wed, 21 Sep 2011 10:00:43 +0000 (+0000) Subject: use StdfBase structure in StyleDescription X-Git-Tag: REL_3_8_BETA5~147 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=caacbbdabce2431ea5f49ce7ca8e30d53dab215f;p=poi.git use StdfBase structure in StyleDescription git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173550 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java new file mode 100644 index 0000000000..03e5503fcf --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StdfBase.java @@ -0,0 +1,78 @@ +/* ==================================================================== + 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.StdfBaseAbstractType; + +/** + * The StdfBase structure specifies general information about a style. + */ +public class StdfBase extends StdfBaseAbstractType +{ + + public StdfBase() + { + } + + public StdfBase( byte[] std, int offset ) + { + fillFields( std, offset ); + } + + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + StdfBase other = (StdfBase) obj; + if ( field_1_info1 != other.field_1_info1 ) + return false; + if ( field_2_info2 != other.field_2_info2 ) + return false; + if ( field_3_info3 != other.field_3_info3 ) + return false; + if ( field_4_bchUpe != other.field_4_bchUpe ) + return false; + if ( field_5_grfstd != other.field_5_grfstd ) + return false; + return true; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + field_1_info1; + result = prime * result + field_2_info2; + result = prime * result + field_3_info3; + result = prime * result + field_4_bchUpe; + result = prime * result + field_5_grfstd; + return result; + } + + public byte[] serialize() + { + byte[] result = new byte[getSize()]; + serialize( result, 0 ); + return result; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java index 7c7858ed50..1d0cb6eb97 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java @@ -22,10 +22,9 @@ import java.util.Arrays; import org.apache.poi.hwpf.usermodel.CharacterProperties; import org.apache.poi.hwpf.usermodel.ParagraphProperties; -import org.apache.poi.util.BitField; -import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; + /** * Comment me * @@ -37,25 +36,11 @@ public final class StyleDescription implements HDFType private final static int PARAGRAPH_STYLE = 1; private final static int CHARACTER_STYLE = 2; + private final static int TABLE_STYLE = 3; + private final static int NUMBERING_STYLE = 4; - private int _istd; private int _baseLength; - private short _infoShort; - private static BitField _sti = BitFieldFactory.getInstance(0xfff); - private static BitField _fScratch = BitFieldFactory.getInstance(0x1000); - private static BitField _fInvalHeight = BitFieldFactory.getInstance(0x2000); - private static BitField _fHasUpe = BitFieldFactory.getInstance(0x4000); - private static BitField _fMassCopy = BitFieldFactory.getInstance(0x8000); - private short _infoShort2; - private static BitField _styleTypeCode = BitFieldFactory.getInstance(0xf); - private static BitField _baseStyle = BitFieldFactory.getInstance(0xfff0); - private short _infoShort3; - private static BitField _numUPX = BitFieldFactory.getInstance(0xf); - private static BitField _nextStyle = BitFieldFactory.getInstance(0xfff0); - private short _bchUpe; - private short _infoShort4; - private static BitField _fAutoRedef = BitFieldFactory.getInstance(0x1); - private static BitField _fHidden = BitFieldFactory.getInstance(0x2); + private StdfBase _stdfBase; UPX[] _upxs; String _name; @@ -71,16 +56,9 @@ public final class StyleDescription implements HDFType { _baseLength = baseLength; int nameStart = offset + baseLength; - _infoShort = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _infoShort2 = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _infoShort3 = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _bchUpe = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; - _infoShort4 = LittleEndian.getShort(std, offset); - offset += LittleEndian.SHORT_SIZE; + + _stdfBase = new StdfBase(std, offset); + offset += StdfBase.getSize(); //first byte(s) of variable length section of std is the length of the //style name and aliases string @@ -112,9 +90,9 @@ public final class StyleDescription implements HDFType // the spec only refers to two possible upxs but it mentions // that more may be added in the future int varOffset = grupxStart; - int numUPX = _numUPX.getValue(_infoShort3); - _upxs = new UPX[numUPX]; - for(int x = 0; x < numUPX; x++) + int countOfUPX = _stdfBase.getCupx(); + _upxs = new UPX[countOfUPX]; + for(int x = 0; x < countOfUPX; x++) { int upxSize = LittleEndian.getShort(std, varOffset); varOffset += LittleEndian.SHORT_SIZE; @@ -137,11 +115,11 @@ public final class StyleDescription implements HDFType } public int getBaseStyle() { - return _baseStyle.getValue(_infoShort2); + return _stdfBase.getIstdBase(); } public byte[] getCHPX() { - switch (_styleTypeCode.getValue(_infoShort2)) + switch (_stdfBase.getStk()) { case PARAGRAPH_STYLE: if (_upxs.length > 1) @@ -158,7 +136,7 @@ public final class StyleDescription implements HDFType } public byte[] getPAPX() { - switch (_styleTypeCode.getValue(_infoShort2)) + switch (_stdfBase.getStk()) { case PARAGRAPH_STYLE: return _upxs[0].getUPX(); @@ -206,18 +184,9 @@ public final class StyleDescription implements HDFType byte[] buf = new byte[size]; + _stdfBase.serialize( buf, 0 ); - int offset = 0; - LittleEndian.putShort(buf, offset, _infoShort); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _infoShort2); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _infoShort3); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _bchUpe); - offset += LittleEndian.SHORT_SIZE; - LittleEndian.putShort(buf, offset, _infoShort4); - offset = _baseLength; + int offset = _baseLength; char[] letters = _name.toCharArray(); LittleEndian.putShort(buf, _baseLength, (short)letters.length); @@ -242,21 +211,44 @@ public final class StyleDescription implements HDFType return buf; } - public boolean equals(Object o) - { - StyleDescription sd = (StyleDescription)o; - if (sd._infoShort == _infoShort && sd._infoShort2 == _infoShort2 && - sd._infoShort3 == _infoShort3 && sd._bchUpe == _bchUpe && - sd._infoShort4 == _infoShort4 && - _name.equals(sd._name)) + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( _name == null ) ? 0 : _name.hashCode() ); + result = prime * result + + ( ( _stdfBase == null ) ? 0 : _stdfBase.hashCode() ); + result = prime * result + Arrays.hashCode( _upxs ); + return result; + } - if (!Arrays.equals(_upxs, sd._upxs)) - { - return false; - } - return true; + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + StyleDescription other = (StyleDescription) obj; + if ( _name == null ) + { + if ( other._name != null ) + return false; + } + else if ( !_name.equals( other._name ) ) + return false; + if ( _stdfBase == null ) + { + if ( other._stdfBase != null ) + return false; + } + else if ( !_stdfBase.equals( other._stdfBase ) ) + return false; + if ( !Arrays.equals( _upxs, other._upxs ) ) + return false; + return true; } - return false; - } }