Browse Source

fix additional issue found in bug 52032, add test files

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195077 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA5
Sergey Vladimirov 12 years ago
parent
commit
a430d57858

+ 80
- 59
src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java View File

@@ -38,71 +38,23 @@ import org.apache.poi.util.POILogger;
@Internal
public final class ListLevel
{
private static final POILogger logger = POILogFactory.getLogger( ListLevel.class );
private static final POILogger logger = POILogFactory
.getLogger( ListLevel.class );

private byte[] _grpprlChpx;
private byte[] _grpprlPapx;
private LVLF _lvlf;
private char[] _xst = {};

public ListLevel( final byte[] buf, final int startOffset )
ListLevel()
{
int offset = startOffset;

_lvlf = new LVLF( buf, offset );
offset += LVLF.getSize();

_grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()];
System.arraycopy( buf, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() );
offset += _lvlf.getCbGrpprlPapx();

_grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()];
System.arraycopy( buf, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() );
offset += _lvlf.getCbGrpprlChpx();

/*
* "If this level uses bullets (see lvlf.nfc), the cch field of this Xst
* MUST be equal to 0x0001, and this MUST NOT contain any placeholders."
* -- page 389 of 621 -- [MS-DOC] -- v20110315 Word (.doc) Binary File
* Format
*/
if ( _lvlf.getNfc() == 0x17 )
{
int numberTextLength = LittleEndian.getShort( buf, offset );
offset += LittleEndian.SHORT_SIZE;

if ( numberTextLength != 1 )
{
logger.log( POILogger.WARN, "LVL at offset ",
Integer.valueOf( startOffset ),
" has nfc == 0x17 (bullets), but cch != 1 (",
Integer.valueOf( numberTextLength ), ")" );
}

_xst = new char[] { (char) LittleEndian.getShort( buf, offset ) };
offset += LittleEndian.SHORT_SIZE;
}
else
{
int numberTextLength = LittleEndian.getShort( buf, offset );
offset += LittleEndian.SHORT_SIZE;
}

if ( numberTextLength > 0 )
{
_xst = new char[numberTextLength];
for ( int x = 0; x < numberTextLength; x++ )
{
_xst[x] = (char) LittleEndian.getShort( buf, offset );
offset += LittleEndian.SHORT_SIZE;
}
}
else
{
/* sometimes numberTextLength<0 */
/* by derjohng */
_xst = new char[] {};
}
}
@Deprecated
public ListLevel( final byte[] buf, final int startOffset )
{
read( buf, startOffset );
}

public ListLevel( int level, boolean numbered )
@@ -206,6 +158,74 @@ public final class ListLevel
return _lvlf.getIxchFollow();
}

int read( final byte[] data, final int startOffset )
{
int offset = startOffset;

_lvlf = new LVLF( data, offset );
offset += LVLF.getSize();

_grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()];
System.arraycopy( data, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() );
offset += _lvlf.getCbGrpprlPapx();

_grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()];
System.arraycopy( data, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() );
offset += _lvlf.getCbGrpprlChpx();

/*
* "If this level uses bullets (see lvlf.nfc), the cch field of this Xst
* MUST be equal to 0x0001, and this MUST NOT contain any placeholders."
* -- page 389 of 621 -- [MS-DOC] -- v20110315 Word (.doc) Binary File
* Format
*/
if ( _lvlf.getNfc() == 0x17 )
{
int cch = LittleEndian.getUShort( data, offset );
offset += LittleEndian.SHORT_SIZE;

if ( cch != 1 )
{
logger.log( POILogger.WARN, "LVL at offset ",
Integer.valueOf( startOffset ),
" has nfc == 0x17 (bullets), but cch != 1 (",
Integer.valueOf( cch ), ")" );
}

_xst = new char[cch];
for ( int x = 0; x < cch; x++ )
{
_xst[x] = (char) LittleEndian.getShort( data, offset );
offset += LittleEndian.SHORT_SIZE;
}
}
else
{
int cch = LittleEndian.getUShort( data, offset );
offset += LittleEndian.SHORT_SIZE;

if ( cch > 0 )
{
_xst = new char[cch];
for ( int x = 0; x < cch; x++ )
{
_xst[x] = (char) LittleEndian.getShort( data, offset );
offset += LittleEndian.SHORT_SIZE;
}
}
else
{
logger.log( POILogger.WARN, "LVL.xst.cch <= 0: ",
Integer.valueOf( cch ) );
/* sometimes numberTextLength<0 */
/* by derjohng */
_xst = new char[] {};
}
}

return offset - startOffset;
}

public void setAlignment( int alignment )
{
_lvlf.setJc( (byte) alignment );
@@ -276,9 +296,10 @@ public final class ListLevel
@Override
public String toString()
{
return "ListLevel: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " )
return "LVL: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " )
+ "\n"
+ ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" )
+ ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" );
+ ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" )
+ ( "xst: " + Arrays.toString( _xst ) + "\n" );
}
}

+ 3
- 4
src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java View File

@@ -41,7 +41,6 @@ import org.apache.poi.util.POILogger;
@Internal
public final class ListTables
{
private static final int LIST_DATA_SIZE = 28;
private static POILogger log = POILogFactory.getLogger(ListTables.class);

ListMap _listMap = new ListMap();
@@ -65,7 +64,7 @@ public final class ListTables

int cLst = LittleEndian.getShort( tableStream, offset );
offset += LittleEndian.SHORT_SIZE;
int levelOffset = offset + ( cLst * LIST_DATA_SIZE );
int levelOffset = offset + ( cLst * LSTF.getSize() );

for ( int x = 0; x < cLst; x++ )
{
@@ -76,9 +75,9 @@ public final class ListTables
int num = lst.numLevels();
for ( int y = 0; y < num; y++ )
{
ListLevel lvl = new ListLevel( tableStream, levelOffset );
ListLevel lvl = new ListLevel();
levelOffset += lvl.read( tableStream, levelOffset );
lst.setLevel( y, lvl );
levelOffset += lvl.getSizeInBytes();
}
}
}

+ 34
- 0
src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java View File

@@ -0,0 +1,34 @@
/* ====================================================================
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 junit.framework.TestCase;

/**
* Test cases for {@link LFOLVLBaseAbstractType}
*
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
public class LFOLVLBaseAbstractTypeTest extends TestCase
{

public void testGetSize()
{
assertEquals( 8, LFOLVLBaseAbstractType.getSize() );
}

}

BIN
test-data/document/Bug52032_1.doc View File


BIN
test-data/document/Bug52032_2.doc View File


test-data/document/Bug52032.doc → test-data/document/Bug52032_3.doc View File


Loading…
Cancel
Save