@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 )
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 );
@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" );
}
}
--- /dev/null
+/* ====================================================================
+ 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() );
+ }
+
+}