Fixing compiler warnings - unnecessary typecasts

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@805284 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-08-18 05:29:53 +00:00
parent 995d8fe73f
commit c83d6bfa24
73 changed files with 3081 additions and 4444 deletions

View File

@ -238,7 +238,6 @@ public class AddDimensionedImage {
String imageFile, double reqImageWidthMM, double reqImageHeightMM, String imageFile, double reqImageWidthMM, double reqImageHeightMM,
int resizeBehaviour) throws FileNotFoundException, IOException, int resizeBehaviour) throws FileNotFoundException, IOException,
IllegalArgumentException { IllegalArgumentException {
HSSFRow row = null;
HSSFClientAnchor anchor = null; HSSFClientAnchor anchor = null;
HSSFPatriarch patriarch = null; HSSFPatriarch patriarch = null;
ClientAnchorDetail rowClientAnchorDetail = null; ClientAnchorDetail rowClientAnchorDetail = null;
@ -280,7 +279,7 @@ public class AddDimensionedImage {
// image as the size of the row/column is adjusted. This could easilly // image as the size of the row/column is adjusted. This could easilly
// become another parameter passed to the method. // become another parameter passed to the method.
anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE); anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
// Now, add the picture to the workbook. Note that the type is assumed // Now, add the picture to the workbook. Note that the type is assumed
// to be a JPEG/JPG, this could easily (and should) be parameterised // to be a JPEG/JPG, this could easily (and should) be parameterised
// however. // however.
@ -485,7 +484,6 @@ public class AddDimensionedImage {
double colWidthMM = 0.0D; double colWidthMM = 0.0D;
double overlapMM = 0.0D; double overlapMM = 0.0D;
double coordinatePositionsPerMM = 0.0D; double coordinatePositionsPerMM = 0.0D;
int fromNumber = startingColumn;
int toColumn = startingColumn; int toColumn = startingColumn;
int inset = 0; int inset = 0;
@ -522,7 +520,7 @@ public class AddDimensionedImage {
// total number of co-ordinate positions to the third paramater // total number of co-ordinate positions to the third paramater
// of the ClientAnchorDetail constructor. For no sepcific reason, // of the ClientAnchorDetail constructor. For no sepcific reason,
// the latter option is used below. // the latter option is used below.
anchorDetail = new ClientAnchorDetail(startingColumn, anchorDetail = new ClientAnchorDetail(startingColumn,
toColumn, ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS); toColumn, ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS);
} }
// In this case, the image will overlap part of another column and it is // In this case, the image will overlap part of another column and it is
@ -706,8 +704,6 @@ public class AddDimensionedImage {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
File file = null;
FileInputStream fis = null;
FileOutputStream fos = null; FileOutputStream fos = null;
HSSFWorkbook workbook = null; HSSFWorkbook workbook = null;
HSSFSheet sheet = null; HSSFSheet sheet = null;
@ -761,13 +757,13 @@ public class AddDimensionedImage {
* * Together, parameter seven and eight determine the column and row * * Together, parameter seven and eight determine the column and row
* co-ordinates of the cell whose top left hand corner will be aligned * co-ordinates of the cell whose top left hand corner will be aligned
* with the images bottom right hand corner. * with the images bottom right hand corner.
* *
* An instance of the ClientAnchorDetail class provides three of the eight * An instance of the ClientAnchorDetail class provides three of the eight
* parameters, one of the co-ordinates for the images top left hand corner, * parameters, one of the co-ordinates for the images top left hand corner,
* one of the co-ordinates for the images bottom right hand corner and * one of the co-ordinates for the images bottom right hand corner and
* either how far the image should be inset from the top or the left hand * either how far the image should be inset from the top or the left hand
* edge of the cell. * edge of the cell.
* *
* @author Mark Beardsley [msb at apache.org] * @author Mark Beardsley [msb at apache.org]
* @version 1.00 5th August 2009. * @version 1.00 5th August 2009.
*/ */
@ -892,7 +888,7 @@ public class AddDimensionedImage {
int pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR) int pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR)
* UNIT_OFFSET_LENGTH; * UNIT_OFFSET_LENGTH;
int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR; int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR;
pixels += Math.round((float) offsetWidthUnits / pixels += Math.round(offsetWidthUnits /
((float) EXCEL_COLUMN_WIDTH_FACTOR / UNIT_OFFSET_LENGTH)); ((float) EXCEL_COLUMN_WIDTH_FACTOR / UNIT_OFFSET_LENGTH));
return pixels; return pixels;
} }
@ -923,4 +919,4 @@ public class AddDimensionedImage {
ConvertImageUnits.PIXELS_PER_MILLIMETRES))); ConvertImageUnits.PIXELS_PER_MILLIMETRES)));
} }
} }
} }

View File

@ -177,7 +177,7 @@ public class Util
* *
* @param date The date to be converted * @param date The date to be converted
* @return The filetime * @return The filetime
* *
* @see #filetimeToDate(long) * @see #filetimeToDate(long)
* @see #filetimeToDate(int, int) * @see #filetimeToDate(int, int)
*/ */
@ -211,10 +211,10 @@ public class Util
* @return <code>true</code> if the collections are equal, else * @return <code>true</code> if the collections are equal, else
* <code>false</code>. * <code>false</code>.
*/ */
public static boolean equals(final Collection c1, final Collection c2) public static boolean equals(Collection<?> c1, Collection<?> c2)
{ {
final Object[] o1 = c1.toArray(); Object[] o1 = c1.toArray();
final Object[] o2 = c2.toArray(); Object[] o2 = c2.toArray();
return internalEquals(o1, o2); return internalEquals(o1, o2);
} }
@ -229,14 +229,14 @@ public class Util
* @return <code>true</code> if the object arrays are equal, * @return <code>true</code> if the object arrays are equal,
* <code>false</code> if they are not. * <code>false</code> if they are not.
*/ */
public static boolean equals(final Object[] c1, final Object[] c2) public static boolean equals(Object[] c1, Object[] c2)
{ {
final Object[] o1 = (Object[]) c1.clone(); final Object[] o1 = c1.clone();
final Object[] o2 = (Object[]) c2.clone(); final Object[] o2 = c2.clone();
return internalEquals(o1, o2); return internalEquals(o1, o2);
} }
private static boolean internalEquals(final Object[] o1, final Object[] o2) private static boolean internalEquals(Object[] o1, Object[] o2)
{ {
for (int i1 = 0; i1 < o1.length; i1++) for (int i1 = 0; i1 < o1.length; i1++)
{ {
@ -326,9 +326,9 @@ public class Util
/** /**
* <p>Returns a textual representation of a {@link Throwable}, including a * <p>Returns a textual representation of a {@link Throwable}, including a
* stacktrace.</p> * stacktrace.</p>
* *
* @param t The {@link Throwable} * @param t The {@link Throwable}
* *
* @return a string containing the output of a call to * @return a string containing the output of a call to
* <code>t.printStacktrace()</code>. * <code>t.printStacktrace()</code>.
*/ */

View File

@ -24,10 +24,10 @@ import org.apache.poi.hssf.record.*;
/** /**
* Event-based record factory. As opposed to RecordFactory * Event-based record factory. As opposed to RecordFactory
* this version sends {@link ERFListener#processRecord(Record) } messages to * this version sends {@link ERFListener#processRecord(Record) } messages to
* the supplied listener. Record notifications are sent one record behind * the supplied listener. Record notifications are sent one record behind
* to ensure that {@link ContinueRecord}s are processed first. * to ensure that {@link ContinueRecord}s are processed first.
* *
* @author Andrew C. Oliver (acoliver@apache.org) - probably to blame for the bugs (so yank his chain on the list) * @author Andrew C. Oliver (acoliver@apache.org) - probably to blame for the bugs (so yank his chain on the list)
* @author Marc Johnson (mjohnson at apache dot org) - methods taken from RecordFactory * @author Marc Johnson (mjohnson at apache dot org) - methods taken from RecordFactory
* @author Glen Stampoultzis (glens at apache.org) - methods taken from RecordFactory * @author Glen Stampoultzis (glens at apache.org) - methods taken from RecordFactory
@ -35,87 +35,87 @@ import org.apache.poi.hssf.record.*;
*/ */
public final class EventRecordFactory { public final class EventRecordFactory {
private final ERFListener _listener; private final ERFListener _listener;
private final short[] _sids; private final short[] _sids;
/** /**
* *
* @param sids an array of Record.sid values identifying the records * @param sids an array of Record.sid values identifying the records
* the listener will work with. Alternatively if this is "null" then * the listener will work with. Alternatively if this is "null" then
* all records are passed. For all 'known' record types use {@link RecordFactory#getAllKnownRecordSIDs()} * all records are passed. For all 'known' record types use {@link RecordFactory#getAllKnownRecordSIDs()}
*/ */
public EventRecordFactory(ERFListener listener, short[] sids) { public EventRecordFactory(ERFListener listener, short[] sids) {
_listener = listener; _listener = listener;
if (sids == null) { if (sids == null) {
_sids = null; _sids = null;
} else { } else {
_sids = (short[]) sids.clone(); _sids = sids.clone();
Arrays.sort(_sids); // for faster binary search Arrays.sort(_sids); // for faster binary search
} }
} }
private boolean isSidIncluded(short sid) { private boolean isSidIncluded(short sid) {
if (_sids == null) { if (_sids == null) {
return true; return true;
} }
return Arrays.binarySearch(_sids, sid) >= 0; return Arrays.binarySearch(_sids, sid) >= 0;
} }
/** /**
* sends the record event to all registered listeners. * sends the record event to all registered listeners.
* @param record the record to be thrown. * @param record the record to be thrown.
* @return <code>false</code> to abort. This aborts * @return <code>false</code> to abort. This aborts
* out of the event loop should the listener return false * out of the event loop should the listener return false
*/ */
private boolean processRecord(Record record) { private boolean processRecord(Record record) {
if (!isSidIncluded(record.getSid())) { if (!isSidIncluded(record.getSid())) {
return true; return true;
} }
return _listener.processRecord(record); return _listener.processRecord(record);
} }
/** /**
* Create an array of records from an input stream * Create an array of records from an input stream
* *
* @param in the InputStream from which the records will be * @param in the InputStream from which the records will be
* obtained * obtained
* *
* @exception RecordFormatException on error processing the * @exception RecordFormatException on error processing the
* InputStream * InputStream
*/ */
public void processRecords(InputStream in) throws RecordFormatException { public void processRecords(InputStream in) throws RecordFormatException {
Record last_record = null; Record last_record = null;
RecordInputStream recStream = new RecordInputStream(in); RecordInputStream recStream = new RecordInputStream(in);
while (recStream.hasNextRecord()) { while (recStream.hasNextRecord()) {
recStream.nextRecord(); recStream.nextRecord();
Record[] recs = RecordFactory.createRecord(recStream); // handle MulRK records Record[] recs = RecordFactory.createRecord(recStream); // handle MulRK records
if (recs.length > 1) { if (recs.length > 1) {
for (int k = 0; k < recs.length; k++) { for (int k = 0; k < recs.length; k++) {
if ( last_record != null ) { if ( last_record != null ) {
if (!processRecord(last_record)) { if (!processRecord(last_record)) {
return; return;
} }
} }
last_record = recs[ k ]; // do to keep the algorithm homogeneous...you can't last_record = recs[ k ]; // do to keep the algorithm homogeneous...you can't
} // actually continue a number record anyhow. } // actually continue a number record anyhow.
} else { } else {
Record record = recs[ 0 ]; Record record = recs[ 0 ];
if (record != null) { if (record != null) {
if (last_record != null) { if (last_record != null) {
if (!processRecord(last_record)) { if (!processRecord(last_record)) {
return; return;
} }
} }
last_record = record; last_record = record;
} }
} }
} }
if (last_record != null) { if (last_record != null) {
processRecord(last_record); processRecord(last_record);
} }
} }
} }

View File

@ -65,8 +65,8 @@ import org.apache.poi.hssf.record.formula.Ref3DPtg;
* @author Josh Micich * @author Josh Micich
*/ */
final class LinkTable { final class LinkTable {
// TODO make this class into a record aggregate // TODO make this class into a record aggregate
private static final class CRNBlock { private static final class CRNBlock {
@ -84,7 +84,7 @@ final class LinkTable {
_crns = crns; _crns = crns;
} }
public CRNRecord[] getCrns() { public CRNRecord[] getCrns() {
return (CRNRecord[]) _crns.clone(); return _crns.clone();
} }
} }
@ -95,7 +95,7 @@ final class LinkTable {
public ExternalBookBlock(RecordStream rs) { public ExternalBookBlock(RecordStream rs) {
_externalBookRecord = (SupBookRecord) rs.getNext(); _externalBookRecord = (SupBookRecord) rs.getNext();
List temp = new ArrayList(); List<Object> temp = new ArrayList<Object>();
while(rs.peekNextClass() == ExternalNameRecord.class) { while(rs.peekNextClass() == ExternalNameRecord.class) {
temp.add(rs.getNext()); temp.add(rs.getNext());
} }
@ -141,7 +141,7 @@ final class LinkTable {
private final ExternalBookBlock[] _externalBookBlocks; private final ExternalBookBlock[] _externalBookBlocks;
private final ExternSheetRecord _externSheetRecord; private final ExternSheetRecord _externSheetRecord;
private final List _definedNames; private final List<NameRecord> _definedNames;
private final int _recordCount; private final int _recordCount;
private final WorkbookRecordList _workbookRecordList; // TODO - would be nice to remove this private final WorkbookRecordList _workbookRecordList; // TODO - would be nice to remove this
@ -150,15 +150,15 @@ final class LinkTable {
_workbookRecordList = workbookRecordList; _workbookRecordList = workbookRecordList;
RecordStream rs = new RecordStream(inputList, startIndex); RecordStream rs = new RecordStream(inputList, startIndex);
List temp = new ArrayList(); List<ExternalBookBlock> temp = new ArrayList<ExternalBookBlock>();
while(rs.peekNextClass() == SupBookRecord.class) { while(rs.peekNextClass() == SupBookRecord.class) {
temp.add(new ExternalBookBlock(rs)); temp.add(new ExternalBookBlock(rs));
} }
_externalBookBlocks = new ExternalBookBlock[temp.size()]; _externalBookBlocks = new ExternalBookBlock[temp.size()];
temp.toArray(_externalBookBlocks); temp.toArray(_externalBookBlocks);
temp.clear(); temp.clear();
if (_externalBookBlocks.length > 0) { if (_externalBookBlocks.length > 0) {
// If any ExternalBookBlock present, there is always 1 of ExternSheetRecord // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord
if (rs.peekNextClass() != ExternSheetRecord.class) { if (rs.peekNextClass() != ExternSheetRecord.class) {
@ -170,8 +170,8 @@ final class LinkTable {
} else { } else {
_externSheetRecord = null; _externSheetRecord = null;
} }
_definedNames = new ArrayList(); _definedNames = new ArrayList<NameRecord>();
// collect zero or more DEFINEDNAMEs id=0x18 // collect zero or more DEFINEDNAMEs id=0x18
while(rs.peekNextClass() == NameRecord.class) { while(rs.peekNextClass() == NameRecord.class) {
NameRecord nr = (NameRecord)rs.getNext(); NameRecord nr = (NameRecord)rs.getNext();
@ -183,19 +183,19 @@ final class LinkTable {
} }
private static ExternSheetRecord readExtSheetRecord(RecordStream rs) { private static ExternSheetRecord readExtSheetRecord(RecordStream rs) {
List temp = new ArrayList(2); List<ExternSheetRecord> temp = new ArrayList<ExternSheetRecord>(2);
while(rs.peekNextClass() == ExternSheetRecord.class) { while(rs.peekNextClass() == ExternSheetRecord.class) {
temp.add(rs.getNext()); temp.add((ExternSheetRecord) rs.getNext());
} }
int nItems = temp.size(); int nItems = temp.size();
if (nItems < 1) { if (nItems < 1) {
throw new RuntimeException("Expected an EXTERNSHEET record but got (" throw new RuntimeException("Expected an EXTERNSHEET record but got ("
+ rs.peekNextClass().getName() + ")"); + rs.peekNextClass().getName() + ")");
} }
if (nItems == 1) { if (nItems == 1) {
// this is the normal case. There should be just one ExternSheetRecord // this is the normal case. There should be just one ExternSheetRecord
return (ExternSheetRecord) temp.get(0); return temp.get(0);
} }
// Some apps generate multiple ExternSheetRecords (see bug 45698). // Some apps generate multiple ExternSheetRecords (see bug 45698).
// It seems like the best thing to do might be to combine these into one // It seems like the best thing to do might be to combine these into one
@ -206,7 +206,7 @@ final class LinkTable {
public LinkTable(int numberOfSheets, WorkbookRecordList workbookRecordList) { public LinkTable(int numberOfSheets, WorkbookRecordList workbookRecordList) {
_workbookRecordList = workbookRecordList; _workbookRecordList = workbookRecordList;
_definedNames = new ArrayList(); _definedNames = new ArrayList<NameRecord>();
_externalBookBlocks = new ExternalBookBlock[] { _externalBookBlocks = new ExternalBookBlock[] {
new ExternalBookBlock(numberOfSheets), new ExternalBookBlock(numberOfSheets),
}; };
@ -267,7 +267,7 @@ final class LinkTable {
} }
public NameRecord getNameRecord(int index) { public NameRecord getNameRecord(int index) {
return (NameRecord) _definedNames.get(index); return _definedNames.get(index);
} }
public void addName(NameRecord name) { public void addName(NameRecord name) {
@ -301,9 +301,9 @@ final class LinkTable {
} }
return false; return false;
} }
private static boolean isDuplicatedNames(NameRecord firstName, NameRecord lastName) { private static boolean isDuplicatedNames(NameRecord firstName, NameRecord lastName) {
return lastName.getNameText().equalsIgnoreCase(firstName.getNameText()) return lastName.getNameText().equalsIgnoreCase(firstName.getNameText())
&& isSameSheetNames(firstName, lastName); && isSameSheetNames(firstName, lastName);
} }
private static boolean isSameSheetNames(NameRecord firstName, NameRecord lastName) { private static boolean isSameSheetNames(NameRecord firstName, NameRecord lastName) {
@ -342,10 +342,10 @@ final class LinkTable {
throw new RuntimeException("No external workbook with name '" + workbookName + "'"); throw new RuntimeException("No external workbook with name '" + workbookName + "'");
} }
int sheetIndex = getSheetIndex(ebrTarget.getSheetNames(), sheetName); int sheetIndex = getSheetIndex(ebrTarget.getSheetNames(), sheetName);
int result = _externSheetRecord.getRefIxForSheet(externalBookIndex, sheetIndex); int result = _externSheetRecord.getRefIxForSheet(externalBookIndex, sheetIndex);
if (result < 0) { if (result < 0) {
throw new RuntimeException("ExternSheetRecord does not contain combination (" throw new RuntimeException("ExternSheetRecord does not contain combination ("
+ externalBookIndex + ", " + sheetIndex + ")"); + externalBookIndex + ", " + sheetIndex + ")");
} }
return result; return result;
@ -356,7 +356,7 @@ final class LinkTable {
if (sheetNames[i].equals(sheetName)) { if (sheetNames[i].equals(sheetName)) {
return i; return i;
} }
} }
throw new RuntimeException("External workbook does not contain sheet '" + sheetName + "'"); throw new RuntimeException("External workbook does not contain sheet '" + sheetName + "'");
} }
@ -428,7 +428,7 @@ final class LinkTable {
continue; continue;
} }
// found it. // found it.
int sheetRefIndex = findRefIndexFromExtBookIndex(i); int sheetRefIndex = findRefIndexFromExtBookIndex(i);
if (sheetRefIndex >= 0) { if (sheetRefIndex >= 0) {
return new NameXPtg(sheetRefIndex, definedNameIndex); return new NameXPtg(sheetRefIndex, definedNameIndex);
} }
@ -437,6 +437,6 @@ final class LinkTable {
} }
private int findRefIndexFromExtBookIndex(int extBookIndex) { private int findRefIndexFromExtBookIndex(int extBookIndex) {
return _externSheetRecord.findRefIndexFromExtBookIndex(extBookIndex); return _externSheetRecord.findRefIndexFromExtBookIndex(extBookIndex);
} }
} }

View File

@ -465,7 +465,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
pos += temp; pos += temp;
// Write the matching OBJ record // Write the matching OBJ record
Record obj = (Record) shapeToObj.get( shapes.get( i ) ); Record obj = shapeToObj.get( shapes.get( i ) );
temp = obj.serialize( pos, data ); temp = obj.serialize( pos, data );
pos += temp; pos += temp;
@ -535,7 +535,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
{ {
this.patriarch = patriarch; this.patriarch = patriarch;
} }
/** /**
* Converts the Records into UserModel * Converts the Records into UserModel
* objects on the bound HSSFPatriarch * objects on the bound HSSFPatriarch
@ -544,7 +544,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
if(patriarch == null) { if(patriarch == null) {
throw new IllegalStateException("Must call setPatriarch() first"); throw new IllegalStateException("Must call setPatriarch() first");
} }
// The top level container ought to have // The top level container ought to have
// the DgRecord and the container of one container // the DgRecord and the container of one container
// per shape group (patriach overall first) // per shape group (patriach overall first)
@ -552,14 +552,13 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
if(topContainer == null) { if(topContainer == null) {
return; return;
} }
topContainer = (EscherContainerRecord) topContainer = topContainer.getChildContainers().get(0);
topContainer.getChildContainers().get(0);
List tcc = topContainer.getChildContainers(); List tcc = topContainer.getChildContainers();
if(tcc.size() == 0) { if(tcc.size() == 0) {
throw new IllegalStateException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!"); throw new IllegalStateException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
} }
// First up, get the patriach position // First up, get the patriach position
// This is in the first EscherSpgrRecord, in // This is in the first EscherSpgrRecord, in
// the first container, with a EscherSRecord too // the first container, with a EscherSRecord too
@ -579,7 +578,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
spgr.getRectX2(), spgr.getRectY2() spgr.getRectX2(), spgr.getRectY2()
); );
} }
// Now process the containers for each group // Now process the containers for each group
// and objects // and objects
for(int i=1; i<tcc.size(); i++) { for(int i=1; i<tcc.size(); i++) {
@ -587,7 +586,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
(EscherContainerRecord)tcc.get(i); (EscherContainerRecord)tcc.get(i);
//System.err.println("\n\n*****\n\n"); //System.err.println("\n\n*****\n\n");
//System.err.println(shapeContainer); //System.err.println(shapeContainer);
// Could be a group, or a base object // Could be a group, or a base object
if(shapeContainer.getChildRecords().size() == 1 && if(shapeContainer.getChildRecords().size() == 1 &&
shapeContainer.getChildContainers().size() == 1) { shapeContainer.getChildContainers().size() == 1) {
@ -595,7 +594,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
HSSFShapeGroup group = HSSFShapeGroup group =
new HSSFShapeGroup(null, new HSSFClientAnchor()); new HSSFShapeGroup(null, new HSSFClientAnchor());
patriarch.getChildren().add(group); patriarch.getChildren().add(group);
EscherContainerRecord groupContainer = EscherContainerRecord groupContainer =
(EscherContainerRecord)shapeContainer.getChild(0); (EscherContainerRecord)shapeContainer.getChild(0);
convertRecordsToUserModel(groupContainer, group); convertRecordsToUserModel(groupContainer, group);
@ -604,7 +603,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
HSSFTextbox box = HSSFTextbox box =
new HSSFTextbox(null, new HSSFClientAnchor()); new HSSFTextbox(null, new HSSFClientAnchor());
patriarch.getChildren().add(box); patriarch.getChildren().add(box);
convertRecordsToUserModel(shapeContainer, box); convertRecordsToUserModel(shapeContainer, box);
} else if(shapeContainer.hasChildOfType((short)0xF011)) { } else if(shapeContainer.hasChildOfType((short)0xF011)) {
// Not yet supporting EscherClientDataRecord stuff // Not yet supporting EscherClientDataRecord stuff
@ -613,7 +612,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
convertRecordsToUserModel(shapeContainer, patriarch); convertRecordsToUserModel(shapeContainer, patriarch);
} }
} }
// Now, clear any trace of what records make up // Now, clear any trace of what records make up
// the patriarch // the patriarch
// Otherwise, everything will go horribly wrong // Otherwise, everything will go horribly wrong
@ -625,14 +624,14 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
// back into shapes // back into shapes
log.log(POILogger.WARN, "Not processing objects into Patriarch!"); log.log(POILogger.WARN, "Not processing objects into Patriarch!");
} }
private void convertRecordsToUserModel(EscherContainerRecord shapeContainer, Object model) { private void convertRecordsToUserModel(EscherContainerRecord shapeContainer, Object model) {
for(Iterator<EscherRecord> it = shapeContainer.getChildIterator(); it.hasNext();) { for(Iterator<EscherRecord> it = shapeContainer.getChildIterator(); it.hasNext();) {
EscherRecord r = it.next(); EscherRecord r = it.next();
if(r instanceof EscherSpgrRecord) { if(r instanceof EscherSpgrRecord) {
// This may be overriden by a later EscherClientAnchorRecord // This may be overriden by a later EscherClientAnchorRecord
EscherSpgrRecord spgr = (EscherSpgrRecord)r; EscherSpgrRecord spgr = (EscherSpgrRecord)r;
if(model instanceof HSSFShapeGroup) { if(model instanceof HSSFShapeGroup) {
HSSFShapeGroup g = (HSSFShapeGroup)model; HSSFShapeGroup g = (HSSFShapeGroup)model;
g.setCoordinates( g.setCoordinates(
@ -642,10 +641,10 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
} else { } else {
throw new IllegalStateException("Got top level anchor but not processing a group"); throw new IllegalStateException("Got top level anchor but not processing a group");
} }
} }
else if(r instanceof EscherClientAnchorRecord) { else if(r instanceof EscherClientAnchorRecord) {
EscherClientAnchorRecord car = (EscherClientAnchorRecord)r; EscherClientAnchorRecord car = (EscherClientAnchorRecord)r;
if(model instanceof HSSFShape) { if(model instanceof HSSFShape) {
HSSFShape g = (HSSFShape)model; HSSFShape g = (HSSFShape)model;
g.getAnchor().setDx1(car.getDx1()); g.getAnchor().setDx1(car.getDx1());
@ -658,7 +657,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
} }
else if(r instanceof EscherTextboxRecord) { else if(r instanceof EscherTextboxRecord) {
EscherTextboxRecord tbr = (EscherTextboxRecord)r; EscherTextboxRecord tbr = (EscherTextboxRecord)r;
// Also need to find the TextObjectRecord too // Also need to find the TextObjectRecord too
// TODO // TODO
} }
@ -673,7 +672,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
} }
} }
} }
public void clear() public void clear()
{ {
clearEscherRecords(); clearEscherRecords();
@ -742,7 +741,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
EscherRecord escherTextbox = ( (TextboxShape) shapeModel ).getEscherTextbox(); EscherRecord escherTextbox = ( (TextboxShape) shapeModel ).getEscherTextbox();
shapeToObj.put( escherTextbox, ( (TextboxShape) shapeModel ).getTextObjectRecord() ); shapeToObj.put( escherTextbox, ( (TextboxShape) shapeModel ).getTextObjectRecord() );
// escherParent.addChildRecord(escherTextbox); // escherParent.addChildRecord(escherTextbox);
if ( shapeModel instanceof CommentShape ){ if ( shapeModel instanceof CommentShape ){
CommentShape comment = (CommentShape)shapeModel; CommentShape comment = (CommentShape)shapeModel;
tailRec.add(comment.getNoteRecord()); tailRec.add(comment.getNoteRecord());

View File

@ -68,9 +68,6 @@ public final class SSTRecord extends ContinuableRecord {
/** Offsets relative the start of the current SST or continue record */ /** Offsets relative the start of the current SST or continue record */
int[] bucketRelativeOffsets; int[] bucketRelativeOffsets;
/**
* default constructor
*/
public SSTRecord() public SSTRecord()
{ {
field_1_num_strings = 0; field_1_num_strings = 0;
@ -86,8 +83,7 @@ public final class SSTRecord extends ContinuableRecord {
* *
* @return the index of that string in the table * @return the index of that string in the table
*/ */
public int addString(UnicodeString string)
public int addString( final UnicodeString string )
{ {
field_1_num_strings++; field_1_num_strings++;
UnicodeString ucs = ( string == null ) ? EMPTY_STRING UnicodeString ucs = ( string == null ) ? EMPTY_STRING
@ -95,12 +91,9 @@ public final class SSTRecord extends ContinuableRecord {
int rval; int rval;
int index = field_3_strings.getIndex(ucs); int index = field_3_strings.getIndex(ucs);
if ( index != -1 ) if ( index != -1 ) {
{
rval = index; rval = index;
} } else {
else
{
// This is a new string -- we didn't see it among the // This is a new string -- we didn't see it among the
// strings we've already collected // strings we've already collected
rval = field_3_strings.size(); rval = field_3_strings.size();
@ -113,7 +106,6 @@ public final class SSTRecord extends ContinuableRecord {
/** /**
* @return number of strings * @return number of strings
*/ */
public int getNumStrings() public int getNumStrings()
{ {
return field_1_num_strings; return field_1_num_strings;
@ -122,7 +114,6 @@ public final class SSTRecord extends ContinuableRecord {
/** /**
* @return number of unique strings * @return number of unique strings
*/ */
public int getNumUniqueStrings() public int getNumUniqueStrings()
{ {
return field_2_num_unique_strings; return field_2_num_unique_strings;
@ -136,8 +127,7 @@ public final class SSTRecord extends ContinuableRecord {
* *
* @return the desired string * @return the desired string
*/ */
public UnicodeString getString(int id )
public UnicodeString getString( final int id )
{ {
return (UnicodeString) field_3_strings.get( id ); return (UnicodeString) field_3_strings.get( id );
} }
@ -148,9 +138,7 @@ public final class SSTRecord extends ContinuableRecord {
* *
* @return string representation * @return string representation
*/ */
public String toString() {
public String toString()
{
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append( "[SST]\n" ); buffer.append( "[SST]\n" );
@ -168,11 +156,7 @@ public final class SSTRecord extends ContinuableRecord {
return buffer.toString(); return buffer.toString();
} }
/** public short getSid() {
* @return sid
*/
public short getSid()
{
return sid; return sid;
} }
@ -254,9 +238,7 @@ public final class SSTRecord extends ContinuableRecord {
* *
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public SSTRecord(RecordInputStream in) {
public SSTRecord( RecordInputStream in )
{
// this method is ALWAYS called after construction -- using // this method is ALWAYS called after construction -- using
// the nontrivial constructor, of course -- so this is where // the nontrivial constructor, of course -- so this is where
// we initialize our fields // we initialize our fields
@ -272,7 +254,6 @@ public final class SSTRecord extends ContinuableRecord {
* @return an iterator of the strings we hold. All instances are * @return an iterator of the strings we hold. All instances are
* UnicodeStrings * UnicodeStrings
*/ */
Iterator getStrings() Iterator getStrings()
{ {
return field_3_strings.iterator(); return field_3_strings.iterator();
@ -281,9 +262,7 @@ public final class SSTRecord extends ContinuableRecord {
/** /**
* @return count of the strings we hold. * @return count of the strings we hold.
*/ */
int countStrings() {
int countStrings()
{
return field_3_strings.size(); return field_3_strings.size();
} }
@ -294,8 +273,7 @@ public final class SSTRecord extends ContinuableRecord {
bucketRelativeOffsets = serializer.getBucketRelativeOffsets(); bucketRelativeOffsets = serializer.getBucketRelativeOffsets();
} }
SSTDeserializer getDeserializer() SSTDeserializer getDeserializer() {
{
return deserializer; return deserializer;
} }
@ -312,15 +290,14 @@ public final class SSTRecord extends ContinuableRecord {
* SST record. * SST record.
* @return The new SST record. * @return The new SST record.
*/ */
public ExtSSTRecord createExtSSTRecord(int sstOffset) public ExtSSTRecord createExtSSTRecord(int sstOffset) {
{
if (bucketAbsoluteOffsets == null || bucketAbsoluteOffsets == null) if (bucketAbsoluteOffsets == null || bucketAbsoluteOffsets == null)
throw new IllegalStateException("SST record has not yet been serialized."); throw new IllegalStateException("SST record has not yet been serialized.");
ExtSSTRecord extSST = new ExtSSTRecord(); ExtSSTRecord extSST = new ExtSSTRecord();
extSST.setNumStringsPerBucket((short)8); extSST.setNumStringsPerBucket((short)8);
int[] absoluteOffsets = (int[]) bucketAbsoluteOffsets.clone(); int[] absoluteOffsets = bucketAbsoluteOffsets.clone();
int[] relativeOffsets = (int[]) bucketRelativeOffsets.clone(); int[] relativeOffsets = bucketRelativeOffsets.clone();
for ( int i = 0; i < absoluteOffsets.length; i++ ) for ( int i = 0; i < absoluteOffsets.length; i++ )
absoluteOffsets[i] += sstOffset; absoluteOffsets[i] += sstOffset;
extSST.setBucketOffsets(absoluteOffsets, relativeOffsets); extSST.setBucketOffsets(absoluteOffsets, relativeOffsets);
@ -333,8 +310,7 @@ public final class SSTRecord extends ContinuableRecord {
* *
* @return The size of the ExtSST record in bytes. * @return The size of the ExtSST record in bytes.
*/ */
public int calcExtSSTRecordSize() public int calcExtSSTRecordSize() {
{
return ExtSSTRecord.getRecordSizeForStrings(field_3_strings.size()); return ExtSSTRecord.getRecordSizeForStrings(field_3_strings.size());
} }
} }

View File

@ -25,10 +25,10 @@ import org.apache.poi.util.LittleEndian;
/** /**
* Font Formatting Block of the Conditional Formatting Rule Record. * Font Formatting Block of the Conditional Formatting Rule Record.
* *
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
*/ */
public final class FontFormatting public final class FontFormatting
{ {
private byte[] _rawData; private byte[] _rawData;
@ -45,7 +45,7 @@ public final class FontFormatting
private static final int OFFSET_FONT_WEIGHT_MODIFIED = 100; private static final int OFFSET_FONT_WEIGHT_MODIFIED = 100;
private static final int OFFSET_NOT_USED1 = 104; private static final int OFFSET_NOT_USED1 = 104;
private static final int OFFSET_NOT_USED2 = 108; private static final int OFFSET_NOT_USED2 = 108;
private static final int OFFSET_NOT_USED3 = 112; // for some reason Excel always writes 0x7FFFFFFF at this offset private static final int OFFSET_NOT_USED3 = 112; // for some reason Excel always writes 0x7FFFFFFF at this offset
private static final int OFFSET_FONT_FORMATING_END = 116; private static final int OFFSET_FONT_FORMATING_END = 116;
private static final int RAW_DATA_SIZE = 118; private static final int RAW_DATA_SIZE = 118;
@ -71,15 +71,15 @@ public final class FontFormatting
public static final short SS_SUPER = 1; public static final short SS_SUPER = 1;
/** Escapement type - Subscript */ /** Escapement type - Subscript */
public static final short SS_SUB = 2; public static final short SS_SUB = 2;
/** Underline type - None */ /** Underline type - None */
public static final byte U_NONE = 0; public static final byte U_NONE = 0;
/** Underline type - Single */ /** Underline type - Single */
public static final byte U_SINGLE = 1; public static final byte U_SINGLE = 1;
/** Underline type - Double */ /** Underline type - Double */
public static final byte U_DOUBLE = 2; public static final byte U_DOUBLE = 2;
/** Underline type - Single Accounting */ /** Underline type - Single Accounting */
public static final byte U_SINGLE_ACCOUNTING = 0x21; public static final byte U_SINGLE_ACCOUNTING = 0x21;
/** Underline type - Double Accounting */ /** Underline type - Double Accounting */
public static final byte U_DOUBLE_ACCOUNTING = 0x22; public static final byte U_DOUBLE_ACCOUNTING = 0x22;
/** Normal boldness (not bold) */ /** Normal boldness (not bold) */
private static final short FONT_WEIGHT_NORMAL = 0x190; private static final short FONT_WEIGHT_NORMAL = 0x190;
@ -92,7 +92,7 @@ public final class FontFormatting
private FontFormatting(byte[] rawData) { private FontFormatting(byte[] rawData) {
_rawData = rawData; _rawData = rawData;
} }
public FontFormatting() public FontFormatting()
{ {
this(new byte[RAW_DATA_SIZE]); this(new byte[RAW_DATA_SIZE]);
@ -144,7 +144,7 @@ public final class FontFormatting
private void setInt(int offset, int value) { private void setInt(int offset, int value) {
LittleEndian.putInt( _rawData, offset, value); LittleEndian.putInt( _rawData, offset, value);
} }
public byte[] getRawRecord() public byte[] getRawRecord()
{ {
return _rawData; return _rawData;
@ -152,7 +152,7 @@ public final class FontFormatting
/** /**
* sets the height of the font in 1/20th point units * sets the height of the font in 1/20th point units
* *
* *
* @param height fontheight (in points/20); or -1 to preserve the cell font height * @param height fontheight (in points/20); or -1 to preserve the cell font height
*/ */
@ -270,7 +270,7 @@ public final class FontFormatting
/** /**
* set the font weight to bold (weight=700) or to normal(weight=400) boldness. * set the font weight to bold (weight=700) or to normal(weight=400) boldness.
* *
* @param bold - set font weight to bold if true; to normal otherwise * @param bold - set font weight to bold if true; to normal otherwise
*/ */
public void setBold(boolean bold) public void setBold(boolean bold)
{ {
@ -541,9 +541,9 @@ public final class FontFormatting
return buffer.toString(); return buffer.toString();
} }
public Object clone() public Object clone()
{ {
byte[] rawData = (byte[]) _rawData.clone(); byte[] rawData = _rawData.clone();
return new FontFormatting(rawData); return new FontFormatting(rawData);
} }
} }

View File

@ -53,10 +53,7 @@ public final class OperandResolver {
if (result instanceof ErrorEval) { if (result instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) result); throw new EvaluationException((ErrorEval) result);
} }
if (result instanceof ValueEval) { return result;
return (ValueEval) result;
}
throw new RuntimeException("Unexpected eval type (" + result.getClass().getName() + ")");
} }
/** /**

View File

@ -283,7 +283,7 @@ public class EscherGraphics
excelFont = new Font( font.getName(), font.getStyle(), (int) ( font.getSize() / verticalPixelsPerPoint )); excelFont = new Font( font.getName(), font.getStyle(), (int) ( font.getSize() / verticalPixelsPerPoint ));
} }
FontDetails d = StaticFontMetrics.getFontDetails( excelFont ); FontDetails d = StaticFontMetrics.getFontDetails( excelFont );
int width = (int) ( (d.getStringWidth( str ) * 8) + 12 ); int width = d.getStringWidth( str ) * 8 + 12;
int height = (int) ( ( font.getSize() / verticalPixelsPerPoint ) + 6 ) * 2; int height = (int) ( ( font.getSize() / verticalPixelsPerPoint ) + 6 ) * 2;
y -= ( font.getSize() / verticalPixelsPerPoint ) + 2 * verticalPixelsPerPoint; // we want to draw the shape from the top-left y -= ( font.getSize() / verticalPixelsPerPoint ) + 2 * verticalPixelsPerPoint; // we want to draw the shape from the top-left
HSSFTextbox textbox = escherGroup.createTextbox( new HSSFChildAnchor( x, y, x + width, y + height ) ); HSSFTextbox textbox = escherGroup.createTextbox( new HSSFChildAnchor( x, y, x + width, y + height ) );
@ -357,13 +357,13 @@ public class EscherGraphics
* <p> * <p>
* This draws the polygon, with <code>nPoint</code> line segments. * This draws the polygon, with <code>nPoint</code> line segments.
* The first <code>nPoint&nbsp;-&nbsp;1</code> line segments are * The first <code>nPoint&nbsp;-&nbsp;1</code> line segments are
* drawn between sequential points * drawn between sequential points
* (<code>xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]</code>). * (<code>xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]</code>).
* The final line segment is a closing one, from the last point to * The final line segment is a closing one, from the last point to
* the first (assuming they are different). * the first (assuming they are different).
* <p> * <p>
* The area inside of the polygon is defined by using an * The area inside of the polygon is defined by using an
* even-odd fill rule (also known as the alternating rule), and * even-odd fill rule (also known as the alternating rule), and
* the area inside of it is filled. * the area inside of it is filled.
* @param xPoints array of the <code>x</code> coordinates. * @param xPoints array of the <code>x</code> coordinates.
* @param yPoints array of the <code>y</code> coordinates. * @param yPoints array of the <code>y</code> coordinates.
@ -454,7 +454,7 @@ public class EscherGraphics
public void setClip(int x, int y, int width, int height) public void setClip(int x, int y, int width, int height)
{ {
setClip(((Shape) (new Rectangle(x,y,width,height)))); setClip(new Rectangle(x,y,width,height));
} }
public void setClip(Shape shape) public void setClip(Shape shape)

View File

@ -70,14 +70,13 @@ import java.util.Map;
* *
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class EscherGraphics2d extends Graphics2D public final class EscherGraphics2d extends Graphics2D {
{ private EscherGraphics _escherGraphics;
private EscherGraphics escherGraphics; private BufferedImage _img;
private BufferedImage img; private AffineTransform _trans;
private AffineTransform trans; private Stroke _stroke;
private Stroke stroke; private Paint _paint;
private Paint paint; private Shape _deviceclip;
private Shape deviceclip;
private POILogger logger = POILogFactory.getLogger(getClass()); private POILogger logger = POILogFactory.getLogger(getClass());
/** /**
@ -87,7 +86,7 @@ public class EscherGraphics2d extends Graphics2D
*/ */
public EscherGraphics2d(EscherGraphics escherGraphics) public EscherGraphics2d(EscherGraphics escherGraphics)
{ {
this.escherGraphics = escherGraphics; this._escherGraphics = escherGraphics;
setImg( new BufferedImage(1, 1, 2) ); setImg( new BufferedImage(1, 1, 2) );
setColor(Color.black); setColor(Color.black);
} }
@ -130,7 +129,7 @@ public class EscherGraphics2d extends Graphics2D
public Graphics create() public Graphics create()
{ {
EscherGraphics2d g2d = new EscherGraphics2d(escherGraphics); EscherGraphics2d g2d = new EscherGraphics2d(_escherGraphics);
return g2d; return g2d;
} }
@ -148,8 +147,8 @@ public class EscherGraphics2d extends Graphics2D
Line2D shape2d = (Line2D) shape; Line2D shape2d = (Line2D) shape;
int width = 0; int width = 0;
if (stroke != null && stroke instanceof BasicStroke) { if (_stroke != null && _stroke instanceof BasicStroke) {
width = (int) ((BasicStroke)stroke).getLineWidth() * 12700; width = (int) ((BasicStroke)_stroke).getLineWidth() * 12700;
} }
drawLine((int)shape2d.getX1(), (int)shape2d.getY1(), (int)shape2d.getX2(), (int)shape2d.getY2(), width); drawLine((int)shape2d.getX1(), (int)shape2d.getY1(), (int)shape2d.getX2(), (int)shape2d.getY2(), width);
@ -223,7 +222,7 @@ public class EscherGraphics2d extends Graphics2D
public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y) public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y)
{ {
BufferedImage img = op.filter(bufferedimage, null); BufferedImage img = op.filter(bufferedimage, null);
drawImage(((Image) (img)), new AffineTransform(1.0F, 0.0F, 0.0F, 1.0F, x, y), null); drawImage(img, new AffineTransform(1.0F, 0.0F, 0.0F, 1.0F, x, y), null);
} }
public void drawLine(int x1, int y1, int x2, int y2, int width) public void drawLine(int x1, int y1, int x2, int y2, int width)
@ -234,8 +233,8 @@ public class EscherGraphics2d extends Graphics2D
public void drawLine(int x1, int y1, int x2, int y2) public void drawLine(int x1, int y1, int x2, int y2)
{ {
int width = 0; int width = 0;
if (stroke != null && stroke instanceof BasicStroke) { if (_stroke != null && _stroke instanceof BasicStroke) {
width = (int) ((BasicStroke)stroke).getLineWidth() * 12700; width = (int) ((BasicStroke)_stroke).getLineWidth() * 12700;
} }
getEscherGraphics().drawLine(x1,y1,x2,y2, width); getEscherGraphics().drawLine(x1,y1,x2,y2, width);
// draw(new GeneralPath(new java.awt.geom.Line2D.Float(x1, y1, x2, y2))); // draw(new GeneralPath(new java.awt.geom.Line2D.Float(x1, y1, x2, y2)));
@ -268,7 +267,7 @@ public class EscherGraphics2d extends Graphics2D
public void drawRect(int x, int y, int width, int height) public void drawRect(int x, int y, int width, int height)
{ {
escherGraphics.drawRect(x,y,width,height); _escherGraphics.drawRect(x,y,width,height);
} }
public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform)
@ -325,7 +324,7 @@ public class EscherGraphics2d extends Graphics2D
public void fillOval(int x, int y, int width, int height) public void fillOval(int x, int y, int width, int height)
{ {
escherGraphics.fillOval(x,y,width,height); _escherGraphics.fillOval(x,y,width,height);
} }
/** /**
@ -334,13 +333,13 @@ public class EscherGraphics2d extends Graphics2D
* <p> * <p>
* This draws the polygon, with <code>nPoint</code> line segments. * This draws the polygon, with <code>nPoint</code> line segments.
* The first <code>nPoint&nbsp;-&nbsp;1</code> line segments are * The first <code>nPoint&nbsp;-&nbsp;1</code> line segments are
* drawn between sequential points * drawn between sequential points
* (<code>xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]</code>). * (<code>xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]</code>).
* The final line segment is a closing one, from the last point to * The final line segment is a closing one, from the last point to
* the first (assuming they are different). * the first (assuming they are different).
* <p> * <p>
* The area inside of the polygon is defined by using an * The area inside of the polygon is defined by using an
* even-odd fill rule (also known as the alternating rule), and * even-odd fill rule (also known as the alternating rule), and
* the area inside of it is filled. * the area inside of it is filled.
* @param xPoints array of the <code>x</code> coordinates. * @param xPoints array of the <code>x</code> coordinates.
* @param yPoints array of the <code>y</code> coordinates. * @param yPoints array of the <code>y</code> coordinates.
@ -349,7 +348,7 @@ public class EscherGraphics2d extends Graphics2D
*/ */
public void fillPolygon(int xPoints[], int yPoints[], int nPoints) public void fillPolygon(int xPoints[], int yPoints[], int nPoints)
{ {
escherGraphics.fillPolygon(xPoints, yPoints, nPoints); _escherGraphics.fillPolygon(xPoints, yPoints, nPoints);
} }
public void fillRect(int x, int y, int width, int height) public void fillRect(int x, int y, int width, int height)
@ -382,15 +381,15 @@ public class EscherGraphics2d extends Graphics2D
public Rectangle getClipBounds() public Rectangle getClipBounds()
{ {
if(getDeviceclip() != null) if(getDeviceclip() != null) {
return getClip().getBounds(); return getClip().getBounds();
else }
return null; return null;
} }
public Color getColor() public Color getColor()
{ {
return escherGraphics.getColor(); return _escherGraphics.getColor();
} }
public Composite getComposite() public Composite getComposite()
@ -421,7 +420,7 @@ public class EscherGraphics2d extends Graphics2D
public Paint getPaint() public Paint getPaint()
{ {
return paint; return _paint;
} }
public Object getRenderingHint(java.awt.RenderingHints.Key key) public Object getRenderingHint(java.awt.RenderingHints.Key key)
@ -436,7 +435,7 @@ public class EscherGraphics2d extends Graphics2D
public Stroke getStroke() public Stroke getStroke()
{ {
return stroke; return _stroke;
} }
public AffineTransform getTransform() public AffineTransform getTransform()
@ -474,7 +473,7 @@ public class EscherGraphics2d extends Graphics2D
public void setClip(int i, int j, int k, int l) public void setClip(int i, int j, int k, int l)
{ {
setClip(((Shape) (new Rectangle(i, j, k, l)))); setClip(new Rectangle(i, j, k, l));
} }
public void setClip(Shape shape) public void setClip(Shape shape)
@ -484,7 +483,7 @@ public class EscherGraphics2d extends Graphics2D
public void setColor(Color c) public void setColor(Color c)
{ {
escherGraphics.setColor(c); _escherGraphics.setColor(c);
} }
public void setComposite(Composite composite) public void setComposite(Composite composite)
@ -501,7 +500,7 @@ public class EscherGraphics2d extends Graphics2D
{ {
if(paint1 != null) if(paint1 != null)
{ {
paint = paint1; _paint = paint1;
if(paint1 instanceof Color) if(paint1 instanceof Color)
setColor( (Color)paint1 ); setColor( (Color)paint1 );
} }
@ -524,7 +523,7 @@ public class EscherGraphics2d extends Graphics2D
public void setStroke(Stroke s) public void setStroke(Stroke s)
{ {
stroke = s; _stroke = s;
} }
public void setTransform(AffineTransform affinetransform) public void setTransform(AffineTransform affinetransform)
@ -571,42 +570,42 @@ public class EscherGraphics2d extends Graphics2D
private EscherGraphics getEscherGraphics() private EscherGraphics getEscherGraphics()
{ {
return escherGraphics; return _escherGraphics;
} }
private BufferedImage getImg() private BufferedImage getImg()
{ {
return img; return _img;
} }
private void setImg( BufferedImage img ) private void setImg( BufferedImage img )
{ {
this.img = img; this._img = img;
} }
private Graphics2D getG2D() private Graphics2D getG2D()
{ {
return (Graphics2D) img.getGraphics(); return (Graphics2D) _img.getGraphics();
} }
private AffineTransform getTrans() private AffineTransform getTrans()
{ {
return trans; return _trans;
} }
private void setTrans( AffineTransform trans ) private void setTrans( AffineTransform trans )
{ {
this.trans = trans; this._trans = trans;
} }
private Shape getDeviceclip() private Shape getDeviceclip()
{ {
return deviceclip; return _deviceclip;
} }
private void setDeviceclip( Shape deviceclip ) private void setDeviceclip( Shape deviceclip )
{ {
this.deviceclip = deviceclip; this._deviceclip = deviceclip;
} }
} }

View File

@ -28,15 +28,14 @@ import org.apache.poi.hssf.util.HSSFColor;
* *
* @author Brian Sanders (bsanders at risklabs dot com) * @author Brian Sanders (bsanders at risklabs dot com)
*/ */
public class HSSFPalette public final class HSSFPalette {
{ private PaletteRecord _palette;
private PaletteRecord palette;
protected HSSFPalette(PaletteRecord palette) protected HSSFPalette(PaletteRecord palette)
{ {
this.palette = palette; _palette = palette;
} }
/** /**
* Retrieves the color at a given index * Retrieves the color at a given index
* *
@ -45,16 +44,15 @@ public class HSSFPalette
*/ */
public HSSFColor getColor(short index) public HSSFColor getColor(short index)
{ {
//Handle the special AUTOMATIC case //Handle the special AUTOMATIC case
if (index == HSSFColor.AUTOMATIC.index) if (index == HSSFColor.AUTOMATIC.index) {
return HSSFColor.AUTOMATIC.getInstance(); return HSSFColor.AUTOMATIC.getInstance();
else { }
byte[] b = palette.getColor(index); byte[] b = _palette.getColor(index);
if (b != null) if (b != null)
{ {
return new CustomColor(index, b); return new CustomColor(index, b);
} }
}
return null; return null;
} }
/** /**
@ -66,7 +64,7 @@ public class HSSFPalette
public HSSFColor getColor(int index) { public HSSFColor getColor(int index) {
return getColor((short)index); return getColor((short)index);
} }
/** /**
* Finds the first occurance of a given color * Finds the first occurance of a given color
* *
@ -77,9 +75,9 @@ public class HSSFPalette
*/ */
public HSSFColor findColor(byte red, byte green, byte blue) public HSSFColor findColor(byte red, byte green, byte blue)
{ {
byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null; for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null;
b = palette.getColor(++i)) b = _palette.getColor(++i))
{ {
if (b[0] == red && b[1] == green && b[2] == blue) if (b[0] == red && b[1] == green && b[2] == blue)
{ {
@ -104,11 +102,11 @@ public class HSSFPalette
{ {
HSSFColor result = null; HSSFColor result = null;
int minColorDistance = Integer.MAX_VALUE; int minColorDistance = Integer.MAX_VALUE;
byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null; for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null;
b = palette.getColor(++i)) b = _palette.getColor(++i))
{ {
int colorDistance = Math.abs(red - b[0]) + int colorDistance = Math.abs(red - b[0]) +
Math.abs(green - b[1]) + Math.abs(blue - b[2]); Math.abs(green - b[1]) + Math.abs(blue - b[2]);
if (colorDistance < minColorDistance) if (colorDistance < minColorDistance)
{ {
@ -129,7 +127,7 @@ public class HSSFPalette
*/ */
public void setColorAtIndex(short index, byte red, byte green, byte blue) public void setColorAtIndex(short index, byte red, byte green, byte blue)
{ {
palette.setColor(index, red, green, blue); _palette.setColor(index, red, green, blue);
} }
/** /**
@ -144,9 +142,9 @@ public class HSSFPalette
*/ */
public HSSFColor addColor( byte red, byte green, byte blue ) public HSSFColor addColor( byte red, byte green, byte blue )
{ {
byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
short i; short i;
for (i = (short) PaletteRecord.FIRST_COLOR_INDEX; i < PaletteRecord.STANDARD_PALETTE_SIZE + PaletteRecord.FIRST_COLOR_INDEX; b = palette.getColor(++i)) for (i = PaletteRecord.FIRST_COLOR_INDEX; i < PaletteRecord.STANDARD_PALETTE_SIZE + PaletteRecord.FIRST_COLOR_INDEX; b = _palette.getColor(++i))
{ {
if (b == null) if (b == null)
{ {
@ -157,52 +155,51 @@ public class HSSFPalette
throw new RuntimeException("Could not find free color index"); throw new RuntimeException("Could not find free color index");
} }
private static class CustomColor extends HSSFColor private static final class CustomColor extends HSSFColor {
{ private short _byteOffset;
private short byteOffset; private byte _red;
private byte red; private byte _green;
private byte green; private byte _blue;
private byte blue;
public CustomColor(short byteOffset, byte[] colors)
private CustomColor(short byteOffset, byte[] colors)
{ {
this(byteOffset, colors[0], colors[1], colors[2]); this(byteOffset, colors[0], colors[1], colors[2]);
} }
private CustomColor(short byteOffset, byte red, byte green, byte blue) private CustomColor(short byteOffset, byte red, byte green, byte blue)
{ {
this.byteOffset = byteOffset; _byteOffset = byteOffset;
this.red = red; _red = red;
this.green = green; _green = green;
this.blue = blue; _blue = blue;
} }
public short getIndex() public short getIndex()
{ {
return byteOffset; return _byteOffset;
} }
public short[] getTriplet() public short[] getTriplet()
{ {
return new short[] return new short[]
{ {
(short) (red & 0xff), (short) (_red & 0xff),
(short) (green & 0xff), (short) (_green & 0xff),
(short) (blue & 0xff) (short) (_blue & 0xff)
}; };
} }
public String getHexString() public String getHexString()
{ {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(getGnumericPart(red)); sb.append(getGnumericPart(_red));
sb.append(':'); sb.append(':');
sb.append(getGnumericPart(green)); sb.append(getGnumericPart(_green));
sb.append(':'); sb.append(':');
sb.append(getGnumericPart(blue)); sb.append(getGnumericPart(_blue));
return sb.toString(); return sb.toString();
} }
private String getGnumericPart(byte color) private String getGnumericPart(byte color)
{ {
String s; String s;

View File

@ -524,9 +524,9 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
* Sets the sheet name. * Sets the sheet name.
* Will throw IllegalArgumentException if the name is duplicated or contains /\?*[] * Will throw IllegalArgumentException if the name is duplicated or contains /\?*[]
* Note - Excel allows sheet names up to 31 chars in length but other applications allow more. * Note - Excel allows sheet names up to 31 chars in length but other applications allow more.
* Excel does not crash with names longer than 31 chars, but silently truncates such names to * Excel does not crash with names longer than 31 chars, but silently truncates such names to
* 31 chars. POI enforces uniqueness on the first 31 chars. * 31 chars. POI enforces uniqueness on the first 31 chars.
* *
* @param sheetIx number (0 based) * @param sheetIx number (0 based)
*/ */
public void setSheetName(int sheetIx, String name) { public void setSheetName(int sheetIx, String name) {
@ -552,7 +552,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
public void setHidden(boolean hiddenFlag) { public void setHidden(boolean hiddenFlag) {
workbook.getWindowOne().setHidden(hiddenFlag); workbook.getWindowOne().setHidden(hiddenFlag);
} }
public boolean isSheetHidden(int sheetIx) { public boolean isSheetHidden(int sheetIx) {
validateSheetIndex(sheetIx); validateSheetIndex(sheetIx);
return workbook.isSheetHidden(sheetIx); return workbook.isSheetHidden(sheetIx);
@ -618,7 +618,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
/** /**
* @deprecated for POI internal use only (formula rendering). This method is likely to * @deprecated for POI internal use only (formula rendering). This method is likely to
* be removed in future versions of POI. * be removed in future versions of POI.
* *
* @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table * @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table
* @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record * @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
* @return the string representation of the defined or external name * @return the string representation of the defined or external name
@ -665,10 +665,10 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
clonedSheet.setActive(false); clonedSheet.setActive(false);
String name = getUniqueSheetName(srcName); String name = getUniqueSheetName(srcName);
int newSheetIndex = _sheets.size(); int newSheetIndex = _sheets.size();
_sheets.add(clonedSheet); _sheets.add(clonedSheet);
workbook.setSheetName(newSheetIndex, name); workbook.setSheetName(newSheetIndex, name);
// Check this sheet has an autofilter, (which has a built-in NameRecord at workbook level) // Check this sheet has an autofilter, (which has a built-in NameRecord at workbook level)
int filterDbNameIndex = findExistingBuiltinNameRecordIdx(sheetIndex, NameRecord.BUILTIN_FILTER_DB); int filterDbNameIndex = findExistingBuiltinNameRecordIdx(sheetIndex, NameRecord.BUILTIN_FILTER_DB);
if (filterDbNameIndex >=0) { if (filterDbNameIndex >=0) {
@ -679,7 +679,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
for (int i=0; i< ptgs.length; i++) { for (int i=0; i< ptgs.length; i++) {
Ptg ptg = ptgs[i]; Ptg ptg = ptgs[i];
ptg = ptg.copy(); ptg = ptg.copy();
if (ptg instanceof Area3DPtg) { if (ptg instanceof Area3DPtg) {
Area3DPtg a3p = (Area3DPtg) ptg; Area3DPtg a3p = (Area3DPtg) ptg;
a3p.setExternSheetIndex(newExtSheetIx); a3p.setExternSheetIndex(newExtSheetIx);
@ -698,7 +698,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
workbook.cloneDrawings(clonedSheet.getSheet()); workbook.cloneDrawings(clonedSheet.getSheet());
} }
// TODO - maybe same logic required for other/all built-in name records // TODO - maybe same logic required for other/all built-in name records
return clonedSheet; return clonedSheet;
} }
@ -966,12 +966,12 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
temp.add(new MemFuncPtg(exprsSize)); temp.add(new MemFuncPtg(exprsSize));
} }
if (startColumn >= 0) { if (startColumn >= 0) {
Area3DPtg colArea = new Area3DPtg(0, MAX_ROW, startColumn, endColumn, Area3DPtg colArea = new Area3DPtg(0, MAX_ROW, startColumn, endColumn,
false, false, false, false, externSheetIndex); false, false, false, false, externSheetIndex);
temp.add(colArea); temp.add(colArea);
} }
if (startRow >= 0) { if (startRow >= 0) {
Area3DPtg rowArea = new Area3DPtg(startRow, endRow, 0, MAX_COLUMN, Area3DPtg rowArea = new Area3DPtg(startRow, endRow, 0, MAX_COLUMN,
false, false, false, false, externSheetIndex); false, false, false, false, externSheetIndex);
temp.add(rowArea); temp.add(rowArea);
} }
@ -1136,7 +1136,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
*/ */
public HSSFCellStyle getCellStyleAt(short idx) public HSSFCellStyle getCellStyleAt(short idx)
{ {
ExtendedFormatRecord xfr = workbook.getExFormatAt((int)idx); ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this); HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this);
return style; return style;
@ -1296,7 +1296,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
int result = names.size(); int result = names.size();
return result; return result;
} }
public HSSFName getName(String name) { public HSSFName getName(String name) {
int nameIndex = getNameIndex(name); int nameIndex = getNameIndex(name);
if (nameIndex < 0) { if (nameIndex < 0) {
@ -1311,7 +1311,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
throw new IllegalStateException("There are no defined names in this workbook"); throw new IllegalStateException("There are no defined names in this workbook");
} }
if (nameIndex < 0 || nameIndex > nNames) { if (nameIndex < 0 || nameIndex > nNames) {
throw new IllegalArgumentException("Specified name index " + nameIndex throw new IllegalArgumentException("Specified name index " + nameIndex
+ " is outside the allowable range (0.." + (nNames-1) + ")."); + " is outside the allowable range (0.." + (nNames-1) + ").");
} }
return (HSSFName) names.get(nameIndex); return (HSSFName) names.get(nameIndex);
@ -1394,7 +1394,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
if (name == null) { if (name == null) {
return null; return null;
} }
return HSSFFormulaParser.toFormulaString(this, name.getNameDefinition()); return HSSFFormulaParser.toFormulaString(this, name.getNameDefinition());
} }
@ -1684,7 +1684,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
} }
} }
} }
public CreationHelper getCreationHelper() { public CreationHelper getCreationHelper() {
return new HSSFCreationHelper(this); return new HSSFCreationHelper(this);
} }

View File

@ -27,19 +27,16 @@ package org.apache.poi.hssf.util;
* @see org.apache.poi.hssf.record.MulRKRecord * @see org.apache.poi.hssf.record.MulRKRecord
* @see org.apache.poi.hssf.record.RKRecord * @see org.apache.poi.hssf.record.RKRecord
*/ */
public class RKUtil public final class RKUtil {
{ private RKUtil() {
private RKUtil() // no instances of this class
{
} }
/** /**
* Do the dirty work of decoding; made a private static method to * Do the dirty work of decoding; made a private static method to
* facilitate testing the algorithm * facilitate testing the algorithm
*/ */
public static double decodeNumber(int number) {
public static double decodeNumber(int number)
{
long raw_number = number; long raw_number = number;
// mask off the two low-order bits, 'cause they're not part of // mask off the two low-order bits, 'cause they're not part of
@ -51,7 +48,7 @@ public class RKUtil
{ {
// ok, it's just a plain ol' int; we can handle this // ok, it's just a plain ol' int; we can handle this
// trivially by casting // trivially by casting
rvalue = ( double ) (raw_number); rvalue = raw_number;
} }
else else
{ {
@ -72,5 +69,4 @@ public class RKUtil
return rvalue; return rvalue;
} }
} }

View File

@ -72,7 +72,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
private static DocumentBlock[] convertRawBlocksToBigBlocks(ListManagedBlock[] blocks) throws IOException { private static DocumentBlock[] convertRawBlocksToBigBlocks(ListManagedBlock[] blocks) throws IOException {
DocumentBlock[] result = new DocumentBlock[blocks.length]; DocumentBlock[] result = new DocumentBlock[blocks.length];
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i] = new DocumentBlock((RawDataBlock)blocks[i]); result[i] = new DocumentBlock((RawDataBlock)blocks[i]);
} }
return result; return result;
} }
@ -127,7 +127,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param stream the InputStream we read data from * @param stream the InputStream we read data from
*/ */
public POIFSDocument(String name, InputStream stream) throws IOException { public POIFSDocument(String name, InputStream stream) throws IOException {
List blocks = new ArrayList(); List<DocumentBlock> blocks = new ArrayList<DocumentBlock>();
_size = 0; _size = 0;
while (true) { while (true) {
@ -142,7 +142,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
break; break;
} }
} }
DocumentBlock[] bigBlocks = (DocumentBlock[]) blocks.toArray(new DocumentBlock[blocks.size()]); DocumentBlock[] bigBlocks = blocks.toArray(new DocumentBlock[blocks.size()]);
_big_store = new BigBlockStore(bigBlocks); _big_store = new BigBlockStore(bigBlocks);
_property = new DocumentProperty(name, _size); _property = new DocumentProperty(name, _size);
@ -201,7 +201,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
int len = buffer.length; int len = buffer.length;
DataInputBlock currentBlock = getDataInputBlock(offset); DataInputBlock currentBlock = getDataInputBlock(offset);
int blockAvailable = currentBlock.available(); int blockAvailable = currentBlock.available();
if (blockAvailable > len) { if (blockAvailable > len) {
currentBlock.readFully(buffer, 0, len); currentBlock.readFully(buffer, 0, len);
@ -249,9 +249,8 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
} }
if (_property.shouldUseSmallBlocks()) { if (_property.shouldUseSmallBlocks()) {
return SmallDocumentBlock.getDataInputBlock(_small_store.getBlocks(), offset); return SmallDocumentBlock.getDataInputBlock(_small_store.getBlocks(), offset);
} else {
return DocumentBlock.getDataInputBlock(_big_store.getBlocks(), offset);
} }
return DocumentBlock.getDataInputBlock(_big_store.getBlocks(), offset);
} }
/** /**
@ -377,11 +376,11 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
/* ********** END begin implementation of POIFSViewable ********** */ /* ********** END begin implementation of POIFSViewable ********** */
private static final class SmallBlockStore { private static final class SmallBlockStore {
private SmallDocumentBlock[] smallBlocks; private SmallDocumentBlock[] _smallBlocks;
private final POIFSDocumentPath path; private final POIFSDocumentPath _path;
private final String name; private final String _name;
private final int size; private final int _size;
private final POIFSWriterListener writer; private final POIFSWriterListener _writer;
/** /**
* Constructor * Constructor
@ -389,11 +388,11 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param blocks blocks to construct the store from * @param blocks blocks to construct the store from
*/ */
SmallBlockStore(SmallDocumentBlock[] blocks) { SmallBlockStore(SmallDocumentBlock[] blocks) {
smallBlocks = (SmallDocumentBlock[]) blocks.clone(); _smallBlocks = blocks.clone();
this.path = null; this._path = null;
this.name = null; this._name = null;
this.size = -1; this._size = -1;
this.writer = null; this._writer = null;
} }
/** /**
@ -405,41 +404,41 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param writer the object that will eventually write the document * @param writer the object that will eventually write the document
*/ */
SmallBlockStore(POIFSDocumentPath path, String name, int size, POIFSWriterListener writer) { SmallBlockStore(POIFSDocumentPath path, String name, int size, POIFSWriterListener writer) {
smallBlocks = new SmallDocumentBlock[0]; _smallBlocks = new SmallDocumentBlock[0];
this.path = path; this._path = path;
this.name = name; this._name = name;
this.size = size; this._size = size;
this.writer = writer; this._writer = writer;
} }
/** /**
* @return <code>true</code> if this store is a valid source of data * @return <code>true</code> if this store is a valid source of data
*/ */
boolean isValid() { boolean isValid() {
return smallBlocks.length > 0 || writer != null; return _smallBlocks.length > 0 || _writer != null;
} }
/** /**
* @return the SmallDocumentBlocks * @return the SmallDocumentBlocks
*/ */
SmallDocumentBlock[] getBlocks() { SmallDocumentBlock[] getBlocks() {
if (isValid() && writer != null) { if (isValid() && _writer != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(size); ByteArrayOutputStream stream = new ByteArrayOutputStream(_size);
DocumentOutputStream dstream = new DocumentOutputStream(stream, size); DocumentOutputStream dstream = new DocumentOutputStream(stream, _size);
writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, path, name, size)); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size));
smallBlocks = SmallDocumentBlock.convert(stream.toByteArray(), size); _smallBlocks = SmallDocumentBlock.convert(stream.toByteArray(), _size);
} }
return smallBlocks; return _smallBlocks;
} }
} // end private class SmallBlockStore } // end private class SmallBlockStore
private static final class BigBlockStore { private static final class BigBlockStore {
private DocumentBlock[] bigBlocks; private DocumentBlock[] bigBlocks;
private final POIFSDocumentPath path; private final POIFSDocumentPath _path;
private final String name; private final String _name;
private final int size; private final int _size;
private final POIFSWriterListener writer; private final POIFSWriterListener _writer;
/** /**
* Constructor * Constructor
@ -447,11 +446,11 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
* @param blocks the blocks making up the store * @param blocks the blocks making up the store
*/ */
BigBlockStore(DocumentBlock[] blocks) { BigBlockStore(DocumentBlock[] blocks) {
bigBlocks = (DocumentBlock[]) blocks.clone(); bigBlocks = blocks.clone();
this.path = null; _path = null;
this.name = null; _name = null;
this.size = -1; _size = -1;
this.writer = null; _writer = null;
} }
/** /**
@ -464,29 +463,29 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
*/ */
BigBlockStore(POIFSDocumentPath path, String name, int size, POIFSWriterListener writer) { BigBlockStore(POIFSDocumentPath path, String name, int size, POIFSWriterListener writer) {
bigBlocks = new DocumentBlock[0]; bigBlocks = new DocumentBlock[0];
this.path = path; _path = path;
this.name = name; _name = name;
this.size = size; _size = size;
this.writer = writer; _writer = writer;
} }
/** /**
* @return <code>true</code> if this store is a valid source of data * @return <code>true</code> if this store is a valid source of data
*/ */
boolean isValid() { boolean isValid() {
return bigBlocks.length > 0 || writer != null; return bigBlocks.length > 0 || _writer != null;
} }
/** /**
* @return the DocumentBlocks * @return the DocumentBlocks
*/ */
DocumentBlock[] getBlocks() { DocumentBlock[] getBlocks() {
if (isValid() && writer != null) { if (isValid() && _writer != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(size); ByteArrayOutputStream stream = new ByteArrayOutputStream(_size);
DocumentOutputStream dstream = new DocumentOutputStream(stream, size); DocumentOutputStream dstream = new DocumentOutputStream(stream, _size);
writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, path, name, size)); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size));
bigBlocks = DocumentBlock.convert(stream.toByteArray(), size); bigBlocks = DocumentBlock.convert(stream.toByteArray(), _size);
} }
return bigBlocks; return bigBlocks;
} }
@ -498,10 +497,10 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
*/ */
void writeBlocks(OutputStream stream) throws IOException { void writeBlocks(OutputStream stream) throws IOException {
if (isValid()) { if (isValid()) {
if (writer != null) { if (_writer != null) {
DocumentOutputStream dstream = new DocumentOutputStream(stream, size); DocumentOutputStream dstream = new DocumentOutputStream(stream, _size);
writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, path, name, size)); _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size));
dstream.writeFiller(countBlocks() * POIFSConstants.BIG_BLOCK_SIZE, dstream.writeFiller(countBlocks() * POIFSConstants.BIG_BLOCK_SIZE,
DocumentBlock.getFillByte()); DocumentBlock.getFillByte());
} else { } else {
@ -518,10 +517,10 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView
int countBlocks() { int countBlocks() {
if (isValid()) { if (isValid()) {
if (writer == null) { if (_writer == null) {
return bigBlocks.length; return bigBlocks.length;
} }
return (size + POIFSConstants.BIG_BLOCK_SIZE - 1) return (_size + POIFSConstants.BIG_BLOCK_SIZE - 1)
/ POIFSConstants.BIG_BLOCK_SIZE; / POIFSConstants.BIG_BLOCK_SIZE;
} }
return 0; return 0;

View File

@ -15,7 +15,7 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.poifs.property; package org.apache.poi.poifs.property;
@ -39,9 +39,7 @@ import org.apache.poi.util.ShortField;
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public abstract class Property public abstract class Property implements Child, POIFSViewable {
implements Child, POIFSViewable
{
static final private byte _default_fill = ( byte ) 0x00; static final private byte _default_fill = ( byte ) 0x00;
static final private int _name_size_offset = 0x40; static final private int _name_size_offset = 0x40;
static final private int _max_name_length = static final private int _max_name_length =
@ -88,10 +86,6 @@ public abstract class Property
private Child _next_child; private Child _next_child;
private Child _previous_child; private Child _previous_child;
/**
* Default constructor
*/
protected Property() protected Property()
{ {
_raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ];
@ -129,8 +123,7 @@ public abstract class Property
* @param array byte data * @param array byte data
* @param offset offset into byte data * @param offset offset into byte data
*/ */
protected Property(int index, byte [] array, int offset)
protected Property(final int index, final byte [] array, final int offset)
{ {
_raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ];
System.arraycopy(array, offset, _raw_data, 0, System.arraycopy(array, offset, _raw_data, 0,
@ -187,8 +180,7 @@ public abstract class Property
* @exception IOException on problems writing to the specified * @exception IOException on problems writing to the specified
* stream. * stream.
*/ */
public void writeData(OutputStream stream)
public void writeData(final OutputStream stream)
throws IOException throws IOException
{ {
stream.write(_raw_data); stream.write(_raw_data);
@ -200,8 +192,7 @@ public abstract class Property
* *
* @param startBlock the start block index * @param startBlock the start block index
*/ */
public void setStartBlock(int startBlock)
public void setStartBlock(final int startBlock)
{ {
_start_block.set(startBlock, _raw_data); _start_block.set(startBlock, _raw_data);
} }
@ -209,7 +200,6 @@ public abstract class Property
/** /**
* @return the start block * @return the start block
*/ */
public int getStartBlock() public int getStartBlock()
{ {
return _start_block.get(); return _start_block.get();
@ -220,7 +210,6 @@ public abstract class Property
* *
* @return size in bytes * @return size in bytes
*/ */
public int getSize() public int getSize()
{ {
return _size.get(); return _size.get();
@ -232,7 +221,6 @@ public abstract class Property
* *
* @return true if the size is less than _big_block_minimum_bytes * @return true if the size is less than _big_block_minimum_bytes
*/ */
public boolean shouldUseSmallBlocks() public boolean shouldUseSmallBlocks()
{ {
return Property.isSmall(_size.get()); return Property.isSmall(_size.get());
@ -246,8 +234,7 @@ public abstract class Property
* @return true if the length is less than * @return true if the length is less than
* _big_block_minimum_bytes * _big_block_minimum_bytes
*/ */
public static boolean isSmall(int length)
public static boolean isSmall(final int length)
{ {
return length < _big_block_minimum_bytes; return length < _big_block_minimum_bytes;
} }
@ -257,7 +244,6 @@ public abstract class Property
* *
* @return property name as String * @return property name as String
*/ */
public String getName() public String getName()
{ {
return _name; return _name;
@ -266,7 +252,6 @@ public abstract class Property
/** /**
* @return true if a directory type Property * @return true if a directory type Property
*/ */
abstract public boolean isDirectory(); abstract public boolean isDirectory();
/** /**
@ -284,7 +269,7 @@ public abstract class Property
* *
* @param name the new name * @param name the new name
*/ */
protected final void setName(final String name) protected void setName(String name)
{ {
char[] char_array = name.toCharArray(); char[] char_array = name.toCharArray();
int limit = Math.min(char_array.length, _max_name_length); int limit = Math.min(char_array.length, _max_name_length);
@ -329,8 +314,7 @@ public abstract class Property
* *
* @param propertyType the property type (root, file, directory) * @param propertyType the property type (root, file, directory)
*/ */
protected void setPropertyType(byte propertyType)
protected void setPropertyType(final byte propertyType)
{ {
_property_type.set(propertyType, _raw_data); _property_type.set(propertyType, _raw_data);
} }
@ -340,8 +324,7 @@ public abstract class Property
* *
* @param nodeColor the node color (red or black) * @param nodeColor the node color (red or black)
*/ */
protected void setNodeColor(byte nodeColor)
protected void setNodeColor(final byte nodeColor)
{ {
_node_color.set(nodeColor, _raw_data); _node_color.set(nodeColor, _raw_data);
} }
@ -351,8 +334,7 @@ public abstract class Property
* *
* @param child the child property's index in the Property Table * @param child the child property's index in the Property Table
*/ */
protected void setChildProperty(int child)
protected void setChildProperty(final int child)
{ {
_child_property.set(child, _raw_data); _child_property.set(child, _raw_data);
} }
@ -362,7 +344,6 @@ public abstract class Property
* *
* @return child property index * @return child property index
*/ */
protected int getChildIndex() protected int getChildIndex()
{ {
return _child_property.get(); return _child_property.get();
@ -373,8 +354,7 @@ public abstract class Property
* *
* @param size the size of the document, in bytes * @param size the size of the document, in bytes
*/ */
protected void setSize(int size)
protected void setSize(final int size)
{ {
_size.set(size, _raw_data); _size.set(size, _raw_data);
} }
@ -385,8 +365,7 @@ public abstract class Property
* @param index this Property's index within its containing * @param index this Property's index within its containing
* Property Table * Property Table
*/ */
protected void setIndex(int index)
protected void setIndex(final int index)
{ {
_index = index; _index = index;
} }
@ -396,7 +375,6 @@ public abstract class Property
* *
* @return the index of this Property within its Property Table * @return the index of this Property within its Property Table
*/ */
protected int getIndex() protected int getIndex()
{ {
return _index; return _index;
@ -406,7 +384,6 @@ public abstract class Property
* Perform whatever activities need to be performed prior to * Perform whatever activities need to be performed prior to
* writing * writing
*/ */
abstract protected void preWrite(); abstract protected void preWrite();
/** /**
@ -414,7 +391,6 @@ public abstract class Property
* *
* @return index of next sibling * @return index of next sibling
*/ */
int getNextChildIndex() int getNextChildIndex()
{ {
return _next_property.get(); return _next_property.get();
@ -425,7 +401,6 @@ public abstract class Property
* *
* @return index of previous sibling * @return index of previous sibling
*/ */
int getPreviousChildIndex() int getPreviousChildIndex()
{ {
return _previous_property.get(); return _previous_property.get();
@ -438,20 +413,16 @@ public abstract class Property
* *
* @return true if the index is valid * @return true if the index is valid
*/ */
static boolean isValidIndex(int index) static boolean isValidIndex(int index)
{ {
return index != _NO_INDEX; return index != _NO_INDEX;
} }
/* ********** START implementation of Child ********** */
/** /**
* Get the next Child, if any * Get the next Child, if any
* *
* @return the next Child; may return null * @return the next Child; may return null
*/ */
public Child getNextChild() public Child getNextChild()
{ {
return _next_child; return _next_child;
@ -462,7 +433,6 @@ public abstract class Property
* *
* @return the previous Child; may return null * @return the previous Child; may return null
*/ */
public Child getPreviousChild() public Child getPreviousChild()
{ {
return _previous_child; return _previous_child;
@ -474,8 +444,7 @@ public abstract class Property
* @param child the new 'next' child; may be null, which has the * @param child the new 'next' child; may be null, which has the
* effect of saying there is no 'next' child * effect of saying there is no 'next' child
*/ */
public void setNextChild(Child child)
public void setNextChild(final Child child)
{ {
_next_child = child; _next_child = child;
_next_property.set((child == null) ? _NO_INDEX _next_property.set((child == null) ? _NO_INDEX
@ -489,8 +458,7 @@ public abstract class Property
* @param child the new 'previous' child; may be null, which has * @param child the new 'previous' child; may be null, which has
* the effect of saying there is no 'previous' child * the effect of saying there is no 'previous' child
*/ */
public void setPreviousChild(Child child)
public void setPreviousChild(final Child child)
{ {
_previous_child = child; _previous_child = child;
_previous_property.set((child == null) ? _NO_INDEX _previous_property.set((child == null) ? _NO_INDEX
@ -498,16 +466,12 @@ public abstract class Property
.getIndex(), _raw_data); .getIndex(), _raw_data);
} }
/* ********** END implementation of Child ********** */
/* ********** START begin implementation of POIFSViewable ********** */
/** /**
* Get an array of objects, some of which may implement * Get an array of objects, some of which may implement
* POIFSViewable * POIFSViewable
* *
* @return an array of Object; may not be null, but may be empty * @return an array of Object; may not be null, but may be empty
*/ */
public Object [] getViewableArray() public Object [] getViewableArray()
{ {
Object[] results = new Object[ 5 ]; Object[] results = new Object[ 5 ];
@ -518,11 +482,11 @@ public abstract class Property
long time = _days_1.get(); long time = _days_1.get();
time <<= 32; time <<= 32;
time += (( long ) _seconds_1.get()) & 0x0000FFFFL; time += _seconds_1.get() & 0x0000FFFFL;
results[ 3 ] = "Time 1 = " + time; results[ 3 ] = "Time 1 = " + time;
time = _days_2.get(); time = _days_2.get();
time <<= 32; time <<= 32;
time += (( long ) _seconds_2.get()) & 0x0000FFFFL; time += _seconds_2.get() & 0x0000FFFFL;
results[ 4 ] = "Time 2 = " + time; results[ 4 ] = "Time 2 = " + time;
return results; return results;
} }
@ -534,7 +498,6 @@ public abstract class Property
* @return an Iterator; may not be null, but may have an empty * @return an Iterator; may not be null, but may have an empty
* back end store * back end store
*/ */
public Iterator getViewableIterator() public Iterator getViewableIterator()
{ {
return Collections.EMPTY_LIST.iterator(); return Collections.EMPTY_LIST.iterator();
@ -547,7 +510,6 @@ public abstract class Property
* @return true if a viewer should call getViewableArray, false if * @return true if a viewer should call getViewableArray, false if
* a viewer should call getViewableIterator * a viewer should call getViewableIterator
*/ */
public boolean preferArray() public boolean preferArray()
{ {
return true; return true;
@ -559,7 +521,6 @@ public abstract class Property
* *
* @return short description * @return short description
*/ */
public String getShortDescription() public String getShortDescription()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
@ -567,7 +528,4 @@ public abstract class Property
buffer.append("Property: \"").append(getName()).append("\""); buffer.append("Property: \"").append(getName()).append("\"");
return buffer.toString(); return buffer.toString();
} }
}
/* ********** END begin implementation of POIFSViewable ********** */
} // end public abstract class Property

View File

@ -393,8 +393,7 @@ public final class WorkbookEvaluator {
return fe.getFreeRefFunction().evaluate(ops, workbook, sheetIndex, srcRowNum, srcColNum); return fe.getFreeRefFunction().evaluate(ops, workbook, sheetIndex, srcRowNum, srcColNum);
} }
} }
// TODO - fix return type of this evaluate method: return operation.evaluate(ops, srcRowNum, (short)srcColNum);
return (ValueEval) operation.evaluate(ops, srcRowNum, (short)srcColNum);
} }
private SheetRefEvaluator createExternSheetRefEvaluator(EvaluationTracker tracker, private SheetRefEvaluator createExternSheetRefEvaluator(EvaluationTracker tracker,
ExternSheetReferenceToken ptg) { ExternSheetReferenceToken ptg) {

View File

@ -26,197 +26,183 @@ package org.apache.poi.ss.util;
* @author Andrew C. Oliver acoliver at apache dot org * @author Andrew C. Oliver acoliver at apache dot org
* @deprecated (Aug-2008) use {@link CellRangeAddress} * @deprecated (Aug-2008) use {@link CellRangeAddress}
*/ */
public class Region implements Comparable { public class Region implements Comparable<Region> {
private int rowFrom; private int _rowFrom;
private short colFrom; private short _colFrom;
private int rowTo; private int _rowTo;
private short colTo; private short _colTo;
/** /**
* Creates a new instance of Region (0,0 - 0,0) * Creates a new instance of Region (0,0 - 0,0)
*/ */
public Region()
{
}
public Region() public Region(int rowFrom, short colFrom, int rowTo, short colTo)
{ {
} this._rowFrom = rowFrom;
this._rowTo = rowTo;
this._colFrom = colFrom;
this._colTo = colTo;
}
public Region(int rowFrom, short colFrom, int rowTo, short colTo) public Region(String ref) {
{ CellReference cellReferenceFrom = new CellReference(ref.substring(0, ref.indexOf(":")));
this.rowFrom = rowFrom; CellReference cellReferenceTo = new CellReference(ref.substring(ref.indexOf(":") + 1));
this.rowTo = rowTo; this._rowFrom = cellReferenceFrom.getRow();
this.colFrom = colFrom; this._colFrom = cellReferenceFrom.getCol();
this.colTo = colTo; this._rowTo = cellReferenceTo.getRow();
} this._colTo = cellReferenceTo.getCol();
public Region(String ref) {
CellReference cellReferenceFrom = new CellReference(ref.substring(0, ref.indexOf(":")));
CellReference cellReferenceTo = new CellReference(ref.substring(ref.indexOf(":") + 1));
this.rowFrom = cellReferenceFrom.getRow();
this.colFrom = (short) cellReferenceFrom.getCol();
this.rowTo = cellReferenceTo.getRow();
this.colTo = (short) cellReferenceTo.getCol();
} }
/** /**
* get the upper left hand corner column number * get the upper left hand corner column number
* *
* @return column number for the upper left hand corner * @return column number for the upper left hand corner
*/ */
public short getColumnFrom()
public short getColumnFrom() {
{ return _colFrom;
return colFrom; }
}
/**
* get the upper left hand corner row number
*
* @return row number for the upper left hand corner
*/
public int getRowFrom()
{
return rowFrom;
}
/**
* get the lower right hand corner column number
*
* @return column number for the lower right hand corner
*/
public short getColumnTo()
{
return colTo;
}
/**
* get the lower right hand corner row number
*
* @return row number for the lower right hand corner
*/
public int getRowTo()
{
return rowTo;
}
/**
* set the upper left hand corner column number
*
* @param colFrom column number for the upper left hand corner
*/
public void setColumnFrom(short colFrom)
{
this.colFrom = colFrom;
}
/**
* set the upper left hand corner row number
*
* @param rowFrom row number for the upper left hand corner
*/
public void setRowFrom(int rowFrom)
{
this.rowFrom = rowFrom;
}
/**
* set the lower right hand corner column number
*
* @param colTo column number for the lower right hand corner
*/
public void setColumnTo(short colTo)
{
this.colTo = colTo;
}
/**
* get the lower right hand corner row number
*
* @param rowTo row number for the lower right hand corner
*/
public void setRowTo(int rowTo)
{
this.rowTo = rowTo;
}
/**
* Answers: "is the row/column inside this range?"
*
* @return <code>true</code> if the cell is in the range and
* <code>false</code> if it is not
*/
public boolean contains(int row, short col)
{
if ((this.rowFrom <= row) && (this.rowTo >= row)
&& (this.colFrom <= col) && (this.colTo >= col))
{
// System.out.println("Region ("+rowFrom+","+colFrom+","+rowTo+","+
// colTo+") does contain "+row+","+col);
return true;
}
return false;
}
public boolean equals(Region r)
{
return (compareTo(r) == 0);
}
/**
* Compares that the given region is the same less than or greater than this
* region. If any regional coordiant passed in is less than this regions
* coordinants then a positive integer is returned. Otherwise a negative
* integer is returned.
*
* @param r region
* @see #compareTo(Object)
*/
public int compareTo(Region r)
{
if ((this.getRowFrom() == r.getRowFrom())
&& (this.getColumnFrom() == r.getColumnFrom())
&& (this.getRowTo() == r.getRowTo())
&& (this.getColumnTo() == r.getColumnTo()))
{
return 0;
}
if ((this.getRowFrom() < r.getRowFrom())
|| (this.getColumnFrom() < r.getColumnFrom())
|| (this.getRowTo() < r.getRowTo())
|| (this.getColumnTo() < r.getColumnTo()))
{
return 1;
}
return -1;
}
public int compareTo(Object o)
{
return compareTo(( Region ) o);
}
/**
* @return the size of the region (number of cells in the area).
*/
public int getArea() {
return (rowTo - rowFrom + 1) * (colTo - colFrom + 1);
}
/** /**
* Convert a List of CellRange objects to an array of regions * get the upper left hand corner row number
* *
* @return row number for the upper left hand corner
*/
public int getRowFrom()
{
return _rowFrom;
}
/**
* get the lower right hand corner column number
*
* @return column number for the lower right hand corner
*/
public short getColumnTo()
{
return _colTo;
}
/**
* get the lower right hand corner row number
*
* @return row number for the lower right hand corner
*/
public int getRowTo()
{
return _rowTo;
}
/**
* set the upper left hand corner column number
*
* @param colFrom column number for the upper left hand corner
*/
public void setColumnFrom(short colFrom)
{
this._colFrom = colFrom;
}
/**
* set the upper left hand corner row number
*
* @param rowFrom row number for the upper left hand corner
*/
public void setRowFrom(int rowFrom)
{
this._rowFrom = rowFrom;
}
/**
* set the lower right hand corner column number
*
* @param colTo column number for the lower right hand corner
*/
public void setColumnTo(short colTo)
{
this._colTo = colTo;
}
/**
* get the lower right hand corner row number
*
* @param rowTo row number for the lower right hand corner
*/
public void setRowTo(int rowTo)
{
this._rowTo = rowTo;
}
/**
* Answers: "is the row/column inside this range?"
*
* @return <code>true</code> if the cell is in the range and
* <code>false</code> if it is not
*/
public boolean contains(int row, short col)
{
if ((this._rowFrom <= row) && (this._rowTo >= row)
&& (this._colFrom <= col) && (this._colTo >= col))
{
// System.out.println("Region ("+rowFrom+","+colFrom+","+rowTo+","+
// colTo+") does contain "+row+","+col);
return true;
}
return false;
}
public boolean equals(Region r)
{
return (compareTo(r) == 0);
}
/**
* Compares that the given region is the same less than or greater than this
* region. If any regional coordiant passed in is less than this regions
* coordinants then a positive integer is returned. Otherwise a negative
* integer is returned.
*
* @param r region
* @see #compareTo(Object)
*/
public int compareTo(Region r)
{
if ((this.getRowFrom() == r.getRowFrom())
&& (this.getColumnFrom() == r.getColumnFrom())
&& (this.getRowTo() == r.getRowTo())
&& (this.getColumnTo() == r.getColumnTo()))
{
return 0;
}
if ((this.getRowFrom() < r.getRowFrom())
|| (this.getColumnFrom() < r.getColumnFrom())
|| (this.getRowTo() < r.getRowTo())
|| (this.getColumnTo() < r.getColumnTo()))
{
return 1;
}
return -1;
}
/**
* @return the size of the region (number of cells in the area).
*/
public int getArea() {
return (_rowTo - _rowFrom + 1) * (_colTo - _colFrom + 1);
}
/**
* Convert a List of CellRange objects to an array of regions
*
* @param cellRanges list of CellRange objects * @param cellRanges list of CellRange objects
* @return regions * @return regions
*/ */
@ -225,7 +211,7 @@ public class Region implements Comparable {
if(size < 1) { if(size < 1) {
return new Region[0]; return new Region[0];
} }
Region[] result = new Region[size]; Region[] result = new Region[size];
for (int i = 0; i != size; i++) { for (int i = 0; i != size; i++) {
@ -235,9 +221,9 @@ public class Region implements Comparable {
} }
private static Region convertToRegion(CellRangeAddress cr) { private static Region convertToRegion(CellRangeAddress cr) {
return new Region(cr.getFirstRow(), (short)cr.getFirstColumn(), cr.getLastRow(), (short)cr.getLastColumn()); return new Region(cr.getFirstRow(), (short)cr.getFirstColumn(), cr.getLastRow(), (short)cr.getLastColumn());
} }
@ -246,7 +232,7 @@ public class Region implements Comparable {
if(size < 1) { if(size < 1) {
return new CellRangeAddress[0]; return new CellRangeAddress[0];
} }
CellRangeAddress[] result = new CellRangeAddress[size]; CellRangeAddress[] result = new CellRangeAddress[size];
for (int i = 0; i != size; i++) { for (int i = 0; i != size; i++) {
@ -259,13 +245,13 @@ public class Region implements Comparable {
return new CellRangeAddress(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r.getColumnTo()); return new CellRangeAddress(r.getRowFrom(), r.getRowTo(), r.getColumnFrom(), r.getColumnTo());
} }
/** /**
* @return the string reference for this region * @return the string reference for this region
*/ */
public String getRegionRef() { public String getRegionRef() {
CellReference cellRefFrom = new CellReference(rowFrom, colFrom); CellReference cellRefFrom = new CellReference(_rowFrom, _colFrom);
CellReference cellRefTo = new CellReference(rowTo, colTo); CellReference cellRefTo = new CellReference(_rowTo, _colTo);
String ref = cellRefFrom.formatAsString() + ":" + cellRefTo.formatAsString(); String ref = cellRefFrom.formatAsString() + ":" + cellRefTo.formatAsString();
return ref; return ref;
} }
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.util; package org.apache.poi.util;
@ -89,34 +87,20 @@ import java.util.*;
* *
* @author Marc Johnson (mjohnson at apache dot org) * @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class BinaryTree // final for performance //for performance
public class BinaryTree extends AbstractMap {
extends AbstractMap final Node[] _root;
{ int _size = 0;
private Node[] _root = new Node[] int _modifications = 0;
{ private final Set[] _key_set = new Set[] { null, null };
null, null private final Set[] _entry_set = new Set[] { null, null };
}; private final Collection[] _value_collection = new Collection[] { null, null };
private int _size = 0; static int _KEY = 0;
private int _modifications = 0; static int _VALUE = 1;
private Set[] _key_set = new Set[] private static int _INDEX_SUM = _KEY + _VALUE;
{ private static int _MINIMUM_INDEX = 0;
null, null private static int _INDEX_COUNT = 2;
}; private static String[] _data_name = new String[]
private Set[] _entry_set = new Set[]
{
null, null
};
private Collection[] _value_collection = new Collection[]
{
null, null
};
private static final int _KEY = 0;
private static final int _VALUE = 1;
private static final int _INDEX_SUM = _KEY + _VALUE;
private static final int _MINIMUM_INDEX = 0;
private static final int _INDEX_COUNT = 2;
private static final String[] _data_name = new String[]
{ {
"key", "value" "key", "value"
}; };
@ -124,9 +108,8 @@ public final class BinaryTree // final for performance
/** /**
* Construct a new BinaryTree * Construct a new BinaryTree
*/ */
public BinaryTree() {
public BinaryTree() _root = new Node[]{ null, null, };
{
} }
/** /**
@ -146,11 +129,11 @@ public final class BinaryTree // final for performance
* or duplicate values in the * or duplicate values in the
* map * map
*/ */
public BinaryTree(Map map)
public BinaryTree(final Map map)
throws ClassCastException, NullPointerException, throws ClassCastException, NullPointerException,
IllegalArgumentException IllegalArgumentException
{ {
this();
putAll(map); putAll(map);
} }
@ -167,8 +150,7 @@ public final class BinaryTree // final for performance
* inappropriate type for this map. * inappropriate type for this map.
* @exception NullPointerException if the value is null * @exception NullPointerException if the value is null
*/ */
public Object getKeyForValue(Object value)
public Object getKeyForValue(final Object value)
throws ClassCastException, NullPointerException throws ClassCastException, NullPointerException
{ {
return doGet(( Comparable ) value, _VALUE); return doGet(( Comparable ) value, _VALUE);
@ -182,8 +164,7 @@ public final class BinaryTree // final for performance
* @return previous key associated with specified value, or null * @return previous key associated with specified value, or null
* if there was no mapping for value. * if there was no mapping for value.
*/ */
public Object removeValue(Object value)
public Object removeValue(final Object value)
{ {
return doRemove(( Comparable ) value, _VALUE); return doRemove(( Comparable ) value, _VALUE);
} }
@ -207,7 +188,6 @@ public final class BinaryTree // final for performance
* *
* @return a set view of the mappings contained in this map. * @return a set view of the mappings contained in this map.
*/ */
public Set entrySetByValue() public Set entrySetByValue()
{ {
if (_entry_set[ _VALUE ] == null) if (_entry_set[ _VALUE ] == null)
@ -423,8 +403,7 @@ public final class BinaryTree // final for performance
* key. null if the specified key or value could not be * key. null if the specified key or value could not be
* found * found
*/ */
private Object doRemove(Comparable o, int index)
private Object doRemove(final Comparable o, final int index)
{ {
Node node = lookup(o, index); Node node = lookup(o, index);
Object rval = null; Object rval = null;
@ -447,8 +426,7 @@ public final class BinaryTree // final for performance
* key was mapped); null if we couldn't find the specified * key was mapped); null if we couldn't find the specified
* object * object
*/ */
private Object doGet(Comparable o, int index)
private Object doGet(final Comparable o, final int index)
{ {
checkNonNullComparable(o, index); checkNonNullComparable(o, index);
Node node = lookup(o, index); Node node = lookup(o, index);
@ -464,8 +442,7 @@ public final class BinaryTree // final for performance
* *
* @return _VALUE (if _KEY was specified), else _KEY * @return _VALUE (if _KEY was specified), else _KEY
*/ */
private int oppositeIndex(int index)
private int oppositeIndex(final int index)
{ {
// old trick ... to find the opposite of a value, m or n, // old trick ... to find the opposite of a value, m or n,
@ -483,8 +460,7 @@ public final class BinaryTree // final for performance
* @return the desired Node, or null if there is no mapping of the * @return the desired Node, or null if there is no mapping of the
* specified data * specified data
*/ */
public Node lookup(Comparable data, int index)
private Node lookup(final Comparable data, final int index)
{ {
Node rval = null; Node rval = null;
Node node = _root[ index ]; Node node = _root[ index ];
@ -498,11 +474,8 @@ public final class BinaryTree // final for performance
rval = node; rval = node;
break; break;
} }
else node = (cmp < 0) ? node.getLeft(index)
{ : node.getRight(index);
node = (cmp < 0) ? node.getLeft(index)
: node.getRight(index);
}
} }
return rval; return rval;
} }
@ -516,10 +489,9 @@ public final class BinaryTree // final for performance
* @return negative value if o1 < o2; 0 if o1 == o2; positive * @return negative value if o1 < o2; 0 if o1 == o2; positive
* value if o1 > o2 * value if o1 > o2
*/ */
private static int compare(Comparable o1, Comparable o2)
private static int compare(final Comparable o1, final Comparable o2)
{ {
return (( Comparable ) o1).compareTo(o2); return o1.compareTo(o2);
} }
/** /**
@ -532,8 +504,7 @@ public final class BinaryTree // final for performance
* @return the smallest node, from the specified node, in the * @return the smallest node, from the specified node, in the
* specified mapping * specified mapping
*/ */
static Node leastNode(Node node, int index)
private static Node leastNode(final Node node, final int index)
{ {
Node rval = node; Node rval = node;
@ -555,8 +526,7 @@ public final class BinaryTree // final for performance
* *
* @return the specified node * @return the specified node
*/ */
static Node nextGreater(Node node, int index)
private Node nextGreater(final Node node, final int index)
{ {
Node rval = null; Node rval = null;
@ -601,9 +571,7 @@ public final class BinaryTree // final for performance
* @param to the node whose color we're changing; may be null * @param to the node whose color we're changing; may be null
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static void copyColor(Node from, Node to, int index)
private static void copyColor(final Node from, final Node to,
final int index)
{ {
if (to != null) if (to != null)
{ {
@ -627,11 +595,9 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static boolean isRed(Node node, int index)
private static boolean isRed(final Node node, final int index)
{ {
return ((node == null) ? false return node == null ? false : node.isRed(index);
: node.isRed(index));
} }
/** /**
@ -641,11 +607,9 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static boolean isBlack(Node node, int index)
private static boolean isBlack(final Node node, final int index)
{ {
return ((node == null) ? true return node == null ? true : node.isBlack(index);
: node.isBlack(index));
} }
/** /**
@ -654,8 +618,7 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static void makeRed(Node node, int index)
private static void makeRed(final Node node, final int index)
{ {
if (node != null) if (node != null)
{ {
@ -669,8 +632,7 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static void makeBlack(Node node, int index)
private static void makeBlack(final Node node, final int index)
{ {
if (node != null) if (node != null)
{ {
@ -685,8 +647,7 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static Node getGrandParent(Node node, int index)
private static Node getGrandParent(final Node node, final int index)
{ {
return getParent(getParent(node, index), index); return getParent(getParent(node, index), index);
} }
@ -698,8 +659,7 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static Node getParent(Node node, int index)
private static Node getParent(final Node node, final int index)
{ {
return ((node == null) ? null return ((node == null) ? null
: node.getParent(index)); : node.getParent(index));
@ -712,8 +672,7 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static Node getRightChild(Node node, int index)
private static Node getRightChild(final Node node, final int index)
{ {
return (node == null) ? null return (node == null) ? null
: node.getRight(index); : node.getRight(index);
@ -726,8 +685,7 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static Node getLeftChild(Node node, int index)
private static Node getLeftChild(final Node node, final int index)
{ {
return (node == null) ? null return (node == null) ? null
: node.getLeft(index); : node.getLeft(index);
@ -744,15 +702,14 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static boolean isLeftChild(Node node, int index) {
private static boolean isLeftChild(final Node node, final int index) if (node == null) {
{ return true;
return (node == null) ? true }
: ((node.getParent(index) == null) ? false if (node.getParent(index) == null) {
: (node return false;
== node.getParent( }
index).getLeft( return node == node.getParent(index).getLeft(index);
index)));
} }
/** /**
@ -766,15 +723,15 @@ public final class BinaryTree // final for performance
* @param node the node (may be null) in question * @param node the node (may be null) in question
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private static boolean isRightChild(Node node, int index)
private static boolean isRightChild(final Node node, final int index)
{ {
return (node == null) ? true if (node == null) {
: ((node.getParent(index) == null) ? false return true;
: (node }
== node.getParent( if (node.getParent(index) == null) {
index).getRight( return false;
index))); }
return node == node.getParent(index).getRight(index);
} }
/** /**
@ -783,8 +740,7 @@ public final class BinaryTree // final for performance
* @param node the node to be rotated * @param node the node to be rotated
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private void rotateLeft(Node node, int index)
private void rotateLeft(final Node node, final int index)
{ {
Node right_child = node.getRight(index); Node right_child = node.getRight(index);
@ -818,8 +774,7 @@ public final class BinaryTree // final for performance
* @param node the node to be rotated * @param node the node to be rotated
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private void rotateRight(Node node, int index)
private void rotateRight(final Node node, final int index)
{ {
Node left_child = node.getLeft(index); Node left_child = node.getLeft(index);
@ -854,8 +809,7 @@ public final class BinaryTree // final for performance
* @param inserted_node the node to be inserted * @param inserted_node the node to be inserted
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private void doRedBlackInsert(Node inserted_node, int index)
private void doRedBlackInsert(final Node inserted_node, final int index)
{ {
Node current_node = inserted_node; Node current_node = inserted_node;
@ -931,8 +885,7 @@ public final class BinaryTree // final for performance
* *
* @param deleted_node the node to be deleted * @param deleted_node the node to be deleted
*/ */
void doRedBlackDelete(Node deleted_node)
private void doRedBlackDelete(final Node deleted_node)
{ {
for (int index = _MINIMUM_INDEX; index < _INDEX_COUNT; index++) for (int index = _MINIMUM_INDEX; index < _INDEX_COUNT; index++)
{ {
@ -1023,9 +976,8 @@ public final class BinaryTree // final for performance
* @param replacement_node the node being replaced * @param replacement_node the node being replaced
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private void doRedBlackDeleteFixup(Node replacement_node,
private void doRedBlackDeleteFixup(final Node replacement_node, int index)
final int index)
{ {
Node current_node = replacement_node; Node current_node = replacement_node;
@ -1121,8 +1073,7 @@ public final class BinaryTree // final for performance
* @param y another node * @param y another node
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
private void swapPosition(Node x, Node y, int index)
private void swapPosition(final Node x, final Node y, final int index)
{ {
// Save initial values. // Save initial values.
@ -1244,9 +1195,8 @@ public final class BinaryTree // final for performance
* @exception NullPointerException if o is null * @exception NullPointerException if o is null
* @exception ClassCastException if o is not Comparable * @exception ClassCastException if o is not Comparable
*/ */
private static void checkNonNullComparable(Object o,
private static void checkNonNullComparable(final Object o, int index)
final int index)
{ {
if (o == null) if (o == null)
{ {
@ -1268,8 +1218,7 @@ public final class BinaryTree // final for performance
* @exception NullPointerException if key is null * @exception NullPointerException if key is null
* @exception ClassCastException if key is not Comparable * @exception ClassCastException if key is not Comparable
*/ */
private static void checkKey(Object key)
private static void checkKey(final Object key)
{ {
checkNonNullComparable(key, _KEY); checkNonNullComparable(key, _KEY);
} }
@ -1282,8 +1231,7 @@ public final class BinaryTree // final for performance
* @exception NullPointerException if value is null * @exception NullPointerException if value is null
* @exception ClassCastException if value is not Comparable * @exception ClassCastException if value is not Comparable
*/ */
private static void checkValue(Object value)
private static void checkValue(final Object value)
{ {
checkNonNullComparable(value, _VALUE); checkNonNullComparable(value, _VALUE);
} }
@ -1298,8 +1246,7 @@ public final class BinaryTree // final for performance
* @exception NullPointerException if key or value is null * @exception NullPointerException if key or value is null
* @exception ClassCastException if key or value is not Comparable * @exception ClassCastException if key or value is not Comparable
*/ */
private static void checkKeyAndValue(Object key, Object value)
private static void checkKeyAndValue(final Object key, final Object value)
{ {
checkKey(key); checkKey(key);
checkValue(value); checkValue(value);
@ -1310,7 +1257,6 @@ public final class BinaryTree // final for performance
* concurrent modification of the map through the map and through * concurrent modification of the map through the map and through
* an Iterator from one of its Set or Collection views * an Iterator from one of its Set or Collection views
*/ */
private void modify() private void modify()
{ {
_modifications++; _modifications++;
@ -1319,7 +1265,6 @@ public final class BinaryTree // final for performance
/** /**
* bump up the size and note that the map has changed * bump up the size and note that the map has changed
*/ */
private void grow() private void grow()
{ {
modify(); modify();
@ -1329,7 +1274,6 @@ public final class BinaryTree // final for performance
/** /**
* decrement the size and note that the map has changed * decrement the size and note that the map has changed
*/ */
private void shrink() private void shrink()
{ {
modify(); modify();
@ -1344,8 +1288,7 @@ public final class BinaryTree // final for performance
* @exception IllegalArgumentException if the node already exists * @exception IllegalArgumentException if the node already exists
* in the value mapping * in the value mapping
*/ */
private void insertValue(Node newNode)
private void insertValue(final Node newNode)
throws IllegalArgumentException throws IllegalArgumentException
{ {
Node node = _root[ _VALUE ]; Node node = _root[ _VALUE ];
@ -1400,7 +1343,6 @@ public final class BinaryTree // final for performance
* *
* @return the number of key-value mappings in this map. * @return the number of key-value mappings in this map.
*/ */
public int size() public int size()
{ {
return _size; return _size;
@ -1419,8 +1361,7 @@ public final class BinaryTree // final for performance
* type for this map. * type for this map.
* @exception NullPointerException if the key is null * @exception NullPointerException if the key is null
*/ */
public boolean containsKey(Object key)
public boolean containsKey(final Object key)
throws ClassCastException, NullPointerException throws ClassCastException, NullPointerException
{ {
checkKey(key); checkKey(key);
@ -1436,8 +1377,7 @@ public final class BinaryTree // final for performance
* @return true if this map maps one or more keys to the specified * @return true if this map maps one or more keys to the specified
* value. * value.
*/ */
public boolean containsValue(Object value)
public boolean containsValue(final Object value)
{ {
checkValue(value); checkValue(value);
return lookup(( Comparable ) value, _VALUE) != null; return lookup(( Comparable ) value, _VALUE) != null;
@ -1456,8 +1396,7 @@ public final class BinaryTree // final for performance
* type for this map. * type for this map.
* @exception NullPointerException if the key is null * @exception NullPointerException if the key is null
*/ */
public Object get(Object key)
public Object get(final Object key)
throws ClassCastException, NullPointerException throws ClassCastException, NullPointerException
{ {
return doGet(( Comparable ) key, _KEY); return doGet(( Comparable ) key, _KEY);
@ -1483,8 +1422,7 @@ public final class BinaryTree // final for performance
* value duplicates an * value duplicates an
* existing value * existing value
*/ */
public Object put(Object key, Object value)
public Object put(final Object key, final Object value)
throws ClassCastException, NullPointerException, throws ClassCastException, NullPointerException,
IllegalArgumentException IllegalArgumentException
{ {
@ -1562,8 +1500,7 @@ public final class BinaryTree // final for performance
* @return previous value associated with specified key, or null * @return previous value associated with specified key, or null
* if there was no mapping for key. * if there was no mapping for key.
*/ */
public Object remove(Object key)
public Object remove(final Object key)
{ {
return doRemove(( Comparable ) key, _KEY); return doRemove(( Comparable ) key, _KEY);
} }
@ -1571,7 +1508,6 @@ public final class BinaryTree // final for performance
/** /**
* Removes all mappings from this map * Removes all mappings from this map
*/ */
public void clear() public void clear()
{ {
modify(); modify();
@ -1592,7 +1528,6 @@ public final class BinaryTree // final for performance
* *
* @return a set view of the keys contained in this map. * @return a set view of the keys contained in this map.
*/ */
public Set keySet() public Set keySet()
{ {
if (_key_set[ _KEY ] == null) if (_key_set[ _KEY ] == null)
@ -1650,7 +1585,6 @@ public final class BinaryTree // final for performance
* *
* @return a collection view of the values contained in this map. * @return a collection view of the values contained in this map.
*/ */
public Collection values() public Collection values()
{ {
if (_value_collection[ _KEY ] == null) if (_value_collection[ _KEY ] == null)
@ -1723,7 +1657,6 @@ public final class BinaryTree // final for performance
* *
* @return a set view of the mappings contained in this map. * @return a set view of the mappings contained in this map.
*/ */
public Set entrySet() public Set entrySet()
{ {
if (_entry_set[ _KEY ] == null) if (_entry_set[ _KEY ] == null)
@ -1803,8 +1736,7 @@ public final class BinaryTree // final for performance
* *
* @param type * @param type
*/ */
BinaryTreeIterator(int type)
BinaryTreeIterator(final int type)
{ {
_type = type; _type = type;
_expected_modifications = BinaryTree.this._modifications; _expected_modifications = BinaryTree.this._modifications;
@ -1825,7 +1757,7 @@ public final class BinaryTree // final for performance
* @return true if the iterator has more elements. * @return true if the iterator has more elements.
*/ */
public final boolean hasNext() public boolean hasNext()
{ {
return _next_node != null; return _next_node != null;
} }
@ -1842,7 +1774,7 @@ public final class BinaryTree // final for performance
* back * back
*/ */
public final Object next() public Object next()
throws NoSuchElementException, ConcurrentModificationException throws NoSuchElementException, ConcurrentModificationException
{ {
if (_next_node == null) if (_next_node == null)
@ -1878,7 +1810,7 @@ public final class BinaryTree // final for performance
* back * back
*/ */
public final void remove() public void remove()
throws IllegalStateException, ConcurrentModificationException throws IllegalStateException, ConcurrentModificationException
{ {
if (_last_returned_node == null) if (_last_returned_node == null)
@ -1897,7 +1829,7 @@ public final class BinaryTree // final for performance
/* ********** END implementation of Iterator ********** */ /* ********** END implementation of Iterator ********** */
} // end private abstract class BinaryTreeIterator } // end private abstract class BinaryTreeIterator
// final for performance // for performance
private static final class Node private static final class Node
implements Map.Entry implements Map.Entry
{ {
@ -1917,7 +1849,7 @@ public final class BinaryTree // final for performance
* @param value * @param value
*/ */
Node(final Comparable key, final Comparable value) Node(Comparable key, Comparable value)
{ {
_data = new Comparable[] _data = new Comparable[]
{ {
@ -1949,8 +1881,7 @@ public final class BinaryTree // final for performance
* *
* @return the key or value * @return the key or value
*/ */
public Comparable getData(int index)
private Comparable getData(final int index)
{ {
return _data[ index ]; return _data[ index ];
} }
@ -1961,8 +1892,7 @@ public final class BinaryTree // final for performance
* @param node the new left node * @param node the new left node
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void setLeft(Node node, int index)
private void setLeft(final Node node, final int index)
{ {
_left[ index ] = node; _left[ index ] = node;
} }
@ -1975,7 +1905,7 @@ public final class BinaryTree // final for performance
* @return the left node -- may be null * @return the left node -- may be null
*/ */
private Node getLeft(final int index) public Node getLeft(int index)
{ {
return _left[ index ]; return _left[ index ];
} }
@ -1986,8 +1916,7 @@ public final class BinaryTree // final for performance
* @param node the new right node * @param node the new right node
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void setRight(Node node, int index)
private void setRight(final Node node, final int index)
{ {
_right[ index ] = node; _right[ index ] = node;
} }
@ -2000,7 +1929,7 @@ public final class BinaryTree // final for performance
* @return the right node -- may be null * @return the right node -- may be null
*/ */
private Node getRight(final int index) public Node getRight(int index)
{ {
return _right[ index ]; return _right[ index ];
} }
@ -2011,8 +1940,7 @@ public final class BinaryTree // final for performance
* @param node the new parent node * @param node the new parent node
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void setParent(Node node, int index)
private void setParent(final Node node, final int index)
{ {
_parent[ index ] = node; _parent[ index ] = node;
} }
@ -2024,8 +1952,7 @@ public final class BinaryTree // final for performance
* *
* @return the parent node -- may be null * @return the parent node -- may be null
*/ */
public Node getParent(int index)
private Node getParent(final int index)
{ {
return _parent[ index ]; return _parent[ index ];
} }
@ -2036,8 +1963,7 @@ public final class BinaryTree // final for performance
* @param node the node to swap with * @param node the node to swap with
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void swapColors(Node node, int index)
private void swapColors(final Node node, final int index)
{ {
// Swap colors -- old hacker's trick // Swap colors -- old hacker's trick
@ -2053,8 +1979,7 @@ public final class BinaryTree // final for performance
* *
* @return true if black (which is represented as a true boolean) * @return true if black (which is represented as a true boolean)
*/ */
public boolean isBlack(int index)
private boolean isBlack(final int index)
{ {
return _black[ index ]; return _black[ index ];
} }
@ -2066,8 +1991,7 @@ public final class BinaryTree // final for performance
* *
* @return true if non-black * @return true if non-black
*/ */
public boolean isRed(int index)
private boolean isRed(final int index)
{ {
return !_black[ index ]; return !_black[ index ];
} }
@ -2077,8 +2001,7 @@ public final class BinaryTree // final for performance
* *
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void setBlack(int index)
private void setBlack(final int index)
{ {
_black[ index ] = true; _black[ index ] = true;
} }
@ -2088,8 +2011,7 @@ public final class BinaryTree // final for performance
* *
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void setRed(int index)
private void setRed(final int index)
{ {
_black[ index ] = false; _black[ index ] = false;
} }
@ -2100,8 +2022,7 @@ public final class BinaryTree // final for performance
* @param node the node whose color we're adopting * @param node the node whose color we're adopting
* @param index _KEY or _VALUE * @param index _KEY or _VALUE
*/ */
public void copyColor(Node node, int index)
private void copyColor(final Node node, final int index)
{ {
_black[ index ] = node._black[ index ]; _black[ index ] = node._black[ index ];
} }
@ -2111,7 +2032,6 @@ public final class BinaryTree // final for performance
/** /**
* @return the key corresponding to this entry. * @return the key corresponding to this entry.
*/ */
public Object getKey() public Object getKey()
{ {
return _data[ _KEY ]; return _data[ _KEY ];
@ -2120,7 +2040,6 @@ public final class BinaryTree // final for performance
/** /**
* @return the value corresponding to this entry. * @return the value corresponding to this entry.
*/ */
public Object getValue() public Object getValue()
{ {
return _data[ _VALUE ]; return _data[ _VALUE ];
@ -2133,10 +2052,7 @@ public final class BinaryTree // final for performance
* @param ignored * @param ignored
* *
* @return does not return * @return does not return
*
* @exception UnsupportedOperationException
*/ */
public Object setValue(Object ignored) public Object setValue(Object ignored)
throws UnsupportedOperationException throws UnsupportedOperationException
{ {
@ -2154,7 +2070,6 @@ public final class BinaryTree // final for performance
* @return true if the specified object is equal to this map * @return true if the specified object is equal to this map
* entry. * entry.
*/ */
public boolean equals(Object o) public boolean equals(Object o)
{ {
if (this == o) if (this == o)
@ -2188,5 +2103,4 @@ public final class BinaryTree // final for performance
/* ********** END implementation of Map.Entry ********** */ /* ********** END implementation of Map.Entry ********** */
} }
} // end public class BinaryTree }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.util; package org.apache.poi.util;
@ -31,34 +29,32 @@ import java.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
* @author Nicola Ken Barozzi (nicolaken at apache.org) * @author Nicola Ken Barozzi (nicolaken at apache.org)
*/ */
public abstract class POILogger {
public abstract class POILogger public static int DEBUG = 1;
{ public static int INFO = 3;
public static int WARN = 5;
public static final int DEBUG = 1; public static int ERROR = 7;
public static final int INFO = 3; public static int FATAL = 9;
public static final int WARN = 5;
public static final int ERROR = 7;
public static final int FATAL = 9;
/** /**
* package scope so it cannot be instantiated outside of the util * package scope so it cannot be instantiated outside of the util
* package. You need a POILogger? Go to the POILogFactory for one * package. You need a POILogger? Go to the POILogFactory for one
*
*/ */
POILogger() POILogger() {
{} // no fields to initialise
}
abstract public void initialize(final String cat);
abstract public void initialize(String cat);
/** /**
* Log a message * Log a message
* *
* @param level One of DEBUG, INFO, WARN, ERROR, FATAL * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
* @param obj1 The object to log. This is converted to a string. * @param obj1 The object to log. This is converted to a string.
*/ */
abstract public void log(final int level, final Object obj1); abstract public void log(int level, Object obj1);
/** /**
* Log a message * Log a message
* *
@ -66,7 +62,7 @@ public abstract class POILogger
* @param obj1 The object to log. This is converted to a string. * @param obj1 The object to log. This is converted to a string.
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
abstract public void log(final int level, final Object obj1, abstract public void log(int level, Object obj1,
final Throwable exception); final Throwable exception);
@ -75,15 +71,7 @@ public abstract class POILogger
* *
* @param level One of DEBUG, INFO, WARN, ERROR, FATAL * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
*/ */
abstract public boolean check(final int level); abstract public boolean check(int level);
/**
* Log a message. Lazily appends Object parameters together.
*
* @param level One of DEBUG, INFO, WARN, ERROR, FATAL
* @param obj1 first object to place in the message
* @param obj2 second object to place in the message
*/
/** /**
* Log a message. Lazily appends Object parameters together. * Log a message. Lazily appends Object parameters together.
@ -92,8 +80,7 @@ public abstract class POILogger
* @param obj1 first object to place in the message * @param obj1 first object to place in the message
* @param obj2 second object to place in the message * @param obj2 second object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2)
public void log(final int level, final Object obj1, final Object obj2)
{ {
if (check(level)) if (check(level))
{ {
@ -109,11 +96,10 @@ public abstract class POILogger
* @param obj2 second Object to place in the message * @param obj2 second Object to place in the message
* @param obj3 third Object to place in the message * @param obj3 third Object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3)
final Object obj3)
{ {
if (check(level)) if (check(level))
{ {
@ -132,11 +118,10 @@ public abstract class POILogger
* @param obj3 third Object to place in the message * @param obj3 third Object to place in the message
* @param obj4 fourth Object to place in the message * @param obj4 fourth Object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4)
final Object obj3, final Object obj4)
{ {
if (check(level)) if (check(level))
{ {
@ -156,11 +141,10 @@ public abstract class POILogger
* @param obj4 fourth Object to place in the message * @param obj4 fourth Object to place in the message
* @param obj5 fifth Object to place in the message * @param obj5 fifth Object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5)
final Object obj3, final Object obj4, final Object obj5)
{ {
if (check(level)) if (check(level))
{ {
@ -181,12 +165,11 @@ public abstract class POILogger
* @param obj5 fifth Object to place in the message * @param obj5 fifth Object to place in the message
* @param obj6 sixth Object to place in the message * @param obj6 sixth Object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5, Object obj6)
final Object obj6)
{ {
if (check(level)) if (check(level))
{ {
@ -208,12 +191,11 @@ public abstract class POILogger
* @param obj6 sixth Object to place in the message * @param obj6 sixth Object to place in the message
* @param obj7 seventh Object to place in the message * @param obj7 seventh Object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5, Object obj6, Object obj7)
final Object obj6, final Object obj7)
{ {
if (check(level)) if (check(level))
{ {
@ -237,12 +219,11 @@ public abstract class POILogger
* @param obj7 seventh Object to place in the message * @param obj7 seventh Object to place in the message
* @param obj8 eighth Object to place in the message * @param obj8 eighth Object to place in the message
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5, Object obj6, Object obj7, Object obj8)
final Object obj6, final Object obj7, final Object obj8)
{ {
if (check(level)) if (check(level))
{ {
@ -259,8 +240,7 @@ public abstract class POILogger
* @param level One of DEBUG, INFO, WARN, ERROR, FATAL * @param level One of DEBUG, INFO, WARN, ERROR, FATAL
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, final Throwable exception)
public void log(final int level, final Throwable exception)
{ {
log(level, null, exception); log(level, null, exception);
} }
@ -273,11 +253,10 @@ public abstract class POILogger
* @param obj2 second Object to place in the message * @param obj2 second Object to place in the message
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2,
final Throwable exception) final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -295,11 +274,10 @@ public abstract class POILogger
* @param obj3 third object to place in the message * @param obj3 third object to place in the message
* @param exception An error message to be logged * @param exception An error message to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, final Throwable exception)
final Object obj3, final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -318,12 +296,11 @@ public abstract class POILogger
* @param obj4 fourth object to place in the message * @param obj4 fourth object to place in the message
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4,
final Object obj3, final Object obj4,
final Throwable exception) final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -343,12 +320,11 @@ public abstract class POILogger
* @param obj5 fifth object to place in the message * @param obj5 fifth object to place in the message
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5,
final Throwable exception) final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -369,12 +345,11 @@ public abstract class POILogger
* @param obj6 sixth object to place in the message * @param obj6 sixth object to place in the message
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5, Object obj6, final Throwable exception)
final Object obj6, final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -397,13 +372,12 @@ public abstract class POILogger
* @param obj7 seventh object to place in the message * @param obj7 seventh object to place in the message
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5, Object obj6, Object obj7,
final Object obj6, final Object obj7,
final Throwable exception) final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -427,13 +401,12 @@ public abstract class POILogger
* @param obj8 eighth object to place in the message * @param obj8 eighth object to place in the message
* @param exception An exception to be logged * @param exception An exception to be logged
*/ */
public void log(int level, Object obj1, Object obj2,
public void log(final int level, final Object obj1, final Object obj2, Object obj3, Object obj4, Object obj5,
final Object obj3, final Object obj4, final Object obj5, Object obj6, Object obj7, Object obj8,
final Object obj6, final Object obj7, final Object obj8,
final Throwable exception) final Throwable exception)
{ {
if (check(level)) if (check(level))
{ {
@ -467,9 +440,8 @@ public abstract class POILogger
* @param message The message to log. * @param message The message to log.
* @param obj1 The first object to match against. * @param obj1 The first object to match against.
*/ */
public void logFormatted(int level, String message,
public void logFormatted(final int level, final String message, Object obj1)
final Object obj1)
{ {
commonLogFormatted(level, message, new Object[] commonLogFormatted(level, message, new Object[]
{ {
@ -502,9 +474,8 @@ public abstract class POILogger
* @param obj1 The first object to match against. * @param obj1 The first object to match against.
* @param obj2 The second object to match against. * @param obj2 The second object to match against.
*/ */
public void logFormatted(int level, String message,
public void logFormatted(final int level, final String message, Object obj1, Object obj2)
final Object obj1, final Object obj2)
{ {
commonLogFormatted(level, message, new Object[] commonLogFormatted(level, message, new Object[]
{ {
@ -538,10 +509,9 @@ public abstract class POILogger
* @param obj2 The second object to match against. * @param obj2 The second object to match against.
* @param obj3 The third object to match against. * @param obj3 The third object to match against.
*/ */
public void logFormatted(int level, String message,
public void logFormatted(final int level, final String message, Object obj1, Object obj2,
final Object obj1, final Object obj2, Object obj3)
final Object obj3)
{ {
commonLogFormatted(level, message, new Object[] commonLogFormatted(level, message, new Object[]
{ {
@ -576,21 +546,20 @@ public abstract class POILogger
* @param obj3 The third object to match against. * @param obj3 The third object to match against.
* @param obj4 The forth object to match against. * @param obj4 The forth object to match against.
*/ */
public void logFormatted(int level, String message,
public void logFormatted(final int level, final String message, Object obj1, Object obj2,
final Object obj1, final Object obj2, Object obj3, Object obj4)
final Object obj3, final Object obj4)
{ {
commonLogFormatted(level, message, new Object[] commonLogFormatted(level, message, new Object[]
{ {
obj1, obj2, obj3, obj4 obj1, obj2, obj3, obj4
}); });
} }
private void commonLogFormatted(final int level, final String message, private void commonLogFormatted(int level, String message,
final Object [] unflatParams) Object [] unflatParams)
{ {
if (check(level)) if (check(level))
{ {
@ -611,21 +580,20 @@ public abstract class POILogger
/** /**
* Flattens any contained objects. Only tranverses one level deep. * Flattens any contained objects. Only tranverses one level deep.
*/ */
private Object [] flattenArrays(Object [] objects)
private Object [] flattenArrays(final Object [] objects)
{ {
List results = new ArrayList(); List<Object> results = new ArrayList<Object>();
for (int i = 0; i < objects.length; i++) for (int i = 0; i < objects.length; i++)
{ {
results.addAll(objectToObjectArray(objects[ i ])); results.addAll(objectToObjectArray(objects[ i ]));
} }
return ( Object [] ) results.toArray(new Object[ results.size() ]); return results.toArray(new Object[ results.size() ]);
} }
private List objectToObjectArray(Object object) private List<Object> objectToObjectArray(Object object)
{ {
List results = new ArrayList(); List<Object> results = new ArrayList<Object>();
if (object instanceof byte []) if (object instanceof byte [])
{ {
@ -705,6 +673,4 @@ public abstract class POILogger
} }
return results; return results;
} }
}
} // end package scope abstract class POILogger

View File

@ -52,7 +52,7 @@ import org.apache.poi.util.POILogFactory;
/** /**
* Represents a container that can store multiple data objects. * Represents a container that can store multiple data objects.
* *
* @author Julien Chable, CDubet * @author Julien Chable, CDubet
* @version 0.1 * @version 0.1
*/ */
@ -125,7 +125,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Constructor. * Constructor.
* *
* @param access * @param access
* Package access. * Package access.
*/ */
@ -166,7 +166,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Open a package with read/write permission. * Open a package with read/write permission.
* *
* @param path * @param path
* The document path. * The document path.
* @return A Package object, else <b>null</b>. * @return A Package object, else <b>null</b>.
@ -180,7 +180,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Open a package. * Open a package.
* *
* @param path * @param path
* The document path. * The document path.
* @param access * @param access
@ -206,11 +206,11 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Open a package. * Open a package.
* *
* Note - uses quite a bit more memory than {@link #open(String)}, which * Note - uses quite a bit more memory than {@link #open(String)}, which
* doesn't need to hold the whole zip file in memory, and can take advantage * doesn't need to hold the whole zip file in memory, and can take advantage
* of native methods * of native methods
* *
* @param in * @param in
* The InputStream to read the package from * The InputStream to read the package from
* @return A PackageBase object * @return A PackageBase object
@ -226,7 +226,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Opens a package if it exists, else it creates one. * Opens a package if it exists, else it creates one.
* *
* @param file * @param file
* The file to open or to create. * The file to open or to create.
* @return A newly created package if the specified file does not exist, * @return A newly created package if the specified file does not exist,
@ -246,7 +246,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Creates a new package. * Creates a new package.
* *
* @param path * @param path
* Path of the document. * Path of the document.
* @return A newly created PackageBase ready to use. * @return A newly created PackageBase ready to use.
@ -257,7 +257,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Creates a new package. * Creates a new package.
* *
* @param file * @param file
* Path of the document. * Path of the document.
* @return A newly created PackageBase ready to use. * @return A newly created PackageBase ready to use.
@ -292,7 +292,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Configure the package. * Configure the package.
* *
* @param pkg * @param pkg
*/ */
private static void configurePackage(OPCPackage pkg) { private static void configurePackage(OPCPackage pkg) {
@ -324,7 +324,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Flush the package : save all. * Flush the package : save all.
* *
* @see #close() * @see #close()
*/ */
public void flush() { public void flush() {
@ -339,7 +339,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Close the package and save its content. * Close the package and save its content.
* *
* @throws IOException * @throws IOException
* If an IO exception occur during the saving process. * If an IO exception occur during the saving process.
*/ */
@ -391,7 +391,7 @@ public abstract class OPCPackage implements RelationshipSource {
* Add a thumbnail to the package. This method is provided to make easier * Add a thumbnail to the package. This method is provided to make easier
* the addition of a thumbnail in a package. You can do the same work by * the addition of a thumbnail in a package. You can do the same work by
* using the traditionnal relationship and part mechanism. * using the traditionnal relationship and part mechanism.
* *
* @param path * @param path
* The full path to the image file. * The full path to the image file.
*/ */
@ -443,7 +443,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Throws an exception if the package access mode is in read only mode * Throws an exception if the package access mode is in read only mode
* (PackageAccess.Read). * (PackageAccess.Read).
* *
* @throws InvalidOperationException * @throws InvalidOperationException
* Throws if a writing operation is done on a read only package. * Throws if a writing operation is done on a read only package.
* @see org.apache.poi.openxml4j.opc.PackageAccess * @see org.apache.poi.openxml4j.opc.PackageAccess
@ -458,7 +458,7 @@ public abstract class OPCPackage implements RelationshipSource {
* Throws an exception if the package access mode is in write only mode * Throws an exception if the package access mode is in write only mode
* (PackageAccess.Write). This method is call when other methods need write * (PackageAccess.Write). This method is call when other methods need write
* right. * right.
* *
* @throws InvalidOperationException * @throws InvalidOperationException
* Throws if a read operation is done on a write only package. * Throws if a read operation is done on a write only package.
* @see org.apache.poi.openxml4j.opc.PackageAccess * @see org.apache.poi.openxml4j.opc.PackageAccess
@ -471,7 +471,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieves or creates if none exists, core package property part. * Retrieves or creates if none exists, core package property part.
* *
* @return The PackageProperties part of this package. * @return The PackageProperties part of this package.
*/ */
public PackageProperties getPackageProperties() public PackageProperties getPackageProperties()
@ -487,7 +487,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieve a part identified by its name. * Retrieve a part identified by its name.
* *
* @param partName * @param partName
* Part name of the part to retrieve. * Part name of the part to retrieve.
* @return The part with the specified name, else <code>null</code>. * @return The part with the specified name, else <code>null</code>.
@ -511,7 +511,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieve parts by content type. * Retrieve parts by content type.
* *
* @param contentType * @param contentType
* The content type criteria. * The content type criteria.
* @return All part associated to the specified content type. * @return All part associated to the specified content type.
@ -527,7 +527,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieve parts by relationship type. * Retrieve parts by relationship type.
* *
* @param relationshipType * @param relationshipType
* Relationship type. * Relationship type.
* @return All parts which are the target of a relationship with the * @return All parts which are the target of a relationship with the
@ -547,7 +547,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Get the target part from the specified relationship. * Get the target part from the specified relationship.
* *
* @param partRel * @param partRel
* The part relationship uses to retrieve the part. * The part relationship uses to retrieve the part.
*/ */
@ -571,7 +571,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Load the parts of the archive if it has not been done yet The * Load the parts of the archive if it has not been done yet The
* relationships of each part are not loaded * relationships of each part are not loaded
* *
* @return All this package's parts. * @return All this package's parts.
*/ */
public ArrayList<PackagePart> getParts() throws InvalidFormatException { public ArrayList<PackagePart> getParts() throws InvalidFormatException {
@ -588,10 +588,10 @@ public abstract class OPCPackage implements RelationshipSource {
PackagePart[] parts = this.getPartsImpl(); PackagePart[] parts = this.getPartsImpl();
this.partList = new PackagePartCollection(); this.partList = new PackagePartCollection();
for (PackagePart part : parts) { for (PackagePart part : parts) {
if (partList.containsKey(part.partName)) if (partList.containsKey(part._partName))
throw new InvalidFormatException( throw new InvalidFormatException(
"A part with the name '" "A part with the name '"
+ part.partName + part._partName
+ "' already exist : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); + "' already exist : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
// Check OPC compliance rule M4.1 // Check OPC compliance rule M4.1
@ -605,29 +605,29 @@ public abstract class OPCPackage implements RelationshipSource {
} }
PartUnmarshaller partUnmarshaller = partUnmarshallers PartUnmarshaller partUnmarshaller = partUnmarshallers
.get(part.contentType); .get(part._contentType);
if (partUnmarshaller != null) { if (partUnmarshaller != null) {
UnmarshallContext context = new UnmarshallContext(this, UnmarshallContext context = new UnmarshallContext(this,
part.partName); part._partName);
try { try {
PackagePart unmarshallPart = partUnmarshaller PackagePart unmarshallPart = partUnmarshaller
.unmarshall(context, part.getInputStream()); .unmarshall(context, part.getInputStream());
partList.put(unmarshallPart.partName, unmarshallPart); partList.put(unmarshallPart._partName, unmarshallPart);
// Core properties case // Core properties case
if (unmarshallPart instanceof PackagePropertiesPart) if (unmarshallPart instanceof PackagePropertiesPart)
this.packageProperties = (PackagePropertiesPart) unmarshallPart; this.packageProperties = (PackagePropertiesPart) unmarshallPart;
} catch (IOException ioe) { } catch (IOException ioe) {
logger.log(POILogger.WARN, "Unmarshall operation : IOException for " logger.log(POILogger.WARN, "Unmarshall operation : IOException for "
+ part.partName); + part._partName);
continue; continue;
} catch (InvalidOperationException invoe) { } catch (InvalidOperationException invoe) {
throw new InvalidFormatException(invoe.getMessage()); throw new InvalidFormatException(invoe.getMessage());
} }
} else { } else {
try { try {
partList.put(part.partName, part); partList.put(part._partName, part);
} catch (InvalidOperationException e) { } catch (InvalidOperationException e) {
throw new InvalidFormatException(e.getMessage()); throw new InvalidFormatException(e.getMessage());
} }
@ -640,7 +640,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Create and add a part, with the specified name and content type, to the * Create and add a part, with the specified name and content type, to the
* package. * package.
* *
* @param partName * @param partName
* Part name. * Part name.
* @param contentType * @param contentType
@ -650,7 +650,7 @@ public abstract class OPCPackage implements RelationshipSource {
* If rule M1.12 is not verified : Packages shall not contain * If rule M1.12 is not verified : Packages shall not contain
* equivalent part names and package implementers shall neither * equivalent part names and package implementers shall neither
* create nor recognize packages with equivalent part names. * create nor recognize packages with equivalent part names.
* @see #createPartImpl(PackagePartName, String, boolean) * @see #createPartImpl(PackagePartName, String, boolean)
*/ */
public PackagePart createPart(PackagePartName partName, String contentType) { public PackagePart createPart(PackagePartName partName, String contentType) {
return this.createPart(partName, contentType, true); return this.createPart(partName, contentType, true);
@ -660,7 +660,7 @@ public abstract class OPCPackage implements RelationshipSource {
* Create and add a part, with the specified name and content type, to the * Create and add a part, with the specified name and content type, to the
* package. For general purpose, prefer the overload version of this method * package. For general purpose, prefer the overload version of this method
* without the 'loadRelationships' parameter. * without the 'loadRelationships' parameter.
* *
* @param partName * @param partName
* Part name. * Part name.
* @param contentType * @param contentType
@ -721,7 +721,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Add a part to the package. * Add a part to the package.
* *
* @param partName * @param partName
* Part name of the part to create. * Part name of the part to create.
* @param contentType * @param contentType
@ -730,7 +730,7 @@ public abstract class OPCPackage implements RelationshipSource {
* the contents to add. In order to have faster operation in * the contents to add. In order to have faster operation in
* document merge, the data are stored in memory not on a hard * document merge, the data are stored in memory not on a hard
* disk * disk
* *
* @return The new part. * @return The new part.
* @see #createPart(PackagePartName, String) * @see #createPart(PackagePartName, String)
*/ */
@ -764,7 +764,7 @@ public abstract class OPCPackage implements RelationshipSource {
* Add the specified part to the package. If a part already exists in the * Add the specified part to the package. If a part already exists in the
* package with the same name as the one specified, then we replace the old * package with the same name as the one specified, then we replace the old
* part by the specified part. * part by the specified part.
* *
* @param part * @param part
* The part to add (or replace). * The part to add (or replace).
* @return The part added to the package, the same as the one specified. * @return The part added to the package, the same as the one specified.
@ -779,20 +779,20 @@ public abstract class OPCPackage implements RelationshipSource {
throw new IllegalArgumentException("part"); throw new IllegalArgumentException("part");
} }
if (partList.containsKey(part.partName)) { if (partList.containsKey(part._partName)) {
if (!partList.get(part.partName).isDeleted()) { if (!partList.get(part._partName).isDeleted()) {
throw new InvalidOperationException( throw new InvalidOperationException(
"A part with the name '" "A part with the name '"
+ part.partName.getName() + part._partName.getName()
+ "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]"); + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
} }
// If the specified partis flagged as deleted, we make it // If the specified partis flagged as deleted, we make it
// available // available
part.setDeleted(false); part.setDeleted(false);
// and delete the old part to replace it thereafeter // and delete the old part to replace it thereafeter
this.partList.remove(part.partName); this.partList.remove(part._partName);
} }
this.partList.put(part.partName, part); this.partList.put(part._partName, part);
this.isDirty = true; this.isDirty = true;
return part; return part;
} }
@ -800,7 +800,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Remove the specified part in this package. If this part is relationship * Remove the specified part in this package. If this part is relationship
* part, then delete all relationships in the source part. * part, then delete all relationships in the source part.
* *
* @param part * @param part
* The part to remove. If <code>null</code>, skip the action. * The part to remove. If <code>null</code>, skip the action.
* @see #removePart(PackagePartName) * @see #removePart(PackagePartName)
@ -814,7 +814,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Remove a part in this package. If this part is relationship part, then * Remove a part in this package. If this part is relationship part, then
* delete all relationships in the source part. * delete all relationships in the source part.
* *
* @param partName * @param partName
* The part name of the part to remove. * The part name of the part to remove.
*/ */
@ -867,7 +867,7 @@ public abstract class OPCPackage implements RelationshipSource {
* Remove a part from this package as well as its relationship part, if one * Remove a part from this package as well as its relationship part, if one
* exists, and all parts listed in the relationship part. Be aware that this * exists, and all parts listed in the relationship part. Be aware that this
* do not delete relationships which target the specified part. * do not delete relationships which target the specified part.
* *
* @param partName * @param partName
* The name of the part to delete. * The name of the part to delete.
* @throws InvalidFormatException * @throws InvalidFormatException
@ -893,11 +893,11 @@ public abstract class OPCPackage implements RelationshipSource {
} }
// Finally delete its relationship part if one exists // Finally delete its relationship part if one exists
this.removePart(relPart.partName); this.removePart(relPart._partName);
} }
// Delete the specified part // Delete the specified part
this.removePart(partToRemove.partName); this.removePart(partToRemove._partName);
} }
/** /**
@ -905,7 +905,7 @@ public abstract class OPCPackage implements RelationshipSource {
* part if one exists. Prefer the use of this method to delete a part in the * part if one exists. Prefer the use of this method to delete a part in the
* package, compare to the remove() methods that don't remove associated * package, compare to the remove() methods that don't remove associated
* relationships part. * relationships part.
* *
* @param partName * @param partName
* Name of the part to delete * Name of the part to delete
*/ */
@ -925,7 +925,7 @@ public abstract class OPCPackage implements RelationshipSource {
* apply to all parts in the relationships part of the specified part. * apply to all parts in the relationships part of the specified part.
* Prefer the use of this method to delete a part in the package, compare to * Prefer the use of this method to delete a part in the package, compare to
* the remove() methods that don't remove associated relationships part. * the remove() methods that don't remove associated relationships part.
* *
* @param partName * @param partName
* Name of the part to delete * Name of the part to delete
*/ */
@ -961,7 +961,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Check if a part already exists in this package from its name. * Check if a part already exists in this package from its name.
* *
* @param partName * @param partName
* Part name to check. * Part name to check.
* @return <i>true</i> if the part is logically added to this package, else * @return <i>true</i> if the part is logically added to this package, else
@ -973,18 +973,18 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Add a relationship to the package (except relationships part). * Add a relationship to the package (except relationships part).
* *
* Check rule M4.1 : The format designer shall specify and the format * Check rule M4.1 : The format designer shall specify and the format
* producer shall create at most one core properties relationship for a * producer shall create at most one core properties relationship for a
* package. A format consumer shall consider more than one core properties * package. A format consumer shall consider more than one core properties
* relationship for a package to be an error. If present, the relationship * relationship for a package to be an error. If present, the relationship
* shall target the Core Properties part. * shall target the Core Properties part.
* *
* Check rule M1.25: The Relationships part shall not have relationships to * Check rule M1.25: The Relationships part shall not have relationships to
* any other part. Package implementers shall enforce this requirement upon * any other part. Package implementers shall enforce this requirement upon
* the attempt to create such a relationship and shall treat any such * the attempt to create such a relationship and shall treat any such
* relationship as invalid. * relationship as invalid.
* *
* @param targetPartName * @param targetPartName
* Target part name. * Target part name.
* @param targetMode * @param targetMode
@ -1032,7 +1032,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Add a package relationship. * Add a package relationship.
* *
* @param targetPartName * @param targetPartName
* Target part name. * Target part name.
* @param targetMode * @param targetMode
@ -1049,11 +1049,11 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Adds an external relationship to a part (except relationships part). * Adds an external relationship to a part (except relationships part).
* *
* The targets of external relationships are not subject to the same * The targets of external relationships are not subject to the same
* validity checks that internal ones are, as the contents is potentially * validity checks that internal ones are, as the contents is potentially
* any file, URL or similar. * any file, URL or similar.
* *
* @param target * @param target
* External target of the relationship * External target of the relationship
* @param relationshipType * @param relationshipType
@ -1069,11 +1069,11 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Adds an external relationship to a part (except relationships part). * Adds an external relationship to a part (except relationships part).
* *
* The targets of external relationships are not subject to the same * The targets of external relationships are not subject to the same
* validity checks that internal ones are, as the contents is potentially * validity checks that internal ones are, as the contents is potentially
* any file, URL or similar. * any file, URL or similar.
* *
* @param target * @param target
* External target of the relationship * External target of the relationship
* @param relationshipType * @param relationshipType
@ -1109,7 +1109,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Delete a relationship from this package. * Delete a relationship from this package.
* *
* @param id * @param id
* Id of the relationship to delete. * Id of the relationship to delete.
*/ */
@ -1122,7 +1122,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieves all package relationships. * Retrieves all package relationships.
* *
* @return All package relationships of this package. * @return All package relationships of this package.
* @throws OpenXML4JException * @throws OpenXML4JException
* @see #getRelationshipsHelper(String) * @see #getRelationshipsHelper(String)
@ -1133,7 +1133,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieves all relationships with the specified type. * Retrieves all relationships with the specified type.
* *
* @param relationshipType * @param relationshipType
* The filter specifying the relationship type. * The filter specifying the relationship type.
* @return All relationships with the specified relationship type. * @return All relationships with the specified relationship type.
@ -1150,7 +1150,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Retrieves all relationships with specified id (normally just ine because * Retrieves all relationships with specified id (normally just ine because
* a relationship id is supposed to be unique). * a relationship id is supposed to be unique).
* *
* @param id * @param id
* Id of the wanted relationship. * Id of the wanted relationship.
*/ */
@ -1214,7 +1214,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Add a marshaller. * Add a marshaller.
* *
* @param contentType * @param contentType
* The content type to bind to the specified marshaller. * The content type to bind to the specified marshaller.
* @param marshaller * @param marshaller
@ -1231,7 +1231,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Add an unmarshaller. * Add an unmarshaller.
* *
* @param contentType * @param contentType
* The content type to bind to the specified unmarshaller. * The content type to bind to the specified unmarshaller.
* @param unmarshaller * @param unmarshaller
@ -1250,7 +1250,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Remove a marshaller by its content type. * Remove a marshaller by its content type.
* *
* @param contentType * @param contentType
* The content type associated with the marshaller to remove. * The content type associated with the marshaller to remove.
*/ */
@ -1260,7 +1260,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Remove an unmarshaller by its content type. * Remove an unmarshaller by its content type.
* *
* @param contentType * @param contentType
* The content type associated with the unmarshaller to remove. * The content type associated with the unmarshaller to remove.
*/ */
@ -1272,7 +1272,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Get the package access mode. * Get the package access mode.
* *
* @return the packageAccess The current package access. * @return the packageAccess The current package access.
*/ */
public PackageAccess getPackageAccess() { public PackageAccess getPackageAccess() {
@ -1281,7 +1281,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Validates the package compliance with the OPC specifications. * Validates the package compliance with the OPC specifications.
* *
* @return <b>true</b> if the package is valid else <b>false</b> * @return <b>true</b> if the package is valid else <b>false</b>
*/ */
public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException { public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException {
@ -1290,7 +1290,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Save the document in the specified file. * Save the document in the specified file.
* *
* @param targetFile * @param targetFile
* Destination file. * Destination file.
* @throws IOException * @throws IOException
@ -1313,7 +1313,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Save the document in the specified output stream. * Save the document in the specified output stream.
* *
* @param outputStream * @param outputStream
* The stream to save the package. * The stream to save the package.
* @see #saveImpl(OutputStream) * @see #saveImpl(OutputStream)
@ -1326,7 +1326,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Core method to create a package part. This method must be implemented by * Core method to create a package part. This method must be implemented by
* the subclass. * the subclass.
* *
* @param partName * @param partName
* URI of the part to create. * URI of the part to create.
* @param contentType * @param contentType
@ -1339,7 +1339,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Core method to delete a package part. This method must be implemented by * Core method to delete a package part. This method must be implemented by
* the subclass. * the subclass.
* *
* @param partName * @param partName
* The URI of the part to delete. * The URI of the part to delete.
*/ */
@ -1352,7 +1352,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Close the package and cause a save of the package. * Close the package and cause a save of the package.
* *
*/ */
protected abstract void closeImpl() throws IOException; protected abstract void closeImpl() throws IOException;
@ -1364,7 +1364,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Save the package into the specified output stream. * Save the package into the specified output stream.
* *
* @param outputStream * @param outputStream
* The output stream use to save this package. * The output stream use to save this package.
*/ */
@ -1373,7 +1373,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Get the package part mapped to the specified URI. * Get the package part mapped to the specified URI.
* *
* @param partName * @param partName
* The URI of the part to retrieve. * The URI of the part to retrieve.
* @return The package part located by the specified URI, else <b>null</b>. * @return The package part located by the specified URI, else <b>null</b>.
@ -1382,7 +1382,7 @@ public abstract class OPCPackage implements RelationshipSource {
/** /**
* Get all parts link to the package. * Get all parts link to the package.
* *
* @return A list of the part owned by the package. * @return A list of the part owned by the package.
*/ */
protected abstract PackagePart[] getPartsImpl() protected abstract PackagePart[] getPartsImpl()

View File

@ -30,7 +30,7 @@ import org.apache.poi.openxml4j.opc.internal.ContentType;
/** /**
* Provides a base class for parts stored in a Package. * Provides a base class for parts stored in a Package.
* *
* @author Julien Chable * @author Julien Chable
* @version 0.9 * @version 0.9
*/ */
@ -39,36 +39,36 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* This part's container. * This part's container.
*/ */
protected OPCPackage container; protected OPCPackage _container;
/** /**
* The part name. (required by the specification [M1.1]) * The part name. (required by the specification [M1.1])
*/ */
protected PackagePartName partName; protected PackagePartName _partName;
/** /**
* The type of content of this part. (required by the specification [M1.2]) * The type of content of this part. (required by the specification [M1.2])
*/ */
protected ContentType contentType; protected ContentType _contentType;
/** /**
* Flag to know if this part is a relationship. * Flag to know if this part is a relationship.
*/ */
private boolean isRelationshipPart; private boolean _isRelationshipPart;
/** /**
* Flag to know if this part has been logically deleted. * Flag to know if this part has been logically deleted.
*/ */
private boolean isDeleted; private boolean _isDeleted;
/** /**
* This part's relationships. * This part's relationships.
*/ */
private PackageRelationshipCollection relationships; private PackageRelationshipCollection _relationships;
/** /**
* Constructor. * Constructor.
* *
* @param pack * @param pack
* Parent package. * Parent package.
* @param partName * @param partName
@ -85,7 +85,7 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Constructor. * Constructor.
* *
* @param pack * @param pack
* Parent package. * Parent package.
* @param partName * @param partName
@ -100,12 +100,12 @@ public abstract class PackagePart implements RelationshipSource {
protected PackagePart(OPCPackage pack, PackagePartName partName, protected PackagePart(OPCPackage pack, PackagePartName partName,
ContentType contentType, boolean loadRelationships) ContentType contentType, boolean loadRelationships)
throws InvalidFormatException { throws InvalidFormatException {
this.partName = partName; _partName = partName;
this.contentType = contentType; _contentType = contentType;
this.container = (ZipPackage) pack; // TODO - enforcing ZipPackage here - perhaps should change constructor signature _container = pack;
// Check if this part is a relationship part // Check if this part is a relationship part
isRelationshipPart = this.partName.isRelationshipPartURI(); _isRelationshipPart = this._partName.isRelationshipPartURI();
// Load relationships if any // Load relationships if any
if (loadRelationships) if (loadRelationships)
@ -114,7 +114,7 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Constructor. * Constructor.
* *
* @param pack * @param pack
* Parent package. * Parent package.
* @param partName * @param partName
@ -130,11 +130,11 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Adds an external relationship to a part (except relationships part). * Adds an external relationship to a part (except relationships part).
* *
* The targets of external relationships are not subject to the same * The targets of external relationships are not subject to the same
* validity checks that internal ones are, as the contents is potentially * validity checks that internal ones are, as the contents is potentially
* any file, URL or similar. * any file, URL or similar.
* *
* @param target * @param target
* External target of the relationship * External target of the relationship
* @param relationshipType * @param relationshipType
@ -150,11 +150,11 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Adds an external relationship to a part (except relationships part). * Adds an external relationship to a part (except relationships part).
* *
* The targets of external relationships are not subject to the same * The targets of external relationships are not subject to the same
* validity checks that internal ones are, as the contents is potentially * validity checks that internal ones are, as the contents is potentially
* any file, URL or similar. * any file, URL or similar.
* *
* @param target * @param target
* External target of the relationship * External target of the relationship
* @param relationshipType * @param relationshipType
@ -174,8 +174,8 @@ public abstract class PackagePart implements RelationshipSource {
throw new IllegalArgumentException("relationshipType"); throw new IllegalArgumentException("relationshipType");
} }
if (relationships == null) { if (_relationships == null) {
relationships = new PackageRelationshipCollection(); _relationships = new PackageRelationshipCollection();
} }
URI targetURI; URI targetURI;
@ -185,13 +185,13 @@ public abstract class PackagePart implements RelationshipSource {
throw new IllegalArgumentException("Invalid target - " + e); throw new IllegalArgumentException("Invalid target - " + e);
} }
return relationships.addRelationship(targetURI, TargetMode.EXTERNAL, return _relationships.addRelationship(targetURI, TargetMode.EXTERNAL,
relationshipType, id); relationshipType, id);
} }
/** /**
* Add a relationship to a part (except relationships part). * Add a relationship to a part (except relationships part).
* *
* @param targetPartName * @param targetPartName
* Name of the target part. This one must be relative to the * Name of the target part. This one must be relative to the
* source root directory of the part. * source root directory of the part.
@ -227,7 +227,7 @@ public abstract class PackagePart implements RelationshipSource {
* @param id * @param id
* Relationship unique id. * Relationship unique id.
* @return The newly created and added relationship * @return The newly created and added relationship
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* If the URI point to a relationship part URI. * If the URI point to a relationship part URI.
* @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName, * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
@ -235,7 +235,7 @@ public abstract class PackagePart implements RelationshipSource {
*/ */
public PackageRelationship addRelationship(PackagePartName targetPartName, public PackageRelationship addRelationship(PackagePartName targetPartName,
TargetMode targetMode, String relationshipType, String id) { TargetMode targetMode, String relationshipType, String id) {
container.throwExceptionIfReadOnly(); _container.throwExceptionIfReadOnly();
if (targetPartName == null) { if (targetPartName == null) {
throw new IllegalArgumentException("targetPartName"); throw new IllegalArgumentException("targetPartName");
@ -247,22 +247,22 @@ public abstract class PackagePart implements RelationshipSource {
throw new IllegalArgumentException("relationshipType"); throw new IllegalArgumentException("relationshipType");
} }
if (this.isRelationshipPart || targetPartName.isRelationshipPartURI()) { if (this._isRelationshipPart || targetPartName.isRelationshipPartURI()) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Rule M1.25: The Relationships part shall not have relationships to any other part."); "Rule M1.25: The Relationships part shall not have relationships to any other part.");
} }
if (relationships == null) { if (_relationships == null) {
relationships = new PackageRelationshipCollection(); _relationships = new PackageRelationshipCollection();
} }
return relationships.addRelationship(targetPartName.getURI(), return _relationships.addRelationship(targetPartName.getURI(),
targetMode, relationshipType, id); targetMode, relationshipType, id);
} }
/** /**
* Add a relationship to a part (except relationships part). * Add a relationship to a part (except relationships part).
* *
* @param targetURI * @param targetURI
* URI the target part. Must be relative to the source root * URI the target part. Must be relative to the source root
* directory of the part. * directory of the part.
@ -297,7 +297,7 @@ public abstract class PackagePart implements RelationshipSource {
* @param id * @param id
* Relationship unique id. * Relationship unique id.
* @return The newly created and added relationship * @return The newly created and added relationship
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* If the URI point to a relationship part URI. * If the URI point to a relationship part URI.
* @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName, * @see org.apache.poi.openxml4j.opc.RelationshipSource#addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
@ -305,7 +305,7 @@ public abstract class PackagePart implements RelationshipSource {
*/ */
public PackageRelationship addRelationship(URI targetURI, public PackageRelationship addRelationship(URI targetURI,
TargetMode targetMode, String relationshipType, String id) { TargetMode targetMode, String relationshipType, String id) {
container.throwExceptionIfReadOnly(); _container.throwExceptionIfReadOnly();
if (targetURI == null) { if (targetURI == null) {
throw new IllegalArgumentException("targetPartName"); throw new IllegalArgumentException("targetPartName");
@ -319,17 +319,17 @@ public abstract class PackagePart implements RelationshipSource {
// Try to retrieve the target part // Try to retrieve the target part
if (this.isRelationshipPart if (this._isRelationshipPart
|| PackagingURIHelper.isRelationshipPartURI(targetURI)) { || PackagingURIHelper.isRelationshipPartURI(targetURI)) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Rule M1.25: The Relationships part shall not have relationships to any other part."); "Rule M1.25: The Relationships part shall not have relationships to any other part.");
} }
if (relationships == null) { if (_relationships == null) {
relationships = new PackageRelationshipCollection(); _relationships = new PackageRelationshipCollection();
} }
return relationships.addRelationship(targetURI, return _relationships.addRelationship(targetURI,
targetMode, relationshipType, id); targetMode, relationshipType, id);
} }
@ -337,27 +337,27 @@ public abstract class PackagePart implements RelationshipSource {
* @see org.apache.poi.openxml4j.opc.RelationshipSource#clearRelationships() * @see org.apache.poi.openxml4j.opc.RelationshipSource#clearRelationships()
*/ */
public void clearRelationships() { public void clearRelationships() {
if (relationships != null) { if (_relationships != null) {
relationships.clear(); _relationships.clear();
} }
} }
/** /**
* Delete the relationship specified by its id. * Delete the relationship specified by its id.
* *
* @param id * @param id
* The ID identified the part to delete. * The ID identified the part to delete.
* @see org.apache.poi.openxml4j.opc.RelationshipSource#removeRelationship(java.lang.String) * @see org.apache.poi.openxml4j.opc.RelationshipSource#removeRelationship(java.lang.String)
*/ */
public void removeRelationship(String id) { public void removeRelationship(String id) {
this.container.throwExceptionIfReadOnly(); this._container.throwExceptionIfReadOnly();
if (this.relationships != null) if (this._relationships != null)
this.relationships.removeRelationship(id); this._relationships.removeRelationship(id);
} }
/** /**
* Retrieve all the relationships attached to this part. * Retrieve all the relationships attached to this part.
* *
* @return This part's relationships. * @return This part's relationships.
* @throws OpenXML4JException * @throws OpenXML4JException
* @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationships() * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationships()
@ -369,20 +369,20 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Retrieves a package relationship from its id. * Retrieves a package relationship from its id.
* *
* @param id * @param id
* ID of the package relationship to retrieve. * ID of the package relationship to retrieve.
* @return The package relationship * @return The package relationship
* @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String) * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String)
*/ */
public PackageRelationship getRelationship(String id) { public PackageRelationship getRelationship(String id) {
return this.relationships.getRelationshipByID(id); return this._relationships.getRelationshipByID(id);
} }
/** /**
* Retrieve all relationships attached to this part which have the specified * Retrieve all relationships attached to this part which have the specified
* type. * type.
* *
* @param relationshipType * @param relationshipType
* Relationship type filter. * Relationship type filter.
* @return All relationships from this part that have the specified type. * @return All relationships from this part that have the specified type.
@ -394,14 +394,14 @@ public abstract class PackagePart implements RelationshipSource {
*/ */
public PackageRelationshipCollection getRelationshipsByType( public PackageRelationshipCollection getRelationshipsByType(
String relationshipType) throws InvalidFormatException { String relationshipType) throws InvalidFormatException {
container.throwExceptionIfWriteOnly(); _container.throwExceptionIfWriteOnly();
return getRelationshipsCore(relationshipType); return getRelationshipsCore(relationshipType);
} }
/** /**
* Implementation of the getRelationships method(). * Implementation of the getRelationships method().
* *
* @param filter * @param filter
* Relationship type filter. If <i>null</i> then the filter is * Relationship type filter. If <i>null</i> then the filter is
* disabled and return all the relationships. * disabled and return all the relationships.
@ -415,29 +415,29 @@ public abstract class PackagePart implements RelationshipSource {
*/ */
private PackageRelationshipCollection getRelationshipsCore(String filter) private PackageRelationshipCollection getRelationshipsCore(String filter)
throws InvalidFormatException { throws InvalidFormatException {
this.container.throwExceptionIfWriteOnly(); this._container.throwExceptionIfWriteOnly();
if (relationships == null) { if (_relationships == null) {
this.throwExceptionIfRelationship(); this.throwExceptionIfRelationship();
relationships = new PackageRelationshipCollection(this); _relationships = new PackageRelationshipCollection(this);
} }
return new PackageRelationshipCollection(relationships, filter); return new PackageRelationshipCollection(_relationships, filter);
} }
/** /**
* Knows if the part have any relationships. * Knows if the part have any relationships.
* *
* @return <b>true</b> if the part have at least one relationship else * @return <b>true</b> if the part have at least one relationship else
* <b>false</b>. * <b>false</b>.
* @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships() * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships()
*/ */
public boolean hasRelationships() { public boolean hasRelationships() {
return (!this.isRelationshipPart && (relationships != null && relationships return (!this._isRelationshipPart && (_relationships != null && _relationships
.size() > 0)); .size() > 0));
} }
/** /**
* Checks if the specified relationship is part of this package part. * Checks if the specified relationship is part of this package part.
* *
* @param rel * @param rel
* The relationship to check. * The relationship to check.
* @return <b>true</b> if the specified relationship exists in this part, * @return <b>true</b> if the specified relationship exists in this part,
@ -458,7 +458,7 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Get the input stream of this part to read its content. * Get the input stream of this part to read its content.
* *
* @return The input stream of the content of this part, else * @return The input stream of the content of this part, else
* <code>null</code>. * <code>null</code>.
*/ */
@ -466,9 +466,9 @@ public abstract class PackagePart implements RelationshipSource {
InputStream inStream = this.getInputStreamImpl(); InputStream inStream = this.getInputStreamImpl();
if (inStream == null) { if (inStream == null) {
throw new IOException("Can't obtain the input stream from " throw new IOException("Can't obtain the input stream from "
+ partName.getName()); + _partName.getName());
} else }
return inStream; return inStream;
} }
/** /**
@ -476,7 +476,7 @@ public abstract class PackagePart implements RelationshipSource {
* Zip package, it'll be transform intot a <i>MemoryPackagePart</i> in * Zip package, it'll be transform intot a <i>MemoryPackagePart</i> in
* order to write inside (the standard Java API doesn't allow to write in * order to write inside (the standard Java API doesn't allow to write in
* the file) * the file)
* *
* @see org.apache.poi.openxml4j.opc.internal.MemoryPackagePart * @see org.apache.poi.openxml4j.opc.internal.MemoryPackagePart
*/ */
public OutputStream getOutputStream() { public OutputStream getOutputStream() {
@ -485,12 +485,12 @@ public abstract class PackagePart implements RelationshipSource {
// this part into a MemoryPackagePart instance for write purpose. // this part into a MemoryPackagePart instance for write purpose.
if (this instanceof ZipPackagePart) { if (this instanceof ZipPackagePart) {
// Delete logically this part // Delete logically this part
this.container.removePart(this.partName); _container.removePart(this._partName);
// Create a memory part // Create a memory part
PackagePart part = container.createPart(this.partName, PackagePart part = _container.createPart(this._partName,
this.contentType.toString(), false); this._contentType.toString(), false);
part.relationships = this.relationships; part._relationships = this._relationships;
if (part == null) { if (part == null) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Can't create a temporary part !"); "Can't create a temporary part !");
@ -504,27 +504,27 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Throws an exception if this package part is a relationship part. * Throws an exception if this package part is a relationship part.
* *
* @throws InvalidOperationException * @throws InvalidOperationException
* If this part is a relationship part. * If this part is a relationship part.
*/ */
private void throwExceptionIfRelationship() private void throwExceptionIfRelationship()
throws InvalidOperationException { throws InvalidOperationException {
if (this.isRelationshipPart) if (this._isRelationshipPart)
throw new InvalidOperationException( throw new InvalidOperationException(
"Can do this operation on a relationship part !"); "Can do this operation on a relationship part !");
} }
/** /**
* Ensure the package relationships collection instance is built. * Ensure the package relationships collection instance is built.
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* Throws if * Throws if
*/ */
private void loadRelationships() throws InvalidFormatException { private void loadRelationships() throws InvalidFormatException {
if (this.relationships == null && !this.isRelationshipPart) { if (this._relationships == null && !this._isRelationshipPart) {
this.throwExceptionIfRelationship(); this.throwExceptionIfRelationship();
relationships = new PackageRelationshipCollection(this); _relationships = new PackageRelationshipCollection(this);
} }
} }
@ -536,22 +536,22 @@ public abstract class PackagePart implements RelationshipSource {
* @return the uri * @return the uri
*/ */
public PackagePartName getPartName() { public PackagePartName getPartName() {
return partName; return _partName;
} }
/** /**
* @return the contentType * @return the contentType
*/ */
public String getContentType() { public String getContentType() {
return contentType.toString(); return _contentType.toString();
} }
/** /**
* Set the content type. * Set the content type.
* *
* @param contentType * @param contentType
* the contentType to set * the contentType to set
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* Throws if the content type is not valid. * Throws if the content type is not valid.
* @throws InvalidOperationException * @throws InvalidOperationException
@ -560,29 +560,29 @@ public abstract class PackagePart implements RelationshipSource {
*/ */
public void setContentType(String contentType) public void setContentType(String contentType)
throws InvalidFormatException { throws InvalidFormatException {
if (container == null) if (_container == null)
this.contentType = new ContentType(contentType); this._contentType = new ContentType(contentType);
else else
throw new InvalidOperationException( throw new InvalidOperationException(
"You can't change the content type of a part."); "You can't change the content type of a part.");
} }
public OPCPackage getPackage() { public OPCPackage getPackage() {
return container; return _container;
} }
/** /**
* @return true if this part is a relationship * @return true if this part is a relationship
*/ */
public boolean isRelationshipPart() { public boolean isRelationshipPart() {
return this.isRelationshipPart; return this._isRelationshipPart;
} }
/** /**
* @return true if this part has been logically deleted * @return true if this part has been logically deleted
*/ */
public boolean isDeleted() { public boolean isDeleted() {
return isDeleted; return _isDeleted;
} }
/** /**
@ -590,20 +590,20 @@ public abstract class PackagePart implements RelationshipSource {
* the isDeleted to set * the isDeleted to set
*/ */
public void setDeleted(boolean isDeleted) { public void setDeleted(boolean isDeleted) {
this.isDeleted = isDeleted; this._isDeleted = isDeleted;
} }
@Override @Override
public String toString() { public String toString() {
return "Name: " + this.partName + " - Content Type: " return "Name: " + this._partName + " - Content Type: "
+ this.contentType.toString(); + this._contentType.toString();
} }
/*-------------- Abstract methods ------------- */ /*-------------- Abstract methods ------------- */
/** /**
* Abtract method that get the input stream of this part. * Abtract method that get the input stream of this part.
* *
* @exception IOException * @exception IOException
* Throws if an IO Exception occur in the implementation * Throws if an IO Exception occur in the implementation
* method. * method.
@ -619,7 +619,7 @@ public abstract class PackagePart implements RelationshipSource {
* Save the content of this part and the associated relationships part (if * Save the content of this part and the associated relationships part (if
* this part own at least one relationship) into the specified output * this part own at least one relationship) into the specified output
* stream. * stream.
* *
* @param zos * @param zos
* Output stream to save this part. * Output stream to save this part.
* @throws OpenXML4JException * @throws OpenXML4JException
@ -629,7 +629,7 @@ public abstract class PackagePart implements RelationshipSource {
/** /**
* Load the content of this part. * Load the content of this part.
* *
* @param ios * @param ios
* The input stream of the content to load. * The input stream of the content to load.
* @return <b>true</b> if the content has been successfully loaded, else * @return <b>true</b> if the content has been successfully loaded, else

View File

@ -22,7 +22,7 @@ import java.net.URISyntaxException;
/** /**
* A part relationship. * A part relationship.
* *
* @author Julien Chable * @author Julien Chable
* @version 1.0 * @version 1.0
*/ */
@ -86,7 +86,7 @@ public final class PackageRelationship {
/** /**
* Constructor. * Constructor.
* *
* @param pkg * @param pkg
* @param sourcePart * @param sourcePart
* @param targetUri * @param targetUri
@ -171,19 +171,19 @@ public final class PackageRelationship {
} }
/** /**
* *
* @return URL of the source part of this relationship * @return URL of the source part of this relationship
*/ */
public URI getSourceURI() { public URI getSourceURI() {
if (source == null) { if (source == null) {
return PackagingURIHelper.PACKAGE_ROOT_URI; return PackagingURIHelper.PACKAGE_ROOT_URI;
} }
return source.partName.getURI(); return source._partName.getURI();
} }
/** /**
* public URI getSourceUri(){ } * public URI getSourceUri(){ }
* *
* @return the targetMode * @return the targetMode
*/ */
public TargetMode getTargetMode() { public TargetMode getTargetMode() {
@ -199,7 +199,7 @@ public final class PackageRelationship {
if(targetMode == TargetMode.EXTERNAL) { if(targetMode == TargetMode.EXTERNAL) {
return targetUri; return targetUri;
} }
// Internal target // Internal target
// If it isn't absolute, resolve it relative // If it isn't absolute, resolve it relative
// to ourselves // to ourselves

View File

@ -34,7 +34,7 @@ import org.apache.poi.util.POILogFactory;
/** /**
* Represents a collection of PackageRelationship elements that are owned by a * Represents a collection of PackageRelationship elements that are owned by a
* given PackagePart or the Package. * given PackagePart or the Package.
* *
* @author Julien Chable, CDubettier * @author Julien Chable, CDubettier
* @version 0.1 * @version 0.1
*/ */
@ -83,11 +83,11 @@ public final class PackageRelationshipCollection implements
/** /**
* Copy constructor. * Copy constructor.
* *
* This collection will contain only elements from the specified collection * This collection will contain only elements from the specified collection
* for which the type is compatible with the specified relationship type * for which the type is compatible with the specified relationship type
* filter. * filter.
* *
* @param coll * @param coll
* Collection to import. * Collection to import.
* @param filter * @param filter
@ -112,21 +112,21 @@ public final class PackageRelationshipCollection implements
/** /**
* Constructor. * Constructor.
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* Throws if the format of the content part is invalid. * Throws if the format of the content part is invalid.
* *
* @throws InvalidOperationException * @throws InvalidOperationException
* Throws if the specified part is a relationship part. * Throws if the specified part is a relationship part.
*/ */
public PackageRelationshipCollection(PackagePart part) public PackageRelationshipCollection(PackagePart part)
throws InvalidFormatException { throws InvalidFormatException {
this(part.container, part); this(part._container, part);
} }
/** /**
* Constructor. Parse the existing package relationship part if one exists. * Constructor. Parse the existing package relationship part if one exists.
* *
* @param container * @param container
* The parent package. * The parent package.
* @param part * @param part
@ -159,7 +159,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Get the relationship part name of the specified part. * Get the relationship part name of the specified part.
* *
* @param part * @param part
* The part . * The part .
* @return The relationship part name of the specified part. Be careful, * @return The relationship part name of the specified part. Be careful,
@ -181,7 +181,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Add the specified relationship to the collection. * Add the specified relationship to the collection.
* *
* @param relPart * @param relPart
* The relationship to add. * The relationship to add.
*/ */
@ -192,7 +192,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Add a relationship to the collection. * Add a relationship to the collection.
* *
* @param targetUri * @param targetUri
* Target URI. * Target URI.
* @param targetMode * @param targetMode
@ -224,7 +224,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Remove a relationship by its ID. * Remove a relationship by its ID.
* *
* @param id * @param id
* The relationship ID to remove. * The relationship ID to remove.
*/ */
@ -240,7 +240,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Remove a relationship by its reference. * Remove a relationship by its reference.
* *
* @param rel * @param rel
* The relationship to delete. * The relationship to delete.
*/ */
@ -254,7 +254,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Retrieves a relationship by its index in the collection. * Retrieves a relationship by its index in the collection.
* *
* @param index * @param index
* Must be a value between [0-relationships_count-1] * Must be a value between [0-relationships_count-1]
*/ */
@ -273,7 +273,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Retrieves a package relationship based on its id. * Retrieves a package relationship based on its id.
* *
* @param id * @param id
* ID of the package relationship to retrieve. * ID of the package relationship to retrieve.
* @return The package relationship identified by the specified id. * @return The package relationship identified by the specified id.
@ -291,7 +291,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Parse the relationship part and add all relationship in this collection. * Parse the relationship part and add all relationship in this collection.
* *
* @param relPart * @param relPart
* The package part to parse. * The package part to parse.
* @throws InvalidFormatException * @throws InvalidFormatException
@ -376,7 +376,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Retrieves all relations with the specified type. * Retrieves all relations with the specified type.
* *
* @param typeFilter * @param typeFilter
* Relationship type filter. If <b>null</b> then all * Relationship type filter. If <b>null</b> then all
* relationships are returned. * relationships are returned.
@ -398,7 +398,7 @@ public final class PackageRelationshipCollection implements
/** /**
* Get an iterator of a collection with all relationship with the specified * Get an iterator of a collection with all relationship with the specified
* type. * type.
* *
* @param typeFilter * @param typeFilter
* Type filter. * Type filter.
* @return An iterator to a collection containing all relationships with the * @return An iterator to a collection containing all relationships with the
@ -429,15 +429,15 @@ public final class PackageRelationshipCollection implements
} else { } else {
str = relationshipsByID.size() + " relationship(s) = ["; str = relationshipsByID.size() + " relationship(s) = [";
} }
if ((relationshipPart != null) && (relationshipPart.partName != null)) { if ((relationshipPart != null) && (relationshipPart._partName != null)) {
str = str + "," + relationshipPart.partName; str = str + "," + relationshipPart._partName;
} else { } else {
str = str + ",relationshipPart=null"; str = str + ",relationshipPart=null";
} }
// Source of this relationship // Source of this relationship
if ((sourcePart != null) && (sourcePart.partName != null)) { if ((sourcePart != null) && (sourcePart._partName != null)) {
str = str + "," + sourcePart.partName; str = str + "," + sourcePart._partName;
} else { } else {
str = str + ",sourcePart=null"; str = str + ",sourcePart=null";
} }

View File

@ -24,7 +24,7 @@ public interface RelationshipSource {
/** /**
* Add a relationship to a part (except relationships part). * Add a relationship to a part (except relationships part).
* *
* @param targetPartName * @param targetPartName
* Name of the target part. This one must be relative to the * Name of the target part. This one must be relative to the
* source root directory of the part. * source root directory of the part.
@ -56,7 +56,7 @@ public interface RelationshipSource {
* @param id * @param id
* Relationship unique id. * Relationship unique id.
* @return The newly created and added relationship * @return The newly created and added relationship
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* If the URI point to a relationship part URI. * If the URI point to a relationship part URI.
*/ */
@ -67,28 +67,28 @@ public interface RelationshipSource {
/** /**
* Adds an external relationship to a part * Adds an external relationship to a part
* (except relationships part). * (except relationships part).
* *
* The targets of external relationships are not * The targets of external relationships are not
* subject to the same validity checks that internal * subject to the same validity checks that internal
* ones are, as the contents is potentially * ones are, as the contents is potentially
* any file, URL or similar. * any file, URL or similar.
* *
* @param target External target of the relationship * @param target External target of the relationship
* @param relationshipType Type of relationship. * @param relationshipType Type of relationship.
* @return The newly created and added relationship * @return The newly created and added relationship
* @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, java.lang.String) * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, java.lang.String)
*/ */
public PackageRelationship addExternalRelationship(String target, String relationshipType); public PackageRelationship addExternalRelationship(String target, String relationshipType);
/** /**
* Adds an external relationship to a part * Adds an external relationship to a part
* (except relationships part). * (except relationships part).
* *
* The targets of external relationships are not * The targets of external relationships are not
* subject to the same validity checks that internal * subject to the same validity checks that internal
* ones are, as the contents is potentially * ones are, as the contents is potentially
* any file, URL or similar. * any file, URL or similar.
* *
* @param target External target of the relationship * @param target External target of the relationship
* @param relationshipType Type of relationship. * @param relationshipType Type of relationship.
* @param id Relationship unique id. * @param id Relationship unique id.
@ -96,7 +96,7 @@ public interface RelationshipSource {
* @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, java.lang.String) * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, java.lang.String)
*/ */
public PackageRelationship addExternalRelationship(String target, String relationshipType, String id); public PackageRelationship addExternalRelationship(String target, String relationshipType, String id);
/** /**
* Delete all the relationships attached to this. * Delete all the relationships attached to this.
*/ */
@ -104,7 +104,7 @@ public interface RelationshipSource {
/** /**
* Delete the relationship specified by its id. * Delete the relationship specified by its id.
* *
* @param id * @param id
* The ID identified the part to delete. * The ID identified the part to delete.
*/ */
@ -112,7 +112,7 @@ public interface RelationshipSource {
/** /**
* Retrieve all the relationships attached to this. * Retrieve all the relationships attached to this.
* *
* @return This part's relationships. * @return This part's relationships.
* @throws OpenXML4JException * @throws OpenXML4JException
*/ */
@ -121,7 +121,7 @@ public interface RelationshipSource {
/** /**
* Retrieves a package relationship from its id. * Retrieves a package relationship from its id.
* *
* @param id * @param id
* ID of the package relationship to retrieve. * ID of the package relationship to retrieve.
* @return The package relationship * @return The package relationship
@ -131,7 +131,7 @@ public interface RelationshipSource {
/** /**
* Retrieve all relationships attached to this part which have the specified * Retrieve all relationships attached to this part which have the specified
* type. * type.
* *
* @param relationshipType * @param relationshipType
* Relationship type filter. * Relationship type filter.
* @return All relationships from this part that have the specified type. * @return All relationships from this part that have the specified type.
@ -141,12 +141,12 @@ public interface RelationshipSource {
* If the package is open in write only mode. * If the package is open in write only mode.
*/ */
public abstract PackageRelationshipCollection getRelationshipsByType( public abstract PackageRelationshipCollection getRelationshipsByType(
String relationshipType) throws InvalidFormatException, String relationshipType) throws InvalidFormatException,
IllegalArgumentException, OpenXML4JException; IllegalArgumentException, OpenXML4JException;
/** /**
* Knows if the part have any relationships. * Knows if the part have any relationships.
* *
* @return <b>true</b> if the part have at least one relationship else * @return <b>true</b> if the part have at least one relationship else
* <b>false</b>. * <b>false</b>.
*/ */
@ -154,13 +154,12 @@ public interface RelationshipSource {
/** /**
* Checks if the specified relationship is part of this package part. * Checks if the specified relationship is part of this package part.
* *
* @param rel * @param rel
* The relationship to check. * The relationship to check.
* @return <b>true</b> if the specified relationship exists in this part, * @return <b>true</b> if the specified relationship exists in this part,
* else returns <b>false</b> * else returns <b>false</b>
*/ */
@SuppressWarnings("finally")
public abstract boolean isRelationshipExists(PackageRelationship rel); public abstract boolean isRelationshipExists(PackageRelationship rel);
} }

View File

@ -423,7 +423,7 @@ public final class ZipPackage extends Package {
+ ZipHelper.getZipItemNameFromOPCName(part + ZipHelper.getZipItemNameFromOPCName(part
.getPartName().getName()) + "'"); .getPartName().getName()) + "'");
PartMarshaller marshaller = partMarshallers PartMarshaller marshaller = partMarshallers
.get(part.contentType); .get(part._contentType);
if (marshaller != null) { if (marshaller != null) {
if (!marshaller.marshall(part, zos)) { if (!marshaller.marshall(part, zos)) {
throw new OpenXML4JException( throw new OpenXML4JException(

View File

@ -29,7 +29,7 @@ import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
/** /**
* Zip implementation of a PackagePart. * Zip implementation of a PackagePart.
* *
* @author Julien Chable * @author Julien Chable
* @version 1.0 * @version 1.0
* @see PackagePart * @see PackagePart
@ -43,7 +43,7 @@ public class ZipPackagePart extends PackagePart {
/** /**
* Constructor. * Constructor.
* *
* @param container * @param container
* The container package. * The container package.
* @param partName * @param partName
@ -60,7 +60,7 @@ public class ZipPackagePart extends PackagePart {
/** /**
* Constructor. * Constructor.
* *
* @param container * @param container
* The container package. * The container package.
* @param zipEntry * @param zipEntry
@ -81,7 +81,7 @@ public class ZipPackagePart extends PackagePart {
/** /**
* Get the zip entry of this part. * Get the zip entry of this part.
* *
* @return The zip entry in the zip structure coresponding to this part. * @return The zip entry in the zip structure coresponding to this part.
*/ */
public ZipEntry getZipArchive() { public ZipEntry getZipArchive() {
@ -91,21 +91,21 @@ public class ZipPackagePart extends PackagePart {
/** /**
* Implementation of the getInputStream() which return the inputStream of * Implementation of the getInputStream() which return the inputStream of
* this part zip entry. * this part zip entry.
* *
* @return Input stream of this part zip entry. * @return Input stream of this part zip entry.
*/ */
@Override @Override
protected InputStream getInputStreamImpl() throws IOException { protected InputStream getInputStreamImpl() throws IOException {
// We use the getInputStream() method from java.util.zip.ZipFile // We use the getInputStream() method from java.util.zip.ZipFile
// class which return an InputStream to this part zip entry. // class which return an InputStream to this part zip entry.
return ((ZipPackage) container).getZipArchive() return ((ZipPackage) _container).getZipArchive()
.getInputStream(zipEntry); .getInputStream(zipEntry);
} }
/** /**
* Implementation of the getOutputStream(). Return <b>null</b>. Normally * Implementation of the getOutputStream(). Return <b>null</b>. Normally
* will never be called since the MemoryPackage is use instead. * will never be called since the MemoryPackage is use instead.
* *
* @return <b>null</b> * @return <b>null</b>
*/ */
@Override @Override
@ -119,7 +119,7 @@ public class ZipPackagePart extends PackagePart {
} }
@Override @Override
public boolean load(InputStream ios) throws InvalidFormatException { public boolean load(InputStream ios) {
throw new InvalidOperationException("Method not implemented !"); throw new InvalidOperationException("Method not implemented !");
} }

View File

@ -43,9 +43,8 @@ import org.dom4j.io.SAXReader;
/** /**
* Manage package content types ([Content_Types].xml part). * Manage package content types ([Content_Types].xml part).
* *
* @author Julien Chable * @author Julien Chable
* @version 1.0
*/ */
public abstract class ContentTypeManager { public abstract class ContentTypeManager {
@ -90,7 +89,7 @@ public abstract class ContentTypeManager {
/** /**
* Constructor. Parses the content of the specified input stream. * Constructor. Parses the content of the specified input stream.
* *
* @param in * @param in
* If different of <i>null</i> then the content types part is * If different of <i>null</i> then the content types part is
* retrieve and parse. * retrieve and parse.
@ -161,7 +160,7 @@ public abstract class ContentTypeManager {
/** /**
* Add an override content type for a specific part. * Add an override content type for a specific part.
* *
* @param partName * @param partName
* Name of the part. * Name of the part.
* @param contentType * @param contentType
@ -176,7 +175,7 @@ public abstract class ContentTypeManager {
/** /**
* Add a content type associated with the specified extension. * Add a content type associated with the specified extension.
* *
* @param extension * @param extension
* The part name extension to bind to a content type. * The part name extension to bind to a content type.
* @param contentType * @param contentType
@ -267,7 +266,7 @@ public abstract class ContentTypeManager {
/** /**
* Check if the specified content type is already register. * Check if the specified content type is already register.
* *
* @param contentType * @param contentType
* The content type to check. * The content type to check.
* @return <code>true</code> if the specified content type is already * @return <code>true</code> if the specified content type is already
@ -315,7 +314,7 @@ public abstract class ContentTypeManager {
* @return The content type associated with the URI (in case of an override * @return The content type associated with the URI (in case of an override
* content type) or the extension (in case of default content type), * content type) or the extension (in case of default content type),
* else <code>null</code>. * else <code>null</code>.
* *
* @exception OpenXML4JRuntimeException * @exception OpenXML4JRuntimeException
* Throws if the content type manager is not able to find the * Throws if the content type manager is not able to find the
* content from an existing part. * content from an existing part.
@ -342,9 +341,8 @@ public abstract class ContentTypeManager {
if (this.container != null && this.container.getPart(partName) != null) { if (this.container != null && this.container.getPart(partName) != null) {
throw new OpenXML4JRuntimeException( throw new OpenXML4JRuntimeException(
"Rule M2.4 exception : this error should NEVER happen, if so please send a mail to the developers team, thanks !"); "Rule M2.4 exception : this error should NEVER happen, if so please send a mail to the developers team, thanks !");
} else {
return null;
} }
return null;
} }
/** /**
@ -358,7 +356,7 @@ public abstract class ContentTypeManager {
/** /**
* Clear all override content types. * Clear all override content types.
* *
*/ */
public void clearOverrideContentTypes() { public void clearOverrideContentTypes() {
if (this.overrideContentType != null) if (this.overrideContentType != null)
@ -367,7 +365,7 @@ public abstract class ContentTypeManager {
/** /**
* Parse the content types part. * Parse the content types part.
* *
* @throws InvalidFormatException * @throws InvalidFormatException
* Throws if the content type doesn't exist or the XML format is * Throws if the content type doesn't exist or the XML format is
* invalid. * invalid.
@ -414,7 +412,7 @@ public abstract class ContentTypeManager {
/** /**
* Save the contents type part. * Save the contents type part.
* *
* @param outStream * @param outStream
* The output stream use to save the XML content of the content * The output stream use to save the XML content of the content
* types part. * types part.
@ -448,7 +446,7 @@ public abstract class ContentTypeManager {
/** /**
* Use to append specific type XML elements, use by the save() method. * Use to append specific type XML elements, use by the save() method.
* *
* @param root * @param root
* XML parent element use to append this override type element. * XML parent element use to append this override type element.
* @param entry * @param entry
@ -459,13 +457,13 @@ public abstract class ContentTypeManager {
Entry<PackagePartName, String> entry) { Entry<PackagePartName, String> entry) {
root.addElement(OVERRIDE_TAG_NAME).addAttribute( root.addElement(OVERRIDE_TAG_NAME).addAttribute(
PART_NAME_ATTRIBUTE_NAME, PART_NAME_ATTRIBUTE_NAME,
((PackagePartName) entry.getKey()).getName()).addAttribute( entry.getKey().getName()).addAttribute(
CONTENT_TYPE_ATTRIBUTE_NAME, (String) entry.getValue()); CONTENT_TYPE_ATTRIBUTE_NAME, entry.getValue());
} }
/** /**
* Use to append default types XML elements, use by the save() metid. * Use to append default types XML elements, use by the save() metid.
* *
* @param root * @param root
* XML parent element use to append this default type element. * XML parent element use to append this default type element.
* @param entry * @param entry
@ -474,16 +472,16 @@ public abstract class ContentTypeManager {
*/ */
private void appendDefaultType(Element root, Entry<String, String> entry) { private void appendDefaultType(Element root, Entry<String, String> entry) {
root.addElement(DEFAULT_TAG_NAME).addAttribute( root.addElement(DEFAULT_TAG_NAME).addAttribute(
EXTENSION_ATTRIBUTE_NAME, (String) entry.getKey()) EXTENSION_ATTRIBUTE_NAME, entry.getKey())
.addAttribute(CONTENT_TYPE_ATTRIBUTE_NAME, .addAttribute(CONTENT_TYPE_ATTRIBUTE_NAME,
(String) entry.getValue()); entry.getValue());
} }
/** /**
* Specific implementation of the save method. Call by the save() method, * Specific implementation of the save method. Call by the save() method,
* call before exiting. * call before exiting.
* *
* @param out * @param out
* The output stream use to write the content type XML. * The output stream use to write the content type XML.
*/ */

View File

@ -41,7 +41,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
private boolean formulasNotResults = false; private boolean formulasNotResults = false;
private boolean includeCellComments = false; private boolean includeCellComments = false;
private boolean includeHeadersFooters = true; private boolean includeHeadersFooters = true;
public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException { public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException {
this(new XSSFWorkbook(path)); this(new XSSFWorkbook(path));
} }
@ -52,14 +52,14 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
super(workbook); super(workbook);
this.workbook = workbook; this.workbook = workbook;
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
if(args.length < 1) { if(args.length < 1) {
System.err.println("Use:"); System.err.println("Use:");
System.err.println(" HXFExcelExtractor <filename.xlsx>"); System.err.println(" HXFExcelExtractor <filename.xlsx>");
System.exit(1); System.exit(1);
} }
POIXMLTextExtractor extractor = POIXMLTextExtractor extractor =
new XSSFExcelExtractor(args[0]); new XSSFExcelExtractor(args[0]);
System.out.println(extractor.getText()); System.out.println(extractor.getText());
} }
@ -89,19 +89,19 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
public void setIncludeHeadersFooters(boolean includeHeadersFooters) { public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
this.includeHeadersFooters = includeHeadersFooters; this.includeHeadersFooters = includeHeadersFooters;
} }
/** /**
* Retreives the text contents of the file * Retreives the text contents of the file
*/ */
public String getText() { public String getText() {
StringBuffer text = new StringBuffer(); StringBuffer text = new StringBuffer();
for(int i=0; i<workbook.getNumberOfSheets(); i++) { for(int i=0; i<workbook.getNumberOfSheets(); i++) {
XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(i); XSSFSheet sheet = workbook.getSheetAt(i);
if(includeSheetNames) { if(includeSheetNames) {
text.append(workbook.getSheetName(i) + "\n"); text.append(workbook.getSheetName(i) + "\n");
} }
// Header(s), if present // Header(s), if present
if(includeHeadersFooters) { if(includeHeadersFooters) {
text.append( text.append(
@ -120,7 +120,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
Row row = (Row)rawR; Row row = (Row)rawR;
for(Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) { for(Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
Cell cell = ri.next(); Cell cell = ri.next();
// Is it a formula one? // Is it a formula one?
if(cell.getCellType() == Cell.CELL_TYPE_FORMULA && formulasNotResults) { if(cell.getCellType() == Cell.CELL_TYPE_FORMULA && formulasNotResults) {
text.append(cell.getCellFormula()); text.append(cell.getCellFormula());
@ -130,7 +130,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
XSSFCell xc = (XSSFCell)cell; XSSFCell xc = (XSSFCell)cell;
text.append(xc.getRawValue()); text.append(xc.getRawValue());
} }
// Output the comment, if requested and exists // Output the comment, if requested and exists
Comment comment = cell.getCellComment(); Comment comment = cell.getCellComment();
if(includeCellComments && comment != null) { if(includeCellComments && comment != null) {
@ -139,13 +139,13 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
String commentText = comment.getString().getString().replace('\n', ' '); String commentText = comment.getString().getString().replace('\n', ' ');
text.append(" Comment by "+comment.getAuthor()+": "+commentText); text.append(" Comment by "+comment.getAuthor()+": "+commentText);
} }
if(ri.hasNext()) if(ri.hasNext())
text.append("\t"); text.append("\t");
} }
text.append("\n"); text.append("\n");
} }
// Finally footer(s), if present // Finally footer(s), if present
if(includeHeadersFooters) { if(includeHeadersFooters) {
text.append( text.append(
@ -159,10 +159,10 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach
); );
} }
} }
return text.toString(); return text.toString();
} }
private String extractHeaderFooter(HeaderFooter hf) { private String extractHeaderFooter(HeaderFooter hf) {
return ExcelExtractor._extractHeaderFooter(hf); return ExcelExtractor._extractHeaderFooter(hf);
} }

View File

@ -585,9 +585,11 @@ public final class XSSFCell implements Cell {
*/ */
public byte getErrorCellValue() { public byte getErrorCellValue() {
String code = getErrorCellString(); String code = getErrorCellString();
if(code == null) return 0; if (code == null) {
return 0;
}
return (byte)FormulaError.forString(code).getCode(); return FormulaError.forString(code).getCode();
} }
/** /**
@ -778,7 +780,7 @@ public final class XSSFCell implements Cell {
SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007; SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;
int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex(); int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
if (cellIndex < 0 || cellIndex > maxcol) { if (cellIndex < 0 || cellIndex > maxcol) {
throw new IllegalArgumentException("Invalid column index (" + cellIndex throw new IllegalArgumentException("Invalid column index (" + cellIndex
+ "). Allowable column range for " + v.name() + " is (0.." + "). Allowable column range for " + v.name() + " is (0.."
+ maxcol + ") or ('A'..'" + v.getLastColumnName() + "')"); + maxcol + ") or ('A'..'" + v.getLastColumnName() + "')");
} }
@ -848,7 +850,7 @@ public final class XSSFCell implements Cell {
*/ */
private boolean convertCellValueToBoolean() { private boolean convertCellValueToBoolean() {
int cellType = getCellType(); int cellType = getCellType();
if (cellType == CELL_TYPE_FORMULA) { if (cellType == CELL_TYPE_FORMULA) {
cellType = getBaseCellType(false); cellType = getBaseCellType(false);
} }

View File

@ -145,9 +145,8 @@ public class XSSFCellStyle implements CellStyle {
CTCellAlignment align = cellXf.getAlignment(); CTCellAlignment align = cellXf.getAlignment();
if(align != null && align.isSetHorizontal()) { if(align != null && align.isSetHorizontal()) {
return HorizontalAlignment.values()[align.getHorizontal().intValue()-1]; return HorizontalAlignment.values()[align.getHorizontal().intValue()-1];
} else {
return HorizontalAlignment.GENERAL;
} }
return HorizontalAlignment.GENERAL;
} }
/** /**
@ -865,7 +864,7 @@ public class XSSFCellStyle implements CellStyle {
*/ */
public void setDataFormat(short fmt) { public void setDataFormat(short fmt) {
cellXf.setApplyNumberFormat(true); cellXf.setApplyNumberFormat(true);
cellXf.setNumFmtId((long)fmt); cellXf.setNumFmtId(fmt);
} }
/** /**

View File

@ -285,7 +285,7 @@ public class XSSFPrintSetup implements PrintSetup {
* @see PaperSize * @see PaperSize
*/ */
public PaperSize getPaperSizeEnum() { public PaperSize getPaperSizeEnum() {
return PaperSize.values()[((int) getPaperSize() - 1)]; return PaperSize.values()[getPaperSize() - 1];
} }
/** /**

View File

@ -255,7 +255,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
/** /**
* Returns the name of this sheet * Returns the name of this sheet
* *
* @return the name of this sheet * @return the name of this sheet
*/ */
public String getSheetName() { public String getSheetName() {
@ -358,7 +358,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
public void createFreezePane(int colSplit, int rowSplit) { public void createFreezePane(int colSplit, int rowSplit) {
createFreezePane( colSplit, rowSplit, colSplit, rowSplit ); createFreezePane( colSplit, rowSplit, colSplit, rowSplit );
} }
/** /**
* Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
* @param colSplit Horizonatal position of split. * @param colSplit Horizonatal position of split.
@ -533,7 +533,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
worksheet.getSheetFormatPr() : worksheet.getSheetFormatPr() :
worksheet.addNewSheetFormatPr(); worksheet.addNewSheetFormatPr();
} }
/** /**
* Returns the CellStyle that applies to the given * Returns the CellStyle that applies to the given
* (0 based) column, or null if no style has been * (0 based) column, or null if no style has been
@ -571,7 +571,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
/** /**
* Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value. * Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value.
* When false, cells with zero value appear blank instead of showing the number zero. * When false, cells with zero value appear blank instead of showing the number zero.
* *
* @return whether all zero values on the worksheet are displayed * @return whether all zero values on the worksheet are displayed
*/ */
public boolean isDisplayZeros(){ public boolean isDisplayZeros(){
@ -1333,7 +1333,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
.getOutlineLevel(), true); .getOutlineLevel(), true);
// write collapse field // write collapse field
setColumn((int) (lastColMax + 1), null, 0, null, null, Boolean.TRUE); setColumn(lastColMax + 1, null, 0, null, null, Boolean.TRUE);
} }
@ -1433,7 +1433,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
/** /**
* Sets all adjacent columns of the same outline level to the specified * Sets all adjacent columns of the same outline level to the specified
* hidden status. * hidden status.
* *
* @param pIdx * @param pIdx
* the col info index of the start of the outline group * the col info index of the start of the outline group
* @return the column index of the last column in the outline group * @return the column index of the last column in the outline group
@ -1626,7 +1626,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
/** /**
* 'Collapsed' state is stored in a single column col info record * 'Collapsed' state is stored in a single column col info record
* immediately after the outline group * immediately after the outline group
* *
* @param idx * @param idx
* @return a boolean represented if the column is collapsed * @return a boolean represented if the column is collapsed
*/ */
@ -1764,7 +1764,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* outline level collapsed, thus hiding all the child rows. Note that in * outline level collapsed, thus hiding all the child rows. Note that in
* this case, if the lowest level were expanded, the middle level would * this case, if the lowest level were expanded, the middle level would
* remain collapsed. * remain collapsed.
* *
* @param rowIndex - * @param rowIndex -
* the row involved, 0 based * the row involved, 0 based
* @param collapse - * @param collapse -
@ -1895,8 +1895,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
endLevel = 0; endLevel = 0;
endHidden = false; endHidden = false;
} else { } else {
endLevel = (int) (getRow(endOfOutlineGroupIdx).getCTRow() endLevel = getRow(endOfOutlineGroupIdx).getCTRow().getOutlineLevel();
.getOutlineLevel());
endHidden = getRow(endOfOutlineGroupIdx).getCTRow().getHidden(); endHidden = getRow(endOfOutlineGroupIdx).getCTRow().getHidden();
} }
@ -1931,7 +1930,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
else else
return getRow(collapseRow).getCTRow().getCollapsed(); return getRow(collapseRow).getCTRow().getCollapsed();
} }
/** /**
* Sets the zoom magnication for the sheet. The zoom is expressed as a * Sets the zoom magnication for the sheet. The zoom is expressed as a
* fraction. For example to express a zoom of 75% use 3 for the numerator * fraction. For example to express a zoom of 75% use 3 for the numerator

View File

@ -35,22 +35,23 @@ import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase; import junit.framework.TestCase;
public class TestCommentsTable extends TestCase { public class TestCommentsTable extends TestCase {
private static final String TEST_A2_TEXT = "test A2 text"; private static final String TEST_A2_TEXT = "test A2 text";
private static final String TEST_A1_TEXT = "test A1 text"; private static final String TEST_A1_TEXT = "test A1 text";
private static final String TEST_AUTHOR = "test author"; private static final String TEST_AUTHOR = "test author";
public void testfindAuthor() throws Exception { public void testfindAuthor() throws Exception {
CommentsDocument doc = CommentsDocument.Factory.newInstance(); CommentsDocument doc = CommentsDocument.Factory.newInstance();
doc.setComments(CTComments.Factory.newInstance()); doc.setComments(CTComments.Factory.newInstance());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
CommentsTable sheetComments = new CommentsTable(); CommentsTable sheetComments = new CommentsTable();
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR)); assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
assertEquals(1, sheetComments.findAuthor("another author")); assertEquals(1, sheetComments.findAuthor("another author"));
@ -58,19 +59,19 @@ public class TestCommentsTable extends TestCase {
assertEquals(2, sheetComments.findAuthor("YAA")); assertEquals(2, sheetComments.findAuthor("YAA"));
assertEquals(1, sheetComments.findAuthor("another author")); assertEquals(1, sheetComments.findAuthor("another author"));
} }
public void testGetCellComment() throws Exception { public void testGetCellComment() throws Exception {
CommentsDocument doc = CommentsDocument.Factory.newInstance(); CommentsDocument doc = CommentsDocument.Factory.newInstance();
doc.setComments(CTComments.Factory.newInstance()); doc.setComments(CTComments.Factory.newInstance());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
CommentsTable sheetComments = new CommentsTable(); CommentsTable sheetComments = new CommentsTable();
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
CTComments comments = sheetComments.getCTComments(); CTComments comments = sheetComments.getCTComments();
CTCommentList commentList = comments.addNewCommentList(); CTCommentList commentList = comments.addNewCommentList();
// Create 2 comments for A1 and A" cells // Create 2 comments for A1 and A" cells
CTComment comment0 = commentList.insertNewComment(0); CTComment comment0 = commentList.insertNewComment(0);
comment0.setRef("A1"); comment0.setRef("A1");
@ -82,7 +83,7 @@ public class TestCommentsTable extends TestCase {
CTRst ctrst1 = CTRst.Factory.newInstance(); CTRst ctrst1 = CTRst.Factory.newInstance();
ctrst1.setT(TEST_A2_TEXT); ctrst1.setT(TEST_A2_TEXT);
comment1.setText(ctrst1); comment1.setText(ctrst1);
// test finding the right comment for a cell // test finding the right comment for a cell
assertEquals(TEST_A1_TEXT, sheetComments.findCellComment("A1").getString().getString()); assertEquals(TEST_A1_TEXT, sheetComments.findCellComment("A1").getString().getString());
assertEquals(TEST_A1_TEXT, sheetComments.findCellComment(0, 0).getString().getString()); assertEquals(TEST_A1_TEXT, sheetComments.findCellComment(0, 0).getString().getString());
@ -91,77 +92,81 @@ public class TestCommentsTable extends TestCase {
assertNull(sheetComments.findCellComment("A3")); assertNull(sheetComments.findCellComment("A3"));
assertNull(sheetComments.findCellComment(2, 0)); assertNull(sheetComments.findCellComment(2, 0));
} }
public void testAddCellComment() throws Exception { public void testAddCellComment() throws Exception {
CommentsDocument doc = CommentsDocument.Factory.newInstance(); CommentsDocument doc = CommentsDocument.Factory.newInstance();
doc.setComments(CTComments.Factory.newInstance()); doc.setComments(CTComments.Factory.newInstance());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
CommentsTable sheetComments = new CommentsTable(); CommentsTable sheetComments = new CommentsTable();
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
CTCommentList commentList = sheetComments.getCTComments().addNewCommentList(); CTCommentList commentList = sheetComments.getCTComments().addNewCommentList();
assertEquals(0, commentList.sizeOfCommentArray()); assertEquals(0, commentList.sizeOfCommentArray());
XSSFComment comment = sheetComments.addComment(); XSSFComment comment = sheetComments.addComment();
comment.setAuthor("test A1 author"); comment.setAuthor("test A1 author");
comment.setRow(0); comment.setRow(0);
comment.setColumn((short)0); comment.setColumn((short)0);
assertEquals(1, commentList.sizeOfCommentArray()); assertEquals(1, commentList.sizeOfCommentArray());
assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId())); assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId()));
assertEquals("test A1 author", comment.getAuthor()); assertEquals("test A1 author", comment.getAuthor());
// Change the author, check it updates // Change the author, check it updates
comment.setAuthor("Another Author"); comment.setAuthor("Another Author");
assertEquals(1, commentList.sizeOfCommentArray()); assertEquals(1, commentList.sizeOfCommentArray());
assertEquals("Another Author", comment.getAuthor()); assertEquals("Another Author", comment.getAuthor());
} }
public void testDontLoostNewLines() throws Exception { public void testDontLoostNewLines() throws Exception {
File xml = new File( File xml = new File(
System.getProperty("HSSF.testdata.path") + System.getProperty("HSSF.testdata.path") +
File.separator + "WithVariousData.xlsx" File.separator + "WithVariousData.xlsx"
); );
assertTrue(xml.exists()); assertTrue(xml.exists());
OPCPackage pkg = OPCPackage.open(xml.toString()); OPCPackage pkg = OPCPackage.open(xml.toString());
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb = new XSSFWorkbook(pkg);
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations(); List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
CommentsTable ct = null; CommentsTable ct = null;
for(POIXMLDocumentPart p : rels) { for(POIXMLDocumentPart p : rels) {
if(p instanceof CommentsTable){ if(p instanceof CommentsTable){
ct = (CommentsTable)p; ct = (CommentsTable)p;
break; break;
} }
} }
assertNotNull(ct); if (ct == null) {
throw new AssertionFailedError("didn't find comments table");
}
assertEquals(2, ct.getNumberOfComments()); assertEquals(2, ct.getNumberOfComments());
assertEquals(1, ct.getNumberOfAuthors()); assertEquals(1, ct.getNumberOfAuthors());
XSSFComment comment = ct.findCellComment("C5"); XSSFComment comment = ct.findCellComment("C5");
assertEquals("Nick Burch", comment.getAuthor()); assertEquals("Nick Burch", comment.getAuthor());
assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString());
wb = XSSFTestDataSamples.writeOutAndReadBack(wb); wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
rels = wb.getSheetAt(0).getRelations(); rels = wb.getSheetAt(0).getRelations();
ct = null; ct = null;
for(POIXMLDocumentPart p : rels) { for(POIXMLDocumentPart p : rels) {
if(p instanceof CommentsTable){ if(p instanceof CommentsTable){
ct = (CommentsTable)p; ct = (CommentsTable)p;
break; break;
} }
} }
assertNotNull(ct); if (ct == null) {
throw new AssertionFailedError("didn't find comments table");
}
assertEquals(2, ct.getNumberOfComments()); assertEquals(2, ct.getNumberOfComments());
assertEquals(1, ct.getNumberOfAuthors()); assertEquals(1, ct.getNumberOfAuthors());
comment = ct.findCellComment("C5"); comment = ct.findCellComment("C5");
assertEquals("Nick Burch", comment.getAuthor()); assertEquals("Nick Burch", comment.getAuthor());
assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString());
} }
@ -171,127 +176,127 @@ public class TestCommentsTable extends TestCase {
File.separator + "WithVariousData.xlsx" File.separator + "WithVariousData.xlsx"
); );
assertTrue(xml.exists()); assertTrue(xml.exists());
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
Sheet sheet1 = workbook.getSheetAt(0); Sheet sheet1 = workbook.getSheetAt(0);
Sheet sheet2 = workbook.getSheetAt(1); Sheet sheet2 = workbook.getSheetAt(1);
assertTrue( ((XSSFSheet)sheet1).hasComments() ); assertTrue( ((XSSFSheet)sheet1).hasComments() );
assertFalse( ((XSSFSheet)sheet2).hasComments() ); assertFalse( ((XSSFSheet)sheet2).hasComments() );
// Comments should be in C5 and C7 // Comments should be in C5 and C7
Row r5 = sheet1.getRow(4); Row r5 = sheet1.getRow(4);
Row r7 = sheet1.getRow(6); Row r7 = sheet1.getRow(6);
assertNotNull( r5.getCell(2).getCellComment() ); assertNotNull( r5.getCell(2).getCellComment() );
assertNotNull( r7.getCell(2).getCellComment() ); assertNotNull( r7.getCell(2).getCellComment() );
// Check they have what we expect // Check they have what we expect
// TODO: Rich text formatting // TODO: Rich text formatting
Comment cc5 = r5.getCell(2).getCellComment(); Comment cc5 = r5.getCell(2).getCellComment();
Comment cc7 = r7.getCell(2).getCellComment(); Comment cc7 = r7.getCell(2).getCellComment();
assertEquals("Nick Burch", cc5.getAuthor()); assertEquals("Nick Burch", cc5.getAuthor());
assertEquals("Nick Burch:\nThis is a comment", cc5.getString().getString()); assertEquals("Nick Burch:\nThis is a comment", cc5.getString().getString());
assertEquals(4, cc5.getRow()); assertEquals(4, cc5.getRow());
assertEquals(2, cc5.getColumn()); assertEquals(2, cc5.getColumn());
assertEquals("Nick Burch", cc7.getAuthor()); assertEquals("Nick Burch", cc7.getAuthor());
assertEquals("Nick Burch:\nComment #1\n", cc7.getString().getString()); assertEquals("Nick Burch:\nComment #1\n", cc7.getString().getString());
assertEquals(6, cc7.getRow()); assertEquals(6, cc7.getRow());
assertEquals(2, cc7.getColumn()); assertEquals(2, cc7.getColumn());
} }
public void testWriteRead() throws Exception { public void testWriteRead() throws Exception {
File xml = new File( File xml = new File(
System.getProperty("HSSF.testdata.path") + System.getProperty("HSSF.testdata.path") +
File.separator + "WithVariousData.xlsx" File.separator + "WithVariousData.xlsx"
); );
assertTrue(xml.exists()); assertTrue(xml.exists());
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
Sheet sheet1 = workbook.getSheetAt(0); XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1); XSSFSheet sheet2 = workbook.getSheetAt(1);
assertTrue( ((XSSFSheet)sheet1).hasComments() ); assertTrue( sheet1.hasComments() );
assertFalse( ((XSSFSheet)sheet2).hasComments() ); assertFalse( sheet2.hasComments() );
// Change on comment on sheet 1, and add another into // Change on comment on sheet 1, and add another into
// sheet 2 // sheet 2
Row r5 = sheet1.getRow(4); Row r5 = sheet1.getRow(4);
Comment cc5 = r5.getCell(2).getCellComment(); Comment cc5 = r5.getCell(2).getCellComment();
cc5.setAuthor("Apache POI"); cc5.setAuthor("Apache POI");
cc5.setString(new XSSFRichTextString("Hello!")); cc5.setString(new XSSFRichTextString("Hello!"));
Row r2s2 = sheet2.createRow(2); Row r2s2 = sheet2.createRow(2);
Cell c1r2s2 = r2s2.createCell(1); Cell c1r2s2 = r2s2.createCell(1);
assertNull(c1r2s2.getCellComment()); assertNull(c1r2s2.getCellComment());
Comment cc2 = sheet2.createComment(); Comment cc2 = sheet2.createComment();
cc2.setAuthor("Also POI"); cc2.setAuthor("Also POI");
cc2.setString(new XSSFRichTextString("A new comment")); cc2.setString(new XSSFRichTextString("A new comment"));
c1r2s2.setCellComment(cc2); c1r2s2.setCellComment(cc2);
// Save, and re-load the file // Save, and re-load the file
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
// Check we still have comments where we should do // Check we still have comments where we should do
sheet1 = workbook.getSheetAt(0); sheet1 = workbook.getSheetAt(0);
sheet2 = (XSSFSheet)workbook.getSheetAt(1); sheet2 = workbook.getSheetAt(1);
assertNotNull(sheet1.getRow(4).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(6).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
assertNotNull(sheet2.getRow(2).getCell(1).getCellComment()); assertNotNull(sheet2.getRow(2).getCell(1).getCellComment());
// And check they still have the contents they should do // And check they still have the contents they should do
assertEquals("Apache POI", assertEquals("Apache POI",
sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", assertEquals("Nick Burch",
sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Also POI", assertEquals("Also POI",
sheet2.getRow(2).getCell(1).getCellComment().getAuthor()); sheet2.getRow(2).getCell(1).getCellComment().getAuthor());
assertEquals("Nick Burch:\nThis is a comment", assertEquals("Nick Burch:\nThis is a comment",
sheet1.getRow(4).getCell(2).getCellComment().getString().getString()); sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
} }
public void testReadWriteMultipleAuthors() throws Exception { public void testReadWriteMultipleAuthors() throws Exception {
File xml = new File( File xml = new File(
System.getProperty("HSSF.testdata.path") + System.getProperty("HSSF.testdata.path") +
File.separator + "WithMoreVariousData.xlsx" File.separator + "WithMoreVariousData.xlsx"
); );
assertTrue(xml.exists()); assertTrue(xml.exists());
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
Sheet sheet1 = workbook.getSheetAt(0); XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1); XSSFSheet sheet2 = workbook.getSheetAt(1);
assertTrue( ((XSSFSheet)sheet1).hasComments() ); assertTrue( sheet1.hasComments() );
assertFalse( ((XSSFSheet)sheet2).hasComments() ); assertFalse( sheet2.hasComments() );
assertEquals("Nick Burch", assertEquals("Nick Burch",
sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", assertEquals("Nick Burch",
sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Torchbox", assertEquals("Torchbox",
sheet1.getRow(12).getCell(2).getCellComment().getAuthor()); sheet1.getRow(12).getCell(2).getCellComment().getAuthor());
// Save, and re-load the file // Save, and re-load the file
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
// Check we still have comments where we should do // Check we still have comments where we should do
sheet1 = workbook.getSheetAt(0); sheet1 = workbook.getSheetAt(0);
assertNotNull(sheet1.getRow(4).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(6).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(12).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(12).getCell(2).getCellComment());
// And check they still have the contents they should do // And check they still have the contents they should do
assertEquals("Nick Burch", assertEquals("Nick Burch",
sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", assertEquals("Nick Burch",
sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Torchbox", assertEquals("Torchbox",
sheet1.getRow(12).getCell(2).getCellComment().getAuthor()); sheet1.getRow(12).getCell(2).getCellComment().getAuthor());
// Todo - check text too, once bug fixed // Todo - check text too, once bug fixed
} }
} }

View File

@ -24,10 +24,10 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
public final class TestXSSFHyperlink extends BaseTestHyperlink { public final class TestXSSFHyperlink extends BaseTestHyperlink {
@Override @Override
protected XSSFITestDataProvider getTestDataProvider() { protected XSSFITestDataProvider getTestDataProvider() {
return XSSFITestDataProvider.getInstance(); return XSSFITestDataProvider.getInstance();
} }
@Override @Override
protected void setUp() { protected void setUp() {
@ -48,7 +48,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0); XSSFSheet sheet = workbook.getSheetAt(0);
// Check the hyperlinks // Check the hyperlinks
assertEquals(4, sheet.getNumHyperlinks()); assertEquals(4, sheet.getNumHyperlinks());
@ -65,7 +65,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
CreationHelper createHelper = workbook.getCreationHelper(); CreationHelper createHelper = workbook.getCreationHelper();
assertEquals(3, workbook.getNumberOfSheets()); assertEquals(3, workbook.getNumberOfSheets());
XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0); XSSFSheet sheet = workbook.getSheetAt(0);
// Check hyperlinks // Check hyperlinks
assertEquals(4, sheet.getNumHyperlinks()); assertEquals(4, sheet.getNumHyperlinks());
@ -81,7 +81,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
assertNotNull(wb2.getSheetAt(1)); assertNotNull(wb2.getSheetAt(1));
assertNotNull(wb2.getSheetAt(2)); assertNotNull(wb2.getSheetAt(2));
sheet = (XSSFSheet)wb2.getSheetAt(0); sheet = wb2.getSheetAt(0);
// Check hyperlinks again // Check hyperlinks again

View File

@ -167,8 +167,8 @@ public final class StyleSheet {
break; break;
case 0x9: case 0x9:
newCHP._fSpec = true; newCHP._fSpec = true;
newCHP._ftcSym = (short)Utils.convertBytesToShort(varParam, 0); newCHP._ftcSym = Utils.convertBytesToShort(varParam, 0);
newCHP._xchSym = (short)Utils.convertBytesToShort(varParam, 2); newCHP._xchSym = Utils.convertBytesToShort(varParam, 2);
break; break;
case 0xa: case 0xa:
newCHP._fOle2 = getFlag(param); newCHP._fOle2 = getFlag(param);
@ -453,8 +453,8 @@ public final class StyleSheet {
doCHPOperation(oldCHP, newCHP, 0x47, param, varParam, grpprl, offset, styleSheet); doCHPOperation(oldCHP, newCHP, 0x47, param, varParam, grpprl, offset, styleSheet);
break; break;
case 0x4d: case 0x4d:
float percentage = (float)param/100.0f; float percentage = param/100.0f;
int add = (int)((float)percentage * (float)newCHP._hps); int add = (int)(percentage * newCHP._hps);
newCHP._hps += add; newCHP._hps += add;
break; break;
case 0x4e: case 0x4e:
@ -485,7 +485,7 @@ public final class StyleSheet {
break; break;
case 0x57: case 0x57:
newCHP._fPropMark = getFlag(varParam[0]); newCHP._fPropMark = getFlag(varParam[0]);
newCHP._ibstPropRMark = (short)Utils.convertBytesToShort(varParam, 1); newCHP._ibstPropRMark = Utils.convertBytesToShort(varParam, 1);
newCHP._dttmPropRMark = Utils.convertBytesToInt(varParam, 3); newCHP._dttmPropRMark = Utils.convertBytesToInt(varParam, 3);
break; break;
case 0x58: case 0x58:
@ -512,7 +512,7 @@ public final class StyleSheet {
break; break;
case 0x62: case 0x62:
newCHP._fDispFldRMark = getFlag(varParam[0]); newCHP._fDispFldRMark = getFlag(varParam[0]);
newCHP._ibstDispFldRMark = (short)Utils.convertBytesToShort(varParam, 1); newCHP._ibstDispFldRMark = Utils.convertBytesToShort(varParam, 1);
newCHP._dttmDispFldRMark = Utils.convertBytesToInt(varParam, 3); newCHP._dttmDispFldRMark = Utils.convertBytesToInt(varParam, 3);
System.arraycopy(varParam, 7, newCHP._xstDispFldRMark, 0, 32); System.arraycopy(varParam, 7, newCHP._xstDispFldRMark, 0, 32);
break; break;
@ -524,8 +524,8 @@ public final class StyleSheet {
newCHP._dttmRMarkDel[1] = Utils.convertBytesToShort(grpprl, offset - 2); newCHP._dttmRMarkDel[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x65: case 0x65:
newCHP._brc[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newCHP._brc[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newCHP._brc[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newCHP._brc[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x66: case 0x66:
newCHP._shd = (short)param; newCHP._shd = (short)param;
@ -834,28 +834,28 @@ public final class StyleSheet {
newPAP._wr = (byte)param; newPAP._wr = (byte)param;
break; break;
case 0x24: case 0x24:
newPAP._brcTop[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newPAP._brcTop[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newPAP._brcTop[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newPAP._brcTop[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x25: case 0x25:
newPAP._brcLeft[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newPAP._brcLeft[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newPAP._brcLeft[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newPAP._brcLeft[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x26: case 0x26:
newPAP._brcBottom[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newPAP._brcBottom[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newPAP._brcBottom[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newPAP._brcBottom[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x27: case 0x27:
newPAP._brcRight[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newPAP._brcRight[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newPAP._brcRight[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newPAP._brcRight[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x28: case 0x28:
newPAP._brcBetween[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newPAP._brcBetween[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newPAP._brcBetween[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newPAP._brcBetween[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x29: case 0x29:
newPAP._brcBar[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); newPAP._brcBar[0] = Utils.convertBytesToShort(grpprl, offset - 4);
newPAP._brcBar[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); newPAP._brcBar[1] = Utils.convertBytesToShort(grpprl, offset - 2);
break; break;
case 0x2a: case 0x2a:
newPAP._fNoAutoHyph = (byte)param; newPAP._fNoAutoHyph = (byte)param;

View File

@ -35,10 +35,10 @@ import org.apache.poi.util.LittleEndian;
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
public final class WordDocument {
public final class WordDocument // TODO - name this constant properly
{ private static final float K_1440_0F = 1440.0f;
/** byte buffer containing the main Document stream*/ /** byte buffer containing the main Document stream*/
byte[] _header; byte[] _header;
/** contains all style information for this document see Word 97 Doc spec*/ /** contains all style information for this document see Word 97 Doc spec*/
StyleSheet _styleSheet; StyleSheet _styleSheet;
@ -1160,19 +1160,19 @@ public final class WordDocument
} }
if(pap._dxaLeft > 0) if(pap._dxaLeft > 0)
{ {
buf.append("start-indent=\"" + ((float)pap._dxaLeft)/1440.0f + "in\"\r\n"); buf.append("start-indent=\"" + pap._dxaLeft/K_1440_0F + "in\"\r\n");
} }
if(pap._dxaRight > 0) if(pap._dxaRight > 0)
{ {
buf.append("end-indent=\"" + ((float)pap._dxaRight)/1440.0f + "in\"\r\n"); buf.append("end-indent=\"" + pap._dxaRight/K_1440_0F + "in\"\r\n");
} }
if(pap._dxaLeft1 != 0) if(pap._dxaLeft1 != 0)
{ {
buf.append("text-indent=\"" + ((float)pap._dxaLeft1)/1440.0f + "in\"\r\n"); buf.append("text-indent=\"" + pap._dxaLeft1/K_1440_0F + "in\"\r\n");
} }
if(pap._lspd[1] == 0) if(pap._lspd[1] == 0)
{ {
//buf.append("line-height=\"" + ((float)pap._lspd[0])/1440.0f + "in\"\r\n"); //buf.append("line-height=\"" + pap._lspd[0]/K_1440_0F + "in\"\r\n");
} }
addBorder(buf, pap._brcTop, "top"); addBorder(buf, pap._brcTop, "top");
addBorder(buf, pap._brcBottom, "bottom"); addBorder(buf, pap._brcBottom, "bottom");
@ -1190,7 +1190,7 @@ public final class WordDocument
buf.append("font-size=\"" + (chp._hps / 2) + "pt\" "); buf.append("font-size=\"" + (chp._hps / 2) + "pt\" ");
buf.append("color=\"" + getColor(chp._ico) + "\" "); buf.append("color=\"" + getColor(chp._ico) + "\" ");
//not supported by fop //not supported by fop
//buf.append("letter-spacing=\"" + ((double)chp._dxaSpace)/1440.0f + "in\" "); //buf.append("letter-spacing=\"" + ((double)chp._dxaSpace)/K_1440_0F + "in\" ");
addBorder(buf, chp._brc, "top"); addBorder(buf, chp._brc, "top");
addBorder(buf, chp._brc, "bottom"); addBorder(buf, chp._brc, "bottom");
@ -1236,11 +1236,11 @@ public final class WordDocument
} }
if(chp._paddingStart != 0) if(chp._paddingStart != 0)
{ {
buf.append("padding-start=\"" + (float)chp._paddingStart/1440.0f + "in\" "); buf.append("padding-start=\"" + chp._paddingStart/K_1440_0F + "in\" ");
} }
if(chp._paddingEnd != 0) if(chp._paddingEnd != 0)
{ {
buf.append("padding-end=\"" + (float)chp._paddingEnd/1440.0f + "in\" "); buf.append("padding-end=\"" + chp._paddingEnd/K_1440_0F + "in\" ");
} }
buf.append(">"); buf.append(">");
} }
@ -1416,12 +1416,12 @@ public final class WordDocument
private String createPageMaster(SEP sep, String type, int section, private String createPageMaster(SEP sep, String type, int section,
String regionBefore, String regionAfter) String regionBefore, String regionAfter)
{ {
float height = ((float)sep._yaPage)/1440.0f; float height = sep._yaPage/K_1440_0F;
float width = ((float)sep._xaPage)/1440.0f; float width = sep._xaPage/K_1440_0F;
float leftMargin = ((float)sep._dxaLeft)/1440.0f; float leftMargin = sep._dxaLeft/K_1440_0F;
float rightMargin = ((float)sep._dxaRight)/1440.0f; float rightMargin = sep._dxaRight/K_1440_0F;
float topMargin = ((float)sep._dyaTop)/1440.0f; float topMargin = sep._dyaTop/K_1440_0F;
float bottomMargin = ((float)sep._dyaBottom)/1440.0f; float bottomMargin = sep._dyaBottom/K_1440_0F;
//add these to the header //add these to the header
String thisPage = type + "-page" + section; String thisPage = type + "-page" + section;
@ -1452,7 +1452,7 @@ public final class WordDocument
_headerBuffer.append("column-count=\"" + (sep._ccolM1 + 1) + "\" "); _headerBuffer.append("column-count=\"" + (sep._ccolM1 + 1) + "\" ");
if(sep._fEvenlySpaced) if(sep._fEvenlySpaced)
{ {
_headerBuffer.append("column-gap=\"" + ((float)(sep._dxaColumns))/1440.0f + "in\""); _headerBuffer.append("column-gap=\"" + sep._dxaColumns/K_1440_0F + "in\"");
} }
else else
{ {
@ -1478,7 +1478,7 @@ public final class WordDocument
if((brc[0] & 0xff00) != 0 && brc[0] != -1) if((brc[0] & 0xff00) != 0 && brc[0] != -1)
{ {
int type = (brc[0] & 0xff00) >> 8; int type = (brc[0] & 0xff00) >> 8;
float width = ((float)(brc[0] & 0x00ff))/8.0f; float width = (brc[0] & 0x00ff)/8.0f;
String style = getBorderStyle(brc[0]); String style = getBorderStyle(brc[0]);
String color = getColor(brc[1] & 0x00ff); String color = getColor(brc[1] & 0x00ff);
String thickness = getBorderThickness(brc[0]); String thickness = getBorderThickness(brc[0]);
@ -1764,7 +1764,7 @@ public final class WordDocument
rowBuffer.append("<fo:table-row "); rowBuffer.append("<fo:table-row ");
if(tap._dyaRowHeight > 0) if(tap._dyaRowHeight > 0)
{ {
rowBuffer.append("height=\"" + ((float)tap._dyaRowHeight)/1440.0f + "in\" "); rowBuffer.append("height=\"" + tap._dyaRowHeight/K_1440_0F + "in\" ");
} }
if(tap._fCantSplit) if(tap._fCantSplit)
{ {
@ -1777,9 +1777,9 @@ public final class WordDocument
TC tc = tap._rgtc[y]; TC tc = tap._rgtc[y];
overrideCellBorder(x, y, size, tap._itcMac, tc, tap); overrideCellBorder(x, y, size, tap._itcMac, tc, tap);
rowBuffer.append("<fo:table-cell "); rowBuffer.append("<fo:table-cell ");
rowBuffer.append("width=\"" + ((float)(tap._rgdxaCenter[y+1] - tap._rgdxaCenter[y]))/1440.0f + "in\" "); rowBuffer.append("width=\"" + (tap._rgdxaCenter[y+1] - tap._rgdxaCenter[y])/K_1440_0F + "in\" ");
rowBuffer.append("padding-start=\"" + ((float)tap._dxaGapHalf)/1440.0f + "in\" "); rowBuffer.append("padding-start=\"" + tap._dxaGapHalf/K_1440_0F + "in\" ");
rowBuffer.append("padding-end=\"" + ((float)tap._dxaGapHalf)/1440.0f + "in\" "); rowBuffer.append("padding-end=\"" + tap._dxaGapHalf/K_1440_0F + "in\" ");
addBorder(rowBuffer, tc._brcTop, "top"); addBorder(rowBuffer, tc._brcTop, "top");
addBorder(rowBuffer, tc._brcLeft, "left"); addBorder(rowBuffer, tc._brcLeft, "left");
addBorder(rowBuffer, tc._brcBottom, "bottom"); addBorder(rowBuffer, tc._brcBottom, "bottom");

View File

@ -224,8 +224,8 @@ public final class StyleSheet implements HDFType {
break; break;
case 0x9: case 0x9:
newCHP.setFSpec(true); newCHP.setFSpec(true);
newCHP.setFtcSym((short)LittleEndian.getShort(varParam, 0)); newCHP.setFtcSym(LittleEndian.getShort(varParam, 0));
newCHP.setXchSym((short)LittleEndian.getShort(varParam, 2)); newCHP.setXchSym(LittleEndian.getShort(varParam, 2));
break; break;
case 0xa: case 0xa:
newCHP.setFOle2(getFlag(param)); newCHP.setFOle2(getFlag(param));
@ -517,8 +517,8 @@ public final class StyleSheet implements HDFType {
doCHPOperation(oldCHP, newCHP, 0x47, param, varParam, grpprl, offset, styleSheet); doCHPOperation(oldCHP, newCHP, 0x47, param, varParam, grpprl, offset, styleSheet);
break; break;
case 0x4d: case 0x4d:
float percentage = (float)param/100.0f; float percentage = param/100.0f;
int add = (int)((float)percentage * (float)newCHP.getHps()); int add = (int)(percentage * newCHP.getHps());
newCHP.setHps(newCHP.getHps() + add); newCHP.setHps(newCHP.getHps() + add);
break; break;
case 0x4e: case 0x4e:
@ -549,7 +549,7 @@ public final class StyleSheet implements HDFType {
break; break;
case 0x57: case 0x57:
newCHP.setFPropMark(varParam[0]); newCHP.setFPropMark(varParam[0]);
newCHP.setIbstPropRMark((short)LittleEndian.getShort(varParam, 1)); newCHP.setIbstPropRMark(LittleEndian.getShort(varParam, 1));
newCHP.setDttmPropRMark(LittleEndian.getInt(varParam, 3)); newCHP.setDttmPropRMark(LittleEndian.getInt(varParam, 3));
break; break;
case 0x58: case 0x58:
@ -577,7 +577,7 @@ public final class StyleSheet implements HDFType {
case 0x62: case 0x62:
byte[] xstDispFldRMark = new byte[32]; byte[] xstDispFldRMark = new byte[32];
newCHP.setFDispFldRMark(varParam[0]); newCHP.setFDispFldRMark(varParam[0]);
newCHP.setIbstDispFldRMark((short)LittleEndian.getShort(varParam, 1)); newCHP.setIbstDispFldRMark(LittleEndian.getShort(varParam, 1));
newCHP.setDttmDispFldRMark(LittleEndian.getInt(varParam, 3)); newCHP.setDttmDispFldRMark(LittleEndian.getInt(varParam, 3));
System.arraycopy(varParam, 7, xstDispFldRMark, 0, 32); System.arraycopy(varParam, 7, xstDispFldRMark, 0, 32);
newCHP.setXstDispFldRMark(xstDispFldRMark); newCHP.setXstDispFldRMark(xstDispFldRMark);
@ -593,8 +593,8 @@ public final class StyleSheet implements HDFType {
break; break;
case 0x65: case 0x65:
short[] brc = new short[2]; short[] brc = new short[2];
brc[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brc[0] = LittleEndian.getShort(grpprl, offset - 4);
brc[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brc[1] = LittleEndian.getShort(grpprl, offset - 2);
newCHP.setBrc(brc); newCHP.setBrc(brc);
break; break;
case 0x66: case 0x66:
@ -947,33 +947,33 @@ public final class StyleSheet implements HDFType {
break; break;
case 0x24: case 0x24:
short[] brcTop = newPAP.getBrcTop(); short[] brcTop = newPAP.getBrcTop();
brcTop[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brcTop[0] = LittleEndian.getShort(grpprl, offset - 4);
brcTop[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brcTop[1] = LittleEndian.getShort(grpprl, offset - 2);
break; break;
case 0x25: case 0x25:
short[] brcLeft = newPAP.getBrcLeft(); short[] brcLeft = newPAP.getBrcLeft();
brcLeft[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brcLeft[0] = LittleEndian.getShort(grpprl, offset - 4);
brcLeft[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brcLeft[1] = LittleEndian.getShort(grpprl, offset - 2);
break; break;
case 0x26: case 0x26:
short[] brcBottom = newPAP.getBrcBottom(); short[] brcBottom = newPAP.getBrcBottom();
brcBottom[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brcBottom[0] = LittleEndian.getShort(grpprl, offset - 4);
brcBottom[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brcBottom[1] = LittleEndian.getShort(grpprl, offset - 2);
break; break;
case 0x27: case 0x27:
short[] brcRight = newPAP.getBrcRight(); short[] brcRight = newPAP.getBrcRight();
brcRight[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brcRight[0] = LittleEndian.getShort(grpprl, offset - 4);
brcRight[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brcRight[1] = LittleEndian.getShort(grpprl, offset - 2);
break; break;
case 0x28: case 0x28:
short[] brcBetween = newPAP.getBrcBetween(); short[] brcBetween = newPAP.getBrcBetween();
brcBetween[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brcBetween[0] = LittleEndian.getShort(grpprl, offset - 4);
brcBetween[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brcBetween[1] = LittleEndian.getShort(grpprl, offset - 2);
break; break;
case 0x29: case 0x29:
short[] brcBar = newPAP.getBrcBar(); short[] brcBar = newPAP.getBrcBar();
brcBar[0] = (short)LittleEndian.getShort(grpprl, offset - 4); brcBar[0] = LittleEndian.getShort(grpprl, offset - 4);
brcBar[1] = (short)LittleEndian.getShort(grpprl, offset - 2); brcBar[1] = LittleEndian.getShort(grpprl, offset - 2);
break; break;
case 0x2a: case 0x2a:
newPAP.setFNoAutoHyph((byte)param); newPAP.setFNoAutoHyph((byte)param);

View File

@ -814,9 +814,7 @@ public abstract class CHPAbstractType
*/ */
public void setFBold(boolean value) public void setFBold(boolean value)
{ {
field_2_format_flags = (int)fBold.setBoolean(field_2_format_flags, value); field_2_format_flags = fBold.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -826,7 +824,6 @@ public abstract class CHPAbstractType
public boolean isFBold() public boolean isFBold()
{ {
return fBold.isSet(field_2_format_flags); return fBold.isSet(field_2_format_flags);
} }
/** /**
@ -835,9 +832,7 @@ public abstract class CHPAbstractType
*/ */
public void setFItalic(boolean value) public void setFItalic(boolean value)
{ {
field_2_format_flags = (int)fItalic.setBoolean(field_2_format_flags, value); field_2_format_flags = fItalic.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -847,7 +842,6 @@ public abstract class CHPAbstractType
public boolean isFItalic() public boolean isFItalic()
{ {
return fItalic.isSet(field_2_format_flags); return fItalic.isSet(field_2_format_flags);
} }
/** /**
@ -856,9 +850,7 @@ public abstract class CHPAbstractType
*/ */
public void setFRMarkDel(boolean value) public void setFRMarkDel(boolean value)
{ {
field_2_format_flags = (int)fRMarkDel.setBoolean(field_2_format_flags, value); field_2_format_flags = fRMarkDel.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -868,7 +860,6 @@ public abstract class CHPAbstractType
public boolean isFRMarkDel() public boolean isFRMarkDel()
{ {
return fRMarkDel.isSet(field_2_format_flags); return fRMarkDel.isSet(field_2_format_flags);
} }
/** /**
@ -877,9 +868,7 @@ public abstract class CHPAbstractType
*/ */
public void setFOutline(boolean value) public void setFOutline(boolean value)
{ {
field_2_format_flags = (int)fOutline.setBoolean(field_2_format_flags, value); field_2_format_flags = fOutline.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -889,7 +878,6 @@ public abstract class CHPAbstractType
public boolean isFOutline() public boolean isFOutline()
{ {
return fOutline.isSet(field_2_format_flags); return fOutline.isSet(field_2_format_flags);
} }
/** /**
@ -898,9 +886,7 @@ public abstract class CHPAbstractType
*/ */
public void setFFldVanish(boolean value) public void setFFldVanish(boolean value)
{ {
field_2_format_flags = (int)fFldVanish.setBoolean(field_2_format_flags, value); field_2_format_flags = fFldVanish.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -910,7 +896,6 @@ public abstract class CHPAbstractType
public boolean isFFldVanish() public boolean isFFldVanish()
{ {
return fFldVanish.isSet(field_2_format_flags); return fFldVanish.isSet(field_2_format_flags);
} }
/** /**
@ -919,9 +904,7 @@ public abstract class CHPAbstractType
*/ */
public void setFSmallCaps(boolean value) public void setFSmallCaps(boolean value)
{ {
field_2_format_flags = (int)fSmallCaps.setBoolean(field_2_format_flags, value); field_2_format_flags = fSmallCaps.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -931,7 +914,6 @@ public abstract class CHPAbstractType
public boolean isFSmallCaps() public boolean isFSmallCaps()
{ {
return fSmallCaps.isSet(field_2_format_flags); return fSmallCaps.isSet(field_2_format_flags);
} }
/** /**
@ -940,9 +922,7 @@ public abstract class CHPAbstractType
*/ */
public void setFCaps(boolean value) public void setFCaps(boolean value)
{ {
field_2_format_flags = (int)fCaps.setBoolean(field_2_format_flags, value); field_2_format_flags = fCaps.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -952,7 +932,6 @@ public abstract class CHPAbstractType
public boolean isFCaps() public boolean isFCaps()
{ {
return fCaps.isSet(field_2_format_flags); return fCaps.isSet(field_2_format_flags);
} }
/** /**
@ -961,9 +940,7 @@ public abstract class CHPAbstractType
*/ */
public void setFVanish(boolean value) public void setFVanish(boolean value)
{ {
field_2_format_flags = (int)fVanish.setBoolean(field_2_format_flags, value); field_2_format_flags = fVanish.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -973,7 +950,6 @@ public abstract class CHPAbstractType
public boolean isFVanish() public boolean isFVanish()
{ {
return fVanish.isSet(field_2_format_flags); return fVanish.isSet(field_2_format_flags);
} }
/** /**
@ -982,9 +958,7 @@ public abstract class CHPAbstractType
*/ */
public void setFRMark(boolean value) public void setFRMark(boolean value)
{ {
field_2_format_flags = (int)fRMark.setBoolean(field_2_format_flags, value); field_2_format_flags = fRMark.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -994,7 +968,6 @@ public abstract class CHPAbstractType
public boolean isFRMark() public boolean isFRMark()
{ {
return fRMark.isSet(field_2_format_flags); return fRMark.isSet(field_2_format_flags);
} }
/** /**
@ -1003,9 +976,7 @@ public abstract class CHPAbstractType
*/ */
public void setFSpec(boolean value) public void setFSpec(boolean value)
{ {
field_2_format_flags = (int)fSpec.setBoolean(field_2_format_flags, value); field_2_format_flags = fSpec.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1015,7 +986,6 @@ public abstract class CHPAbstractType
public boolean isFSpec() public boolean isFSpec()
{ {
return fSpec.isSet(field_2_format_flags); return fSpec.isSet(field_2_format_flags);
} }
/** /**
@ -1024,9 +994,7 @@ public abstract class CHPAbstractType
*/ */
public void setFStrike(boolean value) public void setFStrike(boolean value)
{ {
field_2_format_flags = (int)fStrike.setBoolean(field_2_format_flags, value); field_2_format_flags = fStrike.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1036,7 +1004,6 @@ public abstract class CHPAbstractType
public boolean isFStrike() public boolean isFStrike()
{ {
return fStrike.isSet(field_2_format_flags); return fStrike.isSet(field_2_format_flags);
} }
/** /**
@ -1045,9 +1012,7 @@ public abstract class CHPAbstractType
*/ */
public void setFObj(boolean value) public void setFObj(boolean value)
{ {
field_2_format_flags = (int)fObj.setBoolean(field_2_format_flags, value); field_2_format_flags = fObj.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1057,7 +1022,6 @@ public abstract class CHPAbstractType
public boolean isFObj() public boolean isFObj()
{ {
return fObj.isSet(field_2_format_flags); return fObj.isSet(field_2_format_flags);
} }
/** /**
@ -1066,9 +1030,7 @@ public abstract class CHPAbstractType
*/ */
public void setFShadow(boolean value) public void setFShadow(boolean value)
{ {
field_2_format_flags = (int)fShadow.setBoolean(field_2_format_flags, value); field_2_format_flags = fShadow.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1078,7 +1040,6 @@ public abstract class CHPAbstractType
public boolean isFShadow() public boolean isFShadow()
{ {
return fShadow.isSet(field_2_format_flags); return fShadow.isSet(field_2_format_flags);
} }
/** /**
@ -1087,9 +1048,7 @@ public abstract class CHPAbstractType
*/ */
public void setFLowerCase(boolean value) public void setFLowerCase(boolean value)
{ {
field_2_format_flags = (int)fLowerCase.setBoolean(field_2_format_flags, value); field_2_format_flags = fLowerCase.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1099,7 +1058,6 @@ public abstract class CHPAbstractType
public boolean isFLowerCase() public boolean isFLowerCase()
{ {
return fLowerCase.isSet(field_2_format_flags); return fLowerCase.isSet(field_2_format_flags);
} }
/** /**
@ -1108,9 +1066,7 @@ public abstract class CHPAbstractType
*/ */
public void setFData(boolean value) public void setFData(boolean value)
{ {
field_2_format_flags = (int)fData.setBoolean(field_2_format_flags, value); field_2_format_flags = fData.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1120,7 +1076,6 @@ public abstract class CHPAbstractType
public boolean isFData() public boolean isFData()
{ {
return fData.isSet(field_2_format_flags); return fData.isSet(field_2_format_flags);
} }
/** /**
@ -1129,9 +1084,7 @@ public abstract class CHPAbstractType
*/ */
public void setFOle2(boolean value) public void setFOle2(boolean value)
{ {
field_2_format_flags = (int)fOle2.setBoolean(field_2_format_flags, value); field_2_format_flags = fOle2.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1141,7 +1094,6 @@ public abstract class CHPAbstractType
public boolean isFOle2() public boolean isFOle2()
{ {
return fOle2.isSet(field_2_format_flags); return fOle2.isSet(field_2_format_flags);
} }
/** /**
@ -1150,9 +1102,7 @@ public abstract class CHPAbstractType
*/ */
public void setFEmboss(boolean value) public void setFEmboss(boolean value)
{ {
field_3_format_flags1 = (int)fEmboss.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fEmboss.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1162,7 +1112,6 @@ public abstract class CHPAbstractType
public boolean isFEmboss() public boolean isFEmboss()
{ {
return fEmboss.isSet(field_3_format_flags1); return fEmboss.isSet(field_3_format_flags1);
} }
/** /**
@ -1171,9 +1120,7 @@ public abstract class CHPAbstractType
*/ */
public void setFImprint(boolean value) public void setFImprint(boolean value)
{ {
field_3_format_flags1 = (int)fImprint.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fImprint.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1183,7 +1130,6 @@ public abstract class CHPAbstractType
public boolean isFImprint() public boolean isFImprint()
{ {
return fImprint.isSet(field_3_format_flags1); return fImprint.isSet(field_3_format_flags1);
} }
/** /**
@ -1192,9 +1138,7 @@ public abstract class CHPAbstractType
*/ */
public void setFDStrike(boolean value) public void setFDStrike(boolean value)
{ {
field_3_format_flags1 = (int)fDStrike.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fDStrike.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1204,7 +1148,6 @@ public abstract class CHPAbstractType
public boolean isFDStrike() public boolean isFDStrike()
{ {
return fDStrike.isSet(field_3_format_flags1); return fDStrike.isSet(field_3_format_flags1);
} }
/** /**
@ -1213,9 +1156,7 @@ public abstract class CHPAbstractType
*/ */
public void setFUsePgsuSettings(boolean value) public void setFUsePgsuSettings(boolean value)
{ {
field_3_format_flags1 = (int)fUsePgsuSettings.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fUsePgsuSettings.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1225,7 +1166,6 @@ public abstract class CHPAbstractType
public boolean isFUsePgsuSettings() public boolean isFUsePgsuSettings()
{ {
return fUsePgsuSettings.isSet(field_3_format_flags1); return fUsePgsuSettings.isSet(field_3_format_flags1);
} }
/** /**
@ -1235,8 +1175,6 @@ public abstract class CHPAbstractType
public void setIcoHighlight(byte value) public void setIcoHighlight(byte value)
{ {
field_33_Highlight = (short)icoHighlight.setValue(field_33_Highlight, value); field_33_Highlight = (short)icoHighlight.setValue(field_33_Highlight, value);
} }
/** /**
@ -1246,7 +1184,6 @@ public abstract class CHPAbstractType
public byte getIcoHighlight() public byte getIcoHighlight()
{ {
return ( byte )icoHighlight.getValue(field_33_Highlight); return ( byte )icoHighlight.getValue(field_33_Highlight);
} }
/** /**
@ -1256,8 +1193,6 @@ public abstract class CHPAbstractType
public void setFHighlight(boolean value) public void setFHighlight(boolean value)
{ {
field_33_Highlight = (short)fHighlight.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fHighlight.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1267,7 +1202,6 @@ public abstract class CHPAbstractType
public boolean isFHighlight() public boolean isFHighlight()
{ {
return fHighlight.isSet(field_33_Highlight); return fHighlight.isSet(field_33_Highlight);
} }
/** /**
@ -1277,8 +1211,6 @@ public abstract class CHPAbstractType
public void setKcd(byte value) public void setKcd(byte value)
{ {
field_33_Highlight = (short)kcd.setValue(field_33_Highlight, value); field_33_Highlight = (short)kcd.setValue(field_33_Highlight, value);
} }
/** /**
@ -1288,7 +1220,6 @@ public abstract class CHPAbstractType
public byte getKcd() public byte getKcd()
{ {
return ( byte )kcd.getValue(field_33_Highlight); return ( byte )kcd.getValue(field_33_Highlight);
} }
/** /**
@ -1298,8 +1229,6 @@ public abstract class CHPAbstractType
public void setFNavHighlight(boolean value) public void setFNavHighlight(boolean value)
{ {
field_33_Highlight = (short)fNavHighlight.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fNavHighlight.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1309,7 +1238,6 @@ public abstract class CHPAbstractType
public boolean isFNavHighlight() public boolean isFNavHighlight()
{ {
return fNavHighlight.isSet(field_33_Highlight); return fNavHighlight.isSet(field_33_Highlight);
} }
/** /**
@ -1319,8 +1247,6 @@ public abstract class CHPAbstractType
public void setFChsDiff(boolean value) public void setFChsDiff(boolean value)
{ {
field_33_Highlight = (short)fChsDiff.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fChsDiff.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1330,7 +1256,6 @@ public abstract class CHPAbstractType
public boolean isFChsDiff() public boolean isFChsDiff()
{ {
return fChsDiff.isSet(field_33_Highlight); return fChsDiff.isSet(field_33_Highlight);
} }
/** /**
@ -1340,8 +1265,6 @@ public abstract class CHPAbstractType
public void setFMacChs(boolean value) public void setFMacChs(boolean value)
{ {
field_33_Highlight = (short)fMacChs.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fMacChs.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1351,7 +1274,6 @@ public abstract class CHPAbstractType
public boolean isFMacChs() public boolean isFMacChs()
{ {
return fMacChs.isSet(field_33_Highlight); return fMacChs.isSet(field_33_Highlight);
} }
/** /**
@ -1361,8 +1283,6 @@ public abstract class CHPAbstractType
public void setFFtcAsciSym(boolean value) public void setFFtcAsciSym(boolean value)
{ {
field_33_Highlight = (short)fFtcAsciSym.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fFtcAsciSym.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1372,12 +1292,5 @@ public abstract class CHPAbstractType
public boolean isFFtcAsciSym() public boolean isFFtcAsciSym()
{ {
return fFtcAsciSym.isSet(field_33_Highlight); return fFtcAsciSym.isSet(field_33_Highlight);
} }
}
} // END OF CLASS

View File

@ -24,8 +24,8 @@ import java.io.OutputStream;
/** /**
* A decoder for the crazy LZW implementation used * A decoder for the crazy LZW implementation used
* in Visio. * in Visio.
* According to VSDump, "it's a slightly perverted version of LZW * According to VSDump, "it's a slightly perverted version of LZW
* compression, with inverted meaning of flag byte and 0xFEE as an * compression, with inverted meaning of flag byte and 0xFEE as an
* 'initial shift'". It uses 12 bit codes * 'initial shift'". It uses 12 bit codes
* (http://www.gnome.ru/projects/vsdump_en.html) * (http://www.gnome.ru/projects/vsdump_en.html)
* *
@ -36,7 +36,7 @@ import java.io.OutputStream;
public class HDGFLZW { public class HDGFLZW {
/** /**
* Given an integer, turn it into a java byte, handling * Given an integer, turn it into a java byte, handling
* the wrapping. * the wrapping.
* This is a convenience method * This is a convenience method
*/ */
@ -45,13 +45,15 @@ public static byte fromInt(int b) {
return (byte)(b - 256); return (byte)(b - 256);
} }
/** /**
* Given a java byte, turn it into an integer between 0 * Given a java byte, turn it into an integer between 0
* and 255 (i.e. handle the unwrapping). * and 255 (i.e. handle the unwrapping).
* This is a convenience method * This is a convenience method
*/ */
public static int fromByte(byte b) { public static int fromByte(byte b) {
if(b >= 0) return (int)b; if(b >= 0) {
return (int)(b + 256); return b;
}
return b + 256;
} }
/** /**
@ -113,7 +115,7 @@ public void decode(InputStream src, OutputStream res) throws IOException {
// It needs to be unsigned, so that bit stuff works // It needs to be unsigned, so that bit stuff works
int dataI; int dataI;
// The compressed code sequence is held over 2 bytes // The compressed code sequence is held over 2 bytes
int dataIPt1, dataIPt2; int dataIPt1, dataIPt2;
// How long a code sequence is, and where in the // How long a code sequence is, and where in the
// dictionary to start at // dictionary to start at
int len, pntr; int len, pntr;
@ -138,7 +140,7 @@ public void decode(InputStream src, OutputStream res) throws IOException {
dataIPt1 = src.read(); dataIPt1 = src.read();
dataIPt2 = src.read(); dataIPt2 = src.read();
if(dataIPt1 == -1 || dataIPt2 == -1) break; if(dataIPt1 == -1 || dataIPt2 == -1) break;
// Build up how long the code sequence is, and // Build up how long the code sequence is, and
// what position of the code to start at // what position of the code to start at
// (The position is the first 12 bits, the // (The position is the first 12 bits, the
@ -153,14 +155,14 @@ public void decode(InputStream src, OutputStream res) throws IOException {
} else { } else {
pntr = pntr + 18; pntr = pntr + 18;
} }
// Loop over the codes, outputting what they correspond to // Loop over the codes, outputting what they correspond to
for(int i=0; i<len; i++) { for(int i=0; i<len; i++) {
buffer [(pos + i) & 4095] = buffer [(pntr + i) & 4095]; buffer [(pos + i) & 4095] = buffer [(pntr + i) & 4095];
dataB = buffer[(pntr + i) & 4095]; dataB = buffer[(pntr + i) & 4095];
res.write(new byte[] {dataB}); res.write(new byte[] {dataB});
} }
// Record how far along the stream we have moved // Record how far along the stream we have moved
pos = pos + len; pos = pos + len;
} }
@ -183,14 +185,14 @@ public void compress(InputStream src, OutputStream res) throws IOException {
* Need our own class to handle keeping track of the * Need our own class to handle keeping track of the
* code buffer, pending bytes to write out etc. * code buffer, pending bytes to write out etc.
*/ */
private class Compressor { private static final class Compressor {
// We use 12 bit codes: // We use 12 bit codes:
// * 0-255 are real bytes // * 0-255 are real bytes
// * 256-4095 are the substring codes // * 256-4095 are the substring codes
// Java handily initialises our buffer / dictionary // Java handily initialises our buffer / dictionary
// to all zeros // to all zeros
byte[] dict = new byte[4096]; byte[] dict = new byte[4096];
// The next block of data to be written out, minus // The next block of data to be written out, minus
// its mask byte // its mask byte
byte[] buffer = new byte[16]; byte[] buffer = new byte[16];
@ -198,21 +200,24 @@ private class Compressor {
// (Un-compressed codes are 1 byte each, compressed codes // (Un-compressed codes are 1 byte each, compressed codes
// are two) // are two)
int bufferLen = 0; int bufferLen = 0;
// The raw length of a code is limited to 4 bits // The raw length of a code is limited to 4 bits
byte[] rawCode = new byte[16]; byte[] rawCode = new byte[16];
// And how much we're using // And how much we're using
int rawCodeLen = 0; int rawCodeLen = 0;
// How far through the input and output streams we are // How far through the input and output streams we are
int posInp = 0; int posInp = 0;
int posOut = 0; int posOut = 0;
// What the next mask byte to output will be // What the next mask byte to output will be
int nextMask = 0; int nextMask = 0;
// And how many bits we've already set // And how many bits we've already set
int maskBitsSet = 0; int maskBitsSet = 0;
public Compressor() {
//
}
/** /**
* Returns the last place that the bytes from rawCode are found * Returns the last place that the bytes from rawCode are found
* at in the buffer, or -1 if they can't be found * at in the buffer, or -1 if they can't be found
@ -230,7 +235,7 @@ private int findRawCodeInBuffer() {
matches = false; matches = false;
} }
} }
// Was this position a match? // Was this position a match?
if(matches) { if(matches) {
return i; return i;
@ -255,7 +260,7 @@ private void outputCompressed(OutputStream res) throws IOException {
} }
return; return;
} }
// Increment the mask bit count, we've done another code // Increment the mask bit count, we've done another code
maskBitsSet++; maskBitsSet++;
// Add the length+code to the buffer // Add the length+code to the buffer
@ -263,7 +268,7 @@ private void outputCompressed(OutputStream res) throws IOException {
// length is the last 4 bits) // length is the last 4 bits)
// TODO // TODO
posOut += 2; posOut += 2;
// If we're now at 8 codes, output // If we're now at 8 codes, output
if(maskBitsSet == 8) { if(maskBitsSet == 8) {
output8Codes(res); output8Codes(res);
@ -273,15 +278,15 @@ private void outputCompressed(OutputStream res) throws IOException {
* Output the un-compressed byte * Output the un-compressed byte
*/ */
private void outputUncompressed(byte b, OutputStream res) throws IOException { private void outputUncompressed(byte b, OutputStream res) throws IOException {
// Set the mask bit for us // Set the mask bit for us
nextMask += (1<<maskBitsSet); nextMask += (1<<maskBitsSet);
// And add us to the buffer + dictionary // And add us to the buffer + dictionary
buffer[bufferLen] = fromInt(b); buffer[bufferLen] = fromInt(b);
bufferLen++; bufferLen++;
dict[(posOut&4095)] = fromInt(b); dict[(posOut&4095)] = fromInt(b);
posOut++; posOut++;
// If we're now at 8 codes, output // If we're now at 8 codes, output
if(maskBitsSet == 8) { if(maskBitsSet == 8) {
output8Codes(res); output8Codes(res);
@ -296,20 +301,20 @@ private void output8Codes(OutputStream res) throws IOException {
// Output the mask and the data // Output the mask and the data
res.write(new byte[] { fromInt(nextMask) } ); res.write(new byte[] { fromInt(nextMask) } );
res.write(buffer, 0, bufferLen); res.write(buffer, 0, bufferLen);
// Reset things // Reset things
nextMask = 0; nextMask = 0;
maskBitsSet = 0; maskBitsSet = 0;
bufferLen = 0; bufferLen = 0;
} }
/** /**
* Does the compression * Does the compression
*/ */
private void compress(InputStream src, OutputStream res) throws IOException { private void compress(InputStream src, OutputStream res) throws IOException {
// Have we hit the end of the file yet? // Have we hit the end of the file yet?
boolean going = true; boolean going = true;
// This is a byte as looked up in the dictionary // This is a byte as looked up in the dictionary
// It needs to be signed, as it'll get passed on to // It needs to be signed, as it'll get passed on to
// the output stream // the output stream
@ -317,27 +322,27 @@ private void compress(InputStream src, OutputStream res) throws IOException {
// This is an unsigned byte read from the stream // This is an unsigned byte read from the stream
// It needs to be unsigned, so that bit stuff works // It needs to be unsigned, so that bit stuff works
int dataI; int dataI;
while( going ) { while( going ) {
dataI = src.read(); dataI = src.read();
posInp++; posInp++;
if(dataI == -1) { going = false; } if(dataI == -1) { going = false; }
dataB = fromInt(dataI); dataB = fromInt(dataI);
// If we've run out of data, output anything that's // If we've run out of data, output anything that's
// pending then finish // pending then finish
if(!going && rawCodeLen > 0) { if(!going && rawCodeLen > 0) {
outputCompressed(res); outputCompressed(res);
break; break;
} }
// Try adding this new byte onto rawCode, and // Try adding this new byte onto rawCode, and
// see if all of that is still found in the // see if all of that is still found in the
// buffer dictionary or not // buffer dictionary or not
rawCode[rawCodeLen] = dataB; rawCode[rawCodeLen] = dataB;
rawCodeLen++; rawCodeLen++;
int rawAt = findRawCodeInBuffer(); int rawAt = findRawCodeInBuffer();
// If we found it and are now at 16 bytes, // If we found it and are now at 16 bytes,
// we need to output our pending code block // we need to output our pending code block
if(rawCodeLen == 16 && rawAt > -1) { if(rawCodeLen == 16 && rawAt > -1) {
@ -345,24 +350,24 @@ private void compress(InputStream src, OutputStream res) throws IOException {
rawCodeLen = 0; rawCodeLen = 0;
continue; continue;
} }
// If we did find all of rawCode with our new // If we did find all of rawCode with our new
// byte added on, we can wait to see what happens // byte added on, we can wait to see what happens
// with the next byte // with the next byte
if(rawAt > -1) { if(rawAt > -1) {
continue; continue;
} }
// If we get here, then the rawCode + this byte weren't // If we get here, then the rawCode + this byte weren't
// found in the dictionary // found in the dictionary
// If there was something in rawCode before, then that was // If there was something in rawCode before, then that was
// found in the dictionary, so output that compressed // found in the dictionary, so output that compressed
rawCodeLen--; rawCodeLen--;
if(rawCodeLen > 0) { if(rawCodeLen > 0) {
// Output the old rawCode // Output the old rawCode
outputCompressed(res); outputCompressed(res);
// Can this byte start a new rawCode, or does // Can this byte start a new rawCode, or does
// it need outputting itself? // it need outputting itself?
rawCode[0] = dataB; rawCode[0] = dataB;
@ -385,4 +390,4 @@ private void compress(InputStream src, OutputStream res) throws IOException {
} }
} }
} }

View File

@ -51,11 +51,11 @@ public abstract class ChunkHeader {
} else if(documentVersion == 5 || documentVersion == 4) { } else if(documentVersion == 5 || documentVersion == 4) {
ChunkHeaderV4V5 ch = new ChunkHeaderV4V5(); ChunkHeaderV4V5 ch = new ChunkHeaderV4V5();
ch.type = (int)LittleEndian.getShort(data, offset + 0); ch.type = LittleEndian.getShort(data, offset + 0);
ch.id = (int)LittleEndian.getShort(data, offset + 2); ch.id = LittleEndian.getShort(data, offset + 2);
ch.unknown2 = (short)LittleEndian.getUnsignedByte(data, offset + 4); ch.unknown2 = (short)LittleEndian.getUnsignedByte(data, offset + 4);
ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 5); ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 5);
ch.unknown1 = (short)LittleEndian.getShort(data, offset + 6); ch.unknown1 = LittleEndian.getShort(data, offset + 6);
ch.length = (int)LittleEndian.getUInt(data, offset + 8); ch.length = (int)LittleEndian.getUInt(data, offset + 8);
return ch; return ch;

View File

@ -257,7 +257,7 @@ public final class HSLFSlideShow extends POIDocument {
Record[] rec = new Record[lst.size()]; Record[] rec = new Record[lst.size()];
for (int i = 0; i < a.length; i++) { for (int i = 0; i < a.length; i++) {
Integer offset = (Integer)a[i]; Integer offset = (Integer)a[i];
rec[i] = (Record)Record.buildRecordAtOffset(docstream, offset.intValue()); rec[i] = Record.buildRecordAtOffset(docstream, offset.intValue());
if(rec[i] instanceof PersistRecord) { if(rec[i] instanceof PersistRecord) {
PersistRecord psr = (PersistRecord)rec[i]; PersistRecord psr = (PersistRecord)rec[i];
Integer id = (Integer)offset2id.get(offset); Integer id = (Integer)offset2id.get(offset);

View File

@ -41,9 +41,7 @@ import org.apache.poi.util.LittleEndian;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class SlideShowDumper {
public final class SlideShowDumper
{
private InputStream istream; private InputStream istream;
private POIFSFileSystem filesystem; private POIFSFileSystem filesystem;
@ -196,7 +194,7 @@ public final class SlideShowDumper
} }
public String makeHex(short s) { public String makeHex(short s) {
String hex = Integer.toHexString((int)s).toUpperCase(); String hex = Integer.toHexString(s).toUpperCase();
if(hex.length() == 1) { return "0" + hex; } if(hex.length() == 1) { return "0" + hex; }
return hex; return hex;
} }
@ -232,7 +230,7 @@ public void walkTree(int depth, int startPos, int maxLen) {
System.out.println(ind + "That's a " + recordName); System.out.println(ind + "That's a " + recordName);
// Now check if it's a container or not // Now check if it's a container or not
int container = (int)opt & 0x0f; int container = opt & 0x0f;
// BinaryTagData seems to contain records, but it // BinaryTagData seems to contain records, but it
// isn't tagged as doing so. Try stepping in anyway // isn't tagged as doing so. Try stepping in anyway

View File

@ -53,9 +53,7 @@ import org.apache.poi.hslf.model.TextRun;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class QuickButCruddyTextExtractor {
public final class QuickButCruddyTextExtractor
{
private POIFSFileSystem fs; private POIFSFileSystem fs;
private InputStream is; private InputStream is;
private byte[] pptContents; private byte[] pptContents;
@ -169,7 +167,7 @@ public final class QuickButCruddyTextExtractor
// If it's a container, step into it and return // If it's a container, step into it and return
// (If it's a container, option byte 1 BINARY_AND 0x0f will be 0x0f) // (If it's a container, option byte 1 BINARY_AND 0x0f will be 0x0f)
int container = (int)opt & 0x0f; int container = opt & 0x0f;
if(container == 0x0f) { if(container == 0x0f) {
return (startPos+8); return (startPos+8);
} }

View File

@ -17,13 +17,22 @@
package org.apache.poi.hslf.model; package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*; import java.awt.geom.AffineTransform;
import org.apache.poi.util.LittleEndian; import java.awt.geom.GeneralPath;
import org.apache.poi.util.POILogger; import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.*; import java.awt.geom.Rectangle2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
/** /**
* A "Freeform" shape. * A "Freeform" shape.
@ -85,8 +94,8 @@ public final class Freeform extends AutoShape {
Rectangle2D bounds = path.getBounds2D(); Rectangle2D bounds = path.getBounds2D();
PathIterator it = path.getPathIterator(new AffineTransform()); PathIterator it = path.getPathIterator(new AffineTransform());
ArrayList segInfo = new ArrayList(); List<byte[]> segInfo = new ArrayList<byte[]>();
ArrayList pntInfo = new ArrayList(); List<Point2D.Double> pntInfo = new ArrayList<Point2D.Double>();
boolean isClosed = false; boolean isClosed = false;
while (!it.isDone()) { while (!it.isDone()) {
double[] vals = new double[6]; double[] vals = new double[6];
@ -135,7 +144,7 @@ public final class Freeform extends AutoShape {
verticesProp.setNumberOfElementsInMemory(pntInfo.size()); verticesProp.setNumberOfElementsInMemory(pntInfo.size());
verticesProp.setSizeOfElements(0xFFF0); verticesProp.setSizeOfElements(0xFFF0);
for (int i = 0; i < pntInfo.size(); i++) { for (int i = 0; i < pntInfo.size(); i++) {
Point2D.Double pnt = (Point2D.Double)pntInfo.get(i); Point2D.Double pnt = pntInfo.get(i);
byte[] data = new byte[4]; byte[] data = new byte[4];
LittleEndian.putShort(data, 0, (short)((pnt.getX() - bounds.getX())*MASTER_DPI/POINT_DPI)); LittleEndian.putShort(data, 0, (short)((pnt.getX() - bounds.getX())*MASTER_DPI/POINT_DPI));
LittleEndian.putShort(data, 2, (short)((pnt.getY() - bounds.getY())*MASTER_DPI/POINT_DPI)); LittleEndian.putShort(data, 2, (short)((pnt.getY() - bounds.getY())*MASTER_DPI/POINT_DPI));
@ -148,7 +157,7 @@ public final class Freeform extends AutoShape {
segmentsProp.setNumberOfElementsInMemory(segInfo.size()); segmentsProp.setNumberOfElementsInMemory(segInfo.size());
segmentsProp.setSizeOfElements(0x2); segmentsProp.setSizeOfElements(0x2);
for (int i = 0; i < segInfo.size(); i++) { for (int i = 0; i < segInfo.size(); i++) {
byte[] seg = (byte[])segInfo.get(i); byte[] seg = segInfo.get(i);
segmentsProp.setElement(i, seg); segmentsProp.setElement(i, seg);
} }
opt.addEscherProperty(segmentsProp); opt.addEscherProperty(segmentsProp);
@ -171,10 +180,10 @@ public final class Freeform extends AutoShape {
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
EscherArrayProperty verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000)); EscherArrayProperty verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000));
if(verticesProp == null) verticesProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES)); if(verticesProp == null) verticesProp = (EscherArrayProperty)getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);
EscherArrayProperty segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000)); EscherArrayProperty segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO + 0x4000));
if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO)); if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, EscherProperties.GEOMETRY__SEGMENTINFO);
//sanity check //sanity check
if(verticesProp == null) { if(verticesProp == null) {

View File

@ -58,7 +58,7 @@ public final class CString extends RecordAtom {
* The meaning of the count is specific to the type of the parent record * The meaning of the count is specific to the type of the parent record
*/ */
public int getOptions() { public int getOptions() {
return (int)LittleEndian.getShort(_header); return LittleEndian.getShort(_header);
} }
/** /**

View File

@ -30,9 +30,7 @@ import java.io.ByteArrayOutputStream;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class ColorSchemeAtom extends RecordAtom {
public final class ColorSchemeAtom extends RecordAtom
{
private byte[] _header; private byte[] _header;
private static long _type = 2032l; private static long _type = 2032l;
@ -108,14 +106,14 @@ public final class ColorSchemeAtom extends RecordAtom
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Grab the rgb values // Grab the rgb values
backgroundColourRGB = (int)LittleEndian.getInt(source,start+8+0); backgroundColourRGB = LittleEndian.getInt(source,start+8+0);
textAndLinesColourRGB = (int)LittleEndian.getInt(source,start+8+4); textAndLinesColourRGB = LittleEndian.getInt(source,start+8+4);
shadowsColourRGB = (int)LittleEndian.getInt(source,start+8+8); shadowsColourRGB = LittleEndian.getInt(source,start+8+8);
titleTextColourRGB = (int)LittleEndian.getInt(source,start+8+12); titleTextColourRGB = LittleEndian.getInt(source,start+8+12);
fillsColourRGB = (int)LittleEndian.getInt(source,start+8+16); fillsColourRGB = LittleEndian.getInt(source,start+8+16);
accentColourRGB = (int)LittleEndian.getInt(source,start+8+20); accentColourRGB = LittleEndian.getInt(source,start+8+20);
accentAndHyperlinkColourRGB = (int)LittleEndian.getInt(source,start+8+24); accentAndHyperlinkColourRGB = LittleEndian.getInt(source,start+8+24);
accentAndFollowingHyperlinkColourRGB = (int)LittleEndian.getInt(source,start+8+28); accentAndFollowingHyperlinkColourRGB = LittleEndian.getInt(source,start+8+28);
} }
/** /**
@ -181,7 +179,7 @@ public final class ColorSchemeAtom extends RecordAtom
byte[] with_zero = new byte[4]; byte[] with_zero = new byte[4];
System.arraycopy(rgb,0,with_zero,0,3); System.arraycopy(rgb,0,with_zero,0,3);
with_zero[3] = 0; with_zero[3] = 0;
int ret = (int)LittleEndian.getInt(with_zero,0); int ret = LittleEndian.getInt(with_zero,0);
return ret; return ret;
} }
@ -205,16 +203,15 @@ public final class ColorSchemeAtom extends RecordAtom
writeLittleEndian(accentAndFollowingHyperlinkColourRGB,out); writeLittleEndian(accentAndFollowingHyperlinkColourRGB,out);
} }
/** /**
* Returns color by its index * Returns color by its index
* *
* @param idx 0-based color index * @param idx 0-based color index
* @return color by its index * @return color by its index
*/ */
public int getColor(int idx){ public int getColor(int idx){
int[] clr = {backgroundColourRGB, textAndLinesColourRGB, shadowsColourRGB, titleTextColourRGB, int[] clr = {backgroundColourRGB, textAndLinesColourRGB, shadowsColourRGB, titleTextColourRGB,
fillsColourRGB, accentColourRGB, accentAndHyperlinkColourRGB, accentAndFollowingHyperlinkColourRGB}; fillsColourRGB, accentColourRGB, accentAndHyperlinkColourRGB, accentAndFollowingHyperlinkColourRGB};
return clr[idx]; return clr[idx];
} }
} }

View File

@ -80,16 +80,23 @@ public final class DocumentAtom extends RecordAtom
/** Was the document saved with True Type fonts embeded? */ /** Was the document saved with True Type fonts embeded? */
public boolean getSaveWithFonts() { public boolean getSaveWithFonts() {
if(saveWithFonts == 0) { return false; } else { return true; } } return saveWithFonts != 0;
}
/** Have the placeholders on the title slide been omitted? */ /** Have the placeholders on the title slide been omitted? */
public boolean getOmitTitlePlace() { public boolean getOmitTitlePlace() {
if(omitTitlePlace == 0) { return false; } else { return true; } } return omitTitlePlace != 0;
}
/** Is this a Bi-Directional PPT Doc? */ /** Is this a Bi-Directional PPT Doc? */
public boolean getRightToLeft() { public boolean getRightToLeft() {
if(rightToLeft == 0) { return false; } else { return true; } } return rightToLeft != 0;
}
/** Are comment shapes visible? */ /** Are comment shapes visible? */
public boolean getShowComments() { public boolean getShowComments() {
if(showComments == 0) { return false; } else { return true; } } return showComments != 0;
}
/* *************** record code follows ********************** */ /* *************** record code follows ********************** */
@ -118,10 +125,10 @@ public final class DocumentAtom extends RecordAtom
handoutMasterPersist = LittleEndian.getInt(source,start+28+8); handoutMasterPersist = LittleEndian.getInt(source,start+28+8);
// Get the ID of the first slide // Get the ID of the first slide
firstSlideNum = (int)LittleEndian.getShort(source,start+32+8); firstSlideNum = LittleEndian.getShort(source,start+32+8);
// Get the slide size type // Get the slide size type
slideSizeType = (int)LittleEndian.getShort(source,start+34+8); slideSizeType = LittleEndian.getShort(source,start+34+8);
// Get the booleans as bytes // Get the booleans as bytes
saveWithFonts = source[start+36+8]; saveWithFonts = source[start+36+8];

View File

@ -32,12 +32,10 @@ import java.io.ByteArrayOutputStream;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class EscherTextboxWrapper extends RecordContainer {
public final class EscherTextboxWrapper extends RecordContainer
{
private EscherTextboxRecord _escherRecord; private EscherTextboxRecord _escherRecord;
private long _type; private long _type;
private int shapeId; private int shapeId;
/** /**
* Returns the underlying DDF Escher Record * Returns the underlying DDF Escher Record
@ -49,7 +47,7 @@ public final class EscherTextboxWrapper extends RecordContainer
*/ */
public EscherTextboxWrapper(EscherTextboxRecord textbox) { public EscherTextboxWrapper(EscherTextboxRecord textbox) {
_escherRecord = textbox; _escherRecord = textbox;
_type = (long)_escherRecord.getRecordId(); _type = _escherRecord.getRecordId();
// Find the child records in the escher data // Find the child records in the escher data
byte[] data = _escherRecord.getData(); byte[] data = _escherRecord.getData();
@ -93,17 +91,17 @@ public final class EscherTextboxWrapper extends RecordContainer
_escherRecord.setData(data); _escherRecord.setData(data);
} }
/** /**
* @return Shape ID * @return Shape ID
*/ */
public int getShapeId(){ public int getShapeId(){
return shapeId; return shapeId;
} }
/** /**
* @param id Shape ID * @param id Shape ID
*/ */
public void setShapeId(int id){ public void setShapeId(int id){
shapeId = id; shapeId = id;
} }
} }

View File

@ -65,7 +65,7 @@ public final class NotesAtom extends RecordAtom
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Get the slide ID // Get the slide ID
slideID = (int)LittleEndian.getInt(source,start+8); slideID = LittleEndian.getInt(source,start+8);
// Grok the flags, stored as bits // Grok the flags, stored as bits
int flags = LittleEndian.getUShort(source,start+12); int flags = LittleEndian.getUShort(source,start+12);

View File

@ -86,8 +86,8 @@ public final class SlideAtom extends RecordAtom
layoutAtom = new SSlideLayoutAtom(SSlideLayoutAtomData); layoutAtom = new SSlideLayoutAtom(SSlideLayoutAtomData);
// Get the IDs of the master and notes // Get the IDs of the master and notes
masterID = (int)LittleEndian.getInt(source,start+12+8); masterID = LittleEndian.getInt(source,start+12+8);
notesID = (int)LittleEndian.getInt(source,start+16+8); notesID = LittleEndian.getInt(source,start+16+8);
// Grok the flags, stored as bits // Grok the flags, stored as bits
int flags = LittleEndian.getUShort(source,start+20+8); int flags = LittleEndian.getUShort(source,start+20+8);
@ -214,7 +214,7 @@ public final class SlideAtom extends RecordAtom
} }
// Grab out our data // Grab out our data
geometry = (int)LittleEndian.getInt(data,0); geometry = LittleEndian.getInt(data,0);
placeholderIDs = new byte[8]; placeholderIDs = new byte[8];
System.arraycopy(data,4,placeholderIDs,0,8); System.arraycopy(data,4,placeholderIDs,0,8);
} }

View File

@ -27,9 +27,7 @@ import java.io.OutputStream;
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class SlidePersistAtom extends RecordAtom {
public final class SlidePersistAtom extends RecordAtom
{
private byte[] _header; private byte[] _header;
private static long _type = 1011l; private static long _type = 1011l;
@ -76,10 +74,10 @@ public final class SlidePersistAtom extends RecordAtom
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Grab the reference ID // Grab the reference ID
refID = (int)LittleEndian.getInt(source,start+8); refID = LittleEndian.getInt(source,start+8);
// Next up is a set of flags, but only bit 3 is used! // Next up is a set of flags, but only bit 3 is used!
int flags = (int)LittleEndian.getInt(source,start+12); int flags = LittleEndian.getInt(source,start+12);
if(flags == 4) { if(flags == 4) {
hasShapesOtherThanPlaceholders = true; hasShapesOtherThanPlaceholders = true;
} else { } else {
@ -87,10 +85,10 @@ public final class SlidePersistAtom extends RecordAtom
} }
// Now the number of Placeholder Texts // Now the number of Placeholder Texts
numPlaceholderTexts = (int)LittleEndian.getInt(source,start+16); numPlaceholderTexts = LittleEndian.getInt(source,start+16);
// Last useful one is the unique slide identifier // Last useful one is the unique slide identifier
slideIdentifier = (int)LittleEndian.getInt(source,start+20); slideIdentifier = LittleEndian.getInt(source,start+20);
// Finally you have typically 4 or 8 bytes of reserved fields, // Finally you have typically 4 or 8 bytes of reserved fields,
// all zero running from 24 bytes in to the end // all zero running from 24 bytes in to the end

View File

@ -72,7 +72,7 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Grab the type // Grab the type
textType = (int)LittleEndian.getInt(source,start+8); textType = LittleEndian.getInt(source,start+8);
} }
/** /**

View File

@ -82,30 +82,30 @@ public final class UserEditAtom extends PositionDependentRecordAtom
System.arraycopy(source,start,_header,0,8); System.arraycopy(source,start,_header,0,8);
// Get the last viewed slide ID // Get the last viewed slide ID
lastViewedSlideID = (int)LittleEndian.getInt(source,start+0+8); lastViewedSlideID = LittleEndian.getInt(source,start+0+8);
// Get the PPT version // Get the PPT version
pptVersion = (int)LittleEndian.getInt(source,start+4+8); pptVersion = LittleEndian.getInt(source,start+4+8);
// Get the offset to the previous incremental save's UserEditAtom // Get the offset to the previous incremental save's UserEditAtom
// This will be the byte offset on disk where the previous one // This will be the byte offset on disk where the previous one
// starts, or 0 if this is the first one // starts, or 0 if this is the first one
lastUserEditAtomOffset = (int)LittleEndian.getInt(source,start+8+8); lastUserEditAtomOffset = LittleEndian.getInt(source,start+8+8);
// Get the offset to the persist pointers // Get the offset to the persist pointers
// This will be the byte offset on disk where the preceding // This will be the byte offset on disk where the preceding
// PersistPtrFullBlock or PersistPtrIncrementalBlock starts // PersistPtrFullBlock or PersistPtrIncrementalBlock starts
persistPointersOffset = (int)LittleEndian.getInt(source,start+12+8); persistPointersOffset = LittleEndian.getInt(source,start+12+8);
// Get the persist reference for the document persist object // Get the persist reference for the document persist object
// Normally seems to be 1 // Normally seems to be 1
docPersistRef = (int)LittleEndian.getInt(source,start+16+8); docPersistRef = LittleEndian.getInt(source,start+16+8);
// Maximum number of persist objects written // Maximum number of persist objects written
maxPersistWritten = (int)LittleEndian.getInt(source,start+20+8); maxPersistWritten = LittleEndian.getInt(source,start+20+8);
// Last view type // Last view type
lastViewType = (short)LittleEndian.getShort(source,start+24+8); lastViewType = LittleEndian.getShort(source,start+24+8);
// There might be a few more bytes, which are a reserved field // There might be a few more bytes, which are a reserved field
reserved = new byte[len-26-8]; reserved = new byte[len-26-8];

View File

@ -42,17 +42,13 @@ import org.apache.poi.poifs.property.DocumentProperty;
import org.apache.poi.poifs.storage.BlockWritable; import org.apache.poi.poifs.storage.BlockWritable;
/** /**
* Provides a HashMap with the ability to parse a PIOFS object and provide * Provides a HashMap with the ability to parse a PIOFS object and provide
* an 'easy to access' hashmap structure for the document chunks inside it. * an 'easy to access' hashmap structure for the document chunks inside it.
* *
* @author Travis Ferguson * @author Travis Ferguson
*/ */
public class POIFSChunkParser { public final class POIFSChunkParser {
/**
* Constructor
* @param fs
* @throws IOException
*/
public POIFSChunkParser(POIFSFileSystem fs) throws IOException { public POIFSChunkParser(POIFSFileSystem fs) throws IOException {
this.setFileSystem(fs); this.setFileSystem(fs);
} }
@ -61,7 +57,6 @@ public class POIFSChunkParser {
/** /**
* Set the POIFileSystem object that this object is using. * Set the POIFileSystem object that this object is using.
* @param fs * @param fs
* @throws IOException
*/ */
public void setFileSystem(POIFSFileSystem fs) throws IOException { public void setFileSystem(POIFSFileSystem fs) throws IOException {
this.fs = fs; this.fs = fs;
@ -77,33 +72,32 @@ public class POIFSChunkParser {
/** /**
* Reparse the FileSystem object, resetting all the chunks stored in this object * Reparse the FileSystem object, resetting all the chunks stored in this object
* @throws IOException
* *
*/ */
public void reparseFileSystem() throws IOException { public void reparseFileSystem() throws IOException {
// first clear this object of all chunks // first clear this object of all chunks
DirectoryEntry root = this.fs.getRoot(); DirectoryEntry root = this.fs.getRoot();
Iterator iter = root.getEntries(); Iterator iter = root.getEntries();
this.directoryMap = this.processPOIIterator(iter); this.directoryMap = this.processPOIIterator(iter);
} }
/** /**
* Returns a list of the standard chunk types, as * Returns a list of the standard chunk types, as
* appropriate for the chunks we find in the file. * appropriate for the chunks we find in the file.
*/ */
public Chunks identifyChunks() { public Chunks identifyChunks() {
return Chunks.getInstance(this.isNewChunkVersion(this.directoryMap)); return Chunks.getInstance(this.isNewChunkVersion(this.directoryMap));
} }
/** /**
* Returns a list of the standard chunk types, as * Returns a list of the standard chunk types, as
* appropriate for the chunks we find in the file attachment. * appropriate for the chunks we find in the file attachment.
*/ */
private AttachmentChunks identifyAttachmentChunks(Map attachmentMap) { private AttachmentChunks identifyAttachmentChunks(Map attachmentMap) {
return AttachmentChunks.getInstance(this.isNewChunkVersion(attachmentMap)); return AttachmentChunks.getInstance(this.isNewChunkVersion(attachmentMap));
} }
/** /**
* Return chunk version of the map in parameter * Return chunk version of the map in parameter
*/ */
@ -113,10 +107,10 @@ public class POIFSChunkParser {
boolean hasNewStrings = false; boolean hasNewStrings = false;
String oldStringEnd = Types.asFileEnding(Types.OLD_STRING); String oldStringEnd = Types.asFileEnding(Types.OLD_STRING);
String newStringEnd = Types.asFileEnding(Types.NEW_STRING); String newStringEnd = Types.asFileEnding(Types.NEW_STRING);
for(Iterator i = map.keySet().iterator(); i.hasNext();) { for(Iterator i = map.keySet().iterator(); i.hasNext();) {
String entry = (String)i.next(); String entry = (String)i.next();
if(entry.endsWith( oldStringEnd )) { if(entry.endsWith( oldStringEnd )) {
hasOldStrings = true; hasOldStrings = true;
} }
@ -124,7 +118,7 @@ public class POIFSChunkParser {
hasNewStrings = true; hasNewStrings = true;
} }
} }
if(hasOldStrings && hasNewStrings) { if(hasOldStrings && hasNewStrings) {
throw new IllegalStateException("Your file contains string chunks of both the old and new types. Giving up"); throw new IllegalStateException("Your file contains string chunks of both the old and new types. Giving up");
} else if(hasNewStrings) { } else if(hasNewStrings) {
@ -132,18 +126,18 @@ public class POIFSChunkParser {
} }
return false; return false;
} }
/** /**
* Pull the chunk data that's stored in this object's hashmap out and return it as a HashMap. * Pull the chunk data that's stored in this object's hashmap out and return it as a HashMap.
* @param entryName * @param entryName
*/ */
public Object getChunk(HashMap dirMap, String entryName) { public Object getChunk(HashMap dirMap, String entryName) {
if(dirMap == null) return null; if(dirMap == null) {
else { return null;
return dirMap.get(entryName);
} }
return dirMap.get(entryName);
} }
/** /**
* Pull a directory/hashmap out of this hashmap and return it * Pull a directory/hashmap out of this hashmap and return it
* @param directoryName * @param directoryName
@ -155,14 +149,14 @@ public class POIFSChunkParser {
DirectoryChunkNotFoundException excep = new DirectoryChunkNotFoundException(directoryName); DirectoryChunkNotFoundException excep = new DirectoryChunkNotFoundException(directoryName);
Object obj = getChunk(this.directoryMap, directoryName); Object obj = getChunk(this.directoryMap, directoryName);
if(obj == null || !(obj instanceof HashMap)) throw excep; if(obj == null || !(obj instanceof HashMap)) throw excep;
return (HashMap)obj; return (HashMap)obj;
} }
/** /**
* Pulls a ByteArrayOutputStream from this objects HashMap, this can be used to read a byte array of the contents of the given chunk. * Pulls a ByteArrayOutputStream from this objects HashMap, this can be used to read a byte array of the contents of the given chunk.
* @param dirNode * @param dirNode
* @param chunk * @param chunk
* @throws ChunkNotFoundException * @throws ChunkNotFoundException
*/ */
public Chunk getDocumentNode(HashMap dirNode, Chunk chunk) throws ChunkNotFoundException { public Chunk getDocumentNode(HashMap dirNode, Chunk chunk) throws ChunkNotFoundException {
@ -170,12 +164,12 @@ public class POIFSChunkParser {
ChunkNotFoundException excep = new ChunkNotFoundException(entryName); ChunkNotFoundException excep = new ChunkNotFoundException(entryName);
Object obj = getChunk(dirNode, entryName); Object obj = getChunk(dirNode, entryName);
if(obj == null || !(obj instanceof ByteArrayOutputStream)) throw excep; if(obj == null || !(obj instanceof ByteArrayOutputStream)) throw excep;
chunk.setValue((ByteArrayOutputStream)obj); chunk.setValue((ByteArrayOutputStream)obj);
return chunk; return chunk;
} }
/** /**
* Pulls a Chunk out of this objects root Node tree. * Pulls a Chunk out of this objects root Node tree.
* @param chunk * @param chunk
@ -184,9 +178,9 @@ public class POIFSChunkParser {
public Chunk getDocumentNode(Chunk chunk) throws ChunkNotFoundException { public Chunk getDocumentNode(Chunk chunk) throws ChunkNotFoundException {
return getDocumentNode(this.directoryMap, chunk); return getDocumentNode(this.directoryMap, chunk);
} }
/** /**
* *
* @return a map containing attachment name (String) and data (ByteArrayInputStream) * @return a map containing attachment name (String) and data (ByteArrayInputStream)
*/ */
public Map getAttachmentList() { public Map getAttachmentList() {
@ -194,12 +188,12 @@ public class POIFSChunkParser {
List attachmentList = new ArrayList(); List attachmentList = new ArrayList();
for(Iterator i = directoryMap.keySet().iterator(); i.hasNext();) { for(Iterator i = directoryMap.keySet().iterator(); i.hasNext();) {
String entry = (String)i.next(); String entry = (String)i.next();
if(entry.startsWith(AttachmentChunks.namePrefix)) { if(entry.startsWith(AttachmentChunks.namePrefix)) {
String attachmentIdString = entry.replace(AttachmentChunks.namePrefix, ""); String attachmentIdString = entry.replace(AttachmentChunks.namePrefix, "");
try { try {
int attachmentId = Integer.parseInt(attachmentIdString); int attachmentId = Integer.parseInt(attachmentIdString);
attachmentList.add((HashMap)directoryMap.get(entry)); attachmentList.add(directoryMap.get(entry));
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
System.err.println("Invalid attachment id"); System.err.println("Invalid attachment id");
} }
@ -218,7 +212,7 @@ public class POIFSChunkParser {
} }
return attachments; return attachments;
} }
/** /**
* Processes an iterator returned by a POIFS call to getRoot().getEntries() * Processes an iterator returned by a POIFS call to getRoot().getEntries()
* @param iter * @param iter
@ -226,85 +220,85 @@ public class POIFSChunkParser {
* @throws IOException * @throws IOException
*/ */
private HashMap processPOIIterator(Iterator iter) throws IOException { private HashMap processPOIIterator(Iterator iter) throws IOException {
HashMap currentNode = new HashMap(); HashMap currentNode = new HashMap();
while(iter.hasNext()) {
Object obj = iter.next();
if(obj instanceof DocumentNode) {
this.processDocumentNode((DocumentNode)obj, currentNode);
} else if(obj instanceof DirectoryNode) {
String blockName = ((DirectoryNode)obj).getName();
Iterator viewIt = null;
if( ((DirectoryNode)obj).preferArray()) {
Object[] arr = ((DirectoryNode)obj).getViewableArray();
ArrayList viewList = new ArrayList(arr.length);
for(int i = 0; i < arr.length; i++) { while(iter.hasNext()) {
viewList.add(arr[i]); Object obj = iter.next();
} if(obj instanceof DocumentNode) {
viewIt = viewList.iterator(); this.processDocumentNode((DocumentNode)obj, currentNode);
} else { } else if(obj instanceof DirectoryNode) {
viewIt = ((DirectoryNode)obj).getViewableIterator(); String blockName = ((DirectoryNode)obj).getName();
} Iterator viewIt = null;
//store the next node on the hashmap if( ((DirectoryNode)obj).preferArray()) {
currentNode.put(blockName, processPOIIterator(viewIt)); Object[] arr = ((DirectoryNode)obj).getViewableArray();
} else if(obj instanceof DirectoryProperty) { ArrayList viewList = new ArrayList(arr.length);
//don't do anything with the directory property chunk...
} else { for(int i = 0; i < arr.length; i++) {
System.err.println("Unknown node: " + obj.toString()); viewList.add(arr[i]);
} }
} viewIt = viewList.iterator();
return currentNode; } else {
} viewIt = ((DirectoryNode)obj).getViewableIterator();
}
//store the next node on the hashmap
currentNode.put(blockName, processPOIIterator(viewIt));
} else if(obj instanceof DirectoryProperty) {
//don't do anything with the directory property chunk...
} else {
System.err.println("Unknown node: " + obj.toString());
}
}
return currentNode;
}
/** /**
* Processes a document node and adds it to the current directory HashMap * Processes a document node and adds it to the current directory HashMap
* @param obj * @param obj
* @throws java.io.IOException * @throws java.io.IOException
*/ */
private void processDocumentNode(DocumentNode obj, HashMap currentObj) throws IOException { private void processDocumentNode(DocumentNode obj, HashMap currentObj) throws IOException {
String blockName = ((DocumentNode)obj).getName(); String blockName = obj.getName();
Iterator viewIt = null;
if( ((DocumentNode)obj).preferArray()) {
Object[] arr = ((DocumentNode)obj).getViewableArray();
ArrayList viewList = new ArrayList(arr.length);
for(int i = 0; i < arr.length; i++) { Iterator viewIt = null;
viewList.add(arr[i]); if( obj.preferArray()) {
} Object[] arr = obj.getViewableArray();
viewIt = viewList.iterator(); ArrayList viewList = new ArrayList(arr.length);
} else {
viewIt = ((DocumentNode)obj).getViewableIterator();
}
while(viewIt.hasNext()) { for(int i = 0; i < arr.length; i++) {
Object view = viewIt.next(); viewList.add(arr[i]);
}
viewIt = viewList.iterator();
} else {
viewIt = obj.getViewableIterator();
}
if(view instanceof DocumentProperty) { while(viewIt.hasNext()) {
//we don't care about the properties Object view = viewIt.next();
} else if(view instanceof POIFSDocument) {
//check if our node has blocks or if it can just be read raw. if(view instanceof DocumentProperty) {
int blockCount = ((POIFSDocument)view).countBlocks(); //we don't care about the properties
//System.out.println("Block Name: " + blockName); } else if(view instanceof POIFSDocument) {
if(blockCount <= 0) { //check if our node has blocks or if it can just be read raw.
ByteArrayOutputStream out = new ByteArrayOutputStream(); int blockCount = ((POIFSDocument)view).countBlocks();
//System.out.println("Block Name: " + blockName);
BlockWritable[] bws = ((POIFSDocument)view).getSmallBlocks(); if(blockCount <= 0) {
for(int i = 0; i < bws.length; i++) { ByteArrayOutputStream out = new ByteArrayOutputStream();
bws[i].writeBlocks(out);
} BlockWritable[] bws = ((POIFSDocument)view).getSmallBlocks();
currentObj.put(blockName, out); for(int i = 0; i < bws.length; i++) {
} else { bws[i].writeBlocks(out);
ByteArrayOutputStream out = new ByteArrayOutputStream(); }
((POIFSDocument)view).writeBlocks(out); currentObj.put(blockName, out);
currentObj.put(blockName, out); } else {
} ByteArrayOutputStream out = new ByteArrayOutputStream();
} else { ((POIFSDocument)view).writeBlocks(out);
System.err.println("Unknown View Type: " + view.toString()); currentObj.put(blockName, out);
} }
} } else {
} System.err.println("Unknown View Type: " + view.toString());
}
}
}
/* private instance variables */ /* private instance variables */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -133,7 +133,7 @@ public final class ListData
int resetListID() int resetListID()
{ {
_lsid = (int)(Math.random() * (double)System.currentTimeMillis()); _lsid = (int)(Math.random() * System.currentTimeMillis());
return _lsid; return _lsid;
} }

View File

@ -225,21 +225,19 @@ public final class StyleSheet implements HDFType {
{ {
parentPAP = _styleDescriptions[baseIndex].getPAP(); parentPAP = _styleDescriptions[baseIndex].getPAP();
if(parentPAP == null) if(parentPAP == null) {
{ if(baseIndex == istd) {
if(baseIndex == istd) { // Oh dear, style claims that it is its own parent
// Oh dear, style claims that it is its own parent throw new IllegalStateException("Pap style " + istd + " claimed to have itself as its parent, which isn't allowed");
throw new IllegalStateException("Pap style " + istd + " claimed to have itself as its parent, which isn't allowed"); }
} else { // Create the parent style
// Create the parent style createPap(baseIndex);
createPap(baseIndex); parentPAP = _styleDescriptions[baseIndex].getPAP();
parentPAP = _styleDescriptions[baseIndex].getPAP();
}
} }
} }
pap = (ParagraphProperties)ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2); pap = ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2);
sd.setPAP(pap); sd.setPAP(pap);
} }
} }
@ -274,7 +272,7 @@ public final class StyleSheet implements HDFType {
} }
chp = (CharacterProperties)CharacterSprmUncompressor.uncompressCHP(parentCHP, chpx, 0); chp = CharacterSprmUncompressor.uncompressCHP(parentCHP, chpx, 0);
sd.setCHP(chp); sd.setCHP(chp);
} }
} }

View File

@ -818,9 +818,7 @@ public abstract class CHPAbstractType
*/ */
public void setFBold(boolean value) public void setFBold(boolean value)
{ {
field_2_format_flags = (int)fBold.setBoolean(field_2_format_flags, value); field_2_format_flags = fBold.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -830,7 +828,6 @@ public abstract class CHPAbstractType
public boolean isFBold() public boolean isFBold()
{ {
return fBold.isSet(field_2_format_flags); return fBold.isSet(field_2_format_flags);
} }
/** /**
@ -839,9 +836,7 @@ public abstract class CHPAbstractType
*/ */
public void setFItalic(boolean value) public void setFItalic(boolean value)
{ {
field_2_format_flags = (int)fItalic.setBoolean(field_2_format_flags, value); field_2_format_flags = fItalic.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -851,7 +846,6 @@ public abstract class CHPAbstractType
public boolean isFItalic() public boolean isFItalic()
{ {
return fItalic.isSet(field_2_format_flags); return fItalic.isSet(field_2_format_flags);
} }
/** /**
@ -860,9 +854,7 @@ public abstract class CHPAbstractType
*/ */
public void setFRMarkDel(boolean value) public void setFRMarkDel(boolean value)
{ {
field_2_format_flags = (int)fRMarkDel.setBoolean(field_2_format_flags, value); field_2_format_flags = fRMarkDel.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -872,7 +864,6 @@ public abstract class CHPAbstractType
public boolean isFRMarkDel() public boolean isFRMarkDel()
{ {
return fRMarkDel.isSet(field_2_format_flags); return fRMarkDel.isSet(field_2_format_flags);
} }
/** /**
@ -881,9 +872,7 @@ public abstract class CHPAbstractType
*/ */
public void setFOutline(boolean value) public void setFOutline(boolean value)
{ {
field_2_format_flags = (int)fOutline.setBoolean(field_2_format_flags, value); field_2_format_flags = fOutline.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -893,7 +882,6 @@ public abstract class CHPAbstractType
public boolean isFOutline() public boolean isFOutline()
{ {
return fOutline.isSet(field_2_format_flags); return fOutline.isSet(field_2_format_flags);
} }
/** /**
@ -902,9 +890,7 @@ public abstract class CHPAbstractType
*/ */
public void setFFldVanish(boolean value) public void setFFldVanish(boolean value)
{ {
field_2_format_flags = (int)fFldVanish.setBoolean(field_2_format_flags, value); field_2_format_flags = fFldVanish.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -914,7 +900,6 @@ public abstract class CHPAbstractType
public boolean isFFldVanish() public boolean isFFldVanish()
{ {
return fFldVanish.isSet(field_2_format_flags); return fFldVanish.isSet(field_2_format_flags);
} }
/** /**
@ -923,9 +908,7 @@ public abstract class CHPAbstractType
*/ */
public void setFSmallCaps(boolean value) public void setFSmallCaps(boolean value)
{ {
field_2_format_flags = (int)fSmallCaps.setBoolean(field_2_format_flags, value); field_2_format_flags = fSmallCaps.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -935,7 +918,6 @@ public abstract class CHPAbstractType
public boolean isFSmallCaps() public boolean isFSmallCaps()
{ {
return fSmallCaps.isSet(field_2_format_flags); return fSmallCaps.isSet(field_2_format_flags);
} }
/** /**
@ -944,9 +926,7 @@ public abstract class CHPAbstractType
*/ */
public void setFCaps(boolean value) public void setFCaps(boolean value)
{ {
field_2_format_flags = (int)fCaps.setBoolean(field_2_format_flags, value); field_2_format_flags = fCaps.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -956,7 +936,6 @@ public abstract class CHPAbstractType
public boolean isFCaps() public boolean isFCaps()
{ {
return fCaps.isSet(field_2_format_flags); return fCaps.isSet(field_2_format_flags);
} }
/** /**
@ -965,9 +944,7 @@ public abstract class CHPAbstractType
*/ */
public void setFVanish(boolean value) public void setFVanish(boolean value)
{ {
field_2_format_flags = (int)fVanish.setBoolean(field_2_format_flags, value); field_2_format_flags = fVanish.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -977,7 +954,6 @@ public abstract class CHPAbstractType
public boolean isFVanish() public boolean isFVanish()
{ {
return fVanish.isSet(field_2_format_flags); return fVanish.isSet(field_2_format_flags);
} }
/** /**
@ -986,9 +962,7 @@ public abstract class CHPAbstractType
*/ */
public void setFRMark(boolean value) public void setFRMark(boolean value)
{ {
field_2_format_flags = (int)fRMark.setBoolean(field_2_format_flags, value); field_2_format_flags = fRMark.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -998,7 +972,6 @@ public abstract class CHPAbstractType
public boolean isFRMark() public boolean isFRMark()
{ {
return fRMark.isSet(field_2_format_flags); return fRMark.isSet(field_2_format_flags);
} }
/** /**
@ -1007,9 +980,7 @@ public abstract class CHPAbstractType
*/ */
public void setFSpec(boolean value) public void setFSpec(boolean value)
{ {
field_2_format_flags = (int)fSpec.setBoolean(field_2_format_flags, value); field_2_format_flags = fSpec.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1019,7 +990,6 @@ public abstract class CHPAbstractType
public boolean isFSpec() public boolean isFSpec()
{ {
return fSpec.isSet(field_2_format_flags); return fSpec.isSet(field_2_format_flags);
} }
/** /**
@ -1028,9 +998,7 @@ public abstract class CHPAbstractType
*/ */
public void setFStrike(boolean value) public void setFStrike(boolean value)
{ {
field_2_format_flags = (int)fStrike.setBoolean(field_2_format_flags, value); field_2_format_flags = fStrike.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1040,7 +1008,6 @@ public abstract class CHPAbstractType
public boolean isFStrike() public boolean isFStrike()
{ {
return fStrike.isSet(field_2_format_flags); return fStrike.isSet(field_2_format_flags);
} }
/** /**
@ -1049,9 +1016,7 @@ public abstract class CHPAbstractType
*/ */
public void setFObj(boolean value) public void setFObj(boolean value)
{ {
field_2_format_flags = (int)fObj.setBoolean(field_2_format_flags, value); field_2_format_flags = fObj.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1061,7 +1026,6 @@ public abstract class CHPAbstractType
public boolean isFObj() public boolean isFObj()
{ {
return fObj.isSet(field_2_format_flags); return fObj.isSet(field_2_format_flags);
} }
/** /**
@ -1070,9 +1034,7 @@ public abstract class CHPAbstractType
*/ */
public void setFShadow(boolean value) public void setFShadow(boolean value)
{ {
field_2_format_flags = (int)fShadow.setBoolean(field_2_format_flags, value); field_2_format_flags = fShadow.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1082,7 +1044,6 @@ public abstract class CHPAbstractType
public boolean isFShadow() public boolean isFShadow()
{ {
return fShadow.isSet(field_2_format_flags); return fShadow.isSet(field_2_format_flags);
} }
/** /**
@ -1091,9 +1052,7 @@ public abstract class CHPAbstractType
*/ */
public void setFLowerCase(boolean value) public void setFLowerCase(boolean value)
{ {
field_2_format_flags = (int)fLowerCase.setBoolean(field_2_format_flags, value); field_2_format_flags = fLowerCase.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1103,7 +1062,6 @@ public abstract class CHPAbstractType
public boolean isFLowerCase() public boolean isFLowerCase()
{ {
return fLowerCase.isSet(field_2_format_flags); return fLowerCase.isSet(field_2_format_flags);
} }
/** /**
@ -1112,9 +1070,7 @@ public abstract class CHPAbstractType
*/ */
public void setFData(boolean value) public void setFData(boolean value)
{ {
field_2_format_flags = (int)fData.setBoolean(field_2_format_flags, value); field_2_format_flags = fData.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1124,7 +1080,6 @@ public abstract class CHPAbstractType
public boolean isFData() public boolean isFData()
{ {
return fData.isSet(field_2_format_flags); return fData.isSet(field_2_format_flags);
} }
/** /**
@ -1133,9 +1088,7 @@ public abstract class CHPAbstractType
*/ */
public void setFOle2(boolean value) public void setFOle2(boolean value)
{ {
field_2_format_flags = (int)fOle2.setBoolean(field_2_format_flags, value); field_2_format_flags = fOle2.setBoolean(field_2_format_flags, value);
} }
/** /**
@ -1145,7 +1098,6 @@ public abstract class CHPAbstractType
public boolean isFOle2() public boolean isFOle2()
{ {
return fOle2.isSet(field_2_format_flags); return fOle2.isSet(field_2_format_flags);
} }
/** /**
@ -1154,9 +1106,7 @@ public abstract class CHPAbstractType
*/ */
public void setFEmboss(boolean value) public void setFEmboss(boolean value)
{ {
field_3_format_flags1 = (int)fEmboss.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fEmboss.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1166,7 +1116,6 @@ public abstract class CHPAbstractType
public boolean isFEmboss() public boolean isFEmboss()
{ {
return fEmboss.isSet(field_3_format_flags1); return fEmboss.isSet(field_3_format_flags1);
} }
/** /**
@ -1175,9 +1124,7 @@ public abstract class CHPAbstractType
*/ */
public void setFImprint(boolean value) public void setFImprint(boolean value)
{ {
field_3_format_flags1 = (int)fImprint.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fImprint.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1187,7 +1134,6 @@ public abstract class CHPAbstractType
public boolean isFImprint() public boolean isFImprint()
{ {
return fImprint.isSet(field_3_format_flags1); return fImprint.isSet(field_3_format_flags1);
} }
/** /**
@ -1196,9 +1142,7 @@ public abstract class CHPAbstractType
*/ */
public void setFDStrike(boolean value) public void setFDStrike(boolean value)
{ {
field_3_format_flags1 = (int)fDStrike.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fDStrike.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1208,7 +1152,6 @@ public abstract class CHPAbstractType
public boolean isFDStrike() public boolean isFDStrike()
{ {
return fDStrike.isSet(field_3_format_flags1); return fDStrike.isSet(field_3_format_flags1);
} }
/** /**
@ -1217,9 +1160,7 @@ public abstract class CHPAbstractType
*/ */
public void setFUsePgsuSettings(boolean value) public void setFUsePgsuSettings(boolean value)
{ {
field_3_format_flags1 = (int)fUsePgsuSettings.setBoolean(field_3_format_flags1, value); field_3_format_flags1 = fUsePgsuSettings.setBoolean(field_3_format_flags1, value);
} }
/** /**
@ -1229,7 +1170,6 @@ public abstract class CHPAbstractType
public boolean isFUsePgsuSettings() public boolean isFUsePgsuSettings()
{ {
return fUsePgsuSettings.isSet(field_3_format_flags1); return fUsePgsuSettings.isSet(field_3_format_flags1);
} }
/** /**
@ -1239,8 +1179,6 @@ public abstract class CHPAbstractType
public void setIcoHighlight(byte value) public void setIcoHighlight(byte value)
{ {
field_33_Highlight = (short)icoHighlight.setValue(field_33_Highlight, value); field_33_Highlight = (short)icoHighlight.setValue(field_33_Highlight, value);
} }
/** /**
@ -1250,7 +1188,6 @@ public abstract class CHPAbstractType
public byte getIcoHighlight() public byte getIcoHighlight()
{ {
return ( byte )icoHighlight.getValue(field_33_Highlight); return ( byte )icoHighlight.getValue(field_33_Highlight);
} }
/** /**
@ -1260,8 +1197,6 @@ public abstract class CHPAbstractType
public void setFHighlight(boolean value) public void setFHighlight(boolean value)
{ {
field_33_Highlight = (short)fHighlight.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fHighlight.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1271,7 +1206,6 @@ public abstract class CHPAbstractType
public boolean isFHighlight() public boolean isFHighlight()
{ {
return fHighlight.isSet(field_33_Highlight); return fHighlight.isSet(field_33_Highlight);
} }
/** /**
@ -1281,8 +1215,6 @@ public abstract class CHPAbstractType
public void setKcd(byte value) public void setKcd(byte value)
{ {
field_33_Highlight = (short)kcd.setValue(field_33_Highlight, value); field_33_Highlight = (short)kcd.setValue(field_33_Highlight, value);
} }
/** /**
@ -1292,7 +1224,6 @@ public abstract class CHPAbstractType
public byte getKcd() public byte getKcd()
{ {
return ( byte )kcd.getValue(field_33_Highlight); return ( byte )kcd.getValue(field_33_Highlight);
} }
/** /**
@ -1302,8 +1233,6 @@ public abstract class CHPAbstractType
public void setFNavHighlight(boolean value) public void setFNavHighlight(boolean value)
{ {
field_33_Highlight = (short)fNavHighlight.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fNavHighlight.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1313,7 +1242,6 @@ public abstract class CHPAbstractType
public boolean isFNavHighlight() public boolean isFNavHighlight()
{ {
return fNavHighlight.isSet(field_33_Highlight); return fNavHighlight.isSet(field_33_Highlight);
} }
/** /**
@ -1323,8 +1251,6 @@ public abstract class CHPAbstractType
public void setFChsDiff(boolean value) public void setFChsDiff(boolean value)
{ {
field_33_Highlight = (short)fChsDiff.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fChsDiff.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1334,7 +1260,6 @@ public abstract class CHPAbstractType
public boolean isFChsDiff() public boolean isFChsDiff()
{ {
return fChsDiff.isSet(field_33_Highlight); return fChsDiff.isSet(field_33_Highlight);
} }
/** /**
@ -1344,8 +1269,6 @@ public abstract class CHPAbstractType
public void setFMacChs(boolean value) public void setFMacChs(boolean value)
{ {
field_33_Highlight = (short)fMacChs.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fMacChs.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1355,7 +1278,6 @@ public abstract class CHPAbstractType
public boolean isFMacChs() public boolean isFMacChs()
{ {
return fMacChs.isSet(field_33_Highlight); return fMacChs.isSet(field_33_Highlight);
} }
/** /**
@ -1365,8 +1287,6 @@ public abstract class CHPAbstractType
public void setFFtcAsciSym(boolean value) public void setFFtcAsciSym(boolean value)
{ {
field_33_Highlight = (short)fFtcAsciSym.setBoolean(field_33_Highlight, value); field_33_Highlight = (short)fFtcAsciSym.setBoolean(field_33_Highlight, value);
} }
/** /**
@ -1376,12 +1296,5 @@ public abstract class CHPAbstractType
public boolean isFFtcAsciSym() public boolean isFFtcAsciSym()
{ {
return fFtcAsciSym.isSet(field_33_Highlight); return fFtcAsciSym.isSet(field_33_Highlight);
} }
}
} // END OF CLASS

View File

@ -88,26 +88,24 @@ public abstract class FIBAbstractType implements HDFType {
field_12_chsTables = LittleEndian.getShort(data, 0x16 + offset); field_12_chsTables = LittleEndian.getShort(data, 0x16 + offset);
field_13_fcMin = LittleEndian.getInt(data, 0x18 + offset); field_13_fcMin = LittleEndian.getInt(data, 0x18 + offset);
field_14_fcMac = LittleEndian.getInt(data, 0x1c + offset); field_14_fcMac = LittleEndian.getInt(data, 0x1c + offset);
} }
public void serialize(byte[] data, int offset) public void serialize(byte[] data, int offset)
{ {
LittleEndian.putShort(data, 0x0 + offset, (short)field_1_wIdent);; LittleEndian.putShort(data, 0x0 + offset, (short)field_1_wIdent);
LittleEndian.putShort(data, 0x2 + offset, (short)field_2_nFib);; LittleEndian.putShort(data, 0x2 + offset, (short)field_2_nFib);
LittleEndian.putShort(data, 0x4 + offset, (short)field_3_nProduct);; LittleEndian.putShort(data, 0x4 + offset, (short)field_3_nProduct);
LittleEndian.putShort(data, 0x6 + offset, (short)field_4_lid);; LittleEndian.putShort(data, 0x6 + offset, (short)field_4_lid);
LittleEndian.putShort(data, 0x8 + offset, (short)field_5_pnNext);; LittleEndian.putShort(data, 0x8 + offset, (short)field_5_pnNext);
LittleEndian.putShort(data, 0xa + offset, (short)field_6_options);; LittleEndian.putShort(data, 0xa + offset, field_6_options);
LittleEndian.putShort(data, 0xc + offset, (short)field_7_nFibBack);; LittleEndian.putShort(data, 0xc + offset, (short)field_7_nFibBack);
LittleEndian.putShort(data, 0xe + offset, (short)field_8_lKey);; LittleEndian.putShort(data, 0xe + offset, (short)field_8_lKey);
LittleEndian.putShort(data, 0x10 + offset, (short)field_9_envr);; LittleEndian.putShort(data, 0x10 + offset, (short)field_9_envr);
LittleEndian.putShort(data, 0x12 + offset, (short)field_10_history);; LittleEndian.putShort(data, 0x12 + offset, field_10_history);
LittleEndian.putShort(data, 0x14 + offset, (short)field_11_chs);; LittleEndian.putShort(data, 0x14 + offset, (short)field_11_chs);
LittleEndian.putShort(data, 0x16 + offset, (short)field_12_chsTables);; LittleEndian.putShort(data, 0x16 + offset, (short)field_12_chsTables);
LittleEndian.putInt(data, 0x18 + offset, field_13_fcMin);; LittleEndian.putInt(data, 0x18 + offset, field_13_fcMin);
LittleEndian.putInt(data, 0x1c + offset, field_14_fcMac);; LittleEndian.putInt(data, 0x1c + offset, field_14_fcMac);
} }
public String toString() public String toString()
@ -422,8 +420,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFDot(boolean value) public void setFDot(boolean value)
{ {
field_6_options = (short)fDot.setBoolean(field_6_options, value); field_6_options = (short)fDot.setBoolean(field_6_options, value);
} }
/** /**
@ -433,7 +429,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFDot() public boolean isFDot()
{ {
return fDot.isSet(field_6_options); return fDot.isSet(field_6_options);
} }
/** /**
@ -443,8 +438,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFGlsy(boolean value) public void setFGlsy(boolean value)
{ {
field_6_options = (short)fGlsy.setBoolean(field_6_options, value); field_6_options = (short)fGlsy.setBoolean(field_6_options, value);
} }
/** /**
@ -454,7 +447,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFGlsy() public boolean isFGlsy()
{ {
return fGlsy.isSet(field_6_options); return fGlsy.isSet(field_6_options);
} }
/** /**
@ -464,8 +456,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFComplex(boolean value) public void setFComplex(boolean value)
{ {
field_6_options = (short)fComplex.setBoolean(field_6_options, value); field_6_options = (short)fComplex.setBoolean(field_6_options, value);
} }
/** /**
@ -475,7 +465,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFComplex() public boolean isFComplex()
{ {
return fComplex.isSet(field_6_options); return fComplex.isSet(field_6_options);
} }
/** /**
@ -485,8 +474,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFHasPic(boolean value) public void setFHasPic(boolean value)
{ {
field_6_options = (short)fHasPic.setBoolean(field_6_options, value); field_6_options = (short)fHasPic.setBoolean(field_6_options, value);
} }
/** /**
@ -496,7 +483,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFHasPic() public boolean isFHasPic()
{ {
return fHasPic.isSet(field_6_options); return fHasPic.isSet(field_6_options);
} }
/** /**
@ -506,8 +492,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setCQuickSaves(byte value) public void setCQuickSaves(byte value)
{ {
field_6_options = (short)cQuickSaves.setValue(field_6_options, value); field_6_options = (short)cQuickSaves.setValue(field_6_options, value);
} }
/** /**
@ -517,7 +501,6 @@ public abstract class FIBAbstractType implements HDFType {
public byte getCQuickSaves() public byte getCQuickSaves()
{ {
return ( byte )cQuickSaves.getValue(field_6_options); return ( byte )cQuickSaves.getValue(field_6_options);
} }
/** /**
@ -527,8 +510,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFEncrypted(boolean value) public void setFEncrypted(boolean value)
{ {
field_6_options = (short)fEncrypted.setBoolean(field_6_options, value); field_6_options = (short)fEncrypted.setBoolean(field_6_options, value);
} }
/** /**
@ -538,7 +519,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFEncrypted() public boolean isFEncrypted()
{ {
return fEncrypted.isSet(field_6_options); return fEncrypted.isSet(field_6_options);
} }
/** /**
@ -548,8 +528,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFWhichTblStm(boolean value) public void setFWhichTblStm(boolean value)
{ {
field_6_options = (short)fWhichTblStm.setBoolean(field_6_options, value); field_6_options = (short)fWhichTblStm.setBoolean(field_6_options, value);
} }
/** /**
@ -559,7 +537,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFWhichTblStm() public boolean isFWhichTblStm()
{ {
return fWhichTblStm.isSet(field_6_options); return fWhichTblStm.isSet(field_6_options);
} }
/** /**
@ -569,8 +546,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFReadOnlyRecommended(boolean value) public void setFReadOnlyRecommended(boolean value)
{ {
field_6_options = (short)fReadOnlyRecommended.setBoolean(field_6_options, value); field_6_options = (short)fReadOnlyRecommended.setBoolean(field_6_options, value);
} }
/** /**
@ -580,7 +555,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFReadOnlyRecommended() public boolean isFReadOnlyRecommended()
{ {
return fReadOnlyRecommended.isSet(field_6_options); return fReadOnlyRecommended.isSet(field_6_options);
} }
/** /**
@ -590,8 +564,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFWriteReservation(boolean value) public void setFWriteReservation(boolean value)
{ {
field_6_options = (short)fWriteReservation.setBoolean(field_6_options, value); field_6_options = (short)fWriteReservation.setBoolean(field_6_options, value);
} }
/** /**
@ -601,7 +573,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFWriteReservation() public boolean isFWriteReservation()
{ {
return fWriteReservation.isSet(field_6_options); return fWriteReservation.isSet(field_6_options);
} }
/** /**
@ -611,8 +582,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFExtChar(boolean value) public void setFExtChar(boolean value)
{ {
field_6_options = (short)fExtChar.setBoolean(field_6_options, value); field_6_options = (short)fExtChar.setBoolean(field_6_options, value);
} }
/** /**
@ -622,7 +591,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFExtChar() public boolean isFExtChar()
{ {
return fExtChar.isSet(field_6_options); return fExtChar.isSet(field_6_options);
} }
/** /**
@ -632,8 +600,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFLoadOverride(boolean value) public void setFLoadOverride(boolean value)
{ {
field_6_options = (short)fLoadOverride.setBoolean(field_6_options, value); field_6_options = (short)fLoadOverride.setBoolean(field_6_options, value);
} }
/** /**
@ -643,7 +609,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFLoadOverride() public boolean isFLoadOverride()
{ {
return fLoadOverride.isSet(field_6_options); return fLoadOverride.isSet(field_6_options);
} }
/** /**
@ -653,8 +618,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFFarEast(boolean value) public void setFFarEast(boolean value)
{ {
field_6_options = (short)fFarEast.setBoolean(field_6_options, value); field_6_options = (short)fFarEast.setBoolean(field_6_options, value);
} }
/** /**
@ -664,7 +627,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFFarEast() public boolean isFFarEast()
{ {
return fFarEast.isSet(field_6_options); return fFarEast.isSet(field_6_options);
} }
/** /**
@ -674,8 +636,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFCrypto(boolean value) public void setFCrypto(boolean value)
{ {
field_6_options = (short)fCrypto.setBoolean(field_6_options, value); field_6_options = (short)fCrypto.setBoolean(field_6_options, value);
} }
/** /**
@ -685,7 +645,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFCrypto() public boolean isFCrypto()
{ {
return fCrypto.isSet(field_6_options); return fCrypto.isSet(field_6_options);
} }
/** /**
@ -695,8 +654,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFMac(boolean value) public void setFMac(boolean value)
{ {
field_10_history = (short)fMac.setBoolean(field_10_history, value); field_10_history = (short)fMac.setBoolean(field_10_history, value);
} }
/** /**
@ -706,7 +663,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFMac() public boolean isFMac()
{ {
return fMac.isSet(field_10_history); return fMac.isSet(field_10_history);
} }
/** /**
@ -716,8 +672,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFEmptySpecial(boolean value) public void setFEmptySpecial(boolean value)
{ {
field_10_history = (short)fEmptySpecial.setBoolean(field_10_history, value); field_10_history = (short)fEmptySpecial.setBoolean(field_10_history, value);
} }
/** /**
@ -727,7 +681,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFEmptySpecial() public boolean isFEmptySpecial()
{ {
return fEmptySpecial.isSet(field_10_history); return fEmptySpecial.isSet(field_10_history);
} }
/** /**
@ -737,8 +690,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFLoadOverridePage(boolean value) public void setFLoadOverridePage(boolean value)
{ {
field_10_history = (short)fLoadOverridePage.setBoolean(field_10_history, value); field_10_history = (short)fLoadOverridePage.setBoolean(field_10_history, value);
} }
/** /**
@ -748,7 +699,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFLoadOverridePage() public boolean isFLoadOverridePage()
{ {
return fLoadOverridePage.isSet(field_10_history); return fLoadOverridePage.isSet(field_10_history);
} }
/** /**
@ -758,8 +708,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFFutureSavedUndo(boolean value) public void setFFutureSavedUndo(boolean value)
{ {
field_10_history = (short)fFutureSavedUndo.setBoolean(field_10_history, value); field_10_history = (short)fFutureSavedUndo.setBoolean(field_10_history, value);
} }
/** /**
@ -769,7 +717,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFFutureSavedUndo() public boolean isFFutureSavedUndo()
{ {
return fFutureSavedUndo.isSet(field_10_history); return fFutureSavedUndo.isSet(field_10_history);
} }
/** /**
@ -779,8 +726,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFWord97Saved(boolean value) public void setFWord97Saved(boolean value)
{ {
field_10_history = (short)fWord97Saved.setBoolean(field_10_history, value); field_10_history = (short)fWord97Saved.setBoolean(field_10_history, value);
} }
/** /**
@ -790,7 +735,6 @@ public abstract class FIBAbstractType implements HDFType {
public boolean isFWord97Saved() public boolean isFWord97Saved()
{ {
return fWord97Saved.isSet(field_10_history); return fWord97Saved.isSet(field_10_history);
} }
/** /**
@ -800,8 +744,6 @@ public abstract class FIBAbstractType implements HDFType {
public void setFSpare0(byte value) public void setFSpare0(byte value)
{ {
field_10_history = (short)fSpare0.setValue(field_10_history, value); field_10_history = (short)fSpare0.setValue(field_10_history, value);
} }
/** /**
@ -811,12 +753,5 @@ public abstract class FIBAbstractType implements HDFType {
public byte getFSpare0() public byte getFSpare0()
{ {
return ( byte )fSpare0.getValue(field_10_history); return ( byte )fSpare0.getValue(field_10_history);
} }
}
} // END OF CLASS

View File

@ -67,13 +67,12 @@ public abstract class TCAbstractType implements HDFType {
public void serialize(byte[] data, int offset) public void serialize(byte[] data, int offset)
{ {
LittleEndian.putShort(data, 0x0 + offset, (short)field_1_rgf);; LittleEndian.putShort(data, 0x0 + offset, field_1_rgf);
LittleEndian.putShort(data, 0x2 + offset, (short)field_2_unused);; LittleEndian.putShort(data, 0x2 + offset, field_2_unused);
field_3_brcTop.serialize(data, 0x4 + offset);; field_3_brcTop.serialize(data, 0x4 + offset);
field_4_brcLeft.serialize(data, 0x8 + offset);; field_4_brcLeft.serialize(data, 0x8 + offset);
field_5_brcBottom.serialize(data, 0xc + offset);; field_5_brcBottom.serialize(data, 0xc + offset);
field_6_brcRight.serialize(data, 0x10 + offset);; field_6_brcRight.serialize(data, 0x10 + offset);
} }
public String toString() public String toString()
@ -225,8 +224,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFFirstMerged(boolean value) public void setFFirstMerged(boolean value)
{ {
field_1_rgf = (short)fFirstMerged.setBoolean(field_1_rgf, value); field_1_rgf = (short)fFirstMerged.setBoolean(field_1_rgf, value);
} }
/** /**
@ -236,7 +233,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFFirstMerged() public boolean isFFirstMerged()
{ {
return fFirstMerged.isSet(field_1_rgf); return fFirstMerged.isSet(field_1_rgf);
} }
/** /**
@ -246,8 +242,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFMerged(boolean value) public void setFMerged(boolean value)
{ {
field_1_rgf = (short)fMerged.setBoolean(field_1_rgf, value); field_1_rgf = (short)fMerged.setBoolean(field_1_rgf, value);
} }
/** /**
@ -257,7 +251,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFMerged() public boolean isFMerged()
{ {
return fMerged.isSet(field_1_rgf); return fMerged.isSet(field_1_rgf);
} }
/** /**
@ -267,8 +260,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFVertical(boolean value) public void setFVertical(boolean value)
{ {
field_1_rgf = (short)fVertical.setBoolean(field_1_rgf, value); field_1_rgf = (short)fVertical.setBoolean(field_1_rgf, value);
} }
/** /**
@ -278,7 +269,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFVertical() public boolean isFVertical()
{ {
return fVertical.isSet(field_1_rgf); return fVertical.isSet(field_1_rgf);
} }
/** /**
@ -288,8 +278,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFBackward(boolean value) public void setFBackward(boolean value)
{ {
field_1_rgf = (short)fBackward.setBoolean(field_1_rgf, value); field_1_rgf = (short)fBackward.setBoolean(field_1_rgf, value);
} }
/** /**
@ -299,7 +287,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFBackward() public boolean isFBackward()
{ {
return fBackward.isSet(field_1_rgf); return fBackward.isSet(field_1_rgf);
} }
/** /**
@ -309,8 +296,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFRotateFont(boolean value) public void setFRotateFont(boolean value)
{ {
field_1_rgf = (short)fRotateFont.setBoolean(field_1_rgf, value); field_1_rgf = (short)fRotateFont.setBoolean(field_1_rgf, value);
} }
/** /**
@ -320,7 +305,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFRotateFont() public boolean isFRotateFont()
{ {
return fRotateFont.isSet(field_1_rgf); return fRotateFont.isSet(field_1_rgf);
} }
/** /**
@ -330,8 +314,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFVertMerge(boolean value) public void setFVertMerge(boolean value)
{ {
field_1_rgf = (short)fVertMerge.setBoolean(field_1_rgf, value); field_1_rgf = (short)fVertMerge.setBoolean(field_1_rgf, value);
} }
/** /**
@ -341,7 +323,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFVertMerge() public boolean isFVertMerge()
{ {
return fVertMerge.isSet(field_1_rgf); return fVertMerge.isSet(field_1_rgf);
} }
/** /**
@ -351,8 +332,6 @@ public abstract class TCAbstractType implements HDFType {
public void setFVertRestart(boolean value) public void setFVertRestart(boolean value)
{ {
field_1_rgf = (short)fVertRestart.setBoolean(field_1_rgf, value); field_1_rgf = (short)fVertRestart.setBoolean(field_1_rgf, value);
} }
/** /**
@ -362,7 +341,6 @@ public abstract class TCAbstractType implements HDFType {
public boolean isFVertRestart() public boolean isFVertRestart()
{ {
return fVertRestart.isSet(field_1_rgf); return fVertRestart.isSet(field_1_rgf);
} }
/** /**
@ -372,8 +350,6 @@ public abstract class TCAbstractType implements HDFType {
public void setVertAlign(byte value) public void setVertAlign(byte value)
{ {
field_1_rgf = (short)vertAlign.setValue(field_1_rgf, value); field_1_rgf = (short)vertAlign.setValue(field_1_rgf, value);
} }
/** /**
@ -383,12 +359,5 @@ public abstract class TCAbstractType implements HDFType {
public byte getVertAlign() public byte getVertAlign()
{ {
return ( byte )vertAlign.getValue(field_1_rgf); return ( byte )vertAlign.getValue(field_1_rgf);
} }
}
} // END OF CLASS

View File

@ -46,7 +46,7 @@ public final class CharacterSprmUncompressor
while (sprmIt.hasNext()) while (sprmIt.hasNext())
{ {
SprmOperation sprm = (SprmOperation)sprmIt.next(); SprmOperation sprm = sprmIt.next();
unCompressCHPOperation(parent, newProperties, sprm); unCompressCHPOperation(parent, newProperties, sprm);
} }
@ -108,8 +108,8 @@ public final class CharacterSprmUncompressor
break; break;
case 0x9: case 0x9:
newCHP.setFSpec (true); newCHP.setFSpec (true);
newCHP.setFtcSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset())); newCHP.setFtcSym (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset()));
newCHP.setXchSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2)); newCHP.setXchSym (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2));
break; break;
case 0xa: case 0xa:
newCHP.setFOle2 (getFlag (sprm.getOperand())); newCHP.setFOle2 (getFlag (sprm.getOperand()));
@ -426,8 +426,8 @@ public final class CharacterSprmUncompressor
// styleSheet, opSize); // styleSheet, opSize);
break; break;
case 0x4d: case 0x4d:
float percentage = (float) sprm.getOperand() / 100.0f; float percentage = sprm.getOperand() / 100.0f;
int add = (int) ((float) percentage * (float) newCHP.getHps ()); int add = (int) (percentage * newCHP.getHps ());
newCHP.setHps (newCHP.getHps () + add); newCHP.setHps (newCHP.getHps () + add);
break; break;
case 0x4e: case 0x4e:
@ -462,7 +462,7 @@ public final class CharacterSprmUncompressor
byte[] buf = sprm.getGrpprl(); byte[] buf = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset(); int offset = sprm.getGrpprlOffset();
newCHP.setFPropMark (buf[offset]); newCHP.setFPropMark (buf[offset]);
newCHP.setIbstPropRMark ((short) LittleEndian.getShort (buf, offset + 1)); newCHP.setIbstPropRMark (LittleEndian.getShort (buf, offset + 1));
newCHP.setDttmPropRMark (new DateAndTime(buf, offset +3)); newCHP.setDttmPropRMark (new DateAndTime(buf, offset +3));
break; break;
case 0x58: case 0x58:
@ -494,7 +494,7 @@ public final class CharacterSprmUncompressor
buf = sprm.getGrpprl(); buf = sprm.getGrpprl();
offset = sprm.getGrpprlOffset(); offset = sprm.getGrpprlOffset();
newCHP.setFDispFldRMark (buf[offset]); newCHP.setFDispFldRMark (buf[offset]);
newCHP.setIbstDispFldRMark ((short) LittleEndian.getShort (buf, offset + 1)); newCHP.setIbstDispFldRMark (LittleEndian.getShort (buf, offset + 1));
newCHP.setDttmDispFldRMark (new DateAndTime(buf, offset + 3)); newCHP.setDttmDispFldRMark (new DateAndTime(buf, offset + 3));
System.arraycopy (buf, offset + 7, xstDispFldRMark, 0, 32); System.arraycopy (buf, offset + 7, xstDispFldRMark, 0, 32);
newCHP.setXstDispFldRMark (xstDispFldRMark); newCHP.setXstDispFldRMark (xstDispFldRMark);
@ -553,14 +553,7 @@ public final class CharacterSprmUncompressor
*/ */
public static boolean getFlag (int x) public static boolean getFlag (int x)
{ {
if (x != 0) return x != 0;
{
return true;
}
else
{
return false;
}
} }
private static boolean getCHPFlag (byte x, boolean oldVal) private static boolean getCHPFlag (byte x, boolean oldVal)

View File

@ -54,7 +54,7 @@ public final class ParagraphSprmUncompressor
while (sprmIt.hasNext()) while (sprmIt.hasNext())
{ {
SprmOperation sprm = (SprmOperation)sprmIt.next(); SprmOperation sprm = sprmIt.next();
// PAPXs can contain table sprms if the paragraph marks the end of a // PAPXs can contain table sprms if the paragraph marks the end of a
// table row // table row
@ -326,8 +326,8 @@ public final class ParagraphSprmUncompressor
{ {
byte[] varParam = sprm.getGrpprl(); byte[] varParam = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset(); int offset = sprm.getGrpprlOffset();
newPAP.setFPropRMark ((int) varParam[offset]); newPAP.setFPropRMark (varParam[offset]);
newPAP.setIbstPropRMark ((int) LittleEndian.getShort (varParam, offset + 1)); newPAP.setIbstPropRMark (LittleEndian.getShort (varParam, offset + 1));
newPAP.setDttmPropRMark (new DateAndTime(varParam, offset + 3)); newPAP.setDttmPropRMark (new DateAndTime(varParam, offset + 3));
} }
catch (Exception e) catch (Exception e)

View File

@ -33,7 +33,7 @@ public final class SectionSprmUncompressor extends SprmUncompressor
while (sprmIt.hasNext()) while (sprmIt.hasNext())
{ {
SprmOperation sprm = (SprmOperation)sprmIt.next(); SprmOperation sprm = sprmIt.next();
unCompressSEPOperation(newProperties, sprm); unCompressSEPOperation(newProperties, sprm);
} }

View File

@ -39,7 +39,7 @@ public final class TableSprmUncompressor
while (sprmIt.hasNext()) while (sprmIt.hasNext())
{ {
SprmOperation sprm = (SprmOperation)sprmIt.next(); SprmOperation sprm = sprmIt.next();
//TAPXs are actually PAPXs so we have to make sure we are only trying to //TAPXs are actually PAPXs so we have to make sure we are only trying to
//uncompress the right type of sprm. //uncompress the right type of sprm.

View File

@ -380,13 +380,11 @@ public final class CharacterProperties
cp.field_23_dttmRMarkDel = (DateAndTime)field_23_dttmRMarkDel.clone(); cp.field_23_dttmRMarkDel = (DateAndTime)field_23_dttmRMarkDel.clone();
cp.field_36_dttmPropRMark = (DateAndTime)field_36_dttmPropRMark.clone(); cp.field_36_dttmPropRMark = (DateAndTime)field_36_dttmPropRMark.clone();
cp.field_40_dttmDispFldRMark = (DateAndTime)field_40_dttmDispFldRMark.clone(); cp.field_40_dttmDispFldRMark = (DateAndTime)field_40_dttmDispFldRMark.clone();
cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone(); cp.field_41_xstDispFldRMark = field_41_xstDispFldRMark.clone();
cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone(); cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone();
cp._ico24 = _ico24; cp._ico24 = _ico24;
return cp; return cp;
} }
} }

View File

@ -546,7 +546,7 @@ public final class CharacterRun
cp._props.setDttmPropRMark((DateAndTime)_props.getDttmPropRMark().clone()); cp._props.setDttmPropRMark((DateAndTime)_props.getDttmPropRMark().clone());
cp._props.setDttmDispFldRMark((DateAndTime)_props.getDttmDispFldRMark(). cp._props.setDttmDispFldRMark((DateAndTime)_props.getDttmDispFldRMark().
clone()); clone());
cp._props.setXstDispFldRMark((byte[])_props.getXstDispFldRMark().clone()); cp._props.setXstDispFldRMark(_props.getXstDispFldRMark().clone());
cp._props.setShd((ShadingDescriptor)_props.getShd().clone()); cp._props.setShd((ShadingDescriptor)_props.getShd().clone());
return cp; return cp;

View File

@ -55,7 +55,7 @@ public final class HWPFList {
*/ */
public HWPFList(boolean numbered, StyleSheet styleSheet) public HWPFList(boolean numbered, StyleSheet styleSheet)
{ {
_listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered); _listData = new ListData((int)(Math.random() * System.currentTimeMillis()), numbered);
_override = new ListFormatOverride(_listData.getLsid()); _override = new ListFormatOverride(_listData.getLsid());
_styleSheet = styleSheet; _styleSheet = styleSheet;
} }

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,7 @@ public final class TableProperties
tap.field_14_brcRight = (BorderCode)field_14_brcRight.clone(); tap.field_14_brcRight = (BorderCode)field_14_brcRight.clone();
tap.field_15_brcVertical = (BorderCode)field_15_brcVertical.clone(); tap.field_15_brcVertical = (BorderCode)field_15_brcVertical.clone();
tap.field_16_brcHorizontal = (BorderCode)field_16_brcHorizontal.clone(); tap.field_16_brcHorizontal = (BorderCode)field_16_brcHorizontal.clone();
tap.field_8_rgdxaCenter = (short[])field_8_rgdxaCenter.clone(); tap.field_8_rgdxaCenter = field_8_rgdxaCenter.clone();
tap.field_9_rgtc = new TableCellDescriptor[field_9_rgtc.length]; tap.field_9_rgtc = new TableCellDescriptor[field_9_rgtc.length];
for (int x = 0; x < field_9_rgtc.length; x++) for (int x = 0; x < field_9_rgtc.length; x++)
{ {

View File

@ -50,11 +50,10 @@ public class TestModelFactory extends TestCase {
{ {
ModelFactory mf = new ModelFactory(); ModelFactory mf = new ModelFactory();
assertTrue("listeners member cannot be null", mf.listeners != null); assertTrue("listeners member cannot be null", mf.listeners != null);
assertTrue("listeners member must be a List", mf.listeners instanceof List);
models = new ArrayList(3); models = new ArrayList(3);
factory = new ModelFactory(); factory = new ModelFactory();
book = new HSSFWorkbook(); book = new HSSFWorkbook();
ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book); ByteArrayOutputStream stream = setupRunFile(book);
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new ByteArrayInputStream(stream.toByteArray()) new ByteArrayInputStream(stream.toByteArray())
); );

View File

@ -115,7 +115,6 @@ public final class TestRecordFactory extends TestCase {
* constructs the expected array of records.<P> * constructs the expected array of records.<P>
* SUCCESS: Record factory creates the expected records.<P> * SUCCESS: Record factory creates the expected records.<P>
* FAILURE: The wrong records are created or contain the wrong values <P> * FAILURE: The wrong records are created or contain the wrong values <P>
*
*/ */
public void testContinuedUnknownRecord() { public void testContinuedUnknownRecord() {
byte[] data = { byte[] data = {
@ -125,8 +124,7 @@ public final class TestRecordFactory extends TestCase {
}; };
ByteArrayInputStream bois = new ByteArrayInputStream(data); ByteArrayInputStream bois = new ByteArrayInputStream(data);
Record[] records = (Record[]) Record[] records = RecordFactory.createRecords(bois).toArray(new Record[0]);
RecordFactory.createRecords(bois).toArray(new Record[0]);
assertEquals("Created record count", 3, records.length); assertEquals("Created record count", 3, records.length);
assertEquals("1st record's type", assertEquals("1st record's type",
UnknownRecord.class.getName(), UnknownRecord.class.getName(),