From a8957e80fae34eb8143f67bd9d01901b56f31cbc Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Tue, 18 Aug 2009 05:29:53 +0000 Subject: [PATCH] Fixing compiler warnings - unnecessary typecasts git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@805284 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/AddDimensionedImage.java | 18 +- src/java/org/apache/poi/hpsf/Util.java | 20 +- .../hssf/eventmodel/EventRecordFactory.java | 146 +- .../org/apache/poi/hssf/model/LinkTable.java | 48 +- .../poi/hssf/record/EscherAggregate.java | 37 +- .../org/apache/poi/hssf/record/SSTRecord.java | 50 +- .../poi/hssf/record/cf/FontFormatting.java | 28 +- .../record/formula/eval/OperandResolver.java | 5 +- .../poi/hssf/usermodel/EscherGraphics.java | 10 +- .../poi/hssf/usermodel/EscherGraphics2d.java | 77 +- .../poi/hssf/usermodel/HSSFPalette.java | 91 +- .../poi/hssf/usermodel/HSSFWorkbook.java | 30 +- src/java/org/apache/poi/hssf/util/RKUtil.java | 14 +- .../poi/poifs/filesystem/POIFSDocument.java | 103 +- .../apache/poi/poifs/property/Property.java | 76 +- .../poi/ss/formula/WorkbookEvaluator.java | 3 +- src/java/org/apache/poi/ss/util/Region.java | 382 ++-- src/java/org/apache/poi/util/BinaryTree.java | 276 +-- src/java/org/apache/poi/util/POILogger.java | 198 +- .../apache/poi/openxml4j/opc/OPCPackage.java | 146 +- .../apache/poi/openxml4j/opc/PackagePart.java | 166 +- .../openxml4j/opc/PackageRelationship.java | 12 +- .../opc/PackageRelationshipCollection.java | 42 +- .../poi/openxml4j/opc/RelationshipSource.java | 31 +- .../apache/poi/openxml4j/opc/ZipPackage.java | 2 +- .../poi/openxml4j/opc/ZipPackagePart.java | 16 +- .../opc/internal/ContentTypeManager.java | 36 +- .../xssf/extractor/XSSFExcelExtractor.java | 26 +- .../apache/poi/xssf/usermodel/XSSFCell.java | 10 +- .../poi/xssf/usermodel/XSSFCellStyle.java | 5 +- .../poi/xssf/usermodel/XSSFPrintSetup.java | 2 +- .../apache/poi/xssf/usermodel/XSSFSheet.java | 21 +- .../poi/xssf/model/TestCommentsTable.java | 187 +- .../poi/xssf/usermodel/TestXSSFHyperlink.java | 14 +- .../apache/poi/hdf/extractor/StyleSheet.java | 40 +- .../poi/hdf/extractor/WordDocument.java | 46 +- .../poi/hdf/model/hdftypes/StyleSheet.java | 40 +- .../hdftypes/definitions/CHPAbstractType.java | 129 +- .../hdftypes/definitions/DOPAbstractType.java | 585 ++--- .../hdftypes/definitions/FIBAbstractType.java | 1196 ++++------ .../src/org/apache/poi/hdgf/HDGFLZW.java | 73 +- .../apache/poi/hdgf/chunks/ChunkHeader.java | 6 +- .../org/apache/poi/hslf/HSLFSlideShow.java | 2 +- .../apache/poi/hslf/dev/SlideShowDumper.java | 8 +- .../QuickButCruddyTextExtractor.java | 6 +- .../org/apache/poi/hslf/model/Freeform.java | 31 +- .../org/apache/poi/hslf/record/CString.java | 2 +- .../poi/hslf/record/ColorSchemeAtom.java | 45 +- .../apache/poi/hslf/record/DocumentAtom.java | 19 +- .../poi/hslf/record/EscherTextboxWrapper.java | 34 +- .../org/apache/poi/hslf/record/NotesAtom.java | 2 +- .../org/apache/poi/hslf/record/SlideAtom.java | 6 +- .../poi/hslf/record/SlidePersistAtom.java | 12 +- .../poi/hslf/record/TextHeaderAtom.java | 2 +- .../apache/poi/hslf/record/UserEditAtom.java | 14 +- .../poi/hsmf/parsers/POIFSChunkParser.java | 218 +- .../org/apache/poi/hwpf/model/ListData.java | 2 +- .../org/apache/poi/hwpf/model/StyleSheet.java | 22 +- .../poi/hwpf/model/types/CHPAbstractType.java | 129 +- .../poi/hwpf/model/types/DOPAbstractType.java | 434 +--- .../poi/hwpf/model/types/FIBAbstractType.java | 95 +- .../poi/hwpf/model/types/TCAbstractType.java | 45 +- .../hwpf/sprm/CharacterSprmUncompressor.java | 23 +- .../hwpf/sprm/ParagraphSprmUncompressor.java | 6 +- .../hwpf/sprm/SectionSprmUncompressor.java | 2 +- .../poi/hwpf/sprm/TableSprmUncompressor.java | 2 +- .../hwpf/usermodel/CharacterProperties.java | 4 +- .../poi/hwpf/usermodel/CharacterRun.java | 2 +- .../apache/poi/hwpf/usermodel/HWPFList.java | 2 +- .../org/apache/poi/hwpf/usermodel/Range.java | 1956 ++++++++--------- .../poi/hwpf/usermodel/TableProperties.java | 2 +- .../poi/hssf/eventmodel/TestModelFactory.java | 3 +- .../poi/hssf/record/TestRecordFactory.java | 4 +- 73 files changed, 3107 insertions(+), 4470 deletions(-) diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java index 6fcc3240ca..441938074f 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java @@ -238,7 +238,6 @@ public class AddDimensionedImage { String imageFile, double reqImageWidthMM, double reqImageHeightMM, int resizeBehaviour) throws FileNotFoundException, IOException, IllegalArgumentException { - HSSFRow row = null; HSSFClientAnchor anchor = null; HSSFPatriarch patriarch = null; ClientAnchorDetail rowClientAnchorDetail = null; @@ -280,7 +279,7 @@ public class AddDimensionedImage { // image as the size of the row/column is adjusted. This could easilly // become another parameter passed to the method. anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE); - + // 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 // however. @@ -485,7 +484,6 @@ public class AddDimensionedImage { double colWidthMM = 0.0D; double overlapMM = 0.0D; double coordinatePositionsPerMM = 0.0D; - int fromNumber = startingColumn; int toColumn = startingColumn; int inset = 0; @@ -522,7 +520,7 @@ public class AddDimensionedImage { // total number of co-ordinate positions to the third paramater // of the ClientAnchorDetail constructor. For no sepcific reason, // the latter option is used below. - anchorDetail = new ClientAnchorDetail(startingColumn, + anchorDetail = new ClientAnchorDetail(startingColumn, toColumn, ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS); } // 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 */ public static void main(String[] args) { - File file = null; - FileInputStream fis = null; FileOutputStream fos = null; HSSFWorkbook workbook = null; HSSFSheet sheet = null; @@ -761,13 +757,13 @@ public class AddDimensionedImage { * * Together, parameter seven and eight determine the column and row * co-ordinates of the cell whose top left hand corner will be aligned * with the images bottom right hand corner. - * + * * An instance of the ClientAnchorDetail class provides three of the eight * 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 * edge of the cell. - * + * * @author Mark Beardsley [msb at apache.org] * @version 1.00 5th August 2009. */ @@ -892,7 +888,7 @@ public class AddDimensionedImage { int pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR) * UNIT_OFFSET_LENGTH; int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR; - pixels += Math.round((float) offsetWidthUnits / + pixels += Math.round(offsetWidthUnits / ((float) EXCEL_COLUMN_WIDTH_FACTOR / UNIT_OFFSET_LENGTH)); return pixels; } @@ -923,4 +919,4 @@ public class AddDimensionedImage { ConvertImageUnits.PIXELS_PER_MILLIMETRES))); } } -} \ No newline at end of file +} diff --git a/src/java/org/apache/poi/hpsf/Util.java b/src/java/org/apache/poi/hpsf/Util.java index 93b394ad71..62a384a3dd 100644 --- a/src/java/org/apache/poi/hpsf/Util.java +++ b/src/java/org/apache/poi/hpsf/Util.java @@ -177,7 +177,7 @@ public class Util * * @param date The date to be converted * @return The filetime - * + * * @see #filetimeToDate(long) * @see #filetimeToDate(int, int) */ @@ -211,10 +211,10 @@ public class Util * @return true if the collections are equal, else * false. */ - public static boolean equals(final Collection c1, final Collection c2) + public static boolean equals(Collection c1, Collection c2) { - final Object[] o1 = c1.toArray(); - final Object[] o2 = c2.toArray(); + Object[] o1 = c1.toArray(); + Object[] o2 = c2.toArray(); return internalEquals(o1, o2); } @@ -229,14 +229,14 @@ public class Util * @return true if the object arrays are equal, * false 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[] o2 = (Object[]) c2.clone(); + final Object[] o1 = c1.clone(); + final Object[] o2 = c2.clone(); 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++) { @@ -326,9 +326,9 @@ public class Util /** *

Returns a textual representation of a {@link Throwable}, including a * stacktrace.

- * + * * @param t The {@link Throwable} - * + * * @return a string containing the output of a call to * t.printStacktrace(). */ diff --git a/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java b/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java index 5cdd813700..0151134e87 100644 --- a/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java +++ b/src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java @@ -24,10 +24,10 @@ import org.apache.poi.hssf.record.*; /** * 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 * 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 Marc Johnson (mjohnson at apache dot 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 { - private final ERFListener _listener; + private final ERFListener _listener; private final short[] _sids; - /** - * - * @param sids an array of Record.sid values identifying the records - * the listener will work with. Alternatively if this is "null" then - * all records are passed. For all 'known' record types use {@link RecordFactory#getAllKnownRecordSIDs()} - */ - public EventRecordFactory(ERFListener listener, short[] sids) { - _listener = listener; - if (sids == null) { - _sids = null; - } else { - _sids = (short[]) sids.clone(); - Arrays.sort(_sids); // for faster binary search - } - } + /** + * + * @param sids an array of Record.sid values identifying the records + * the listener will work with. Alternatively if this is "null" then + * all records are passed. For all 'known' record types use {@link RecordFactory#getAllKnownRecordSIDs()} + */ + public EventRecordFactory(ERFListener listener, short[] sids) { + _listener = listener; + if (sids == null) { + _sids = null; + } else { + _sids = sids.clone(); + Arrays.sort(_sids); // for faster binary search + } + } private boolean isSidIncluded(short sid) { if (_sids == null) { return true; } return Arrays.binarySearch(_sids, sid) >= 0; - } + } + + /** + * sends the record event to all registered listeners. + * @param record the record to be thrown. + * @return false to abort. This aborts + * out of the event loop should the listener return false + */ + private boolean processRecord(Record record) { + if (!isSidIncluded(record.getSid())) { + return true; + } + return _listener.processRecord(record); + } - /** - * sends the record event to all registered listeners. - * @param record the record to be thrown. - * @return false to abort. This aborts - * out of the event loop should the listener return false - */ - private boolean processRecord(Record record) { - if (!isSidIncluded(record.getSid())) { - return true; - } - return _listener.processRecord(record); - } + /** + * Create an array of records from an input stream + * + * @param in the InputStream from which the records will be + * obtained + * + * @exception RecordFormatException on error processing the + * InputStream + */ + public void processRecords(InputStream in) throws RecordFormatException { + Record last_record = null; - /** - * Create an array of records from an input stream - * - * @param in the InputStream from which the records will be - * obtained - * - * @exception RecordFormatException on error processing the - * InputStream - */ - public void processRecords(InputStream in) throws RecordFormatException { - Record last_record = null; + RecordInputStream recStream = new RecordInputStream(in); - RecordInputStream recStream = new RecordInputStream(in); + while (recStream.hasNextRecord()) { + recStream.nextRecord(); + Record[] recs = RecordFactory.createRecord(recStream); // handle MulRK records + if (recs.length > 1) { + for (int k = 0; k < recs.length; k++) { + if ( last_record != null ) { + if (!processRecord(last_record)) { + return; + } + } + last_record = recs[ k ]; // do to keep the algorithm homogeneous...you can't + } // actually continue a number record anyhow. + } else { + Record record = recs[ 0 ]; - while (recStream.hasNextRecord()) { - recStream.nextRecord(); - Record[] recs = RecordFactory.createRecord(recStream); // handle MulRK records - if (recs.length > 1) { - for (int k = 0; k < recs.length; k++) { - if ( last_record != null ) { - if (!processRecord(last_record)) { - return; - } - } - last_record = recs[ k ]; // do to keep the algorithm homogeneous...you can't - } // actually continue a number record anyhow. - } else { - Record record = recs[ 0 ]; + if (record != null) { + if (last_record != null) { + if (!processRecord(last_record)) { + return; + } + } + last_record = record; + } + } + } - if (record != null) { - if (last_record != null) { - if (!processRecord(last_record)) { - return; - } - } - last_record = record; - } - } - } - - if (last_record != null) { - processRecord(last_record); - } - } -} \ No newline at end of file + if (last_record != null) { + processRecord(last_record); + } + } +} diff --git a/src/java/org/apache/poi/hssf/model/LinkTable.java b/src/java/org/apache/poi/hssf/model/LinkTable.java index f5c44ce5c9..73b7d02da0 100755 --- a/src/java/org/apache/poi/hssf/model/LinkTable.java +++ b/src/java/org/apache/poi/hssf/model/LinkTable.java @@ -65,8 +65,8 @@ import org.apache.poi.hssf.record.formula.Ref3DPtg; * @author Josh Micich */ final class LinkTable { - - + + // TODO make this class into a record aggregate private static final class CRNBlock { @@ -84,7 +84,7 @@ final class LinkTable { _crns = crns; } public CRNRecord[] getCrns() { - return (CRNRecord[]) _crns.clone(); + return _crns.clone(); } } @@ -95,7 +95,7 @@ final class LinkTable { public ExternalBookBlock(RecordStream rs) { _externalBookRecord = (SupBookRecord) rs.getNext(); - List temp = new ArrayList(); + List temp = new ArrayList(); while(rs.peekNextClass() == ExternalNameRecord.class) { temp.add(rs.getNext()); } @@ -141,7 +141,7 @@ final class LinkTable { private final ExternalBookBlock[] _externalBookBlocks; private final ExternSheetRecord _externSheetRecord; - private final List _definedNames; + private final List _definedNames; private final int _recordCount; private final WorkbookRecordList _workbookRecordList; // TODO - would be nice to remove this @@ -150,15 +150,15 @@ final class LinkTable { _workbookRecordList = workbookRecordList; RecordStream rs = new RecordStream(inputList, startIndex); - List temp = new ArrayList(); + List temp = new ArrayList(); while(rs.peekNextClass() == SupBookRecord.class) { temp.add(new ExternalBookBlock(rs)); } - + _externalBookBlocks = new ExternalBookBlock[temp.size()]; temp.toArray(_externalBookBlocks); temp.clear(); - + if (_externalBookBlocks.length > 0) { // If any ExternalBookBlock present, there is always 1 of ExternSheetRecord if (rs.peekNextClass() != ExternSheetRecord.class) { @@ -170,8 +170,8 @@ final class LinkTable { } else { _externSheetRecord = null; } - - _definedNames = new ArrayList(); + + _definedNames = new ArrayList(); // collect zero or more DEFINEDNAMEs id=0x18 while(rs.peekNextClass() == NameRecord.class) { NameRecord nr = (NameRecord)rs.getNext(); @@ -183,19 +183,19 @@ final class LinkTable { } private static ExternSheetRecord readExtSheetRecord(RecordStream rs) { - List temp = new ArrayList(2); + List temp = new ArrayList(2); while(rs.peekNextClass() == ExternSheetRecord.class) { - temp.add(rs.getNext()); + temp.add((ExternSheetRecord) rs.getNext()); } - + int nItems = temp.size(); if (nItems < 1) { - throw new RuntimeException("Expected an EXTERNSHEET record but got (" + throw new RuntimeException("Expected an EXTERNSHEET record but got (" + rs.peekNextClass().getName() + ")"); } if (nItems == 1) { // 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). // 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) { _workbookRecordList = workbookRecordList; - _definedNames = new ArrayList(); + _definedNames = new ArrayList(); _externalBookBlocks = new ExternalBookBlock[] { new ExternalBookBlock(numberOfSheets), }; @@ -267,7 +267,7 @@ final class LinkTable { } public NameRecord getNameRecord(int index) { - return (NameRecord) _definedNames.get(index); + return _definedNames.get(index); } public void addName(NameRecord name) { @@ -301,9 +301,9 @@ final class LinkTable { } return false; } - + private static boolean isDuplicatedNames(NameRecord firstName, NameRecord lastName) { - return lastName.getNameText().equalsIgnoreCase(firstName.getNameText()) + return lastName.getNameText().equalsIgnoreCase(firstName.getNameText()) && isSameSheetNames(firstName, 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 + "'"); } int sheetIndex = getSheetIndex(ebrTarget.getSheetNames(), sheetName); - + int result = _externSheetRecord.getRefIxForSheet(externalBookIndex, sheetIndex); if (result < 0) { - throw new RuntimeException("ExternSheetRecord does not contain combination (" + throw new RuntimeException("ExternSheetRecord does not contain combination (" + externalBookIndex + ", " + sheetIndex + ")"); } return result; @@ -356,7 +356,7 @@ final class LinkTable { if (sheetNames[i].equals(sheetName)) { return i; } - + } throw new RuntimeException("External workbook does not contain sheet '" + sheetName + "'"); } @@ -428,7 +428,7 @@ final class LinkTable { continue; } // found it. - int sheetRefIndex = findRefIndexFromExtBookIndex(i); + int sheetRefIndex = findRefIndexFromExtBookIndex(i); if (sheetRefIndex >= 0) { return new NameXPtg(sheetRefIndex, definedNameIndex); } @@ -437,6 +437,6 @@ final class LinkTable { } private int findRefIndexFromExtBookIndex(int extBookIndex) { - return _externSheetRecord.findRefIndexFromExtBookIndex(extBookIndex); + return _externSheetRecord.findRefIndexFromExtBookIndex(extBookIndex); } } diff --git a/src/java/org/apache/poi/hssf/record/EscherAggregate.java b/src/java/org/apache/poi/hssf/record/EscherAggregate.java index a6267ef3b8..4b94f281af 100644 --- a/src/java/org/apache/poi/hssf/record/EscherAggregate.java +++ b/src/java/org/apache/poi/hssf/record/EscherAggregate.java @@ -465,7 +465,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { pos += temp; // 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 ); pos += temp; @@ -535,7 +535,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { { this.patriarch = patriarch; } - + /** * Converts the Records into UserModel * objects on the bound HSSFPatriarch @@ -544,7 +544,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { if(patriarch == null) { throw new IllegalStateException("Must call setPatriarch() first"); } - + // The top level container ought to have // the DgRecord and the container of one container // per shape group (patriach overall first) @@ -552,14 +552,13 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { if(topContainer == null) { return; } - topContainer = (EscherContainerRecord) - topContainer.getChildContainers().get(0); - + topContainer = topContainer.getChildContainers().get(0); + List tcc = topContainer.getChildContainers(); 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!"); } - + // First up, get the patriach position // This is in the first EscherSpgrRecord, in // the first container, with a EscherSRecord too @@ -579,7 +578,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { spgr.getRectX2(), spgr.getRectY2() ); } - + // Now process the containers for each group // and objects for(int i=1; i it = shapeContainer.getChildIterator(); it.hasNext();) { EscherRecord r = it.next(); if(r instanceof EscherSpgrRecord) { // This may be overriden by a later EscherClientAnchorRecord EscherSpgrRecord spgr = (EscherSpgrRecord)r; - + if(model instanceof HSSFShapeGroup) { HSSFShapeGroup g = (HSSFShapeGroup)model; g.setCoordinates( @@ -642,10 +641,10 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { } else { throw new IllegalStateException("Got top level anchor but not processing a group"); } - } + } else if(r instanceof EscherClientAnchorRecord) { EscherClientAnchorRecord car = (EscherClientAnchorRecord)r; - + if(model instanceof HSSFShape) { HSSFShape g = (HSSFShape)model; g.getAnchor().setDx1(car.getDx1()); @@ -658,7 +657,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { } else if(r instanceof EscherTextboxRecord) { EscherTextboxRecord tbr = (EscherTextboxRecord)r; - + // Also need to find the TextObjectRecord too // TODO } @@ -673,7 +672,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { } } } - + public void clear() { clearEscherRecords(); @@ -742,7 +741,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { EscherRecord escherTextbox = ( (TextboxShape) shapeModel ).getEscherTextbox(); shapeToObj.put( escherTextbox, ( (TextboxShape) shapeModel ).getTextObjectRecord() ); // escherParent.addChildRecord(escherTextbox); - + if ( shapeModel instanceof CommentShape ){ CommentShape comment = (CommentShape)shapeModel; tailRec.add(comment.getNoteRecord()); diff --git a/src/java/org/apache/poi/hssf/record/SSTRecord.java b/src/java/org/apache/poi/hssf/record/SSTRecord.java index d87b06320e..481fa84d3c 100644 --- a/src/java/org/apache/poi/hssf/record/SSTRecord.java +++ b/src/java/org/apache/poi/hssf/record/SSTRecord.java @@ -68,9 +68,6 @@ public final class SSTRecord extends ContinuableRecord { /** Offsets relative the start of the current SST or continue record */ int[] bucketRelativeOffsets; - /** - * default constructor - */ public SSTRecord() { field_1_num_strings = 0; @@ -86,8 +83,7 @@ public final class SSTRecord extends ContinuableRecord { * * @return the index of that string in the table */ - - public int addString( final UnicodeString string ) + public int addString(UnicodeString string) { field_1_num_strings++; UnicodeString ucs = ( string == null ) ? EMPTY_STRING @@ -95,12 +91,9 @@ public final class SSTRecord extends ContinuableRecord { int rval; int index = field_3_strings.getIndex(ucs); - if ( index != -1 ) - { + if ( index != -1 ) { rval = index; - } - else - { + } else { // This is a new string -- we didn't see it among the // strings we've already collected rval = field_3_strings.size(); @@ -113,7 +106,6 @@ public final class SSTRecord extends ContinuableRecord { /** * @return number of strings */ - public int getNumStrings() { return field_1_num_strings; @@ -122,7 +114,6 @@ public final class SSTRecord extends ContinuableRecord { /** * @return number of unique strings */ - public int getNumUniqueStrings() { return field_2_num_unique_strings; @@ -136,8 +127,7 @@ public final class SSTRecord extends ContinuableRecord { * * @return the desired string */ - - public UnicodeString getString( final int id ) + public UnicodeString getString(int id ) { return (UnicodeString) field_3_strings.get( id ); } @@ -148,9 +138,7 @@ public final class SSTRecord extends ContinuableRecord { * * @return string representation */ - - public String toString() - { + public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append( "[SST]\n" ); @@ -168,11 +156,7 @@ public final class SSTRecord extends ContinuableRecord { return buffer.toString(); } - /** - * @return sid - */ - public short getSid() - { + public short getSid() { return sid; } @@ -254,9 +238,7 @@ public final class SSTRecord extends ContinuableRecord { * * @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 // the nontrivial constructor, of course -- so this is where // 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 * UnicodeStrings */ - Iterator getStrings() { return field_3_strings.iterator(); @@ -281,9 +262,7 @@ public final class SSTRecord extends ContinuableRecord { /** * @return count of the strings we hold. */ - - int countStrings() - { + int countStrings() { return field_3_strings.size(); } @@ -294,8 +273,7 @@ public final class SSTRecord extends ContinuableRecord { bucketRelativeOffsets = serializer.getBucketRelativeOffsets(); } - SSTDeserializer getDeserializer() - { + SSTDeserializer getDeserializer() { return deserializer; } @@ -312,15 +290,14 @@ public final class SSTRecord extends ContinuableRecord { * SST record. * @return The new SST record. */ - public ExtSSTRecord createExtSSTRecord(int sstOffset) - { + public ExtSSTRecord createExtSSTRecord(int sstOffset) { if (bucketAbsoluteOffsets == null || bucketAbsoluteOffsets == null) throw new IllegalStateException("SST record has not yet been serialized."); ExtSSTRecord extSST = new ExtSSTRecord(); extSST.setNumStringsPerBucket((short)8); - int[] absoluteOffsets = (int[]) bucketAbsoluteOffsets.clone(); - int[] relativeOffsets = (int[]) bucketRelativeOffsets.clone(); + int[] absoluteOffsets = bucketAbsoluteOffsets.clone(); + int[] relativeOffsets = bucketRelativeOffsets.clone(); for ( int i = 0; i < absoluteOffsets.length; i++ ) absoluteOffsets[i] += sstOffset; extSST.setBucketOffsets(absoluteOffsets, relativeOffsets); @@ -333,8 +310,7 @@ public final class SSTRecord extends ContinuableRecord { * * @return The size of the ExtSST record in bytes. */ - public int calcExtSSTRecordSize() - { + public int calcExtSSTRecordSize() { return ExtSSTRecord.getRecordSizeForStrings(field_3_strings.size()); } } diff --git a/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java b/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java index d8da21095d..be7aafac0e 100644 --- a/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java +++ b/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java @@ -25,10 +25,10 @@ import org.apache.poi.util.LittleEndian; /** * Font Formatting Block of the Conditional Formatting Rule Record. - * + * * @author Dmitriy Kumshayev */ -public final class FontFormatting +public final class FontFormatting { 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_NOT_USED1 = 104; 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 RAW_DATA_SIZE = 118; @@ -71,15 +71,15 @@ public final class FontFormatting public static final short SS_SUPER = 1; /** Escapement type - Subscript */ public static final short SS_SUB = 2; - /** Underline type - None */ + /** Underline type - None */ public static final byte U_NONE = 0; - /** Underline type - Single */ + /** Underline type - Single */ public static final byte U_SINGLE = 1; - /** Underline type - Double */ + /** Underline type - Double */ public static final byte U_DOUBLE = 2; - /** Underline type - Single Accounting */ + /** Underline type - Single Accounting */ public static final byte U_SINGLE_ACCOUNTING = 0x21; - /** Underline type - Double Accounting */ + /** Underline type - Double Accounting */ public static final byte U_DOUBLE_ACCOUNTING = 0x22; /** Normal boldness (not bold) */ private static final short FONT_WEIGHT_NORMAL = 0x190; @@ -92,7 +92,7 @@ public final class FontFormatting private FontFormatting(byte[] rawData) { _rawData = rawData; } - + public FontFormatting() { this(new byte[RAW_DATA_SIZE]); @@ -144,7 +144,7 @@ public final class FontFormatting private void setInt(int offset, int value) { LittleEndian.putInt( _rawData, offset, value); } - + public byte[] getRawRecord() { return _rawData; @@ -152,7 +152,7 @@ public final class FontFormatting /** * 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 */ @@ -270,7 +270,7 @@ public final class FontFormatting /** * 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) { @@ -541,9 +541,9 @@ public final class FontFormatting return buffer.toString(); } - public Object clone() + public Object clone() { - byte[] rawData = (byte[]) _rawData.clone(); + byte[] rawData = _rawData.clone(); return new FontFormatting(rawData); } } diff --git a/src/java/org/apache/poi/hssf/record/formula/eval/OperandResolver.java b/src/java/org/apache/poi/hssf/record/formula/eval/OperandResolver.java index 29f7a4dc2d..690a486f31 100755 --- a/src/java/org/apache/poi/hssf/record/formula/eval/OperandResolver.java +++ b/src/java/org/apache/poi/hssf/record/formula/eval/OperandResolver.java @@ -53,10 +53,7 @@ public final class OperandResolver { if (result instanceof ErrorEval) { throw new EvaluationException((ErrorEval) result); } - if (result instanceof ValueEval) { - return (ValueEval) result; - } - throw new RuntimeException("Unexpected eval type (" + result.getClass().getName() + ")"); + return result; } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java index f13bd0ed1f..bcd9673a53 100644 --- a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java +++ b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java @@ -283,7 +283,7 @@ public class EscherGraphics excelFont = new Font( font.getName(), font.getStyle(), (int) ( font.getSize() / verticalPixelsPerPoint )); } 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; 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 ) ); @@ -357,13 +357,13 @@ public class EscherGraphics *

* This draws the polygon, with nPoint line segments. * The first nPoint - 1 line segments are - * drawn between sequential points + * drawn between sequential points * (xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]). - * 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 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. * @param xPoints array of the x coordinates. * @param yPoints array of the y coordinates. @@ -454,7 +454,7 @@ public class EscherGraphics 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) diff --git a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java index 217f0eba5f..41b94ffd48 100644 --- a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java +++ b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java @@ -70,14 +70,13 @@ import java.util.Map; * * @author Glen Stampoultzis (glens at apache.org) */ -public class EscherGraphics2d extends Graphics2D -{ - private EscherGraphics escherGraphics; - private BufferedImage img; - private AffineTransform trans; - private Stroke stroke; - private Paint paint; - private Shape deviceclip; +public final class EscherGraphics2d extends Graphics2D { + private EscherGraphics _escherGraphics; + private BufferedImage _img; + private AffineTransform _trans; + private Stroke _stroke; + private Paint _paint; + private Shape _deviceclip; private POILogger logger = POILogFactory.getLogger(getClass()); /** @@ -87,7 +86,7 @@ public class EscherGraphics2d extends Graphics2D */ public EscherGraphics2d(EscherGraphics escherGraphics) { - this.escherGraphics = escherGraphics; + this._escherGraphics = escherGraphics; setImg( new BufferedImage(1, 1, 2) ); setColor(Color.black); } @@ -130,7 +129,7 @@ public class EscherGraphics2d extends Graphics2D public Graphics create() { - EscherGraphics2d g2d = new EscherGraphics2d(escherGraphics); + EscherGraphics2d g2d = new EscherGraphics2d(_escherGraphics); return g2d; } @@ -148,8 +147,8 @@ public class EscherGraphics2d extends Graphics2D Line2D shape2d = (Line2D) shape; int width = 0; - if (stroke != null && stroke instanceof BasicStroke) { - width = (int) ((BasicStroke)stroke).getLineWidth() * 12700; + if (_stroke != null && _stroke instanceof BasicStroke) { + width = (int) ((BasicStroke)_stroke).getLineWidth() * 12700; } 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) { 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) @@ -234,8 +233,8 @@ public class EscherGraphics2d extends Graphics2D public void drawLine(int x1, int y1, int x2, int y2) { int width = 0; - if (stroke != null && stroke instanceof BasicStroke) { - width = (int) ((BasicStroke)stroke).getLineWidth() * 12700; + if (_stroke != null && _stroke instanceof BasicStroke) { + width = (int) ((BasicStroke)_stroke).getLineWidth() * 12700; } getEscherGraphics().drawLine(x1,y1,x2,y2, width); // 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) { - escherGraphics.drawRect(x,y,width,height); + _escherGraphics.drawRect(x,y,width,height); } 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) { - escherGraphics.fillOval(x,y,width,height); + _escherGraphics.fillOval(x,y,width,height); } /** @@ -334,13 +333,13 @@ public class EscherGraphics2d extends Graphics2D *

* This draws the polygon, with nPoint line segments. * The first nPoint - 1 line segments are - * drawn between sequential points + * drawn between sequential points * (xPoints[i],yPoints[i],xPoints[i+1],yPoints[i+1]). - * 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 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. * @param xPoints array of the x coordinates. * @param yPoints array of the y coordinates. @@ -349,7 +348,7 @@ public class EscherGraphics2d extends Graphics2D */ 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) @@ -382,15 +381,15 @@ public class EscherGraphics2d extends Graphics2D public Rectangle getClipBounds() { - if(getDeviceclip() != null) + if(getDeviceclip() != null) { return getClip().getBounds(); - else - return null; + } + return null; } public Color getColor() { - return escherGraphics.getColor(); + return _escherGraphics.getColor(); } public Composite getComposite() @@ -421,7 +420,7 @@ public class EscherGraphics2d extends Graphics2D public Paint getPaint() { - return paint; + return _paint; } public Object getRenderingHint(java.awt.RenderingHints.Key key) @@ -436,7 +435,7 @@ public class EscherGraphics2d extends Graphics2D public Stroke getStroke() { - return stroke; + return _stroke; } public AffineTransform getTransform() @@ -474,7 +473,7 @@ public class EscherGraphics2d extends Graphics2D 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) @@ -484,7 +483,7 @@ public class EscherGraphics2d extends Graphics2D public void setColor(Color c) { - escherGraphics.setColor(c); + _escherGraphics.setColor(c); } public void setComposite(Composite composite) @@ -501,7 +500,7 @@ public class EscherGraphics2d extends Graphics2D { if(paint1 != null) { - paint = paint1; + _paint = paint1; if(paint1 instanceof Color) setColor( (Color)paint1 ); } @@ -524,7 +523,7 @@ public class EscherGraphics2d extends Graphics2D public void setStroke(Stroke s) { - stroke = s; + _stroke = s; } public void setTransform(AffineTransform affinetransform) @@ -571,42 +570,42 @@ public class EscherGraphics2d extends Graphics2D private EscherGraphics getEscherGraphics() { - return escherGraphics; + return _escherGraphics; } private BufferedImage getImg() { - return img; + return _img; } private void setImg( BufferedImage img ) { - this.img = img; + this._img = img; } private Graphics2D getG2D() { - return (Graphics2D) img.getGraphics(); + return (Graphics2D) _img.getGraphics(); } private AffineTransform getTrans() { - return trans; + return _trans; } private void setTrans( AffineTransform trans ) { - this.trans = trans; + this._trans = trans; } private Shape getDeviceclip() { - return deviceclip; + return _deviceclip; } private void setDeviceclip( Shape deviceclip ) { - this.deviceclip = deviceclip; + this._deviceclip = deviceclip; } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java index 4c9d63ebc4..8cf3a8b550 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java @@ -28,15 +28,14 @@ import org.apache.poi.hssf.util.HSSFColor; * * @author Brian Sanders (bsanders at risklabs dot com) */ -public class HSSFPalette -{ - private PaletteRecord palette; - +public final class HSSFPalette { + private PaletteRecord _palette; + protected HSSFPalette(PaletteRecord palette) { - this.palette = palette; + _palette = palette; } - + /** * Retrieves the color at a given index * @@ -45,16 +44,15 @@ public class HSSFPalette */ public HSSFColor getColor(short index) { - //Handle the special AUTOMATIC case - if (index == HSSFColor.AUTOMATIC.index) - return HSSFColor.AUTOMATIC.getInstance(); - else { - byte[] b = palette.getColor(index); + //Handle the special AUTOMATIC case + if (index == HSSFColor.AUTOMATIC.index) { + return HSSFColor.AUTOMATIC.getInstance(); + } + byte[] b = _palette.getColor(index); if (b != null) { return new CustomColor(index, b); } - } return null; } /** @@ -66,7 +64,7 @@ public class HSSFPalette public HSSFColor getColor(int index) { return getColor((short)index); } - + /** * Finds the first occurance of a given color * @@ -77,9 +75,9 @@ public class HSSFPalette */ public HSSFColor findColor(byte red, byte green, byte blue) { - byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); - for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null; - b = palette.getColor(++i)) + byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); + for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null; + b = _palette.getColor(++i)) { if (b[0] == red && b[1] == green && b[2] == blue) { @@ -104,11 +102,11 @@ public class HSSFPalette { HSSFColor result = null; int minColorDistance = Integer.MAX_VALUE; - byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); - for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null; - b = palette.getColor(++i)) + byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); + for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null; + 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]); if (colorDistance < minColorDistance) { @@ -129,7 +127,7 @@ public class HSSFPalette */ 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 ) { - byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); + byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX); 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) { @@ -157,52 +155,51 @@ public class HSSFPalette throw new RuntimeException("Could not find free color index"); } - private static class CustomColor extends HSSFColor - { - private short byteOffset; - private byte red; - private byte green; - private byte blue; - - private CustomColor(short byteOffset, byte[] colors) + private static final class CustomColor extends HSSFColor { + private short _byteOffset; + private byte _red; + private byte _green; + private byte _blue; + + public CustomColor(short byteOffset, byte[] colors) { this(byteOffset, colors[0], colors[1], colors[2]); } - + private CustomColor(short byteOffset, byte red, byte green, byte blue) { - this.byteOffset = byteOffset; - this.red = red; - this.green = green; - this.blue = blue; + _byteOffset = byteOffset; + _red = red; + _green = green; + _blue = blue; } - + public short getIndex() { - return byteOffset; + return _byteOffset; } - + public short[] getTriplet() { return new short[] { - (short) (red & 0xff), - (short) (green & 0xff), - (short) (blue & 0xff) + (short) (_red & 0xff), + (short) (_green & 0xff), + (short) (_blue & 0xff) }; } - + public String getHexString() { StringBuffer sb = new StringBuffer(); - sb.append(getGnumericPart(red)); + sb.append(getGnumericPart(_red)); sb.append(':'); - sb.append(getGnumericPart(green)); + sb.append(getGnumericPart(_green)); sb.append(':'); - sb.append(getGnumericPart(blue)); + sb.append(getGnumericPart(_blue)); return sb.toString(); } - + private String getGnumericPart(byte color) { String s; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index e0a08420e8..0f98298a17 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -524,9 +524,9 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm * Sets the sheet name. * 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. - * 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. - * + * * @param sheetIx number (0 based) */ 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) { workbook.getWindowOne().setHidden(hiddenFlag); } - + public boolean isSheetHidden(int sheetIx) { validateSheetIndex(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 * be removed in future versions of POI. - * + * * @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table * @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record * @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); String name = getUniqueSheetName(srcName); - int newSheetIndex = _sheets.size(); + int newSheetIndex = _sheets.size(); _sheets.add(clonedSheet); workbook.setSheetName(newSheetIndex, name); - + // Check this sheet has an autofilter, (which has a built-in NameRecord at workbook level) int filterDbNameIndex = findExistingBuiltinNameRecordIdx(sheetIndex, NameRecord.BUILTIN_FILTER_DB); 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++) { Ptg ptg = ptgs[i]; ptg = ptg.copy(); - + if (ptg instanceof Area3DPtg) { Area3DPtg a3p = (Area3DPtg) ptg; a3p.setExternSheetIndex(newExtSheetIx); @@ -698,7 +698,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm workbook.cloneDrawings(clonedSheet.getSheet()); } // TODO - maybe same logic required for other/all built-in name records - + return clonedSheet; } @@ -966,12 +966,12 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm temp.add(new MemFuncPtg(exprsSize)); } 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); temp.add(colArea); } 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); temp.add(rowArea); } @@ -1136,7 +1136,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm */ public HSSFCellStyle getCellStyleAt(short idx) { - ExtendedFormatRecord xfr = workbook.getExFormatAt((int)idx); + ExtendedFormatRecord xfr = workbook.getExFormatAt(idx); HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this); return style; @@ -1296,7 +1296,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm int result = names.size(); return result; } - + public HSSFName getName(String name) { int nameIndex = getNameIndex(name); 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"); } 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) + ")."); } return (HSSFName) names.get(nameIndex); @@ -1394,7 +1394,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm if (name == null) { return null; } - + return HSSFFormulaParser.toFormulaString(this, name.getNameDefinition()); } @@ -1684,7 +1684,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm } } } - + public CreationHelper getCreationHelper() { return new HSSFCreationHelper(this); } diff --git a/src/java/org/apache/poi/hssf/util/RKUtil.java b/src/java/org/apache/poi/hssf/util/RKUtil.java index 27aecb06b3..b36166e29e 100644 --- a/src/java/org/apache/poi/hssf/util/RKUtil.java +++ b/src/java/org/apache/poi/hssf/util/RKUtil.java @@ -27,19 +27,16 @@ package org.apache.poi.hssf.util; * @see org.apache.poi.hssf.record.MulRKRecord * @see org.apache.poi.hssf.record.RKRecord */ -public class RKUtil -{ - private RKUtil() - { +public final class RKUtil { + private RKUtil() { + // no instances of this class } /** * Do the dirty work of decoding; made a private static method to * facilitate testing the algorithm */ - - public static double decodeNumber(int number) - { + public static double decodeNumber(int number) { long raw_number = number; // 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 // trivially by casting - rvalue = ( double ) (raw_number); + rvalue = raw_number; } else { @@ -72,5 +69,4 @@ public class RKUtil return rvalue; } - } diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java b/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java index b783035556..7e0df0013e 100644 --- a/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java +++ b/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java @@ -72,7 +72,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView private static DocumentBlock[] convertRawBlocksToBigBlocks(ListManagedBlock[] blocks) throws IOException { DocumentBlock[] result = new DocumentBlock[blocks.length]; for (int i = 0; i < result.length; i++) { - result[i] = new DocumentBlock((RawDataBlock)blocks[i]); + result[i] = new DocumentBlock((RawDataBlock)blocks[i]); } return result; } @@ -127,7 +127,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView * @param stream the InputStream we read data from */ public POIFSDocument(String name, InputStream stream) throws IOException { - List blocks = new ArrayList(); + List blocks = new ArrayList(); _size = 0; while (true) { @@ -142,7 +142,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView break; } } - DocumentBlock[] bigBlocks = (DocumentBlock[]) blocks.toArray(new DocumentBlock[blocks.size()]); + DocumentBlock[] bigBlocks = blocks.toArray(new DocumentBlock[blocks.size()]); _big_store = new BigBlockStore(bigBlocks); _property = new DocumentProperty(name, _size); @@ -201,7 +201,7 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView int len = buffer.length; DataInputBlock currentBlock = getDataInputBlock(offset); - + int blockAvailable = currentBlock.available(); if (blockAvailable > len) { currentBlock.readFully(buffer, 0, len); @@ -249,9 +249,8 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView } if (_property.shouldUseSmallBlocks()) { 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 ********** */ private static final class SmallBlockStore { - private SmallDocumentBlock[] smallBlocks; - private final POIFSDocumentPath path; - private final String name; - private final int size; - private final POIFSWriterListener writer; + private SmallDocumentBlock[] _smallBlocks; + private final POIFSDocumentPath _path; + private final String _name; + private final int _size; + private final POIFSWriterListener _writer; /** * Constructor @@ -389,11 +388,11 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView * @param blocks blocks to construct the store from */ SmallBlockStore(SmallDocumentBlock[] blocks) { - smallBlocks = (SmallDocumentBlock[]) blocks.clone(); - this.path = null; - this.name = null; - this.size = -1; - this.writer = null; + _smallBlocks = blocks.clone(); + this._path = null; + this._name = null; + this._size = -1; + 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 */ SmallBlockStore(POIFSDocumentPath path, String name, int size, POIFSWriterListener writer) { - smallBlocks = new SmallDocumentBlock[0]; - this.path = path; - this.name = name; - this.size = size; - this.writer = writer; + _smallBlocks = new SmallDocumentBlock[0]; + this._path = path; + this._name = name; + this._size = size; + this._writer = writer; } /** * @return true if this store is a valid source of data */ boolean isValid() { - return smallBlocks.length > 0 || writer != null; + return _smallBlocks.length > 0 || _writer != null; } /** * @return the SmallDocumentBlocks */ SmallDocumentBlock[] getBlocks() { - if (isValid() && writer != null) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(size); - DocumentOutputStream dstream = new DocumentOutputStream(stream, size); + if (isValid() && _writer != null) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(_size); + DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); - writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, path, name, size)); - smallBlocks = SmallDocumentBlock.convert(stream.toByteArray(), size); + _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); + _smallBlocks = SmallDocumentBlock.convert(stream.toByteArray(), _size); } - return smallBlocks; + return _smallBlocks; } } // end private class SmallBlockStore private static final class BigBlockStore { private DocumentBlock[] bigBlocks; - private final POIFSDocumentPath path; - private final String name; - private final int size; - private final POIFSWriterListener writer; + private final POIFSDocumentPath _path; + private final String _name; + private final int _size; + private final POIFSWriterListener _writer; /** * Constructor @@ -447,11 +446,11 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView * @param blocks the blocks making up the store */ BigBlockStore(DocumentBlock[] blocks) { - bigBlocks = (DocumentBlock[]) blocks.clone(); - this.path = null; - this.name = null; - this.size = -1; - this.writer = null; + bigBlocks = blocks.clone(); + _path = null; + _name = null; + _size = -1; + _writer = null; } /** @@ -464,29 +463,29 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView */ BigBlockStore(POIFSDocumentPath path, String name, int size, POIFSWriterListener writer) { bigBlocks = new DocumentBlock[0]; - this.path = path; - this.name = name; - this.size = size; - this.writer = writer; + _path = path; + _name = name; + _size = size; + _writer = writer; } /** * @return true if this store is a valid source of data */ boolean isValid() { - return bigBlocks.length > 0 || writer != null; + return bigBlocks.length > 0 || _writer != null; } /** * @return the DocumentBlocks */ DocumentBlock[] getBlocks() { - if (isValid() && writer != null) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(size); - DocumentOutputStream dstream = new DocumentOutputStream(stream, size); + if (isValid() && _writer != null) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(_size); + DocumentOutputStream dstream = new DocumentOutputStream(stream, _size); - writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, path, name, size)); - bigBlocks = DocumentBlock.convert(stream.toByteArray(), size); + _writer.processPOIFSWriterEvent(new POIFSWriterEvent(dstream, _path, _name, _size)); + bigBlocks = DocumentBlock.convert(stream.toByteArray(), _size); } return bigBlocks; } @@ -498,10 +497,10 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView */ void writeBlocks(OutputStream stream) throws IOException { if (isValid()) { - if (writer != null) { - DocumentOutputStream dstream = new DocumentOutputStream(stream, size); + if (_writer != null) { + 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, DocumentBlock.getFillByte()); } else { @@ -518,10 +517,10 @@ public final class POIFSDocument implements BATManaged, BlockWritable, POIFSView int countBlocks() { if (isValid()) { - if (writer == null) { + if (_writer == null) { return bigBlocks.length; } - return (size + POIFSConstants.BIG_BLOCK_SIZE - 1) + return (_size + POIFSConstants.BIG_BLOCK_SIZE - 1) / POIFSConstants.BIG_BLOCK_SIZE; } return 0; diff --git a/src/java/org/apache/poi/poifs/property/Property.java b/src/java/org/apache/poi/poifs/property/Property.java index fe0e8d9b48..c1e8c0e1c1 100644 --- a/src/java/org/apache/poi/poifs/property/Property.java +++ b/src/java/org/apache/poi/poifs/property/Property.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.poifs.property; @@ -39,9 +39,7 @@ import org.apache.poi.util.ShortField; * @author Marc Johnson (mjohnson at apache dot org) */ -public abstract class Property - implements Child, POIFSViewable -{ +public abstract class Property implements Child, POIFSViewable { static final private byte _default_fill = ( byte ) 0x00; static final private int _name_size_offset = 0x40; static final private int _max_name_length = @@ -88,10 +86,6 @@ public abstract class Property private Child _next_child; private Child _previous_child; - /** - * Default constructor - */ - protected Property() { _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; @@ -129,8 +123,7 @@ public abstract class Property * @param array byte data * @param offset offset into byte data */ - - protected Property(final int index, final byte [] array, final int offset) + protected Property(int index, byte [] array, int offset) { _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; System.arraycopy(array, offset, _raw_data, 0, @@ -187,8 +180,7 @@ public abstract class Property * @exception IOException on problems writing to the specified * stream. */ - - public void writeData(final OutputStream stream) + public void writeData(OutputStream stream) throws IOException { stream.write(_raw_data); @@ -200,8 +192,7 @@ public abstract class Property * * @param startBlock the start block index */ - - public void setStartBlock(final int startBlock) + public void setStartBlock(int startBlock) { _start_block.set(startBlock, _raw_data); } @@ -209,7 +200,6 @@ public abstract class Property /** * @return the start block */ - public int getStartBlock() { return _start_block.get(); @@ -220,7 +210,6 @@ public abstract class Property * * @return size in bytes */ - public int getSize() { return _size.get(); @@ -232,7 +221,6 @@ public abstract class Property * * @return true if the size is less than _big_block_minimum_bytes */ - public boolean shouldUseSmallBlocks() { return Property.isSmall(_size.get()); @@ -246,8 +234,7 @@ public abstract class Property * @return true if the length is less than * _big_block_minimum_bytes */ - - public static boolean isSmall(final int length) + public static boolean isSmall(int length) { return length < _big_block_minimum_bytes; } @@ -257,7 +244,6 @@ public abstract class Property * * @return property name as String */ - public String getName() { return _name; @@ -266,7 +252,6 @@ public abstract class Property /** * @return true if a directory type Property */ - abstract public boolean isDirectory(); /** @@ -284,7 +269,7 @@ public abstract class Property * * @param name the new name */ - protected final void setName(final String name) + protected void setName(String name) { char[] char_array = name.toCharArray(); 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) */ - - protected void setPropertyType(final byte propertyType) + protected void setPropertyType(byte propertyType) { _property_type.set(propertyType, _raw_data); } @@ -340,8 +324,7 @@ public abstract class Property * * @param nodeColor the node color (red or black) */ - - protected void setNodeColor(final byte nodeColor) + protected void setNodeColor(byte nodeColor) { _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 */ - - protected void setChildProperty(final int child) + protected void setChildProperty(int child) { _child_property.set(child, _raw_data); } @@ -362,7 +344,6 @@ public abstract class Property * * @return child property index */ - protected int getChildIndex() { return _child_property.get(); @@ -373,8 +354,7 @@ public abstract class Property * * @param size the size of the document, in bytes */ - - protected void setSize(final int size) + protected void setSize(int size) { _size.set(size, _raw_data); } @@ -385,8 +365,7 @@ public abstract class Property * @param index this Property's index within its containing * Property Table */ - - protected void setIndex(final int index) + protected void setIndex(int index) { _index = index; } @@ -396,7 +375,6 @@ public abstract class Property * * @return the index of this Property within its Property Table */ - protected int getIndex() { return _index; @@ -406,7 +384,6 @@ public abstract class Property * Perform whatever activities need to be performed prior to * writing */ - abstract protected void preWrite(); /** @@ -414,7 +391,6 @@ public abstract class Property * * @return index of next sibling */ - int getNextChildIndex() { return _next_property.get(); @@ -425,7 +401,6 @@ public abstract class Property * * @return index of previous sibling */ - int getPreviousChildIndex() { return _previous_property.get(); @@ -438,20 +413,16 @@ public abstract class Property * * @return true if the index is valid */ - static boolean isValidIndex(int index) { return index != _NO_INDEX; } - /* ********** START implementation of Child ********** */ - /** * Get the next Child, if any * * @return the next Child; may return null */ - public Child getNextChild() { return _next_child; @@ -462,7 +433,6 @@ public abstract class Property * * @return the previous Child; may return null */ - public Child getPreviousChild() { return _previous_child; @@ -474,8 +444,7 @@ public abstract class Property * @param child the new 'next' child; may be null, which has the * effect of saying there is no 'next' child */ - - public void setNextChild(final Child child) + public void setNextChild(Child child) { _next_child = child; _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 * the effect of saying there is no 'previous' child */ - - public void setPreviousChild(final Child child) + public void setPreviousChild(Child child) { _previous_child = child; _previous_property.set((child == null) ? _NO_INDEX @@ -498,16 +466,12 @@ public abstract class Property .getIndex(), _raw_data); } - /* ********** END implementation of Child ********** */ - /* ********** START begin implementation of POIFSViewable ********** */ - /** * Get an array of objects, some of which may implement * POIFSViewable * * @return an array of Object; may not be null, but may be empty */ - public Object [] getViewableArray() { Object[] results = new Object[ 5 ]; @@ -518,11 +482,11 @@ public abstract class Property long time = _days_1.get(); time <<= 32; - time += (( long ) _seconds_1.get()) & 0x0000FFFFL; + time += _seconds_1.get() & 0x0000FFFFL; results[ 3 ] = "Time 1 = " + time; time = _days_2.get(); time <<= 32; - time += (( long ) _seconds_2.get()) & 0x0000FFFFL; + time += _seconds_2.get() & 0x0000FFFFL; results[ 4 ] = "Time 2 = " + time; return results; } @@ -534,7 +498,6 @@ public abstract class Property * @return an Iterator; may not be null, but may have an empty * back end store */ - public Iterator getViewableIterator() { return Collections.EMPTY_LIST.iterator(); @@ -547,7 +510,6 @@ public abstract class Property * @return true if a viewer should call getViewableArray, false if * a viewer should call getViewableIterator */ - public boolean preferArray() { return true; @@ -559,7 +521,6 @@ public abstract class Property * * @return short description */ - public String getShortDescription() { StringBuffer buffer = new StringBuffer(); @@ -567,7 +528,4 @@ public abstract class Property buffer.append("Property: \"").append(getName()).append("\""); return buffer.toString(); } - - /* ********** END begin implementation of POIFSViewable ********** */ -} // end public abstract class Property - +} diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java index b0c7e2d464..abb925713e 100644 --- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java @@ -393,8 +393,7 @@ public final class WorkbookEvaluator { return fe.getFreeRefFunction().evaluate(ops, workbook, sheetIndex, srcRowNum, srcColNum); } } - // TODO - fix return type of this evaluate method: - return (ValueEval) operation.evaluate(ops, srcRowNum, (short)srcColNum); + return operation.evaluate(ops, srcRowNum, (short)srcColNum); } private SheetRefEvaluator createExternSheetRefEvaluator(EvaluationTracker tracker, ExternSheetReferenceToken ptg) { diff --git a/src/java/org/apache/poi/ss/util/Region.java b/src/java/org/apache/poi/ss/util/Region.java index 27fc792c45..d0c373838c 100644 --- a/src/java/org/apache/poi/ss/util/Region.java +++ b/src/java/org/apache/poi/ss/util/Region.java @@ -26,197 +26,183 @@ package org.apache.poi.ss.util; * @author Andrew C. Oliver acoliver at apache dot org * @deprecated (Aug-2008) use {@link CellRangeAddress} */ -public class Region implements Comparable { - private int rowFrom; - private short colFrom; - private int rowTo; - private short colTo; - - /** - * Creates a new instance of Region (0,0 - 0,0) - */ - - 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(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(); +public class Region implements Comparable { + private int _rowFrom; + private short _colFrom; + private int _rowTo; + private short _colTo; + + /** + * Creates a new instance of Region (0,0 - 0,0) + */ + 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(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 = cellReferenceFrom.getCol(); + this._rowTo = cellReferenceTo.getRow(); + this._colTo = cellReferenceTo.getCol(); + } + + + /** + * get the upper left hand corner column number + * + * @return column number for the upper left hand corner + */ + public short getColumnFrom() + { + 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 + */ - /** - * get the upper left hand corner column number - * - * @return column number for the upper left hand corner - */ - - public short getColumnFrom() - { - 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 true if the cell is in the range and - * false 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); - } - + public void setColumnTo(short colTo) + { + this._colTo = colTo; + } /** - * Convert a List of CellRange objects to an array of regions - * + * 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 true if the cell is in the range and + * false 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 * @return regions */ @@ -225,7 +211,7 @@ public class Region implements Comparable { if(size < 1) { return new Region[0]; } - + Region[] result = new Region[size]; for (int i = 0; i != size; i++) { @@ -235,9 +221,9 @@ public class Region implements Comparable { } - + private static Region convertToRegion(CellRangeAddress cr) { - + 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) { return new CellRangeAddress[0]; } - + CellRangeAddress[] result = new CellRangeAddress[size]; 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 the string reference for this region - */ - public String getRegionRef() { - CellReference cellRefFrom = new CellReference(rowFrom, colFrom); - CellReference cellRefTo = new CellReference(rowTo, colTo); - String ref = cellRefFrom.formatAsString() + ":" + cellRefTo.formatAsString(); + /** + * @return the string reference for this region + */ + public String getRegionRef() { + CellReference cellRefFrom = new CellReference(_rowFrom, _colFrom); + CellReference cellRefTo = new CellReference(_rowTo, _colTo); + String ref = cellRefFrom.formatAsString() + ":" + cellRefTo.formatAsString(); return ref; - } + } } diff --git a/src/java/org/apache/poi/util/BinaryTree.java b/src/java/org/apache/poi/util/BinaryTree.java index 58d7820b4f..551d588789 100644 --- a/src/java/org/apache/poi/util/BinaryTree.java +++ b/src/java/org/apache/poi/util/BinaryTree.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -89,34 +87,20 @@ import java.util.*; * * @author Marc Johnson (mjohnson at apache dot org) */ -public final class BinaryTree // final for performance - - extends AbstractMap -{ - private Node[] _root = new Node[] - { - null, null - }; - private int _size = 0; - private int _modifications = 0; - private Set[] _key_set = new Set[] - { - null, null - }; - 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[] +//for performance +public class BinaryTree extends AbstractMap { + final Node[] _root; + int _size = 0; + int _modifications = 0; + private final Set[] _key_set = new Set[] { null, null }; + private final Set[] _entry_set = new Set[] { null, null }; + private final Collection[] _value_collection = new Collection[] { null, null }; + static int _KEY = 0; + static int _VALUE = 1; + private static int _INDEX_SUM = _KEY + _VALUE; + private static int _MINIMUM_INDEX = 0; + private static int _INDEX_COUNT = 2; + private static String[] _data_name = new String[] { "key", "value" }; @@ -124,9 +108,8 @@ public final class BinaryTree // final for performance /** * 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 * map */ - - public BinaryTree(final Map map) + public BinaryTree(Map map) throws ClassCastException, NullPointerException, IllegalArgumentException { + this(); putAll(map); } @@ -167,8 +150,7 @@ public final class BinaryTree // final for performance * inappropriate type for this map. * @exception NullPointerException if the value is null */ - - public Object getKeyForValue(final Object value) + public Object getKeyForValue(Object value) throws ClassCastException, NullPointerException { 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 * if there was no mapping for value. */ - - public Object removeValue(final Object value) + public Object removeValue(Object 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. */ - public Set entrySetByValue() { 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 * found */ - - private Object doRemove(final Comparable o, final int index) + private Object doRemove(Comparable o, int index) { Node node = lookup(o, index); 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 * object */ - - private Object doGet(final Comparable o, final int index) + private Object doGet(Comparable o, int index) { checkNonNullComparable(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 */ - - private int oppositeIndex(final int index) + private int oppositeIndex(int index) { // 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 * specified data */ - - private Node lookup(final Comparable data, final int index) + public Node lookup(Comparable data, int index) { Node rval = null; Node node = _root[ index ]; @@ -498,11 +474,8 @@ public final class BinaryTree // final for performance rval = node; break; } - else - { - node = (cmp < 0) ? node.getLeft(index) - : node.getRight(index); - } + node = (cmp < 0) ? node.getLeft(index) + : node.getRight(index); } return rval; } @@ -516,10 +489,9 @@ public final class BinaryTree // final for performance * @return negative value if o1 < o2; 0 if o1 == o2; positive * value if o1 > o2 */ - - private static int compare(final Comparable o1, final Comparable o2) + private static int compare(Comparable o1, 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 * specified mapping */ - - private static Node leastNode(final Node node, final int index) + static Node leastNode(Node node, int index) { Node rval = node; @@ -555,8 +526,7 @@ public final class BinaryTree // final for performance * * @return the specified node */ - - private Node nextGreater(final Node node, final int index) + static Node nextGreater(Node node, int index) { 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 index _KEY or _VALUE */ - - private static void copyColor(final Node from, final Node to, - final int index) + private static void copyColor(Node from, Node to, int index) { if (to != null) { @@ -627,11 +595,9 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static boolean isRed(final Node node, final int index) + private static boolean isRed(Node node, int index) { - return ((node == null) ? false - : node.isRed(index)); + return node == null ? false : node.isRed(index); } /** @@ -641,11 +607,9 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static boolean isBlack(final Node node, final int index) + private static boolean isBlack(Node node, int index) { - return ((node == null) ? true - : node.isBlack(index)); + return node == null ? true : node.isBlack(index); } /** @@ -654,8 +618,7 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static void makeRed(final Node node, final int index) + private static void makeRed(Node node, int index) { if (node != null) { @@ -669,8 +632,7 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static void makeBlack(final Node node, final int index) + private static void makeBlack(Node node, int index) { if (node != null) { @@ -685,8 +647,7 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static Node getGrandParent(final Node node, final int index) + private static Node getGrandParent(Node node, int 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 index _KEY or _VALUE */ - - private static Node getParent(final Node node, final int index) + private static Node getParent(Node node, int index) { return ((node == null) ? null : node.getParent(index)); @@ -712,8 +672,7 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static Node getRightChild(final Node node, final int index) + private static Node getRightChild(Node node, int index) { return (node == null) ? null : node.getRight(index); @@ -726,8 +685,7 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static Node getLeftChild(final Node node, final int index) + private static Node getLeftChild(Node node, int index) { return (node == null) ? null : node.getLeft(index); @@ -744,15 +702,14 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static boolean isLeftChild(final Node node, final int index) - { - return (node == null) ? true - : ((node.getParent(index) == null) ? false - : (node - == node.getParent( - index).getLeft( - index))); + private static boolean isLeftChild(Node node, int index) { + if (node == null) { + return true; + } + if (node.getParent(index) == null) { + return false; + } + return node == node.getParent(index).getLeft(index); } /** @@ -766,15 +723,15 @@ public final class BinaryTree // final for performance * @param node the node (may be null) in question * @param index _KEY or _VALUE */ - - private static boolean isRightChild(final Node node, final int index) + private static boolean isRightChild(Node node, int index) { - return (node == null) ? true - : ((node.getParent(index) == null) ? false - : (node - == node.getParent( - index).getRight( - index))); + if (node == null) { + return true; + } + if (node.getParent(index) == null) { + return false; + } + 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 index _KEY or _VALUE */ - - private void rotateLeft(final Node node, final int index) + private void rotateLeft(Node node, int 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 index _KEY or _VALUE */ - - private void rotateRight(final Node node, final int index) + private void rotateRight(Node node, int 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 index _KEY or _VALUE */ - - private void doRedBlackInsert(final Node inserted_node, final int index) + private void doRedBlackInsert(Node inserted_node, int index) { Node current_node = inserted_node; @@ -931,8 +885,7 @@ public final class BinaryTree // final for performance * * @param deleted_node the node to be deleted */ - - private void doRedBlackDelete(final Node deleted_node) + void doRedBlackDelete(Node deleted_node) { 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 index _KEY or _VALUE */ - - private void doRedBlackDeleteFixup(final Node replacement_node, - final int index) + private void doRedBlackDeleteFixup(Node replacement_node, + int index) { Node current_node = replacement_node; @@ -1121,8 +1073,7 @@ public final class BinaryTree // final for performance * @param y another node * @param index _KEY or _VALUE */ - - private void swapPosition(final Node x, final Node y, final int index) + private void swapPosition(Node x, Node y, int index) { // Save initial values. @@ -1244,9 +1195,8 @@ public final class BinaryTree // final for performance * @exception NullPointerException if o is null * @exception ClassCastException if o is not Comparable */ - - private static void checkNonNullComparable(final Object o, - final int index) + private static void checkNonNullComparable(Object o, + int index) { if (o == null) { @@ -1268,8 +1218,7 @@ public final class BinaryTree // final for performance * @exception NullPointerException if key is null * @exception ClassCastException if key is not Comparable */ - - private static void checkKey(final Object key) + private static void checkKey(Object key) { checkNonNullComparable(key, _KEY); } @@ -1282,8 +1231,7 @@ public final class BinaryTree // final for performance * @exception NullPointerException if value is null * @exception ClassCastException if value is not Comparable */ - - private static void checkValue(final Object value) + private static void checkValue(Object value) { checkNonNullComparable(value, _VALUE); } @@ -1298,8 +1246,7 @@ public final class BinaryTree // final for performance * @exception NullPointerException if key or value is null * @exception ClassCastException if key or value is not Comparable */ - - private static void checkKeyAndValue(final Object key, final Object value) + private static void checkKeyAndValue(Object key, Object value) { checkKey(key); checkValue(value); @@ -1310,7 +1257,6 @@ public final class BinaryTree // final for performance * concurrent modification of the map through the map and through * an Iterator from one of its Set or Collection views */ - private void modify() { _modifications++; @@ -1319,7 +1265,6 @@ public final class BinaryTree // final for performance /** * bump up the size and note that the map has changed */ - private void grow() { modify(); @@ -1329,7 +1274,6 @@ public final class BinaryTree // final for performance /** * decrement the size and note that the map has changed */ - private void shrink() { modify(); @@ -1344,8 +1288,7 @@ public final class BinaryTree // final for performance * @exception IllegalArgumentException if the node already exists * in the value mapping */ - - private void insertValue(final Node newNode) + private void insertValue(Node newNode) throws IllegalArgumentException { 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. */ - public int size() { return _size; @@ -1419,8 +1361,7 @@ public final class BinaryTree // final for performance * type for this map. * @exception NullPointerException if the key is null */ - - public boolean containsKey(final Object key) + public boolean containsKey(Object key) throws ClassCastException, NullPointerException { 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 * value. */ - - public boolean containsValue(final Object value) + public boolean containsValue(Object value) { checkValue(value); return lookup(( Comparable ) value, _VALUE) != null; @@ -1456,8 +1396,7 @@ public final class BinaryTree // final for performance * type for this map. * @exception NullPointerException if the key is null */ - - public Object get(final Object key) + public Object get(Object key) throws ClassCastException, NullPointerException { return doGet(( Comparable ) key, _KEY); @@ -1483,8 +1422,7 @@ public final class BinaryTree // final for performance * value duplicates an * existing value */ - - public Object put(final Object key, final Object value) + public Object put(Object key, Object value) throws ClassCastException, NullPointerException, IllegalArgumentException { @@ -1562,8 +1500,7 @@ public final class BinaryTree // final for performance * @return previous value associated with specified key, or null * if there was no mapping for key. */ - - public Object remove(final Object key) + public Object remove(Object key) { return doRemove(( Comparable ) key, _KEY); } @@ -1571,7 +1508,6 @@ public final class BinaryTree // final for performance /** * Removes all mappings from this map */ - public void clear() { modify(); @@ -1592,7 +1528,6 @@ public final class BinaryTree // final for performance * * @return a set view of the keys contained in this map. */ - public Set keySet() { 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. */ - public Collection values() { 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. */ - public Set entrySet() { if (_entry_set[ _KEY ] == null) @@ -1803,8 +1736,7 @@ public final class BinaryTree // final for performance * * @param type */ - - BinaryTreeIterator(final int type) + BinaryTreeIterator(int type) { _type = type; _expected_modifications = BinaryTree.this._modifications; @@ -1825,7 +1757,7 @@ public final class BinaryTree // final for performance * @return true if the iterator has more elements. */ - public final boolean hasNext() + public boolean hasNext() { return _next_node != null; } @@ -1842,7 +1774,7 @@ public final class BinaryTree // final for performance * back */ - public final Object next() + public Object next() throws NoSuchElementException, ConcurrentModificationException { if (_next_node == null) @@ -1878,7 +1810,7 @@ public final class BinaryTree // final for performance * back */ - public final void remove() + public void remove() throws IllegalStateException, ConcurrentModificationException { if (_last_returned_node == null) @@ -1897,7 +1829,7 @@ public final class BinaryTree // final for performance /* ********** END implementation of Iterator ********** */ } // end private abstract class BinaryTreeIterator - // final for performance + // for performance private static final class Node implements Map.Entry { @@ -1917,7 +1849,7 @@ public final class BinaryTree // final for performance * @param value */ - Node(final Comparable key, final Comparable value) + Node(Comparable key, Comparable value) { _data = new Comparable[] { @@ -1949,8 +1881,7 @@ public final class BinaryTree // final for performance * * @return the key or value */ - - private Comparable getData(final int index) + public Comparable getData(int index) { return _data[ index ]; } @@ -1961,8 +1892,7 @@ public final class BinaryTree // final for performance * @param node the new left node * @param index _KEY or _VALUE */ - - private void setLeft(final Node node, final int index) + public void setLeft(Node node, int index) { _left[ index ] = node; } @@ -1975,7 +1905,7 @@ public final class BinaryTree // final for performance * @return the left node -- may be null */ - private Node getLeft(final int index) + public Node getLeft(int index) { return _left[ index ]; } @@ -1986,8 +1916,7 @@ public final class BinaryTree // final for performance * @param node the new right node * @param index _KEY or _VALUE */ - - private void setRight(final Node node, final int index) + public void setRight(Node node, int index) { _right[ index ] = node; } @@ -2000,7 +1929,7 @@ public final class BinaryTree // final for performance * @return the right node -- may be null */ - private Node getRight(final int index) + public Node getRight(int index) { return _right[ index ]; } @@ -2011,8 +1940,7 @@ public final class BinaryTree // final for performance * @param node the new parent node * @param index _KEY or _VALUE */ - - private void setParent(final Node node, final int index) + public void setParent(Node node, int index) { _parent[ index ] = node; } @@ -2024,8 +1952,7 @@ public final class BinaryTree // final for performance * * @return the parent node -- may be null */ - - private Node getParent(final int index) + public Node getParent(int index) { return _parent[ index ]; } @@ -2036,8 +1963,7 @@ public final class BinaryTree // final for performance * @param node the node to swap with * @param index _KEY or _VALUE */ - - private void swapColors(final Node node, final int index) + public void swapColors(Node node, int index) { // 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) */ - - private boolean isBlack(final int index) + public boolean isBlack(int index) { return _black[ index ]; } @@ -2066,8 +1991,7 @@ public final class BinaryTree // final for performance * * @return true if non-black */ - - private boolean isRed(final int index) + public boolean isRed(int index) { return !_black[ index ]; } @@ -2077,8 +2001,7 @@ public final class BinaryTree // final for performance * * @param index _KEY or _VALUE */ - - private void setBlack(final int index) + public void setBlack(int index) { _black[ index ] = true; } @@ -2088,8 +2011,7 @@ public final class BinaryTree // final for performance * * @param index _KEY or _VALUE */ - - private void setRed(final int index) + public void setRed(int index) { _black[ index ] = false; } @@ -2100,8 +2022,7 @@ public final class BinaryTree // final for performance * @param node the node whose color we're adopting * @param index _KEY or _VALUE */ - - private void copyColor(final Node node, final int index) + public void copyColor(Node node, int index) { _black[ index ] = node._black[ index ]; } @@ -2111,7 +2032,6 @@ public final class BinaryTree // final for performance /** * @return the key corresponding to this entry. */ - public Object getKey() { return _data[ _KEY ]; @@ -2120,7 +2040,6 @@ public final class BinaryTree // final for performance /** * @return the value corresponding to this entry. */ - public Object getValue() { return _data[ _VALUE ]; @@ -2133,10 +2052,7 @@ public final class BinaryTree // final for performance * @param ignored * * @return does not return - * - * @exception UnsupportedOperationException */ - public Object setValue(Object ignored) throws UnsupportedOperationException { @@ -2154,7 +2070,6 @@ public final class BinaryTree // final for performance * @return true if the specified object is equal to this map * entry. */ - public boolean equals(Object o) { if (this == o) @@ -2188,5 +2103,4 @@ public final class BinaryTree // final for performance /* ********** END implementation of Map.Entry ********** */ } -} // end public class BinaryTree - +} diff --git a/src/java/org/apache/poi/util/POILogger.java b/src/java/org/apache/poi/util/POILogger.java index 514edf90ca..caf2035ac7 100644 --- a/src/java/org/apache/poi/util/POILogger.java +++ b/src/java/org/apache/poi/util/POILogger.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -31,34 +29,32 @@ import java.util.*; * @author Glen Stampoultzis (glens at apache.org) * @author Nicola Ken Barozzi (nicolaken at apache.org) */ +public abstract class POILogger { -public abstract class POILogger -{ - - public static final int DEBUG = 1; - public static final int INFO = 3; - public static final int WARN = 5; - public static final int ERROR = 7; - public static final int FATAL = 9; + public static int DEBUG = 1; + public static int INFO = 3; + public static int WARN = 5; + public static int ERROR = 7; + public static int FATAL = 9; /** * package scope so it cannot be instantiated outside of the util * package. You need a POILogger? Go to the POILogFactory for one - * */ - POILogger() - {} - - abstract public void initialize(final String cat); - + POILogger() { + // no fields to initialise + } + + abstract public void initialize(String cat); + /** * Log a message * * @param level One of DEBUG, INFO, WARN, ERROR, FATAL * @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 * @@ -66,7 +62,7 @@ public abstract class POILogger * @param obj1 The object to log. This is converted to a string. * @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); @@ -75,15 +71,7 @@ public abstract class POILogger * * @param level One of DEBUG, INFO, WARN, ERROR, FATAL */ - abstract public boolean check(final 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 - */ + abstract public boolean check(int level); /** * 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 obj2 second object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2) + public void log(int level, Object obj1, Object obj2) { if (check(level)) { @@ -109,11 +96,10 @@ public abstract class POILogger * @param obj2 second Object to place in the message * @param obj3 third Object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3) + public void log(int level, Object obj1, Object obj2, + Object obj3) { - + if (check(level)) { @@ -132,11 +118,10 @@ public abstract class POILogger * @param obj3 third Object to place in the message * @param obj4 fourth Object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4) + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4) { - + if (check(level)) { @@ -156,11 +141,10 @@ public abstract class POILogger * @param obj4 fourth Object to place in the message * @param obj5 fifth Object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5) + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5) { - + if (check(level)) { @@ -181,12 +165,11 @@ public abstract class POILogger * @param obj5 fifth Object to place in the message * @param obj6 sixth Object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, - final Object obj6) + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, + Object obj6) { - + if (check(level)) { @@ -208,12 +191,11 @@ public abstract class POILogger * @param obj6 sixth Object to place in the message * @param obj7 seventh Object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, - final Object obj6, final Object obj7) + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, + Object obj6, Object obj7) { - + if (check(level)) { @@ -237,12 +219,11 @@ public abstract class POILogger * @param obj7 seventh Object to place in the message * @param obj8 eighth Object to place in the message */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, - final Object obj6, final Object obj7, final Object obj8) + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, + Object obj6, Object obj7, Object obj8) { - + if (check(level)) { @@ -259,8 +240,7 @@ public abstract class POILogger * @param level One of DEBUG, INFO, WARN, ERROR, FATAL * @param exception An exception to be logged */ - - public void log(final int level, final Throwable exception) + public void log(int level, final Throwable exception) { log(level, null, exception); } @@ -273,11 +253,10 @@ public abstract class POILogger * @param obj2 second Object to place in the message * @param exception An exception to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, + public void log(int level, Object obj1, Object obj2, final Throwable exception) { - + if (check(level)) { @@ -295,11 +274,10 @@ public abstract class POILogger * @param obj3 third object to place in the message * @param exception An error message to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Throwable exception) + public void log(int level, Object obj1, Object obj2, + Object obj3, final Throwable exception) { - + if (check(level)) { @@ -318,12 +296,11 @@ public abstract class POILogger * @param obj4 fourth object to place in the message * @param exception An exception to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, final Throwable exception) { - + if (check(level)) { @@ -343,12 +320,11 @@ public abstract class POILogger * @param obj5 fifth object to place in the message * @param exception An exception to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, final Throwable exception) { - + if (check(level)) { @@ -369,12 +345,11 @@ public abstract class POILogger * @param obj6 sixth object to place in the message * @param exception An exception to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, - final Object obj6, final Throwable exception) + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, + Object obj6, final Throwable exception) { - + if (check(level)) { @@ -397,13 +372,12 @@ public abstract class POILogger * @param obj7 seventh object to place in the message * @param exception An exception to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, - final Object obj6, final Object obj7, + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, + Object obj6, Object obj7, final Throwable exception) { - + if (check(level)) { @@ -427,13 +401,12 @@ public abstract class POILogger * @param obj8 eighth object to place in the message * @param exception An exception to be logged */ - - public void log(final int level, final Object obj1, final Object obj2, - final Object obj3, final Object obj4, final Object obj5, - final Object obj6, final Object obj7, final Object obj8, + public void log(int level, Object obj1, Object obj2, + Object obj3, Object obj4, Object obj5, + Object obj6, Object obj7, Object obj8, final Throwable exception) { - + if (check(level)) { @@ -467,9 +440,8 @@ public abstract class POILogger * @param message The message to log. * @param obj1 The first object to match against. */ - - public void logFormatted(final int level, final String message, - final Object obj1) + public void logFormatted(int level, String message, + Object obj1) { commonLogFormatted(level, message, new Object[] { @@ -502,9 +474,8 @@ public abstract class POILogger * @param obj1 The first object to match against. * @param obj2 The second object to match against. */ - - public void logFormatted(final int level, final String message, - final Object obj1, final Object obj2) + public void logFormatted(int level, String message, + Object obj1, Object obj2) { commonLogFormatted(level, message, new Object[] { @@ -538,10 +509,9 @@ public abstract class POILogger * @param obj2 The second object to match against. * @param obj3 The third object to match against. */ - - public void logFormatted(final int level, final String message, - final Object obj1, final Object obj2, - final Object obj3) + public void logFormatted(int level, String message, + Object obj1, Object obj2, + Object obj3) { commonLogFormatted(level, message, new Object[] { @@ -576,21 +546,20 @@ public abstract class POILogger * @param obj3 The third object to match against. * @param obj4 The forth object to match against. */ - - public void logFormatted(final int level, final String message, - final Object obj1, final Object obj2, - final Object obj3, final Object obj4) + public void logFormatted(int level, String message, + Object obj1, Object obj2, + Object obj3, Object obj4) { commonLogFormatted(level, message, new Object[] { obj1, obj2, obj3, obj4 }); - } + } - private void commonLogFormatted(final int level, final String message, - final Object [] unflatParams) + private void commonLogFormatted(int level, String message, + Object [] unflatParams) { - + if (check(level)) { @@ -611,21 +580,20 @@ public abstract class POILogger /** * Flattens any contained objects. Only tranverses one level deep. */ - - private Object [] flattenArrays(final Object [] objects) + private Object [] flattenArrays(Object [] objects) { - List results = new ArrayList(); + List results = new ArrayList(); for (int i = 0; i < objects.length; 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 objectToObjectArray(Object object) { - List results = new ArrayList(); + List results = new ArrayList(); if (object instanceof byte []) { @@ -705,6 +673,4 @@ public abstract class POILogger } return results; } - -} // end package scope abstract class POILogger - +} diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index 4efe6bdd89..5952d9122d 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -52,7 +52,7 @@ import org.apache.poi.util.POILogFactory; /** * Represents a container that can store multiple data objects. - * + * * @author Julien Chable, CDubet * @version 0.1 */ @@ -125,7 +125,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Constructor. - * + * * @param access * Package access. */ @@ -166,7 +166,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Open a package with read/write permission. - * + * * @param path * The document path. * @return A Package object, else null. @@ -180,7 +180,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Open a package. - * + * * @param path * The document path. * @param access @@ -206,11 +206,11 @@ public abstract class OPCPackage implements RelationshipSource { /** * Open a package. - * + * * 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 * of native methods - * + * * @param in * The InputStream to read the package from * @return A PackageBase object @@ -226,7 +226,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Opens a package if it exists, else it creates one. - * + * * @param file * The file to open or to create. * @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. - * + * * @param path * Path of the document. * @return A newly created PackageBase ready to use. @@ -257,7 +257,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Creates a new package. - * + * * @param file * Path of the document. * @return A newly created PackageBase ready to use. @@ -292,7 +292,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Configure the package. - * + * * @param pkg */ private static void configurePackage(OPCPackage pkg) { @@ -324,7 +324,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Flush the package : save all. - * + * * @see #close() */ public void flush() { @@ -339,7 +339,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Close the package and save its content. - * + * * @throws IOException * 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 * the addition of a thumbnail in a package. You can do the same work by * using the traditionnal relationship and part mechanism. - * + * * @param path * 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 * (PackageAccess.Read). - * + * * @throws InvalidOperationException * Throws if a writing operation is done on a read only package. * @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 * (PackageAccess.Write). This method is call when other methods need write * right. - * + * * @throws InvalidOperationException * Throws if a read operation is done on a write only package. * @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. - * + * * @return The PackageProperties part of this package. */ public PackageProperties getPackageProperties() @@ -487,7 +487,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Retrieve a part identified by its name. - * + * * @param partName * Part name of the part to retrieve. * @return The part with the specified name, else null. @@ -511,7 +511,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Retrieve parts by content type. - * + * * @param contentType * The content type criteria. * @return All part associated to the specified content type. @@ -527,7 +527,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Retrieve parts by relationship type. - * + * * @param relationshipType * Relationship type. * @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. - * + * * @param partRel * 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 * relationships of each part are not loaded - * + * * @return All this package's parts. */ public ArrayList getParts() throws InvalidFormatException { @@ -588,10 +588,10 @@ public abstract class OPCPackage implements RelationshipSource { PackagePart[] parts = this.getPartsImpl(); this.partList = new PackagePartCollection(); for (PackagePart part : parts) { - if (partList.containsKey(part.partName)) + if (partList.containsKey(part._partName)) throw new InvalidFormatException( "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]"); // Check OPC compliance rule M4.1 @@ -605,29 +605,29 @@ public abstract class OPCPackage implements RelationshipSource { } PartUnmarshaller partUnmarshaller = partUnmarshallers - .get(part.contentType); + .get(part._contentType); if (partUnmarshaller != null) { UnmarshallContext context = new UnmarshallContext(this, - part.partName); + part._partName); try { PackagePart unmarshallPart = partUnmarshaller .unmarshall(context, part.getInputStream()); - partList.put(unmarshallPart.partName, unmarshallPart); + partList.put(unmarshallPart._partName, unmarshallPart); // Core properties case if (unmarshallPart instanceof PackagePropertiesPart) this.packageProperties = (PackagePropertiesPart) unmarshallPart; } catch (IOException ioe) { logger.log(POILogger.WARN, "Unmarshall operation : IOException for " - + part.partName); + + part._partName); continue; } catch (InvalidOperationException invoe) { throw new InvalidFormatException(invoe.getMessage()); } } else { try { - partList.put(part.partName, part); + partList.put(part._partName, part); } catch (InvalidOperationException e) { 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 * package. - * + * * @param partName * Part name. * @param contentType @@ -650,7 +650,7 @@ public abstract class OPCPackage implements RelationshipSource { * If rule M1.12 is not verified : Packages shall not contain * equivalent part names and package implementers shall neither * 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) { 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 * package. For general purpose, prefer the overload version of this method * without the 'loadRelationships' parameter. - * + * * @param partName * Part name. * @param contentType @@ -721,7 +721,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Add a part to the package. - * + * * @param partName * Part name of the part to create. * @param contentType @@ -730,7 +730,7 @@ public abstract class OPCPackage implements RelationshipSource { * the contents to add. In order to have faster operation in * document merge, the data are stored in memory not on a hard * disk - * + * * @return The new part. * @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 * package with the same name as the one specified, then we replace the old * part by the specified part. - * + * * @param part * The part to add (or replace). * @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"); } - if (partList.containsKey(part.partName)) { - if (!partList.get(part.partName).isDeleted()) { + if (partList.containsKey(part._partName)) { + if (!partList.get(part._partName).isDeleted()) { throw new InvalidOperationException( "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]"); } // If the specified partis flagged as deleted, we make it // available part.setDeleted(false); // 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; return part; } @@ -800,7 +800,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Remove the specified part in this package. If this part is relationship * part, then delete all relationships in the source part. - * + * * @param part * The part to remove. If null, skip the action. * @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 * delete all relationships in the source part. - * + * * @param partName * 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 * exists, and all parts listed in the relationship part. Be aware that this * do not delete relationships which target the specified part. - * + * * @param partName * The name of the part to delete. * @throws InvalidFormatException @@ -893,11 +893,11 @@ public abstract class OPCPackage implements RelationshipSource { } // Finally delete its relationship part if one exists - this.removePart(relPart.partName); + this.removePart(relPart._partName); } // 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 * package, compare to the remove() methods that don't remove associated * relationships part. - * + * * @param partName * 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. * 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. - * + * * @param partName * 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. - * + * * @param partName * Part name to check. * @return true 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). - * + * * Check rule M4.1 : The format designer shall specify and the format * producer shall create at most one core properties relationship for a * package. A format consumer shall consider more than one core properties * relationship for a package to be an error. If present, the relationship * shall target the Core Properties part. - * + * * Check rule M1.25: The Relationships part shall not have relationships to * any other part. Package implementers shall enforce this requirement upon * the attempt to create such a relationship and shall treat any such * relationship as invalid. - * + * * @param targetPartName * Target part name. * @param targetMode @@ -1032,7 +1032,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Add a package relationship. - * + * * @param targetPartName * Target part name. * @param targetMode @@ -1049,11 +1049,11 @@ public abstract class OPCPackage implements RelationshipSource { /** * Adds an external relationship to a part (except relationships part). - * + * * The targets of external relationships are not subject to the same * validity checks that internal ones are, as the contents is potentially * any file, URL or similar. - * + * * @param target * External target of the relationship * @param relationshipType @@ -1069,11 +1069,11 @@ public abstract class OPCPackage implements RelationshipSource { /** * Adds an external relationship to a part (except relationships part). - * + * * The targets of external relationships are not subject to the same * validity checks that internal ones are, as the contents is potentially * any file, URL or similar. - * + * * @param target * External target of the relationship * @param relationshipType @@ -1109,7 +1109,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Delete a relationship from this package. - * + * * @param id * Id of the relationship to delete. */ @@ -1122,7 +1122,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Retrieves all package relationships. - * + * * @return All package relationships of this package. * @throws OpenXML4JException * @see #getRelationshipsHelper(String) @@ -1133,7 +1133,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Retrieves all relationships with the specified type. - * + * * @param relationshipType * The filter specifying the 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 * a relationship id is supposed to be unique). - * + * * @param id * Id of the wanted relationship. */ @@ -1214,7 +1214,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Add a marshaller. - * + * * @param contentType * The content type to bind to the specified marshaller. * @param marshaller @@ -1231,7 +1231,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Add an unmarshaller. - * + * * @param contentType * The content type to bind to the specified unmarshaller. * @param unmarshaller @@ -1250,7 +1250,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Remove a marshaller by its content type. - * + * * @param contentType * 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. - * + * * @param contentType * The content type associated with the unmarshaller to remove. */ @@ -1272,7 +1272,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Get the package access mode. - * + * * @return the packageAccess The current package access. */ public PackageAccess getPackageAccess() { @@ -1281,7 +1281,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Validates the package compliance with the OPC specifications. - * + * * @return true if the package is valid else false */ public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException { @@ -1290,7 +1290,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Save the document in the specified file. - * + * * @param targetFile * Destination file. * @throws IOException @@ -1313,7 +1313,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Save the document in the specified output stream. - * + * * @param outputStream * The stream to save the package. * @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 * the subclass. - * + * * @param partName * URI of the part to create. * @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 * the subclass. - * + * * @param partName * 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. - * + * */ protected abstract void closeImpl() throws IOException; @@ -1364,7 +1364,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Save the package into the specified output stream. - * + * * @param outputStream * 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. - * + * * @param partName * The URI of the part to retrieve. * @return The package part located by the specified URI, else null. @@ -1382,7 +1382,7 @@ public abstract class OPCPackage implements RelationshipSource { /** * Get all parts link to the package. - * + * * @return A list of the part owned by the package. */ protected abstract PackagePart[] getPartsImpl() diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java index 928e0a783f..2b49cb21ec 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePart.java @@ -30,7 +30,7 @@ import org.apache.poi.openxml4j.opc.internal.ContentType; /** * Provides a base class for parts stored in a Package. - * + * * @author Julien Chable * @version 0.9 */ @@ -39,36 +39,36 @@ public abstract class PackagePart implements RelationshipSource { /** * This part's container. */ - protected OPCPackage container; + protected OPCPackage _container; /** * 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]) */ - protected ContentType contentType; + protected ContentType _contentType; /** * 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. */ - private boolean isDeleted; + private boolean _isDeleted; /** * This part's relationships. */ - private PackageRelationshipCollection relationships; + private PackageRelationshipCollection _relationships; /** * Constructor. - * + * * @param pack * Parent package. * @param partName @@ -85,7 +85,7 @@ public abstract class PackagePart implements RelationshipSource { /** * Constructor. - * + * * @param pack * Parent package. * @param partName @@ -100,12 +100,12 @@ public abstract class PackagePart implements RelationshipSource { protected PackagePart(OPCPackage pack, PackagePartName partName, ContentType contentType, boolean loadRelationships) throws InvalidFormatException { - this.partName = partName; - this.contentType = contentType; - this.container = (ZipPackage) pack; // TODO - enforcing ZipPackage here - perhaps should change constructor signature + _partName = partName; + _contentType = contentType; + _container = pack; // Check if this part is a relationship part - isRelationshipPart = this.partName.isRelationshipPartURI(); + _isRelationshipPart = this._partName.isRelationshipPartURI(); // Load relationships if any if (loadRelationships) @@ -114,7 +114,7 @@ public abstract class PackagePart implements RelationshipSource { /** * Constructor. - * + * * @param pack * Parent package. * @param partName @@ -130,11 +130,11 @@ public abstract class PackagePart implements RelationshipSource { /** * Adds an external relationship to a part (except relationships part). - * + * * The targets of external relationships are not subject to the same * validity checks that internal ones are, as the contents is potentially * any file, URL or similar. - * + * * @param target * External target of the relationship * @param relationshipType @@ -150,11 +150,11 @@ public abstract class PackagePart implements RelationshipSource { /** * Adds an external relationship to a part (except relationships part). - * + * * The targets of external relationships are not subject to the same * validity checks that internal ones are, as the contents is potentially * any file, URL or similar. - * + * * @param target * External target of the relationship * @param relationshipType @@ -174,8 +174,8 @@ public abstract class PackagePart implements RelationshipSource { throw new IllegalArgumentException("relationshipType"); } - if (relationships == null) { - relationships = new PackageRelationshipCollection(); + if (_relationships == null) { + _relationships = new PackageRelationshipCollection(); } URI targetURI; @@ -185,13 +185,13 @@ public abstract class PackagePart implements RelationshipSource { throw new IllegalArgumentException("Invalid target - " + e); } - return relationships.addRelationship(targetURI, TargetMode.EXTERNAL, + return _relationships.addRelationship(targetURI, TargetMode.EXTERNAL, relationshipType, id); } /** * Add a relationship to a part (except relationships part). - * + * * @param targetPartName * Name of the target part. This one must be relative to the * source root directory of the part. @@ -227,7 +227,7 @@ public abstract class PackagePart implements RelationshipSource { * @param id * Relationship unique id. * @return The newly created and added relationship - * + * * @throws InvalidFormatException * If the URI point to a relationship part URI. * @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, TargetMode targetMode, String relationshipType, String id) { - container.throwExceptionIfReadOnly(); + _container.throwExceptionIfReadOnly(); if (targetPartName == null) { throw new IllegalArgumentException("targetPartName"); @@ -247,22 +247,22 @@ public abstract class PackagePart implements RelationshipSource { throw new IllegalArgumentException("relationshipType"); } - if (this.isRelationshipPart || targetPartName.isRelationshipPartURI()) { + if (this._isRelationshipPart || targetPartName.isRelationshipPartURI()) { throw new InvalidOperationException( "Rule M1.25: The Relationships part shall not have relationships to any other part."); } - if (relationships == null) { - relationships = new PackageRelationshipCollection(); + if (_relationships == null) { + _relationships = new PackageRelationshipCollection(); } - return relationships.addRelationship(targetPartName.getURI(), + return _relationships.addRelationship(targetPartName.getURI(), targetMode, relationshipType, id); } /** * Add a relationship to a part (except relationships part). - * + * * @param targetURI * URI the target part. Must be relative to the source root * directory of the part. @@ -297,7 +297,7 @@ public abstract class PackagePart implements RelationshipSource { * @param id * Relationship unique id. * @return The newly created and added relationship - * + * * @throws InvalidFormatException * If the URI point to a relationship part URI. * @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, TargetMode targetMode, String relationshipType, String id) { - container.throwExceptionIfReadOnly(); + _container.throwExceptionIfReadOnly(); if (targetURI == null) { throw new IllegalArgumentException("targetPartName"); @@ -319,17 +319,17 @@ public abstract class PackagePart implements RelationshipSource { // Try to retrieve the target part - if (this.isRelationshipPart + if (this._isRelationshipPart || PackagingURIHelper.isRelationshipPartURI(targetURI)) { throw new InvalidOperationException( "Rule M1.25: The Relationships part shall not have relationships to any other part."); } - if (relationships == null) { - relationships = new PackageRelationshipCollection(); + if (_relationships == null) { + _relationships = new PackageRelationshipCollection(); } - return relationships.addRelationship(targetURI, + return _relationships.addRelationship(targetURI, targetMode, relationshipType, id); } @@ -337,27 +337,27 @@ public abstract class PackagePart implements RelationshipSource { * @see org.apache.poi.openxml4j.opc.RelationshipSource#clearRelationships() */ public void clearRelationships() { - if (relationships != null) { - relationships.clear(); + if (_relationships != null) { + _relationships.clear(); } } /** * Delete the relationship specified by its id. - * + * * @param id * The ID identified the part to delete. * @see org.apache.poi.openxml4j.opc.RelationshipSource#removeRelationship(java.lang.String) */ public void removeRelationship(String id) { - this.container.throwExceptionIfReadOnly(); - if (this.relationships != null) - this.relationships.removeRelationship(id); + this._container.throwExceptionIfReadOnly(); + if (this._relationships != null) + this._relationships.removeRelationship(id); } /** * Retrieve all the relationships attached to this part. - * + * * @return This part's relationships. * @throws OpenXML4JException * @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. - * + * * @param id * ID of the package relationship to retrieve. * @return The package relationship * @see org.apache.poi.openxml4j.opc.RelationshipSource#getRelationship(java.lang.String) */ 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 * type. - * + * * @param relationshipType * Relationship type filter. * @return All relationships from this part that have the specified type. @@ -394,14 +394,14 @@ public abstract class PackagePart implements RelationshipSource { */ public PackageRelationshipCollection getRelationshipsByType( String relationshipType) throws InvalidFormatException { - container.throwExceptionIfWriteOnly(); + _container.throwExceptionIfWriteOnly(); return getRelationshipsCore(relationshipType); } /** * Implementation of the getRelationships method(). - * + * * @param filter * Relationship type filter. If null then the filter is * disabled and return all the relationships. @@ -415,29 +415,29 @@ public abstract class PackagePart implements RelationshipSource { */ private PackageRelationshipCollection getRelationshipsCore(String filter) throws InvalidFormatException { - this.container.throwExceptionIfWriteOnly(); - if (relationships == null) { + this._container.throwExceptionIfWriteOnly(); + if (_relationships == null) { 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. - * + * * @return true if the part have at least one relationship else * false. * @see org.apache.poi.openxml4j.opc.RelationshipSource#hasRelationships() */ public boolean hasRelationships() { - return (!this.isRelationshipPart && (relationships != null && relationships + return (!this._isRelationshipPart && (_relationships != null && _relationships .size() > 0)); } /** * Checks if the specified relationship is part of this package part. - * + * * @param rel * The relationship to check. * @return true 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. - * + * * @return The input stream of the content of this part, else * null. */ @@ -466,9 +466,9 @@ public abstract class PackagePart implements RelationshipSource { InputStream inStream = this.getInputStreamImpl(); if (inStream == null) { throw new IOException("Can't obtain the input stream from " - + partName.getName()); - } else - return inStream; + + _partName.getName()); + } + return inStream; } /** @@ -476,7 +476,7 @@ public abstract class PackagePart implements RelationshipSource { * Zip package, it'll be transform intot a MemoryPackagePart in * order to write inside (the standard Java API doesn't allow to write in * the file) - * + * * @see org.apache.poi.openxml4j.opc.internal.MemoryPackagePart */ public OutputStream getOutputStream() { @@ -485,12 +485,12 @@ public abstract class PackagePart implements RelationshipSource { // this part into a MemoryPackagePart instance for write purpose. if (this instanceof ZipPackagePart) { // Delete logically this part - this.container.removePart(this.partName); + _container.removePart(this._partName); // Create a memory part - PackagePart part = container.createPart(this.partName, - this.contentType.toString(), false); - part.relationships = this.relationships; + PackagePart part = _container.createPart(this._partName, + this._contentType.toString(), false); + part._relationships = this._relationships; if (part == null) { throw new InvalidOperationException( "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 InvalidOperationException * If this part is a relationship part. */ private void throwExceptionIfRelationship() throws InvalidOperationException { - if (this.isRelationshipPart) + if (this._isRelationshipPart) throw new InvalidOperationException( "Can do this operation on a relationship part !"); } /** * Ensure the package relationships collection instance is built. - * + * * @throws InvalidFormatException * Throws if */ private void loadRelationships() throws InvalidFormatException { - if (this.relationships == null && !this.isRelationshipPart) { + if (this._relationships == null && !this._isRelationshipPart) { this.throwExceptionIfRelationship(); - relationships = new PackageRelationshipCollection(this); + _relationships = new PackageRelationshipCollection(this); } } @@ -536,22 +536,22 @@ public abstract class PackagePart implements RelationshipSource { * @return the uri */ public PackagePartName getPartName() { - return partName; + return _partName; } /** * @return the contentType */ public String getContentType() { - return contentType.toString(); + return _contentType.toString(); } /** * Set the content type. - * + * * @param contentType * the contentType to set - * + * * @throws InvalidFormatException * Throws if the content type is not valid. * @throws InvalidOperationException @@ -560,29 +560,29 @@ public abstract class PackagePart implements RelationshipSource { */ public void setContentType(String contentType) throws InvalidFormatException { - if (container == null) - this.contentType = new ContentType(contentType); + if (_container == null) + this._contentType = new ContentType(contentType); else throw new InvalidOperationException( "You can't change the content type of a part."); } public OPCPackage getPackage() { - return container; + return _container; } /** * @return true if this part is a relationship */ public boolean isRelationshipPart() { - return this.isRelationshipPart; + return this._isRelationshipPart; } /** * @return true if this part has been logically deleted */ public boolean isDeleted() { - return isDeleted; + return _isDeleted; } /** @@ -590,20 +590,20 @@ public abstract class PackagePart implements RelationshipSource { * the isDeleted to set */ public void setDeleted(boolean isDeleted) { - this.isDeleted = isDeleted; + this._isDeleted = isDeleted; } @Override public String toString() { - return "Name: " + this.partName + " - Content Type: " - + this.contentType.toString(); + return "Name: " + this._partName + " - Content Type: " + + this._contentType.toString(); } /*-------------- Abstract methods ------------- */ /** * Abtract method that get the input stream of this part. - * + * * @exception IOException * Throws if an IO Exception occur in the implementation * method. @@ -619,7 +619,7 @@ public abstract class PackagePart implements RelationshipSource { * Save the content of this part and the associated relationships part (if * this part own at least one relationship) into the specified output * stream. - * + * * @param zos * Output stream to save this part. * @throws OpenXML4JException @@ -629,7 +629,7 @@ public abstract class PackagePart implements RelationshipSource { /** * Load the content of this part. - * + * * @param ios * The input stream of the content to load. * @return true if the content has been successfully loaded, else diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java index 03bd296294..f43fa1b62f 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java @@ -22,7 +22,7 @@ import java.net.URISyntaxException; /** * A part relationship. - * + * * @author Julien Chable * @version 1.0 */ @@ -86,7 +86,7 @@ public final class PackageRelationship { /** * Constructor. - * + * * @param pkg * @param sourcePart * @param targetUri @@ -171,19 +171,19 @@ public final class PackageRelationship { } /** - * + * * @return URL of the source part of this relationship */ public URI getSourceURI() { if (source == null) { return PackagingURIHelper.PACKAGE_ROOT_URI; } - return source.partName.getURI(); + return source._partName.getURI(); } /** * public URI getSourceUri(){ } - * + * * @return the targetMode */ public TargetMode getTargetMode() { @@ -199,7 +199,7 @@ public final class PackageRelationship { if(targetMode == TargetMode.EXTERNAL) { return targetUri; } - + // Internal target // If it isn't absolute, resolve it relative // to ourselves diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java index 8a11738711..990a3bf4cb 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java @@ -34,7 +34,7 @@ import org.apache.poi.util.POILogFactory; /** * Represents a collection of PackageRelationship elements that are owned by a * given PackagePart or the Package. - * + * * @author Julien Chable, CDubettier * @version 0.1 */ @@ -83,11 +83,11 @@ public final class PackageRelationshipCollection implements /** * Copy constructor. - * + * * This collection will contain only elements from the specified collection * for which the type is compatible with the specified relationship type * filter. - * + * * @param coll * Collection to import. * @param filter @@ -112,21 +112,21 @@ public final class PackageRelationshipCollection implements /** * Constructor. - * + * * @throws InvalidFormatException * Throws if the format of the content part is invalid. - * + * * @throws InvalidOperationException * Throws if the specified part is a relationship part. */ public PackageRelationshipCollection(PackagePart part) throws InvalidFormatException { - this(part.container, part); + this(part._container, part); } /** * Constructor. Parse the existing package relationship part if one exists. - * + * * @param container * The parent package. * @param part @@ -159,7 +159,7 @@ public final class PackageRelationshipCollection implements /** * Get the relationship part name of the specified part. - * + * * @param part * The part . * @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. - * + * * @param relPart * The relationship to add. */ @@ -192,7 +192,7 @@ public final class PackageRelationshipCollection implements /** * Add a relationship to the collection. - * + * * @param targetUri * Target URI. * @param targetMode @@ -224,7 +224,7 @@ public final class PackageRelationshipCollection implements /** * Remove a relationship by its ID. - * + * * @param id * The relationship ID to remove. */ @@ -240,7 +240,7 @@ public final class PackageRelationshipCollection implements /** * Remove a relationship by its reference. - * + * * @param rel * The relationship to delete. */ @@ -254,7 +254,7 @@ public final class PackageRelationshipCollection implements /** * Retrieves a relationship by its index in the collection. - * + * * @param index * 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. - * + * * @param id * ID of the package relationship to retrieve. * @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. - * + * * @param relPart * The package part to parse. * @throws InvalidFormatException @@ -376,7 +376,7 @@ public final class PackageRelationshipCollection implements /** * Retrieves all relations with the specified type. - * + * * @param typeFilter * Relationship type filter. If null then all * relationships are returned. @@ -398,7 +398,7 @@ public final class PackageRelationshipCollection implements /** * Get an iterator of a collection with all relationship with the specified * type. - * + * * @param typeFilter * Type filter. * @return An iterator to a collection containing all relationships with the @@ -429,15 +429,15 @@ public final class PackageRelationshipCollection implements } else { str = relationshipsByID.size() + " relationship(s) = ["; } - if ((relationshipPart != null) && (relationshipPart.partName != null)) { - str = str + "," + relationshipPart.partName; + if ((relationshipPart != null) && (relationshipPart._partName != null)) { + str = str + "," + relationshipPart._partName; } else { str = str + ",relationshipPart=null"; } // Source of this relationship - if ((sourcePart != null) && (sourcePart.partName != null)) { - str = str + "," + sourcePart.partName; + if ((sourcePart != null) && (sourcePart._partName != null)) { + str = str + "," + sourcePart._partName; } else { str = str + ",sourcePart=null"; } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/RelationshipSource.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/RelationshipSource.java index 018f76c667..87c424df54 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/RelationshipSource.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/RelationshipSource.java @@ -24,7 +24,7 @@ public interface RelationshipSource { /** * Add a relationship to a part (except relationships part). - * + * * @param targetPartName * Name of the target part. This one must be relative to the * source root directory of the part. @@ -56,7 +56,7 @@ public interface RelationshipSource { * @param id * Relationship unique id. * @return The newly created and added relationship - * + * * @throws InvalidFormatException * If the URI point to a relationship part URI. */ @@ -67,28 +67,28 @@ public interface RelationshipSource { /** * Adds an external relationship to a part * (except relationships part). - * + * * The targets of external relationships are not * subject to the same validity checks that internal * ones are, as the contents is potentially * any file, URL or similar. - * + * * @param target External target of the relationship * @param relationshipType Type of relationship. * @return The newly created and added relationship * @see org.apache.poi.openxml4j.opc.RelationshipSource#addExternalRelationship(java.lang.String, java.lang.String) */ public PackageRelationship addExternalRelationship(String target, String relationshipType); - + /** * Adds an external relationship to a part * (except relationships part). - * + * * The targets of external relationships are not * subject to the same validity checks that internal * ones are, as the contents is potentially * any file, URL or similar. - * + * * @param target External target of the relationship * @param relationshipType Type of relationship. * @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) */ public PackageRelationship addExternalRelationship(String target, String relationshipType, String id); - + /** * Delete all the relationships attached to this. */ @@ -104,7 +104,7 @@ public interface RelationshipSource { /** * Delete the relationship specified by its id. - * + * * @param id * The ID identified the part to delete. */ @@ -112,7 +112,7 @@ public interface RelationshipSource { /** * Retrieve all the relationships attached to this. - * + * * @return This part's relationships. * @throws OpenXML4JException */ @@ -121,7 +121,7 @@ public interface RelationshipSource { /** * Retrieves a package relationship from its id. - * + * * @param id * ID of the package relationship to retrieve. * @return The package relationship @@ -131,7 +131,7 @@ public interface RelationshipSource { /** * Retrieve all relationships attached to this part which have the specified * type. - * + * * @param relationshipType * Relationship type filter. * @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. */ public abstract PackageRelationshipCollection getRelationshipsByType( - String relationshipType) throws InvalidFormatException, + String relationshipType) throws InvalidFormatException, IllegalArgumentException, OpenXML4JException; /** * Knows if the part have any relationships. - * + * * @return true if the part have at least one relationship else * false. */ @@ -154,13 +154,12 @@ public interface RelationshipSource { /** * Checks if the specified relationship is part of this package part. - * + * * @param rel * The relationship to check. * @return true if the specified relationship exists in this part, * else returns false */ - @SuppressWarnings("finally") public abstract boolean isRelationshipExists(PackageRelationship rel); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index 6e676cc9b2..a394f59583 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -423,7 +423,7 @@ public final class ZipPackage extends Package { + ZipHelper.getZipItemNameFromOPCName(part .getPartName().getName()) + "'"); PartMarshaller marshaller = partMarshallers - .get(part.contentType); + .get(part._contentType); if (marshaller != null) { if (!marshaller.marshall(part, zos)) { throw new OpenXML4JException( diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java index a4e50ba0a8..e20311787b 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackagePart.java @@ -29,7 +29,7 @@ import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller; /** * Zip implementation of a PackagePart. - * + * * @author Julien Chable * @version 1.0 * @see PackagePart @@ -43,7 +43,7 @@ public class ZipPackagePart extends PackagePart { /** * Constructor. - * + * * @param container * The container package. * @param partName @@ -60,7 +60,7 @@ public class ZipPackagePart extends PackagePart { /** * Constructor. - * + * * @param container * The container package. * @param zipEntry @@ -81,7 +81,7 @@ public class ZipPackagePart extends PackagePart { /** * Get the zip entry of this part. - * + * * @return The zip entry in the zip structure coresponding to this part. */ public ZipEntry getZipArchive() { @@ -91,21 +91,21 @@ public class ZipPackagePart extends PackagePart { /** * Implementation of the getInputStream() which return the inputStream of * this part zip entry. - * + * * @return Input stream of this part zip entry. */ @Override protected InputStream getInputStreamImpl() throws IOException { // We use the getInputStream() method from java.util.zip.ZipFile // class which return an InputStream to this part zip entry. - return ((ZipPackage) container).getZipArchive() + return ((ZipPackage) _container).getZipArchive() .getInputStream(zipEntry); } /** * Implementation of the getOutputStream(). Return null. Normally * will never be called since the MemoryPackage is use instead. - * + * * @return null */ @Override @@ -119,7 +119,7 @@ public class ZipPackagePart extends PackagePart { } @Override - public boolean load(InputStream ios) throws InvalidFormatException { + public boolean load(InputStream ios) { throw new InvalidOperationException("Method not implemented !"); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java index f36bf068ff..b8c30df930 100755 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java @@ -43,9 +43,8 @@ import org.dom4j.io.SAXReader; /** * Manage package content types ([Content_Types].xml part). - * + * * @author Julien Chable - * @version 1.0 */ public abstract class ContentTypeManager { @@ -90,7 +89,7 @@ public abstract class ContentTypeManager { /** * Constructor. Parses the content of the specified input stream. - * + * * @param in * If different of null then the content types part is * retrieve and parse. @@ -161,7 +160,7 @@ public abstract class ContentTypeManager { /** * Add an override content type for a specific part. - * + * * @param partName * Name of the part. * @param contentType @@ -176,7 +175,7 @@ public abstract class ContentTypeManager { /** * Add a content type associated with the specified extension. - * + * * @param extension * The part name extension to bind to a content type. * @param contentType @@ -267,7 +266,7 @@ public abstract class ContentTypeManager { /** * Check if the specified content type is already register. - * + * * @param contentType * The content type to check. * @return true 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 * content type) or the extension (in case of default content type), * else null. - * + * * @exception OpenXML4JRuntimeException * Throws if the content type manager is not able to find the * content from an existing part. @@ -342,9 +341,8 @@ public abstract class ContentTypeManager { if (this.container != null && this.container.getPart(partName) != null) { throw new OpenXML4JRuntimeException( "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. - * + * */ public void clearOverrideContentTypes() { if (this.overrideContentType != null) @@ -367,7 +365,7 @@ public abstract class ContentTypeManager { /** * Parse the content types part. - * + * * @throws InvalidFormatException * Throws if the content type doesn't exist or the XML format is * invalid. @@ -414,7 +412,7 @@ public abstract class ContentTypeManager { /** * Save the contents type part. - * + * * @param outStream * The output stream use to save the XML content of the content * types part. @@ -448,7 +446,7 @@ public abstract class ContentTypeManager { /** * Use to append specific type XML elements, use by the save() method. - * + * * @param root * XML parent element use to append this override type element. * @param entry @@ -459,13 +457,13 @@ public abstract class ContentTypeManager { Entry entry) { root.addElement(OVERRIDE_TAG_NAME).addAttribute( PART_NAME_ATTRIBUTE_NAME, - ((PackagePartName) entry.getKey()).getName()).addAttribute( - CONTENT_TYPE_ATTRIBUTE_NAME, (String) entry.getValue()); + entry.getKey().getName()).addAttribute( + CONTENT_TYPE_ATTRIBUTE_NAME, entry.getValue()); } /** * Use to append default types XML elements, use by the save() metid. - * + * * @param root * XML parent element use to append this default type element. * @param entry @@ -474,16 +472,16 @@ public abstract class ContentTypeManager { */ private void appendDefaultType(Element root, Entry entry) { root.addElement(DEFAULT_TAG_NAME).addAttribute( - EXTENSION_ATTRIBUTE_NAME, (String) entry.getKey()) + EXTENSION_ATTRIBUTE_NAME, entry.getKey()) .addAttribute(CONTENT_TYPE_ATTRIBUTE_NAME, - (String) entry.getValue()); + entry.getValue()); } /** * Specific implementation of the save method. Call by the save() method, * call before exiting. - * + * * @param out * The output stream use to write the content type XML. */ diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java index 8a17cf5d8b..382f5c1547 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java @@ -41,7 +41,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach private boolean formulasNotResults = false; private boolean includeCellComments = false; private boolean includeHeadersFooters = true; - + public XSSFExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException { this(new XSSFWorkbook(path)); } @@ -52,14 +52,14 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach super(workbook); this.workbook = workbook; } - + public static void main(String[] args) throws Exception { if(args.length < 1) { System.err.println("Use:"); System.err.println(" HXFExcelExtractor "); System.exit(1); } - POIXMLTextExtractor extractor = + POIXMLTextExtractor extractor = new XSSFExcelExtractor(args[0]); System.out.println(extractor.getText()); } @@ -89,19 +89,19 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach public void setIncludeHeadersFooters(boolean includeHeadersFooters) { this.includeHeadersFooters = includeHeadersFooters; } - + /** * Retreives the text contents of the file */ public String getText() { StringBuffer text = new StringBuffer(); - + for(int i=0; i ri = row.cellIterator(); ri.hasNext();) { Cell cell = ri.next(); - + // Is it a formula one? if(cell.getCellType() == Cell.CELL_TYPE_FORMULA && formulasNotResults) { text.append(cell.getCellFormula()); @@ -130,7 +130,7 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach XSSFCell xc = (XSSFCell)cell; text.append(xc.getRawValue()); } - + // Output the comment, if requested and exists Comment comment = cell.getCellComment(); if(includeCellComments && comment != null) { @@ -139,13 +139,13 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach String commentText = comment.getString().getString().replace('\n', ' '); text.append(" Comment by "+comment.getAuthor()+": "+commentText); } - + if(ri.hasNext()) text.append("\t"); } text.append("\n"); } - + // Finally footer(s), if present if(includeHeadersFooters) { text.append( @@ -159,10 +159,10 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor implements org.apach ); } } - + return text.toString(); } - + private String extractHeaderFooter(HeaderFooter hf) { return ExcelExtractor._extractHeaderFooter(hf); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index f6615b73e8..f9c2bdf2bd 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -585,9 +585,11 @@ public final class XSSFCell implements Cell { */ public byte getErrorCellValue() { 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; int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex(); 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.." + maxcol + ") or ('A'..'" + v.getLastColumnName() + "')"); } @@ -848,7 +850,7 @@ public final class XSSFCell implements Cell { */ private boolean convertCellValueToBoolean() { int cellType = getCellType(); - + if (cellType == CELL_TYPE_FORMULA) { cellType = getBaseCellType(false); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 17f267b7cb..5ce05a176d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -145,9 +145,8 @@ public class XSSFCellStyle implements CellStyle { CTCellAlignment align = cellXf.getAlignment(); if(align != null && align.isSetHorizontal()) { 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) { cellXf.setApplyNumberFormat(true); - cellXf.setNumFmtId((long)fmt); + cellXf.setNumFmtId(fmt); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java index 2905228204..47a27b6a63 100755 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java @@ -285,7 +285,7 @@ public class XSSFPrintSetup implements PrintSetup { * @see PaperSize */ public PaperSize getPaperSizeEnum() { - return PaperSize.values()[((int) getPaperSize() - 1)]; + return PaperSize.values()[getPaperSize() - 1]; } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 81d8c3ebc8..77d4b5c34e 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -255,7 +255,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { /** * Returns the name of this sheet - * + * * @return the name of this sheet */ public String getSheetName() { @@ -358,7 +358,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { public void createFreezePane(int colSplit, int rowSplit) { createFreezePane( colSplit, rowSplit, colSplit, rowSplit ); } - + /** * Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * @param colSplit Horizonatal position of split. @@ -533,7 +533,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { worksheet.getSheetFormatPr() : worksheet.addNewSheetFormatPr(); } - + /** * Returns the CellStyle that applies to the given * (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. * When false, cells with zero value appear blank instead of showing the number zero. - * + * * @return whether all zero values on the worksheet are displayed */ public boolean isDisplayZeros(){ @@ -1333,7 +1333,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { .getOutlineLevel(), true); // 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 * hidden status. - * + * * @param pIdx * the col info index of the start of 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 * immediately after the outline group - * + * * @param idx * @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 * this case, if the lowest level were expanded, the middle level would * remain collapsed. - * + * * @param rowIndex - * the row involved, 0 based * @param collapse - @@ -1895,8 +1895,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { endLevel = 0; endHidden = false; } else { - endLevel = (int) (getRow(endOfOutlineGroupIdx).getCTRow() - .getOutlineLevel()); + endLevel = getRow(endOfOutlineGroupIdx).getCTRow().getOutlineLevel(); endHidden = getRow(endOfOutlineGroupIdx).getCTRow().getHidden(); } @@ -1931,7 +1930,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { else return getRow(collapseRow).getCTRow().getCollapsed(); } - + /** * 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 diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java index 05a85fc548..07eaa4b8fc 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java @@ -35,22 +35,23 @@ import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.OPCPackage; import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; public class TestCommentsTable extends TestCase { - + 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_AUTHOR = "test author"; public void testfindAuthor() throws Exception { - CommentsDocument doc = CommentsDocument.Factory.newInstance(); + CommentsDocument doc = CommentsDocument.Factory.newInstance(); doc.setComments(CTComments.Factory.newInstance()); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - CommentsTable sheetComments = new CommentsTable(); - sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CommentsTable sheetComments = new CommentsTable(); + sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR)); assertEquals(1, sheetComments.findAuthor("another author")); @@ -58,19 +59,19 @@ public class TestCommentsTable extends TestCase { assertEquals(2, sheetComments.findAuthor("YAA")); assertEquals(1, sheetComments.findAuthor("another author")); } - + public void testGetCellComment() throws Exception { - CommentsDocument doc = CommentsDocument.Factory.newInstance(); + CommentsDocument doc = CommentsDocument.Factory.newInstance(); doc.setComments(CTComments.Factory.newInstance()); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - CommentsTable sheetComments = new CommentsTable(); - sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CommentsTable sheetComments = new CommentsTable(); + sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); CTComments comments = sheetComments.getCTComments(); CTCommentList commentList = comments.addNewCommentList(); - + // Create 2 comments for A1 and A" cells CTComment comment0 = commentList.insertNewComment(0); comment0.setRef("A1"); @@ -82,7 +83,7 @@ public class TestCommentsTable extends TestCase { CTRst ctrst1 = CTRst.Factory.newInstance(); ctrst1.setT(TEST_A2_TEXT); comment1.setText(ctrst1); - + // test finding the right comment for a cell assertEquals(TEST_A1_TEXT, sheetComments.findCellComment("A1").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(2, 0)); } - + public void testAddCellComment() throws Exception { - CommentsDocument doc = CommentsDocument.Factory.newInstance(); + CommentsDocument doc = CommentsDocument.Factory.newInstance(); doc.setComments(CTComments.Factory.newInstance()); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - CommentsTable sheetComments = new CommentsTable(); - sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + CommentsTable sheetComments = new CommentsTable(); + sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray())); CTCommentList commentList = sheetComments.getCTComments().addNewCommentList(); assertEquals(0, commentList.sizeOfCommentArray()); - + XSSFComment comment = sheetComments.addComment(); comment.setAuthor("test A1 author"); comment.setRow(0); comment.setColumn((short)0); - + assertEquals(1, commentList.sizeOfCommentArray()); assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId())); assertEquals("test A1 author", comment.getAuthor()); - + // Change the author, check it updates comment.setAuthor("Another Author"); assertEquals(1, commentList.sizeOfCommentArray()); assertEquals("Another Author", comment.getAuthor()); } - + public void testDontLoostNewLines() throws Exception { File xml = new File( System.getProperty("HSSF.testdata.path") + File.separator + "WithVariousData.xlsx" ); assertTrue(xml.exists()); - + OPCPackage pkg = OPCPackage.open(xml.toString()); XSSFWorkbook wb = new XSSFWorkbook(pkg); - List rels = wb.getSheetAt(0).getRelations(); - CommentsTable ct = null; - for(POIXMLDocumentPart p : rels) { - if(p instanceof CommentsTable){ - ct = (CommentsTable)p; - break; - } - } - assertNotNull(ct); + List rels = wb.getSheetAt(0).getRelations(); + CommentsTable ct = null; + for(POIXMLDocumentPart p : rels) { + if(p instanceof CommentsTable){ + ct = (CommentsTable)p; + break; + } + } + if (ct == null) { + throw new AssertionFailedError("didn't find comments table"); + } assertEquals(2, ct.getNumberOfComments()); assertEquals(1, ct.getNumberOfAuthors()); XSSFComment comment = ct.findCellComment("C5"); - + assertEquals("Nick Burch", comment.getAuthor()); assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); - wb = XSSFTestDataSamples.writeOutAndReadBack(wb); - rels = wb.getSheetAt(0).getRelations(); - ct = null; - for(POIXMLDocumentPart p : rels) { - if(p instanceof CommentsTable){ - ct = (CommentsTable)p; - break; - } - } - assertNotNull(ct); + wb = XSSFTestDataSamples.writeOutAndReadBack(wb); + rels = wb.getSheetAt(0).getRelations(); + ct = null; + for(POIXMLDocumentPart p : rels) { + if(p instanceof CommentsTable){ + ct = (CommentsTable)p; + break; + } + } + if (ct == null) { + throw new AssertionFailedError("didn't find comments table"); + } assertEquals(2, ct.getNumberOfComments()); assertEquals(1, ct.getNumberOfAuthors()); - + comment = ct.findCellComment("C5"); - + assertEquals("Nick Burch", comment.getAuthor()); - + assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); } @@ -171,127 +176,127 @@ public class TestCommentsTable extends TestCase { File.separator + "WithVariousData.xlsx" ); assertTrue(xml.exists()); - + XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); Sheet sheet1 = workbook.getSheetAt(0); Sheet sheet2 = workbook.getSheetAt(1); - + assertTrue( ((XSSFSheet)sheet1).hasComments() ); assertFalse( ((XSSFSheet)sheet2).hasComments() ); - + // Comments should be in C5 and C7 Row r5 = sheet1.getRow(4); Row r7 = sheet1.getRow(6); assertNotNull( r5.getCell(2).getCellComment() ); assertNotNull( r7.getCell(2).getCellComment() ); - + // Check they have what we expect // TODO: Rich text formatting Comment cc5 = r5.getCell(2).getCellComment(); Comment cc7 = r7.getCell(2).getCellComment(); - + assertEquals("Nick Burch", cc5.getAuthor()); assertEquals("Nick Burch:\nThis is a comment", cc5.getString().getString()); assertEquals(4, cc5.getRow()); assertEquals(2, cc5.getColumn()); - + assertEquals("Nick Burch", cc7.getAuthor()); assertEquals("Nick Burch:\nComment #1\n", cc7.getString().getString()); assertEquals(6, cc7.getRow()); assertEquals(2, cc7.getColumn()); } - + public void testWriteRead() throws Exception { File xml = new File( System.getProperty("HSSF.testdata.path") + File.separator + "WithVariousData.xlsx" ); assertTrue(xml.exists()); - + XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); - Sheet sheet1 = workbook.getSheetAt(0); - XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1); - - assertTrue( ((XSSFSheet)sheet1).hasComments() ); - assertFalse( ((XSSFSheet)sheet2).hasComments() ); - + XSSFSheet sheet1 = workbook.getSheetAt(0); + XSSFSheet sheet2 = workbook.getSheetAt(1); + + assertTrue( sheet1.hasComments() ); + assertFalse( sheet2.hasComments() ); + // Change on comment on sheet 1, and add another into // sheet 2 Row r5 = sheet1.getRow(4); Comment cc5 = r5.getCell(2).getCellComment(); cc5.setAuthor("Apache POI"); cc5.setString(new XSSFRichTextString("Hello!")); - + Row r2s2 = sheet2.createRow(2); Cell c1r2s2 = r2s2.createCell(1); assertNull(c1r2s2.getCellComment()); - + Comment cc2 = sheet2.createComment(); cc2.setAuthor("Also POI"); cc2.setString(new XSSFRichTextString("A new comment")); c1r2s2.setCellComment(cc2); - - + + // Save, and re-load the file - workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); + workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); // Check we still have comments where we should do sheet1 = workbook.getSheetAt(0); - sheet2 = (XSSFSheet)workbook.getSheetAt(1); + sheet2 = workbook.getSheetAt(1); assertNotNull(sheet1.getRow(4).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(6).getCell(2).getCellComment()); assertNotNull(sheet2.getRow(2).getCell(1).getCellComment()); - + // And check they still have the contents they should do - assertEquals("Apache POI", + assertEquals("Apache POI", sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); - assertEquals("Nick Burch", + assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); - assertEquals("Also POI", + assertEquals("Also POI", sheet2.getRow(2).getCell(1).getCellComment().getAuthor()); - + assertEquals("Nick Burch:\nThis is a comment", sheet1.getRow(4).getCell(2).getCellComment().getString().getString()); } - + public void testReadWriteMultipleAuthors() throws Exception { File xml = new File( System.getProperty("HSSF.testdata.path") + File.separator + "WithMoreVariousData.xlsx" ); assertTrue(xml.exists()); - + XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); - Sheet sheet1 = workbook.getSheetAt(0); - XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1); - - assertTrue( ((XSSFSheet)sheet1).hasComments() ); - assertFalse( ((XSSFSheet)sheet2).hasComments() ); - - assertEquals("Nick Burch", + XSSFSheet sheet1 = workbook.getSheetAt(0); + XSSFSheet sheet2 = workbook.getSheetAt(1); + + assertTrue( sheet1.hasComments() ); + assertFalse( sheet2.hasComments() ); + + assertEquals("Nick Burch", sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); - assertEquals("Nick Burch", + assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); - assertEquals("Torchbox", + assertEquals("Torchbox", sheet1.getRow(12).getCell(2).getCellComment().getAuthor()); - + // Save, and re-load the file - workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); + workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); // Check we still have comments where we should do sheet1 = workbook.getSheetAt(0); assertNotNull(sheet1.getRow(4).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(6).getCell(2).getCellComment()); assertNotNull(sheet1.getRow(12).getCell(2).getCellComment()); - + // And check they still have the contents they should do - assertEquals("Nick Burch", + assertEquals("Nick Burch", sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); - assertEquals("Nick Burch", + assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); - assertEquals("Torchbox", + assertEquals("Torchbox", sheet1.getRow(12).getCell(2).getCellComment().getAuthor()); - + // Todo - check text too, once bug fixed } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java index 4e08e7274d..0a7b08347e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java @@ -24,10 +24,10 @@ import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFITestDataProvider; public final class TestXSSFHyperlink extends BaseTestHyperlink { - @Override - protected XSSFITestDataProvider getTestDataProvider() { - return XSSFITestDataProvider.getInstance(); - } + @Override + protected XSSFITestDataProvider getTestDataProvider() { + return XSSFITestDataProvider.getInstance(); + } @Override protected void setUp() { @@ -48,7 +48,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); assertEquals(3, workbook.getNumberOfSheets()); - XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0); + XSSFSheet sheet = workbook.getSheetAt(0); // Check the hyperlinks assertEquals(4, sheet.getNumHyperlinks()); @@ -65,7 +65,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); CreationHelper createHelper = workbook.getCreationHelper(); assertEquals(3, workbook.getNumberOfSheets()); - XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0); + XSSFSheet sheet = workbook.getSheetAt(0); // Check hyperlinks assertEquals(4, sheet.getNumHyperlinks()); @@ -81,7 +81,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink { assertNotNull(wb2.getSheetAt(1)); assertNotNull(wb2.getSheetAt(2)); - sheet = (XSSFSheet)wb2.getSheetAt(0); + sheet = wb2.getSheetAt(0); // Check hyperlinks again diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java index 9dc5925e9a..310b0e2235 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/StyleSheet.java @@ -167,8 +167,8 @@ public final class StyleSheet { break; case 0x9: newCHP._fSpec = true; - newCHP._ftcSym = (short)Utils.convertBytesToShort(varParam, 0); - newCHP._xchSym = (short)Utils.convertBytesToShort(varParam, 2); + newCHP._ftcSym = Utils.convertBytesToShort(varParam, 0); + newCHP._xchSym = Utils.convertBytesToShort(varParam, 2); break; case 0xa: newCHP._fOle2 = getFlag(param); @@ -453,8 +453,8 @@ public final class StyleSheet { doCHPOperation(oldCHP, newCHP, 0x47, param, varParam, grpprl, offset, styleSheet); break; case 0x4d: - float percentage = (float)param/100.0f; - int add = (int)((float)percentage * (float)newCHP._hps); + float percentage = param/100.0f; + int add = (int)(percentage * newCHP._hps); newCHP._hps += add; break; case 0x4e: @@ -485,7 +485,7 @@ public final class StyleSheet { break; case 0x57: newCHP._fPropMark = getFlag(varParam[0]); - newCHP._ibstPropRMark = (short)Utils.convertBytesToShort(varParam, 1); + newCHP._ibstPropRMark = Utils.convertBytesToShort(varParam, 1); newCHP._dttmPropRMark = Utils.convertBytesToInt(varParam, 3); break; case 0x58: @@ -512,7 +512,7 @@ public final class StyleSheet { break; case 0x62: newCHP._fDispFldRMark = getFlag(varParam[0]); - newCHP._ibstDispFldRMark = (short)Utils.convertBytesToShort(varParam, 1); + newCHP._ibstDispFldRMark = Utils.convertBytesToShort(varParam, 1); newCHP._dttmDispFldRMark = Utils.convertBytesToInt(varParam, 3); System.arraycopy(varParam, 7, newCHP._xstDispFldRMark, 0, 32); break; @@ -524,8 +524,8 @@ public final class StyleSheet { newCHP._dttmRMarkDel[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x65: - newCHP._brc[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newCHP._brc[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newCHP._brc[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newCHP._brc[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x66: newCHP._shd = (short)param; @@ -834,28 +834,28 @@ public final class StyleSheet { newPAP._wr = (byte)param; break; case 0x24: - newPAP._brcTop[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newPAP._brcTop[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newPAP._brcTop[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newPAP._brcTop[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x25: - newPAP._brcLeft[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newPAP._brcLeft[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newPAP._brcLeft[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newPAP._brcLeft[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x26: - newPAP._brcBottom[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newPAP._brcBottom[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newPAP._brcBottom[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newPAP._brcBottom[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x27: - newPAP._brcRight[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newPAP._brcRight[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newPAP._brcRight[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newPAP._brcRight[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x28: - newPAP._brcBetween[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newPAP._brcBetween[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newPAP._brcBetween[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newPAP._brcBetween[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x29: - newPAP._brcBar[0] = (short)Utils.convertBytesToShort(grpprl, offset - 4); - newPAP._brcBar[1] = (short)Utils.convertBytesToShort(grpprl, offset - 2); + newPAP._brcBar[0] = Utils.convertBytesToShort(grpprl, offset - 4); + newPAP._brcBar[1] = Utils.convertBytesToShort(grpprl, offset - 2); break; case 0x2a: newPAP._fNoAutoHyph = (byte)param; diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java index a525d97141..fb237ffc52 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java @@ -35,10 +35,10 @@ import org.apache.poi.util.LittleEndian; * * @author Ryan Ackley */ - -public final class WordDocument -{ - /** byte buffer containing the main Document stream*/ +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[] _header; /** contains all style information for this document see Word 97 Doc spec*/ StyleSheet _styleSheet; @@ -1160,19 +1160,19 @@ public final class WordDocument } 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) { - 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) { - 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) { - //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._brcBottom, "bottom"); @@ -1190,7 +1190,7 @@ public final class WordDocument buf.append("font-size=\"" + (chp._hps / 2) + "pt\" "); buf.append("color=\"" + getColor(chp._ico) + "\" "); //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, "bottom"); @@ -1236,11 +1236,11 @@ public final class WordDocument } 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) { - buf.append("padding-end=\"" + (float)chp._paddingEnd/1440.0f + "in\" "); + buf.append("padding-end=\"" + chp._paddingEnd/K_1440_0F + "in\" "); } buf.append(">"); } @@ -1416,12 +1416,12 @@ public final class WordDocument private String createPageMaster(SEP sep, String type, int section, String regionBefore, String regionAfter) { - float height = ((float)sep._yaPage)/1440.0f; - float width = ((float)sep._xaPage)/1440.0f; - float leftMargin = ((float)sep._dxaLeft)/1440.0f; - float rightMargin = ((float)sep._dxaRight)/1440.0f; - float topMargin = ((float)sep._dyaTop)/1440.0f; - float bottomMargin = ((float)sep._dyaBottom)/1440.0f; + float height = sep._yaPage/K_1440_0F; + float width = sep._xaPage/K_1440_0F; + float leftMargin = sep._dxaLeft/K_1440_0F; + float rightMargin = sep._dxaRight/K_1440_0F; + float topMargin = sep._dyaTop/K_1440_0F; + float bottomMargin = sep._dyaBottom/K_1440_0F; //add these to the header String thisPage = type + "-page" + section; @@ -1452,7 +1452,7 @@ public final class WordDocument _headerBuffer.append("column-count=\"" + (sep._ccolM1 + 1) + "\" "); if(sep._fEvenlySpaced) { - _headerBuffer.append("column-gap=\"" + ((float)(sep._dxaColumns))/1440.0f + "in\""); + _headerBuffer.append("column-gap=\"" + sep._dxaColumns/K_1440_0F + "in\""); } else { @@ -1478,7 +1478,7 @@ public final class WordDocument if((brc[0] & 0xff00) != 0 && brc[0] != -1) { 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 color = getColor(brc[1] & 0x00ff); String thickness = getBorderThickness(brc[0]); @@ -1764,7 +1764,7 @@ public final class WordDocument rowBuffer.append(" 0) { - rowBuffer.append("height=\"" + ((float)tap._dyaRowHeight)/1440.0f + "in\" "); + rowBuffer.append("height=\"" + tap._dyaRowHeight/K_1440_0F + "in\" "); } if(tap._fCantSplit) { @@ -1777,9 +1777,9 @@ public final class WordDocument TC tc = tap._rgtc[y]; overrideCellBorder(x, y, size, tap._itcMac, tc, tap); rowBuffer.append("= 0) return (int)b; - return (int)(b + 256); + if(b >= 0) { + 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 int dataI; // 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 // dictionary to start at int len, pntr; @@ -138,7 +140,7 @@ public void decode(InputStream src, OutputStream res) throws IOException { dataIPt1 = src.read(); dataIPt2 = src.read(); if(dataIPt1 == -1 || dataIPt2 == -1) break; - + // Build up how long the code sequence is, and // what position of the code to start at // (The position is the first 12 bits, the @@ -153,14 +155,14 @@ public void decode(InputStream src, OutputStream res) throws IOException { } else { pntr = pntr + 18; } - + // Loop over the codes, outputting what they correspond to for(int i=0; i 0) { outputCompressed(res); break; } - + // Try adding this new byte onto rawCode, and // see if all of that is still found in the // buffer dictionary or not rawCode[rawCodeLen] = dataB; rawCodeLen++; int rawAt = findRawCodeInBuffer(); - + // If we found it and are now at 16 bytes, // we need to output our pending code block if(rawCodeLen == 16 && rawAt > -1) { @@ -345,24 +350,24 @@ private void compress(InputStream src, OutputStream res) throws IOException { rawCodeLen = 0; continue; } - + // If we did find all of rawCode with our new // byte added on, we can wait to see what happens // with the next byte if(rawAt > -1) { continue; } - + // If we get here, then the rawCode + this byte weren't // found in the dictionary - + // If there was something in rawCode before, then that was // found in the dictionary, so output that compressed rawCodeLen--; if(rawCodeLen > 0) { // Output the old rawCode outputCompressed(res); - + // Can this byte start a new rawCode, or does // it need outputting itself? rawCode[0] = dataB; @@ -385,4 +390,4 @@ private void compress(InputStream src, OutputStream res) throws IOException { } } -} \ No newline at end of file +} diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java index 7808ce847d..1565074de9 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java @@ -51,11 +51,11 @@ public abstract class ChunkHeader { } else if(documentVersion == 5 || documentVersion == 4) { ChunkHeaderV4V5 ch = new ChunkHeaderV4V5(); - ch.type = (int)LittleEndian.getShort(data, offset + 0); - ch.id = (int)LittleEndian.getShort(data, offset + 2); + ch.type = LittleEndian.getShort(data, offset + 0); + ch.id = LittleEndian.getShort(data, offset + 2); ch.unknown2 = (short)LittleEndian.getUnsignedByte(data, offset + 4); 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); return ch; diff --git a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java index 80767b3a0e..90b2cfd3ed 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java @@ -257,7 +257,7 @@ public final class HSLFSlideShow extends POIDocument { Record[] rec = new Record[lst.size()]; for (int i = 0; i < a.length; 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) { PersistRecord psr = (PersistRecord)rec[i]; Integer id = (Integer)offset2id.get(offset); diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java index d9c1a2ae91..9cb1a45a55 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java @@ -41,9 +41,7 @@ import org.apache.poi.util.LittleEndian; * * @author Nick Burch */ - -public final class SlideShowDumper -{ +public final class SlideShowDumper { private InputStream istream; private POIFSFileSystem filesystem; @@ -196,7 +194,7 @@ public final class SlideShowDumper } 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; } return hex; } @@ -232,7 +230,7 @@ public void walkTree(int depth, int startPos, int maxLen) { System.out.println(ind + "That's a " + recordName); // 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 // isn't tagged as doing so. Try stepping in anyway diff --git a/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java b/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java index b2182edcd6..0446d4fba8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java @@ -53,9 +53,7 @@ import org.apache.poi.hslf.model.TextRun; * * @author Nick Burch */ - -public final class QuickButCruddyTextExtractor -{ +public final class QuickButCruddyTextExtractor { private POIFSFileSystem fs; private InputStream is; 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, option byte 1 BINARY_AND 0x0f will be 0x0f) - int container = (int)opt & 0x0f; + int container = opt & 0x0f; if(container == 0x0f) { return (startPos+8); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java index 302415068b..97c818e519 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java @@ -17,13 +17,22 @@ package org.apache.poi.hslf.model; -import org.apache.poi.ddf.*; -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; - -import java.awt.geom.*; +import java.awt.geom.AffineTransform; +import java.awt.geom.GeneralPath; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; import java.util.ArrayList; 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. @@ -85,8 +94,8 @@ public final class Freeform extends AutoShape { Rectangle2D bounds = path.getBounds2D(); PathIterator it = path.getPathIterator(new AffineTransform()); - ArrayList segInfo = new ArrayList(); - ArrayList pntInfo = new ArrayList(); + List segInfo = new ArrayList(); + List pntInfo = new ArrayList(); boolean isClosed = false; while (!it.isDone()) { double[] vals = new double[6]; @@ -135,7 +144,7 @@ public final class Freeform extends AutoShape { verticesProp.setNumberOfElementsInMemory(pntInfo.size()); verticesProp.setSizeOfElements(0xFFF0); 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]; 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)); @@ -148,7 +157,7 @@ public final class Freeform extends AutoShape { segmentsProp.setNumberOfElementsInMemory(segInfo.size()); segmentsProp.setSizeOfElements(0x2); for (int i = 0; i < segInfo.size(); i++) { - byte[] seg = (byte[])segInfo.get(i); + byte[] seg = segInfo.get(i); segmentsProp.setElement(i, seg); } opt.addEscherProperty(segmentsProp); @@ -171,10 +180,10 @@ public final class Freeform extends AutoShape { opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); 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)); - if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__SEGMENTINFO)); + if(segmentsProp == null) segmentsProp = (EscherArrayProperty)getEscherProperty(opt, EscherProperties.GEOMETRY__SEGMENTINFO); //sanity check if(verticesProp == null) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CString.java b/src/scratchpad/src/org/apache/poi/hslf/record/CString.java index a428621e63..41f49fcd9d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CString.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CString.java @@ -58,7 +58,7 @@ public final class CString extends RecordAtom { * The meaning of the count is specific to the type of the parent record */ public int getOptions() { - return (int)LittleEndian.getShort(_header); + return LittleEndian.getShort(_header); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java index 4aea93f869..9d14b7bff5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java @@ -30,9 +30,7 @@ import java.io.ByteArrayOutputStream; * * @author Nick Burch */ - -public final class ColorSchemeAtom extends RecordAtom -{ +public final class ColorSchemeAtom extends RecordAtom { private byte[] _header; private static long _type = 2032l; @@ -108,14 +106,14 @@ public final class ColorSchemeAtom extends RecordAtom System.arraycopy(source,start,_header,0,8); // Grab the rgb values - backgroundColourRGB = (int)LittleEndian.getInt(source,start+8+0); - textAndLinesColourRGB = (int)LittleEndian.getInt(source,start+8+4); - shadowsColourRGB = (int)LittleEndian.getInt(source,start+8+8); - titleTextColourRGB = (int)LittleEndian.getInt(source,start+8+12); - fillsColourRGB = (int)LittleEndian.getInt(source,start+8+16); - accentColourRGB = (int)LittleEndian.getInt(source,start+8+20); - accentAndHyperlinkColourRGB = (int)LittleEndian.getInt(source,start+8+24); - accentAndFollowingHyperlinkColourRGB = (int)LittleEndian.getInt(source,start+8+28); + backgroundColourRGB = LittleEndian.getInt(source,start+8+0); + textAndLinesColourRGB = LittleEndian.getInt(source,start+8+4); + shadowsColourRGB = LittleEndian.getInt(source,start+8+8); + titleTextColourRGB = LittleEndian.getInt(source,start+8+12); + fillsColourRGB = LittleEndian.getInt(source,start+8+16); + accentColourRGB = LittleEndian.getInt(source,start+8+20); + accentAndHyperlinkColourRGB = LittleEndian.getInt(source,start+8+24); + accentAndFollowingHyperlinkColourRGB = LittleEndian.getInt(source,start+8+28); } /** @@ -181,7 +179,7 @@ public final class ColorSchemeAtom extends RecordAtom byte[] with_zero = new byte[4]; System.arraycopy(rgb,0,with_zero,0,3); with_zero[3] = 0; - int ret = (int)LittleEndian.getInt(with_zero,0); + int ret = LittleEndian.getInt(with_zero,0); return ret; } @@ -205,16 +203,15 @@ public final class ColorSchemeAtom extends RecordAtom writeLittleEndian(accentAndFollowingHyperlinkColourRGB,out); } - /** - * Returns color by its index - * - * @param idx 0-based color index - * @return color by its index - */ - public int getColor(int idx){ - int[] clr = {backgroundColourRGB, textAndLinesColourRGB, shadowsColourRGB, titleTextColourRGB, - fillsColourRGB, accentColourRGB, accentAndHyperlinkColourRGB, accentAndFollowingHyperlinkColourRGB}; - return clr[idx]; - } - + /** + * Returns color by its index + * + * @param idx 0-based color index + * @return color by its index + */ + public int getColor(int idx){ + int[] clr = {backgroundColourRGB, textAndLinesColourRGB, shadowsColourRGB, titleTextColourRGB, + fillsColourRGB, accentColourRGB, accentAndHyperlinkColourRGB, accentAndFollowingHyperlinkColourRGB}; + return clr[idx]; + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java index 3b28ab56a5..22a9b7c3ef 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentAtom.java @@ -80,16 +80,23 @@ public final class DocumentAtom extends RecordAtom /** Was the document saved with True Type fonts embeded? */ public boolean getSaveWithFonts() { - if(saveWithFonts == 0) { return false; } else { return true; } } + return saveWithFonts != 0; + } + /** Have the placeholders on the title slide been omitted? */ public boolean getOmitTitlePlace() { - if(omitTitlePlace == 0) { return false; } else { return true; } } + return omitTitlePlace != 0; + } + /** Is this a Bi-Directional PPT Doc? */ public boolean getRightToLeft() { - if(rightToLeft == 0) { return false; } else { return true; } } + return rightToLeft != 0; + } + /** Are comment shapes visible? */ public boolean getShowComments() { - if(showComments == 0) { return false; } else { return true; } } + return showComments != 0; + } /* *************** record code follows ********************** */ @@ -118,10 +125,10 @@ public final class DocumentAtom extends RecordAtom handoutMasterPersist = LittleEndian.getInt(source,start+28+8); // 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 - slideSizeType = (int)LittleEndian.getShort(source,start+34+8); + slideSizeType = LittleEndian.getShort(source,start+34+8); // Get the booleans as bytes saveWithFonts = source[start+36+8]; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java b/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java index 8476d3dd56..37583354d1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java @@ -32,12 +32,10 @@ import java.io.ByteArrayOutputStream; * * @author Nick Burch */ - -public final class EscherTextboxWrapper extends RecordContainer -{ +public final class EscherTextboxWrapper extends RecordContainer { private EscherTextboxRecord _escherRecord; private long _type; - private int shapeId; + private int shapeId; /** * Returns the underlying DDF Escher Record @@ -49,7 +47,7 @@ public final class EscherTextboxWrapper extends RecordContainer */ public EscherTextboxWrapper(EscherTextboxRecord textbox) { _escherRecord = textbox; - _type = (long)_escherRecord.getRecordId(); + _type = _escherRecord.getRecordId(); // Find the child records in the escher data byte[] data = _escherRecord.getData(); @@ -93,17 +91,17 @@ public final class EscherTextboxWrapper extends RecordContainer _escherRecord.setData(data); } - /** - * @return Shape ID - */ - public int getShapeId(){ - return shapeId; - } - - /** - * @param id Shape ID - */ - public void setShapeId(int id){ - shapeId = id; - } + /** + * @return Shape ID + */ + public int getShapeId(){ + return shapeId; + } + + /** + * @param id Shape ID + */ + public void setShapeId(int id){ + shapeId = id; + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java index bf4c5fe1a9..7aace80632 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java @@ -65,7 +65,7 @@ public final class NotesAtom extends RecordAtom System.arraycopy(source,start,_header,0,8); // Get the slide ID - slideID = (int)LittleEndian.getInt(source,start+8); + slideID = LittleEndian.getInt(source,start+8); // Grok the flags, stored as bits int flags = LittleEndian.getUShort(source,start+12); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java index f759ed02c1..8d697843fc 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java @@ -86,8 +86,8 @@ public final class SlideAtom extends RecordAtom layoutAtom = new SSlideLayoutAtom(SSlideLayoutAtomData); // Get the IDs of the master and notes - masterID = (int)LittleEndian.getInt(source,start+12+8); - notesID = (int)LittleEndian.getInt(source,start+16+8); + masterID = LittleEndian.getInt(source,start+12+8); + notesID = LittleEndian.getInt(source,start+16+8); // Grok the flags, stored as bits int flags = LittleEndian.getUShort(source,start+20+8); @@ -214,7 +214,7 @@ public final class SlideAtom extends RecordAtom } // Grab out our data - geometry = (int)LittleEndian.getInt(data,0); + geometry = LittleEndian.getInt(data,0); placeholderIDs = new byte[8]; System.arraycopy(data,4,placeholderIDs,0,8); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java index a567cff830..0ac22adf34 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java @@ -27,9 +27,7 @@ import java.io.OutputStream; * * @author Nick Burch */ - -public final class SlidePersistAtom extends RecordAtom -{ +public final class SlidePersistAtom extends RecordAtom { private byte[] _header; private static long _type = 1011l; @@ -76,10 +74,10 @@ public final class SlidePersistAtom extends RecordAtom System.arraycopy(source,start,_header,0,8); // 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! - int flags = (int)LittleEndian.getInt(source,start+12); + int flags = LittleEndian.getInt(source,start+12); if(flags == 4) { hasShapesOtherThanPlaceholders = true; } else { @@ -87,10 +85,10 @@ public final class SlidePersistAtom extends RecordAtom } // 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 - slideIdentifier = (int)LittleEndian.getInt(source,start+20); + slideIdentifier = LittleEndian.getInt(source,start+20); // Finally you have typically 4 or 8 bytes of reserved fields, // all zero running from 24 bytes in to the end diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java index 9931eb93b1..d19a6c1c01 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java @@ -72,7 +72,7 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor System.arraycopy(source,start,_header,0,8); // Grab the type - textType = (int)LittleEndian.getInt(source,start+8); + textType = LittleEndian.getInt(source,start+8); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java index 97765c408b..878e846af5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java @@ -82,30 +82,30 @@ public final class UserEditAtom extends PositionDependentRecordAtom System.arraycopy(source,start,_header,0,8); // 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 - 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 // This will be the byte offset on disk where the previous 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 // This will be the byte offset on disk where the preceding // 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 // 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 - maxPersistWritten = (int)LittleEndian.getInt(source,start+20+8); + maxPersistWritten = LittleEndian.getInt(source,start+20+8); // 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 reserved = new byte[len-26-8]; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java index 5004285050..47af9dfc52 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -42,17 +42,13 @@ import org.apache.poi.poifs.property.DocumentProperty; 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. - * + * * @author Travis Ferguson */ -public class POIFSChunkParser { - /** - * Constructor - * @param fs - * @throws IOException - */ +public final class POIFSChunkParser { + public POIFSChunkParser(POIFSFileSystem fs) throws IOException { this.setFileSystem(fs); } @@ -61,7 +57,6 @@ public class POIFSChunkParser { /** * Set the POIFileSystem object that this object is using. * @param fs - * @throws IOException */ public void setFileSystem(POIFSFileSystem fs) throws IOException { this.fs = fs; @@ -77,33 +72,32 @@ public class POIFSChunkParser { /** * Reparse the FileSystem object, resetting all the chunks stored in this object - * @throws IOException * */ public void reparseFileSystem() throws IOException { // first clear this object of all chunks DirectoryEntry root = this.fs.getRoot(); Iterator iter = root.getEntries(); - + 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. */ public Chunks identifyChunks() { 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. */ private AttachmentChunks identifyAttachmentChunks(Map attachmentMap) { return AttachmentChunks.getInstance(this.isNewChunkVersion(attachmentMap)); } - + /** * Return chunk version of the map in parameter */ @@ -113,10 +107,10 @@ public class POIFSChunkParser { boolean hasNewStrings = false; String oldStringEnd = Types.asFileEnding(Types.OLD_STRING); String newStringEnd = Types.asFileEnding(Types.NEW_STRING); - + for(Iterator i = map.keySet().iterator(); i.hasNext();) { String entry = (String)i.next(); - + if(entry.endsWith( oldStringEnd )) { hasOldStrings = true; } @@ -124,7 +118,7 @@ public class POIFSChunkParser { hasNewStrings = true; } } - + if(hasOldStrings && hasNewStrings) { throw new IllegalStateException("Your file contains string chunks of both the old and new types. Giving up"); } else if(hasNewStrings) { @@ -132,18 +126,18 @@ public class POIFSChunkParser { } return false; } - + /** * Pull the chunk data that's stored in this object's hashmap out and return it as a HashMap. * @param entryName */ public Object getChunk(HashMap dirMap, String entryName) { - if(dirMap == null) return null; - else { - return dirMap.get(entryName); + if(dirMap == null) { + return null; } + return dirMap.get(entryName); } - + /** * Pull a directory/hashmap out of this hashmap and return it * @param directoryName @@ -155,14 +149,14 @@ public class POIFSChunkParser { DirectoryChunkNotFoundException excep = new DirectoryChunkNotFoundException(directoryName); Object obj = getChunk(this.directoryMap, directoryName); if(obj == null || !(obj instanceof HashMap)) throw excep; - + 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. * @param dirNode - * @param chunk + * @param chunk * @throws ChunkNotFoundException */ public Chunk getDocumentNode(HashMap dirNode, Chunk chunk) throws ChunkNotFoundException { @@ -170,12 +164,12 @@ public class POIFSChunkParser { ChunkNotFoundException excep = new ChunkNotFoundException(entryName); Object obj = getChunk(dirNode, entryName); if(obj == null || !(obj instanceof ByteArrayOutputStream)) throw excep; - + chunk.setValue((ByteArrayOutputStream)obj); - + return chunk; } - + /** * Pulls a Chunk out of this objects root Node tree. * @param chunk @@ -184,9 +178,9 @@ public class POIFSChunkParser { public Chunk getDocumentNode(Chunk chunk) throws ChunkNotFoundException { return getDocumentNode(this.directoryMap, chunk); } - + /** - * + * * @return a map containing attachment name (String) and data (ByteArrayInputStream) */ public Map getAttachmentList() { @@ -194,12 +188,12 @@ public class POIFSChunkParser { List attachmentList = new ArrayList(); for(Iterator i = directoryMap.keySet().iterator(); i.hasNext();) { String entry = (String)i.next(); - + if(entry.startsWith(AttachmentChunks.namePrefix)) { String attachmentIdString = entry.replace(AttachmentChunks.namePrefix, ""); try { int attachmentId = Integer.parseInt(attachmentIdString); - attachmentList.add((HashMap)directoryMap.get(entry)); + attachmentList.add(directoryMap.get(entry)); } catch (NumberFormatException nfe) { System.err.println("Invalid attachment id"); } @@ -218,7 +212,7 @@ public class POIFSChunkParser { } return attachments; } - + /** * Processes an iterator returned by a POIFS call to getRoot().getEntries() * @param iter @@ -226,85 +220,85 @@ public class POIFSChunkParser { * @throws IOException */ private HashMap processPOIIterator(Iterator iter) throws IOException { - 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++) { - viewList.add(arr[i]); - } - viewIt = viewList.iterator(); - } 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; - } + 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++) { + viewList.add(arr[i]); + } + viewIt = viewList.iterator(); + } 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 - * @param obj - * @throws java.io.IOException - */ - private void processDocumentNode(DocumentNode obj, HashMap currentObj) throws IOException { - String blockName = ((DocumentNode)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++) { - viewList.add(arr[i]); - } - viewIt = viewList.iterator(); - } else { - viewIt = ((DocumentNode)obj).getViewableIterator(); - } - - while(viewIt.hasNext()) { - Object view = viewIt.next(); - - if(view instanceof DocumentProperty) { - //we don't care about the properties - } else if(view instanceof POIFSDocument) { - //check if our node has blocks or if it can just be read raw. - int blockCount = ((POIFSDocument)view).countBlocks(); - //System.out.println("Block Name: " + blockName); - if(blockCount <= 0) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - BlockWritable[] bws = ((POIFSDocument)view).getSmallBlocks(); - for(int i = 0; i < bws.length; i++) { - bws[i].writeBlocks(out); - } - currentObj.put(blockName, out); - } else { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ((POIFSDocument)view).writeBlocks(out); - currentObj.put(blockName, out); - } - } else { - System.err.println("Unknown View Type: " + view.toString()); - } - } - } + * Processes a document node and adds it to the current directory HashMap + * @param obj + * @throws java.io.IOException + */ + private void processDocumentNode(DocumentNode obj, HashMap currentObj) throws IOException { + String blockName = obj.getName(); + + Iterator viewIt = null; + if( obj.preferArray()) { + Object[] arr = obj.getViewableArray(); + ArrayList viewList = new ArrayList(arr.length); + + for(int i = 0; i < arr.length; i++) { + viewList.add(arr[i]); + } + viewIt = viewList.iterator(); + } else { + viewIt = obj.getViewableIterator(); + } + + while(viewIt.hasNext()) { + Object view = viewIt.next(); + + if(view instanceof DocumentProperty) { + //we don't care about the properties + } else if(view instanceof POIFSDocument) { + //check if our node has blocks or if it can just be read raw. + int blockCount = ((POIFSDocument)view).countBlocks(); + //System.out.println("Block Name: " + blockName); + if(blockCount <= 0) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + BlockWritable[] bws = ((POIFSDocument)view).getSmallBlocks(); + for(int i = 0; i < bws.length; i++) { + bws[i].writeBlocks(out); + } + currentObj.put(blockName, out); + } else { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ((POIFSDocument)view).writeBlocks(out); + currentObj.put(blockName, out); + } + } else { + System.err.println("Unknown View Type: " + view.toString()); + } + } + } /* private instance variables */ private static final long serialVersionUID = 1L; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java index e9ab368b3a..be95dd17c5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListData.java @@ -133,7 +133,7 @@ public final class ListData int resetListID() { - _lsid = (int)(Math.random() * (double)System.currentTimeMillis()); + _lsid = (int)(Math.random() * System.currentTimeMillis()); return _lsid; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index c0a6a029aa..edb74eace6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -225,21 +225,19 @@ public final class StyleSheet implements HDFType { { parentPAP = _styleDescriptions[baseIndex].getPAP(); - if(parentPAP == null) - { - if(baseIndex == istd) { - // 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"); - } else { - // Create the parent style - createPap(baseIndex); - parentPAP = _styleDescriptions[baseIndex].getPAP(); - } + if(parentPAP == null) { + if(baseIndex == istd) { + // 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"); + } + // Create the parent style + createPap(baseIndex); + parentPAP = _styleDescriptions[baseIndex].getPAP(); } } - pap = (ParagraphProperties)ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2); + pap = ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2); 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); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java index de5896ea40..00a19b30d8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/CHPAbstractType.java @@ -818,9 +818,7 @@ public abstract class CHPAbstractType */ 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() { return fBold.isSet(field_2_format_flags); - } /** @@ -839,9 +836,7 @@ public abstract class CHPAbstractType */ 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() { return fItalic.isSet(field_2_format_flags); - } /** @@ -860,9 +854,7 @@ public abstract class CHPAbstractType */ 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() { return fRMarkDel.isSet(field_2_format_flags); - } /** @@ -881,9 +872,7 @@ public abstract class CHPAbstractType */ 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() { return fOutline.isSet(field_2_format_flags); - } /** @@ -902,9 +890,7 @@ public abstract class CHPAbstractType */ 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() { return fFldVanish.isSet(field_2_format_flags); - } /** @@ -923,9 +908,7 @@ public abstract class CHPAbstractType */ 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() { return fSmallCaps.isSet(field_2_format_flags); - } /** @@ -944,9 +926,7 @@ public abstract class CHPAbstractType */ 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() { return fCaps.isSet(field_2_format_flags); - } /** @@ -965,9 +944,7 @@ public abstract class CHPAbstractType */ 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() { return fVanish.isSet(field_2_format_flags); - } /** @@ -986,9 +962,7 @@ public abstract class CHPAbstractType */ 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() { return fRMark.isSet(field_2_format_flags); - } /** @@ -1007,9 +980,7 @@ public abstract class CHPAbstractType */ 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() { return fSpec.isSet(field_2_format_flags); - } /** @@ -1028,9 +998,7 @@ public abstract class CHPAbstractType */ 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() { return fStrike.isSet(field_2_format_flags); - } /** @@ -1049,9 +1016,7 @@ public abstract class CHPAbstractType */ 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() { return fObj.isSet(field_2_format_flags); - } /** @@ -1070,9 +1034,7 @@ public abstract class CHPAbstractType */ 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() { return fShadow.isSet(field_2_format_flags); - } /** @@ -1091,9 +1052,7 @@ public abstract class CHPAbstractType */ 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() { return fLowerCase.isSet(field_2_format_flags); - } /** @@ -1112,9 +1070,7 @@ public abstract class CHPAbstractType */ 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() { return fData.isSet(field_2_format_flags); - } /** @@ -1133,9 +1088,7 @@ public abstract class CHPAbstractType */ 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() { return fOle2.isSet(field_2_format_flags); - } /** @@ -1154,9 +1106,7 @@ public abstract class CHPAbstractType */ 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() { return fEmboss.isSet(field_3_format_flags1); - } /** @@ -1175,9 +1124,7 @@ public abstract class CHPAbstractType */ 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() { return fImprint.isSet(field_3_format_flags1); - } /** @@ -1196,9 +1142,7 @@ public abstract class CHPAbstractType */ 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() { return fDStrike.isSet(field_3_format_flags1); - } /** @@ -1217,9 +1160,7 @@ public abstract class CHPAbstractType */ 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() { return fUsePgsuSettings.isSet(field_3_format_flags1); - } /** @@ -1239,8 +1179,6 @@ public abstract class CHPAbstractType public void setIcoHighlight(byte value) { field_33_Highlight = (short)icoHighlight.setValue(field_33_Highlight, value); - - } /** @@ -1250,7 +1188,6 @@ public abstract class CHPAbstractType public byte getIcoHighlight() { return ( byte )icoHighlight.getValue(field_33_Highlight); - } /** @@ -1260,8 +1197,6 @@ public abstract class CHPAbstractType public void setFHighlight(boolean value) { field_33_Highlight = (short)fHighlight.setBoolean(field_33_Highlight, value); - - } /** @@ -1271,7 +1206,6 @@ public abstract class CHPAbstractType public boolean isFHighlight() { return fHighlight.isSet(field_33_Highlight); - } /** @@ -1281,8 +1215,6 @@ public abstract class CHPAbstractType public void setKcd(byte value) { field_33_Highlight = (short)kcd.setValue(field_33_Highlight, value); - - } /** @@ -1292,7 +1224,6 @@ public abstract class CHPAbstractType public byte getKcd() { return ( byte )kcd.getValue(field_33_Highlight); - } /** @@ -1302,8 +1233,6 @@ public abstract class CHPAbstractType public void setFNavHighlight(boolean value) { field_33_Highlight = (short)fNavHighlight.setBoolean(field_33_Highlight, value); - - } /** @@ -1313,7 +1242,6 @@ public abstract class CHPAbstractType public boolean isFNavHighlight() { return fNavHighlight.isSet(field_33_Highlight); - } /** @@ -1323,8 +1251,6 @@ public abstract class CHPAbstractType public void setFChsDiff(boolean value) { field_33_Highlight = (short)fChsDiff.setBoolean(field_33_Highlight, value); - - } /** @@ -1334,7 +1260,6 @@ public abstract class CHPAbstractType public boolean isFChsDiff() { return fChsDiff.isSet(field_33_Highlight); - } /** @@ -1344,8 +1269,6 @@ public abstract class CHPAbstractType public void setFMacChs(boolean value) { field_33_Highlight = (short)fMacChs.setBoolean(field_33_Highlight, value); - - } /** @@ -1355,7 +1278,6 @@ public abstract class CHPAbstractType public boolean isFMacChs() { return fMacChs.isSet(field_33_Highlight); - } /** @@ -1365,8 +1287,6 @@ public abstract class CHPAbstractType public void setFFtcAsciSym(boolean value) { field_33_Highlight = (short)fFtcAsciSym.setBoolean(field_33_Highlight, value); - - } /** @@ -1376,12 +1296,5 @@ public abstract class CHPAbstractType public boolean isFFtcAsciSym() { return fFtcAsciSym.isSet(field_33_Highlight); - } - - -} // END OF CLASS - - - - +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java index d7530196ab..b623f4a27e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java @@ -239,65 +239,63 @@ public abstract class DOPAbstractType implements HDFType { field_51_nfcEdnRef = LittleEndian.getShort(data, 0x1ee + offset); field_52_hpsZoonFontPag = LittleEndian.getShort(data, 0x1f0 + offset); field_53_dywDispPag = LittleEndian.getShort(data, 0x1f2 + offset); - } public void serialize(byte[] data, int offset) { - data[ 0x0 + offset] = field_1_formatFlags;; - data[ 0x1 + offset] = field_2_unused2;; - LittleEndian.putShort(data, 0x2 + offset, (short)field_3_footnoteInfo);; - data[ 0x4 + offset] = field_4_fOutlineDirtySave;; - data[ 0x5 + offset] = field_5_docinfo;; - data[ 0x6 + offset] = field_6_docinfo1;; - data[ 0x7 + offset] = field_7_docinfo2;; - LittleEndian.putShort(data, 0x8 + offset, (short)field_8_docinfo3);; - LittleEndian.putShort(data, 0xa + offset, (short)field_9_dxaTab);; - LittleEndian.putShort(data, 0xc + offset, (short)field_10_wSpare);; - LittleEndian.putShort(data, 0xe + offset, (short)field_11_dxaHotz);; - LittleEndian.putShort(data, 0x10 + offset, (short)field_12_cConsexHypLim);; - LittleEndian.putShort(data, 0x12 + offset, (short)field_13_wSpare2);; - LittleEndian.putInt(data, 0x14 + offset, field_14_dttmCreated);; - LittleEndian.putInt(data, 0x18 + offset, field_15_dttmRevised);; - LittleEndian.putInt(data, 0x1c + offset, field_16_dttmLastPrint);; - LittleEndian.putShort(data, 0x20 + offset, (short)field_17_nRevision);; - LittleEndian.putInt(data, 0x22 + offset, field_18_tmEdited);; - LittleEndian.putInt(data, 0x26 + offset, field_19_cWords);; - LittleEndian.putInt(data, 0x2a + offset, field_20_cCh);; - LittleEndian.putShort(data, 0x2e + offset, (short)field_21_cPg);; - LittleEndian.putInt(data, 0x30 + offset, field_22_cParas);; - LittleEndian.putShort(data, 0x34 + offset, (short)field_23_Edn);; - LittleEndian.putShort(data, 0x36 + offset, (short)field_24_Edn1);; - LittleEndian.putInt(data, 0x38 + offset, field_25_cLines);; - LittleEndian.putInt(data, 0x3c + offset, field_26_cWordsFtnEnd);; - LittleEndian.putInt(data, 0x40 + offset, field_27_cChFtnEdn);; - LittleEndian.putShort(data, 0x44 + offset, (short)field_28_cPgFtnEdn);; - LittleEndian.putInt(data, 0x46 + offset, field_29_cParasFtnEdn);; - LittleEndian.putInt(data, 0x4a + offset, field_30_cLinesFtnEdn);; - LittleEndian.putInt(data, 0x4e + offset, field_31_lKeyProtDoc);; - LittleEndian.putShort(data, 0x52 + offset, (short)field_32_view);; - LittleEndian.putInt(data, 0x54 + offset, field_33_docinfo4);; - LittleEndian.putShort(data, 0x58 + offset, (short)field_34_adt);; - System.arraycopy(field_35_doptypography, 0, data, 0x5a + offset, field_35_doptypography.length);; - System.arraycopy(field_36_dogrid, 0, data, 0x190 + offset, field_36_dogrid.length);; - LittleEndian.putShort(data, 0x19a + offset, (short)field_37_docinfo5);; - LittleEndian.putShort(data, 0x19c + offset, (short)field_38_docinfo6);; - System.arraycopy(field_39_asumyi, 0, data, 0x19e + offset, field_39_asumyi.length);; - LittleEndian.putInt(data, 0x1aa + offset, field_40_cChWS);; - LittleEndian.putInt(data, 0x1ae + offset, field_41_cChWSFtnEdn);; - LittleEndian.putInt(data, 0x1b2 + offset, field_42_grfDocEvents);; - LittleEndian.putInt(data, 0x1b6 + offset, field_43_virusinfo);; - System.arraycopy(field_44_Spare, 0, data, 0x1ba + offset, field_44_Spare.length);; - LittleEndian.putInt(data, 0x1d8 + offset, field_45_reserved1);; - LittleEndian.putInt(data, 0x1dc + offset, field_46_reserved2);; - LittleEndian.putInt(data, 0x1e0 + offset, field_47_cDBC);; - LittleEndian.putInt(data, 0x1e4 + offset, field_48_cDBCFtnEdn);; - LittleEndian.putInt(data, 0x1e8 + offset, field_49_reserved);; - LittleEndian.putShort(data, 0x1ec + offset, (short)field_50_nfcFtnRef);; - LittleEndian.putShort(data, 0x1ee + offset, (short)field_51_nfcEdnRef);; - LittleEndian.putShort(data, 0x1f0 + offset, (short)field_52_hpsZoonFontPag);; - LittleEndian.putShort(data, 0x1f2 + offset, (short)field_53_dywDispPag);; - + data[ 0x0 + offset] = field_1_formatFlags; + data[ 0x1 + offset] = field_2_unused2; + LittleEndian.putShort(data, 0x2 + offset, field_3_footnoteInfo); + data[ 0x4 + offset] = field_4_fOutlineDirtySave; + data[ 0x5 + offset] = field_5_docinfo; + data[ 0x6 + offset] = field_6_docinfo1; + data[ 0x7 + offset] = field_7_docinfo2; + LittleEndian.putShort(data, 0x8 + offset, field_8_docinfo3); + LittleEndian.putShort(data, 0xa + offset, (short)field_9_dxaTab); + LittleEndian.putShort(data, 0xc + offset, (short)field_10_wSpare); + LittleEndian.putShort(data, 0xe + offset, (short)field_11_dxaHotz); + LittleEndian.putShort(data, 0x10 + offset, (short)field_12_cConsexHypLim); + LittleEndian.putShort(data, 0x12 + offset, (short)field_13_wSpare2); + LittleEndian.putInt(data, 0x14 + offset, field_14_dttmCreated); + LittleEndian.putInt(data, 0x18 + offset, field_15_dttmRevised); + LittleEndian.putInt(data, 0x1c + offset, field_16_dttmLastPrint); + LittleEndian.putShort(data, 0x20 + offset, (short)field_17_nRevision); + LittleEndian.putInt(data, 0x22 + offset, field_18_tmEdited); + LittleEndian.putInt(data, 0x26 + offset, field_19_cWords); + LittleEndian.putInt(data, 0x2a + offset, field_20_cCh); + LittleEndian.putShort(data, 0x2e + offset, (short)field_21_cPg); + LittleEndian.putInt(data, 0x30 + offset, field_22_cParas); + LittleEndian.putShort(data, 0x34 + offset, field_23_Edn); + LittleEndian.putShort(data, 0x36 + offset, field_24_Edn1); + LittleEndian.putInt(data, 0x38 + offset, field_25_cLines); + LittleEndian.putInt(data, 0x3c + offset, field_26_cWordsFtnEnd); + LittleEndian.putInt(data, 0x40 + offset, field_27_cChFtnEdn); + LittleEndian.putShort(data, 0x44 + offset, field_28_cPgFtnEdn); + LittleEndian.putInt(data, 0x46 + offset, field_29_cParasFtnEdn); + LittleEndian.putInt(data, 0x4a + offset, field_30_cLinesFtnEdn); + LittleEndian.putInt(data, 0x4e + offset, field_31_lKeyProtDoc); + LittleEndian.putShort(data, 0x52 + offset, field_32_view); + LittleEndian.putInt(data, 0x54 + offset, field_33_docinfo4); + LittleEndian.putShort(data, 0x58 + offset, field_34_adt); + System.arraycopy(field_35_doptypography, 0, data, 0x5a + offset, field_35_doptypography.length); + System.arraycopy(field_36_dogrid, 0, data, 0x190 + offset, field_36_dogrid.length); + LittleEndian.putShort(data, 0x19a + offset, field_37_docinfo5); + LittleEndian.putShort(data, 0x19c + offset, field_38_docinfo6); + System.arraycopy(field_39_asumyi, 0, data, 0x19e + offset, field_39_asumyi.length); + LittleEndian.putInt(data, 0x1aa + offset, field_40_cChWS); + LittleEndian.putInt(data, 0x1ae + offset, field_41_cChWSFtnEdn); + LittleEndian.putInt(data, 0x1b2 + offset, field_42_grfDocEvents); + LittleEndian.putInt(data, 0x1b6 + offset, field_43_virusinfo); + System.arraycopy(field_44_Spare, 0, data, 0x1ba + offset, field_44_Spare.length); + LittleEndian.putInt(data, 0x1d8 + offset, field_45_reserved1); + LittleEndian.putInt(data, 0x1dc + offset, field_46_reserved2); + LittleEndian.putInt(data, 0x1e0 + offset, field_47_cDBC); + LittleEndian.putInt(data, 0x1e4 + offset, field_48_cDBCFtnEdn); + LittleEndian.putInt(data, 0x1e8 + offset, field_49_reserved); + LittleEndian.putShort(data, 0x1ec + offset, field_50_nfcFtnRef); + LittleEndian.putShort(data, 0x1ee + offset, field_51_nfcEdnRef); + LittleEndian.putShort(data, 0x1f0 + offset, field_52_hpsZoonFontPag); + LittleEndian.putShort(data, 0x1f2 + offset, field_53_dywDispPag); } public String toString() @@ -1426,8 +1424,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFFacingPages(boolean value) { field_1_formatFlags = (byte)fFacingPages.setBoolean(field_1_formatFlags, value); - - } /** @@ -1437,7 +1433,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFFacingPages() { return fFacingPages.isSet(field_1_formatFlags); - } /** @@ -1447,8 +1442,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFWidowControl(boolean value) { field_1_formatFlags = (byte)fWidowControl.setBoolean(field_1_formatFlags, value); - - } /** @@ -1458,7 +1451,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFWidowControl() { return fWidowControl.isSet(field_1_formatFlags); - } /** @@ -1468,8 +1460,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFPMHMainDoc(boolean value) { field_1_formatFlags = (byte)fPMHMainDoc.setBoolean(field_1_formatFlags, value); - - } /** @@ -1479,7 +1469,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFPMHMainDoc() { return fPMHMainDoc.isSet(field_1_formatFlags); - } /** @@ -1489,8 +1478,6 @@ public abstract class DOPAbstractType implements HDFType { public void setGrfSupression(byte value) { field_1_formatFlags = (byte)grfSupression.setValue(field_1_formatFlags, value); - - } /** @@ -1500,7 +1487,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getGrfSupression() { return ( byte )grfSupression.getValue(field_1_formatFlags); - } /** @@ -1510,8 +1496,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFpc(byte value) { field_1_formatFlags = (byte)fpc.setValue(field_1_formatFlags, value); - - } /** @@ -1521,7 +1505,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getFpc() { return ( byte )fpc.getValue(field_1_formatFlags); - } /** @@ -1531,8 +1514,6 @@ public abstract class DOPAbstractType implements HDFType { public void setUnused1(boolean value) { field_1_formatFlags = (byte)unused1.setBoolean(field_1_formatFlags, value); - - } /** @@ -1542,7 +1523,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isUnused1() { return unused1.isSet(field_1_formatFlags); - } /** @@ -1552,8 +1532,6 @@ public abstract class DOPAbstractType implements HDFType { public void setRncFtn(byte value) { field_3_footnoteInfo = (short)rncFtn.setValue(field_3_footnoteInfo, value); - - } /** @@ -1563,7 +1541,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getRncFtn() { return ( byte )rncFtn.getValue(field_3_footnoteInfo); - } /** @@ -1573,8 +1550,6 @@ public abstract class DOPAbstractType implements HDFType { public void setNFtn(short value) { field_3_footnoteInfo = (short)nFtn.setValue(field_3_footnoteInfo, value); - - } /** @@ -1584,7 +1559,6 @@ public abstract class DOPAbstractType implements HDFType { public short getNFtn() { return ( short )nFtn.getValue(field_3_footnoteInfo); - } /** @@ -1594,8 +1568,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFOnlyMacPics(boolean value) { field_5_docinfo = (byte)fOnlyMacPics.setBoolean(field_5_docinfo, value); - - } /** @@ -1605,7 +1577,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFOnlyMacPics() { return fOnlyMacPics.isSet(field_5_docinfo); - } /** @@ -1615,8 +1586,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFOnlyWinPics(boolean value) { field_5_docinfo = (byte)fOnlyWinPics.setBoolean(field_5_docinfo, value); - - } /** @@ -1626,7 +1595,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFOnlyWinPics() { return fOnlyWinPics.isSet(field_5_docinfo); - } /** @@ -1636,8 +1604,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFLabelDoc(boolean value) { field_5_docinfo = (byte)fLabelDoc.setBoolean(field_5_docinfo, value); - - } /** @@ -1647,7 +1613,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFLabelDoc() { return fLabelDoc.isSet(field_5_docinfo); - } /** @@ -1657,8 +1622,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFHyphCapitals(boolean value) { field_5_docinfo = (byte)fHyphCapitals.setBoolean(field_5_docinfo, value); - - } /** @@ -1668,7 +1631,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFHyphCapitals() { return fHyphCapitals.isSet(field_5_docinfo); - } /** @@ -1678,8 +1640,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFAutoHyphen(boolean value) { field_5_docinfo = (byte)fAutoHyphen.setBoolean(field_5_docinfo, value); - - } /** @@ -1689,7 +1649,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFAutoHyphen() { return fAutoHyphen.isSet(field_5_docinfo); - } /** @@ -1699,8 +1658,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFFormNoFields(boolean value) { field_5_docinfo = (byte)fFormNoFields.setBoolean(field_5_docinfo, value); - - } /** @@ -1710,7 +1667,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFFormNoFields() { return fFormNoFields.isSet(field_5_docinfo); - } /** @@ -1720,8 +1676,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFLinkStyles(boolean value) { field_5_docinfo = (byte)fLinkStyles.setBoolean(field_5_docinfo, value); - - } /** @@ -1731,7 +1685,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFLinkStyles() { return fLinkStyles.isSet(field_5_docinfo); - } /** @@ -1741,8 +1694,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFRevMarking(boolean value) { field_5_docinfo = (byte)fRevMarking.setBoolean(field_5_docinfo, value); - - } /** @@ -1752,7 +1703,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFRevMarking() { return fRevMarking.isSet(field_5_docinfo); - } /** @@ -1762,8 +1712,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFBackup(boolean value) { field_6_docinfo1 = (byte)fBackup.setBoolean(field_6_docinfo1, value); - - } /** @@ -1773,7 +1721,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFBackup() { return fBackup.isSet(field_6_docinfo1); - } /** @@ -1783,8 +1730,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFExactCWords(boolean value) { field_6_docinfo1 = (byte)fExactCWords.setBoolean(field_6_docinfo1, value); - - } /** @@ -1794,7 +1739,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFExactCWords() { return fExactCWords.isSet(field_6_docinfo1); - } /** @@ -1804,8 +1748,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFPagHidden(boolean value) { field_6_docinfo1 = (byte)fPagHidden.setBoolean(field_6_docinfo1, value); - - } /** @@ -1815,7 +1757,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFPagHidden() { return fPagHidden.isSet(field_6_docinfo1); - } /** @@ -1825,8 +1766,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFPagResults(boolean value) { field_6_docinfo1 = (byte)fPagResults.setBoolean(field_6_docinfo1, value); - - } /** @@ -1836,7 +1775,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFPagResults() { return fPagResults.isSet(field_6_docinfo1); - } /** @@ -1846,8 +1784,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFLockAtn(boolean value) { field_6_docinfo1 = (byte)fLockAtn.setBoolean(field_6_docinfo1, value); - - } /** @@ -1857,7 +1793,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFLockAtn() { return fLockAtn.isSet(field_6_docinfo1); - } /** @@ -1867,8 +1802,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFMirrorMargins(boolean value) { field_6_docinfo1 = (byte)fMirrorMargins.setBoolean(field_6_docinfo1, value); - - } /** @@ -1878,7 +1811,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFMirrorMargins() { return fMirrorMargins.isSet(field_6_docinfo1); - } /** @@ -1888,8 +1820,6 @@ public abstract class DOPAbstractType implements HDFType { public void setUnused3(boolean value) { field_6_docinfo1 = (byte)unused3.setBoolean(field_6_docinfo1, value); - - } /** @@ -1899,7 +1829,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isUnused3() { return unused3.isSet(field_6_docinfo1); - } /** @@ -1909,8 +1838,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFDfltTrueType(boolean value) { field_6_docinfo1 = (byte)fDfltTrueType.setBoolean(field_6_docinfo1, value); - - } /** @@ -1920,7 +1847,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFDfltTrueType() { return fDfltTrueType.isSet(field_6_docinfo1); - } /** @@ -1930,8 +1856,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFPagSupressTopSpacing(boolean value) { field_7_docinfo2 = (byte)fPagSupressTopSpacing.setBoolean(field_7_docinfo2, value); - - } /** @@ -1941,7 +1865,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFPagSupressTopSpacing() { return fPagSupressTopSpacing.isSet(field_7_docinfo2); - } /** @@ -1951,8 +1874,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFProtEnabled(boolean value) { field_7_docinfo2 = (byte)fProtEnabled.setBoolean(field_7_docinfo2, value); - - } /** @@ -1962,7 +1883,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFProtEnabled() { return fProtEnabled.isSet(field_7_docinfo2); - } /** @@ -1972,8 +1892,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFDispFormFldSel(boolean value) { field_7_docinfo2 = (byte)fDispFormFldSel.setBoolean(field_7_docinfo2, value); - - } /** @@ -1983,7 +1901,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFDispFormFldSel() { return fDispFormFldSel.isSet(field_7_docinfo2); - } /** @@ -1993,8 +1910,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFRMView(boolean value) { field_7_docinfo2 = (byte)fRMView.setBoolean(field_7_docinfo2, value); - - } /** @@ -2004,7 +1919,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFRMView() { return fRMView.isSet(field_7_docinfo2); - } /** @@ -2014,8 +1928,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFRMPrint(boolean value) { field_7_docinfo2 = (byte)fRMPrint.setBoolean(field_7_docinfo2, value); - - } /** @@ -2025,7 +1937,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFRMPrint() { return fRMPrint.isSet(field_7_docinfo2); - } /** @@ -2035,8 +1946,6 @@ public abstract class DOPAbstractType implements HDFType { public void setUnused4(boolean value) { field_7_docinfo2 = (byte)unused4.setBoolean(field_7_docinfo2, value); - - } /** @@ -2046,7 +1955,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isUnused4() { return unused4.isSet(field_7_docinfo2); - } /** @@ -2056,8 +1964,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFLockRev(boolean value) { field_7_docinfo2 = (byte)fLockRev.setBoolean(field_7_docinfo2, value); - - } /** @@ -2067,7 +1973,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFLockRev() { return fLockRev.isSet(field_7_docinfo2); - } /** @@ -2077,8 +1982,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFEmbedFonts(boolean value) { field_7_docinfo2 = (byte)fEmbedFonts.setBoolean(field_7_docinfo2, value); - - } /** @@ -2088,7 +1991,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFEmbedFonts() { return fEmbedFonts.isSet(field_7_docinfo2); - } /** @@ -2098,8 +2000,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfNoTabForInd(boolean value) { field_8_docinfo3 = (short)oldfNoTabForInd.setBoolean(field_8_docinfo3, value); - - } /** @@ -2109,7 +2009,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfNoTabForInd() { return oldfNoTabForInd.isSet(field_8_docinfo3); - } /** @@ -2119,8 +2018,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfNoSpaceRaiseLower(boolean value) { field_8_docinfo3 = (short)oldfNoSpaceRaiseLower.setBoolean(field_8_docinfo3, value); - - } /** @@ -2130,7 +2027,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfNoSpaceRaiseLower() { return oldfNoSpaceRaiseLower.isSet(field_8_docinfo3); - } /** @@ -2140,8 +2036,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfSuppressSpbfAfterPageBreak(boolean value) { field_8_docinfo3 = (short)oldfSuppressSpbfAfterPageBreak.setBoolean(field_8_docinfo3, value); - - } /** @@ -2151,7 +2045,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfSuppressSpbfAfterPageBreak() { return oldfSuppressSpbfAfterPageBreak.isSet(field_8_docinfo3); - } /** @@ -2161,8 +2054,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfWrapTrailSpaces(boolean value) { field_8_docinfo3 = (short)oldfWrapTrailSpaces.setBoolean(field_8_docinfo3, value); - - } /** @@ -2172,7 +2063,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfWrapTrailSpaces() { return oldfWrapTrailSpaces.isSet(field_8_docinfo3); - } /** @@ -2182,8 +2072,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfMapPrintTextColor(boolean value) { field_8_docinfo3 = (short)oldfMapPrintTextColor.setBoolean(field_8_docinfo3, value); - - } /** @@ -2193,7 +2081,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfMapPrintTextColor() { return oldfMapPrintTextColor.isSet(field_8_docinfo3); - } /** @@ -2203,8 +2090,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfNoColumnBalance(boolean value) { field_8_docinfo3 = (short)oldfNoColumnBalance.setBoolean(field_8_docinfo3, value); - - } /** @@ -2214,7 +2099,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfNoColumnBalance() { return oldfNoColumnBalance.isSet(field_8_docinfo3); - } /** @@ -2224,8 +2108,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfConvMailMergeEsc(boolean value) { field_8_docinfo3 = (short)oldfConvMailMergeEsc.setBoolean(field_8_docinfo3, value); - - } /** @@ -2235,7 +2117,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfConvMailMergeEsc() { return oldfConvMailMergeEsc.isSet(field_8_docinfo3); - } /** @@ -2245,8 +2126,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfSupressTopSpacing(boolean value) { field_8_docinfo3 = (short)oldfSupressTopSpacing.setBoolean(field_8_docinfo3, value); - - } /** @@ -2256,7 +2135,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfSupressTopSpacing() { return oldfSupressTopSpacing.isSet(field_8_docinfo3); - } /** @@ -2266,8 +2144,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfOrigWordTableRules(boolean value) { field_8_docinfo3 = (short)oldfOrigWordTableRules.setBoolean(field_8_docinfo3, value); - - } /** @@ -2277,7 +2153,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfOrigWordTableRules() { return oldfOrigWordTableRules.isSet(field_8_docinfo3); - } /** @@ -2287,8 +2162,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfTransparentMetafiles(boolean value) { field_8_docinfo3 = (short)oldfTransparentMetafiles.setBoolean(field_8_docinfo3, value); - - } /** @@ -2298,7 +2171,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfTransparentMetafiles() { return oldfTransparentMetafiles.isSet(field_8_docinfo3); - } /** @@ -2308,8 +2180,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfShowBreaksInFrames(boolean value) { field_8_docinfo3 = (short)oldfShowBreaksInFrames.setBoolean(field_8_docinfo3, value); - - } /** @@ -2319,7 +2189,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfShowBreaksInFrames() { return oldfShowBreaksInFrames.isSet(field_8_docinfo3); - } /** @@ -2329,8 +2198,6 @@ public abstract class DOPAbstractType implements HDFType { public void setOldfSwapBordersFacingPgs(boolean value) { field_8_docinfo3 = (short)oldfSwapBordersFacingPgs.setBoolean(field_8_docinfo3, value); - - } /** @@ -2340,7 +2207,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isOldfSwapBordersFacingPgs() { return oldfSwapBordersFacingPgs.isSet(field_8_docinfo3); - } /** @@ -2350,8 +2216,6 @@ public abstract class DOPAbstractType implements HDFType { public void setUnused5(byte value) { field_8_docinfo3 = (short)unused5.setValue(field_8_docinfo3, value); - - } /** @@ -2361,7 +2225,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getUnused5() { return ( byte )unused5.getValue(field_8_docinfo3); - } /** @@ -2371,8 +2234,6 @@ public abstract class DOPAbstractType implements HDFType { public void setRncEdn(byte value) { field_23_Edn = (short)rncEdn.setValue(field_23_Edn, value); - - } /** @@ -2382,7 +2243,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getRncEdn() { return ( byte )rncEdn.getValue(field_23_Edn); - } /** @@ -2392,8 +2252,6 @@ public abstract class DOPAbstractType implements HDFType { public void setNEdn(short value) { field_23_Edn = (short)nEdn.setValue(field_23_Edn, value); - - } /** @@ -2403,7 +2261,6 @@ public abstract class DOPAbstractType implements HDFType { public short getNEdn() { return ( short )nEdn.getValue(field_23_Edn); - } /** @@ -2413,8 +2270,6 @@ public abstract class DOPAbstractType implements HDFType { public void setEpc(byte value) { field_24_Edn1 = (short)epc.setValue(field_24_Edn1, value); - - } /** @@ -2424,7 +2279,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getEpc() { return ( byte )epc.getValue(field_24_Edn1); - } /** @@ -2434,8 +2288,6 @@ public abstract class DOPAbstractType implements HDFType { public void setNfcFtnRef1(byte value) { field_24_Edn1 = (short)nfcFtnRef1.setValue(field_24_Edn1, value); - - } /** @@ -2445,7 +2297,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getNfcFtnRef1() { return ( byte )nfcFtnRef1.getValue(field_24_Edn1); - } /** @@ -2455,8 +2306,6 @@ public abstract class DOPAbstractType implements HDFType { public void setNfcEdnRef1(byte value) { field_24_Edn1 = (short)nfcEdnRef1.setValue(field_24_Edn1, value); - - } /** @@ -2466,7 +2315,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getNfcEdnRef1() { return ( byte )nfcEdnRef1.getValue(field_24_Edn1); - } /** @@ -2476,8 +2324,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFPrintFormData(boolean value) { field_24_Edn1 = (short)fPrintFormData.setBoolean(field_24_Edn1, value); - - } /** @@ -2487,7 +2333,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFPrintFormData() { return fPrintFormData.isSet(field_24_Edn1); - } /** @@ -2497,8 +2342,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFSaveFormData(boolean value) { field_24_Edn1 = (short)fSaveFormData.setBoolean(field_24_Edn1, value); - - } /** @@ -2508,7 +2351,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSaveFormData() { return fSaveFormData.isSet(field_24_Edn1); - } /** @@ -2518,8 +2360,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFShadeFormData(boolean value) { field_24_Edn1 = (short)fShadeFormData.setBoolean(field_24_Edn1, value); - - } /** @@ -2529,7 +2369,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFShadeFormData() { return fShadeFormData.isSet(field_24_Edn1); - } /** @@ -2539,8 +2378,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFWCFtnEdn(boolean value) { field_24_Edn1 = (short)fWCFtnEdn.setBoolean(field_24_Edn1, value); - - } /** @@ -2550,7 +2387,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFWCFtnEdn() { return fWCFtnEdn.isSet(field_24_Edn1); - } /** @@ -2560,8 +2396,6 @@ public abstract class DOPAbstractType implements HDFType { public void setWvkSaved(byte value) { field_32_view = (short)wvkSaved.setValue(field_32_view, value); - - } /** @@ -2571,7 +2405,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getWvkSaved() { return ( byte )wvkSaved.getValue(field_32_view); - } /** @@ -2581,8 +2414,6 @@ public abstract class DOPAbstractType implements HDFType { public void setWScaleSaved(short value) { field_32_view = (short)wScaleSaved.setValue(field_32_view, value); - - } /** @@ -2592,7 +2423,6 @@ public abstract class DOPAbstractType implements HDFType { public short getWScaleSaved() { return ( short )wScaleSaved.getValue(field_32_view); - } /** @@ -2602,8 +2432,6 @@ public abstract class DOPAbstractType implements HDFType { public void setZkSaved(byte value) { field_32_view = (short)zkSaved.setValue(field_32_view, value); - - } /** @@ -2613,7 +2441,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getZkSaved() { return ( byte )zkSaved.getValue(field_32_view); - } /** @@ -2623,8 +2450,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFRotateFontW6(boolean value) { field_32_view = (short)fRotateFontW6.setBoolean(field_32_view, value); - - } /** @@ -2634,7 +2459,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFRotateFontW6() { return fRotateFontW6.isSet(field_32_view); - } /** @@ -2644,8 +2468,6 @@ public abstract class DOPAbstractType implements HDFType { public void setIGutterPos(boolean value) { field_32_view = (short)iGutterPos.setBoolean(field_32_view, value); - - } /** @@ -2655,7 +2477,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isIGutterPos() { return iGutterPos.isSet(field_32_view); - } /** @@ -2664,9 +2485,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFNoTabForInd(boolean value) { - field_33_docinfo4 = (int)fNoTabForInd.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fNoTabForInd.setBoolean(field_33_docinfo4, value); } /** @@ -2676,7 +2495,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFNoTabForInd() { return fNoTabForInd.isSet(field_33_docinfo4); - } /** @@ -2685,9 +2503,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFNoSpaceRaiseLower(boolean value) { - field_33_docinfo4 = (int)fNoSpaceRaiseLower.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fNoSpaceRaiseLower.setBoolean(field_33_docinfo4, value); } /** @@ -2697,7 +2513,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFNoSpaceRaiseLower() { return fNoSpaceRaiseLower.isSet(field_33_docinfo4); - } /** @@ -2706,9 +2521,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFSupressSpdfAfterPageBreak(boolean value) { - field_33_docinfo4 = (int)fSupressSpdfAfterPageBreak.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fSupressSpdfAfterPageBreak.setBoolean(field_33_docinfo4, value); } /** @@ -2718,7 +2531,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSupressSpdfAfterPageBreak() { return fSupressSpdfAfterPageBreak.isSet(field_33_docinfo4); - } /** @@ -2727,9 +2539,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFWrapTrailSpaces(boolean value) { - field_33_docinfo4 = (int)fWrapTrailSpaces.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fWrapTrailSpaces.setBoolean(field_33_docinfo4, value); } /** @@ -2739,7 +2549,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFWrapTrailSpaces() { return fWrapTrailSpaces.isSet(field_33_docinfo4); - } /** @@ -2748,9 +2557,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFMapPrintTextColor(boolean value) { - field_33_docinfo4 = (int)fMapPrintTextColor.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fMapPrintTextColor.setBoolean(field_33_docinfo4, value); } /** @@ -2760,7 +2567,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFMapPrintTextColor() { return fMapPrintTextColor.isSet(field_33_docinfo4); - } /** @@ -2769,9 +2575,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFNoColumnBalance(boolean value) { - field_33_docinfo4 = (int)fNoColumnBalance.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fNoColumnBalance.setBoolean(field_33_docinfo4, value); } /** @@ -2781,7 +2585,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFNoColumnBalance() { return fNoColumnBalance.isSet(field_33_docinfo4); - } /** @@ -2790,9 +2593,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFConvMailMergeEsc(boolean value) { - field_33_docinfo4 = (int)fConvMailMergeEsc.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fConvMailMergeEsc.setBoolean(field_33_docinfo4, value); } /** @@ -2802,7 +2603,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFConvMailMergeEsc() { return fConvMailMergeEsc.isSet(field_33_docinfo4); - } /** @@ -2811,9 +2611,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFSupressTopSpacing(boolean value) { - field_33_docinfo4 = (int)fSupressTopSpacing.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fSupressTopSpacing.setBoolean(field_33_docinfo4, value); } /** @@ -2823,7 +2621,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSupressTopSpacing() { return fSupressTopSpacing.isSet(field_33_docinfo4); - } /** @@ -2832,9 +2629,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFOrigWordTableRules(boolean value) { - field_33_docinfo4 = (int)fOrigWordTableRules.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fOrigWordTableRules.setBoolean(field_33_docinfo4, value); } /** @@ -2844,7 +2639,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFOrigWordTableRules() { return fOrigWordTableRules.isSet(field_33_docinfo4); - } /** @@ -2853,9 +2647,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFTransparentMetafiles(boolean value) { - field_33_docinfo4 = (int)fTransparentMetafiles.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fTransparentMetafiles.setBoolean(field_33_docinfo4, value); } /** @@ -2865,7 +2657,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFTransparentMetafiles() { return fTransparentMetafiles.isSet(field_33_docinfo4); - } /** @@ -2874,9 +2665,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFShowBreaksInFrames(boolean value) { - field_33_docinfo4 = (int)fShowBreaksInFrames.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fShowBreaksInFrames.setBoolean(field_33_docinfo4, value); } /** @@ -2886,7 +2675,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFShowBreaksInFrames() { return fShowBreaksInFrames.isSet(field_33_docinfo4); - } /** @@ -2895,9 +2683,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFSwapBordersFacingPgs(boolean value) { - field_33_docinfo4 = (int)fSwapBordersFacingPgs.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fSwapBordersFacingPgs.setBoolean(field_33_docinfo4, value); } /** @@ -2907,7 +2693,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSwapBordersFacingPgs() { return fSwapBordersFacingPgs.isSet(field_33_docinfo4); - } /** @@ -2916,9 +2701,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFSuppressTopSPacingMac5(boolean value) { - field_33_docinfo4 = (int)fSuppressTopSPacingMac5.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fSuppressTopSPacingMac5.setBoolean(field_33_docinfo4, value); } /** @@ -2928,7 +2711,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSuppressTopSPacingMac5() { return fSuppressTopSPacingMac5.isSet(field_33_docinfo4); - } /** @@ -2937,9 +2719,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFTruncDxaExpand(boolean value) { - field_33_docinfo4 = (int)fTruncDxaExpand.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fTruncDxaExpand.setBoolean(field_33_docinfo4, value); } /** @@ -2949,7 +2729,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFTruncDxaExpand() { return fTruncDxaExpand.isSet(field_33_docinfo4); - } /** @@ -2958,9 +2737,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFPrintBodyBeforeHdr(boolean value) { - field_33_docinfo4 = (int)fPrintBodyBeforeHdr.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fPrintBodyBeforeHdr.setBoolean(field_33_docinfo4, value); } /** @@ -2970,7 +2747,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFPrintBodyBeforeHdr() { return fPrintBodyBeforeHdr.isSet(field_33_docinfo4); - } /** @@ -2979,9 +2755,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFNoLeading(boolean value) { - field_33_docinfo4 = (int)fNoLeading.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fNoLeading.setBoolean(field_33_docinfo4, value); } /** @@ -2991,7 +2765,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFNoLeading() { return fNoLeading.isSet(field_33_docinfo4); - } /** @@ -3000,9 +2773,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFMWSmallCaps(boolean value) { - field_33_docinfo4 = (int)fMWSmallCaps.setBoolean(field_33_docinfo4, value); - - + field_33_docinfo4 = fMWSmallCaps.setBoolean(field_33_docinfo4, value); } /** @@ -3012,7 +2783,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFMWSmallCaps() { return fMWSmallCaps.isSet(field_33_docinfo4); - } /** @@ -3022,8 +2792,6 @@ public abstract class DOPAbstractType implements HDFType { public void setLvl(byte value) { field_37_docinfo5 = (short)lvl.setValue(field_37_docinfo5, value); - - } /** @@ -3033,7 +2801,6 @@ public abstract class DOPAbstractType implements HDFType { public byte getLvl() { return ( byte )lvl.getValue(field_37_docinfo5); - } /** @@ -3043,8 +2810,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFGramAllDone(boolean value) { field_37_docinfo5 = (short)fGramAllDone.setBoolean(field_37_docinfo5, value); - - } /** @@ -3054,7 +2819,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFGramAllDone() { return fGramAllDone.isSet(field_37_docinfo5); - } /** @@ -3064,8 +2828,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFGramAllClean(boolean value) { field_37_docinfo5 = (short)fGramAllClean.setBoolean(field_37_docinfo5, value); - - } /** @@ -3075,7 +2837,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFGramAllClean() { return fGramAllClean.isSet(field_37_docinfo5); - } /** @@ -3085,8 +2846,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFSubsetFonts(boolean value) { field_37_docinfo5 = (short)fSubsetFonts.setBoolean(field_37_docinfo5, value); - - } /** @@ -3096,7 +2855,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSubsetFonts() { return fSubsetFonts.isSet(field_37_docinfo5); - } /** @@ -3106,8 +2864,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFHideLastVersion(boolean value) { field_37_docinfo5 = (short)fHideLastVersion.setBoolean(field_37_docinfo5, value); - - } /** @@ -3117,7 +2873,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFHideLastVersion() { return fHideLastVersion.isSet(field_37_docinfo5); - } /** @@ -3127,8 +2882,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFHtmlDoc(boolean value) { field_37_docinfo5 = (short)fHtmlDoc.setBoolean(field_37_docinfo5, value); - - } /** @@ -3138,7 +2891,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFHtmlDoc() { return fHtmlDoc.isSet(field_37_docinfo5); - } /** @@ -3148,8 +2900,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFSnapBorder(boolean value) { field_37_docinfo5 = (short)fSnapBorder.setBoolean(field_37_docinfo5, value); - - } /** @@ -3159,7 +2909,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFSnapBorder() { return fSnapBorder.isSet(field_37_docinfo5); - } /** @@ -3169,8 +2918,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFIncludeHeader(boolean value) { field_37_docinfo5 = (short)fIncludeHeader.setBoolean(field_37_docinfo5, value); - - } /** @@ -3180,7 +2927,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFIncludeHeader() { return fIncludeHeader.isSet(field_37_docinfo5); - } /** @@ -3190,8 +2936,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFIncludeFooter(boolean value) { field_37_docinfo5 = (short)fIncludeFooter.setBoolean(field_37_docinfo5, value); - - } /** @@ -3201,7 +2945,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFIncludeFooter() { return fIncludeFooter.isSet(field_37_docinfo5); - } /** @@ -3211,8 +2954,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFForcePageSizePag(boolean value) { field_37_docinfo5 = (short)fForcePageSizePag.setBoolean(field_37_docinfo5, value); - - } /** @@ -3222,7 +2963,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFForcePageSizePag() { return fForcePageSizePag.isSet(field_37_docinfo5); - } /** @@ -3232,8 +2972,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFMinFontSizePag(boolean value) { field_37_docinfo5 = (short)fMinFontSizePag.setBoolean(field_37_docinfo5, value); - - } /** @@ -3243,7 +2981,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFMinFontSizePag() { return fMinFontSizePag.isSet(field_37_docinfo5); - } /** @@ -3253,8 +2990,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFHaveVersions(boolean value) { field_38_docinfo6 = (short)fHaveVersions.setBoolean(field_38_docinfo6, value); - - } /** @@ -3264,7 +2999,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFHaveVersions() { return fHaveVersions.isSet(field_38_docinfo6); - } /** @@ -3274,8 +3008,6 @@ public abstract class DOPAbstractType implements HDFType { public void setFAutoVersions(boolean value) { field_38_docinfo6 = (short)fAutoVersions.setBoolean(field_38_docinfo6, value); - - } /** @@ -3285,7 +3017,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFAutoVersions() { return fAutoVersions.isSet(field_38_docinfo6); - } /** @@ -3294,9 +3025,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFVirusPrompted(boolean value) { - field_43_virusinfo = (int)fVirusPrompted.setBoolean(field_43_virusinfo, value); - - + field_43_virusinfo = fVirusPrompted.setBoolean(field_43_virusinfo, value); } /** @@ -3306,7 +3035,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFVirusPrompted() { return fVirusPrompted.isSet(field_43_virusinfo); - } /** @@ -3315,9 +3043,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setFVirusLoadSafe(boolean value) { - field_43_virusinfo = (int)fVirusLoadSafe.setBoolean(field_43_virusinfo, value); - - + field_43_virusinfo = fVirusLoadSafe.setBoolean(field_43_virusinfo, value); } /** @@ -3327,7 +3053,6 @@ public abstract class DOPAbstractType implements HDFType { public boolean isFVirusLoadSafe() { return fVirusLoadSafe.isSet(field_43_virusinfo); - } /** @@ -3336,9 +3061,7 @@ public abstract class DOPAbstractType implements HDFType { */ public void setKeyVirusSession30(int value) { - field_43_virusinfo = (int)KeyVirusSession30.setValue(field_43_virusinfo, value); - - + field_43_virusinfo = KeyVirusSession30.setValue(field_43_virusinfo, value); } /** @@ -3347,13 +3070,6 @@ public abstract class DOPAbstractType implements HDFType { */ public int getKeyVirusSession30() { - return ( int )KeyVirusSession30.getValue(field_43_virusinfo); - + return KeyVirusSession30.getValue(field_43_virusinfo); } - - -} // END OF CLASS - - - - +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java index eebde48268..32c308e38d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FIBAbstractType.java @@ -88,26 +88,24 @@ public abstract class FIBAbstractType implements HDFType { field_12_chsTables = LittleEndian.getShort(data, 0x16 + offset); field_13_fcMin = LittleEndian.getInt(data, 0x18 + offset); field_14_fcMac = LittleEndian.getInt(data, 0x1c + offset); - } public void serialize(byte[] data, int offset) { - LittleEndian.putShort(data, 0x0 + offset, (short)field_1_wIdent);; - LittleEndian.putShort(data, 0x2 + offset, (short)field_2_nFib);; - LittleEndian.putShort(data, 0x4 + offset, (short)field_3_nProduct);; - LittleEndian.putShort(data, 0x6 + offset, (short)field_4_lid);; - LittleEndian.putShort(data, 0x8 + offset, (short)field_5_pnNext);; - LittleEndian.putShort(data, 0xa + offset, (short)field_6_options);; - LittleEndian.putShort(data, 0xc + offset, (short)field_7_nFibBack);; - LittleEndian.putShort(data, 0xe + offset, (short)field_8_lKey);; - LittleEndian.putShort(data, 0x10 + offset, (short)field_9_envr);; - LittleEndian.putShort(data, 0x12 + offset, (short)field_10_history);; - LittleEndian.putShort(data, 0x14 + offset, (short)field_11_chs);; - LittleEndian.putShort(data, 0x16 + offset, (short)field_12_chsTables);; - LittleEndian.putInt(data, 0x18 + offset, field_13_fcMin);; - LittleEndian.putInt(data, 0x1c + offset, field_14_fcMac);; - + LittleEndian.putShort(data, 0x0 + offset, (short)field_1_wIdent); + LittleEndian.putShort(data, 0x2 + offset, (short)field_2_nFib); + LittleEndian.putShort(data, 0x4 + offset, (short)field_3_nProduct); + LittleEndian.putShort(data, 0x6 + offset, (short)field_4_lid); + LittleEndian.putShort(data, 0x8 + offset, (short)field_5_pnNext); + LittleEndian.putShort(data, 0xa + offset, field_6_options); + LittleEndian.putShort(data, 0xc + offset, (short)field_7_nFibBack); + LittleEndian.putShort(data, 0xe + offset, (short)field_8_lKey); + LittleEndian.putShort(data, 0x10 + offset, (short)field_9_envr); + LittleEndian.putShort(data, 0x12 + offset, field_10_history); + LittleEndian.putShort(data, 0x14 + offset, (short)field_11_chs); + LittleEndian.putShort(data, 0x16 + offset, (short)field_12_chsTables); + LittleEndian.putInt(data, 0x18 + offset, field_13_fcMin); + LittleEndian.putInt(data, 0x1c + offset, field_14_fcMac); } public String toString() @@ -422,8 +420,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFDot(boolean value) { field_6_options = (short)fDot.setBoolean(field_6_options, value); - - } /** @@ -433,7 +429,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFDot() { return fDot.isSet(field_6_options); - } /** @@ -443,8 +438,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFGlsy(boolean value) { field_6_options = (short)fGlsy.setBoolean(field_6_options, value); - - } /** @@ -454,7 +447,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFGlsy() { return fGlsy.isSet(field_6_options); - } /** @@ -464,8 +456,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFComplex(boolean value) { field_6_options = (short)fComplex.setBoolean(field_6_options, value); - - } /** @@ -475,7 +465,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFComplex() { return fComplex.isSet(field_6_options); - } /** @@ -485,8 +474,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFHasPic(boolean value) { field_6_options = (short)fHasPic.setBoolean(field_6_options, value); - - } /** @@ -496,7 +483,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFHasPic() { return fHasPic.isSet(field_6_options); - } /** @@ -506,8 +492,6 @@ public abstract class FIBAbstractType implements HDFType { public void setCQuickSaves(byte value) { field_6_options = (short)cQuickSaves.setValue(field_6_options, value); - - } /** @@ -517,7 +501,6 @@ public abstract class FIBAbstractType implements HDFType { public byte getCQuickSaves() { return ( byte )cQuickSaves.getValue(field_6_options); - } /** @@ -527,8 +510,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFEncrypted(boolean value) { field_6_options = (short)fEncrypted.setBoolean(field_6_options, value); - - } /** @@ -538,7 +519,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFEncrypted() { return fEncrypted.isSet(field_6_options); - } /** @@ -548,8 +528,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFWhichTblStm(boolean value) { field_6_options = (short)fWhichTblStm.setBoolean(field_6_options, value); - - } /** @@ -559,7 +537,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFWhichTblStm() { return fWhichTblStm.isSet(field_6_options); - } /** @@ -569,8 +546,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFReadOnlyRecommended(boolean value) { field_6_options = (short)fReadOnlyRecommended.setBoolean(field_6_options, value); - - } /** @@ -580,7 +555,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFReadOnlyRecommended() { return fReadOnlyRecommended.isSet(field_6_options); - } /** @@ -590,8 +564,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFWriteReservation(boolean value) { field_6_options = (short)fWriteReservation.setBoolean(field_6_options, value); - - } /** @@ -601,7 +573,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFWriteReservation() { return fWriteReservation.isSet(field_6_options); - } /** @@ -611,8 +582,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFExtChar(boolean value) { field_6_options = (short)fExtChar.setBoolean(field_6_options, value); - - } /** @@ -622,7 +591,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFExtChar() { return fExtChar.isSet(field_6_options); - } /** @@ -632,8 +600,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFLoadOverride(boolean value) { field_6_options = (short)fLoadOverride.setBoolean(field_6_options, value); - - } /** @@ -643,7 +609,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFLoadOverride() { return fLoadOverride.isSet(field_6_options); - } /** @@ -653,8 +618,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFFarEast(boolean value) { field_6_options = (short)fFarEast.setBoolean(field_6_options, value); - - } /** @@ -664,7 +627,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFFarEast() { return fFarEast.isSet(field_6_options); - } /** @@ -674,8 +636,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFCrypto(boolean value) { field_6_options = (short)fCrypto.setBoolean(field_6_options, value); - - } /** @@ -685,7 +645,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFCrypto() { return fCrypto.isSet(field_6_options); - } /** @@ -695,8 +654,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFMac(boolean value) { field_10_history = (short)fMac.setBoolean(field_10_history, value); - - } /** @@ -706,7 +663,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFMac() { return fMac.isSet(field_10_history); - } /** @@ -716,8 +672,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFEmptySpecial(boolean value) { field_10_history = (short)fEmptySpecial.setBoolean(field_10_history, value); - - } /** @@ -727,7 +681,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFEmptySpecial() { return fEmptySpecial.isSet(field_10_history); - } /** @@ -737,8 +690,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFLoadOverridePage(boolean value) { field_10_history = (short)fLoadOverridePage.setBoolean(field_10_history, value); - - } /** @@ -748,7 +699,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFLoadOverridePage() { return fLoadOverridePage.isSet(field_10_history); - } /** @@ -758,8 +708,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFFutureSavedUndo(boolean value) { field_10_history = (short)fFutureSavedUndo.setBoolean(field_10_history, value); - - } /** @@ -769,7 +717,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFFutureSavedUndo() { return fFutureSavedUndo.isSet(field_10_history); - } /** @@ -779,8 +726,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFWord97Saved(boolean value) { field_10_history = (short)fWord97Saved.setBoolean(field_10_history, value); - - } /** @@ -790,7 +735,6 @@ public abstract class FIBAbstractType implements HDFType { public boolean isFWord97Saved() { return fWord97Saved.isSet(field_10_history); - } /** @@ -800,8 +744,6 @@ public abstract class FIBAbstractType implements HDFType { public void setFSpare0(byte value) { field_10_history = (short)fSpare0.setValue(field_10_history, value); - - } /** @@ -811,12 +753,5 @@ public abstract class FIBAbstractType implements HDFType { public byte getFSpare0() { return ( byte )fSpare0.getValue(field_10_history); - } - - -} // END OF CLASS - - - - +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java index d5a993566b..68b4a108c3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TCAbstractType.java @@ -67,13 +67,12 @@ public abstract class TCAbstractType implements HDFType { public void serialize(byte[] data, int offset) { - LittleEndian.putShort(data, 0x0 + offset, (short)field_1_rgf);; - LittleEndian.putShort(data, 0x2 + offset, (short)field_2_unused);; - field_3_brcTop.serialize(data, 0x4 + offset);; - field_4_brcLeft.serialize(data, 0x8 + offset);; - field_5_brcBottom.serialize(data, 0xc + offset);; - field_6_brcRight.serialize(data, 0x10 + offset);; - + LittleEndian.putShort(data, 0x0 + offset, field_1_rgf); + LittleEndian.putShort(data, 0x2 + offset, field_2_unused); + field_3_brcTop.serialize(data, 0x4 + offset); + field_4_brcLeft.serialize(data, 0x8 + offset); + field_5_brcBottom.serialize(data, 0xc + offset); + field_6_brcRight.serialize(data, 0x10 + offset); } public String toString() @@ -225,8 +224,6 @@ public abstract class TCAbstractType implements HDFType { public void setFFirstMerged(boolean value) { field_1_rgf = (short)fFirstMerged.setBoolean(field_1_rgf, value); - - } /** @@ -236,7 +233,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFFirstMerged() { return fFirstMerged.isSet(field_1_rgf); - } /** @@ -246,8 +242,6 @@ public abstract class TCAbstractType implements HDFType { public void setFMerged(boolean value) { field_1_rgf = (short)fMerged.setBoolean(field_1_rgf, value); - - } /** @@ -257,7 +251,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFMerged() { return fMerged.isSet(field_1_rgf); - } /** @@ -267,8 +260,6 @@ public abstract class TCAbstractType implements HDFType { public void setFVertical(boolean value) { field_1_rgf = (short)fVertical.setBoolean(field_1_rgf, value); - - } /** @@ -278,7 +269,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFVertical() { return fVertical.isSet(field_1_rgf); - } /** @@ -288,8 +278,6 @@ public abstract class TCAbstractType implements HDFType { public void setFBackward(boolean value) { field_1_rgf = (short)fBackward.setBoolean(field_1_rgf, value); - - } /** @@ -299,7 +287,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFBackward() { return fBackward.isSet(field_1_rgf); - } /** @@ -309,8 +296,6 @@ public abstract class TCAbstractType implements HDFType { public void setFRotateFont(boolean value) { field_1_rgf = (short)fRotateFont.setBoolean(field_1_rgf, value); - - } /** @@ -320,7 +305,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFRotateFont() { return fRotateFont.isSet(field_1_rgf); - } /** @@ -330,8 +314,6 @@ public abstract class TCAbstractType implements HDFType { public void setFVertMerge(boolean value) { field_1_rgf = (short)fVertMerge.setBoolean(field_1_rgf, value); - - } /** @@ -341,7 +323,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFVertMerge() { return fVertMerge.isSet(field_1_rgf); - } /** @@ -351,8 +332,6 @@ public abstract class TCAbstractType implements HDFType { public void setFVertRestart(boolean value) { field_1_rgf = (short)fVertRestart.setBoolean(field_1_rgf, value); - - } /** @@ -362,7 +341,6 @@ public abstract class TCAbstractType implements HDFType { public boolean isFVertRestart() { return fVertRestart.isSet(field_1_rgf); - } /** @@ -372,8 +350,6 @@ public abstract class TCAbstractType implements HDFType { public void setVertAlign(byte value) { field_1_rgf = (short)vertAlign.setValue(field_1_rgf, value); - - } /** @@ -383,12 +359,5 @@ public abstract class TCAbstractType implements HDFType { public byte getVertAlign() { return ( byte )vertAlign.getValue(field_1_rgf); - } - - -} // END OF CLASS - - - - +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java index 7dabf810f9..20c62ac282 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -46,7 +46,7 @@ public final class CharacterSprmUncompressor while (sprmIt.hasNext()) { - SprmOperation sprm = (SprmOperation)sprmIt.next(); + SprmOperation sprm = sprmIt.next(); unCompressCHPOperation(parent, newProperties, sprm); } @@ -108,8 +108,8 @@ public final class CharacterSprmUncompressor break; case 0x9: newCHP.setFSpec (true); - newCHP.setFtcSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset())); - newCHP.setXchSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2)); + newCHP.setFtcSym (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset())); + newCHP.setXchSym (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2)); break; case 0xa: newCHP.setFOle2 (getFlag (sprm.getOperand())); @@ -426,8 +426,8 @@ public final class CharacterSprmUncompressor // styleSheet, opSize); break; case 0x4d: - float percentage = (float) sprm.getOperand() / 100.0f; - int add = (int) ((float) percentage * (float) newCHP.getHps ()); + float percentage = sprm.getOperand() / 100.0f; + int add = (int) (percentage * newCHP.getHps ()); newCHP.setHps (newCHP.getHps () + add); break; case 0x4e: @@ -462,7 +462,7 @@ public final class CharacterSprmUncompressor byte[] buf = sprm.getGrpprl(); int offset = sprm.getGrpprlOffset(); 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)); break; case 0x58: @@ -494,7 +494,7 @@ public final class CharacterSprmUncompressor buf = sprm.getGrpprl(); offset = sprm.getGrpprlOffset(); 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)); System.arraycopy (buf, offset + 7, xstDispFldRMark, 0, 32); newCHP.setXstDispFldRMark (xstDispFldRMark); @@ -553,14 +553,7 @@ public final class CharacterSprmUncompressor */ public static boolean getFlag (int x) { - if (x != 0) - { - return true; - } - else - { - return false; - } + return x != 0; } private static boolean getCHPFlag (byte x, boolean oldVal) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index e8de893a2e..fc0fdf813e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -54,7 +54,7 @@ public final class ParagraphSprmUncompressor 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 // table row @@ -326,8 +326,8 @@ public final class ParagraphSprmUncompressor { byte[] varParam = sprm.getGrpprl(); int offset = sprm.getGrpprlOffset(); - newPAP.setFPropRMark ((int) varParam[offset]); - newPAP.setIbstPropRMark ((int) LittleEndian.getShort (varParam, offset + 1)); + newPAP.setFPropRMark (varParam[offset]); + newPAP.setIbstPropRMark (LittleEndian.getShort (varParam, offset + 1)); newPAP.setDttmPropRMark (new DateAndTime(varParam, offset + 3)); } catch (Exception e) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java index 802b9fcbc2..2fc2a92fe9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java @@ -33,7 +33,7 @@ public final class SectionSprmUncompressor extends SprmUncompressor while (sprmIt.hasNext()) { - SprmOperation sprm = (SprmOperation)sprmIt.next(); + SprmOperation sprm = sprmIt.next(); unCompressSEPOperation(newProperties, sprm); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java index 56de089e99..85ea447973 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java @@ -39,7 +39,7 @@ public final class TableSprmUncompressor 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 //uncompress the right type of sprm. diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java index 540b30000a..8f3e4f1937 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java @@ -380,13 +380,11 @@ public final class CharacterProperties cp.field_23_dttmRMarkDel = (DateAndTime)field_23_dttmRMarkDel.clone(); cp.field_36_dttmPropRMark = (DateAndTime)field_36_dttmPropRMark.clone(); cp.field_40_dttmDispFldRMark = (DateAndTime)field_40_dttmDispFldRMark.clone(); - cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone(); + cp.field_41_xstDispFldRMark = field_41_xstDispFldRMark.clone(); cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone(); cp._ico24 = _ico24; return cp; } - - } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java index 9a779643a6..15d61776eb 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -546,7 +546,7 @@ public final class CharacterRun cp._props.setDttmPropRMark((DateAndTime)_props.getDttmPropRMark().clone()); cp._props.setDttmDispFldRMark((DateAndTime)_props.getDttmDispFldRMark(). clone()); - cp._props.setXstDispFldRMark((byte[])_props.getXstDispFldRMark().clone()); + cp._props.setXstDispFldRMark(_props.getXstDispFldRMark().clone()); cp._props.setShd((ShadingDescriptor)_props.getShd().clone()); return cp; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java index a9a95c6b4f..8a4c3fa007 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java @@ -55,7 +55,7 @@ public final class HWPFList { */ 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()); _styleSheet = styleSheet; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index a6fe3fdf4a..ff6f2162e2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -17,7 +17,6 @@ package org.apache.poi.hwpf.usermodel; - import org.apache.poi.util.LittleEndian; import org.apache.poi.hwpf.HWPFDocument; @@ -46,8 +45,8 @@ import java.util.NoSuchElementException; import java.lang.ref.WeakReference; /** - * This class is the central class of the HWPF object model. All properties - * that apply to a range of characters in a Word document extend this class. + * This class is the central class of the HWPF object model. All properties that + * apply to a range of characters in a Word document extend this class. * * It is possible to insert text and/or properties at the beginning or end of a * range. @@ -60,703 +59,712 @@ import java.lang.ref.WeakReference; */ public class Range { // TODO -instantiable superclass - public static final int TYPE_PARAGRAPH = 0; - public static final int TYPE_CHARACTER= 1; - public static final int TYPE_SECTION = 2; - public static final int TYPE_TEXT = 3; - public static final int TYPE_LISTENTRY = 4; - public static final int TYPE_TABLE = 5; - public static final int TYPE_UNDEFINED = 6; - - /** Needed so inserts and deletes will ripple up through containing Ranges */ - private WeakReference _parent; - - /** The starting character offset of this range.*/ - protected int _start; - - /** The ending character offset of this range.*/ - protected int _end; - - /** The document this range blongs to.*/ - protected HWPFDocument _doc; - - /** Have we loaded the section indexes yet*/ - boolean _sectionRangeFound; - - /** All sections that belong to the document this Range belongs to.*/ - protected List _sections; - - /** The start index in the sections list for this Range*/ - protected int _sectionStart; - - /** The end index in the sections list for this Range.*/ - protected int _sectionEnd; - - /** Have we loaded the paragraph indexes yet.*/ - protected boolean _parRangeFound; - - /** All paragraphs that belong to the document this Range belongs to.*/ - protected List _paragraphs; - - /** The start index in the paragraphs list for this Range*/ - protected int _parStart; - - /** The end index in the paragraphs list for this Range.*/ - protected int _parEnd; - - /** Have we loaded the characterRun indexes yet.*/ - protected boolean _charRangeFound; - - /** All CharacterRuns that belong to the document this Range belongs to.*/ - protected List _characters; - - /** The start index in the characterRuns list for this Range*/ - protected int _charStart; - - /** The end index in the characterRuns list for this Range. */ - protected int _charEnd; - - /** Have we loaded the Text indexes yet*/ - protected boolean _textRangeFound; - - /** All text pieces that belong to the document this Range belongs to.*/ - protected List _text; - - /** The start index in the text list for this Range.*/ - protected int _textStart; - - /** The end index in the text list for this Range.*/ - protected int _textEnd; - -// protected Range() -// { -// -// } - - /** - * Used to construct a Range from a document. This is generally used to - * create a Range that spans the whole document, or at least one - * whole part of the document (eg main text, header, comment) - * - * @param start Starting character offset of the range. - * @param end Ending character offset of the range. - * @param doc The HWPFDocument the range is based on. - */ - public Range(int start, int end, HWPFDocument doc) - { - _start = start; - _end = end; - _doc = doc; - _sections = _doc.getSectionTable().getSections(); - _paragraphs = _doc.getParagraphTable().getParagraphs(); - _characters = _doc.getCharacterTable().getTextRuns(); - _text = _doc.getTextTable().getTextPieces(); - _parent = new WeakReference(null); - - sanityCheckStartEnd(); - } - - - /** - * Used to create Ranges that are children of other Ranges. - * - * @param start Starting character offset of the range. - * @param end Ending character offset of the range. - * @param parent The parent this range belongs to. - */ - protected Range(int start, int end, Range parent) - { - _start = start; - _end = end; - _doc = parent._doc; - _sections = parent._sections; - _paragraphs = parent._paragraphs; - _characters = parent._characters; - _text = parent._text; - _parent = new WeakReference(parent); - - sanityCheckStartEnd(); - } - - /** - * Constructor used to build a Range from indexes in one of its internal - * lists. - * - * @param startIdx The starting index in the list. - * @param endIdx The ending index in the list. - * @param idxType The list type. - * @param parent The parent Range this range belongs to. - */ - protected Range(int startIdx, int endIdx, int idxType, Range parent) - { - _doc = parent._doc; - _sections = parent._sections; - _paragraphs = parent._paragraphs; - _characters = parent._characters; - _text = parent._text; - _parent = new WeakReference(parent); - - switch (idxType) - { - case TYPE_PARAGRAPH: - _parStart = parent._parStart + startIdx; - _parEnd = parent._parStart + endIdx; - _start = ((PropertyNode)_paragraphs.get(_parStart)).getStart(); - _end = ((PropertyNode)_paragraphs.get(_parEnd)).getEnd(); - _parRangeFound = true; - break; - case TYPE_CHARACTER: - _charStart = parent._charStart + startIdx; - _charEnd = parent._charStart + endIdx; - _start = ((PropertyNode)_characters.get(_charStart)).getStart(); - _end = ((PropertyNode)_characters.get(_charEnd)).getEnd(); - _charRangeFound = true; - break; - case TYPE_SECTION: - _sectionStart = parent._sectionStart + startIdx; - _sectionEnd = parent._sectionStart + endIdx; - _start = ((PropertyNode)_sections.get(_sectionStart)).getStart(); - _end = ((PropertyNode)_sections.get(_sectionEnd)).getEnd(); - _sectionRangeFound = true; - break; - case TYPE_TEXT: - _textStart = parent._textStart + startIdx; - _textEnd = parent._textStart + endIdx; - _start = ((PropertyNode)_text.get(_textStart)).getStart(); - _end = ((PropertyNode)_text.get(_textEnd)).getEnd(); - _textRangeFound = true; - break; - } - - sanityCheckStartEnd(); - } - - /** - * Ensures that the start and end were were given - * are actually valid, to avoid issues later on - * if they're not - */ - private void sanityCheckStartEnd() { - if(_start < 0) { - throw new IllegalArgumentException("Range start must not be negative. Given " + _start); - } - if(_end < _start) { - throw new IllegalArgumentException("The end (" + _end + ") must not be before the start ("+_start+")"); - } - } - - /** - * Does any TextPiece in this Range use unicode? - * - * @return true if it does and false if it doesn't - */ - public boolean usesUnicode() { - - initText(); - - for (int i = _textStart; i < _textEnd; i++) + public static final int TYPE_PARAGRAPH = 0; + public static final int TYPE_CHARACTER = 1; + public static final int TYPE_SECTION = 2; + public static final int TYPE_TEXT = 3; + public static final int TYPE_LISTENTRY = 4; + public static final int TYPE_TABLE = 5; + public static final int TYPE_UNDEFINED = 6; + + /** Needed so inserts and deletes will ripple up through containing Ranges */ + private WeakReference _parent; + + /** The starting character offset of this range. */ + protected int _start; + + /** The ending character offset of this range. */ + protected int _end; + + /** The document this range blongs to. */ + protected HWPFDocument _doc; + + /** Have we loaded the section indexes yet */ + boolean _sectionRangeFound; + + /** All sections that belong to the document this Range belongs to. */ + protected List _sections; + + /** The start index in the sections list for this Range */ + protected int _sectionStart; + + /** The end index in the sections list for this Range. */ + protected int _sectionEnd; + + /** Have we loaded the paragraph indexes yet. */ + protected boolean _parRangeFound; + + /** All paragraphs that belong to the document this Range belongs to. */ + protected List _paragraphs; + + /** The start index in the paragraphs list for this Range */ + protected int _parStart; + + /** The end index in the paragraphs list for this Range. */ + protected int _parEnd; + + /** Have we loaded the characterRun indexes yet. */ + protected boolean _charRangeFound; + + /** All CharacterRuns that belong to the document this Range belongs to. */ + protected List _characters; + + /** The start index in the characterRuns list for this Range */ + protected int _charStart; + + /** The end index in the characterRuns list for this Range. */ + protected int _charEnd; + + /** Have we loaded the Text indexes yet */ + protected boolean _textRangeFound; + + /** All text pieces that belong to the document this Range belongs to. */ + protected List _text; + + /** The start index in the text list for this Range. */ + protected int _textStart; + + /** The end index in the text list for this Range. */ + protected int _textEnd; + + // protected Range() + // { + // + // } + + /** + * Used to construct a Range from a document. This is generally used to + * create a Range that spans the whole document, or at least one whole part + * of the document (eg main text, header, comment) + * + * @param start + * Starting character offset of the range. + * @param end + * Ending character offset of the range. + * @param doc + * The HWPFDocument the range is based on. + */ + public Range(int start, int end, HWPFDocument doc) { + _start = start; + _end = end; + _doc = doc; + _sections = _doc.getSectionTable().getSections(); + _paragraphs = _doc.getParagraphTable().getParagraphs(); + _characters = _doc.getCharacterTable().getTextRuns(); + _text = _doc.getTextTable().getTextPieces(); + _parent = new WeakReference(null); + + sanityCheckStartEnd(); + } + + /** + * Used to create Ranges that are children of other Ranges. + * + * @param start + * Starting character offset of the range. + * @param end + * Ending character offset of the range. + * @param parent + * The parent this range belongs to. + */ + protected Range(int start, int end, Range parent) { + _start = start; + _end = end; + _doc = parent._doc; + _sections = parent._sections; + _paragraphs = parent._paragraphs; + _characters = parent._characters; + _text = parent._text; + _parent = new WeakReference(parent); + + sanityCheckStartEnd(); + } + + /** + * Constructor used to build a Range from indexes in one of its internal + * lists. + * + * @param startIdx + * The starting index in the list. + * @param endIdx + * The ending index in the list. + * @param idxType + * The list type. + * @param parent + * The parent Range this range belongs to. + */ + protected Range(int startIdx, int endIdx, int idxType, Range parent) { + _doc = parent._doc; + _sections = parent._sections; + _paragraphs = parent._paragraphs; + _characters = parent._characters; + _text = parent._text; + _parent = new WeakReference(parent); + + switch (idxType) { + case TYPE_PARAGRAPH: + _parStart = parent._parStart + startIdx; + _parEnd = parent._parStart + endIdx; + _start = ((PropertyNode) _paragraphs.get(_parStart)).getStart(); + _end = ((PropertyNode) _paragraphs.get(_parEnd)).getEnd(); + _parRangeFound = true; + break; + case TYPE_CHARACTER: + _charStart = parent._charStart + startIdx; + _charEnd = parent._charStart + endIdx; + _start = ((PropertyNode) _characters.get(_charStart)).getStart(); + _end = ((PropertyNode) _characters.get(_charEnd)).getEnd(); + _charRangeFound = true; + break; + case TYPE_SECTION: + _sectionStart = parent._sectionStart + startIdx; + _sectionEnd = parent._sectionStart + endIdx; + _start = ((PropertyNode) _sections.get(_sectionStart)).getStart(); + _end = ((PropertyNode) _sections.get(_sectionEnd)).getEnd(); + _sectionRangeFound = true; + break; + case TYPE_TEXT: + _textStart = parent._textStart + startIdx; + _textEnd = parent._textStart + endIdx; + _start = ((PropertyNode) _text.get(_textStart)).getStart(); + _end = ((PropertyNode) _text.get(_textEnd)).getEnd(); + _textRangeFound = true; + break; + } + + sanityCheckStartEnd(); + } + + /** + * Ensures that the start and end were were given are actually valid, to + * avoid issues later on if they're not + */ + private void sanityCheckStartEnd() { + if (_start < 0) { + throw new IllegalArgumentException("Range start must not be negative. Given " + _start); + } + if (_end < _start) { + throw new IllegalArgumentException("The end (" + _end + + ") must not be before the start (" + _start + ")"); + } + } + + /** + * Does any TextPiece in this Range use unicode? + * + * @return true if it does and false if it doesn't + */ + public boolean usesUnicode() { + + initText(); + + for (int i = _textStart; i < _textEnd; i++) { + TextPiece piece = (TextPiece) _text.get(i); + if (piece.isUnicode()) + return true; + } + + return false; + } + + /** + * Gets the text that this Range contains. + * + * @return The text for this range. + */ + public String text() { + initText(); + + StringBuffer sb = new StringBuffer(); + + for (int x = _textStart; x < _textEnd; x++) { + TextPiece piece = (TextPiece) _text.get(x); + + // Figure out where in this piece the text + // we're after lives + int rStart = 0; + int rEnd = piece.characterLength(); + if (_start > piece.getStart()) { + rStart = _start - piece.getStart(); + } + if (_end < piece.getEnd()) { + rEnd -= (piece.getEnd() - _end); + } + + // Luckily TextPieces work in characters, so we don't + // need to worry about unicode here + sb.append(piece.substring(rStart, rEnd)); + } + return sb.toString(); + } + + /** + * Removes any fields (eg macros, page markers etc) from the string. + * Normally used to make some text suitable for showing to humans, and the + * resultant text should not normally be saved back into the document! + */ + public static String stripFields(String text) { + // First up, fields can be nested... + // A field can be 0x13 [contents] 0x15 + // Or it can be 0x13 [contents] 0x14 [real text] 0x15 + + // If there are no fields, all easy + if (text.indexOf('\u0013') == -1) + return text; + + // Loop over until they're all gone + // That's when we're out of both 0x13s and 0x15s + while (text.indexOf('\u0013') > -1 && text.indexOf('\u0015') > -1) { + int first13 = text.indexOf('\u0013'); + int next13 = text.indexOf('\u0013', first13 + 1); + int first14 = text.indexOf('\u0014', first13 + 1); + int last15 = text.lastIndexOf('\u0015'); + + // If they're the wrong way around, give up + if (last15 < first13) { + break; + } + + // If no more 13s and 14s, just zap + if (next13 == -1 && first14 == -1) { + text = text.substring(0, first13) + text.substring(last15 + 1); + break; + } + + // If a 14 comes before the next 13, then + // zap from the 13 to the 14, and remove + // the 15 + if (first14 != -1 && (first14 < next13 || next13 == -1)) { + text = text.substring(0, first13) + text.substring(first14 + 1, last15) + + text.substring(last15 + 1); + continue; + } + + // Another 13 comes before the next 14. + // This means there's nested stuff, so we + // can just zap the lot + text = text.substring(0, first13) + text.substring(last15 + 1); + continue; + } + + return text; + } + + /** + * Used to get the number of sections in a range. If this range is smaller + * than a section, it will return 1 for its containing section. + * + * @return The number of sections in this range. + */ + public int numSections() { + initSections(); + return _sectionEnd - _sectionStart; + } + + /** + * Used to get the number of paragraphs in a range. If this range is smaller + * than a paragraph, it will return 1 for its containing paragraph. + * + * @return The number of paragraphs in this range. + */ + + public int numParagraphs() { + initParagraphs(); + return _parEnd - _parStart; + } + + /** + * + * @return The number of characterRuns in this range. + */ + + public int numCharacterRuns() { + initCharacterRuns(); + return _charEnd - _charStart; + } + + /** + * Inserts text into the front of this range. + * + * @param text + * The text to insert + * @return The character run that text was inserted into. + */ + public CharacterRun insertBefore(String text) + // throws UnsupportedEncodingException + { + initAll(); + + TextPiece tp = (TextPiece) _text.get(_textStart); + StringBuffer sb = tp.getStringBuffer(); + + // Since this is the first item in our list, it is safe to assume that + // _start >= tp.getStart() + int insertIndex = _start - tp.getStart(); + sb.insert(insertIndex, text); + + int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length()); + _doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength); + _doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength); + _doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength); + adjustForInsert(adjustedLength); + + // update the FIB.CCPText + friends fields + adjustFIB(text.length()); + + return getCharacterRun(0); + } + + /** + * Inserts text onto the end of this range + * + * @param text + * The text to insert + * @return The character run the text was inserted into. + */ + public CharacterRun insertAfter(String text) { + initAll(); + + int listIndex = _textEnd - 1; + TextPiece tp = (TextPiece) _text.get(listIndex); + StringBuffer sb = tp.getStringBuffer(); + + int insertIndex = _end - tp.getStart(); + + if (tp.getStringBuffer().charAt(_end - 1) == '\r' && text.charAt(0) != '\u0007') { + insertIndex--; + } + sb.insert(insertIndex, text); + int adjustedLength = _doc.getTextTable().adjustForInsert(listIndex, text.length()); + _doc.getCharacterTable().adjustForInsert(_charEnd - 1, adjustedLength); + _doc.getParagraphTable().adjustForInsert(_parEnd - 1, adjustedLength); + _doc.getSectionTable().adjustForInsert(_sectionEnd - 1, adjustedLength); + adjustForInsert(text.length()); + + return getCharacterRun(numCharacterRuns() - 1); + + } + + /** + * Inserts text into the front of this range and it gives that text the + * CharacterProperties specified in props. + * + * @param text + * The text to insert. + * @param props + * The CharacterProperties to give the text. + * @return A new CharacterRun that has the given text and properties and is + * n ow a part of the document. + */ + public CharacterRun insertBefore(String text, CharacterProperties props) + // throws UnsupportedEncodingException + { + initAll(); + PAPX papx = (PAPX) _paragraphs.get(_parStart); + short istd = papx.getIstd(); + + StyleSheet ss = _doc.getStyleSheet(); + CharacterProperties baseStyle = ss.getCharacterStyle(istd); + byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); + SprmBuffer buf = new SprmBuffer(grpprl); + _doc.getCharacterTable().insert(_charStart, _start, buf); + + return insertBefore(text); + } + + /** + * Inserts text onto the end of this range and gives that text the + * CharacterProperties specified in props. + * + * @param text + * The text to insert. + * @param props + * The CharacterProperties to give the text. + * @return A new CharacterRun that has the given text and properties and is + * n ow a part of the document. + */ + public CharacterRun insertAfter(String text, CharacterProperties props) + // throws UnsupportedEncodingException + { + initAll(); + PAPX papx = (PAPX) _paragraphs.get(_parEnd - 1); + short istd = papx.getIstd(); + + StyleSheet ss = _doc.getStyleSheet(); + CharacterProperties baseStyle = ss.getCharacterStyle(istd); + byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); + SprmBuffer buf = new SprmBuffer(grpprl); + _doc.getCharacterTable().insert(_charEnd, _end, buf); + _charEnd++; + return insertAfter(text); + } + + /** + * Inserts and empty paragraph into the front of this range. + * + * @param props + * The properties that the new paragraph will have. + * @param styleIndex + * The index into the stylesheet for the new paragraph. + * @return The newly inserted paragraph. + */ + public Paragraph insertBefore(ParagraphProperties props, int styleIndex) + // throws UnsupportedEncodingException + { + return this.insertBefore(props, styleIndex, "\r"); + } + + /** + * Inserts a paragraph into the front of this range. The paragraph will + * contain one character run that has the default properties for the + * paragraph's style. + * + * It is necessary for the text to end with the character '\r' + * + * @param props + * The paragraph's properties. + * @param styleIndex + * The index of the paragraph's style in the style sheet. + * @param text + * The text to insert. + * @return A newly inserted paragraph. + */ + protected Paragraph insertBefore(ParagraphProperties props, int styleIndex, String text) + // throws UnsupportedEncodingException { - TextPiece piece = (TextPiece)_text.get(i); - if (piece.isUnicode()) - return true; + initAll(); + StyleSheet ss = _doc.getStyleSheet(); + ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex); + CharacterProperties baseChp = ss.getCharacterStyle(styleIndex); + + byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle); + byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; + LittleEndian.putShort(withIndex, (short) styleIndex); + System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); + SprmBuffer buf = new SprmBuffer(withIndex); + + _doc.getParagraphTable().insert(_parStart, _start, buf); + insertBefore(text, baseChp); + return getParagraph(0); } - return false; - } - - /** - * Gets the text that this Range contains. - * - * @return The text for this range. - */ - public String text() - { - initText(); - - StringBuffer sb = new StringBuffer(); - - for (int x = _textStart; x < _textEnd; x++) - { - TextPiece piece = (TextPiece)_text.get(x); - - // Figure out where in this piece the text - // we're after lives - int rStart = 0; - int rEnd = piece.characterLength(); - if(_start > piece.getStart()) { - rStart = _start - piece.getStart(); - } - if(_end < piece.getEnd()) { - rEnd -= (piece.getEnd() - _end); - } - - // Luckily TextPieces work in characters, so we don't - // need to worry about unicode here - sb.append(piece.substring(rStart, rEnd)); - } - return sb.toString(); - } - - /** - * Removes any fields (eg macros, page markers etc) - * from the string. - * Normally used to make some text suitable for showing - * to humans, and the resultant text should not normally - * be saved back into the document! - */ - public static String stripFields(String text) { - // First up, fields can be nested... - // A field can be 0x13 [contents] 0x15 - // Or it can be 0x13 [contents] 0x14 [real text] 0x15 - - // If there are no fields, all easy - if(text.indexOf('\u0013') == -1) return text; - - // Loop over until they're all gone - // That's when we're out of both 0x13s and 0x15s - while( text.indexOf('\u0013') > -1 && - text.indexOf('\u0015') > -1) { - int first13 = text.indexOf('\u0013'); - int next13 = text.indexOf('\u0013', first13+1); - int first14 = text.indexOf('\u0014', first13+1); - int last15 = text.lastIndexOf('\u0015'); - - // If they're the wrong way around, give up - if(last15 < first13) { - break; - } - - // If no more 13s and 14s, just zap - if(next13 == -1 && first14 == -1) { - text = text.substring(0, first13) + - text.substring(last15+1); - break; - } - - // If a 14 comes before the next 13, then - // zap from the 13 to the 14, and remove - // the 15 - if(first14 != -1 && (first14 < next13 || next13 == -1)) { - text = text.substring(0, first13) + - text.substring(first14+1, last15) + - text.substring(last15+1); - continue; - } - - // Another 13 comes before the next 14. - // This means there's nested stuff, so we - // can just zap the lot - text = text.substring(0, first13) + - text.substring(last15+1); - continue; - } - - return text; - } - - /** - * Used to get the number of sections in a range. If this range is smaller - * than a section, it will return 1 for its containing section. - * - * @return The number of sections in this range. - */ - public int numSections() - { - initSections(); - return _sectionEnd - _sectionStart; - } - - /** - * Used to get the number of paragraphs in a range. If this range is smaller - * than a paragraph, it will return 1 for its containing paragraph. - * - * @return The number of paragraphs in this range. - */ - - public int numParagraphs() - { - initParagraphs(); - return _parEnd - _parStart; - } - - /** - * - * @return The number of characterRuns in this range. - */ - - public int numCharacterRuns() - { - initCharacterRuns(); - return _charEnd - _charStart; - } - - /** - * Inserts text into the front of this range. - * - * @param text The text to insert - * @return The character run that text was inserted into. - */ - public CharacterRun insertBefore(String text) - //throws UnsupportedEncodingException - { - initAll(); - - TextPiece tp = (TextPiece)_text.get(_textStart); - StringBuffer sb = (StringBuffer)tp.getStringBuffer(); - - // Since this is the first item in our list, it is safe to assume that - // _start >= tp.getStart() - int insertIndex = _start - tp.getStart(); - sb.insert(insertIndex, text); - - int adjustedLength = _doc.getTextTable().adjustForInsert(_textStart, text.length()); - _doc.getCharacterTable().adjustForInsert(_charStart, adjustedLength); - _doc.getParagraphTable().adjustForInsert(_parStart, adjustedLength); - _doc.getSectionTable().adjustForInsert(_sectionStart, adjustedLength); - adjustForInsert(adjustedLength); - - // update the FIB.CCPText + friends fields - adjustFIB(text.length()); - - return getCharacterRun(0); - } - - /** - * Inserts text onto the end of this range - * - * @param text The text to insert - * @return The character run the text was inserted into. - */ - public CharacterRun insertAfter(String text) - { - initAll(); - - int listIndex = _textEnd - 1; - TextPiece tp = (TextPiece)_text.get(listIndex); - StringBuffer sb = (StringBuffer)tp.getStringBuffer(); - - int insertIndex = _end - tp.getStart(); - - if (tp.getStringBuffer().charAt(_end - 1) == '\r' && text.charAt(0) != '\u0007') - { - insertIndex--; - } - sb.insert(insertIndex, text); - int adjustedLength = _doc.getTextTable().adjustForInsert(listIndex, text.length()); - _doc.getCharacterTable().adjustForInsert(_charEnd - 1, adjustedLength); - _doc.getParagraphTable().adjustForInsert(_parEnd - 1, adjustedLength); - _doc.getSectionTable().adjustForInsert(_sectionEnd - 1, adjustedLength); - adjustForInsert(text.length()); - - return getCharacterRun(numCharacterRuns() - 1); - - } - - /** - * Inserts text into the front of this range and it gives that text the - * CharacterProperties specified in props. - * - * @param text The text to insert. - * @param props The CharacterProperties to give the text. - * @return A new CharacterRun that has the given text and properties and is n - * ow a part of the document. - */ - public CharacterRun insertBefore(String text, CharacterProperties props) - //throws UnsupportedEncodingException - { - initAll(); - PAPX papx = (PAPX)_paragraphs.get(_parStart); - short istd = papx.getIstd(); - - StyleSheet ss = _doc.getStyleSheet(); - CharacterProperties baseStyle = ss.getCharacterStyle(istd); - byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); - SprmBuffer buf = new SprmBuffer(grpprl); - _doc.getCharacterTable().insert(_charStart, _start, buf); - - return insertBefore(text); - } - - /** - * Inserts text onto the end of this range and gives that text the - * CharacterProperties specified in props. - * - * @param text The text to insert. - * @param props The CharacterProperties to give the text. - * @return A new CharacterRun that has the given text and properties and is n - * ow a part of the document. - */ - public CharacterRun insertAfter(String text, CharacterProperties props) - //throws UnsupportedEncodingException - { - initAll(); - PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1); - short istd = papx.getIstd(); - - StyleSheet ss = _doc.getStyleSheet(); - CharacterProperties baseStyle = ss.getCharacterStyle(istd); - byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle); - SprmBuffer buf = new SprmBuffer(grpprl); - _doc.getCharacterTable().insert(_charEnd, _end, buf); - _charEnd++; - return insertAfter(text); - } - - /** - * Inserts and empty paragraph into the front of this range. - * - * @param props The properties that the new paragraph will have. - * @param styleIndex The index into the stylesheet for the new paragraph. - * @return The newly inserted paragraph. - */ - public Paragraph insertBefore(ParagraphProperties props, int styleIndex) - //throws UnsupportedEncodingException - { - return this.insertBefore(props, styleIndex, "\r"); - } - - /** - * Inserts a paragraph into the front of this range. The paragraph will - * contain one character run that has the default properties for the - * paragraph's style. - * - * It is necessary for the text to end with the character '\r' - * - * @param props The paragraph's properties. - * @param styleIndex The index of the paragraph's style in the style sheet. - * @param text The text to insert. - * @return A newly inserted paragraph. - */ - protected Paragraph insertBefore(ParagraphProperties props, int styleIndex, String text) - //throws UnsupportedEncodingException - { - initAll(); - StyleSheet ss = _doc.getStyleSheet(); - ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex); - CharacterProperties baseChp = ss.getCharacterStyle(styleIndex); - - byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle); - byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; - LittleEndian.putShort(withIndex, (short)styleIndex); - System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); - SprmBuffer buf = new SprmBuffer(withIndex); - - _doc.getParagraphTable().insert(_parStart, _start, buf); - insertBefore(text, baseChp); - return getParagraph(0); - } - - /** - * Inserts and empty paragraph into the end of this range. - * - * @param props The properties that the new paragraph will have. - * @param styleIndex The index into the stylesheet for the new paragraph. - * @return The newly inserted paragraph. - */ - - public Paragraph insertAfter(ParagraphProperties props, int styleIndex) - //throws UnsupportedEncodingException - { - return this.insertAfter(props, styleIndex, "\r"); - } - - /** - * Inserts a paragraph into the end of this range. The paragraph will - * contain one character run that has the default properties for the - * paragraph's style. - * - * It is necessary for the text to end with the character '\r' - * - * @param props The paragraph's properties. - * @param styleIndex The index of the paragraph's style in the style sheet. - * @param text The text to insert. - * @return A newly inserted paragraph. - */ - protected Paragraph insertAfter(ParagraphProperties props, int styleIndex, String text) - //throws UnsupportedEncodingException - { - initAll(); - StyleSheet ss = _doc.getStyleSheet(); - ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex); - CharacterProperties baseChp = ss.getCharacterStyle(styleIndex); - - byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle); - byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; - LittleEndian.putShort(withIndex, (short)styleIndex); - System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); - SprmBuffer buf = new SprmBuffer(withIndex); - - _doc.getParagraphTable().insert(_parEnd, _end, buf); - _parEnd++; - insertAfter(text, baseChp); - return getParagraph(numParagraphs() - 1); - } - - public void delete() - { - - initAll(); - - int numSections = _sections.size(); - int numRuns = _characters.size(); - int numParagraphs = _paragraphs.size(); - int numTextPieces = _text.size(); - - for (int x = _charStart; x < numRuns; x++) - { - CHPX chpx = (CHPX)_characters.get(x); - chpx.adjustForDelete(_start, _end - _start); - } - - for (int x = _parStart; x < numParagraphs; x++) - { - PAPX papx = (PAPX)_paragraphs.get(x); - //System.err.println("Paragraph " + x + " was " + papx.getStart() + " -> " + papx.getEnd()); - papx.adjustForDelete(_start, _end - _start); - //System.err.println("Paragraph " + x + " is now " + papx.getStart() + " -> " + papx.getEnd()); - } - - for (int x = _sectionStart; x < numSections; x++) - { - SEPX sepx = (SEPX)_sections.get(x); - //System.err.println("Section " + x + " was " + sepx.getStart() + " -> " + sepx.getEnd()); - sepx.adjustForDelete(_start, _end - _start); - //System.err.println("Section " + x + " is now " + sepx.getStart() + " -> " + sepx.getEnd()); - } - - for (int x = _textStart; x < numTextPieces; x++) - { - TextPiece piece = (TextPiece)_text.get(x); - piece.adjustForDelete(_start, _end - _start); - } - - // update the FIB.CCPText + friends field - adjustFIB(-(_end - _start)); - } - - /** - * Inserts a simple table into the beginning of this range. The number of - * columns is determined by the TableProperties passed into this function. - * - * @param props The table properties for the table. - * @param rows The number of rows. - * @return The empty Table that is now part of the document. - */ - public Table insertBefore(TableProperties props, int rows) - { - ParagraphProperties parProps = new ParagraphProperties(); - parProps.setFInTable((byte)1); - parProps.setTableLevel((byte)1); - - int columns = props.getItcMac(); - for (int x = 0; x < rows; x++) - { - Paragraph cell = this.insertBefore(parProps, StyleSheet.NIL_STYLE); - cell.insertAfter(String.valueOf('\u0007')); - for(int y = 1; y < columns; y++) - { - cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE); - cell.insertAfter(String.valueOf('\u0007')); - } - cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE, String.valueOf('\u0007')); - cell.setTableRowEnd(props); - } - return new Table(_start, _start + (rows * (columns + 1)), this, 1); - } - - /** - * Inserts a list into the beginning of this range. - * - * @param props The properties of the list entry. All list entries are - * paragraphs. - * @param listID The id of the list that contains the properties. - * @param level The indentation level of the list. - * @param styleIndex The base style's index in the stylesheet. - * @return The empty ListEntry that is now part of the document. - */ - public ListEntry insertBefore(ParagraphProperties props, int listID, int level, int styleIndex) - { - ListTables lt = _doc.getListTables(); - if (lt.getLevel(listID, level) == null) - { - throw new NoSuchElementException("The specified list and level do not exist"); - } - - int ilfo = lt.getOverrideIndexFromListID(listID); - props.setIlfo(ilfo); - props.setIlvl((byte)level); - - return (ListEntry)insertBefore(props, styleIndex); - } - - /** - * Inserts a list into the beginning of this range. - * - * @param props The properties of the list entry. All list entries are - * paragraphs. - * @param listID The id of the list that contains the properties. - * @param level The indentation level of the list. - * @param styleIndex The base style's index in the stylesheet. - * @return The empty ListEntry that is now part of the document. - */ - public ListEntry insertAfter(ParagraphProperties props, int listID, int level, int styleIndex) - { - ListTables lt = _doc.getListTables(); - if (lt.getLevel(listID, level) == null) - { - throw new NoSuchElementException("The specified list and level do not exist"); - } - int ilfo = lt.getOverrideIndexFromListID(listID); - props.setIlfo(ilfo); - props.setIlvl((byte)level); - - return (ListEntry)insertAfter(props, styleIndex); - } - - /** - * Replace (one instance of) a piece of text with another... - * - * @param pPlaceHolder The text to be replaced (e.g., "${organization}") - * @param pValue The replacement text (e.g., "Apache Software Foundation") - * @param pOffset The offset or index where the text to be replaced begins - * (relative to/within this Range) - */ - public void replaceText(String pPlaceHolder, String pValue, int pOffset) - { - int absPlaceHolderIndex = getStartOffset() + pOffset; - Range subRange = new Range( - absPlaceHolderIndex, - (absPlaceHolderIndex + pPlaceHolder.length()), getDocument() - ); - - // this Range isn't a proper parent of the subRange() so we'll have to keep - // track of an updated endOffset on our own - int previousEndOffset = subRange.getEndOffset(); - - subRange.insertBefore(pValue); - - if (subRange.getEndOffset() != previousEndOffset) - _end += (subRange.getEndOffset() - previousEndOffset); - - // re-create the sub-range so we can delete it - subRange = new Range( - (absPlaceHolderIndex + pValue.length()), - (absPlaceHolderIndex + pPlaceHolder.length() + pValue.length()), - getDocument() - ); - - // deletes are automagically propagated - subRange.delete(); - } - - /** - * Replace (all instances of) a piece of text with another... - * - * @param pPlaceHolder The text to be replaced (e.g., "${organization}") - * @param pValue The replacement text (e.g., "Apache Software Foundation") - */ - public void replaceText(String pPlaceHolder, String pValue) - { + /** + * Inserts and empty paragraph into the end of this range. + * + * @param props + * The properties that the new paragraph will have. + * @param styleIndex + * The index into the stylesheet for the new paragraph. + * @return The newly inserted paragraph. + */ + + public Paragraph insertAfter(ParagraphProperties props, int styleIndex) + // throws UnsupportedEncodingException + { + return this.insertAfter(props, styleIndex, "\r"); + } + + /** + * Inserts a paragraph into the end of this range. The paragraph will + * contain one character run that has the default properties for the + * paragraph's style. + * + * It is necessary for the text to end with the character '\r' + * + * @param props + * The paragraph's properties. + * @param styleIndex + * The index of the paragraph's style in the style sheet. + * @param text + * The text to insert. + * @return A newly inserted paragraph. + */ + protected Paragraph insertAfter(ParagraphProperties props, int styleIndex, String text) + // throws UnsupportedEncodingException + { + initAll(); + StyleSheet ss = _doc.getStyleSheet(); + ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex); + CharacterProperties baseChp = ss.getCharacterStyle(styleIndex); + + byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle); + byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; + LittleEndian.putShort(withIndex, (short) styleIndex); + System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); + SprmBuffer buf = new SprmBuffer(withIndex); + + _doc.getParagraphTable().insert(_parEnd, _end, buf); + _parEnd++; + insertAfter(text, baseChp); + return getParagraph(numParagraphs() - 1); + } + + public void delete() { + + initAll(); + + int numSections = _sections.size(); + int numRuns = _characters.size(); + int numParagraphs = _paragraphs.size(); + int numTextPieces = _text.size(); + + for (int x = _charStart; x < numRuns; x++) { + CHPX chpx = (CHPX) _characters.get(x); + chpx.adjustForDelete(_start, _end - _start); + } + + for (int x = _parStart; x < numParagraphs; x++) { + PAPX papx = (PAPX) _paragraphs.get(x); + // System.err.println("Paragraph " + x + " was " + papx.getStart() + + // " -> " + papx.getEnd()); + papx.adjustForDelete(_start, _end - _start); + // System.err.println("Paragraph " + x + " is now " + + // papx.getStart() + " -> " + papx.getEnd()); + } + + for (int x = _sectionStart; x < numSections; x++) { + SEPX sepx = (SEPX) _sections.get(x); + // System.err.println("Section " + x + " was " + sepx.getStart() + + // " -> " + sepx.getEnd()); + sepx.adjustForDelete(_start, _end - _start); + // System.err.println("Section " + x + " is now " + sepx.getStart() + // + " -> " + sepx.getEnd()); + } + + for (int x = _textStart; x < numTextPieces; x++) { + TextPiece piece = (TextPiece) _text.get(x); + piece.adjustForDelete(_start, _end - _start); + } + + // update the FIB.CCPText + friends field + adjustFIB(-(_end - _start)); + } + + /** + * Inserts a simple table into the beginning of this range. The number of + * columns is determined by the TableProperties passed into this function. + * + * @param props + * The table properties for the table. + * @param rows + * The number of rows. + * @return The empty Table that is now part of the document. + */ + public Table insertBefore(TableProperties props, int rows) { + ParagraphProperties parProps = new ParagraphProperties(); + parProps.setFInTable((byte) 1); + parProps.setTableLevel((byte) 1); + + int columns = props.getItcMac(); + for (int x = 0; x < rows; x++) { + Paragraph cell = this.insertBefore(parProps, StyleSheet.NIL_STYLE); + cell.insertAfter(String.valueOf('\u0007')); + for (int y = 1; y < columns; y++) { + cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE); + cell.insertAfter(String.valueOf('\u0007')); + } + cell = cell.insertAfter(parProps, StyleSheet.NIL_STYLE, String.valueOf('\u0007')); + cell.setTableRowEnd(props); + } + return new Table(_start, _start + (rows * (columns + 1)), this, 1); + } + + /** + * Inserts a list into the beginning of this range. + * + * @param props + * The properties of the list entry. All list entries are + * paragraphs. + * @param listID + * The id of the list that contains the properties. + * @param level + * The indentation level of the list. + * @param styleIndex + * The base style's index in the stylesheet. + * @return The empty ListEntry that is now part of the document. + */ + public ListEntry insertBefore(ParagraphProperties props, int listID, int level, int styleIndex) { + ListTables lt = _doc.getListTables(); + if (lt.getLevel(listID, level) == null) { + throw new NoSuchElementException("The specified list and level do not exist"); + } + + int ilfo = lt.getOverrideIndexFromListID(listID); + props.setIlfo(ilfo); + props.setIlvl((byte) level); + + return (ListEntry) insertBefore(props, styleIndex); + } + + /** + * Inserts a list into the beginning of this range. + * + * @param props + * The properties of the list entry. All list entries are + * paragraphs. + * @param listID + * The id of the list that contains the properties. + * @param level + * The indentation level of the list. + * @param styleIndex + * The base style's index in the stylesheet. + * @return The empty ListEntry that is now part of the document. + */ + public ListEntry insertAfter(ParagraphProperties props, int listID, int level, int styleIndex) { + ListTables lt = _doc.getListTables(); + if (lt.getLevel(listID, level) == null) { + throw new NoSuchElementException("The specified list and level do not exist"); + } + int ilfo = lt.getOverrideIndexFromListID(listID); + props.setIlfo(ilfo); + props.setIlvl((byte) level); + + return (ListEntry) insertAfter(props, styleIndex); + } + + /** + * Replace (one instance of) a piece of text with another... + * + * @param pPlaceHolder + * The text to be replaced (e.g., "${organization}") + * @param pValue + * The replacement text (e.g., "Apache Software Foundation") + * @param pOffset + * The offset or index where the text to be replaced begins + * (relative to/within this Range) + */ + public void replaceText(String pPlaceHolder, String pValue, int pOffset) { + int absPlaceHolderIndex = getStartOffset() + pOffset; + Range subRange = new Range(absPlaceHolderIndex, (absPlaceHolderIndex + pPlaceHolder + .length()), getDocument()); + + // this Range isn't a proper parent of the subRange() so we'll have to + // keep + // track of an updated endOffset on our own + int previousEndOffset = subRange.getEndOffset(); + + subRange.insertBefore(pValue); + + if (subRange.getEndOffset() != previousEndOffset) + _end += (subRange.getEndOffset() - previousEndOffset); + + // re-create the sub-range so we can delete it + subRange = new Range((absPlaceHolderIndex + pValue.length()), (absPlaceHolderIndex + + pPlaceHolder.length() + pValue.length()), getDocument()); + + // deletes are automagically propagated + subRange.delete(); + } + + /** + * Replace (all instances of) a piece of text with another... + * + * @param pPlaceHolder + * The text to be replaced (e.g., "${organization}") + * @param pValue + * The replacement text (e.g., "Apache Software Foundation") + */ + public void replaceText(String pPlaceHolder, String pValue) { boolean keepLooking = true; while (keepLooking) { @@ -767,299 +775,285 @@ public class Range { // TODO -instantiable superclass else keepLooking = false; } - } - - /** - * Gets the character run at index. The index is relative to this range. - * - * @param index The index of the character run to get. - * @return The character run at the specified index in this range. - */ - public CharacterRun getCharacterRun(int index) - { - initCharacterRuns(); - CHPX chpx = (CHPX)_characters.get(index + _charStart); - - int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start), - chpx.getEnd()); - PAPX papx = (PAPX)_paragraphs.get(point[0]); - short istd = papx.getIstd(); - - CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this); - - return chp; - } - - /** - * Gets the section at index. The index is relative to this range. - * - * @param index The index of the section to get. - * @return The section at the specified index in this range. - */ - public Section getSection(int index) - { - initSections(); - SEPX sepx = (SEPX)_sections.get(index + _sectionStart); - Section sep = new Section(sepx, this); - return sep; - } - - /** - * Gets the paragraph at index. The index is relative to this range. - * - * @param index The index of the paragraph to get. - * @return The paragraph at the specified index in this range. - */ - - public Paragraph getParagraph(int index) - { - initParagraphs(); - PAPX papx = (PAPX)_paragraphs.get(index + _parStart); - - ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet()); - Paragraph pap = null; - if (props.getIlfo() > 0) - { - pap = new ListEntry(papx, this, _doc.getListTables()); - } - else - { - pap = new Paragraph(papx, this); - } - - return pap; - } - - /** - * This method is used to determine the type. Handy for switch statements - * compared to the instanceof operator. - * - * @return A TYPE constant. - */ - public int type() - { - return TYPE_UNDEFINED; - } - - /** - * Gets the table that starts with paragraph. In a Word file, a table consists - * of a group of paragraphs with certain flags set. - * - * @param paragraph The paragraph that is the first paragraph in the table. - * @return The table that starts with paragraph - */ - public Table getTable(Paragraph paragraph) - { - if (!paragraph.isInTable()) - { - throw new IllegalArgumentException("This paragraph doesn't belong to a table"); - } - - Range r = (Range)paragraph; - if (r._parent.get() != this) - { - throw new IllegalArgumentException("This paragraph is not a child of this range"); - } - - r.initAll(); - int tableEnd = r._parEnd; - - if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable() - && getParagraph(r._parStart - 1)._sectionEnd >= r._sectionStart) - { - throw new IllegalArgumentException("This paragraph is not the first one in the table"); - } - - int limit = _paragraphs.size(); - for (; tableEnd < limit; tableEnd++) - { - if (!getParagraph(tableEnd).isInTable()) - { - break; - } - } - - initAll(); - if (tableEnd > _parEnd) - { - throw new ArrayIndexOutOfBoundsException("The table's bounds fall outside of this Range"); - } - if (tableEnd < 0) - { - throw new ArrayIndexOutOfBoundsException("The table's end is negative, which isn't allowed!"); - } - return new Table(r._parStart, tableEnd, r._doc.getRange(), paragraph.getTableLevel()); - } - - /** - * loads all of the list indexes. - */ - protected void initAll() - { - initText(); - initCharacterRuns(); - initParagraphs(); - initSections(); - } - - /** - * inits the paragraph list indexes. - */ - private void initParagraphs() - { - if (!_parRangeFound) - { - int[] point = findRange(_paragraphs, _parStart, _start, _end); - _parStart = point[0]; - _parEnd = point[1]; - _parRangeFound = true; - } - } - - /** - * inits the character run list indexes. - */ - private void initCharacterRuns() - { - if (!_charRangeFound) - { - int[] point = findRange(_characters, _charStart, _start, _end); - _charStart = point[0]; - _charEnd = point[1]; - _charRangeFound = true; - } - } - - /** - * inits the text piece list indexes. - */ - private void initText() - { - if (!_textRangeFound) - { - int[] point = findRange(_text, _textStart, _start, _end); - _textStart = point[0]; - _textEnd = point[1]; - _textRangeFound = true; - } - } - - /** - * inits the section list indexes. - */ - private void initSections() - { - if (!_sectionRangeFound) - { - int[] point = findRange(_sections, _sectionStart, _start, _end); - _sectionStart = point[0]; - _sectionEnd = point[1]; - _sectionRangeFound = true; - } - } - - /** - * Used to find the list indexes of a particular property. - * - * @param rpl A list of property nodes. - * @param min A hint on where to start looking. - * @param start The starting character offset. - * @param end The ending character offset. - * @return An int array of length 2. The first int is the start index and the - * second int is the end index. - */ - private int[] findRange(List rpl, int min, int start, int end) - { - int x = min; - PropertyNode node = (PropertyNode)rpl.get(x); - while(node.getEnd() <= start && x < rpl.size()-1) - { - x++; - node = (PropertyNode)rpl.get(x); - } - - if (node.getEnd() <= start) { - return new int[] {rpl.size(), rpl.size()}; - } - - int y = x; - node = (PropertyNode)rpl.get(y); - while(node.getEnd() < end && y < rpl.size()-1) - { - y++; - node = (PropertyNode)rpl.get(y); - } - return new int[]{x, y + 1}; - } - - /** - * resets the list indexes. - */ - private void reset() - { - _textRangeFound = false; - _charRangeFound = false; - _parRangeFound = false; - _sectionRangeFound = false; - } - - /** - * Adjust the value of the various FIB character count fields, - * eg FIB.CCPText after an insert or a delete... - * - * Works on all CCP fields from this range onwards - * - * @param adjustment The (signed) value that should be added to the FIB CCP fields - */ - protected void adjustFIB(int adjustment) { - // update the FIB.CCPText field (this should happen once per adjustment, so we don't want it in - // adjustForInsert() or it would get updated multiple times if the range has a parent) - // without this, OpenOffice.org (v. 2.2.x) does not see all the text in the document - - CPSplitCalculator cpS = _doc.getCPSplitCalculator(); - FileInformationBlock fib = _doc.getFileInformationBlock(); - - // Do for each affected part - if(_start < cpS.getMainDocumentEnd()) { - fib.setCcpText(fib.getCcpText() + adjustment); } - if(_start < cpS.getCommentsEnd()) { - fib.setCcpAtn(fib.getCcpAtn() + adjustment); + /** + * Gets the character run at index. The index is relative to this range. + * + * @param index + * The index of the character run to get. + * @return The character run at the specified index in this range. + */ + public CharacterRun getCharacterRun(int index) { + initCharacterRuns(); + CHPX chpx = (CHPX) _characters.get(index + _charStart); + + int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start), chpx + .getEnd()); + PAPX papx = (PAPX) _paragraphs.get(point[0]); + short istd = papx.getIstd(); + + CharacterRun chp = new CharacterRun(chpx, _doc.getStyleSheet(), istd, this); + + return chp; + } + + /** + * Gets the section at index. The index is relative to this range. + * + * @param index + * The index of the section to get. + * @return The section at the specified index in this range. + */ + public Section getSection(int index) { + initSections(); + SEPX sepx = (SEPX) _sections.get(index + _sectionStart); + Section sep = new Section(sepx, this); + return sep; + } + + /** + * Gets the paragraph at index. The index is relative to this range. + * + * @param index + * The index of the paragraph to get. + * @return The paragraph at the specified index in this range. + */ + + public Paragraph getParagraph(int index) { + initParagraphs(); + PAPX papx = (PAPX) _paragraphs.get(index + _parStart); + + ParagraphProperties props = papx.getParagraphProperties(_doc.getStyleSheet()); + Paragraph pap = null; + if (props.getIlfo() > 0) { + pap = new ListEntry(papx, this, _doc.getListTables()); + } else { + pap = new Paragraph(papx, this); + } + + return pap; + } + + /** + * This method is used to determine the type. Handy for switch statements + * compared to the instanceof operator. + * + * @return A TYPE constant. + */ + public int type() { + return TYPE_UNDEFINED; + } + + /** + * Gets the table that starts with paragraph. In a Word file, a table + * consists of a group of paragraphs with certain flags set. + * + * @param paragraph + * The paragraph that is the first paragraph in the table. + * @return The table that starts with paragraph + */ + public Table getTable(Paragraph paragraph) { + if (!paragraph.isInTable()) { + throw new IllegalArgumentException("This paragraph doesn't belong to a table"); + } + + Range r = paragraph; + if (r._parent.get() != this) { + throw new IllegalArgumentException("This paragraph is not a child of this range"); + } + + r.initAll(); + int tableEnd = r._parEnd; + + if (r._parStart != 0 && getParagraph(r._parStart - 1).isInTable() + && getParagraph(r._parStart - 1)._sectionEnd >= r._sectionStart) { + throw new IllegalArgumentException("This paragraph is not the first one in the table"); + } + + int limit = _paragraphs.size(); + for (; tableEnd < limit; tableEnd++) { + if (!getParagraph(tableEnd).isInTable()) { + break; + } + } + + initAll(); + if (tableEnd > _parEnd) { + throw new ArrayIndexOutOfBoundsException( + "The table's bounds fall outside of this Range"); + } + if (tableEnd < 0) { + throw new ArrayIndexOutOfBoundsException( + "The table's end is negative, which isn't allowed!"); + } + return new Table(r._parStart, tableEnd, r._doc.getRange(), paragraph.getTableLevel()); + } + + /** + * loads all of the list indexes. + */ + protected void initAll() { + initText(); + initCharacterRuns(); + initParagraphs(); + initSections(); + } + + /** + * inits the paragraph list indexes. + */ + private void initParagraphs() { + if (!_parRangeFound) { + int[] point = findRange(_paragraphs, _parStart, _start, _end); + _parStart = point[0]; + _parEnd = point[1]; + _parRangeFound = true; + } } - if(_start < cpS.getEndNoteEnd()) { - fib.setCcpEdn(fib.getCcpEdn() + adjustment); + + /** + * inits the character run list indexes. + */ + private void initCharacterRuns() { + if (!_charRangeFound) { + int[] point = findRange(_characters, _charStart, _start, _end); + _charStart = point[0]; + _charEnd = point[1]; + _charRangeFound = true; + } + } + + /** + * inits the text piece list indexes. + */ + private void initText() { + if (!_textRangeFound) { + int[] point = findRange(_text, _textStart, _start, _end); + _textStart = point[0]; + _textEnd = point[1]; + _textRangeFound = true; + } } - if(_start < cpS.getFootnoteEnd()) { - fib.setCcpFtn(fib.getCcpFtn() + adjustment); + + /** + * inits the section list indexes. + */ + private void initSections() { + if (!_sectionRangeFound) { + int[] point = findRange(_sections, _sectionStart, _start, _end); + _sectionStart = point[0]; + _sectionEnd = point[1]; + _sectionRangeFound = true; + } } - if(_start < cpS.getHeaderStoryEnd()) { - fib.setCcpHdd(fib.getCcpHdd() + adjustment); + + /** + * Used to find the list indexes of a particular property. + * + * @param rpl + * A list of property nodes. + * @param min + * A hint on where to start looking. + * @param start + * The starting character offset. + * @param end + * The ending character offset. + * @return An int array of length 2. The first int is the start index and + * the second int is the end index. + */ + private int[] findRange(List rpl, int min, int start, int end) { + int x = min; + PropertyNode node = (PropertyNode) rpl.get(x); + while (node.getEnd() <= start && x < rpl.size() - 1) { + x++; + node = (PropertyNode) rpl.get(x); + } + + if (node.getEnd() <= start) { + return new int[] { rpl.size(), rpl.size() }; + } + + int y = x; + node = (PropertyNode) rpl.get(y); + while (node.getEnd() < end && y < rpl.size() - 1) { + y++; + node = (PropertyNode) rpl.get(y); + } + return new int[] { x, y + 1 }; } - if(_start < cpS.getHeaderTextboxEnd()) { - fib.setCcpHdrTxtBx(fib.getCcpHdrTxtBx() + adjustment); + + /** + * resets the list indexes. + */ + private void reset() { + _textRangeFound = false; + _charRangeFound = false; + _parRangeFound = false; + _sectionRangeFound = false; } - if(_start < cpS.getMainTextboxEnd()) { - fib.setCcpTxtBx(fib.getCcpTxtBx() + adjustment); + + /** + * Adjust the value of the various FIB character count fields, eg + * FIB.CCPText after an insert or a delete... + * + * Works on all CCP fields from this range onwards + * + * @param adjustment + * The (signed) value that should be added to the FIB CCP fields + */ + protected void adjustFIB(int adjustment) { + // update the FIB.CCPText field (this should happen once per adjustment, + // so we don't want it in + // adjustForInsert() or it would get updated multiple times if the range + // has a parent) + // without this, OpenOffice.org (v. 2.2.x) does not see all the text in + // the document + + CPSplitCalculator cpS = _doc.getCPSplitCalculator(); + FileInformationBlock fib = _doc.getFileInformationBlock(); + + // Do for each affected part + if (_start < cpS.getMainDocumentEnd()) { + fib.setCcpText(fib.getCcpText() + adjustment); + } + + if (_start < cpS.getCommentsEnd()) { + fib.setCcpAtn(fib.getCcpAtn() + adjustment); + } + if (_start < cpS.getEndNoteEnd()) { + fib.setCcpEdn(fib.getCcpEdn() + adjustment); + } + if (_start < cpS.getFootnoteEnd()) { + fib.setCcpFtn(fib.getCcpFtn() + adjustment); + } + if (_start < cpS.getHeaderStoryEnd()) { + fib.setCcpHdd(fib.getCcpHdd() + adjustment); + } + if (_start < cpS.getHeaderTextboxEnd()) { + fib.setCcpHdrTxtBx(fib.getCcpHdrTxtBx() + adjustment); + } + if (_start < cpS.getMainTextboxEnd()) { + fib.setCcpTxtBx(fib.getCcpTxtBx() + adjustment); + } } - } - - /** - * adjust this range after an insert happens. - * @param length the length to adjust for (expected to be a count of code-points, not necessarily chars) - */ - private void adjustForInsert(int length) - { - _end += length; - - reset(); - Range parent = (Range)_parent.get(); - if (parent != null) - { - parent.adjustForInsert(length); - } - } + /** + * adjust this range after an insert happens. + * + * @param length + * the length to adjust for (expected to be a count of + * code-points, not necessarily chars) + */ + private void adjustForInsert(int length) { + _end += length; + + reset(); + Range parent = (Range) _parent.get(); + if (parent != null) { + parent.adjustForInsert(length); + } + } public int getStartOffset() { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java index b06526ccd1..9d136f77f1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableProperties.java @@ -65,7 +65,7 @@ public final class TableProperties tap.field_14_brcRight = (BorderCode)field_14_brcRight.clone(); tap.field_15_brcVertical = (BorderCode)field_15_brcVertical.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]; for (int x = 0; x < field_9_rgtc.length; x++) { diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java index f342fd7231..7cb7f11644 100644 --- a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java @@ -50,11 +50,10 @@ public class TestModelFactory extends TestCase { { ModelFactory mf = new ModelFactory(); assertTrue("listeners member cannot be null", mf.listeners != null); - assertTrue("listeners member must be a List", mf.listeners instanceof List); models = new ArrayList(3); factory = new ModelFactory(); book = new HSSFWorkbook(); - ByteArrayOutputStream stream = (ByteArrayOutputStream)setupRunFile(book); + ByteArrayOutputStream stream = setupRunFile(book); POIFSFileSystem fs = new POIFSFileSystem( new ByteArrayInputStream(stream.toByteArray()) ); diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java b/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java index 4dface4251..1ade68044d 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java +++ b/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java @@ -115,7 +115,6 @@ public final class TestRecordFactory extends TestCase { * constructs the expected array of records.

* SUCCESS: Record factory creates the expected records.

* FAILURE: The wrong records are created or contain the wrong values

- * */ public void testContinuedUnknownRecord() { byte[] data = { @@ -125,8 +124,7 @@ public final class TestRecordFactory extends TestCase { }; ByteArrayInputStream bois = new ByteArrayInputStream(data); - Record[] records = (Record[]) - RecordFactory.createRecords(bois).toArray(new Record[0]); + Record[] records = RecordFactory.createRecords(bois).toArray(new Record[0]); assertEquals("Created record count", 3, records.length); assertEquals("1st record's type", UnknownRecord.class.getName(), -- 2.39.5