latest changes

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353518 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Said Ryan Ackley 2004-03-02 06:26:04 +00:00
parent 65f4bf6e54
commit d313836fb2
70 changed files with 7898 additions and 794 deletions

View File

@ -65,9 +65,14 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.TableProperties;
import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import org.apache.poi.hwpf.model.hdftypes.*;
import org.apache.poi.hwpf.model.*;
import org.apache.poi.hwpf.model.io.*;
import org.apache.poi.hwpf.usermodel.*;
/**
@ -114,6 +119,8 @@ public class HWPFDocument
/** Holds fonts for this document.*/
private FontTable _ft;
private ListTables _lt;
/**
* This constructor loads a Word document from an InputStream.
@ -148,6 +155,8 @@ public class HWPFDocument
_tableStream = new byte[tableProps.getSize()];
_filesystem.createDocumentInputStream(name).read(_tableStream);
_fib.fillVariableFields(_mainStream, _tableStream);
// get the start of text in the main stream
int fcMin = _fib.getFcMin();
@ -171,6 +180,13 @@ public class HWPFDocument
_ss = new StyleSheet(_tableStream, _fib.getFcStshf());
_ft = new FontTable(_tableStream, _fib.getFcSttbfffn(), _fib.getLcbSttbfffn());
int listOffset = _fib.getFcPlcfLst();
int lfoOffset = _fib.getFcPlfLfo();
if (listOffset != 0 && _fib.getLcbPlcfLst() != 0)
{
_lt = new ListTables(_tableStream, _fib.getFcPlcfLst(), _fib.getFcPlfLfo());
}
int x = 0;
}
@ -185,6 +201,10 @@ public class HWPFDocument
return new Range(0, _fib.getFcMac() - _fib.getFcMin(), this);
}
public ListTables getListTables()
{
return _lt;
}
/**
* Writes out the word file that is represented by an instance of this class.
*
@ -201,6 +221,7 @@ public class HWPFDocument
HWPFOutputStream tableStream = docSys.getStream("1Table");
int tableOffset = 0;
// FileInformationBlock fib = (FileInformationBlock)_fib.clone();
// clear the offsets and sizes in our FileInformationBlock.
_fib.clearOffsetsSizes();
@ -250,6 +271,19 @@ public class HWPFDocument
_fib.setLcbPlcfsed(tableStream.getOffset() - tableOffset);
tableOffset = tableStream.getOffset();
// write out the list tables
if (_lt != null)
{
_fib.setFcPlcfLst(tableOffset);
_lt.writeListDataTo(tableStream);
_fib.setLcbPlcfLst(tableStream.getOffset() - tableOffset);
_fib.setFcPlfLfo(tableStream.getOffset());
_lt.writeListOverridesTo(tableStream);
_fib.setLcbPlfLfo(tableStream.getOffset() - tableOffset);
tableOffset = tableStream.getOffset();
}
// write out the FontTable.
_fib.setFcSttbfffn(tableOffset);
_ft.writeTo(docSys);
@ -276,6 +310,11 @@ public class HWPFDocument
System.arraycopy(mainBuf, 0, tempBuf, 0, mainBuf.length);
mainBuf = tempBuf;
}
// write out the FileInformationBlock.
//_fib.serialize(mainBuf, 0);
_fib.writeTo(mainBuf, tableStream);
byte[] tableBuf = tableStream.toByteArray();
if (tableBuf.length < 4096)
{
@ -284,8 +323,6 @@ public class HWPFDocument
tableBuf = tempBuf;
}
// write out the FileInformationBlock.
_fib.serialize(mainBuf, 0);
// spit out the Word document.
POIFSFileSystem pfs = new POIFSFileSystem();
@ -295,27 +332,34 @@ public class HWPFDocument
pfs.writeFilesystem(out);
}
CHPBinTable getCharacterTable()
public CHPBinTable getCharacterTable()
{
return _cbt;
}
PAPBinTable getParagraphTable()
public PAPBinTable getParagraphTable()
{
return _pbt;
}
SectionTable getSectionTable()
public SectionTable getSectionTable()
{
return _st;
}
TextPieceTable getTextTable()
public TextPieceTable getTextTable()
{
return _cft.getTextPieceTable();
}
public int registerList(List list)
{
if (_lt == null)
{
_lt = new ListTables();
}
return _lt.addList(list.getListData(), list.getOverride());
}
/**
* Takes two arguments, 1) name of the Word file to read in 2) location to
@ -328,19 +372,29 @@ public class HWPFDocument
try
{
HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
CharacterRun run = new CharacterRun();
run.setBold(true);
run.setItalic(true);
run.setCapitalized(true);
Range r = doc.getRange();
TableIterator ti = new TableIterator(r);
while (ti.hasNext())
{
Table t = ti.next();
int x = 0;
}
Range range = doc.getRange();
range.insertBefore("Hello World!!! HAHAHAHAHA I DID IT!!!", run);
OutputStream out = new FileOutputStream(args[1]);
doc.write(out);
out.flush();
out.close();
// CharacterRun run = new CharacterRun();
// run.setBold(true);
// run.setItalic(true);
// run.setCapitalized(true);
//
// Range range = doc.getRange();
// range.insertBefore("Hello World!!! HAHAHAHAHA I DID IT!!!", run);
//
// OutputStream out = new FileOutputStream(args[1]);
// doc.write(out);
//
// out.flush();
// out.close();
}

View File

@ -0,0 +1,254 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.util.List;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.IOException;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
import org.apache.poi.hwpf.sprm.SprmBuffer;
/**
* This class holds all of the character formatting properties.
*
* @author Ryan Ackley
*/
public class CHPBinTable
{
/** List of character properties.*/
ArrayList _textRuns = new ArrayList();
/**
* Constructor used to read a binTable in from a Word document.
*
* @param documentStream
* @param tableStream
* @param offset
* @param size
* @param fcMin
*/
public CHPBinTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin)
{
PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4);
int length = binTable.length();
for (int x = 0; x < length; x++)
{
GenericPropertyNode node = binTable.getProperty(x);
int pageNum = LittleEndian.getInt(node.getBytes());
int pageOffset = POIFSConstants.BIG_BLOCK_SIZE * pageNum;
CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream,
pageOffset, fcMin);
int fkpSize = cfkp.size();
for (int y = 0; y < fkpSize; y++)
{
_textRuns.add(cfkp.getCHPX(y));
}
}
}
public void adjustForDelete(int listIndex, int offset, int length)
{
int size = _textRuns.size();
int endMark = offset + length;
int endIndex = listIndex;
CHPX chpx = (CHPX)_textRuns.get(endIndex);
while (chpx.getEnd() < endMark)
{
chpx = (CHPX)_textRuns.get(++endIndex);
}
if (listIndex == endIndex)
{
chpx = (CHPX)_textRuns.get(endIndex);
chpx.setEnd((chpx.getEnd() - endMark) + offset);
}
else
{
chpx = (CHPX)_textRuns.get(listIndex);
chpx.setEnd(offset);
for (int x = listIndex + 1; x < endIndex; x++)
{
chpx = (CHPX)_textRuns.get(x);
chpx.setStart(offset);
chpx.setEnd(offset);
}
chpx = (CHPX)_textRuns.get(endIndex);
chpx.setEnd((chpx.getEnd() - endMark) + offset);
}
for (int x = endIndex + 1; x < size; x++)
{
chpx = (CHPX)_textRuns.get(x);
chpx.setStart(chpx.getStart() - length);
chpx.setEnd(chpx.getEnd() - length);
}
}
public void insert(int listIndex, int cpStart, SprmBuffer buf)
{
CHPX insertChpx = new CHPX(cpStart, cpStart, buf);
if (listIndex == _textRuns.size())
{
_textRuns.add(insertChpx);
}
else
{
CHPX chpx = (CHPX)_textRuns.get(listIndex);
if (chpx.getStart() < cpStart)
{
CHPX clone = new CHPX(cpStart, chpx.getEnd(), chpx.getSprmBuf());
chpx.setEnd(cpStart);
_textRuns.add(listIndex + 1, insertChpx);
_textRuns.add(listIndex + 2, clone);
}
else
{
_textRuns.add(listIndex, insertChpx);
}
}
}
public void adjustForInsert(int listIndex, int length)
{
int size = _textRuns.size();
CHPX chpx = (CHPX)_textRuns.get(listIndex);
chpx.setEnd(chpx.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
chpx = (CHPX)_textRuns.get(x);
chpx.setStart(chpx.getStart() + length);
chpx.setEnd(chpx.getEnd() + length);
}
}
public List getTextRuns()
{
return _textRuns;
}
public void writeTo(HWPFFileSystem sys, int fcMin)
throws IOException
{
HWPFOutputStream docStream = sys.getStream("WordDocument");
OutputStream tableStream = sys.getStream("1Table");
PlexOfCps binTable = new PlexOfCps(4);
// each FKP must start on a 512 byte page.
int docOffset = docStream.getOffset();
int mod = docOffset % POIFSConstants.BIG_BLOCK_SIZE;
if (mod != 0)
{
byte[] padding = new byte[POIFSConstants.BIG_BLOCK_SIZE - mod];
docStream.write(padding);
}
// get the page number for the first fkp
docOffset = docStream.getOffset();
int pageNum = docOffset/POIFSConstants.BIG_BLOCK_SIZE;
// get the ending fc
int endingFc = ((PropertyNode)_textRuns.get(_textRuns.size() - 1)).getEnd();
endingFc += fcMin;
ArrayList overflow = _textRuns;
do
{
PropertyNode startingProp = (PropertyNode)overflow.get(0);
int start = startingProp.getStart() + fcMin;
CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage();
cfkp.fill(overflow);
byte[] bufFkp = cfkp.toByteArray(fcMin);
docStream.write(bufFkp);
overflow = cfkp.getOverflow();
int end = endingFc;
if (overflow != null)
{
end = ((PropertyNode)overflow.get(0)).getStart() + fcMin;
}
byte[] intHolder = new byte[4];
LittleEndian.putInt(intHolder, pageNum++);
binTable.addProperty(new GenericPropertyNode(start, end, intHolder));
}
while (overflow != null);
tableStream.write(binTable.toByteArray());
}
}

View File

@ -0,0 +1,213 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.util.List;
import java.util.ArrayList;
import org.apache.poi.util.LittleEndian;
/**
* Represents a CHP fkp. The style properties for paragraph and character runs
* are stored in fkps. There are PAP fkps for paragraph properties and CHP fkps
* for character run properties. The first part of the fkp for both CHP and PAP
* fkps consists of an array of 4 byte int offsets that represent a
* Paragraph's or Character run's text offset in the main stream. The ending
* offset is the next value in the array. For example, if an fkp has X number of
* Paragraph's stored in it then there are (x + 1) 4 byte ints in the beginning
* array. The number X is determined by the last byte in a 512 byte fkp.
*
* CHP and PAP fkps also store the compressed styles(grpprl) that correspond to
* the offsets on the front of the fkp. The offset of the grpprls is determined
* differently for CHP fkps and PAP fkps.
*
* @author Ryan Ackley
*/
public class CHPFormattedDiskPage extends FormattedDiskPage
{
private static final int FC_SIZE = 4;
private ArrayList _chpxList = new ArrayList();
private ArrayList _overFlow;
public CHPFormattedDiskPage()
{
}
/**
* This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array
* read from a Word file).
*
* @param fkp The 512 byte array to read data from
*/
public CHPFormattedDiskPage(byte[] documentStream, int offset, int fcMin)
{
super(documentStream, offset);
for (int x = 0; x < _crun; x++)
{
_chpxList.add(new CHPX(getStart(x) - fcMin, getEnd(x) - fcMin, getGrpprl(x)));
}
}
public CHPX getCHPX(int index)
{
return (CHPX)_chpxList.get(index);
}
public void fill(List filler)
{
_chpxList.addAll(filler);
}
public ArrayList getOverflow()
{
return _overFlow;
}
/**
* Gets the chpx for the character run at index in this fkp.
*
* @param index The index of the chpx to get.
* @return a chpx grpprl.
*/
protected byte[] getGrpprl(int index)
{
int chpxOffset = 2 * LittleEndian.getUnsignedByte(_fkp, _offset + (((_crun + 1) * 4) + index));
//optimization if offset == 0 use "Normal" style
if(chpxOffset == 0)
{
return new byte[0];
}
int size = LittleEndian.getUnsignedByte(_fkp, _offset + chpxOffset);
byte[] chpx = new byte[size];
System.arraycopy(_fkp, _offset + ++chpxOffset, chpx, 0, size);
return chpx;
}
protected byte[] toByteArray(int fcMin)
{
byte[] buf = new byte[512];
int size = _chpxList.size();
int grpprlOffset = 511;
int offsetOffset = 0;
int fcOffset = 0;
// total size is currently the size of one FC
int totalSize = FC_SIZE + 1;
int index = 0;
for (; index < size; index++)
{
int grpprlLength = ((CHPX)_chpxList.get(index)).getGrpprl().length;
// check to see if we have enough room for an FC, the grpprl offset,
// the grpprl size byte and the grpprl.
totalSize += (FC_SIZE + 2 + grpprlLength);
// if size is uneven we will have to add one so the first grpprl falls
// on a word boundary
if (totalSize > 511 + (index % 2))
{
totalSize -= (FC_SIZE + 2 + grpprlLength);
break;
}
// grpprls must fall on word boundaries
if ((1 + grpprlLength) % 2 > 0)
{
totalSize += 1;
}
}
// see if we couldn't fit some
if (index != size)
{
_overFlow = new ArrayList();
_overFlow.addAll(_chpxList.subList(index, size));
}
// index should equal number of CHPXs that will be in this fkp now.
buf[511] = (byte)index;
offsetOffset = (FC_SIZE * index) + FC_SIZE;
//grpprlOffset = offsetOffset + index + (grpprlOffset % 2);
CHPX chpx = null;
for (int x = 0; x < index; x++)
{
chpx = (CHPX)_chpxList.get(x);
byte[] grpprl = chpx.getGrpprl();
LittleEndian.putInt(buf, fcOffset, chpx.getStart() + fcMin);
grpprlOffset -= (1 + grpprl.length);
grpprlOffset -= (grpprlOffset % 2);
buf[offsetOffset] = (byte)(grpprlOffset/2);
buf[grpprlOffset] = (byte)grpprl.length;
System.arraycopy(grpprl, 0, buf, grpprlOffset + 1, grpprl.length);
offsetOffset += 1;
fcOffset += FC_SIZE;
}
// put the last chpx's end in
LittleEndian.putInt(buf, fcOffset, chpx.getEnd() + fcMin);
return buf;
}
}

View File

@ -52,21 +52,49 @@
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.*;
package org.apache.poi.hwpf.model;
import java.util.List;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor;
public class SectionRange extends Range
/**
* Comment me
*
* @author Ryan Ackley
*/
public class CHPX extends CachedPropertyNode
{
public SectionRange(int start, int end, HWPFDocument doc)
public CHPX(int fcStart, int fcEnd, byte[] grpprl)
{
super(start, end, doc);
super(fcStart, fcEnd, new SprmBuffer(grpprl));
}
public SectionRange(int start, int end, Range parent)
public CHPX(int fcStart, int fcEnd, SprmBuffer buf)
{
super(start, end, parent);
super(fcStart, fcEnd, buf);
}
public byte[] getGrpprl()
{
return ((SprmBuffer)_buf).toByteArray();
}
public CharacterProperties getCharacterProperties(StyleSheet ss, short istd)
{
CharacterProperties props = (CharacterProperties)super.getCacheContents();
if (props == null)
{
CharacterProperties baseStyle = ss.getCharacterStyle(istd);
props = CharacterSprmUncompressor.uncompressCHP(baseStyle, getGrpprl(), 0);
super.fillCache(props);
}
return props;
}
}

View File

@ -0,0 +1,116 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
public class ComplexFileTable
{
private static final byte GRPPRL_TYPE = 1;
private static final byte TEXT_PIECE_TABLE_TYPE = 2;
TextPieceTable _tpt;
public ComplexFileTable(byte[] documentStream, byte[] tableStream, int offset, int fcMin) throws IOException
{
//skips through the prms before we reach the piece table. These contain data
//for actual fast saved files
while (tableStream[offset] == GRPPRL_TYPE)
{
offset++;
int skip = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE + skip;
}
if(tableStream[offset] != TEXT_PIECE_TABLE_TYPE)
{
throw new IOException("The text piece table is corrupted");
}
else
{
int pieceTableSize = LittleEndian.getInt(tableStream, ++offset);
offset += LittleEndian.INT_SIZE;
_tpt = new TextPieceTable(documentStream, tableStream, offset, pieceTableSize, fcMin);
}
}
public TextPieceTable getTextPieceTable()
{
return _tpt;
}
public void writeTo(HWPFFileSystem sys)
throws IOException
{
HWPFOutputStream docStream = sys.getStream("WordDocument");
HWPFOutputStream tableStream = sys.getStream("1Table");
tableStream.write(TEXT_PIECE_TABLE_TYPE);
byte[] table = _tpt.writeTo(docStream);
byte[] numHolder = new byte[LittleEndian.INT_SIZE];
LittleEndian.putInt(numHolder, table.length);
tableStream.write(numHolder);
tableStream.write(table);
}
}

View File

@ -1,3 +1,5 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
@ -52,21 +54,24 @@
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.*;
package org.apache.poi.hwpf.model;
import java.util.List;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.types.DOPAbstractType;
public class ParagraphRange extends Range
/**
* Comment me
*
* @author Ryan Ackley
*/
public class DocumentProperties extends DOPAbstractType
{
public ParagraphRange(int start, int end, HWPFDocument doc)
{
super(start, end, doc);
}
public ParagraphRange(int start, int end, Range parent)
{
super(start, end, parent);
}
public DocumentProperties(byte[] tableStream, int offset)
{
super.fillFields(tableStream, offset);
}
}

View File

@ -0,0 +1,200 @@
package org.apache.poi.hwpf.model;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Arrays;
import java.io.IOException;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
import org.apache.poi.util.LittleEndian;
public class FIBFieldHandler
{
public static final int STSHFORIG = 0;
public static final int STSHF = 1;
public static final int PLCFFNDREF = 2;
public static final int PLCFFNDTXT = 3;
public static final int PLCFANDREF = 4;
public static final int PLCFANDTXT = 5;
public static final int PLCFSED = 6;
public static final int PLCFPAD = 7;
public static final int PLCFPHE = 8;
public static final int STTBGLSY = 9;
public static final int PLCFGLSY = 10;
public static final int PLCFHDD = 11;
public static final int PLCFBTECHPX = 12;
public static final int PLCFBTEPAPX = 13;
public static final int PLCFSEA = 14;
public static final int STTBFFFN = 15;
public static final int PLCFFLDMOM = 16;
public static final int PLCFFLDHDR = 17;
public static final int PLCFFLDFTN = 18;
public static final int PLCFFLDATN = 19;
public static final int PLCFFLDMCR = 20;
public static final int STTBFBKMK = 21;
public static final int PLCFBKF = 22;
public static final int PLCFBKL = 23;
public static final int CMDS = 24;
public static final int PLCMCR = 25;
public static final int STTBFMCR = 26;
public static final int PRDRVR = 27;
public static final int PRENVPORT = 28;
public static final int PRENVLAND = 29;
public static final int WSS = 30;
public static final int DOP = 31;
public static final int STTBFASSOC = 32;
public static final int CLX = 33;
public static final int PLCFPGDFTN = 34;
public static final int AUTOSAVESOURCE = 35;
public static final int GRPXSTATNOWNERS = 36;//validated
public static final int STTBFATNBKMK = 37;
public static final int PLCFDOAMOM = 38;
public static final int PLCDOAHDR = 39;
public static final int PLCSPAMOM = 40;
public static final int PLCSPAHDR = 41;
public static final int PLCFATNBKF = 42;
public static final int PLCFATNBKL = 43;
public static final int PMS = 44;
public static final int FORMFLDSTTBS = 45;
public static final int PLCFENDREF = 46;
public static final int PLCFENDTXT = 47;
public static final int PLCFFLDEDN = 48;
public static final int PLCFPGDEDN = 49;
public static final int DGGINFO = 50;
public static final int STTBFRMARK = 51;
public static final int STTBCAPTION = 52;
public static final int STTBAUTOCAPTION = 53;
public static final int PLCFWKB = 54;
public static final int PLCFSPL = 55;
public static final int PLCFTXBXTXT = 56;
public static final int PLCFFLDTXBX = 57;//validated
public static final int PLCFHDRTXBXTXT = 58;
public static final int PLCFFLDHDRTXBX = 59;
public static final int STWUSER = 60;
public static final int STTBTTMBD = 61;
public static final int UNUSED = 62;
public static final int PGDMOTHER = 63;
public static final int BKDMOTHER = 64;
public static final int PGDFTN = 65;
public static final int BKDFTN = 66;
public static final int PGDEDN = 67;
public static final int BKDEDN = 68;
public static final int STTBFINTFLD = 69;
public static final int ROUTESLIP = 70;
public static final int STTBSAVEDBY = 71;
public static final int STTBFNM = 72;
public static final int PLCFLST = 73;
public static final int PLFLFO = 74;
public static final int PLCFTXBXBKD = 75;//validated
public static final int PLCFTXBXHDRBKD = 76;
public static final int DOCUNDO = 77;
public static final int RGBUSE = 78;
public static final int USP = 79;
public static final int USKF = 80;
public static final int PLCUPCRGBUSE = 81;
public static final int PLCUPCUSP = 82;
public static final int STTBGLSYSTYLE = 83;
public static final int PLGOSL = 84;
public static final int PLCOCX = 85;
public static final int PLCFBTELVC = 86;
public static final int MODIFIED = 87;
public static final int PLCFLVC = 88;
public static final int PLCASUMY = 89;
public static final int PLCFGRAM = 90;
public static final int STTBLISTNAMES = 91;
public static final int STTBFUSSR = 92;
private static final int FIELD_SIZE = LittleEndian.INT_SIZE * 2;
private HashMap _unknownMap = new HashMap();
private int[] _fields;
public FIBFieldHandler(byte[] mainStream, int offset, byte[] tableStream,
HashSet offsetList, boolean areKnown)
{
int numFields = LittleEndian.getShort(mainStream, offset);
offset += LittleEndian.SHORT_SIZE;
_fields = new int[numFields * 2];
for (int x = 0; x < numFields; x++)
{
int fieldOffset = (x * FIELD_SIZE) + offset;
int dsOffset = LittleEndian.getInt(mainStream, fieldOffset);
fieldOffset += LittleEndian.INT_SIZE;
int dsSize = LittleEndian.getInt(mainStream, fieldOffset);
if (offsetList.contains(new Integer(x)) ^ areKnown)
{
if (dsSize > 0)
{
UnhandledDataStructure unhandled = new UnhandledDataStructure(
tableStream, dsOffset, dsSize);
_unknownMap.put(new Integer(x), unhandled);
}
}
_fields[x*2] = dsOffset;
_fields[(x*2) + 1] = dsSize;
}
}
public void clearFields()
{
Arrays.fill(_fields, 0);
}
public int getFieldOffset(int field)
{
return _fields[field*2];
}
public int getFieldSize(int field)
{
return _fields[(field*2) + 1];
}
public void setFieldOffset(int field, int offset)
{
_fields[field*2] = offset;
}
public void setFieldSize(int field, int size)
{
_fields[(field*2) + 1] = size;
}
public int sizeInBytes()
{
return (_fields.length * LittleEndian.INT_SIZE) + LittleEndian.SHORT_SIZE;
}
void writeTo(byte[] mainStream, int offset, HWPFOutputStream tableStream)
throws IOException
{
int length = _fields.length/2;
LittleEndian.putShort(mainStream, offset, (short)length);
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < length; x++)
{
UnhandledDataStructure ds = (UnhandledDataStructure)_unknownMap.get(new Integer(x));
if (ds != null)
{
LittleEndian.putInt(mainStream, offset, tableStream.getOffset());
offset += LittleEndian.INT_SIZE;
byte[] buf = ds.getBuf();
tableStream.write(buf);
LittleEndian.putInt(mainStream, offset, buf.length);
offset += LittleEndian.INT_SIZE;
}
else
{
LittleEndian.putInt(mainStream, offset, _fields[x * 2]);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(mainStream, offset, _fields[(x * 2) + 1]);
offset += LittleEndian.INT_SIZE;
}
}
}
}

View File

@ -0,0 +1,82 @@
package org.apache.poi.hwpf.model;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
public class FIBLongHandler
{
public static final int CBMAC = 0;
public static final int PRODUCTCREATED = 1;
public static final int PRODUCTREVISED = 2;
public static final int CCPTEXT = 3;
public static final int CCPFTN = 4;
public static final int CCPHDD = 5;
public static final int CCPMCR = 6;
public static final int CCPATN = 7;
public static final int CCPEDN = 8;
public static final int CCPTXBX = 9;
public static final int CCPHDRTXBX = 10;
public static final int PNFBPCHPFIRST = 11;
public static final int PNCHPFIRST = 12;
public static final int CPNBTECHP = 13;
public static final int PNFBPPAPFIRST = 14;
public static final int PNPAPFIRST = 15;
public static final int CPNBTEPAP = 16;
public static final int PNFBPLVCFIRST = 17;
public static final int PNLVCFIRST = 18;
public static final int CPNBTELVC = 19;
public static final int FCISLANDFIRST = 20;
public static final int FCISLANDLIM = 21;
int[] _longs;
public FIBLongHandler(byte[] mainStream, int offset)
{
int longCount = LittleEndian.getShort(mainStream, offset);
offset += LittleEndian.SHORT_SIZE;
_longs = new int[longCount];
for (int x = 0; x < longCount; x++)
{
_longs[x] = LittleEndian.getInt(mainStream, offset + (x * LittleEndian.INT_SIZE));
}
}
/**
* Refers to a 32 bit windows "long" same as a Java int
* @param longCode
* @return
*/
public int getLong(int longCode)
{
return _longs[longCode];
}
public void setLong(int longCode, int value)
{
_longs[longCode] = value;
}
void serialize(byte[] mainStream, int offset)
throws IOException
{
LittleEndian.putShort(mainStream, offset, (short)_longs.length);
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < _longs.length; x++)
{
LittleEndian.putInt(mainStream, offset, _longs[x]);
offset += LittleEndian.INT_SIZE;
}
}
int sizeInBytes()
{
return (_longs.length * LittleEndian.INT_SIZE) + LittleEndian.SHORT_SIZE;
}
}

View File

@ -0,0 +1,61 @@
package org.apache.poi.hwpf.model;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
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)
throws IOException
{
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;
}
}
}

View File

@ -0,0 +1,267 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import java.util.Arrays;
/**
* FFN - Font Family Name. FFN is a data structure that stores the names of the Main
* Font and that of Alternate font as an array of characters. It has also a header
* that stores info about the whole structure and the fonts
*
* @author Praveen Mathew
*/
public class Ffn
{
private int field_1_cbFfnM1;//total length of FFN - 1.
private byte field_2;
private static BitField _prq = new BitField(0x0003);// pitch request
private static BitField _fTrueType = new BitField(0x0004);// when 1, font is a TrueType font
private static BitField _ff = new BitField(0x0070);
private short field_3_wWeight;// base weight of font
private byte field_4_chs;// character set identifier
private byte field_5_ixchSzAlt; // index into ffn.szFfn to the name of
// the alternate font
private byte [] field_6_panose = new byte[10];//????
private byte [] field_7_fontSig = new byte[24];//????
// zero terminated string that records name of font, cuurently not
// supporting Extended chars
private char [] field_8_xszFfn;
// extra facilitator members
private int xszFfnLength;
public Ffn(byte[] buf, int offset)
{
int offsetTmp = offset;
field_1_cbFfnM1 = LittleEndian.getUnsignedByte(buf,offset);
offset += LittleEndian.BYTE_SIZE;
field_2 = buf[offset];
offset += LittleEndian.BYTE_SIZE;
field_3_wWeight = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
field_4_chs = buf[offset];
offset += LittleEndian.BYTE_SIZE;
field_5_ixchSzAlt = buf[offset];
offset += LittleEndian.BYTE_SIZE;
// read panose and fs so we can write them back out.
System.arraycopy(buf, offset, field_6_panose, 0, field_6_panose.length);
offset += field_6_panose.length;
System.arraycopy(buf, offset, field_7_fontSig, 0, field_7_fontSig.length);
offset += field_7_fontSig.length;
offsetTmp = offset - offsetTmp;
xszFfnLength = this.getSize() - offsetTmp;
field_8_xszFfn = new char[xszFfnLength];
for(int i = 0; i < xszFfnLength; i++)
{
field_8_xszFfn[i] = (char)LittleEndian.getUnsignedByte(buf, offset);
offset += LittleEndian.BYTE_SIZE;
}
}
public int getField_1_cbFfnM1()
{
return field_1_cbFfnM1;
}
public byte getField_2()
{
return field_2;
}
public short getField_3_wWeight()
{
return field_3_wWeight;
}
public byte getField_4_chs()
{
return field_4_chs;
}
public byte getField_5_ixchSzAlt()
{
return field_5_ixchSzAlt;
}
public byte [] getField_6_panose()
{
return field_6_panose;
}
public byte [] getField_7_fontSig()
{
return field_7_fontSig;
}
public char [] getField_8_xszFfn()
{
return field_8_xszFfn;
}
public int getSize()
{
return (field_1_cbFfnM1 + 1);
}
public char [] getMainFontName()
{
char [] temp = new char[field_5_ixchSzAlt];
System.arraycopy(field_8_xszFfn,0,temp,0,temp.length);
return temp;
}
public char [] getAltFontName()
{
char [] temp = new char[xszFfnLength - field_5_ixchSzAlt];
System.arraycopy(field_8_xszFfn, field_5_ixchSzAlt, temp, 0, temp.length);
return temp;
}
public void setField_1_cbFfnM1(int field_1_cbFfnM1)
{
this.field_1_cbFfnM1 = field_1_cbFfnM1;
}
// changed protected to public
public byte[] toByteArray()
{
int offset = 0;
byte[] buf = new byte[this.getSize()];
buf[offset] = (byte)field_1_cbFfnM1;
offset += LittleEndian.BYTE_SIZE;
buf[offset] = field_2;
offset += LittleEndian.BYTE_SIZE;
LittleEndian.putShort(buf, offset, field_3_wWeight);
offset += LittleEndian.SHORT_SIZE;
buf[offset] = field_4_chs;
offset += LittleEndian.BYTE_SIZE;
buf[offset] = field_5_ixchSzAlt;
offset += LittleEndian.BYTE_SIZE;
System.arraycopy(field_6_panose,0,buf, offset,field_6_panose.length);
offset += field_6_panose.length;
System.arraycopy(field_7_fontSig,0,buf, offset, field_7_fontSig.length);
offset += field_7_fontSig.length;
for(int i = 0; i < field_8_xszFfn.length; i++)
{
buf[offset] = (byte)field_8_xszFfn[i];
offset += LittleEndian.BYTE_SIZE;
}
return buf;
}
public boolean equals(Object o)
{
boolean retVal = true;
if (((Ffn)o).getField_1_cbFfnM1() == field_1_cbFfnM1)
{
if(((Ffn)o).getField_2() == field_2)
{
if(((Ffn)o).getField_3_wWeight() == field_3_wWeight)
{
if(((Ffn)o).getField_4_chs() == field_4_chs)
{
if(((Ffn)o).getField_5_ixchSzAlt() == field_5_ixchSzAlt)
{
if(Arrays.equals(((Ffn)o).getField_6_panose(),field_6_panose))
{
if(Arrays.equals(((Ffn)o).getField_7_fontSig(),field_7_fontSig))
{
if(!(Arrays.equals(((Ffn)o).getField_8_xszFfn(),field_8_xszFfn)))
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
}
else
retVal = false;
return retVal;
}
}

View File

@ -0,0 +1,354 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.io.IOException;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
import org.apache.poi.hwpf.model.types.FIBAbstractType;
/**
*
* @author andy
*/
public class FileInformationBlock extends FIBAbstractType
implements Cloneable
{
FIBLongHandler _longHandler;
FIBShortHandler _shortHandler;
FIBFieldHandler _fieldHandler;
/** Creates a new instance of FileInformationBlock */
public FileInformationBlock(byte[] mainDocument)
{
fillFields(mainDocument, 0);
}
public void fillVariableFields(byte[] mainDocument, byte[] tableStream)
{
HashSet fieldSet = new HashSet();
fieldSet.add(new Integer(FIBFieldHandler.STSHF));
fieldSet.add(new Integer(FIBFieldHandler.CLX));
fieldSet.add(new Integer(FIBFieldHandler.DOP));
fieldSet.add(new Integer(FIBFieldHandler.PLCFBTECHPX));
fieldSet.add(new Integer(FIBFieldHandler.PLCFBTEPAPX));
fieldSet.add(new Integer(FIBFieldHandler.PLCFSED));
fieldSet.add(new Integer(FIBFieldHandler.PLCFLST));
fieldSet.add(new Integer(FIBFieldHandler.PLFLFO));
fieldSet.add(new Integer(FIBFieldHandler.STTBFFFN));
fieldSet.add(new Integer(FIBFieldHandler.MODIFIED));
_shortHandler = new FIBShortHandler(mainDocument);
_longHandler = new FIBLongHandler(mainDocument, _shortHandler.START + _shortHandler.sizeInBytes());
_fieldHandler = new FIBFieldHandler(mainDocument,
_shortHandler.START + _shortHandler.sizeInBytes() + _longHandler.sizeInBytes(),
tableStream, fieldSet, true);
}
public int getFcDop()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.DOP);
}
public void setFcDop(int fcDop)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.DOP, fcDop);
}
public int getLcbDop()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.DOP);
}
public void setLcbDop(int lcbDop)
{
_fieldHandler.setFieldSize(FIBFieldHandler.DOP, lcbDop);
}
public int getFcStshf()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.STSHF);
}
public int getLcbStshf()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.STSHF);
}
public void setFcStshf(int fcStshf)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.STSHF, fcStshf);
}
public void setLcbStshf(int lcbStshf)
{
_fieldHandler.setFieldSize(FIBFieldHandler.STSHF, lcbStshf);
}
public int getFcClx()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.CLX);
}
public int getLcbClx()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.CLX);
}
public void setFcClx(int fcClx)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.CLX, fcClx);
}
public void setLcbClx(int lcbClx)
{
_fieldHandler.setFieldSize(FIBFieldHandler.CLX, lcbClx);
}
public int getFcPlcfbteChpx()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFBTECHPX);
}
public int getLcbPlcfbteChpx()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTECHPX);
}
public void setFcPlcfbteChpx(int fcPlcfBteChpx)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTECHPX, fcPlcfBteChpx);
}
public void setLcbPlcfbteChpx(int lcbPlcfBteChpx)
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTECHPX, lcbPlcfBteChpx);
}
public int getFcPlcfbtePapx()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFBTEPAPX);
}
public int getLcbPlcfbtePapx()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFBTEPAPX);
}
public void setFcPlcfbtePapx(int fcPlcfBtePapx)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.PLCFBTEPAPX, fcPlcfBtePapx);
}
public void setLcbPlcfbtePapx(int lcbPlcfBtePapx)
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLCFBTEPAPX, lcbPlcfBtePapx);
}
public int getFcPlcfsed()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFSED);
}
public int getLcbPlcfsed()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFSED);
}
public void setFcPlcfsed(int fcPlcfSed)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.PLCFSED, fcPlcfSed);
}
public void setLcbPlcfsed(int lcbPlcfSed)
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLCFSED, lcbPlcfSed);
}
public int getFcPlcfLst()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLCFLST);
}
public int getLcbPlcfLst()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLCFLST);
}
public void setFcPlcfLst(int fcPlcfLst)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.PLCFLST, fcPlcfLst);
}
public void setLcbPlcfLst(int lcbPlcfLst)
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLCFLST, lcbPlcfLst);
}
public int getFcPlfLfo()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
}
public int getLcbPlfLfo()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
}
public void setFcPlfLfo(int fcPlfLfo)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, fcPlfLfo);
}
public void setLcbPlfLfo(int lcbPlfLfo)
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, lcbPlfLfo);
}
public int getFcSttbfffn()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.STTBFFFN);
}
public int getLcbSttbfffn()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.STTBFFFN);
}
public void setFcSttbfffn(int fcSttbFffn)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.STTBFFFN, fcSttbFffn);
}
public void setLcbSttbfffn(int lcbSttbFffn)
{
_fieldHandler.setFieldSize(FIBFieldHandler.STTBFFFN, lcbSttbFffn);
}
public int getModifiedLow()
{
return _fieldHandler.getFieldOffset(FIBFieldHandler.PLFLFO);
}
public int getModifiedHigh()
{
return _fieldHandler.getFieldSize(FIBFieldHandler.PLFLFO);
}
public void setModifiedLow(int modifiedLow)
{
_fieldHandler.setFieldOffset(FIBFieldHandler.PLFLFO, modifiedLow);
}
public void setModifiedHigh(int modifiedHigh)
{
_fieldHandler.setFieldSize(FIBFieldHandler.PLFLFO, modifiedHigh);
}
public void setCbMac(int cbMac)
{
_longHandler.setLong(FIBLongHandler.CBMAC, cbMac);
}
public void clearOffsetsSizes()
{
_fieldHandler.clearFields();
}
public void writeTo (byte[] mainStream, HWPFOutputStream tableStream)
throws IOException
{
//HWPFOutputStream mainDocument = sys.getStream("WordDocument");
//HWPFOutputStream tableStream = sys.getStream("1Table");
super.serialize(mainStream, 0);
int size = super.getSize();
_shortHandler.serialize(mainStream);
_longHandler.serialize(mainStream, size + _shortHandler.sizeInBytes());
_fieldHandler.writeTo(mainStream,
super.getSize() + _shortHandler.sizeInBytes() + _longHandler.sizeInBytes(), tableStream);
}
public int getSize()
{
return super.getSize() + _shortHandler.sizeInBytes() +
_longHandler.sizeInBytes() + _fieldHandler.sizeInBytes();
}
// public Object clone()
// {
// try
// {
// return super.clone();
// }
// catch (CloneNotSupportedException e)
// {
// e.printStackTrace();
// return null;
// }
// }
}

View File

@ -0,0 +1,196 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.IOException;
import org.apache.poi.hwpf.model.io.HWPFFileSystem;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
import org.apache.poi.util.LittleEndian;
/**
* FontTable or in MS terminology sttbfffn is a common data structure written in all
* Word files. The sttbfffn is an sttbf where each string is an FFN structure instead
* of pascal-style strings. An sttbf is a string Table stored in file. Thus sttbffn
* is like an Sttbf with an array of FFN structures that stores the font name strings
*
* @author Praveen Mathew
*/
public class FontTable
{
private short _stringCount;// how many strings are included in the string table
private short _extraDataSz;// size in bytes of the extra data
// added extra facilitator members
private int lcbSttbfffn;// count of bytes in sttbfffn
private int fcSttbfffn;// table stream offset for sttbfffn
// FFN structure containing strings of font names
private Ffn[] _fontNames = null;
public FontTable(byte[] buf, int offset, int lcbSttbfffn)
{
this.lcbSttbfffn = lcbSttbfffn;
this.fcSttbfffn = offset;
_stringCount = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
_extraDataSz = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
_fontNames = new Ffn[_stringCount]; //Ffn corresponds to a Pascal style String in STTBF.
for(int i = 0;i<_stringCount; i++)
{
_fontNames[i] = new Ffn(buf,offset);
offset += _fontNames[i].getSize();
}
}
public short getStringCount()
{
return _stringCount;
}
public short getExtraDataSz()
{
return _extraDataSz;
}
public Ffn[] getFontNames()
{
return _fontNames;
}
public int getSize()
{
return lcbSttbfffn;
}
public char [] getMainFont(int chpFtc )
{
if(chpFtc >= _stringCount)
{
System.out.println("Mismatch in chpFtc with stringCount");
return null;
}
return _fontNames[chpFtc].getMainFontName();
}
public char [] getAltFont(int chpFtc )
{
if(chpFtc >= _stringCount)
{
System.out.println("Mismatch in chpFtc with stringCount");
return null;
}
return _fontNames[chpFtc].getAltFontName();
}
public void setStringCount(short stringCount)
{
this._stringCount = stringCount;
}
public void writeTo(HWPFFileSystem sys)
throws IOException
{
HWPFOutputStream tableStream = sys.getStream("1Table");
byte[] buf = new byte[LittleEndian.SHORT_SIZE];
LittleEndian.putShort(buf, _stringCount);
tableStream.write(buf);
LittleEndian.putShort(buf, _extraDataSz);
tableStream.write(buf);
for(int i = 0; i < _fontNames.length; i++)
{
tableStream.write(_fontNames[i].toByteArray());
}
}
public boolean equals(Object o)
{
boolean retVal = true;
if(((FontTable)o).getStringCount() == _stringCount)
{
if(((FontTable)o).getExtraDataSz() == _extraDataSz)
{
Ffn[] fontNamesNew = ((FontTable)o).getFontNames();
for(int i = 0;i<_stringCount; i++)
{
if(!(_fontNames[i].equals(fontNamesNew[i])))
retVal = false;
}
}
else
retVal = false;
}
else
retVal = false;
return retVal;
}
}

View File

@ -0,0 +1,128 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
/**
* Represents an FKP data structure. This data structure is used to store the
* grpprls of the paragraph and character properties of the document. A grpprl
* is a list of sprms(decompression operations) to perform on a parent style.
*
* The style properties for paragraph and character runs
* are stored in fkps. There are PAP fkps for paragraph properties and CHP fkps
* for character run properties. The first part of the fkp for both CHP and PAP
* fkps consists of an array of 4 byte int offsets in the main stream for that
* Paragraph's or Character run's text. The ending offset is the next
* value in the array. For example, if an fkp has X number of Paragraph's
* stored in it then there are (x + 1) 4 byte ints in the beginning array. The
* number X is determined by the last byte in a 512 byte fkp.
*
* CHP and PAP fkps also store the compressed styles(grpprl) that correspond to
* the offsets on the front of the fkp. The offset of the grpprls is determined
* differently for CHP fkps and PAP fkps.
*
* @author Ryan Ackley
*/
public abstract class FormattedDiskPage
{
protected byte[] _fkp;
protected int _crun;
protected int _offset;
public FormattedDiskPage()
{
}
/**
* Uses a 512-byte array to create a FKP
*/
public FormattedDiskPage(byte[] documentStream, int offset)
{
_crun = LittleEndian.getUnsignedByte(documentStream, offset + 511);
_fkp = documentStream;
_offset = offset;
}
/**
* Used to get a text offset corresponding to a grpprl in this fkp.
* @param index The index of the property in this FKP
* @return an int representing an offset in the "WordDocument" stream
*/
protected int getStart(int index)
{
return LittleEndian.getInt(_fkp, _offset + (index * 4));
}
/**
* Used to get the end of the text corresponding to a grpprl in this fkp.
* @param index The index of the property in this fkp.
* @return an int representing an offset in the "WordDocument" stream
*/
protected int getEnd(int index)
{
return LittleEndian.getInt(_fkp, _offset + ((index + 1) * 4));
}
/**
* Used to get the total number of grrprl's stored int this FKP
* @return The number of grpprls in this FKP
*/
public int size()
{
return _crun;
}
protected abstract byte[] getGrpprl(int index);
}

View File

@ -0,0 +1,17 @@
package org.apache.poi.hwpf.model;
public class GenericPropertyNode
extends PropertyNode
{
public GenericPropertyNode(int start, int end, byte[] buf)
{
super(start, end, buf);
}
protected byte[] getBytes()
{
return (byte[])_buf;
}
}

View File

@ -0,0 +1,16 @@
/*
* HDFType.java
*
* Created on February 24, 2002, 2:37 PM
*/
package org.apache.poi.hwpf.model;
/**
*
* @author andy
*/
public interface HDFType {
}

View File

@ -0,0 +1,193 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import java.util.Arrays;
public class ListData
{
private int _lsid;
private int _tplc;
private short[] _rgistd;
private byte _info;
private static BitField _fSimpleList = new BitField(0x1);
private static BitField _fRestartHdn = new BitField(0x2);
private byte _reserved;
ListLevel[] _levels;
public ListData(int listID, boolean numbered)
{
_lsid = listID;
_rgistd = new short[9];
for (int x = 0; x < 9; x++)
{
_rgistd[x] = StyleSheet.NIL_STYLE;
}
_levels = new ListLevel[9];
for (int x = 0; x < _levels.length; x++)
{
_levels[x] = new ListLevel(x, numbered);
}
}
ListData(byte[] buf, int offset)
{
_lsid = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_tplc = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_rgistd = new short[9];
for (int x = 0; x < 9; x++)
{
_rgistd[x] = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
}
_info = buf[offset++];
_reserved = buf[offset];
if (_fSimpleList.getValue(_info) > 0)
{
_levels = new ListLevel[1];
}
else
{
_levels = new ListLevel[9];
}
}
public int getLsid()
{
return _lsid;
}
public int numLevels()
{
return _levels.length;
}
public void setLevel(int index, ListLevel level)
{
_levels[index] = level;
}
public ListLevel[] getLevels()
{
return _levels;
}
/**
* Gets the level associated to a particular List at a particular index.
*
* @param index 1-based index
* @return a list level
*/
public ListLevel getLevel(int index)
{
return _levels[index - 1];
}
public int getLevelStyle(int index)
{
return _rgistd[index];
}
public void setLevelStyle(int index, int styleIndex)
{
_rgistd[index] = (short)styleIndex;
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
ListData lst = (ListData)obj;
return lst._info == _info && Arrays.equals(lst._levels, _levels) &&
lst._lsid == _lsid && lst._reserved == _reserved && lst._tplc == _tplc &&
Arrays.equals(lst._rgistd, _rgistd);
}
int resetListID()
{
_lsid = (int)(Math.random() * (double)System.currentTimeMillis());
return _lsid;
}
public byte[] toByteArray()
{
byte[] buf = new byte[28];
int offset = 0;
LittleEndian.putInt(buf, _lsid);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _tplc);
offset += LittleEndian.INT_SIZE;
for (int x = 0; x < 9; x++)
{
LittleEndian.putShort(buf, offset, _rgistd[x]);
offset += LittleEndian.SHORT_SIZE;
}
buf[offset++] = _info;
buf[offset] = _reserved;
return buf;
}
}

View File

@ -0,0 +1,158 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
import java.util.Arrays;
public class ListFormatOverride
{
int _lsid;
int _reserved1;
int _reserved2;
byte _clfolvl;
byte[] _reserved3 = new byte[3];
ListFormatOverrideLevel[] _levelOverrides;
public ListFormatOverride(int lsid)
{
_lsid = lsid;
_levelOverrides = new ListFormatOverrideLevel[0];
}
public ListFormatOverride(byte[] buf, int offset)
{
_lsid = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_reserved1 = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_reserved2 = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_clfolvl = buf[offset++];
System.arraycopy(buf, offset, _reserved3, 0, _reserved3.length);
_levelOverrides = new ListFormatOverrideLevel[_clfolvl];
}
public int numOverrides()
{
return _clfolvl;
}
public int getLsid()
{
return _lsid;
}
void setLsid(int lsid)
{
_lsid = lsid;
}
public ListFormatOverrideLevel[] getLevelOverrides()
{
return _levelOverrides;
}
public void setOverride(int index, ListFormatOverrideLevel lfolvl)
{
_levelOverrides[index] = lfolvl;
}
public ListFormatOverrideLevel getOverrideLevel(int level)
{
ListFormatOverrideLevel retLevel = null;
for(int x = 0; x < _levelOverrides.length; x++)
{
if (_levelOverrides[x].getLevelNum() == level)
{
retLevel = _levelOverrides[x];
}
}
return retLevel;
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
ListFormatOverride lfo = (ListFormatOverride)obj;
return lfo._clfolvl == _clfolvl && lfo._lsid == _lsid &&
lfo._reserved1 == _reserved1 && lfo._reserved2 == _reserved2 &&
Arrays.equals(lfo._reserved3, _reserved3) &&
Arrays.equals(lfo._levelOverrides, _levelOverrides);
}
public byte[] toByteArray()
{
byte[] buf = new byte[16];
int offset = 0;
LittleEndian.putInt(buf, offset, _lsid);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _reserved1);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _reserved2);
offset += LittleEndian.INT_SIZE;
buf[offset++] = _clfolvl;
System.arraycopy(_reserved3, 0, buf, offset, 3);
return buf;
}
}

View File

@ -0,0 +1,148 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import java.util.Arrays;
public class ListFormatOverrideLevel
{
private static final int BASE_SIZE = 8;
int _iStartAt;
byte _info;
private static BitField _ilvl = new BitField(0xf);
private static BitField _fStartAt = new BitField(0x10);
private static BitField _fFormatting = new BitField(0x20);
byte[] _reserved = new byte[3];
ListLevel _lvl;
public ListFormatOverrideLevel(byte[] buf, int offset)
{
while(buf[offset] == -1)
{
offset++;
}
_iStartAt = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_info = buf[offset++];
System.arraycopy(buf, offset, _reserved, 0, _reserved.length);
offset += _reserved.length;
if (_fFormatting.getValue(_info) > 0)
{
_lvl = new ListLevel(buf, offset);
}
}
public ListLevel getLevel()
{
return _lvl;
}
public int getLevelNum()
{
return _ilvl.getValue(_info);
}
public boolean isFormatting()
{
return _fFormatting.getValue(_info) != 0;
}
public boolean isStartAt()
{
return _fStartAt.getValue(_info) != 0;
}
public int getSizeInBytes()
{
return (_lvl == null ? BASE_SIZE : BASE_SIZE + _lvl.getSizeInBytes());
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
ListFormatOverrideLevel lfolvl = (ListFormatOverrideLevel)obj;
return lfolvl._iStartAt == _iStartAt && lfolvl._info == _info &&
lfolvl._lvl.equals(_lvl) && Arrays.equals(lfolvl._reserved, _reserved);
}
public byte[] toByteArray()
{
byte[] buf = new byte[getSizeInBytes()];
int offset = 0;
LittleEndian.putInt(buf, _iStartAt);
offset += LittleEndian.INT_SIZE;
buf[offset++] = _info;
System.arraycopy(_reserved, 0, buf, offset, 3);
offset += 3;
if (_lvl != null)
{
byte[] levelBuf = _lvl.toByteArray();
System.arraycopy(levelBuf, 0, buf, offset, levelBuf.length);
}
return buf;
}
}

View File

@ -0,0 +1,268 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
import java.util.Arrays;
public class ListLevel
{
private int _iStartAt;
private byte _nfc;
private byte _info;
private static BitField _jc;
private static BitField _fLegal;
private static BitField _fNoRestart;
private static BitField _fPrev;
private static BitField _fPrevSpace;
private static BitField _fWord6;
private byte[] _rgbxchNums;
private byte _ixchFollow;
private int _dxaSpace;
private int _dxaIndent;
private int _cbGrpprlChpx;
private int _cbGrpprlPapx;
private short _reserved;
private byte[] _grpprlPapx;
private byte[] _grpprlChpx;
private char[] _numberText;
public ListLevel(int startAt, int numberFormatCode, int alignment,
byte[] numberProperties, byte[] entryProperties,
String numberText)
{
_iStartAt = startAt;
_nfc = (byte)numberFormatCode;
_jc.setValue(_info, alignment);
_grpprlChpx = numberProperties;
_grpprlPapx = entryProperties;
_numberText = numberText.toCharArray();
}
public ListLevel(int level, boolean numbered)
{
_iStartAt = 1;
_grpprlPapx = new byte[0];
_grpprlChpx = new byte[0];
_numberText = new char[0];
_rgbxchNums = new byte[9];
if (numbered)
{
_rgbxchNums[0] = 1;
_numberText = new char[]{(char)level, '.'};
}
else
{
_numberText = new char[]{'\u2022'};
}
}
public ListLevel(byte[] buf, int offset)
{
_iStartAt = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_nfc = buf[offset++];
_info = buf[offset++];
_rgbxchNums = new byte[9];
for (int x = 0; x < 9; x++)
{
_rgbxchNums[x] = buf[offset++];
}
_ixchFollow = buf[offset++];
_dxaSpace = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_dxaIndent = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_cbGrpprlChpx = LittleEndian.getUnsignedByte(buf, offset++);
_cbGrpprlPapx = LittleEndian.getUnsignedByte(buf, offset++);
_reserved = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
_grpprlPapx = new byte[_cbGrpprlPapx];
_grpprlChpx = new byte[_cbGrpprlChpx];
System.arraycopy(buf, offset, _grpprlChpx, 0, _cbGrpprlChpx);
offset += _cbGrpprlChpx;
System.arraycopy(buf, offset, _grpprlPapx, 0, _cbGrpprlPapx);
offset += _cbGrpprlPapx;
int numberTextLength = LittleEndian.getShort(buf, offset);
_numberText = new char[numberTextLength];
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < numberTextLength; x++)
{
_numberText[x] = (char)LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
}
}
public int getStartAt()
{
return _iStartAt;
}
public int getNumberFormat()
{
return _nfc;
}
public int getAlignment()
{
return _jc.getValue(_info);
}
public String getNumberText()
{
return new String(_numberText);
}
public void setStartAt(int startAt)
{
_iStartAt = startAt;
}
public void setNumberFormat(int numberFormatCode)
{
_nfc = (byte)numberFormatCode;
}
public void setAlignment(int alignment)
{
_jc.setValue(_info, alignment);
}
public void setNumberProperties(byte[] grpprl)
{
_grpprlChpx = grpprl;
}
public void setLevelProperties(byte[] grpprl)
{
_grpprlPapx = grpprl;
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
ListLevel lvl = (ListLevel)obj;
return _cbGrpprlChpx == lvl._cbGrpprlChpx && lvl._cbGrpprlPapx == _cbGrpprlPapx &&
lvl._dxaIndent == _dxaIndent && lvl._dxaSpace == _dxaSpace &&
Arrays.equals(lvl._grpprlChpx, _grpprlChpx) &&
Arrays.equals(lvl._grpprlPapx, _grpprlPapx) &&
lvl._info == _info && lvl._iStartAt == _iStartAt &&
lvl._ixchFollow == _ixchFollow && lvl._nfc == _nfc &&
Arrays.equals(lvl._numberText, _numberText) &&
Arrays.equals(lvl._rgbxchNums, _rgbxchNums) &&
lvl._reserved == _reserved;
}
public byte[] toByteArray()
{
byte[] buf = new byte[getSizeInBytes()];
int offset = 0;
LittleEndian.putInt(buf, offset, _iStartAt);
offset += LittleEndian.INT_SIZE;
buf[offset++] = _nfc;
buf[offset++] = _info;
System.arraycopy(_rgbxchNums, 0, buf, offset, _rgbxchNums.length);
offset += _rgbxchNums.length;
buf[offset++] = _ixchFollow;
LittleEndian.putInt(buf, offset, _dxaSpace);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _dxaIndent);
offset += LittleEndian.INT_SIZE;
buf[offset++] = (byte)_cbGrpprlChpx;
buf[offset++] = (byte)_cbGrpprlPapx;
LittleEndian.putShort(buf, offset, _reserved);
offset += LittleEndian.SHORT_SIZE;
System.arraycopy(_grpprlChpx, 0, buf, offset, _cbGrpprlChpx);
offset += _cbGrpprlChpx;
System.arraycopy(_grpprlPapx, 0, buf, offset, _cbGrpprlPapx);
offset += _cbGrpprlPapx;
LittleEndian.putShort(buf, offset, (short)_numberText.length);
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < _numberText.length; x++)
{
LittleEndian.putShort(buf, offset, (short)_numberText[x]);
offset += LittleEndian.SHORT_SIZE;
}
return buf;
}
public int getSizeInBytes()
{
return 28 + _cbGrpprlChpx + _cbGrpprlPapx + (_numberText.length * LittleEndian.SHORT_SIZE) + 2;
}
}

View File

@ -0,0 +1,262 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class ListTables
{
private static final int LIST_DATA_SIZE = 28;
private static final int LIST_FORMAT_OVERRIDE_SIZE = 16;
HashMap _listMap = new HashMap();
ArrayList _overrideList = new ArrayList();
public ListTables()
{
}
public ListTables(byte[] tableStream, int lstOffset, int lfoOffset)
{
// get the list data
int length = LittleEndian.getShort(tableStream, lstOffset);
lstOffset += LittleEndian.SHORT_SIZE;
int levelOffset = lstOffset + (length * LIST_DATA_SIZE);
for (int x = 0; x < length; x++)
{
ListData lst = new ListData(tableStream, lstOffset);
_listMap.put(new Integer(lst.getLsid()), lst);
lstOffset += LIST_DATA_SIZE;
int num = lst.numLevels();
for (int y = 0; y < num; y++)
{
ListLevel lvl = new ListLevel(tableStream, levelOffset);
lst.setLevel(y, lvl);
levelOffset += lvl.getSizeInBytes();
}
}
// now get the list format overrides. The size is an int unlike the LST size
length = LittleEndian.getInt(tableStream, lfoOffset);
lfoOffset += LittleEndian.INT_SIZE;
int lfolvlOffset = lfoOffset + (LIST_FORMAT_OVERRIDE_SIZE * length);
for (int x = 0; x < length; x++)
{
ListFormatOverride lfo = new ListFormatOverride(tableStream, lfoOffset);
lfoOffset += LIST_FORMAT_OVERRIDE_SIZE;
int num = lfo.numOverrides();
for (int y = 0; y < num; y++)
{
ListFormatOverrideLevel lfolvl = new ListFormatOverrideLevel(tableStream, lfolvlOffset);
lfo.setOverride(y, lfolvl);
lfolvlOffset += lfolvl.getSizeInBytes();
}
_overrideList.add(lfo);
}
}
public int addList(ListData lst, ListFormatOverride override)
{
int lsid = lst.getLsid();
while (_listMap.get(new Integer(lsid)) != null)
{
lsid = lst.resetListID();
override.setLsid(lsid);
}
_listMap.put(new Integer(lsid), lst);
_overrideList.add(override);
return lsid;
}
public void writeListDataTo(HWPFOutputStream tableStream)
throws IOException
{
Integer[] intList = (Integer[])_listMap.keySet().toArray(new Integer[0]);
// use this stream as a buffer for the levels since their size varies.
ByteArrayOutputStream levelBuf = new ByteArrayOutputStream();
// use a byte array for the lists because we know their size.
byte[] listBuf = new byte[intList.length * LIST_DATA_SIZE];
byte[] shortHolder = new byte[2];
LittleEndian.putShort(shortHolder, (short)intList.length);
tableStream.write(shortHolder);
for (int x = 0; x < intList.length; x++)
{
ListData lst = (ListData)_listMap.get(intList[x]);
tableStream.write(lst.toByteArray());
ListLevel[] lvls = lst.getLevels();
for (int y = 0; y < lvls.length; y++)
{
levelBuf.write(lvls[y].toByteArray());
}
}
tableStream.write(levelBuf.toByteArray());
}
public void writeListOverridesTo(HWPFOutputStream tableStream)
throws IOException
{
// use this stream as a buffer for the levels since their size varies.
ByteArrayOutputStream levelBuf = new ByteArrayOutputStream();
int size = _overrideList.size();
byte[] intHolder = new byte[4];
LittleEndian.putInt(intHolder, size);
tableStream.write(intHolder);
for (int x = 0; x < size; x++)
{
ListFormatOverride lfo = (ListFormatOverride)_overrideList.get(x);
tableStream.write(lfo.toByteArray());
ListFormatOverrideLevel[] lfolvls = lfo.getLevelOverrides();
for (int y = 0; y < lfolvls.length; y++)
{
levelBuf.write(lfolvls[y].toByteArray());
}
}
tableStream.write(levelBuf.toByteArray());
}
public ListFormatOverride getOverride(int lfoIndex)
{
return (ListFormatOverride)_overrideList.get(lfoIndex - 1);
}
public int getOverrideIndexFromListID(int lstid)
{
int returnVal = -1;
int size = _overrideList.size();
for (int x = 0; x < size; x++)
{
ListFormatOverride next = (ListFormatOverride)_overrideList.get(x);
if (next.getLsid() == lstid)
{
// 1-based index I think
returnVal = x+1;
break;
}
}
if (returnVal == -1)
{
throw new NoSuchElementException("No list found with the specified ID");
}
return returnVal;
}
public ListLevel getLevel(int listID, int level)
{
ListData lst = (ListData)_listMap.get(new Integer(listID));
ListLevel lvl = lst.getLevels()[level];
return lvl;
}
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
ListTables tables = (ListTables)obj;
if (_listMap.size() == tables._listMap.size())
{
Iterator it = _listMap.keySet().iterator();
while (it.hasNext())
{
Object key = it.next();
ListData lst1 = (ListData)_listMap.get(key);
ListData lst2 = (ListData)tables._listMap.get(key);
if (!lst1.equals(lst2))
{
return false;
}
}
int size = _overrideList.size();
if (size == tables._overrideList.size())
{
for (int x = 0; x < size; x++)
{
if (!_overrideList.get(x).equals(tables._overrideList.get(x)))
{
return false;
}
}
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,247 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.util.ArrayList;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.hwpf.model.io.*;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.LittleEndian;
public class PAPBinTable
{
ArrayList _paragraphs = new ArrayList();
public PAPBinTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin)
{
PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4);
int length = binTable.length();
for (int x = 0; x < length; x++)
{
GenericPropertyNode node = binTable.getProperty(x);
int pageNum = LittleEndian.getInt(node.getBytes());
int pageOffset = POIFSConstants.BIG_BLOCK_SIZE * pageNum;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream,
pageOffset, fcMin);
int fkpSize = pfkp.size();
for (int y = 0; y < fkpSize; y++)
{
_paragraphs.add(pfkp.getPAPX(y));
}
}
}
public void insert(int listIndex, int cpStart, SprmBuffer buf)
{
PAPX forInsert = new PAPX(cpStart, cpStart, buf);
if (listIndex == _paragraphs.size())
{
_paragraphs.add(forInsert);
}
else
{
PAPX currentPap = (PAPX)_paragraphs.get(listIndex);
if (currentPap != null && currentPap.getStart() < cpStart)
{
SprmBuffer clonedBuf = null;
try
{
clonedBuf = (SprmBuffer)currentPap.getSprmBuf().clone();
}
catch (CloneNotSupportedException exc)
{
exc.printStackTrace();
}
currentPap.setEnd(cpStart);
PAPX splitPap = new PAPX(cpStart, currentPap.getEnd(), clonedBuf);
_paragraphs.add(++listIndex, forInsert);
_paragraphs.add(++listIndex, splitPap);
}
else
{
_paragraphs.add(listIndex, forInsert);
}
}
}
public void adjustForDelete(int listIndex, int offset, int length)
{
int size = _paragraphs.size();
int endMark = offset + length;
int endIndex = listIndex;
PAPX papx = (PAPX)_paragraphs.get(endIndex);
while (papx.getEnd() < endMark)
{
papx = (PAPX)_paragraphs.get(++endIndex);
}
if (listIndex == endIndex)
{
papx = (PAPX)_paragraphs.get(endIndex);
papx.setEnd((papx.getEnd() - endMark) + offset);
}
else
{
papx = (PAPX)_paragraphs.get(listIndex);
papx.setEnd(offset);
for (int x = listIndex + 1; x < endIndex; x++)
{
papx = (PAPX)_paragraphs.get(x);
papx.setStart(offset);
papx.setEnd(offset);
}
papx = (PAPX)_paragraphs.get(endIndex);
papx.setEnd((papx.getEnd() - endMark) + offset);
}
for (int x = endIndex + 1; x < size; x++)
{
papx = (PAPX)_paragraphs.get(x);
papx.setStart(papx.getStart() - length);
papx.setEnd(papx.getEnd() - length);
}
}
public void adjustForInsert(int listIndex, int length)
{
int size = _paragraphs.size();
PAPX papx = (PAPX)_paragraphs.get(listIndex);
papx.setEnd(papx.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
papx = (PAPX)_paragraphs.get(x);
papx.setStart(papx.getStart() + length);
papx.setEnd(papx.getEnd() + length);
}
}
public ArrayList getParagraphs()
{
return _paragraphs;
}
public void writeTo(HWPFFileSystem sys, int fcMin)
throws IOException
{
HWPFOutputStream docStream = sys.getStream("WordDocument");
OutputStream tableStream = sys.getStream("1Table");
PlexOfCps binTable = new PlexOfCps(4);
// each FKP must start on a 512 byte page.
int docOffset = docStream.getOffset();
int mod = docOffset % POIFSConstants.BIG_BLOCK_SIZE;
if (mod != 0)
{
byte[] padding = new byte[POIFSConstants.BIG_BLOCK_SIZE - mod];
docStream.write(padding);
}
// get the page number for the first fkp
docOffset = docStream.getOffset();
int pageNum = docOffset/POIFSConstants.BIG_BLOCK_SIZE;
// get the ending fc
int endingFc = ((PropertyNode)_paragraphs.get(_paragraphs.size() - 1)).getEnd();
endingFc += fcMin;
ArrayList overflow = _paragraphs;
do
{
PropertyNode startingProp = (PropertyNode)overflow.get(0);
int start = startingProp.getStart() + fcMin;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage();
pfkp.fill(overflow);
byte[] bufFkp = pfkp.toByteArray(fcMin);
docStream.write(bufFkp);
overflow = pfkp.getOverflow();
int end = endingFc;
if (overflow != null)
{
end = ((PropertyNode)overflow.get(0)).getStart() + fcMin;
}
byte[] intHolder = new byte[4];
LittleEndian.putInt(intHolder, pageNum++);
binTable.addProperty(new GenericPropertyNode(start, end, intHolder));
}
while (overflow != null);
tableStream.write(binTable.toByteArray());
}
}

View File

@ -0,0 +1,268 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.LittleEndian;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* Represents a PAP FKP. The style properties for paragraph and character runs
* are stored in fkps. There are PAP fkps for paragraph properties and CHP fkps
* for character run properties. The first part of the fkp for both CHP and PAP
* fkps consists of an array of 4 byte int offsets in the main stream for that
* Paragraph's or Character run's text. The ending offset is the next
* value in the array. For example, if an fkp has X number of Paragraph's
* stored in it then there are (x + 1) 4 byte ints in the beginning array. The
* number X is determined by the last byte in a 512 byte fkp.
*
* CHP and PAP fkps also store the compressed styles(grpprl) that correspond to
* the offsets on the front of the fkp. The offset of the grpprls is determined
* differently for CHP fkps and PAP fkps.
*
* @author Ryan Ackley
*/
public class PAPFormattedDiskPage extends FormattedDiskPage
{
private static final int BX_SIZE = 13;
private static final int FC_SIZE = 4;
private ArrayList _papxList = new ArrayList();
private ArrayList _overFlow;
public PAPFormattedDiskPage()
{
}
/**
* Creates a PAPFormattedDiskPage from a 512 byte array
*
* @param fkp a 512 byte array.
*/
public PAPFormattedDiskPage(byte[] documentStream, int offset, int fcMin)
{
super(documentStream, offset);
for (int x = 0; x < _crun; x++)
{
_papxList.add(new PAPX(getStart(x) - fcMin, getEnd(x) - fcMin, getGrpprl(x), getParagraphHeight(x)));
}
_fkp = null;
}
public void fill(List filler)
{
_papxList.addAll(filler);
}
public ArrayList getOverflow()
{
return _overFlow;
}
public PAPX getPAPX(int index)
{
return (PAPX)_papxList.get(index);
}
/**
* Gets the papx for the paragraph at index in this fkp.
*
* @param index The index of the papx to get.
* @return a papx grpprl.
*/
protected byte[] getGrpprl(int index)
{
int papxOffset = 2 * LittleEndian.getUnsignedByte(_fkp, _offset + (((_crun + 1) * FC_SIZE) + (index * BX_SIZE)));
int size = 2 * LittleEndian.getUnsignedByte(_fkp, _offset + papxOffset);
if(size == 0)
{
size = 2 * LittleEndian.getUnsignedByte(_fkp, _offset + ++papxOffset);
}
else
{
size--;
}
byte[] papx = new byte[size];
System.arraycopy(_fkp, _offset + ++papxOffset, papx, 0, size);
return papx;
}
protected byte[] toByteArray(int fcMin)
{
byte[] buf = new byte[512];
int size = _papxList.size();
int grpprlOffset = 0;
int bxOffset = 0;
int fcOffset = 0;
byte[] lastGrpprl = new byte[0];
// total size is currently the size of one FC
int totalSize = FC_SIZE;
int index = 0;
for (; index < size; index++)
{
byte[] grpprl = ((PAPX)_papxList.get(index)).getGrpprl();
int grpprlLength = grpprl.length;
// check to see if we have enough room for an FC, a BX, and the grpprl
// and the 1 byte size of the grpprl.
int addition = 0;
if (!Arrays.equals(grpprl, lastGrpprl))
{
addition = (FC_SIZE + BX_SIZE + grpprlLength + 1);
}
else
{
addition = (FC_SIZE + BX_SIZE);
}
totalSize += addition;
// if size is uneven we will have to add one so the first grpprl falls
// on a word boundary
if (totalSize > 511 + (index % 2))
{
totalSize -= addition;
break;
}
// grpprls must fall on word boundaries
if (grpprlLength % 2 > 0)
{
totalSize += 1;
}
else
{
totalSize += 2;
}
lastGrpprl = grpprl;
}
// see if we couldn't fit some
if (index != size)
{
_overFlow = new ArrayList();
_overFlow.addAll(_papxList.subList(index, size));
}
// index should equal number of papxs that will be in this fkp now.
buf[511] = (byte)index;
bxOffset = (FC_SIZE * index) + FC_SIZE;
grpprlOffset = 511;
PAPX papx = null;
lastGrpprl = new byte[0];
for (int x = 0; x < index; x++)
{
papx = (PAPX)_papxList.get(x);
byte[] phe = papx.getParagraphHeight().toByteArray();
byte[] grpprl = papx.getGrpprl();
boolean same = Arrays.equals(lastGrpprl, grpprl);
if (!same)
{
grpprlOffset -= (grpprl.length + (2 - grpprl.length % 2));
grpprlOffset -= (grpprlOffset % 2);
}
LittleEndian.putInt(buf, fcOffset, papx.getStart() + fcMin);
buf[bxOffset] = (byte)(grpprlOffset/2);
System.arraycopy(phe, 0, buf, bxOffset + 1, phe.length);
// refer to the section on PAPX in the spec. Places a size on the front
// of the PAPX. Has to do with how the grpprl stays on word
// boundaries.
if (!same)
{
int copyOffset = grpprlOffset;
if ( (grpprl.length % 2) > 0)
{
buf[copyOffset++] = (byte) ( (grpprl.length + 1) / 2);
}
else
{
buf[++copyOffset] = (byte) ( (grpprl.length) / 2);
copyOffset++;
}
System.arraycopy(grpprl, 0, buf, copyOffset, grpprl.length);
lastGrpprl = grpprl;
}
bxOffset += BX_SIZE;
fcOffset += FC_SIZE;
}
// put the last papx's end in
LittleEndian.putInt(buf, fcOffset, papx.getEnd() + fcMin);
return buf;
}
private ParagraphHeight getParagraphHeight(int index)
{
int pheOffset = _offset + 1 + (((_crun + 1) * 4) + (index * 13));
ParagraphHeight phe = new ParagraphHeight(_fkp, pheOffset);
return phe;
}
}

View File

@ -0,0 +1,135 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import org.apache.poi.hwpf.sprm.SprmBuffer;
/**
* Comment me
*
* @author Ryan Ackley
*/
public class PAPX extends CachedPropertyNode
{
private ParagraphHeight _phe;
public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe)
{
super(fcStart, fcEnd, new SprmBuffer(papx));
_phe = phe;
}
public PAPX(int fcStart, int fcEnd, SprmBuffer buf)
{
super(fcStart, fcEnd, buf);
_phe = new ParagraphHeight();
}
public ParagraphHeight getParagraphHeight()
{
return _phe;
}
public byte[] getGrpprl()
{
return ((SprmBuffer)_buf).toByteArray();
}
public short getIstd()
{
byte[] buf = getGrpprl();
if (buf.length == 0)
{
return 0;
}
else
{
return LittleEndian.getShort(buf);
}
}
public ParagraphProperties getParagraphProperties(StyleSheet ss)
{
ParagraphProperties props = (ParagraphProperties)super.getCacheContents();
if (props == null)
{
short istd = getIstd();
ParagraphProperties baseStyle = ss.getParagraphStyle(istd);
props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2);
super.fillCache(props);
}
return props;
}
public boolean equals(Object o)
{
if (super.equals(o))
{
return _phe.equals(((PAPX)o)._phe);
}
return false;
}
}

View File

@ -0,0 +1,120 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.OutputStream;
import java.io.IOException;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class ParagraphHeight
{
private short infoField;
private BitField fSpare = new BitField(0x0001);
private BitField fUnk = new BitField(0x0002);
private BitField fDiffLines = new BitField(0x0004);
private BitField clMac = new BitField(0xff00);
private short reserved;
private int dxaCol;
private int dymLineOrHeight;
public ParagraphHeight(byte[] buf, int offset)
{
infoField = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
reserved = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
dxaCol = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
dymLineOrHeight = LittleEndian.getInt(buf, offset);
}
public ParagraphHeight()
{
}
public void write(OutputStream out)
throws IOException
{
out.write(toByteArray());
}
protected byte[] toByteArray()
{
byte[] buf = new byte[12];
int offset = 0;
LittleEndian.putShort(buf, offset, infoField);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, reserved);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(buf, offset, dxaCol);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, dymLineOrHeight);
return buf;
}
public boolean equals(Object o)
{
ParagraphHeight ph = (ParagraphHeight)o;
return infoField == ph.infoField && reserved == ph.reserved &&
dxaCol == ph.dxaCol && dymLineOrHeight == ph.dymLineOrHeight;
}
}

View File

@ -0,0 +1,144 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class PieceDescriptor
{
short descriptor;
private static BitField fNoParaLast = new BitField(0x01);
private static BitField fPaphNil = new BitField(0x02);
private static BitField fCopied = new BitField(0x04);
int fc;
short prm;
boolean unicode;
public PieceDescriptor(byte[] buf, int offset)
{
descriptor = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
fc = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
prm = LittleEndian.getShort(buf, offset);
// see if this piece uses unicode.
if ((fc & 0x40000000) == 0)
{
unicode = true;
}
else
{
unicode = false;
fc &= ~(0x40000000);//gives me FC in doc stream
fc /= 2;
}
}
public int getFilePosition()
{
return fc;
}
public void setFilePosition(int pos)
{
fc = pos;
}
public boolean isUnicode()
{
return unicode;
}
protected byte[] toByteArray()
{
// set up the fc
int tempFc = fc;
if (!unicode)
{
tempFc *= 2;
tempFc |= (0x40000000);
}
int offset = 0;
byte[] buf = new byte[8];
LittleEndian.putShort(buf, offset, descriptor);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(buf, offset, tempFc);
offset += LittleEndian.INT_SIZE;
LittleEndian.putShort(buf, offset, prm);
return buf;
}
public static int getSizeInBytes()
{
return 8;
}
public boolean equals(Object o)
{
PieceDescriptor pd = (PieceDescriptor)o;
return descriptor == pd.descriptor && prm == pd.prm && unicode == pd.unicode;
}
}

View File

@ -0,0 +1,179 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.util.ArrayList;
import org.apache.poi.util.LittleEndian;
/**
* common data structure in a Word file. Contains an array of 4 byte ints in
* the front that relate to an array of abitrary data structures in the back.
*
*
* @author Ryan Ackley
*/
public class PlexOfCps
{
private int _count;
private int _offset;
private int _sizeOfStruct;
private ArrayList _props;
public PlexOfCps(int sizeOfStruct)
{
_props = new ArrayList();
_sizeOfStruct = sizeOfStruct;
}
/**
* Constructor
*
* @param size The size in bytes of this PlexOfCps
* @param sizeOfStruct The size of the data structure type stored in
* this PlexOfCps.
*/
public PlexOfCps(byte[] buf, int start, int size, int sizeOfStruct)
{
_count = (size - 4)/(4 + sizeOfStruct);
_sizeOfStruct = sizeOfStruct;
_props = new ArrayList(_count);
for (int x = 0; x < _count; x++)
{
_props.add(getProperty(x, buf, start));
}
}
public GenericPropertyNode getProperty(int index)
{
return (GenericPropertyNode)_props.get(index);
}
public void addProperty(GenericPropertyNode node)
{
_props.add(node);
}
public byte[] toByteArray()
{
int size = _props.size();
int cpBufSize = ((size + 1) * LittleEndian.INT_SIZE);
int structBufSize = + (_sizeOfStruct * size);
int bufSize = cpBufSize + structBufSize;
byte[] buf = new byte[bufSize];
GenericPropertyNode node = null;
for (int x = 0; x < size; x++)
{
node = (GenericPropertyNode)_props.get(x);
// put the starting offset of the property into the plcf.
LittleEndian.putInt(buf, (LittleEndian.INT_SIZE * x), node.getStart());
// put the struct into the plcf
System.arraycopy(node.getBytes(), 0, buf, cpBufSize + (x * _sizeOfStruct),
_sizeOfStruct);
}
// put the ending offset of the last property into the plcf.
LittleEndian.putInt(buf, LittleEndian.INT_SIZE * size, node.getEnd());
return buf;
}
private GenericPropertyNode getProperty(int index, byte[] buf, int offset)
{
int start = LittleEndian.getInt(buf, offset + getIntOffset(index));
int end = LittleEndian.getInt(buf, offset + getIntOffset(index+1));
byte[] struct = new byte[_sizeOfStruct];
System.arraycopy(buf, offset + getStructOffset(index), struct, 0, _sizeOfStruct);
return new GenericPropertyNode(start, end, struct);
}
private int getIntOffset(int index)
{
return index * 4;
}
/**
* returns the number of data structures in this PlexOfCps.
*
* @return The number of data structures in this PlexOfCps
*/
public int length()
{
return _count;
}
/**
* Returns the offset, in bytes, from the beginning if this PlexOfCps to
* the data structure at index.
*
* @param index The index of the data structure.
*
* @return The offset, in bytes, from the beginning if this PlexOfCps to
* the data structure at index.
*/
private int getStructOffset(int index)
{
return (4 * (_count + 1)) + (_sizeOfStruct * index);
}
}

View File

@ -0,0 +1,158 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import org.apache.poi.hwpf.sprm.SprmBuffer;
/**
* Represents a lightweight node in the Trees used to store content
* properties.
*
* @author Ryan Ackley
*/
public abstract class PropertyNode implements Comparable
{
protected Object _buf;
private int _cpStart;
private int _cpEnd;
/**
* @param fcStart The start of the text for this property.
* @param fcEnd The end of the text for this property.
* @param grpprl The property description in compressed form.
*/
protected PropertyNode(int fcStart, int fcEnd, Object buf)
{
_cpStart = fcStart;
_cpEnd = fcEnd;
_buf = buf;
}
/**
* @return The offset of this property's text.
*/
public int getStart()
{
return _cpStart;
}
void setStart(int start)
{
_cpStart = start;
}
/**
* @return The offset of the end of this property's text.
*/
public int getEnd()
{
return _cpEnd;
}
void setEnd(int end)
{
_cpEnd = end;
}
protected boolean limitsAreEqual(Object o)
{
return ((PropertyNode)o).getStart() == _cpStart &&
((PropertyNode)o).getEnd() == _cpEnd;
}
public boolean equals(Object o)
{
if (limitsAreEqual(o))
{
Object testBuf = ((PropertyNode)o)._buf;
if (testBuf instanceof byte[] && _buf instanceof byte[])
{
return Arrays.equals((byte[])testBuf, (byte[])_buf);
}
return _buf.equals(testBuf);
}
return false;
}
/**
* Used for sorting in collections.
*/
public int compareTo(Object o)
{
int cpEnd = ((PropertyNode)o).getEnd();
if(_cpEnd == cpEnd)
{
return 0;
}
else if(_cpEnd < cpEnd)
{
return -1;
}
else
{
return 1;
}
}
}

View File

@ -0,0 +1,99 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.hwpf.sprm.SectionSprmUncompressor;
import org.apache.poi.hwpf.sprm.SectionSprmCompressor;
import org.apache.poi.hwpf.usermodel.SectionProperties;
public class SEPX extends PropertyNode
{
SectionDescriptor _sed;
public SEPX(SectionDescriptor sed, int start, int end, byte[] grpprl)
{
super(start, end, SectionSprmUncompressor.uncompressSEP(grpprl, 0));
_sed = sed;
}
public byte[] getGrpprl()
{
return SectionSprmCompressor.compressSectionProperty((SectionProperties)_buf);
}
public SectionDescriptor getSectionDescriptor()
{
return _sed;
}
public SectionProperties getSectionProperties()
{
return (SectionProperties)_buf;
}
public boolean equals(Object o)
{
SEPX sepx = (SEPX)o;
if (super.equals(o))
{
return sepx._sed.equals(_sed);
}
return false;
}
}

View File

@ -0,0 +1,115 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import org.apache.poi.util.LittleEndian;
public class SectionDescriptor
{
private short fn;
private int fc;
private short fnMpr;
private int fcMpr;
public SectionDescriptor()
{
}
public SectionDescriptor(byte[] buf, int offset)
{
fn = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
fc = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
fnMpr = LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
fcMpr = LittleEndian.getInt(buf, offset);
}
public int getFc()
{
return fc;
}
public void setFc(int fc)
{
this.fc = fc;
}
public boolean equals(Object o)
{
SectionDescriptor sed = (SectionDescriptor)o;
return sed.fn == fn && sed.fnMpr == fnMpr;
}
public byte[] toByteArray()
{
int offset = 0;
byte[] buf = new byte[12];
LittleEndian.putShort(buf, offset, fn);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(buf, offset, fc);
offset += LittleEndian.INT_SIZE;
LittleEndian.putShort(buf, offset, fnMpr);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(buf, offset, fcMpr);
return buf;
}
}

View File

@ -0,0 +1,159 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.util.ArrayList;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
public class SectionTable
{
private static final int SED_SIZE = 12;
private ArrayList _sections = new ArrayList();
public SectionTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin)
{
PlexOfCps sedPlex = new PlexOfCps(tableStream, offset, size, SED_SIZE);
int length = sedPlex.length();
for (int x = 0; x < length; x++)
{
GenericPropertyNode node = sedPlex.getProperty(x);
SectionDescriptor sed = new SectionDescriptor(node.getBytes(), 0);
int fileOffset = sed.getFc();
// check for the optimization
if (fileOffset == 0xffffffff)
{
_sections.add(new SEPX(sed, node.getStart(), node.getEnd(), new byte[0]));
}
else
{
// The first short at the offset is the size of the grpprl.
int sepxSize = LittleEndian.getShort(documentStream, fileOffset);
byte[] buf = new byte[sepxSize];
fileOffset += LittleEndian.SHORT_SIZE;
System.arraycopy(documentStream, fileOffset, buf, 0, buf.length);
_sections.add(new SEPX(sed, node.getStart(), node.getEnd(), buf));
}
}
}
public void adjustForInsert(int listIndex, int length)
{
int size = _sections.size();
SEPX sepx = (SEPX)_sections.get(listIndex);
sepx.setEnd(sepx.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
sepx = (SEPX)_sections.get(x);
sepx.setStart(sepx.getStart() + length);
sepx.setEnd(sepx.getEnd() + length);
}
}
public ArrayList getSections()
{
return _sections;
}
public void writeTo(HWPFFileSystem sys, int fcMin)
throws IOException
{
HWPFOutputStream docStream = sys.getStream("WordDocument");
HWPFOutputStream tableStream = sys.getStream("1Table");
int offset = docStream.getOffset();
int len = _sections.size();
PlexOfCps plex = new PlexOfCps(SED_SIZE);
for (int x = 0; x < len; x++)
{
SEPX sepx = (SEPX)_sections.get(x);
byte[] grpprl = sepx.getGrpprl();
// write the sepx to the document stream. starts with a 2 byte size
// followed by the grpprl
byte[] shortBuf = new byte[2];
LittleEndian.putShort(shortBuf, (short)grpprl.length);
docStream.write(shortBuf);
docStream.write(grpprl);
// set the fc in the section descriptor
SectionDescriptor sed = sepx.getSectionDescriptor();
sed.setFc(offset);
// add the section descriptor bytes to the PlexOfCps.
GenericPropertyNode property = new GenericPropertyNode(sepx.getStart(), sepx.getEnd(), sed.toByteArray());
plex.addProperty(property);
offset = docStream.getOffset();
}
tableStream.write(plex.toByteArray());
}
}

View File

@ -0,0 +1,294 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
/**
* Comment me
*
* @author Ryan Ackley
*/
public class StyleDescription implements HDFType
{
private final static int PARAGRAPH_STYLE = 1;
private final static int CHARACTER_STYLE = 2;
private int _istd;
private int _baseLength;
private short _infoShort;
private static BitField _sti = new BitField(0xfff);
private static BitField _fScratch = new BitField(0x1000);
private static BitField _fInvalHeight = new BitField(0x2000);
private static BitField _fHasUpe = new BitField(0x4000);
private static BitField _fMassCopy = new BitField(0x8000);
private short _infoShort2;
private static BitField _styleTypeCode = new BitField(0xf);
private static BitField _baseStyle = new BitField(0xfff0);
private short _infoShort3;
private static BitField _numUPX = new BitField(0xf);
private static BitField _nextStyle = new BitField(0xfff0);
private short _bchUpe;
private short _infoShort4;
private static BitField _fAutoRedef = new BitField(0x1);
private static BitField _fHidden = new BitField(0x2);
UPX[] _upxs;
String _name;
ParagraphProperties _pap;
CharacterProperties _chp;
public StyleDescription()
{
// _pap = new ParagraphProperties();
// _chp = new CharacterProperties();
}
public StyleDescription(byte[] std, int baseLength, int offset, boolean word9)
{
_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;
//first byte(s) of variable length section of std is the length of the
//style name and aliases string
int nameLength = 0;
int multiplier = 1;
if(word9)
{
nameLength = LittleEndian.getShort(std, nameStart);
multiplier = 2;
nameStart += LittleEndian.SHORT_SIZE;
}
else
{
nameLength = std[nameStart];
}
try
{
_name = new String(std, nameStart, nameLength * multiplier, "UTF-16LE");
}
catch (UnsupportedEncodingException ignore)
{
// ignore
}
//length then null terminator.
int grupxStart = ((nameLength + 1) * multiplier) + nameStart;
// 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 upxSize = LittleEndian.getShort(std, varOffset);
varOffset += LittleEndian.SHORT_SIZE;
byte[] upx = new byte[upxSize];
System.arraycopy(std, varOffset, upx, 0, upxSize);
_upxs[x] = new UPX(upx);
varOffset += upxSize;
// the upx will always start on a word boundary.
if(upxSize % 2 == 1)
{
++varOffset;
}
}
}
public int getBaseStyle()
{
return _baseStyle.getValue(_infoShort2);
}
public byte[] getCHPX()
{
switch (_styleTypeCode.getValue(_infoShort2))
{
case PARAGRAPH_STYLE:
if (_upxs.length > 1)
{
return _upxs[1].getUPX();
}
return null;
case CHARACTER_STYLE:
return _upxs[0].getUPX();
default:
return null;
}
}
public byte[] getPAPX()
{
switch (_styleTypeCode.getValue(_infoShort2))
{
case PARAGRAPH_STYLE:
return _upxs[0].getUPX();
default:
return null;
}
}
public ParagraphProperties getPAP()
{
return _pap;
}
public CharacterProperties getCHP()
{
return _chp;
}
void setPAP(ParagraphProperties pap)
{
_pap = pap;
}
void setCHP(CharacterProperties chp)
{
_chp = chp;
}
public byte[] toByteArray()
{
// size equals _baseLength bytes for known variables plus 2 bytes for name
// length plus name length * 2 plus 2 bytes for null plus upx's preceded by
// length
int size = _baseLength + 2 + ((_name.length() + 1) * 2);
// determine the size needed for the upxs. They always fall on word
// boundaries.
size += _upxs[0].size() + 2;
for (int x = 1; x < _upxs.length; x++)
{
size += _upxs[x-1].size() % 2;
size += _upxs[x].size() + 2;
}
byte[] buf = new byte[size];
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;
char[] letters = _name.toCharArray();
LittleEndian.putShort(buf, _baseLength, (short)letters.length);
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < letters.length; x++)
{
LittleEndian.putShort(buf, offset, (short)letters[x]);
offset += LittleEndian.SHORT_SIZE;
}
// get past the null delimiter for the name.
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < _upxs.length; x++)
{
short upxSize = (short)_upxs[x].size();
LittleEndian.putShort(buf, offset, upxSize);
offset += LittleEndian.SHORT_SIZE;
System.arraycopy(_upxs[x].getUPX(), 0, buf, offset, upxSize);
offset += upxSize + (upxSize % 2);
}
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))
{
if (!Arrays.equals(_upxs, sd._upxs))
{
return false;
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,346 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.util.*;
import java.io.IOException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor;
/**
* Represents a document's stylesheet. A word documents formatting is stored as
* compressed styles that are based on styles contained in the stylesheet. This
* class also contains static utility functions to uncompress different
* formatting properties.
*
* @author Ryan Ackley
*/
public class StyleSheet implements HDFType
{
public static final int NIL_STYLE = 4095;
private static final int PAP_TYPE = 1;
private static final int CHP_TYPE = 2;
private static final int SEP_TYPE = 4;
private static final int TAP_TYPE = 5;
private final static ParagraphProperties NIL_PAP = new ParagraphProperties();
private final static CharacterProperties NIL_CHP = new CharacterProperties();
private int _stshiLength;
private int _baseLength;
private int _flags;
private int _maxIndex;
private int _maxFixedIndex;
private int _stylenameVersion;
private int[] _rgftc;
StyleDescription[] _styleDescriptions;
/**
* StyleSheet constructor. Loads a document's stylesheet information,
*
* @param styleSheet A byte array containing a document's raw stylesheet
* info. Found by using FileInformationBlock.getFcStshf() and
* FileInformationBLock.getLcbStshf()
*/
public StyleSheet(byte[] tableStream, int offset)
{
_stshiLength = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
int stdCount = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_baseLength = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_flags = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_maxIndex = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_maxFixedIndex = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_stylenameVersion = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_rgftc = new int[3];
_rgftc[0] = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_rgftc[1] = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
_rgftc[2] = LittleEndian.getShort(tableStream, offset);
offset += LittleEndian.SHORT_SIZE;
offset = (LittleEndian.SHORT_SIZE + _stshiLength);
_styleDescriptions = new StyleDescription[stdCount];
for(int x = 0; x < stdCount; x++)
{
int stdSize = LittleEndian.getShort(tableStream, offset);
//get past the size
offset += 2;
if(stdSize > 0)
{
//byte[] std = new byte[stdSize];
StyleDescription aStyle = new StyleDescription(tableStream,
_baseLength, offset, true);
_styleDescriptions[x] = aStyle;
}
offset += stdSize;
}
for(int x = 0; x < _styleDescriptions.length; x++)
{
if(_styleDescriptions[x] != null)
{
createPap(x);
createChp(x);
}
}
}
public void writeTo(HWPFOutputStream out)
throws IOException
{
int offset = 0;
// add two bytes so we can prepend the stylesheet w/ its size
byte[] buf = new byte[_stshiLength + 2];
LittleEndian.putShort(buf, offset, (short)_stshiLength);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_styleDescriptions.length);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_baseLength);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_flags);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_maxIndex);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_maxFixedIndex);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_stylenameVersion);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_rgftc[0]);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_rgftc[1]);
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(buf, offset, (short)_rgftc[2]);
out.write(buf);
byte[] sizeHolder = new byte[2];
for (int x = 0; x < _styleDescriptions.length; x++)
{
if(_styleDescriptions[x] != null)
{
byte[] std = _styleDescriptions[x].toByteArray();
LittleEndian.putShort(sizeHolder, (short)(std.length));
out.write(sizeHolder);
out.write(std);
// Must always start on a word boundary.
if (std.length % 2 == 1)
{
out.write('\0');
}
}
else
{
sizeHolder[0] = 0;
sizeHolder[1] = 0;
out.write(sizeHolder);
}
}
}
public boolean equals(Object o)
{
StyleSheet ss = (StyleSheet)o;
if (ss._baseLength == _baseLength && ss._flags == _flags &&
ss._maxFixedIndex ==_maxFixedIndex && ss._maxIndex == _maxIndex &&
ss._rgftc[0] == _rgftc[0] && ss._rgftc[1] == _rgftc[1] &&
ss._rgftc[2] == _rgftc[2] && ss._stshiLength == _stshiLength &&
ss._stylenameVersion == _stylenameVersion)
{
if (ss._styleDescriptions.length == _styleDescriptions.length)
{
for (int x = 0; x < _styleDescriptions.length; x++)
{
// check for null
if (ss._styleDescriptions[x] != _styleDescriptions[x])
{
// check for equality
if (!ss._styleDescriptions[x].equals(_styleDescriptions[x]))
{
return false;
}
}
}
return true;
}
}
return false;
}
/**
* Creates a PartagraphProperties object from a papx stored in the
* StyleDescription at the index istd in the StyleDescription array. The PAP
* is placed in the StyleDescription at istd after its been created. Not
* every StyleDescription will contain a papx. In these cases this function
* does nothing
*
* @param istd The index of the StyleDescription to create the
* ParagraphProperties from (and also place the finished PAP in)
*/
private void createPap(int istd)
{
StyleDescription sd = _styleDescriptions[istd];
ParagraphProperties pap = sd.getPAP();
byte[] papx = sd.getPAPX();
int baseIndex = sd.getBaseStyle();
if(pap == null && papx != null)
{
ParagraphProperties parentPAP = new ParagraphProperties();
if(baseIndex != NIL_STYLE)
{
parentPAP = _styleDescriptions[baseIndex].getPAP();
if(parentPAP == null)
{
createPap(baseIndex);
parentPAP = _styleDescriptions[baseIndex].getPAP();
}
}
pap = (ParagraphProperties)ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2);
sd.setPAP(pap);
}
}
/**
* Creates a CharacterProperties object from a chpx stored in the
* StyleDescription at the index istd in the StyleDescription array. The
* CharacterProperties object is placed in the StyleDescription at istd after
* its been created. Not every StyleDescription will contain a chpx. In these
* cases this function does nothing.
*
* @param istd The index of the StyleDescription to create the
* CharacterProperties object from.
*/
private void createChp(int istd)
{
StyleDescription sd = _styleDescriptions[istd];
CharacterProperties chp = sd.getCHP();
byte[] chpx = sd.getCHPX();
int baseIndex = sd.getBaseStyle();
if(chp == null && chpx != null)
{
CharacterProperties parentCHP = new CharacterProperties();
if(baseIndex != NIL_STYLE)
{
parentCHP = _styleDescriptions[baseIndex].getCHP();
if(parentCHP == null)
{
createChp(baseIndex);
parentCHP = _styleDescriptions[baseIndex].getCHP();
}
}
chp = (CharacterProperties)CharacterSprmUncompressor.uncompressCHP(parentCHP, chpx, 0);
sd.setCHP(chp);
}
}
/**
* Gets the StyleDescription at index x.
*
* @param x the index of the desired StyleDescription.
*/
public StyleDescription getStyleDescription(int x)
{
return _styleDescriptions[x];
}
public CharacterProperties getCharacterStyle(int x)
{
if (x == NIL_STYLE)
{
return NIL_CHP;
}
return (_styleDescriptions[x] != null ? _styleDescriptions[x].getCHP() : null);
}
public ParagraphProperties getParagraphStyle(int x)
{
if (x == NIL_STYLE)
{
return NIL_PAP;
}
return (_styleDescriptions[x] != null ? _styleDescriptions[x].getPAP() : null);
}
}

View File

@ -0,0 +1,40 @@
package org.apache.poi.hwpf.model;
import junit.framework.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
import java.io.*;
import java.util.*;
public class TestListTables
extends HWPFTestCase
{
public TestListTables()
{
}
public void testReadWrite()
throws Exception
{
FileInformationBlock fib = _hWPFDocFixture._fib;
byte[] tableStream = _hWPFDocFixture._tableStream;
ListTables listTables = new ListTables(tableStream, fib.getFcPlcfLst(), fib.getFcPlfLfo());
HWPFFileSystem fileSys = new HWPFFileSystem();
HWPFOutputStream tableOut = fileSys.getStream("1Table");
listTables.writeListDataTo(tableOut);
int offset = tableOut.getOffset();
listTables.writeListOverridesTo(tableOut);
ListTables newTables = new ListTables(tableOut.toByteArray(), 0, offset);
assertEquals(listTables, newTables);
}
}

View File

@ -0,0 +1,130 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.UnsupportedEncodingException;
/**
* Lightweight representation of a text piece.
*
* @author Ryan Ackley
*/
public class TextPiece extends PropertyNode implements Comparable
{
private boolean _usesUnicode;
private int _length;
private PieceDescriptor _pd;
/**
* @param start Offset in main document stream.
* @param length The total length of the text in bytes. Note: 1 character
* does not necessarily refer to 1 byte.
* @param unicode true if this text is unicode.
*/
public TextPiece(int start, int end, byte[] text, PieceDescriptor pd)
throws UnsupportedEncodingException
{
super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252")));
_usesUnicode = pd.isUnicode();
_length = end - start;
_pd = pd;
}
/**
* @return If this text piece uses unicode
*/
public boolean usesUnicode()
{
return _usesUnicode;
}
public PieceDescriptor getPieceDescriptor()
{
return _pd;
}
public StringBuffer getStringBuffer()
{
return (StringBuffer)_buf;
}
public byte[] getRawBytes()
{
try
{
return ((StringBuffer)_buf).toString().getBytes(_usesUnicode ?
"UTF-16LE" : "Cp1252");
}
catch (UnsupportedEncodingException ignore)
{
// shouldn't ever happen considering we wouldn't have been able to
// create the StringBuffer w/o getting this exception
return ((StringBuffer)_buf).toString().getBytes();
}
}
public boolean equals(Object o)
{
if (limitsAreEqual(o))
{
TextPiece tp = (TextPiece)o;
return getStringBuffer().toString().equals(tp.getStringBuffer().toString()) &&
tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd);
}
return false;
}
}

View File

@ -0,0 +1,238 @@
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.hwpf.model.io.*;
public class TextPieceTable
{
ArrayList _textPieces = new ArrayList();
//int _multiple;
int _cpMin;
public TextPieceTable(byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin)
throws UnsupportedEncodingException
{
// get our plex of PieceDescriptors
PlexOfCps pieceTable = new PlexOfCps(tableStream, offset, size, PieceDescriptor.getSizeInBytes());
//_multiple = 2;
int length = pieceTable.length();
PieceDescriptor[] pieces = new PieceDescriptor[length];
// iterate through piece descriptors raw bytes and create
// PieceDescriptor objects
for (int x = 0; x < length; x++)
{
GenericPropertyNode node = pieceTable.getProperty(x);
pieces[x] = new PieceDescriptor(node.getBytes(), 0);
// if (!pieces[x].isUnicode())
// {
// _multiple = 1;
// }
}
_cpMin = pieces[0].getFilePosition() - fcMin;
// if a piece is unicode the actual offset may be bumped because of the
// doubling of the needed size.
int bump = 0;
// using the PieceDescriptors, build our list of TextPieces.
for (int x = 0; x < pieces.length; x++)
{
int start = pieces[x].getFilePosition();
PropertyNode node = pieceTable.getProperty(x);
int nodeStart = node.getStart();
// multiple will be 2 if there is only one piece and its unicode. Some
// type of optimization.
boolean unicode = pieces[x].isUnicode();
int multiple = 1;
if (unicode)
{
multiple = 2;
}
int nodeEnd = ((node.getEnd() - nodeStart) * multiple) + nodeStart;
int textSize = nodeEnd - nodeStart;
byte[] buf = new byte[textSize];
System.arraycopy(documentStream, start, buf, 0, textSize);
_textPieces.add(new TextPiece(nodeStart + bump, nodeEnd + bump, buf, pieces[x]));
if (unicode)
{
bump += (node.getEnd() - nodeStart);
}
}
}
public int getCpMin()
{
return _cpMin;
}
public List getTextPieces()
{
return _textPieces;
}
public byte[] writeTo(HWPFOutputStream docStream)
throws IOException
{
PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes());
//int fcMin = docStream.getOffset();
int size = _textPieces.size();
int bumpDown = 0;
for (int x = 0; x < size; x++)
{
TextPiece next = (TextPiece)_textPieces.get(x);
PieceDescriptor pd = next.getPieceDescriptor();
int offset = docStream.getOffset();
int mod = (offset % POIFSConstants.BIG_BLOCK_SIZE);
if (mod != 0)
{
mod = POIFSConstants.BIG_BLOCK_SIZE - mod;
byte[] buf = new byte[mod];
docStream.write(buf);
}
// set the text piece position to the current docStream offset.
pd.setFilePosition(docStream.getOffset());
// write the text to the docstream and save the piece descriptor to the
// plex which will be written later to the tableStream.
//if (_multiple == 1 && pd.isUnicode() &&
docStream.write(next.getRawBytes());
int nodeStart = next.getStart();
int multiple = 1;
if (pd.isUnicode())
{
multiple = 2;
}
textPlex.addProperty(new GenericPropertyNode(nodeStart - bumpDown,
((next.getEnd() - nodeStart)/multiple + nodeStart) - bumpDown,
pd.toByteArray()));
if (pd.isUnicode())
{
bumpDown += ((next.getEnd() - nodeStart)/multiple);
}
}
return textPlex.toByteArray();
}
public int adjustForInsert(int listIndex, int length)
{
int size = _textPieces.size();
TextPiece tp = (TextPiece)_textPieces.get(listIndex);
length = length * (tp.usesUnicode() ? 2 : 1);
tp.setEnd(tp.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
tp = (TextPiece)_textPieces.get(x);
tp.setStart(tp.getStart() + length);
tp.setEnd(tp.getEnd() + length);
}
return length;
}
public boolean equals(Object o)
{
TextPieceTable tpt = (TextPieceTable)o;
int size = tpt._textPieces.size();
if (size == _textPieces.size())
{
for (int x = 0; x < size; x++)
{
if (!tpt._textPieces.get(x).equals(_textPieces.get(x)))
{
return false;
}
}
return true;
}
return false;
}
}

View File

@ -52,22 +52,31 @@
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
package org.apache.poi.hwpf.model;
import org.apache.poi.hwpf.*;
import java.util.Arrays;
import java.util.List;
public class CharacterRange extends Range
public class UPX
{
public CharacterRange(int start, int end, HWPFDocument doc)
private byte[] _upx;
public UPX(byte[] upx)
{
super(start, end, doc);
}
public CharacterRange(int start, int end, Range parent)
{
super(start, end, parent);
_upx = upx;
}
public byte[] getUPX()
{
return _upx;
}
public int size()
{
return _upx.length;
}
public boolean equals(Object o)
{
UPX upx = (UPX)o;
return Arrays.equals(_upx, upx._upx);
}
}

View File

@ -0,0 +1,17 @@
package org.apache.poi.hwpf.model;
public class UnhandledDataStructure
{
byte[] _buf;
public UnhandledDataStructure(byte[] buf, int offset, int length)
{
_buf = new byte[length];
System.arraycopy(buf, offset, _buf, 0, length);
}
byte[] getBuf()
{
return _buf;
}
}

View File

@ -1,324 +0,0 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.util.LittleEndian;
public class CharacterSprmCompresser
{
public CharacterSprmCompresser()
{
}
public static byte[] compressCharacterProperty(CharacterRun newCHP, CharacterRun oldCHP)
{
ArrayList sprmList = new ArrayList();
int size = 0;
if (newCHP.isFRMarkDel() != oldCHP.isFRMarkDel())
{
int value = 0;
if (newCHP.isFRMarkDel())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0800, value, null, sprmList);
}
if (newCHP.isFRMark() != oldCHP.isFRMark())
{
int value = 0;
if (newCHP.isFRMark())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0801, value, null, sprmList);
}
if (newCHP.isFFldVanish() != oldCHP.isFFldVanish())
{
int value = 0;
if (newCHP.isFFldVanish())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0802, value, null, sprmList);
}
if (!oldCHP.isFSpec() || newCHP.getFcPic() != oldCHP.getFcPic())
{
byte[] varParam = new byte[4];
LittleEndian.putInt(varParam, 0, newCHP.getFcPic());
size += SprmUtils.addSprm((short)0x6a03, 0, varParam, sprmList);
}
if (newCHP.getIbstRMark() != oldCHP.getIbstRMark())
{
size += SprmUtils.addSprm((short)0x4804, newCHP.getIbstRMark(), null, sprmList);
}
if (!newCHP.getDttmRMark().equals(oldCHP.getDttmRMark()))
{
byte[] buf = new byte[4];
newCHP.getDttmRMark().serialize(buf, 0);
size += SprmUtils.addSprm((short)0x6805, LittleEndian.getInt(buf), null, sprmList);
}
if (newCHP.isFData() != oldCHP.isFData())
{
int value = 0;
if (newCHP.isFData())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0806, value, null, sprmList);
}
if (newCHP.isFSpec() && newCHP.getFtcSym() != 0)
{
byte[] varParam = new byte[4];
LittleEndian.putShort(varParam, 0, (short)newCHP.getFtcSym());
LittleEndian.putShort(varParam, 2, (short)newCHP.getXchSym());
size += SprmUtils.addSprm((short)0x6a09, 0, varParam, sprmList);
}
if (newCHP.isFOle2() != newCHP.isFOle2())
{
int value = 0;
if (newCHP.isFOle2())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x080a, value, null, sprmList);
}
if (newCHP.getIcoHighlight() != oldCHP.getIcoHighlight())
{
size += SprmUtils.addSprm((short)0x2a0c, newCHP.getIcoHighlight(), null, sprmList);
}
if (newCHP.getFcObj() != oldCHP.getFcObj())
{
size += SprmUtils.addSprm((short)0x680e, newCHP.getFcObj(), null, sprmList);
}
if (newCHP.getIstd() != oldCHP.getIstd())
{
size += SprmUtils.addSprm((short)0x4a30, newCHP.getIstd(), null, sprmList);
}
if (newCHP.isFBold() != oldCHP.isFBold())
{
int value = 0;
if (newCHP.isFBold())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0835, value, null, sprmList);
}
if (newCHP.isFItalic() != oldCHP.isFItalic())
{
int value = 0;
if (newCHP.isFItalic())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0836, value, null, sprmList);
}
if (newCHP.isFStrike() != oldCHP.isFStrike())
{
int value = 0;
if (newCHP.isFStrike())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0837, value, null, sprmList);
}
if (newCHP.isFOutline() != oldCHP.isFOutline())
{
int value = 0;
if (newCHP.isFOutline())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0838, value, null, sprmList);
}
if (newCHP.isFShadow() != oldCHP.isFShadow())
{
int value = 0;
if (newCHP.isFShadow())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0839, value, null, sprmList);
}
if (newCHP.isFSmallCaps() != oldCHP.isFSmallCaps())
{
int value = 0;
if (newCHP.isFSmallCaps())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x083a, value, null, sprmList);
}
if (newCHP.isFCaps() != oldCHP.isFCaps())
{
int value = 0;
if (newCHP.isFCaps())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x083b, value, null, sprmList);
}
if (newCHP.isFVanish() != oldCHP.isFVanish())
{
int value = 0;
if (newCHP.isFVanish())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x083c, value, null, sprmList);
}
if (newCHP.getKul() != oldCHP.getKul())
{
size += SprmUtils.addSprm((short)0x2a3e, newCHP.getKul(), null, sprmList);
}
if (newCHP.getDxaSpace() != oldCHP.getDxaSpace())
{
size += SprmUtils.addSprm((short)0x8840, newCHP.getDxaSpace(), null, sprmList);
}
if (newCHP.getIco() != oldCHP.getIco())
{
size += SprmUtils.addSprm((short)0x2a42, newCHP.getIco(), null, sprmList);
}
if (newCHP.getHps() != oldCHP.getHps())
{
size += SprmUtils.addSprm((short)0x2a43, newCHP.getHps(), null, sprmList);
}
if (newCHP.getHpsPos() != oldCHP.getHpsPos())
{
size += SprmUtils.addSprm((short)0x4845, newCHP.getHpsPos(), null, sprmList);
}
if (newCHP.getHpsKern() != oldCHP.getHpsKern())
{
size += SprmUtils.addSprm((short)0x484b, newCHP.getHpsKern(), null, sprmList);
}
if (newCHP.getYsr() != oldCHP.getYsr())
{
size += SprmUtils.addSprm((short)0x484e, newCHP.getYsr(), null, sprmList);
}
if (newCHP.getFtcAscii() != oldCHP.getFtcAscii())
{
size += SprmUtils.addSprm((short)0x4a4f, newCHP.getFtcAscii(), null, sprmList);
}
if (newCHP.getFtcFE() != oldCHP.getFtcFE())
{
size += SprmUtils.addSprm((short)0x4a50, newCHP.getFtcFE(), null, sprmList);
}
if (newCHP.getFtcOther() != oldCHP.getFtcOther())
{
size += SprmUtils.addSprm((short)0x4a51, newCHP.getFtcOther(), null, sprmList);
}
if (newCHP.isFDStrike() != oldCHP.isFDStrike())
{
int value = 0;
if (newCHP.isFDStrike())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x2a53, value, null, sprmList);
}
if (newCHP.isFImprint() != oldCHP.isFImprint())
{
int value = 0;
if (newCHP.isFImprint())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0854, value, null, sprmList);
}
if (newCHP.isFSpec() != oldCHP.isFSpec())
{
int value = 0;
if (newCHP.isFSpec())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0855, value, null, sprmList);
}
if (newCHP.isFObj() != oldCHP.isFObj())
{
int value = 0;
if (newCHP.isFObj())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0856, value, null, sprmList);
}
if (newCHP.isFEmboss() != oldCHP.isFEmboss())
{
int value = 0;
if (newCHP.isFEmboss())
{
value = 0x01;
}
size += SprmUtils.addSprm((short)0x0858, value, null, sprmList);
}
if (newCHP.getSfxtText() != oldCHP.getSfxtText())
{
size += SprmUtils.addSprm((short)0x2859, newCHP.getSfxtText(), null, sprmList);
}
return SprmUtils.getGrpprl(sprmList, size);
}
}

View File

@ -58,7 +58,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.util.LittleEndian;
public class CharacterSprmCompressor
@ -66,7 +66,7 @@ public class CharacterSprmCompressor
public CharacterSprmCompressor()
{
}
public static byte[] compressCharacterProperty(CharacterRun newCHP, CharacterRun oldCHP)
public static byte[] compressCharacterProperty(CharacterProperties newCHP, CharacterProperties oldCHP)
{
ArrayList sprmList = new ArrayList();
int size = 0;

View File

@ -54,11 +54,11 @@
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.DateAndTime;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
import org.apache.poi.hwpf.model.hdftypes.StyleSheet;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.util.LittleEndian;
public class CharacterSprmUncompressor
@ -67,14 +67,14 @@ public class CharacterSprmUncompressor
{
}
public static CharacterRun uncompressCHP(CharacterRun parent,
public static CharacterProperties uncompressCHP(CharacterProperties parent,
byte[] grpprl,
int offset)
{
CharacterRun newProperties = null;
CharacterProperties newProperties = null;
try
{
newProperties = (CharacterRun) parent.clone();
newProperties = (CharacterProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
@ -105,8 +105,8 @@ public class CharacterSprmUncompressor
* @param offset The offset in the grpprl of the next sprm
* @param styleSheet The StyleSheet for this document.
*/
static void unCompressCHPOperation (CharacterRun oldCHP,
CharacterRun newCHP,
static void unCompressCHPOperation (CharacterProperties oldCHP,
CharacterProperties newCHP,
SprmOperation sprm)
{
@ -264,7 +264,7 @@ public class CharacterSprmUncompressor
{
// preserve the fSpec setting from the original CHP
boolean fSpec = newCHP.isFSpec ();
newCHP = (CharacterRun) oldCHP.clone ();
newCHP = (CharacterProperties) oldCHP.clone ();
newCHP.setFSpec (fSpec);
}

View File

@ -60,7 +60,7 @@ import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
public class ParagraphSprmCompressor
{
@ -68,8 +68,8 @@ public class ParagraphSprmCompressor
{
}
public static byte[] compressParagraphProperty(Paragraph newPAP,
Paragraph oldPAP)
public static byte[] compressParagraphProperty(ParagraphProperties newPAP,
ParagraphProperties oldPAP)
{
ArrayList sprmList = new ArrayList();
int size = 0;
@ -297,13 +297,13 @@ public class ParagraphSprmCompressor
}
size += SprmUtils.addSprm((short)0x442B, val, null, sprmList);
}
if (newPAP.getShd() != oldPAP.getShd())
if (newPAP.getShd() != null && !newPAP.getShd().equals(oldPAP.getShd()))
{
size += SprmUtils.addSprm((short)0x442D, newPAP.getShd(), null, sprmList);
size += SprmUtils.addSprm((short)0x442D, newPAP.getShd().toShort(), null, sprmList);
}
if (newPAP.getDcs() != oldPAP.getDcs())
if (newPAP.getDcs() != null && !newPAP.getDcs().equals(oldPAP.getDcs()))
{
size += SprmUtils.addSprm((short)0x442C, newPAP.getDcs(), null, sprmList);
size += SprmUtils.addSprm((short)0x442C, newPAP.getDcs().toShort(), null, sprmList);
}
if (newPAP.getLvl() != oldPAP.getLvl())
{
@ -328,6 +328,21 @@ public class ParagraphSprmCompressor
size += SprmUtils.addSprm((short)0xC645, 0, newPAP.getNumrm(), sprmList);
}
if (newPAP.getTableLevel() != oldPAP.getTableLevel())
{
size += SprmUtils.addSprm((short)0x6649, newPAP.getTableLevel(), null, sprmList);
}
if (newPAP.getEmbeddedCellMark() != oldPAP.getEmbeddedCellMark())
{
size += SprmUtils.addSprm((short)0x244b, newPAP.getEmbeddedCellMark(), null, sprmList);
}
if (newPAP.getFTtpEmbedded() != oldPAP.getFTtpEmbedded())
{
size += SprmUtils.addSprm((short)0x244c, newPAP.getFTtpEmbedded(), null, sprmList);
}
return SprmUtils.getGrpprl(sprmList, size);
}

View File

@ -54,10 +54,12 @@
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.hwpf.usermodel.DateAndTime;
import org.apache.poi.hwpf.usermodel.LineSpacingDescriptor;
import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
import org.apache.poi.hwpf.usermodel.DropCapSpecifier;
import org.apache.poi.util.LittleEndian;
import java.util.HashMap;
@ -73,14 +75,14 @@ public class ParagraphSprmUncompressor
{
}
public static Paragraph uncompressPAP(Paragraph parent,
public static ParagraphProperties uncompressPAP(ParagraphProperties parent,
byte[] grpprl,
int offset)
{
Paragraph newProperties = null;
ParagraphProperties newProperties = null;
try
{
newProperties = (Paragraph) parent.clone();
newProperties = (ParagraphProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
@ -91,7 +93,13 @@ public class ParagraphSprmUncompressor
while (sprmIt.hasNext())
{
SprmOperation sprm = (SprmOperation)sprmIt.next();
unCompressPAPOperation(newProperties, sprm);
// PAPXs can contain table sprms if the paragraph marks the end of a
// table row
if (sprm.getType() == SprmOperation.PAP_TYPE)
{
unCompressPAPOperation(newProperties, sprm);
}
}
return newProperties;
@ -109,7 +117,7 @@ public class ParagraphSprmUncompressor
* @param offset The current offset in the papx.
* @param spra A part of the sprm that defined this operation.
*/
static void unCompressPAPOperation (Paragraph newPAP, SprmOperation sprm)
static void unCompressPAPOperation (ParagraphProperties newPAP, SprmOperation sprm)
{
switch (sprm.getOperation())
{
@ -292,10 +300,10 @@ public class ParagraphSprmUncompressor
newPAP.setDyaHeight (sprm.getOperand());
break;
case 0x2c:
newPAP.setDcs ((short) sprm.getOperand());
newPAP.setDcs (new DropCapSpecifier((short)sprm.getOperand()));
break;
case 0x2d:
newPAP.setShd ((short) sprm.getOperand());
newPAP.setShd (new ShadingDescriptor((short)sprm.getOperand()));
break;
case 0x2e:
newPAP.setDyaFromText (sprm.getOperand());
@ -405,12 +413,21 @@ public class ParagraphSprmUncompressor
case 0x48:
newPAP.setFAdjustRight ((byte) sprm.getOperand());
break;
case 0x49:
newPAP.setTableLevel((byte)sprm.getOperand());
break;
case 0x4b:
newPAP.setEmbeddedCellMark((byte)sprm.getOperand());
break;
case 0x4c:
newPAP.setFTtpEmbedded((byte)sprm.getOperand());
break;
default:
break;
}
}
private static void handleTabs(Paragraph pap, SprmOperation sprm)
private static void handleTabs(ParagraphProperties pap, SprmOperation sprm)
{
byte[] grpprl = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset();
@ -431,12 +448,13 @@ public class ParagraphSprmUncompressor
}
int addSize = grpprl[offset++];
int start = offset;
for (int x = 0; x < addSize; x++)
{
Integer key = new Integer(LittleEndian.getInt(grpprl, offset));
Byte val = new Byte(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]);
Integer key = new Integer(LittleEndian.getShort(grpprl, offset));
Byte val = new Byte(grpprl[start + ((LittleEndian.SHORT_SIZE * addSize) + x)]);
tabMap.put(key, val);
offset += LittleEndian.INT_SIZE;
offset += LittleEndian.SHORT_SIZE;
}
tabPositions = new int[tabMap.size()];

View File

@ -58,7 +58,7 @@ package org.apache.poi.hwpf.sprm;
//import java.util.ArrayList;
//import java.util.Arrays;
//
//import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
//import org.apache.poi.hwpf.model.types.SEPAbstractType;
//import org.apache.poi.hwpf.usermodel.SectionProperties;
//import org.apache.poi.util.LittleEndian;
//
@ -276,19 +276,18 @@ package org.apache.poi.hwpf.sprm;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
import org.apache.poi.hwpf.usermodel.Section;
import org.apache.poi.hwpf.model.types.SEPAbstractType;
import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.util.LittleEndian;
public class SectionSprmCompressor
{
private final static Section DEFAULT_SEP = new Section();
private final static SectionProperties DEFAULT_SEP = new SectionProperties();
public SectionSprmCompressor()
{
}
public static byte[] compressSectionProperty(Section newSEP,
Section oldSEP)
public static byte[] compressSectionProperty(SectionProperties newSEP)
{
int size = 0;
ArrayList sprmList = new ArrayList();

View File

@ -54,7 +54,7 @@
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.Section;
import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.usermodel.BorderCode;
public class SectionSprmUncompressor extends SprmUncompressor
@ -62,19 +62,10 @@ public class SectionSprmUncompressor extends SprmUncompressor
public SectionSprmUncompressor()
{
}
public static Section uncompressSEP(Section parent,
byte[] grpprl,
int offset)
public static SectionProperties uncompressSEP(byte[] grpprl, int offset)
{
Section newProperties = null;
try
{
newProperties = (Section) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("There is no way this exception should happen!!");
}
SectionProperties newProperties = new SectionProperties();
SprmIterator sprmIt = new SprmIterator(grpprl, offset);
while (sprmIt.hasNext())
@ -95,7 +86,7 @@ public class SectionSprmUncompressor extends SprmUncompressor
* @param param The operation's parameter.
* @param varParam The operation variable length parameter.
*/
static void unCompressSEPOperation (Section newSEP, SprmOperation sprm)
static void unCompressSEPOperation (SectionProperties newSEP, SprmOperation sprm)
{
switch (sprm.getOperation())
{

View File

@ -56,17 +56,30 @@ package org.apache.poi.hwpf.sprm;
import org.apache.poi.util.LittleEndian;
import java.util.Arrays;
public class SprmBuffer
implements Cloneable
{
byte[] _buf;
int _offset;
boolean _istd;
public SprmBuffer(byte[] buf)
public SprmBuffer(byte[] buf, boolean istd)
{
_offset = buf.length;
_buf = buf;
_istd = istd;
}
public SprmBuffer(byte[] buf)
{
this(buf, false);
}
public SprmBuffer()
{
_buf = new byte[4];
_offset = 0;
}
public void addSprm(short opcode, byte operand)
{
int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE;
@ -108,6 +121,27 @@ public class SprmBuffer
return _buf;
}
public boolean equals(Object obj)
{
SprmBuffer sprmBuf = (SprmBuffer)obj;
return (Arrays.equals(_buf, sprmBuf._buf));
}
public void append(byte[] grpprl)
{
ensureCapacity(grpprl.length);
System.arraycopy(grpprl, 0, _buf, _offset, grpprl.length);
}
public Object clone()
throws CloneNotSupportedException
{
SprmBuffer retVal = (SprmBuffer)super.clone();
retVal._buf = new byte[_buf.length];
System.arraycopy(_buf, 0, retVal._buf, 0, _buf.length);
return retVal;
}
private void ensureCapacity(int addition)
{
if (_offset + addition >= _buf.length)
@ -115,7 +149,7 @@ public class SprmBuffer
// add 6 more than they need for use the next iteration
byte[] newBuf = new byte[_offset + addition + 6];
System.arraycopy(_buf, 0, newBuf, 0, _buf.length);
_buf = newBuf;
}
}
}

View File

@ -70,11 +70,18 @@ public class SprmOperation
final static private BitField TYPE_BITFIELD = new BitField(0x1c00);
final static private BitField SIZECODE_BITFIELD = new BitField(0xe000);
final static private short LONG_SPRM_TABLE = (short)0xd608;
final static private short LONG_SPRM_PARAGRAPH = (short)0xc615;
final static public int PAP_TYPE = 1;
final static public int TAP_TYPE = 5;
private int _type;
private int _operation;
private int _gOffset;
private byte[] _grpprl;
private int _sizeCode;
private int _size;
public SprmOperation(byte[] grpprl, int offset)
{
@ -87,6 +94,7 @@ public class SprmOperation
_operation = OP_BITFIELD.getValue(sprmStart);
_type = TYPE_BITFIELD.getValue(sprmStart);
_sizeCode = SIZECODE_BITFIELD.getValue(sprmStart);
_size = initSize(sprmStart);
}
public int getType()
@ -135,6 +143,15 @@ public class SprmOperation
}
public int size()
{
return _size;
}
public byte[] getGrpprl()
{
return _grpprl;
}
private int initSize(short sprm)
{
switch (_sizeCode)
{
@ -148,17 +165,20 @@ public class SprmOperation
case 3:
return 6;
case 6:
return _grpprl[_gOffset] + 3;
if (sprm == LONG_SPRM_TABLE || sprm == LONG_SPRM_PARAGRAPH)
{
int retVal = (0x0000ffff & LittleEndian.getShort(_grpprl, _gOffset)) + 3;
_gOffset += 2;
return retVal;
}
else
{
return (0x000000ff & _grpprl[_gOffset++]) + 3;
}
case 7:
return 5;
default:
throw new IllegalArgumentException("SPRM contains an invalid size code");
}
}
public byte[] getGrpprl()
{
return _grpprl;
}
}

View File

@ -77,6 +77,16 @@ public class SprmUtils
return buf;
}
public static int addSpecialSprm(short instruction, byte[] varParam, List list)
{
byte[] sprm = new byte[varParam.length + 4];
System.arraycopy(varParam, 0, sprm, 4, varParam.length);
LittleEndian.putShort(sprm, instruction);
LittleEndian.putShort(sprm, 2, (short)(varParam.length + 1));
list.add(sprm);
return sprm.length;
}
public static int addSprm(short instruction, int param, byte[] varParam, List list)
{
int type = (instruction & 0xe000) >> 13;

View File

@ -126,16 +126,16 @@ public class TableSprmCompressor
cellDescriptors[x].serialize(buf,
1+((itcMac+1)*LittleEndian.SHORT_SIZE)+(x*TableCellDescriptor.SIZE));
}
size += SprmUtils.addSprm((short)0xD608, 0, buf, sprmList);
size += SprmUtils.addSpecialSprm((short)0xD608, buf, sprmList);
buf = new byte[(itcMac * ShadingDescriptor.SIZE) + 1];
buf[0] = (byte)itcMac;
ShadingDescriptor[] shds = newTAP.getRgshd();
for (int x = 0; x < itcMac; x++)
{
shds[x].serialize(buf, 1 + (x * ShadingDescriptor.SIZE));
}
size += SprmUtils.addSprm((short)0xD608, 0, buf, sprmList);
// buf = new byte[(itcMac * ShadingDescriptor.SIZE) + 1];
// buf[0] = (byte)itcMac;
// ShadingDescriptor[] shds = newTAP.getRgshd();
// for (int x = 0; x < itcMac; x++)
// {
// shds[x].serialize(buf, 1 + (x * ShadingDescriptor.SIZE));
// }
// size += SprmUtils.addSpecialSprm((short)0xD609, buf, sprmList);
}
if (newTAP.getTlp() != 0)
{

View File

@ -67,25 +67,23 @@ public class TableSprmUncompressor
{
}
public static TableProperties uncompressTAP(TableProperties parent,
byte[] grpprl,
public static TableProperties uncompressTAP(byte[] grpprl,
int offset)
{
TableProperties newProperties = null;
try
{
newProperties = (TableProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("There is no way this exception should happen!!");
}
TableProperties newProperties = new TableProperties();
SprmIterator sprmIt = new SprmIterator(grpprl, offset);
while (sprmIt.hasNext())
{
SprmOperation sprm = (SprmOperation)sprmIt.next();
unCompressTAPOperation(newProperties, sprm);
//TAPXs are actually PAPXs so we have to make sure we are only trying to
//uncompress the right type of sprm.
if (sprm.getType() == SprmOperation.TAP_TYPE)
{
unCompressTAPOperation(newProperties, sprm);
}
}
return newProperties;

View File

@ -54,8 +54,8 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.CHPAbstractType;
import org.apache.poi.hwpf.model.hdftypes.StyleDescription;
import org.apache.poi.hwpf.model.types.CHPAbstractType;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.sprm.SprmBuffer;
@ -113,7 +113,6 @@ public class CharacterProperties
public final static short SPRM_FELID = 0x486E;
public final static short SPRM_IDCTHINT = 0x286F;
SprmBuffer _chpx;
public CharacterProperties()
{
@ -139,12 +138,7 @@ public class CharacterProperties
public void markDeleted(boolean mark)
{
if (_chpx != null && mark != isFRMarkDel())
{
byte newVal = (byte)(mark ? 1 : 0);
_chpx.addSprm(SPRM_FRMARKDEL, newVal);
super.setFRMarkDel(mark);
}
super.setFRMarkDel(mark);
}
public boolean isBold()
@ -154,12 +148,7 @@ public class CharacterProperties
public void setBold(boolean bold)
{
if (_chpx != null && bold != isFBold())
{
byte newVal = (byte)(bold ? 1 : 0);
_chpx.addSprm(SPRM_FBOLD, newVal);
super.setFBold(bold);
}
super.setFBold(bold);
}
public boolean isItalic()
@ -169,12 +158,7 @@ public class CharacterProperties
public void setItalic(boolean italic)
{
if (_chpx != null && italic != isFItalic())
{
byte newVal = (byte)(italic ? 1 : 0);
_chpx.addSprm(SPRM_FITALIC, newVal);
super.setFItalic(italic);
}
super.setFItalic(italic);
}
public boolean isOutlined()
@ -184,13 +168,7 @@ public class CharacterProperties
public void setOutline(boolean outlined)
{
if (_chpx != null && outlined != isFOutline())
{
byte newVal = (byte)(outlined ? 1 : 0);
_chpx.addSprm(SPRM_FOUTLINE, newVal);
super.setFOutline(outlined);
}
super.setFOutline(outlined);
}
public boolean isFldVanished()
@ -200,14 +178,9 @@ public class CharacterProperties
public void setFldVanish(boolean fldVanish)
{
if (_chpx != null && fldVanish != isFFldVanish())
{
byte newVal = (byte)(fldVanish ? 1 : 0);
_chpx.addSprm(SPRM_FFLDVANISH, newVal);
super.setFFldVanish(fldVanish);
}
super.setFFldVanish(fldVanish);
}
public boolean isSmallCaps()
{
return isFSmallCaps();
@ -215,13 +188,9 @@ public class CharacterProperties
public void setSmallCaps(boolean smallCaps)
{
if (_chpx != null && smallCaps != isFSmallCaps())
{
byte newVal = (byte)(smallCaps ? 1 : 0);
_chpx.addSprm(SPRM_FSMALLCAPS, newVal);
super.setFSmallCaps(smallCaps);
}
super.setFSmallCaps(smallCaps);
}
public boolean isCapitalized()
{
return isFCaps();
@ -229,12 +198,7 @@ public class CharacterProperties
public void setCapitalized(boolean caps)
{
if (_chpx != null && caps != isFCaps())
{
byte newVal = (byte)(caps ? 1 : 0);
_chpx.addSprm(SPRM_FCAPS, newVal);
super.setFCaps(caps);
}
super.setFCaps(caps);
}
public boolean isVanished()
@ -244,12 +208,7 @@ public class CharacterProperties
public void setVanished(boolean vanish)
{
if (_chpx != null && vanish != isFVanish())
{
byte newVal = (byte)(vanish ? 1 : 0);
_chpx.addSprm(SPRM_FVANISH, newVal);
super.setFVanish(vanish);
}
super.setFVanish(vanish);
}
public boolean isMarkedInserted()
@ -259,12 +218,7 @@ public class CharacterProperties
public void markInserted(boolean mark)
{
if (_chpx != null && mark != isFRMark())
{
byte newVal = (byte)(mark ? 1 : 0);
_chpx.addSprm(SPRM_FRMARK, newVal);
super.setFRMark(mark);
}
super.setFRMark(mark);
}
public boolean isStrikeThrough()
@ -274,14 +228,9 @@ public class CharacterProperties
public void strikeThrough(boolean strike)
{
if (_chpx != null && strike != isFStrike())
{
byte newVal = (byte)(strike ? 1 : 0);
_chpx.addSprm(SPRM_FSTRIKE, newVal);
super.setFStrike(strike);
}
super.setFStrike(strike);
}
public boolean isShadowed()
{
return isFShadow();
@ -289,12 +238,7 @@ public class CharacterProperties
public void setShadow(boolean shadow)
{
if (_chpx != null && shadow != isFShadow())
{
byte newVal = (byte)(shadow ? 1 : 0);
_chpx.addSprm(SPRM_FSHADOW, newVal);
super.setFShadow(shadow);
}
super.setFShadow(shadow);
}
@ -305,13 +249,7 @@ public class CharacterProperties
public void setEmbossed(boolean emboss)
{
if (_chpx != null && emboss != isFEmboss())
{
byte newVal = (byte)(emboss ? 1 : 0);
_chpx.addSprm(SPRM_FEMBOSS, newVal);
super.setFEmboss(emboss);
}
super.setFEmboss(emboss);
}
public boolean isImprinted()
@ -322,12 +260,6 @@ public class CharacterProperties
public void setImprinted(boolean imprint)
{
super.setFImprint(imprint);
if (_chpx != null && imprint != isFImprint())
{
byte newVal = (byte)(imprint ? 1 : 0);
_chpx.addSprm(SPRM_FIMPRINT, newVal);
}
}
public boolean isDoubleStrikeThrough()
@ -338,38 +270,6 @@ public class CharacterProperties
public void setDoubleStrikethrough(boolean dstrike)
{
super.setFDStrike(dstrike);
if (_chpx != null && dstrike != isFDStrike())
{
byte newVal = (byte)(dstrike ? 1 : 0);
_chpx.addSprm(SPRM_FDSTRIKE, newVal);
}
}
public void setFtcAscii(int ftcAscii)
{
super.setFtcAscii(ftcAscii);
if (_chpx != null && ftcAscii != getFtcAscii())
{
_chpx.addSprm(SPRM_RGFTCASCII, (short)ftcAscii);
}
}
public void setFtcFE(int ftcFE)
{
super.setFtcFE(ftcFE);
if (_chpx != null && ftcFE != getFtcFE())
{
_chpx.addSprm(SPRM_RGFTCFAREAST, (short)ftcFE);
}
}
public void setFtcOther(int ftcOther)
{
super.setFtcOther(ftcOther);
if (_chpx != null && ftcOther != getFtcOther())
{
_chpx.addSprm(SPRM_RGFTCNOTFAREAST, (short)ftcOther);
}
}
public int getFontSize()
@ -380,10 +280,6 @@ public class CharacterProperties
public void setFontSize(int halfPoints)
{
super.setHps(halfPoints);
if (_chpx != null && halfPoints != getHps())
{
_chpx.addSprm(SPRM_HPS, (short)halfPoints);
}
}
public int getCharacterSpacing()
@ -393,11 +289,7 @@ public class CharacterProperties
public void setCharacterSpacing(int twips)
{
super.setDxaSpace(twips);
if (_chpx != null && twips != getDxaSpace())
{
_chpx.addSprm(SPRM_DXASPACE, twips);
}
super.setDxaSpace(twips);
}
public short getSubSuperScriptIndex()
@ -408,11 +300,56 @@ public class CharacterProperties
public void setSubSuperScriptIndex(short iss)
{
super.setDxaSpace(iss);
if (_chpx != null && iss != getIss())
{
_chpx.addSprm(SPRM_DXASPACE, iss);
}
}
public int getUnderlineCode()
{
return super.getKul();
}
public void setUnderlineCode(int kul)
{
super.setKul((byte)kul);
}
public int getColor()
{
return super.getIco();
}
public void setColor(int color)
{
super.setIco((byte)color);
}
public int getVerticalOffset()
{
return super.getHpsPos();
}
public void setVerticalOffset(int hpsPos)
{
super.setHpsPos(hpsPos);
}
public int getKerning()
{
return super.getHpsKern();
}
public void setKerning(int kern)
{
super.setHpsKern(kern);
}
public boolean isHighlighted()
{
return super.isFHighlight();
}
public void setHighlighted(byte color)
{
super.setIcoHighlight(color);
}

View File

@ -54,13 +54,17 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.CHPAbstractType;
import org.apache.poi.hwpf.model.hdftypes.StyleDescription;
import org.apache.poi.hwpf.model.types.CHPAbstractType;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.model.CHPX;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
public class CharacterRun
extends CHPAbstractType implements Cloneable
extends Range
implements Cloneable
{
public final static short SPRM_FRMARKDEL = (short)0x0800;
public final static short SPRM_FRMARK = 0x0801;
@ -114,321 +118,350 @@ public class CharacterRun
public final static short SPRM_IDCTHINT = 0x286F;
SprmBuffer _chpx;
CharacterProperties _props;
public CharacterRun()
CharacterRun(CHPX chpx, StyleSheet ss, short istd, Range parent)
{
field_17_fcPic = -1;
field_22_dttmRMark = new DateAndTime();
field_23_dttmRMarkDel = new DateAndTime();
field_36_dttmPropRMark = new DateAndTime();
field_40_dttmDispFldRMark = new DateAndTime();
field_41_xstDispFldRMark = new byte[36];
field_42_shd = new ShadingDescriptor();
field_43_brc = new BorderCode();
field_7_hps = 20;
field_24_istd = 10;
field_16_wCharScale = 100;
field_13_lidDefault = 0x0400;
field_14_lidFE = 0x0400;
super(chpx.getStart(), chpx.getEnd(), parent);
_props = chpx.getCharacterProperties(ss, istd);
_chpx = chpx.getSprmBuf();
}
// SprmBuffer initProperties(CharacterProperties baseStyle)
// {
// byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(_props, baseStyle);
// _chpx = new SprmBuffer(grpprl);
// return _chpx;
// }
public boolean isMarkedDeleted()
{
return isFRMarkDel();
return _props.isFRMarkDel();
}
public void markDeleted(boolean mark)
{
super.setFRMarkDel(mark);
if (_chpx != null && mark != isFRMarkDel())
{
byte newVal = (byte)(mark ? 1 : 0);
_chpx.addSprm(SPRM_FRMARKDEL, newVal);
}
_props.setFRMarkDel(mark);
byte newVal = (byte)(mark ? 1 : 0);
_chpx.addSprm(SPRM_FRMARKDEL, newVal);
}
public boolean isBold()
{
return isFBold();
return _props.isFBold();
}
public void setBold(boolean bold)
{
super.setFBold(bold);
if (_chpx != null && bold != isFBold())
{
byte newVal = (byte)(bold ? 1 : 0);
_chpx.addSprm(SPRM_FBOLD, newVal);
}
_props.setFBold(bold);
byte newVal = (byte)(bold ? 1 : 0);
_chpx.addSprm(SPRM_FBOLD, newVal);
}
public boolean isItalic()
{
return isFItalic();
return _props.isFItalic();
}
public void setItalic(boolean italic)
{
super.setFItalic(italic);
if (_chpx != null && italic != isFItalic())
{
byte newVal = (byte)(italic ? 1 : 0);
_chpx.addSprm(SPRM_FITALIC, newVal);
}
_props.setFItalic(italic);
byte newVal = (byte)(italic ? 1 : 0);
_chpx.addSprm(SPRM_FITALIC, newVal);
}
public boolean isOutlined()
{
return isFOutline();
return _props.isFOutline();
}
public void setOutline(boolean outlined)
{
super.setFOutline(outlined);
if (_chpx != null && outlined != isFOutline())
{
byte newVal = (byte)(outlined ? 1 : 0);
_chpx.addSprm(SPRM_FOUTLINE, newVal);
}
_props.setFOutline(outlined);
byte newVal = (byte)(outlined ? 1 : 0);
_chpx.addSprm(SPRM_FOUTLINE, newVal);
}
public boolean isFldVanished()
{
return isFFldVanish();
return _props.isFFldVanish();
}
public void setFldVanish(boolean fldVanish)
{
super.setFFldVanish(fldVanish);
if (_chpx != null && fldVanish != isFFldVanish())
{
byte newVal = (byte)(fldVanish ? 1 : 0);
_chpx.addSprm(SPRM_FFLDVANISH, newVal);
}
_props.setFFldVanish(fldVanish);
byte newVal = (byte)(fldVanish ? 1 : 0);
_chpx.addSprm(SPRM_FFLDVANISH, newVal);
}
public boolean isSmallCaps()
{
return isFSmallCaps();
return _props.isFSmallCaps();
}
public void setSmallCaps(boolean smallCaps)
{
super.setFSmallCaps(smallCaps);
if (_chpx != null && smallCaps != isFSmallCaps())
{
byte newVal = (byte)(smallCaps ? 1 : 0);
_chpx.addSprm(SPRM_FSMALLCAPS, newVal);
}
_props.setFSmallCaps(smallCaps);
byte newVal = (byte)(smallCaps ? 1 : 0);
_chpx.addSprm(SPRM_FSMALLCAPS, newVal);
}
public boolean isCapitalized()
{
return isFCaps();
return _props.isFCaps();
}
public void setCapitalized(boolean caps)
{
super.setFCaps(caps);
if (_chpx != null && caps != isFCaps())
{
byte newVal = (byte)(caps ? 1 : 0);
_chpx.addSprm(SPRM_FCAPS, newVal);
}
_props.setFCaps(caps);
byte newVal = (byte)(caps ? 1 : 0);
_chpx.addSprm(SPRM_FCAPS, newVal);
}
public boolean isVanished()
{
return isFVanish();
return _props.isFVanish();
}
public void setVanished(boolean vanish)
{
super.setFVanish(vanish);
if (_chpx != null && vanish != isFVanish())
{
byte newVal = (byte)(vanish ? 1 : 0);
_chpx.addSprm(SPRM_FVANISH, newVal);
}
_props.setFVanish(vanish);
byte newVal = (byte)(vanish ? 1 : 0);
_chpx.addSprm(SPRM_FVANISH, newVal);
}
public boolean isMarkedInserted()
{
return isFRMark();
return _props.isFRMark();
}
public void markInserted(boolean mark)
{
super.setFRMark(mark);
if (_chpx != null && mark != isFRMark())
{
byte newVal = (byte)(mark ? 1 : 0);
_chpx.addSprm(SPRM_FRMARK, newVal);
}
_props.setFRMark(mark);
byte newVal = (byte)(mark ? 1 : 0);
_chpx.addSprm(SPRM_FRMARK, newVal);
}
public boolean isStrikeThrough()
{
return isFStrike();
return _props.isFStrike();
}
public void strikeThrough(boolean strike)
{
super.setFStrike(strike);
if (_chpx != null && strike != isFStrike())
{
byte newVal = (byte)(strike ? 1 : 0);
_chpx.addSprm(SPRM_FSTRIKE, newVal);
}
_props.setFStrike(strike);
byte newVal = (byte)(strike ? 1 : 0);
_chpx.addSprm(SPRM_FSTRIKE, newVal);
}
public boolean isShadowed()
{
return isFShadow();
return _props.isFShadow();
}
public void setShadow(boolean shadow)
{
super.setFShadow(shadow);
if (_chpx != null && shadow != isFShadow())
{
byte newVal = (byte)(shadow ? 1 : 0);
_chpx.addSprm(SPRM_FSHADOW, newVal);
}
_props.setFShadow(shadow);
byte newVal = (byte)(shadow ? 1 : 0);
_chpx.addSprm(SPRM_FSHADOW, newVal);
}
public boolean isEmbossed()
{
return isFEmboss();
return _props.isFEmboss();
}
public void setEmbossed(boolean emboss)
{
super.setFEmboss(emboss);
if (_chpx != null && emboss != isFEmboss())
{
byte newVal = (byte)(emboss ? 1 : 0);
_chpx.addSprm(SPRM_FEMBOSS, newVal);
}
_props.setFEmboss(emboss);
byte newVal = (byte)(emboss ? 1 : 0);
_chpx.addSprm(SPRM_FEMBOSS, newVal);
}
public boolean isImprinted()
{
return isFImprint();
return _props.isFImprint();
}
public void setImprinted(boolean imprint)
{
super.setFImprint(imprint);
if (_chpx != null && imprint != isFImprint())
{
byte newVal = (byte)(imprint ? 1 : 0);
_chpx.addSprm(SPRM_FIMPRINT, newVal);
}
_props.setFImprint(imprint);
byte newVal = (byte)(imprint ? 1 : 0);
_chpx.addSprm(SPRM_FIMPRINT, newVal);
}
public boolean isDoubleStrikeThrough()
{
return isFDStrike();
return _props.isFDStrike();
}
public void setDoubleStrikethrough(boolean dstrike)
{
super.setFDStrike(dstrike);
if (_chpx != null && dstrike != isFDStrike())
{
byte newVal = (byte)(dstrike ? 1 : 0);
_chpx.addSprm(SPRM_FDSTRIKE, newVal);
}
_props.setFDStrike(dstrike);
byte newVal = (byte)(dstrike ? 1 : 0);
_chpx.addSprm(SPRM_FDSTRIKE, newVal);
}
public void setFtcAscii(int ftcAscii)
{
super.setFtcAscii(ftcAscii);
if (_chpx != null && ftcAscii != getFtcAscii())
{
_chpx.addSprm(SPRM_RGFTCASCII, (short)ftcAscii);
}
_props.setFtcAscii(ftcAscii);
_chpx.addSprm(SPRM_RGFTCASCII, (short)ftcAscii);
}
public void setFtcFE(int ftcFE)
{
super.setFtcFE(ftcFE);
if (_chpx != null && ftcFE != getFtcFE())
{
_chpx.addSprm(SPRM_RGFTCFAREAST, (short)ftcFE);
}
_props.setFtcFE(ftcFE);
_chpx.addSprm(SPRM_RGFTCFAREAST, (short)ftcFE);
}
public void setFtcOther(int ftcOther)
{
super.setFtcOther(ftcOther);
if (_chpx != null && ftcOther != getFtcOther())
{
_chpx.addSprm(SPRM_RGFTCNOTFAREAST, (short)ftcOther);
}
_props.setFtcOther(ftcOther);
_chpx.addSprm(SPRM_RGFTCNOTFAREAST, (short)ftcOther);
}
public int getFontSize()
{
return getHps();
return _props.getHps();
}
public void setFontSize(int halfPoints)
{
super.setHps(halfPoints);
if (_chpx != null && halfPoints != getHps())
{
_chpx.addSprm(SPRM_HPS, (short)halfPoints);
}
_props.setHps(halfPoints);
_chpx.addSprm(SPRM_HPS, (short)halfPoints);
}
public int getCharacterSpacing()
{
return getDxaSpace();
return _props.getDxaSpace();
}
public void setCharacterSpacing(int twips)
{
super.setDxaSpace(twips);
if (_chpx != null && twips != getDxaSpace())
{
_chpx.addSprm(SPRM_DXASPACE, twips);
}
_props.setDxaSpace(twips);
_chpx.addSprm(SPRM_DXASPACE, twips);
}
public short getSubSuperScriptIndex()
{
return getIss();
return _props.getIss();
}
public void setSubSuperScriptIndex(short iss)
{
super.setDxaSpace(iss);
if (_chpx != null && iss != getIss())
{
_chpx.addSprm(SPRM_DXASPACE, iss);
}
_props.setDxaSpace(iss);
_chpx.addSprm(SPRM_DXASPACE, iss);
}
public int getUnderlineCode()
{
return _props.getKul();
}
public void setUnderlineCode(int kul)
{
_props.setKul((byte)kul);
_chpx.addSprm(SPRM_KUL, (byte)kul);
}
public int getColor()
{
return _props.getIco();
}
public void setColor(int color)
{
_props.setIco((byte)color);
_chpx.addSprm(SPRM_ICO, (byte)color);
}
public int getVerticalOffset()
{
return _props.getHpsPos();
}
public void setVerticalOffset(int hpsPos)
{
_props.setHpsPos(hpsPos);
_chpx.addSprm(SPRM_HPSPOS, (byte)hpsPos);
}
public int getKerning()
{
return _props.getHpsKern();
}
public void setKerning(int kern)
{
_props.setHpsKern(kern);
_chpx.addSprm(SPRM_HPSKERN, (short)kern);
}
public boolean isHighlighted()
{
return _props.isFHighlight();
}
public void setHighlighted(byte color)
{
_props.setFHighlight(true);
_props.setIcoHighlight(color);
_chpx.addSprm(SPRM_HIGHLIGHT, color);
}
public Object clone()
throws CloneNotSupportedException
{
CharacterRun cp = (CharacterRun)super.clone();
cp.field_22_dttmRMark = (DateAndTime)field_22_dttmRMark.clone();
cp.field_23_dttmRMarkDel = (DateAndTime)field_23_dttmRMarkDel.clone();
cp.field_36_dttmPropRMark = (DateAndTime)field_36_dttmPropRMark.clone();
cp.field_40_dttmDispFldRMark = (DateAndTime)field_40_dttmDispFldRMark.clone();
cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone();
cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone();
cp._props.setDttmRMark((DateAndTime)_props.getDttmRMark().clone());
cp._props.setDttmRMarkDel((DateAndTime)_props.getDttmRMarkDel().clone());
cp._props.setDttmPropRMark((DateAndTime)_props.getDttmPropRMark().clone());
cp._props.setDttmDispFldRMark((DateAndTime)_props.getDttmDispFldRMark().
clone());
cp._props.setXstDispFldRMark((byte[])_props.getXstDispFldRMark().clone());
cp._props.setShd((ShadingDescriptor)_props.getShd().clone());
return cp;
}
}

View File

@ -0,0 +1,26 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class DropCapSpecifier
{
private short _info;
private static BitField _type = new BitField(0x07);
private static BitField _lines = new BitField(0xf8);
public DropCapSpecifier(byte[] buf, int offset)
{
this(LittleEndian.getShort(buf, offset));
}
public DropCapSpecifier(short info)
{
_info = info;
}
public short toShort()
{
return _info;
}
}

View File

@ -83,6 +83,13 @@ public class LineSpacingDescriptor
_fMultiLinespace = fMultiLinespace;
}
public int toInt()
{
byte[] intHolder = new byte[4];
serialize(intHolder, 0);
return LittleEndian.getInt(intHolder);
}
public void serialize(byte[] buf, int offset)
{
LittleEndian.putShort(buf, offset, _dyaLine);

View File

@ -0,0 +1,63 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.ListTables;
import org.apache.poi.hwpf.model.ListLevel;
import org.apache.poi.hwpf.model.ListData;
import org.apache.poi.hwpf.model.ListFormatOverride;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
public class List
{
private ListData _listData;
private ListFormatOverride _override;
private boolean _registered;
private StyleSheet _styleSheet;
public List(boolean numbered, StyleSheet styleSheet)
{
_listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered);
_override = new ListFormatOverride(_listData.getLsid());
_styleSheet = styleSheet;
}
public void setLevelNumberProperties(int level, CharacterProperties chp)
{
ListLevel listLevel = _listData.getLevel(level);
int styleIndex = _listData.getLevelStyle(level);
CharacterProperties base = _styleSheet.getCharacterStyle(styleIndex);
byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(chp, base);
listLevel.setNumberProperties(grpprl);
}
public void setLevelParagraphProperties(int level, ParagraphProperties pap)
{
ListLevel listLevel = _listData.getLevel(level);
int styleIndex = _listData.getLevelStyle(level);
ParagraphProperties base = _styleSheet.getParagraphStyle(styleIndex);
byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(pap, base);
listLevel.setLevelProperties(grpprl);
}
public void setLevelStyle(int level, int styleIndex)
{
_listData.setLevelStyle(level, styleIndex);
}
public ListData getListData()
{
return _listData;
}
public ListFormatOverride getOverride()
{
return _override;
}
}

View File

@ -0,0 +1,24 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.ListFormatOverride;
import org.apache.poi.hwpf.model.ListFormatOverrideLevel;
import org.apache.poi.hwpf.model.ListLevel;
import org.apache.poi.hwpf.model.ListTables;
import org.apache.poi.hwpf.sprm.SprmBuffer;
public class ListEntry
extends Paragraph
{
ListLevel _level;
ListFormatOverrideLevel _overrideLevel;
ListEntry(int start, int end, ListTables tables,
ParagraphProperties pap, SprmBuffer sprmBuf, Range parent)
{
super(start, end, pap, sprmBuf, parent);
ListFormatOverride override = tables.getOverride(pap.getIlfo());
_overrideLevel = override.getOverrideLevel(pap.getIlvl());
_level = tables.getLevel(override.getLsid(), pap.getIlvl());
}
}

View File

@ -54,13 +54,17 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.PAPAbstractType;
import org.apache.poi.hwpf.model.hdftypes.StyleDescription;
import org.apache.poi.hwpf.model.types.PAPAbstractType;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.model.PAPX;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
import org.apache.poi.hwpf.sprm.TableSprmCompressor;
public class Paragraph
extends PAPAbstractType
extends Range
implements Cloneable
{
public final static short SPRM_JC = 0x2403;
@ -121,41 +125,379 @@ public class Paragraph
public final static short SPRM_FADJUSTRIGHT = 0x2448;
private StyleDescription _baseStyle;
private SprmBuffer _papx;
private short _istd;
private ParagraphProperties _props;
protected SprmBuffer _papx;
public Paragraph()
protected Paragraph(int startIdx, int endIdx, Table parent)
{
field_21_lspd = new LineSpacingDescriptor();
field_24_phe = new byte[12];
field_46_brcTop = new BorderCode();
field_47_brcLeft = new BorderCode();
field_48_brcBottom = new BorderCode();
field_49_brcRight = new BorderCode();
field_50_brcBetween = new BorderCode();
field_51_brcBar = new BorderCode();
field_60_anld = new byte[84];
this.field_17_fWidowControl = 1;
this.field_21_lspd.setMultiLinespace((short)1);
this.field_21_lspd.setDyaLine((short)240);
this.field_12_ilvl = (byte)9;
super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent);
PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1);
_props = papx.getParagraphProperties(_doc.getStyleSheet());
_papx = papx.getSprmBuf();
}
public Paragraph(int start, int end, ParagraphProperties pap, SprmBuffer papx, Range parent)
{
super(start, end, parent);
_props = pap;
_papx = papx;
}
public boolean isInTable()
{
return _props.getFInTable() != 0;
}
public boolean isTableRowEnd()
{
return _props.getFTtp() != 0 || _props.getFTtpEmbedded() != 0;
}
public int getTableLevel()
{
return _props.getTableLevel();
}
public boolean isEmbeddedCellMark()
{
return _props.getEmbeddedCellMark() != 0;
}
public int getJustification()
{
return _props.getJc();
}
public void setJustification(byte jc)
{
_props.setJc(jc);
_papx.addSprm(SPRM_JC, jc);
}
public boolean keepOnPage()
{
return _props.getFKeep() != 0;
}
public void setKeepOnPage(boolean fKeep)
{
byte keep = (byte)(fKeep ? 1 : 0);
_props.setFKeep(keep);
_papx.addSprm(SPRM_FKEEP, keep);
}
public boolean keepWithNext()
{
return _props.getFKeepFollow() != 0;
}
public void setKeepWithNext(boolean fKeepFollow)
{
byte keepFollow = (byte)(fKeepFollow ? 1 : 0);
_props.setFKeepFollow(keepFollow);
_papx.addSprm(SPRM_FKEEPFOLLOW, keepFollow);
}
public boolean pageBreakBefore()
{
return _props.getFPageBreakBefore() != 0;
}
public void setPageBreakBefore(boolean fPageBreak)
{
byte pageBreak = (byte)(fPageBreak ? 1 : 0);
_props.setFPageBreakBefore(pageBreak);
_papx.addSprm(SPRM_FPAGEBREAKBEFORE, pageBreak);
}
public boolean isLineNotNumbered()
{
return _props.getFNoLnn() != 0;
}
public void setLineNotNumbered(boolean fNoLnn)
{
byte noLnn = (byte)(fNoLnn ? 1 : 0);
_props.setFNoLnn(noLnn);
_papx.addSprm(SPRM_FNOLINENUMB, noLnn);
}
public boolean isSideBySide()
{
return _props.getFSideBySide() != 0;
}
public void setSideBySide(boolean fSideBySide)
{
byte sideBySide = (byte)(fSideBySide ? 1 : 0);
_props.setFSideBySide(sideBySide);
_papx.addSprm(SPRM_FSIDEBYSIDE, sideBySide);
}
public boolean isAutoHyphenated()
{
return _props.getFNoAutoHyph() == 0;
}
public void setAutoHyphenated(boolean autoHyph)
{
byte auto = (byte)(!autoHyph ? 1 : 0);
_props.setFNoAutoHyph(auto);
_papx.addSprm(SPRM_FNOAUTOHYPH, auto);
}
public boolean isWidowControlled()
{
return _props.getFWidowControl() != 0;
}
public void setWidowControl(boolean widowControl)
{
byte widow = (byte)(widowControl ? 1 : 0);
_props.setFWidowControl(widow);
_papx.addSprm(SPRM_FWIDOWCONTROL, widow);
}
public int getIndentFromRight()
{
return _props.getDxaRight();
}
public void setIndentFromRight(int dxaRight)
{
_props.setDxaRight(dxaRight);
_papx.addSprm(SPRM_DXARIGHT, (short)dxaRight);
}
public int getIndentFromLeft()
{
return _props.getDxaLeft();
}
public void setIndentFromLeft(int dxaLeft)
{
_props.setDxaLeft(dxaLeft);
_papx.addSprm(SPRM_DXALEFT, (short)dxaLeft);
}
public int getFirstLineIndent()
{
return _props.getDxaLeft1();
}
public void setFirstLineIndent(int first)
{
_props.setDxaLeft1(first);
_papx.addSprm(SPRM_DXALEFT1, (short)first);
}
public LineSpacingDescriptor getLineSpacing()
{
return _props.getLspd();
}
public void setLineSpacing(LineSpacingDescriptor lspd)
{
_props.setLspd(lspd);
_papx.addSprm(SPRM_DYALINE, lspd.toInt());
}
public int getSpacingBefore()
{
return _props.getDyaBefore();
}
public void setSpacingBefore(int before)
{
_props.setDyaBefore(before);
_papx.addSprm(SPRM_DYABEFORE, (short)before);
}
public int getSpacingAfter()
{
return _props.getDyaAfter();
}
public void setSpacingAfter(int after)
{
_props.setDyaAfter(after);
_papx.addSprm(SPRM_DYAAFTER, (short)after);
}
public boolean isKinsoku()
{
return _props.getFKinsoku() != 0;
}
public void setKinsoku(boolean kinsoku)
{
byte kin = (byte)(kinsoku ? 1 : 0);
_props.setFKinsoku(kin);
_papx.addSprm(SPRM_FKINSOKU, kin);
}
public boolean isWordWrapped()
{
return _props.getFWordWrap() != 0;
}
public void setWordWrapped(boolean wrap)
{
byte wordWrap = (byte)(wrap ? 1 : 0);
_props.setFWordWrap(wordWrap);
_papx.addSprm(SPRM_FWORDWRAP, wordWrap);
}
public int getFontAlignment()
{
return _props.getWAlignFont();
}
public void setFontAlignment(int align)
{
_props.setWAlignFont(align);
_papx.addSprm(SPRM_WALIGNFONT, (short)align);
}
public boolean isVertical()
{
return _props.isFVertical();
}
public void setVertical(boolean vertical)
{
_props.setFVertical(vertical);
_papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
}
public boolean isBackward()
{
return _props.isFBackward();
}
public void setBackward(boolean bward)
{
_props.setFBackward(bward);
_papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
}
public BorderCode getTopBorder()
{
return _props.getBrcTop();
}
public void setTopBorder(BorderCode top)
{
_props.setBrcTop(top);
_papx.addSprm(SPRM_BRCTOP, top.toInt());
}
public BorderCode getLeftBorder()
{
return _props.getBrcLeft();
}
public void setLeftBorder(BorderCode left)
{
_props.setBrcLeft(left);
_papx.addSprm(SPRM_BRCLEFT, left.toInt());
}
public BorderCode getBottomBorder()
{
return _props.getBrcBottom();
}
public void setBottomBorder(BorderCode bottom)
{
_props.setBrcBottom(bottom);
_papx.addSprm(SPRM_BRCBOTTOM, bottom.toInt());
}
public BorderCode getRightBorder()
{
return _props.getBrcRight();
}
public void setRightBorder(BorderCode right)
{
_props.setBrcRight(right);
_papx.addSprm(SPRM_BRCRIGHT, right.toInt());
}
public BorderCode getBarBorder()
{
return _props.getBrcBar();
}
public void setBarBorder(BorderCode bar)
{
_props.setBrcBar(bar);
_papx.addSprm(SPRM_BRCBAR, bar.toInt());
}
public ShadingDescriptor getShading()
{
return _props.getShd();
}
public void setShading(ShadingDescriptor shd)
{
_props.setShd(shd);
_papx.addSprm(SPRM_SHD, shd.toShort());
}
public DropCapSpecifier getDropCap()
{
return _props.getDcs();
}
public void setDropCap(DropCapSpecifier dcs)
{
_props.setDcs(dcs);
_papx.addSprm(SPRM_DCS, dcs.toShort());
}
void setTableRowEnd(TableProperties props)
{
setTableRowEnd((byte)1);
byte[] grpprl = TableSprmCompressor.compressTableProperty(props);
_papx.append(grpprl);
}
private void setTableRowEnd(byte val)
{
_props.setFTtp(val);
_papx.addSprm(SPRM_FTTP, val);
}
public Object clone()
throws CloneNotSupportedException
{
Paragraph pp = (Paragraph)super.clone();
pp.field_21_lspd = (LineSpacingDescriptor)field_21_lspd.clone();
pp.field_24_phe = (byte[])field_24_phe.clone();
pp.field_46_brcTop = (BorderCode)field_46_brcTop.clone();
pp.field_47_brcLeft = (BorderCode)field_47_brcLeft.clone();
pp.field_48_brcBottom = (BorderCode)field_48_brcBottom.clone();
pp.field_49_brcRight = (BorderCode)field_49_brcRight.clone();
pp.field_50_brcBetween = (BorderCode)field_50_brcBetween.clone();
pp.field_51_brcBar = (BorderCode)field_51_brcBar.clone();
pp.field_60_anld = (byte[])field_60_anld.clone();
return pp;
Paragraph p = (Paragraph)super.clone();
p._props = (ParagraphProperties)_props.clone();
//p._baseStyle = _baseStyle;
p._papx = new SprmBuffer();
return p;
}
private short getFrameTextFlow()
{
short retVal = 0;
if (_props.isFVertical())
{
retVal |= 1;
}
if (_props.isFBackward())
{
retVal |= 2;
}
if (_props.isFRotateFont())
{
retVal |= 4;
}
return retVal;
}
}

View File

@ -54,8 +54,8 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.PAPAbstractType;
import org.apache.poi.hwpf.model.hdftypes.StyleDescription;
import org.apache.poi.hwpf.model.types.PAPAbstractType;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.sprm.SprmBuffer;
@ -139,9 +139,272 @@ public class ParagraphProperties
this.field_21_lspd.setMultiLinespace((short)1);
this.field_21_lspd.setDyaLine((short)240);
this.field_12_ilvl = (byte)9;
this.field_66_rgdxaTab = new int[0];
this.field_67_rgtbd = new byte[0];
this.field_63_dttmPropRMark = new DateAndTime();
}
public int getJustification()
{
return super.getJc();
}
public void setJustification(byte jc)
{
super.setJc(jc);
}
public boolean keepOnPage()
{
return super.getFKeep() != 0;
}
public void setKeepOnPage(boolean fKeep)
{
super.setFKeep((byte)(fKeep ? 1 : 0));
}
public boolean keepWithNext()
{
return super.getFKeepFollow() != 0;
}
public void setKeepWithNext(boolean fKeepFollow)
{
super.setFKeepFollow((byte)(fKeepFollow ? 1 : 0));
}
public boolean pageBreakBefore()
{
return super.getFPageBreakBefore() != 0;
}
public void setPageBreakBefore(boolean fPageBreak)
{
super.setFPageBreakBefore((byte)(fPageBreak ? 1 : 0));
}
public boolean isLineNotNumbered()
{
return super.getFNoLnn() != 0;
}
public void setLineNotNumbered(boolean fNoLnn)
{
super.setFNoLnn((byte)(fNoLnn ? 1 : 0));
}
public boolean isSideBySide()
{
return super.getFSideBySide() != 0;
}
public void setSideBySide(boolean fSideBySide)
{
super.setFSideBySide((byte)(fSideBySide ? 1 : 0));
}
public boolean isAutoHyphenated()
{
return super.getFNoAutoHyph() == 0;
}
public void setAutoHyphenated(boolean auto)
{
super.setFNoAutoHyph((byte)(!auto ? 1 : 0));
}
public boolean isWidowControlled()
{
return super.getFWidowControl() != 0;
}
public void setWidowControl(boolean widowControl)
{
super.setFWidowControl((byte)(widowControl ? 1 : 0));
}
public int getIndentFromRight()
{
return super.getDxaRight();
}
public void setIndentFromRight(int dxaRight)
{
super.setDxaRight(dxaRight);
}
public int getIndentFromLeft()
{
return super.getDxaLeft();
}
public void setIndentFromLeft(int dxaLeft)
{
super.setDxaLeft(dxaLeft);
}
public int getFirstLineIndent()
{
return super.getDxaLeft1();
}
public void setFirstLineIndent(int first)
{
super.setDxaLeft1(first);
}
public LineSpacingDescriptor getLineSpacing()
{
return super.getLspd();
}
public void setLineSpacing(LineSpacingDescriptor lspd)
{
super.setLspd(lspd);
}
public int getSpacingBefore()
{
return super.getDyaBefore();
}
public void setSpacingBefore(int before)
{
super.setDyaBefore(before);
}
public int getSpacingAfter()
{
return super.getDyaAfter();
}
public void setSpacingAfter(int after)
{
super.setDyaAfter(after);
}
public boolean isKinsoku()
{
return super.getFKinsoku() != 0;
}
public void setKinsoku(boolean kinsoku)
{
super.setFKinsoku((byte)(kinsoku ? 1 : 0));
}
public boolean isWordWrapped()
{
return super.getFWordWrap() != 0;
}
public void setWordWrapped(boolean wrap)
{
super.setFWordWrap((byte)(wrap ? 1 : 0));
}
public int getFontAlignment()
{
return super.getWAlignFont();
}
public void setFontAlignment(int align)
{
super.setWAlignFont(align);
}
public boolean isVertical()
{
return super.isFVertical();
}
public void setVertical(boolean vertical)
{
super.setFVertical(vertical);
}
public boolean isBackward()
{
return super.isFBackward();
}
public void setBackward(boolean bward)
{
super.setFBackward(bward);
}
public BorderCode getTopBorder()
{
return super.getBrcTop();
}
public void setTopBorder(BorderCode top)
{
super.setBrcTop(top);
}
public BorderCode getLeftBorder()
{
return super.getBrcLeft();
}
public void setLeftBorder(BorderCode left)
{
super.setBrcLeft(left);
}
public BorderCode getBottomBorder()
{
return super.getBrcBottom();
}
public void setBottomBorder(BorderCode bottom)
{
super.setBrcBottom(bottom);
}
public BorderCode getRightBorder()
{
return super.getBrcRight();
}
public void setRightBorder(BorderCode right)
{
super.setBrcRight(right);
}
public BorderCode getBarBorder()
{
return super.getBrcBar();
}
public void setBarBorder(BorderCode bar)
{
super.setBrcBar(bar);
}
public ShadingDescriptor getShading()
{
return super.getShd();
}
public void setShading(ShadingDescriptor shd)
{
super.setShd(shd);
}
public DropCapSpecifier getDropCap()
{
return super.getDcs();
}
public void setDropCap(DropCapSpecifier dcs)
{
super.setDcs(dcs);
}
public Object clone()
throws CloneNotSupportedException
{

View File

@ -0,0 +1,531 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.usermodel.Section;
import org.apache.poi.hwpf.model.PropertyNode;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.model.CHPBinTable;
import org.apache.poi.hwpf.model.CHPX;
import org.apache.poi.hwpf.model.PAPX;
import org.apache.poi.hwpf.model.SEPX;
import org.apache.poi.hwpf.model.PAPBinTable;
import org.apache.poi.hwpf.model.SectionTable;
import org.apache.poi.hwpf.model.TextPieceTable;
import org.apache.poi.hwpf.model.TextPiece;
import org.apache.poi.hwpf.model.ListTables;
import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor;
import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
import org.apache.poi.hwpf.sprm.SectionSprmUncompressor;
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
public class Range
{
public static final int PARAGRAPH_INDEX = 0;
public static final int CHARACTER_INDEX = 1;
public static final int SECTION_INDEX = 2;
public static final int TEXT_INDEX = 3;
private WeakReference _parent;
protected int _start;
protected int _end;
protected HWPFDocument _doc;
boolean _sectionRangeFound;
protected List _sections;
int _sectionStart;
int _sectionEnd;
boolean _parRangeFound;
protected List _paragraphs;
protected int _parStart;
protected int _parEnd;
boolean _charRangeFound;
protected List _characters;
int _charStart;
int _charEnd;
boolean _textRangeFound;
protected List _text;
int _textStart;
int _textEnd;
// protected Range()
// {
//
// }
public Range(int start, int end, HWPFDocument doc)
{
_start = start;
_end = end;
_doc = doc;
_sections = _doc.getSectionTable().getSections();
_paragraphs = _doc.getParagraphTable().getParagraphs();
_characters = _doc.getCharacterTable().getTextRuns();
_text = _doc.getTextTable().getTextPieces();
_parent = new WeakReference(null);
}
protected Range(int start, int end, Range parent)
{
_start = start;
_end = end;
_doc = parent._doc;
_sections = parent._sections;
_paragraphs = parent._paragraphs;
_characters = parent._characters;
_text = parent._text;
_parent = new WeakReference(parent);
}
protected Range(int startIdx, int endIdx, int idxType, Range parent)
{
_doc = parent._doc;
_sections = parent._sections;
_paragraphs = parent._paragraphs;
_characters = parent._characters;
_text = parent._text;
_parent = new WeakReference(parent);
switch (idxType)
{
case PARAGRAPH_INDEX:
_parStart = parent._parStart + startIdx;
_parEnd = parent._parStart + endIdx;
_start = ((PropertyNode)_paragraphs.get(_parStart)).getStart();
_end = ((PropertyNode)_paragraphs.get(_parEnd)).getEnd();
_parRangeFound = true;
break;
case CHARACTER_INDEX:
_charStart = parent._charStart + startIdx;
_charEnd = parent._charStart + endIdx;
_start = ((PropertyNode)_characters.get(_charStart)).getStart();
_end = ((PropertyNode)_characters.get(_charEnd)).getEnd();
_charRangeFound = true;
break;
case SECTION_INDEX:
_sectionStart = parent._sectionStart + startIdx;
_sectionEnd = parent._sectionStart + endIdx;
_start = ((PropertyNode)_sections.get(_sectionStart)).getStart();
_end = ((PropertyNode)_sections.get(_sectionEnd)).getEnd();
_sectionRangeFound = true;
break;
case TEXT_INDEX:
_textStart = parent._textStart + startIdx;
_textEnd = parent._textStart + endIdx;
_start = ((PropertyNode)_text.get(_textStart)).getStart();
_end = ((PropertyNode)_text.get(_textEnd)).getEnd();
_textRangeFound = true;
break;
}
}
public String text()
{
initText();
StringBuffer sb = new StringBuffer();
for (int x = _textStart; x < _textEnd; x++)
{
TextPiece piece = (TextPiece)_text.get(x);
int start = _start > piece.getStart() ? _start - piece.getStart() : 0;
int end = _end <= piece.getEnd() ? _end - piece.getStart() : piece.getEnd() - piece.getStart();
sb.append(piece.getStringBuffer().substring(start, end));
}
return sb.toString();
}
public int numSections()
{
initSections();
return _sectionEnd - _sectionStart;
}
public int numParagraphs()
{
initParagraphs();
return _parEnd - _parStart;
}
public int numCharacterRuns()
{
initCharacterRuns();
return _charEnd - _charStart;
}
public CharacterRun insertBefore(String text)
//throws UnsupportedEncodingException
{
initAll();
TextPiece tp = (TextPiece)_text.get(_textStart);
StringBuffer sb = (StringBuffer)tp.getStringBuffer();
// Since this is the first item in our list, it is safe to assume that
// _start >= tp.getStart()
int insertIndex = _start - tp.getStart();
sb.insert(insertIndex, text);
int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length());
_doc.getCharacterTable().adjustForInsert(_textStart, adjustedLength);
_doc.getParagraphTable().adjustForInsert(_textStart, adjustedLength);
_doc.getSectionTable().adjustForInsert(_textStart, adjustedLength);
adjustForInsert(text.length());
return getCharacterRun(0);
}
public CharacterRun insertAfter(String text)
{
initAll();
int listIndex = _textEnd - 1;
TextPiece tp = (TextPiece)_text.get(listIndex);
StringBuffer sb = (StringBuffer)tp.getStringBuffer();
int insertIndex = _end - tp.getStart();
sb.insert(insertIndex, text);
int adjustedLength = _doc.getTextTable().adjustForInsert(listIndex, text.length());
_doc.getCharacterTable().adjustForInsert(_charEnd - 1, adjustedLength);
_doc.getParagraphTable().adjustForInsert(_parEnd - 1, adjustedLength);
_doc.getSectionTable().adjustForInsert(_sectionEnd - 1, adjustedLength);
adjustForInsert(text.length());
return getCharacterRun(numCharacterRuns() - 1);
}
public CharacterRun insertBefore(String text, CharacterProperties props)
//throws UnsupportedEncodingException
{
initAll();
PAPX papx = (PAPX)_paragraphs.get(_parStart);
short istd = papx.getIstd();
StyleSheet ss = _doc.getStyleSheet();
CharacterProperties baseStyle = ss.getCharacterStyle(istd);
byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
SprmBuffer buf = new SprmBuffer(grpprl);
_doc.getCharacterTable().insert(_charStart, _start, buf);
return insertBefore(text);
}
public CharacterRun insertAfter(String text, CharacterProperties props)
//throws UnsupportedEncodingException
{
initAll();
PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1);
short istd = papx.getIstd();
StyleSheet ss = _doc.getStyleSheet();
CharacterProperties baseStyle = ss.getCharacterStyle(istd);
byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
SprmBuffer buf = new SprmBuffer(grpprl);
_doc.getCharacterTable().insert(_charEnd, _end, buf);
_charEnd++;
return insertAfter(text);
}
public Paragraph insertBefore(ParagraphProperties props, int styleIndex)
//throws UnsupportedEncodingException
{
return this.insertBefore(props, styleIndex, "\r");
}
protected Paragraph insertBefore(ParagraphProperties props, int styleIndex, String text)
//throws UnsupportedEncodingException
{
initAll();
StyleSheet ss = _doc.getStyleSheet();
ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, (short)styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex);
_doc.getParagraphTable().insert(_parStart, _start, buf);
insertBefore(text, baseChp);
return getParagraph(0);
}
public Paragraph insertAfter(ParagraphProperties props, int styleIndex)
//throws UnsupportedEncodingException
{
return this.insertAfter(props, styleIndex, "\r");
}
protected Paragraph insertAfter(ParagraphProperties props, int styleIndex, String text)
//throws UnsupportedEncodingException
{
initAll();
StyleSheet ss = _doc.getStyleSheet();
ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, (short)styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex);
_doc.getParagraphTable().insert(_parEnd, _end, buf);
_parEnd++;
insertAfter(text, baseChp);
return getParagraph(numParagraphs() - 1);
}
public Table insertBefore(TableProperties props, int rows)
{
ParagraphProperties parProps = new ParagraphProperties();
parProps.setFInTable((byte)1);
parProps.setTableLevel((byte)1);
int columns = props.getItcMac();
for (int x = 0; x < rows; x++)
{
Paragraph cell = this.insertBefore(parProps, StyleSheet.NIL_STYLE);
cell.insertAfter(String.valueOf('\u0007'));
for(int y = 1; y < columns; y++)
{
cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE);
cell.insertAfter(String.valueOf('\u0007'));
}
cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE, String.valueOf('\u0007'));
cell.setTableRowEnd(props);
}
return new Table(_start, _start + (rows * (columns + 1)), this, 0);
}
public ListEntry insertBefore(ParagraphProperties props, int listID, int level, int styleIndex)
//throws UnsupportedEncodingException
{
ListTables lt = _doc.getListTables();
if (lt.getLevel(listID, level) == null)
{
throw new NoSuchElementException("The specified list and level do not exist");
}
int ilfo = lt.getOverrideIndexFromListID(listID);
props.setIlfo(ilfo);
props.setIlvl((byte)level);
return (ListEntry)insertBefore(props, styleIndex);
}
public CharacterRun getCharacterRun(int index)
{
initCharacterRuns();
CHPX chpx = (CHPX)_characters.get(index + _charStart);
int[] point = findRange(_paragraphs, _parStart, chpx.getStart(),
chpx.getEnd());
PAPX papx = (PAPX)_paragraphs.get(point[0]);
short istd = papx.getIstd();
CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
return chp;
}
public Section getSection(int index)
{
initSections();
SEPX sepx = (SEPX)_sections.get(index + _sectionStart);
Section sep = new Section(sepx, this);
return sep;
}
public Paragraph getParagraph(int index)
{
initParagraphs();
PAPX papx = (PAPX)_paragraphs.get(index + _parStart);
ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet());
Paragraph pap = null;
if (props.getIlfo() > 0)
{
pap = new ListEntry(papx.getStart(), papx.getEnd(), _doc.getListTables(),
props, papx.getSprmBuf(), this);
}
else
{
pap = new Paragraph(papx.getStart(), papx.getEnd(), props,
papx.getSprmBuf(), this);
}
return pap;
}
private void initAll()
{
initText();
initCharacterRuns();
initParagraphs();
initSections();
}
private void initParagraphs()
{
if (!_parRangeFound)
{
int[] point = findRange(_paragraphs, _parStart, _start, _end);
_parStart = point[0];
_parEnd = point[1];
_parRangeFound = true;
}
}
private void initCharacterRuns()
{
if (!_charRangeFound)
{
int[] point = findRange(_characters, _charStart, _start, _end);
_charStart = point[0];
_charEnd = point[1];
_charRangeFound = true;
}
}
private void initText()
{
if (!_textRangeFound)
{
int[] point = findRange(_text, _textStart, _start, _end);
_textStart = point[0];
_textEnd = point[1];
_textRangeFound = true;
}
}
private void initSections()
{
if (!_sectionRangeFound)
{
int[] point = findRange(_sections, _sectionStart, _start, _end);
_sectionStart = point[0];
_sectionEnd = point[1];
_sectionRangeFound = true;
}
}
private int[] findRange(List rpl, int min, int start, int end)
{
int x = min;
PropertyNode node = (PropertyNode)rpl.get(x);
while(node.getEnd() <= start)
{
x++;
node = (PropertyNode)rpl.get(x);
}
int y = x;
node = (PropertyNode)rpl.get(y);
while(node.getEnd() < end)
{
y++;
node = (PropertyNode)rpl.get(y);
}
return new int[]{x, y + 1};
}
private void reset()
{
_textRangeFound = false;
_charRangeFound = false;
_parRangeFound = false;
_sectionRangeFound = false;
}
private void adjustForInsert(int length)
{
_end += length;
reset();
Range parent = (Range)_parent.get();
if (parent != null)
{
parent.adjustForInsert(length);
}
}
}

View File

@ -54,31 +54,27 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
import org.apache.poi.hwpf.model.SEPX;
public class Section
extends SEPAbstractType
extends Range
{
public Section()
private SectionProperties _props;
public Section(SEPX sepx, Range parent)
{
field_20_brcTop = new BorderCode();
field_21_brcLeft = new BorderCode();
field_22_brcBottom = new BorderCode();
field_23_brcRight = new BorderCode();
field_26_dttmPropRMark = new DateAndTime();
super(sepx.getStart(), sepx.getEnd(), parent);
_props = sepx.getSectionProperties();
}
public Object clone()
throws CloneNotSupportedException
{
Section copy = (Section)super.clone();
copy.field_20_brcTop = (BorderCode)field_20_brcTop.clone();
copy.field_21_brcLeft = (BorderCode)field_21_brcLeft.clone();
copy.field_22_brcBottom = (BorderCode)field_22_brcBottom.clone();
copy.field_23_brcRight = (BorderCode)field_23_brcRight.clone();
copy.field_26_dttmPropRMark = (DateAndTime)field_26_dttmPropRMark.clone();
throws CloneNotSupportedException
{
Section s = (Section)super.clone();
s._props = (SectionProperties)_props.clone();
return s;
}
return copy;
}
}

View File

@ -54,7 +54,11 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
import org.apache.poi.hwpf.model.types.SEPAbstractType;
import java.lang.reflect.Field;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
public class SectionProperties
extends SEPAbstractType
@ -81,4 +85,31 @@ public class SectionProperties
return copy;
}
public boolean equals(Object obj)
{
Field[] fields = SectionProperties.class.getSuperclass().getDeclaredFields();
AccessibleObject.setAccessible(fields, true);
try
{
for (int x = 0; x < fields.length; x++)
{
Object obj1 = fields[x].get(this);
Object obj2 = fields[x].get(obj);
if (obj1 == null && obj2 == null)
{
continue;
}
if (!obj1.equals(obj2))
{
return false;
}
}
return true;
}
catch (Exception e)
{
return false;
}
}
}

View File

@ -73,7 +73,12 @@ public class ShadingDescriptor
public ShadingDescriptor(byte[] buf, int offset)
{
_info = LittleEndian.getShort(buf, offset);
this(LittleEndian.getShort(buf, offset));
}
public ShadingDescriptor(short info)
{
_info = info;
}
public short toShort()

View File

@ -0,0 +1,40 @@
package org.apache.poi.hwpf.usermodel;
import java.util.ArrayList;
public class Table
extends Range
{
ArrayList _rows;
Table(int startIdx, int endIdx, Range parent, int levelNum)
{
super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent);
_rows = new ArrayList();
int numParagraphs = numParagraphs();
int rowStart = 0;
int rowEnd = 0;
while (rowEnd < numParagraphs)
{
Paragraph p = getParagraph(rowEnd);
rowEnd++;
if (p.isTableRowEnd() && p.getTableLevel() == levelNum)
{
_rows.add(new TableRow(rowStart, rowEnd, this, levelNum));
rowStart = rowEnd;
}
}
}
public int numRows()
{
return _rows.size();
}
public TableRow getRow(int index)
{
return (TableRow)_rows.get(index);
}
}

View File

@ -0,0 +1,16 @@
package org.apache.poi.hwpf.usermodel;
public class TableCell
extends Range
{
int _levelNum;
public TableCell(int startIdx, int endIdx, TableRow parent, int levelNum, TableCellDescriptor tcd)
{
super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent);
_levelNum = levelNum;
}
}

View File

@ -54,7 +54,7 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.TCAbstractType;
import org.apache.poi.hwpf.model.types.TCAbstractType;
public class TableCellDescriptor
extends TCAbstractType
@ -63,6 +63,11 @@ public class TableCellDescriptor
public TableCellDescriptor()
{
field_3_brcTop = new BorderCode();
field_4_brcLeft = new BorderCode();
field_5_brcBottom = new BorderCode();
field_6_brcRight = new BorderCode();
}
public Object clone()

View File

@ -0,0 +1,58 @@
package org.apache.poi.hwpf.usermodel;
import java.util.ArrayList;
public class TableIterator
{
Range _range;
int _index;
int _levelNum;
TableIterator(Range range, int levelNum)
{
_range = range;
_index = 0;
_levelNum = levelNum;
}
public TableIterator(Range range)
{
this(range, 1);
}
public boolean hasNext()
{
int numParagraphs = _range.numParagraphs();
for (;_index < numParagraphs; _index++)
{
Paragraph paragraph = _range.getParagraph(_index);
if (paragraph.isInTable() && paragraph.getTableLevel() == _levelNum)
{
return true;
}
}
return false;
}
public Table next()
{
int numParagraphs = _range.numParagraphs();
int numRows = 0;
int startIndex = _index;
int endIndex = _index;
for (;_index < numParagraphs; _index++)
{
Paragraph paragraph = _range.getParagraph(_index);
if (!paragraph.isInTable() || paragraph.getTableLevel() < _levelNum)
{
endIndex = _index;
break;
}
}
return new Table(startIndex, endIndex, _range, _levelNum);
}
}

View File

@ -54,14 +54,37 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.TAPAbstractType;
import org.apache.poi.hwpf.model.types.TAPAbstractType;
public class TableProperties
extends TAPAbstractType
implements Cloneable
{
public TableProperties()
{
}
public TableProperties(int columns)
{
field_7_itcMac = (short)columns;
field_10_rgshd = new ShadingDescriptor[columns];
for (int x = 0; x < columns; x++)
{
field_10_rgshd[x] = new ShadingDescriptor();
}
field_11_brcBottom = new BorderCode();
field_12_brcTop = new BorderCode();
field_13_brcLeft = new BorderCode();
field_14_brcRight = new BorderCode();
field_15_brcVertical = new BorderCode();
field_16_brcHorizontal = new BorderCode();
field_8_rgdxaCenter = new short[columns];
field_9_rgtc = new TableCellDescriptor[columns];
for (int x = 0; x < columns; x++)
{
field_9_rgtc[x] = new TableCellDescriptor();
}
}
public Object clone()

View File

@ -0,0 +1,100 @@
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
import org.apache.poi.hwpf.sprm.SprmBuffer;
public class TableRow
extends Paragraph
{
private final static char TABLE_CELL_MARK = '\u0007';
private final static short SPRM_TJC = 0x5400;
private final static short SPRM_DXAGAPHALF = (short)0x9602;
private final static short SPRM_FCANTSPLIT = 0x3403;
private final static short SPRM_FTABLEHEADER = 0x3404;
private final static short SPRM_DYAROWHEIGHT = (short)0x9407;
int _levelNum;
TableProperties _tprops;
TableCell[] _cells;
public TableRow(int startIdx, int endIdx, Table parent, int levelNum)
{
super(startIdx, endIdx, parent);
_tprops = TableSprmUncompressor.uncompressTAP(_papx.toByteArray(), 2);
_levelNum = levelNum;
_cells = new TableCell[_tprops.getItcMac()];
int start = 0;
int cellIndex = 0;
for (int x = 0; x < numParagraphs(); x++)
{
Paragraph p = getParagraph(x);
String s = p.text();
if ((levelNum == 1 && s.charAt(s.length()-1) == TABLE_CELL_MARK) ||
p.isEmbeddedCellMark() && p.getTableLevel() == levelNum)
{
_cells[cellIndex] = new TableCell(start, x+1, this, levelNum, _tprops.getRgtc()[cellIndex]);
}
}
}
public int getRowJustification()
{
return _tprops.getJc();
}
public void setRowJustification(int jc)
{
_tprops.setJc(jc);
_papx.addSprm(SPRM_TJC, (short)jc);
}
public int getGapHalf()
{
return _tprops.getDxaGapHalf();
}
public void setGapHalf(int dxaGapHalf)
{
_tprops.setDxaGapHalf(dxaGapHalf);
_papx.addSprm(SPRM_DXAGAPHALF, (short)dxaGapHalf);
}
public int getRowHeight()
{
return _tprops.getDyaRowHeight();
}
public void setRowHeight(int dyaRowHeight)
{
_tprops.setDyaRowHeight(dyaRowHeight);
_papx.addSprm(SPRM_DYAROWHEIGHT, (short)dyaRowHeight);
}
public boolean cantSplit()
{
return _tprops.getFCantSplit();
}
public void setCantSplit(boolean cantSplit)
{
_tprops.setFCantSplit(cantSplit);
_papx.addSprm(SPRM_FCANTSPLIT, (byte)(cantSplit ? 1 : 0));
}
public boolean isTableHeader()
{
return _tprops.getFTableHeader();
}
public void setTableHeader(boolean tableHeader)
{
_tprops.setFTableHeader(tableHeader);
_papx.addSprm(SPRM_FTABLEHEADER, (byte)(tableHeader ? 1 : 0));
}
}

View File

@ -0,0 +1,85 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf;
import junit.framework.*;
public class AllTests
extends TestCase
{
public AllTests(String s)
{
super(s);
}
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(org.apache.poi.hwpf.model.TestCHPBinTable.class);
suite.addTestSuite(org.apache.poi.hwpf.model.
TestDocumentProperties.class);
suite.addTestSuite(org.apache.poi.hwpf.model.
TestFileInformationBlock.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestFontTable.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestPAPBinTable.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestPlexOfCps.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestSectionTable.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestStyleSheet.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestTextPieceTable.class);
suite.addTestSuite(org.apache.poi.hwpf.model.TestListTables.class);
return suite;
}
}

View File

@ -5,7 +5,7 @@ import java.io.FileInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.hwpf.model.hdftypes.*;
import org.apache.poi.hwpf.model.*;
import java.io.File;
@ -30,7 +30,7 @@ public class HWPFDocFixture
filename = "c:";
}
filename = filename + "/test.doc";
filename = filename + "/test99.doc";
POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream(

View File

@ -0,0 +1,40 @@
package org.apache.poi.hwpf.model;
import junit.framework.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.model.io.*;
import java.io.*;
import java.util.*;
public class TestListTables
extends HWPFTestCase
{
public TestListTables()
{
}
public void testReadWrite()
throws Exception
{
FileInformationBlock fib = _hWPFDocFixture._fib;
byte[] tableStream = _hWPFDocFixture._tableStream;
ListTables listTables = new ListTables(tableStream, fib.getFcPlcfLst(), fib.getFcPlfLfo());
HWPFFileSystem fileSys = new HWPFFileSystem();
HWPFOutputStream tableOut = fileSys.getStream("1Table");
listTables.writeListDataTo(tableOut);
int offset = tableOut.getOffset();
listTables.writeListOverridesTo(tableOut);
ListTables newTables = new ListTables(tableOut.toByteArray(), 0, offset);
assertEquals(listTables, newTables);
}
}