-/*
- * ====================================================================
- * 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/>.
- */
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+
package org.apache.poi.hwpf;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
+import java.util.Iterator;
+
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.common.POIFSConstants;
/** Holds fonts for this document.*/
private FontTable _ft;
+ /** Hold list tables */
private ListTables _lt;
return new Range(0, p.getEnd(), this);
}
+ /**
+ * Returns the character length of a document.
+ * @return
+ */
+ public int characterLength()
+ {
+ java.util.List textPieces = _tpt.getTextPieces();
+ Iterator textIt = textPieces.iterator();
+
+ int length = 0;
+ while(textIt.hasNext())
+ {
+ TextPiece tp = (TextPiece)textIt.next();
+ length += tp.characterLength();
+ }
+ return length;
+ }
+
public ListTables getListTables()
{
return _lt;
return _ft;
}
+ public void delete(int start, int length)
+ {
+ Range r = new Range(start, start + length, this);
+ r.delete();
+ }
+
/**
* Takes two arguments, 1) name of the Word file to read in 2) location to
* write it out at.
offset += _fontSig.length;
offsetTmp = offset - offsetTmp;
- _xszFfnLength = this.getSize() - offsetTmp;
+ _xszFfnLength = (this.getSize() - offsetTmp)/2;
_xszFfn = new char[_xszFfnLength];
for(int i = 0; i < _xszFfnLength; i++)
for(int i = 0; i < _xszFfn.length; i++)
{
- buf[offset] = (byte)_xszFfn[i];
- offset += LittleEndian.BYTE_SIZE;
+ LittleEndian.putShort(buf, offset, (short)_xszFfn[i]);
+ offset += LittleEndian.SHORT_SIZE;
}
- return buf;
+ return buf;
- }
+ }
public boolean equals(Object o)
{
for(int i = 0; i < _fontNames.length; i++)
{
- tableStream.write(_fontNames[i].toByteArray());
+ tableStream.write(_fontNames[i].toByteArray());
}
}
int maxHugeGrpprlSize = LittleEndian.getUShort(_dataStream,
hugeGrpprlOffset);
- if (maxHugeGrpprlSize < grpprl.length)
+ if (maxHugeGrpprlSize < grpprl.length-2) // grpprl.length-2 because we don't store the istd
throw new UnsupportedOperationException(
"This Paragraph's dataStream storage is too small.");
}
// store grpprl at hugeGrpprlOffset
System.arraycopy(grpprl, 2, _dataStream, hugeGrpprlOffset + 2,
- grpprl.length);
- LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length);
+ grpprl.length - 2); // grpprl.length-2 because we don't store the istd
+ LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length - 2);
// grpprl = grpprl containing only a sprmPHugePapx2
int istd = LittleEndian.getUShort(grpprl, 0);
_cpEnd = end;
}
+ /**
+ * Adjust for a deletion that can span multiple PropertyNodes.
+ * @param start
+ * @param length
+ */
+ public void adjustForDelete(int start, int length)
+ {
+ int end = start + length;
+
+ if (_cpEnd > start)
+ {
+ if (_cpStart < end)
+ {
+ _cpEnd = end >= _cpEnd ? start : _cpEnd - length;
+ _cpStart = Math.min(start, _cpStart);
+ }
+ else
+ {
+ _cpEnd -= length;
+ _cpStart -= length;
+ }
+ }
+ }
protected boolean limitsAreEqual(Object o)
{
/* ====================================================================
- * 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/>.
- */
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hwpf.model;
public class TextPiece extends PropertyNode implements Comparable
{
private boolean _usesUnicode;
- private int _length;
+
private PieceDescriptor _pd;
/**
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;
+ /** start - end is length on file. This is double the expected when its
+ * unicode.*/
+ super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252")));
+ _usesUnicode = pd.isUnicode();
+ _pd = pd;
}
/**
* @return If this text piece uses unicode
return ((StringBuffer)_buf).substring(start/denominator, end/denominator);
}
+ public void adjustForDelete(int start, int length)
+ {
+
+ }
+
+ public int characterLength()
+ {
+ return (getEnd() - getStart()) / (_usesUnicode ? 2 : 1);
+ }
+
public boolean equals(Object o)
{
if (limitsAreEqual(o))
int size = _textPieces.size();
TextPiece tp = (TextPiece)_textPieces.get(listIndex);
+
+ //The text piece stores the length on file.
length = length * (tp.usesUnicode() ? 2 : 1);
tp.setEnd(tp.getEnd() + length);
for (int x = listIndex + 1; x < size; x++)
{
return true;
}
- else if ((x & 0x80) == 0x80)
+ else if ((x & 0x81) == 0x80)
{
return oldVal;
}
cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone();
cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone();
+ cp._ico24 = _ico24;
+
return cp;
}
--- /dev/null
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+/**
+ * @author Ryan Ackley
+ */
+package org.apache.poi.hwpf.usermodel;
+
+import org.apache.poi.hwpf.HWPFDocument;
+
+public class DocumentPosition
+ extends Range
+{
+ public DocumentPosition(HWPFDocument doc, int pos)
+ {
+ super(pos, pos, doc);
+ }
+
+}
\ No newline at end of file
* org.apache.poi.hwpf.HWPFDocument#registerList(HWPFList) registerList} in
* {@link org.apache.poi.hwpf.HWPFDocument HWPFDocument}.
*
- * In Word, lists are not ranged entities. Lists only act as properties for
- * list entries. Once you register a list, you can add list entries to a
- * document that use the list.
+ * In Word, lists are not ranged entities, meaning you can't actually add one
+ * to the document. Lists only act as properties for list entries. Once you
+ * register a list, you can add list entries to a document that are a part of
+ * the list.
+ *
+ * The only benefit of this that I see, is that you can add a list entry
+ * anywhere in the document and continue numbering from the previous list.
*
* @author Ryan Ackley
*/
private boolean _registered;
private StyleSheet _styleSheet;
+ /**
+ *
+ * @param numbered true if the list should be numbered; false if it should be
+ * bulleted.
+ * @param styleSheet The document's stylesheet.
+ */
public HWPFList(boolean numbered, StyleSheet styleSheet)
{
_listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered);
_styleSheet = styleSheet;
}
+ /**
+ * Sets the character properties of the list numbers.
+ *
+ * @param level the level number that the properties should apply to.
+ * @param chp The character properties.
+ */
public void setLevelNumberProperties(int level, CharacterProperties chp)
{
ListLevel listLevel = _listData.getLevel(level);
listLevel.setNumberProperties(grpprl);
}
+ /**
+ * Sets the paragraph properties for a particular level of the list.
+ *
+ * @param level The level number.
+ * @param pap The paragraph properties
+ */
public void setLevelParagraphProperties(int level, ParagraphProperties pap)
{
ListLevel listLevel = _listData.getLevel(level);
public void setJustification(byte jc)
{
_props.setJc(jc);
- _papx.addSprm(SPRM_JC, jc);
+ _papx.updateSprm(SPRM_JC, jc);
}
public boolean keepOnPage()
{
byte keep = (byte)(fKeep ? 1 : 0);
_props.setFKeep(keep);
- _papx.addSprm(SPRM_FKEEP, keep);
+ _papx.updateSprm(SPRM_FKEEP, keep);
}
public boolean keepWithNext()
{
byte keepFollow = (byte)(fKeepFollow ? 1 : 0);
_props.setFKeepFollow(keepFollow);
- _papx.addSprm(SPRM_FKEEPFOLLOW, keepFollow);
+ _papx.updateSprm(SPRM_FKEEPFOLLOW, keepFollow);
}
public boolean pageBreakBefore()
{
byte pageBreak = (byte)(fPageBreak ? 1 : 0);
_props.setFPageBreakBefore(pageBreak);
- _papx.addSprm(SPRM_FPAGEBREAKBEFORE, pageBreak);
+ _papx.updateSprm(SPRM_FPAGEBREAKBEFORE, pageBreak);
}
public boolean isLineNotNumbered()
{
byte noLnn = (byte)(fNoLnn ? 1 : 0);
_props.setFNoLnn(noLnn);
- _papx.addSprm(SPRM_FNOLINENUMB, noLnn);
+ _papx.updateSprm(SPRM_FNOLINENUMB, noLnn);
}
public boolean isSideBySide()
{
byte sideBySide = (byte)(fSideBySide ? 1 : 0);
_props.setFSideBySide(sideBySide);
- _papx.addSprm(SPRM_FSIDEBYSIDE, sideBySide);
+ _papx.updateSprm(SPRM_FSIDEBYSIDE, sideBySide);
}
public boolean isAutoHyphenated()
{
byte auto = (byte)(!autoHyph ? 1 : 0);
_props.setFNoAutoHyph(auto);
- _papx.addSprm(SPRM_FNOAUTOHYPH, auto);
+ _papx.updateSprm(SPRM_FNOAUTOHYPH, auto);
}
public boolean isWidowControlled()
{
byte widow = (byte)(widowControl ? 1 : 0);
_props.setFWidowControl(widow);
- _papx.addSprm(SPRM_FWIDOWCONTROL, widow);
+ _papx.updateSprm(SPRM_FWIDOWCONTROL, widow);
}
public int getIndentFromRight()
public void setIndentFromRight(int dxaRight)
{
_props.setDxaRight(dxaRight);
- _papx.addSprm(SPRM_DXARIGHT, (short)dxaRight);
+ _papx.updateSprm(SPRM_DXARIGHT, (short)dxaRight);
}
public int getIndentFromLeft()
public void setIndentFromLeft(int dxaLeft)
{
_props.setDxaLeft(dxaLeft);
- _papx.addSprm(SPRM_DXALEFT, (short)dxaLeft);
+ _papx.updateSprm(SPRM_DXALEFT, (short)dxaLeft);
}
public int getFirstLineIndent()
public void setFirstLineIndent(int first)
{
_props.setDxaLeft1(first);
- _papx.addSprm(SPRM_DXALEFT1, (short)first);
+ _papx.updateSprm(SPRM_DXALEFT1, (short)first);
}
public LineSpacingDescriptor getLineSpacing()
public void setLineSpacing(LineSpacingDescriptor lspd)
{
_props.setLspd(lspd);
- _papx.addSprm(SPRM_DYALINE, lspd.toInt());
+ _papx.updateSprm(SPRM_DYALINE, lspd.toInt());
}
public int getSpacingBefore()
public void setSpacingBefore(int before)
{
_props.setDyaBefore(before);
- _papx.addSprm(SPRM_DYABEFORE, (short)before);
+ _papx.updateSprm(SPRM_DYABEFORE, (short)before);
}
public int getSpacingAfter()
public void setSpacingAfter(int after)
{
_props.setDyaAfter(after);
- _papx.addSprm(SPRM_DYAAFTER, (short)after);
+ _papx.updateSprm(SPRM_DYAAFTER, (short)after);
}
public boolean isKinsoku()
{
byte kin = (byte)(kinsoku ? 1 : 0);
_props.setFKinsoku(kin);
- _papx.addSprm(SPRM_FKINSOKU, kin);
+ _papx.updateSprm(SPRM_FKINSOKU, kin);
}
public boolean isWordWrapped()
{
byte wordWrap = (byte)(wrap ? 1 : 0);
_props.setFWordWrap(wordWrap);
- _papx.addSprm(SPRM_FWORDWRAP, wordWrap);
+ _papx.updateSprm(SPRM_FWORDWRAP, wordWrap);
}
public int getFontAlignment()
public void setFontAlignment(int align)
{
_props.setWAlignFont(align);
- _papx.addSprm(SPRM_WALIGNFONT, (short)align);
+ _papx.updateSprm(SPRM_WALIGNFONT, (short)align);
}
public boolean isVertical()
public void setVertical(boolean vertical)
{
_props.setFVertical(vertical);
- _papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
+ _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
}
public boolean isBackward()
public void setBackward(boolean bward)
{
_props.setFBackward(bward);
- _papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
+ _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
}
public BorderCode getTopBorder()
public void setTopBorder(BorderCode top)
{
_props.setBrcTop(top);
- _papx.addSprm(SPRM_BRCTOP, top.toInt());
+ _papx.updateSprm(SPRM_BRCTOP, top.toInt());
}
public BorderCode getLeftBorder()
public void setLeftBorder(BorderCode left)
{
_props.setBrcLeft(left);
- _papx.addSprm(SPRM_BRCLEFT, left.toInt());
+ _papx.updateSprm(SPRM_BRCLEFT, left.toInt());
}
public BorderCode getBottomBorder()
public void setBottomBorder(BorderCode bottom)
{
_props.setBrcBottom(bottom);
- _papx.addSprm(SPRM_BRCBOTTOM, bottom.toInt());
+ _papx.updateSprm(SPRM_BRCBOTTOM, bottom.toInt());
}
public BorderCode getRightBorder()
public void setRightBorder(BorderCode right)
{
_props.setBrcRight(right);
- _papx.addSprm(SPRM_BRCRIGHT, right.toInt());
+ _papx.updateSprm(SPRM_BRCRIGHT, right.toInt());
}
public BorderCode getBarBorder()
public void setBarBorder(BorderCode bar)
{
_props.setBrcBar(bar);
- _papx.addSprm(SPRM_BRCBAR, bar.toInt());
+ _papx.updateSprm(SPRM_BRCBAR, bar.toInt());
}
public ShadingDescriptor getShading()
public void setShading(ShadingDescriptor shd)
{
_props.setShd(shd);
- _papx.addSprm(SPRM_SHD, shd.toShort());
+ _papx.updateSprm(SPRM_SHD, shd.toShort());
}
public DropCapSpecifier getDropCap()
public void setDropCap(DropCapSpecifier dcs)
{
_props.setDcs(dcs);
- _papx.addSprm(SPRM_DCS, dcs.toShort());
+ _papx.updateSprm(SPRM_DCS, dcs.toShort());
}
void setTableRowEnd(TableProperties props)
private void setTableRowEnd(byte val)
{
_props.setFTtp(val);
- _papx.addSprm(SPRM_FTTP, val);
+ _papx.updateSprm(SPRM_FTTP, val);
}
public Object clone()
* It is possible to insert text and/or properties at the beginning or end of a
* range.
*
+ * Ranges are only valid if there hasn't been an insert in a prior Range since
+ * the Range's creation. Once an element (text, paragraph, etc.) has been
+ * inserted into a Range, subsequent Ranges become unstable.
+ *
* @author Ryan Ackley
*/
public class Range
_parent = new WeakReference(null);
}
+
/**
* Used to create Ranges that are children of other Ranges.
*
return getParagraph(numParagraphs() - 1);
}
+ public void delete()
+ {
+ initAll();
+
+ int numSections = _sections.size();
+ int numRuns = _characters.size();
+ int numParagraphs = _paragraphs.size();
+
+ for (int x = _charStart; x < numRuns; x++)
+ {
+ CHPX chpx = (CHPX)_characters.get(x);
+ chpx.adjustForDelete(_start, _end - _start);
+ }
+
+ for (int x = _parStart; x < numParagraphs; x++)
+ {
+ PAPX papx = (PAPX)_paragraphs.get(x);
+ papx.adjustForDelete(_start, _end - _start);
+ }
+
+ for (int x = _sectionStart; x < numSections; x++)
+ {
+ SEPX sepx = (SEPX)_sections.get(x);
+ sepx.adjustForDelete(_start, _end - _start);
+ }
+ }
+
/**
* Inserts a simple table into the beginning of this range. The number of
* columns is determined by the TableProperties passed into this function.
initCharacterRuns();
CHPX chpx = (CHPX)_characters.get(index + _charStart);
- int[] point = findRange(_paragraphs, _parStart, chpx.getStart(),
+ int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start),
chpx.getEnd());
PAPX papx = (PAPX)_paragraphs.get(point[0]);
short istd = papx.getIstd();