From 78e643fe2184d931b08120ee5f29e2b2e9daf3c1 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Thu, 8 Oct 2009 22:29:41 +0000 Subject: [PATCH] Bugzilla 47962 - Fixed some potential NPEs. Avoided unnecessary creation of box instances. Applied patch with mods git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@823348 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/contrib/view/SVTableCellEditor.java | 6 +- .../poi/hssf/contrib/view/SVTableUtils.java | 6 +- .../poi/ss/usermodel/contrib/CellUtil.java | 6 +- .../poi/ss/usermodel/contrib/RegionUtil.java | 2 +- .../ModifyDocumentSummaryInformation.java | 52 +- .../poi/ddf/DefaultEscherRecordFactory.java | 4 +- .../org/apache/poi/ddf/EscherOptRecord.java | 2 +- .../org/apache/poi/ddf/EscherProperties.java | 8 +- .../org/apache/poi/hpsf/CustomProperties.java | 45 +- .../poi/hpsf/DocumentSummaryInformation.java | 11 +- .../org/apache/poi/hpsf/MutableSection.java | 53 +- src/java/org/apache/poi/hpsf/Property.java | 2 +- src/java/org/apache/poi/hpsf/Section.java | 4 +- src/java/org/apache/poi/hpsf/Variant.java | 176 +-- .../org/apache/poi/hpsf/VariantSupport.java | 39 +- .../poi/hpsf/wellknown/PropertyIDMap.java | 45 +- .../FormatTrackingHSSFListener.java | 4 +- .../poi/hssf/eventusermodel/HSSFRequest.java | 152 +- .../apache/poi/hssf/model/DrawingManager.java | 4 +- src/java/org/apache/poi/hssf/model/Sheet.java | 4 +- .../org/apache/poi/hssf/model/Workbook.java | 12 +- .../record/EmbeddedObjectRefSubRecord.java | 52 +- .../poi/hssf/record/EscherAggregate.java | 2 +- .../apache/poi/hssf/record/NoteRecord.java | 8 +- .../poi/hssf/record/PageBreakRecord.java | 8 +- .../apache/poi/hssf/record/RecordFactory.java | 8 +- .../org/apache/poi/hssf/record/SubRecord.java | 2 +- .../poi/hssf/record/TextObjectRecord.java | 22 +- .../ColumnInfoRecordsAggregate.java | 24 +- .../aggregates/RowRecordsAggregate.java | 8 +- .../formula/function/FunctionDataBuilder.java | 16 +- .../poi/hssf/usermodel/FontDetails.java | 4 +- .../poi/hssf/usermodel/HSSFPictureData.java | 1 + .../apache/poi/hssf/usermodel/HSSFSheet.java | 12 +- .../poi/hssf/usermodel/HSSFWorkbook.java | 2 +- .../org/apache/poi/hssf/util/HSSFColor.java | 4 +- .../poi/ss/formula/WorkbookEvaluator.java | 4 +- .../poi/ss/usermodel/BuiltinFormats.java | 8 +- .../poi/ss/usermodel/DataFormatter.java | 4 +- .../apache/poi/ss/util/SheetReferences.java | 9 +- .../org/apache/poi/util/BitFieldFactory.java | 16 +- src/java/org/apache/poi/util/HexRead.java | 6 +- src/java/org/apache/poi/util/IntMapper.java | 2 +- src/java/org/apache/poi/util/POILogger.java | 8 +- src/java/org/apache/poi/util/StringUtil.java | 36 +- .../java/org/apache/poi/POIXMLProperties.java | 340 ++--- .../poi/xssf/extractor/XSSFExportToXml.java | 550 ++++--- .../apache/poi/xwpf/usermodel/Borders.java | 4 +- .../org/apache/poi/xwpf/usermodel/TOC.java | 14 +- .../poi/xwpf/usermodel/XWPFDocument.java | 49 +- .../poi/hdf/extractor/WordDocument.java | 6 +- .../poi/hdf/extractor/data/ListTables.java | 8 +- .../poi/hdf/extractor/util/BTreeSet.java | 6 +- .../poi/hdf/model/HDFObjectFactory.java | 2 +- .../poi/hdf/model/hdftypes/ListTables.java | 8 +- .../apache/poi/hdf/model/util/BTreeSet.java | 6 +- .../src/org/apache/poi/hdgf/chunks/Chunk.java | 10 +- .../apache/poi/hdgf/chunks/ChunkFactory.java | 4 +- .../apache/poi/hslf/EncryptedSlideShow.java | 2 +- .../org/apache/poi/hslf/HSLFSlideShow.java | 8 +- .../apache/poi/hslf/dev/SlideIdListing.java | 2 +- .../hslf/dev/UserEditAndPersistListing.java | 2 +- .../hslf/extractor/PowerPointExtractor.java | 2 +- .../org/apache/poi/hslf/model/ShapeTypes.java | 2 +- .../org/apache/poi/hslf/record/CString.java | 2 +- .../poi/hslf/record/PersistPtrHolder.java | 12 +- .../org/apache/poi/hslf/record/Record.java | 2 +- .../poi/hslf/record/RecordContainer.java | 2 +- .../apache/poi/hslf/record/RecordTypes.java | 6 +- .../apache/poi/hslf/record/UserEditAtom.java | 4 +- .../apache/poi/hslf/usermodel/SlideShow.java | 18 +- .../poi/hwpf/model/FIBFieldHandler.java | 6 +- .../org/apache/poi/hwpf/model/FSPATable.java | 4 +- .../poi/hwpf/model/FileInformationBlock.java | 24 +- .../org/apache/poi/hwpf/model/ListTables.java | 10 +- .../hwpf/sprm/ParagraphSprmUncompressor.java | 16 +- .../apache/poi/hslf/TestReWriteSanity.java | 10 +- .../apache/poi/hslf/usermodel/TestBugs.java | 12 +- .../poi/hpsf/basic/TestMetaDataIPI.java | 1348 ++++++++--------- .../apache/poi/hpsf/basic/TestUnicode.java | 8 +- .../org/apache/poi/hpsf/basic/TestWrite.java | 70 +- .../poi/hpsf/basic/TestWriteWellKnown.java | 89 +- .../ExcelFileFormatDocFunctionExtractor.java | 68 +- .../poi/hssf/usermodel/StreamUtility.java | 74 +- .../poi/ss/usermodel/BaseTestDataFormat.java | 2 +- .../org/apache/poi/util/LocalTestNode.java | 4 +- .../org/apache/poi/util/TestArrayUtil.java | 354 ++--- .../org/apache/poi/util/TestBinaryTree.java | 24 +- .../org/apache/poi/util/TestPOILogger.java | 4 +- .../org/apache/poi/util/TestStringUtil.java | 72 +- 90 files changed, 1981 insertions(+), 2192 deletions(-) diff --git a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellEditor.java b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellEditor.java index 8b421ceaf1..e7a2a5ded3 100644 --- a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellEditor.java +++ b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellEditor.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hssf.contrib.view; import java.awt.*; @@ -33,7 +33,6 @@ import org.apache.poi.hssf.util.HSSFColor; * nearly completely consists of overridden methods. * * @author Jason Height - * @since 16 July 2002 */ public class SVTableCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { private static final Color black = getAWTColor(new HSSFColor.BLACK()); @@ -192,7 +191,7 @@ public class SVTableCellEditor extends AbstractCellEditor implements TableCellEd * */ private final Color getAWTColor(int index, Color deflt) { - HSSFColor clr = (HSSFColor)colors.get(new Integer(index)); + HSSFColor clr = (HSSFColor)colors.get(Integer.valueOf(index)); if (clr == null) return deflt; return getAWTColor(clr); } @@ -201,5 +200,4 @@ public class SVTableCellEditor extends AbstractCellEditor implements TableCellEd short[] rgb = clr.getTriplet(); return new Color(rgb[0],rgb[1],rgb[2]); } - } diff --git a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableUtils.java b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableUtils.java index 954dc68e6e..5815ea0a59 100644 --- a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableUtils.java +++ b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableUtils.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.hssf.contrib.view; import java.util.*; @@ -29,7 +29,6 @@ import org.apache.poi.hssf.util.*; * SVTableCell Editor and Renderer helper functions. * * @author Jason Height - * @since 16 July 2002 */ public class SVTableUtils { private final static Hashtable colors = HSSFColor.getIndexHash(); @@ -73,7 +72,7 @@ public class SVTableUtils { * @return The aWTColor value */ public final static Color getAWTColor(int index, Color deflt) { - HSSFColor clr = (HSSFColor) colors.get(new Integer(index)); + HSSFColor clr = (HSSFColor) colors.get(Integer.valueOf(index)); if (clr == null) { return deflt; } @@ -91,5 +90,4 @@ public class SVTableUtils { short[] rgb = clr.getTriplet(); return new Color(rgb[0], rgb[1], rgb[2]); } - } diff --git a/src/contrib/src/org/apache/poi/ss/usermodel/contrib/CellUtil.java b/src/contrib/src/org/apache/poi/ss/usermodel/contrib/CellUtil.java index 337c987d24..d18cd4159b 100644 --- a/src/contrib/src/org/apache/poi/ss/usermodel/contrib/CellUtil.java +++ b/src/contrib/src/org/apache/poi/ss/usermodel/contrib/CellUtil.java @@ -154,7 +154,7 @@ public final class CellUtil { * @see CellStyle for alignment options */ public static void setAlignment(Cell cell, Workbook workbook, short align) { - setCellStyleProperty(cell, workbook, ALIGNMENT, new Short(align)); + setCellStyleProperty(cell, workbook, ALIGNMENT, Short.valueOf(align)); } /** @@ -311,7 +311,7 @@ public final class CellUtil { * @param value property value */ private static void putShort(Map properties, String name, short value) { - properties.put(name, new Short(value)); + properties.put(name, Short.valueOf(value)); } /** @@ -322,7 +322,7 @@ public final class CellUtil { * @param value property value */ private static void putBoolean(Map properties, String name, boolean value) { - properties.put(name, new Boolean(value)); + properties.put(name, Boolean.valueOf(value)); } /** diff --git a/src/contrib/src/org/apache/poi/ss/usermodel/contrib/RegionUtil.java b/src/contrib/src/org/apache/poi/ss/usermodel/contrib/RegionUtil.java index 9654eb6ffd..612d72aac1 100644 --- a/src/contrib/src/org/apache/poi/ss/usermodel/contrib/RegionUtil.java +++ b/src/contrib/src/org/apache/poi/ss/usermodel/contrib/RegionUtil.java @@ -48,7 +48,7 @@ public final class RegionUtil { public CellPropertySetter(Workbook workbook, String propertyName, int value) { _workbook = workbook; _propertyName = propertyName; - _propertyValue = new Short((short) value); + _propertyValue = Short.valueOf((short) value); } diff --git a/src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java b/src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java index 1636e9a8fc..66c1cbdb0e 100644 --- a/src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java +++ b/src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java @@ -45,53 +45,52 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * the summary information and in the document summary information. The * application reads the name of a POI filesystem from the command line and * performs the following actions:

- * + * *
    - * + * *
  • Open the POI filesystem.

  • - * + * *
  • Read the summary information.

  • - * + * *
  • Read and print the "author" property.

  • - * + * *
  • Change the author to "Rainer Klute".

  • - * + * *
  • Read the document summary information.

  • - * + * *
  • Read and print the "category" property.

  • - * + * *
  • Change the category to "POI example".

  • - * + * *
  • Read the custom properties (if available).

  • - * + * *
  • Insert a new custom property.

  • - * + * *
  • Write the custom properties back to the document summary * information.

  • - * + * *
  • Write the summary information to the POI filesystem.

  • - * + * *
  • Write the document summary information to the POI filesystem.

  • - * + * *
  • Write the POI filesystem back to the original file.

  • - * + * * - * + * * @author Rainer Klute klute@rainer-klute.de */ -public class ModifyDocumentSummaryInformation -{ +public class ModifyDocumentSummaryInformation { /** *

    Main method - see class description.

    * * @param args The command-line parameters. - * @throws IOException - * @throws MarkUnsupportedException - * @throws NoPropertySetStreamException - * @throws UnexpectedPropertySetTypeException - * @throws WritingNotSupportedException + * @throws IOException + * @throws MarkUnsupportedException + * @throws NoPropertySetStreamException + * @throws UnexpectedPropertySetTypeException + * @throws WritingNotSupportedException */ public static void main(final String[] args) throws IOException, NoPropertySetStreamException, MarkUnsupportedException, @@ -165,12 +164,12 @@ public class ModifyDocumentSummaryInformation CustomProperties customProperties = dsi.getCustomProperties(); if (customProperties == null) customProperties = new CustomProperties(); - + /* Insert some custom properties into the container. */ customProperties.put("Key 1", "Value 1"); customProperties.put("Schl\u00fcssel 2", "Wert 2"); customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); + customProperties.put("Sample Boolean", Boolean.TRUE); customProperties.put("Sample Date", new Date()); /* Read a custom property. */ @@ -191,6 +190,5 @@ public class ModifyDocumentSummaryInformation OutputStream out = new FileOutputStream(poiFilesystem); poifs.writeFilesystem(out); out.close(); - } - + } } diff --git a/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java b/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java index 57e8c6d32b..c5d21edd23 100644 --- a/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java +++ b/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java @@ -89,7 +89,7 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory { return r; } - Constructor recordConstructor = recordsMap.get(new Short(header.getRecordId())); + Constructor recordConstructor = recordsMap.get(Short.valueOf(header.getRecordId())); EscherRecord escherRecord = null; if (recordConstructor == null) { return new UnknownEscherRecord(); @@ -135,7 +135,7 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory { } catch (NoSuchMethodException e) { throw new RuntimeException(e); } - result.put(new Short(sid), constructor); + result.put(Short.valueOf(sid), constructor); } return result; } diff --git a/src/java/org/apache/poi/ddf/EscherOptRecord.java b/src/java/org/apache/poi/ddf/EscherOptRecord.java index 157375a4ea..916afb985a 100644 --- a/src/java/org/apache/poi/ddf/EscherOptRecord.java +++ b/src/java/org/apache/poi/ddf/EscherOptRecord.java @@ -158,7 +158,7 @@ public class EscherOptRecord { EscherProperty p1 = (EscherProperty) o1; EscherProperty p2 = (EscherProperty) o2; - return new Short( p1.getPropertyNumber() ).compareTo( new Short( p2.getPropertyNumber() ) ); + return Short.valueOf( p1.getPropertyNumber() ).compareTo( Short.valueOf( p2.getPropertyNumber() ) ); } } ); } diff --git a/src/java/org/apache/poi/ddf/EscherProperties.java b/src/java/org/apache/poi/ddf/EscherProperties.java index 458e83d3be..767e92be98 100644 --- a/src/java/org/apache/poi/ddf/EscherProperties.java +++ b/src/java/org/apache/poi/ddf/EscherProperties.java @@ -586,20 +586,20 @@ public final class EscherProperties { } private static void addProp(Map m, int s, String propName) { - m.put(new Short((short) s), new EscherPropertyMetaData(propName)); + m.put(Short.valueOf((short) s), new EscherPropertyMetaData(propName)); } private static void addProp(Map m, int s, String propName, byte type) { - m.put(new Short((short) s), new EscherPropertyMetaData(propName, type)); + m.put(Short.valueOf((short) s), new EscherPropertyMetaData(propName, type)); } public static String getPropertyName(short propertyId) { - EscherPropertyMetaData o = properties.get(new Short(propertyId)); + EscherPropertyMetaData o = properties.get(Short.valueOf(propertyId)); return o == null ? "unknown" : o.getDescription(); } public static byte getPropertyType(short propertyId) { - EscherPropertyMetaData escherPropertyMetaData = properties.get(new Short(propertyId)); + EscherPropertyMetaData escherPropertyMetaData = properties.get(Short.valueOf(propertyId)); return escherPropertyMetaData == null ? 0 : escherPropertyMetaData.getType(); } } diff --git a/src/java/org/apache/poi/hpsf/CustomProperties.java b/src/java/org/apache/poi/hpsf/CustomProperties.java index a4a9a7be09..a3242057ba 100644 --- a/src/java/org/apache/poi/hpsf/CustomProperties.java +++ b/src/java/org/apache/poi/hpsf/CustomProperties.java @@ -33,7 +33,7 @@ import org.apache.poi.hpsf.wellknown.PropertyIDMap; * name is the key that maps to a typed value. This implementation hides * property IDs from the developer and regards the property names as keys to * typed values.

    - * + * *

    While this class provides a simple API to custom properties, it ignores * the fact that not names, but IDs are the real keys to properties. Under the * hood this class maintains a 1:1 relationship between IDs and names. Therefore @@ -41,14 +41,14 @@ import org.apache.poi.hpsf.wellknown.PropertyIDMap; * mapping to the same name or with properties without a name: the result will * contain only a subset of the original properties. If you really need to deal * such property sets, use HPSF's low-level access methods.

    - * + * *

    An application can call the {@link #isPure} method to check whether a * property set parsed by {@link CustomProperties} is still pure (i.e. * unmodified) or whether one or more properties have been dropped.

    - * + * *

    This class is not thread-safe; concurrent access to instances of this * class must be synchronized.

    - * + * * @author Rainer Klute <klute@rainer-klute.de> */ @@ -64,7 +64,7 @@ public class CustomProperties extends HashMap *

    Maps property names to property IDs.

    */ private Map dictionaryNameToID = new HashMap(); - + /** *

    Tells whether this object is pure or not.

    */ @@ -96,7 +96,7 @@ public class CustomProperties extends HashMap ") do not match."); /* Register name and ID in the dictionary. Mapping in both directions is possible. If there is already a */ - final Long idKey = new Long(cp.getID()); + final Long idKey = Long.valueOf(cp.getID()); final Object oldID = dictionaryNameToID.get(name); dictionaryIDToName.remove(oldID); dictionaryNameToID.put(name, idKey); @@ -113,16 +113,16 @@ public class CustomProperties extends HashMap /** *

    Puts a {@link CustomProperty} that has not yet a valid ID into this * map. The method will allocate a suitable ID for the custom property:

    - * + * *
      - * + * *
    • If there is already a property with the same name, take the ID * of that property.

    • - * + * *
    • Otherwise find the highest ID and use its value plus one.

    • - * + * *
    - * + * * @param customProperty * @return If the was already a property with the same name, the * @throws ClassCastException @@ -153,7 +153,7 @@ public class CustomProperties extends HashMap /** *

    Removes a custom property.

    - * @param name The name of the custom property to remove + * @param name The name of the custom property to remove * @return The removed property or null if the specified property was not found. * * @see java.util.HashSet#remove(java.lang.Object) @@ -170,7 +170,7 @@ public class CustomProperties extends HashMap /** *

    Adds a named string property.

    - * + * * @param name The property's name. * @param value The property's value. * @return the property that was stored under the specified name before, or @@ -258,10 +258,10 @@ public class CustomProperties extends HashMap return put(cp); } - + /** *

    Gets a named value from the custom properties.

    - * + * * @param name the name of the value to get * @return the value or null if a value with the specified * name is not found in the custom properties. @@ -292,18 +292,18 @@ public class CustomProperties extends HashMap final CustomProperty cp = new CustomProperty(p, name); return put(cp); } - + /** * Returns a set of all the names of our * custom properties */ public Set keySet() { - return dictionaryNameToID.keySet(); - } + return dictionaryNameToID.keySet(); + } - /** + /** *

    Sets the codepage.

    * * @param codepage the codepage @@ -313,7 +313,7 @@ public class CustomProperties extends HashMap final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_CODEPAGE); p.setType(Variant.VT_I2); - p.setValue(new Integer(codepage)); + p.setValue(Integer.valueOf(codepage)); put(new CustomProperty(p)); } @@ -322,7 +322,7 @@ public class CustomProperties extends HashMap /** *

    Gets the dictionary which contains IDs and names of the named custom * properties. - * + * * @return the dictionary. */ Map getDictionary() @@ -355,7 +355,7 @@ public class CustomProperties extends HashMap *

    Tells whether this {@link CustomProperties} instance is pure or one or * more properties of the underlying low-level property set has been * dropped.

    - * + * * @return true if the {@link CustomProperties} is pure, else * false. */ @@ -373,5 +373,4 @@ public class CustomProperties extends HashMap { this.isPure = isPure; } - } diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index 016870a9e4..bfee086e45 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -567,9 +567,8 @@ public class DocumentSummaryInformation extends SpecialPropertySet /** *

    Gets the custom properties.

    - * + * * @return The custom properties. - * @since 2006-02-09 */ public CustomProperties getCustomProperties() { @@ -589,7 +588,7 @@ public class DocumentSummaryInformation extends SpecialPropertySet { propertyCount++; final CustomProperty cp = new CustomProperty(p, - (String) dictionary.get(new Long(id))); + (String) dictionary.get(Long.valueOf(id))); cps.put(cp.getName(), cp); } } @@ -601,9 +600,8 @@ public class DocumentSummaryInformation extends SpecialPropertySet /** *

    Sets the custom properties.

    - * + * * @param customProperties The custom properties - * @since 2006-02-07 */ public void setCustomProperties(final CustomProperties customProperties) { @@ -650,8 +648,6 @@ public class DocumentSummaryInformation extends SpecialPropertySet /** *

    Removes the custom properties.

    - * - * @since 2006-02-08 */ public void removeCustomProperties() { @@ -674,5 +670,4 @@ public class DocumentSummaryInformation extends SpecialPropertySet { throw new UnsupportedOperationException(msg + " is not yet implemented."); } - } diff --git a/src/java/org/apache/poi/hpsf/MutableSection.java b/src/java/org/apache/poi/hpsf/MutableSection.java index 084896ff64..0e521dc44d 100644 --- a/src/java/org/apache/poi/hpsf/MutableSection.java +++ b/src/java/org/apache/poi/hpsf/MutableSection.java @@ -80,11 +80,11 @@ public class MutableSection extends Section /** - *

    Constructs a MutableSection by doing a deep copy of an - * existing Section. All nested Property + *

    Constructs a MutableSection by doing a deep copy of an + * existing Section. All nested Property * instances, will be their mutable counterparts in the new * MutableSection.

    - * + * * @param s The section set to copy */ public MutableSection(final Section s) @@ -182,7 +182,7 @@ public class MutableSection extends Section */ public void setProperty(final int id, final int value) { - setProperty(id, Variant.VT_I4, new Integer(value)); + setProperty(id, Variant.VT_I4, Integer.valueOf(value)); dirty = true; } @@ -199,7 +199,7 @@ public class MutableSection extends Section */ public void setProperty(final int id, final long value) { - setProperty(id, Variant.VT_I8, new Long(value)); + setProperty(id, Variant.VT_I8, Long.valueOf(value)); dirty = true; } @@ -216,7 +216,7 @@ public class MutableSection extends Section */ public void setProperty(final int id, final boolean value) { - setProperty(id, Variant.VT_BOOL, new Boolean(value)); + setProperty(id, Variant.VT_BOOL, Boolean.valueOf(value)); dirty = true; } @@ -300,7 +300,7 @@ public class MutableSection extends Section */ protected void setPropertyBooleanValue(final int id, final boolean value) { - setProperty(id, Variant.VT_BOOL, new Boolean(value)); + setProperty(id, Variant.VT_BOOL, Boolean.valueOf(value)); } @@ -339,10 +339,10 @@ public class MutableSection extends Section * properties) and the properties themselves.

    * * @return the section's length in bytes. - * @throws WritingNotSupportedException - * @throws IOException + * @throws WritingNotSupportedException + * @throws IOException */ - private int calcSize() throws WritingNotSupportedException, IOException + private int calcSize() throws WritingNotSupportedException, IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); write(out); @@ -357,7 +357,7 @@ public class MutableSection extends Section /** *

    Writes this section into an output stream.

    - * + * *

    Internally this is done by writing into three byte array output * streams: one for the properties, one for the property list and one for * the section as such. The two former are appended to the latter when they @@ -390,7 +390,7 @@ public class MutableSection extends Section * "propertyListStream". */ final ByteArrayOutputStream propertyListStream = new ByteArrayOutputStream(); - + /* Maintain the current position in the list. */ int position = 0; @@ -418,7 +418,7 @@ public class MutableSection extends Section * dictionary is present. In order to cope with this problem we * add the codepage property and set it to Unicode. */ setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(Constants.CP_UNICODE)); + Integer.valueOf(Constants.CP_UNICODE)); codepage = getCodepage(); } @@ -444,7 +444,7 @@ public class MutableSection extends Section { final MutableProperty p = (MutableProperty) i.next(); final long id = p.getID(); - + /* Write the property list entry. */ TypeWriter.writeUIntToStream(propertyListStream, p.getID()); TypeWriter.writeUIntToStream(propertyListStream, position); @@ -472,17 +472,17 @@ public class MutableSection extends Section /* Write the section: */ byte[] pb1 = propertyListStream.toByteArray(); byte[] pb2 = propertyStream.toByteArray(); - + /* Write the section's length: */ TypeWriter.writeToStream(out, LittleEndian.INT_SIZE * 2 + pb1.length + pb2.length); - + /* Write the section's number of properties: */ TypeWriter.writeToStream(out, getPropertyCount()); - + /* Write the property list: */ out.write(pb1); - + /* Write the properties: */ out.write(pb2); @@ -562,7 +562,7 @@ public class MutableSection extends Section *

    Overwrites the super class' method to cope with a redundancy: * the property count is maintained in a separate member variable, but * shouldn't.

    - * + * * @return The number of properties in this section */ public int getPropertyCount() @@ -574,7 +574,7 @@ public class MutableSection extends Section /** *

    Gets this section's properties.

    - * + * * @return this section's properties. */ public Property[] getProperties() @@ -587,7 +587,7 @@ public class MutableSection extends Section /** *

    Gets a property.

    - * + * * @param id The ID of the property to get * @return The property or null if there is no such property */ @@ -611,10 +611,10 @@ public class MutableSection extends Section * method.

    * * @param dictionary The dictionary - * + * * @exception IllegalPropertySetDataException if the dictionary's key and * value types are not correct. - * + * * @see Section#getDictionary() */ public void setDictionary(final Map dictionary) @@ -646,7 +646,7 @@ public class MutableSection extends Section (Integer) getProperty(PropertyIDMap.PID_CODEPAGE); if (codepage == null) setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(Constants.CP_UNICODE)); + Integer.valueOf(Constants.CP_UNICODE)); } else /* Setting the dictionary to null means to remove property 0. @@ -658,7 +658,7 @@ public class MutableSection extends Section /** *

    Sets a property.

    - * + * * @param id The property ID. * @param value The property's value. The value's class must be one of those * supported by HPSF. @@ -707,7 +707,6 @@ public class MutableSection extends Section public void setCodepage(final int codepage) { setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(codepage)); + Integer.valueOf(codepage)); } - } diff --git a/src/java/org/apache/poi/hpsf/Property.java b/src/java/org/apache/poi/hpsf/Property.java index 38ce0d5660..c06a807ef3 100644 --- a/src/java/org/apache/poi/hpsf/Property.java +++ b/src/java/org/apache/poi/hpsf/Property.java @@ -217,7 +217,7 @@ public class Property for (int i = 0; i < nrEntries; i++) { /* The key. */ - final Long id = new Long(LittleEndian.getUInt(src, o)); + final Long id = Long.valueOf(LittleEndian.getUInt(src, o)); o += LittleEndian.INT_SIZE; /* The value (a string). The length is the either the diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index 525450e799..917929a64a 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -278,7 +278,7 @@ public class Section this.offset + ple.offset, ple.length, codepage); if (p.getID() == PropertyIDMap.PID_CODEPAGE) - p = new Property(p.getID(), p.getType(), new Integer(codepage)); + p = new Property(p.getID(), p.getType(), Integer.valueOf(codepage)); properties[i1++] = p; } @@ -450,7 +450,7 @@ public class Section { String s = null; if (dictionary != null) - s = (String) dictionary.get(new Long(pid)); + s = (String) dictionary.get(Long.valueOf(pid)); if (s == null) s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid); if (s == null) diff --git a/src/java/org/apache/poi/hpsf/Variant.java b/src/java/org/apache/poi/hpsf/Variant.java index 358924130a..a37cbf0479 100644 --- a/src/java/org/apache/poi/hpsf/Variant.java +++ b/src/java/org/apache/poi/hpsf/Variant.java @@ -351,32 +351,32 @@ public class Variant /** *

    Denotes a variant type with a length that is unknown to HPSF yet.

    */ - public static final Integer LENGTH_UNKNOWN = new Integer(-2); + public static final Integer LENGTH_UNKNOWN = Integer.valueOf(-2); /** *

    Denotes a variant type with a variable length.

    */ - public static final Integer LENGTH_VARIABLE = new Integer(-1); + public static final Integer LENGTH_VARIABLE = Integer.valueOf(-1); /** *

    Denotes a variant type with a length of 0 bytes.

    */ - public static final Integer LENGTH_0 = new Integer(0); + public static final Integer LENGTH_0 = Integer.valueOf(0); /** *

    Denotes a variant type with a length of 2 bytes.

    */ - public static final Integer LENGTH_2 = new Integer(2); + public static final Integer LENGTH_2 = Integer.valueOf(2); /** *

    Denotes a variant type with a length of 4 bytes.

    */ - public static final Integer LENGTH_4 = new Integer(4); + public static final Integer LENGTH_4 = Integer.valueOf(4); /** *

    Denotes a variant type with a length of 8 bytes.

    */ - public static final Integer LENGTH_8 = new Integer(8); + public static final Integer LENGTH_8 = Integer.valueOf(8); @@ -384,92 +384,92 @@ public class Variant { /* Initialize the number-to-name map: */ Map tm1 = new HashMap(); - tm1.put(new Long(0), "VT_EMPTY"); - tm1.put(new Long(1), "VT_NULL"); - tm1.put(new Long(2), "VT_I2"); - tm1.put(new Long(3), "VT_I4"); - tm1.put(new Long(4), "VT_R4"); - tm1.put(new Long(5), "VT_R8"); - tm1.put(new Long(6), "VT_CY"); - tm1.put(new Long(7), "VT_DATE"); - tm1.put(new Long(8), "VT_BSTR"); - tm1.put(new Long(9), "VT_DISPATCH"); - tm1.put(new Long(10), "VT_ERROR"); - tm1.put(new Long(11), "VT_BOOL"); - tm1.put(new Long(12), "VT_VARIANT"); - tm1.put(new Long(13), "VT_UNKNOWN"); - tm1.put(new Long(14), "VT_DECIMAL"); - tm1.put(new Long(16), "VT_I1"); - tm1.put(new Long(17), "VT_UI1"); - tm1.put(new Long(18), "VT_UI2"); - tm1.put(new Long(19), "VT_UI4"); - tm1.put(new Long(20), "VT_I8"); - tm1.put(new Long(21), "VT_UI8"); - tm1.put(new Long(22), "VT_INT"); - tm1.put(new Long(23), "VT_UINT"); - tm1.put(new Long(24), "VT_VOID"); - tm1.put(new Long(25), "VT_HRESULT"); - tm1.put(new Long(26), "VT_PTR"); - tm1.put(new Long(27), "VT_SAFEARRAY"); - tm1.put(new Long(28), "VT_CARRAY"); - tm1.put(new Long(29), "VT_USERDEFINED"); - tm1.put(new Long(30), "VT_LPSTR"); - tm1.put(new Long(31), "VT_LPWSTR"); - tm1.put(new Long(64), "VT_FILETIME"); - tm1.put(new Long(65), "VT_BLOB"); - tm1.put(new Long(66), "VT_STREAM"); - tm1.put(new Long(67), "VT_STORAGE"); - tm1.put(new Long(68), "VT_STREAMED_OBJECT"); - tm1.put(new Long(69), "VT_STORED_OBJECT"); - tm1.put(new Long(70), "VT_BLOB_OBJECT"); - tm1.put(new Long(71), "VT_CF"); - tm1.put(new Long(72), "VT_CLSID"); + tm1.put(Long.valueOf(0), "VT_EMPTY"); + tm1.put(Long.valueOf(1), "VT_NULL"); + tm1.put(Long.valueOf(2), "VT_I2"); + tm1.put(Long.valueOf(3), "VT_I4"); + tm1.put(Long.valueOf(4), "VT_R4"); + tm1.put(Long.valueOf(5), "VT_R8"); + tm1.put(Long.valueOf(6), "VT_CY"); + tm1.put(Long.valueOf(7), "VT_DATE"); + tm1.put(Long.valueOf(8), "VT_BSTR"); + tm1.put(Long.valueOf(9), "VT_DISPATCH"); + tm1.put(Long.valueOf(10), "VT_ERROR"); + tm1.put(Long.valueOf(11), "VT_BOOL"); + tm1.put(Long.valueOf(12), "VT_VARIANT"); + tm1.put(Long.valueOf(13), "VT_UNKNOWN"); + tm1.put(Long.valueOf(14), "VT_DECIMAL"); + tm1.put(Long.valueOf(16), "VT_I1"); + tm1.put(Long.valueOf(17), "VT_UI1"); + tm1.put(Long.valueOf(18), "VT_UI2"); + tm1.put(Long.valueOf(19), "VT_UI4"); + tm1.put(Long.valueOf(20), "VT_I8"); + tm1.put(Long.valueOf(21), "VT_UI8"); + tm1.put(Long.valueOf(22), "VT_INT"); + tm1.put(Long.valueOf(23), "VT_UINT"); + tm1.put(Long.valueOf(24), "VT_VOID"); + tm1.put(Long.valueOf(25), "VT_HRESULT"); + tm1.put(Long.valueOf(26), "VT_PTR"); + tm1.put(Long.valueOf(27), "VT_SAFEARRAY"); + tm1.put(Long.valueOf(28), "VT_CARRAY"); + tm1.put(Long.valueOf(29), "VT_USERDEFINED"); + tm1.put(Long.valueOf(30), "VT_LPSTR"); + tm1.put(Long.valueOf(31), "VT_LPWSTR"); + tm1.put(Long.valueOf(64), "VT_FILETIME"); + tm1.put(Long.valueOf(65), "VT_BLOB"); + tm1.put(Long.valueOf(66), "VT_STREAM"); + tm1.put(Long.valueOf(67), "VT_STORAGE"); + tm1.put(Long.valueOf(68), "VT_STREAMED_OBJECT"); + tm1.put(Long.valueOf(69), "VT_STORED_OBJECT"); + tm1.put(Long.valueOf(70), "VT_BLOB_OBJECT"); + tm1.put(Long.valueOf(71), "VT_CF"); + tm1.put(Long.valueOf(72), "VT_CLSID"); Map tm2 = new HashMap(tm1.size(), 1.0F); tm2.putAll(tm1); numberToName = Collections.unmodifiableMap(tm2); /* Initialize the number-to-length map: */ tm1.clear(); - tm1.put(new Long(0), LENGTH_0); - tm1.put(new Long(1), LENGTH_UNKNOWN); - tm1.put(new Long(2), LENGTH_2); - tm1.put(new Long(3), LENGTH_4); - tm1.put(new Long(4), LENGTH_4); - tm1.put(new Long(5), LENGTH_8); - tm1.put(new Long(6), LENGTH_UNKNOWN); - tm1.put(new Long(7), LENGTH_UNKNOWN); - tm1.put(new Long(8), LENGTH_UNKNOWN); - tm1.put(new Long(9), LENGTH_UNKNOWN); - tm1.put(new Long(10), LENGTH_UNKNOWN); - tm1.put(new Long(11), LENGTH_UNKNOWN); - tm1.put(new Long(12), LENGTH_UNKNOWN); - tm1.put(new Long(13), LENGTH_UNKNOWN); - tm1.put(new Long(14), LENGTH_UNKNOWN); - tm1.put(new Long(16), LENGTH_UNKNOWN); - tm1.put(new Long(17), LENGTH_UNKNOWN); - tm1.put(new Long(18), LENGTH_UNKNOWN); - tm1.put(new Long(19), LENGTH_UNKNOWN); - tm1.put(new Long(20), LENGTH_UNKNOWN); - tm1.put(new Long(21), LENGTH_UNKNOWN); - tm1.put(new Long(22), LENGTH_UNKNOWN); - tm1.put(new Long(23), LENGTH_UNKNOWN); - tm1.put(new Long(24), LENGTH_UNKNOWN); - tm1.put(new Long(25), LENGTH_UNKNOWN); - tm1.put(new Long(26), LENGTH_UNKNOWN); - tm1.put(new Long(27), LENGTH_UNKNOWN); - tm1.put(new Long(28), LENGTH_UNKNOWN); - tm1.put(new Long(29), LENGTH_UNKNOWN); - tm1.put(new Long(30), LENGTH_VARIABLE); - tm1.put(new Long(31), LENGTH_UNKNOWN); - tm1.put(new Long(64), LENGTH_8); - tm1.put(new Long(65), LENGTH_UNKNOWN); - tm1.put(new Long(66), LENGTH_UNKNOWN); - tm1.put(new Long(67), LENGTH_UNKNOWN); - tm1.put(new Long(68), LENGTH_UNKNOWN); - tm1.put(new Long(69), LENGTH_UNKNOWN); - tm1.put(new Long(70), LENGTH_UNKNOWN); - tm1.put(new Long(71), LENGTH_UNKNOWN); - tm1.put(new Long(72), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(0), LENGTH_0); + tm1.put(Long.valueOf(1), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(2), LENGTH_2); + tm1.put(Long.valueOf(3), LENGTH_4); + tm1.put(Long.valueOf(4), LENGTH_4); + tm1.put(Long.valueOf(5), LENGTH_8); + tm1.put(Long.valueOf(6), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(7), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(8), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(9), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(10), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(11), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(12), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(13), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(14), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(16), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(17), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(18), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(19), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(20), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(21), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(22), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(23), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(24), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(25), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(26), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(27), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(28), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(29), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(30), LENGTH_VARIABLE); + tm1.put(Long.valueOf(31), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(64), LENGTH_8); + tm1.put(Long.valueOf(65), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(66), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(67), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(68), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(69), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(70), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(71), LENGTH_UNKNOWN); + tm1.put(Long.valueOf(72), LENGTH_UNKNOWN); tm2 = new HashMap(tm1.size(), 1.0F); tm2.putAll(tm1); numberToLength = Collections.unmodifiableMap(tm2); @@ -486,7 +486,7 @@ public class Variant */ public static String getVariantName(final long variantType) { - final String name = (String) numberToName.get(new Long(variantType)); + final String name = (String) numberToName.get(Long.valueOf(variantType)); return name != null ? name : "unknown variant type"; } @@ -501,7 +501,7 @@ public class Variant */ public static int getVariantLength(final long variantType) { - final Long key = new Long((int) variantType); + final Long key = Long.valueOf((int) variantType); final Long length = (Long) numberToLength.get(key); if (length == null) return -2; diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index e96e6739df..c01b3c57c5 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -29,10 +29,10 @@ import org.apache.poi.util.LittleEndianConsts; /** *

    Supports reading and writing of variant data.

    - * + * *

    FIXME (3): Reading and writing should be made more * uniform than it is now. The following items should be resolved: - * + * *

      * *
    • Reading requires a length parameter that is 4 byte greater than the @@ -68,7 +68,7 @@ public class VariantSupport extends Variant * on or off.

      * * @return true if logging is turned on, else - * false. + * false. */ public static boolean isLogUnsupportedTypes() { @@ -97,7 +97,7 @@ public class VariantSupport extends Variant { if (unsupportedMessage == null) unsupportedMessage = new LinkedList(); - Long vt = new Long(ex.getVariantType()); + Long vt = Long.valueOf(ex.getVariantType()); if (!unsupportedMessage.contains(vt)) { System.err.println(ex.getMessage()); @@ -121,7 +121,7 @@ public class VariantSupport extends Variant *

      Checks whether HPSF supports the specified variant type. Unsupported * types should be implemented included in the {@link #SUPPORTED_TYPES} * array.

      - * + * * @see Variant * @param variantType the variant type to check * @return true if HPFS supports this type, else @@ -139,7 +139,7 @@ public class VariantSupport extends Variant /** *

      Reads a variant type from a byte array.

      - * + * * @param src The byte array * @param offset The offset in the byte array where the variant starts * @param length The length of the variant including the variant type field @@ -182,7 +182,7 @@ public class VariantSupport extends Variant * Read a short. In Java it is represented as an * Integer object. */ - value = new Integer(LittleEndian.getShort(src, o1)); + value = Integer.valueOf(LittleEndian.getShort(src, o1)); break; } case Variant.VT_I4: @@ -191,7 +191,7 @@ public class VariantSupport extends Variant * Read a word. In Java it is represented as an * Integer object. */ - value = new Integer(LittleEndian.getInt(src, o1)); + value = Integer.valueOf(LittleEndian.getInt(src, o1)); break; } case Variant.VT_I8: @@ -200,7 +200,7 @@ public class VariantSupport extends Variant * Read a double word. In Java it is represented as a * Long object. */ - value = new Long(LittleEndian.getLong(src, o1)); + value = Long.valueOf(LittleEndian.getLong(src, o1)); break; } case Variant.VT_R8: @@ -279,7 +279,7 @@ public class VariantSupport extends Variant * while the current implementation calculates it in the Section constructor. * Test files in Bugzilla 42726 and 45583 clearly show that this approach does not always work. * The workaround below attempts to gracefully handle such cases instead of throwing exceptions. - * + * * August 20, 2009 */ l1 = LittleEndian.getInt(src, o1); o1 += LittleEndian.INT_SIZE; @@ -318,16 +318,16 @@ public class VariantSupport extends Variant /** - *

      Turns a codepage number into the equivalent character encoding's + *

      Turns a codepage number into the equivalent character encoding's * name.

      * * @param codepage The codepage number - * - * @return The character encoding's name. If the codepage number is 65001, + * + * @return The character encoding's name. If the codepage number is 65001, * the encoding name is "UTF-8". All other positive numbers are mapped to - * "cp" followed by the number, e.g. if the codepage number is 1252 the + * "cp" followed by the number, e.g. if the codepage number is 1252 the * returned character encoding name will be "cp1252". - * + * * @exception UnsupportedEncodingException if the specified codepage is * less than zero. */ @@ -500,7 +500,7 @@ public class VariantSupport extends Variant } case Variant.VT_LPWSTR: { - final int nrOfChars = ((String) value).length() + 1; + final int nrOfChars = ((String) value).length() + 1; length += TypeWriter.writeUIntToStream(out, nrOfChars); char[] s = Util.pad4((String) value); for (int i = 0; i < s.length; i++) @@ -546,7 +546,7 @@ public class VariantSupport extends Variant + value.getClass().toString() + ", " + value.toString()); } - length += TypeWriter.writeToStream(out, + length += TypeWriter.writeToStream(out, ((Integer) value).intValue()); break; } @@ -558,7 +558,7 @@ public class VariantSupport extends Variant } case Variant.VT_R8: { - length += TypeWriter.writeToStream(out, + length += TypeWriter.writeToStream(out, ((Double) value).doubleValue()); break; } @@ -579,7 +579,7 @@ public class VariantSupport extends Variant * is a byte array we can write it nevertheless. */ if (value instanceof byte[]) { - final byte[] b = (byte[]) value; + final byte[] b = (byte[]) value; out.write(b); length = b.length; writeUnsupportedTypeMessage @@ -593,5 +593,4 @@ public class VariantSupport extends Variant return length; } - } diff --git a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java index 9c8fe488b9..4eef8c4b02 100644 --- a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java +++ b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java @@ -102,7 +102,7 @@ public class PropertyIDMap extends HashMap { /**

      ID of the property that denotes whether read/write access to the * document is allowed or whether is should be opened as read-only. It can * have the following values:

      - * + * * * * @@ -133,7 +133,7 @@ public class PropertyIDMap extends HashMap { * section of the Document Summary Information property set. */ - /** + /** *

      The entry is a dictionary.

      */ public static final int PID_DICTIONARY = 0; @@ -143,61 +143,61 @@ public class PropertyIDMap extends HashMap { */ public static final int PID_CODEPAGE = 1; - /** + /** *

      The entry is a string denoting the category the file belongs * to, e.g. review, memo, etc. This is useful to find documents of * same type.

      */ public static final int PID_CATEGORY = 2; - /** + /** *

      Target format for power point presentation, e.g. 35mm, * printer, video etc.

      */ public static final int PID_PRESFORMAT = 3; - /** + /** *

      Number of bytes.

      */ public static final int PID_BYTECOUNT = 4; - /** + /** *

      Number of lines.

      */ public static final int PID_LINECOUNT = 5; - /** + /** *

      Number of paragraphs.

      */ public static final int PID_PARCOUNT = 6; - /** + /** *

      Number of slides in a power point presentation.

      */ public static final int PID_SLIDECOUNT = 7; - /** + /** *

      Number of slides with notes.

      */ public static final int PID_NOTECOUNT = 8; - /** + /** *

      Number of hidden slides.

      */ public static final int PID_HIDDENCOUNT = 9; - /** + /** *

      Number of multimedia clips, e.g. sound or video.

      */ public static final int PID_MMCLIPCOUNT = 10; - /** + /** *

      This entry is set to -1 when scaling of the thumbnail is * desired. Otherwise the thumbnail should be cropped.

      */ public static final int PID_SCALE = 11; - /** + /** *

      This entry denotes an internally used property. It is a * vector of variants consisting of pairs of a string (VT_LPSTR) * and a number (VT_I4). The string is a heading name, and the @@ -206,29 +206,29 @@ public class PropertyIDMap extends HashMap { */ public static final int PID_HEADINGPAIR = 12; - /** + /** *

      This entry contains the names of document parts (word: names * of the documents in the master document, excel: sheet names, * power point: slide titles, binder: document names).

      */ public static final int PID_DOCPARTS = 13; - /** + /** *

      This entry contains the name of the project manager.

      */ public static final int PID_MANAGER = 14; - /** + /** *

      This entry contains the company name.

      */ public static final int PID_COMPANY = 15; - /** + /** *

      If this entry is -1 the links are dirty and should be * re-evaluated.

      */ public static final int PID_LINKSDIRTY = 16; - + /** *

      The highest well-known property ID. Applications are free to use higher values for custom purposes.

      */ @@ -254,7 +254,7 @@ public class PropertyIDMap extends HashMap { /** *

      Creates a {@link PropertyIDMap}.

      - * + * * @param initialCapacity The initial capacity as defined for * {@link HashMap} * @param loadFactor The load factor as defined for {@link HashMap} @@ -268,7 +268,7 @@ public class PropertyIDMap extends HashMap { /** *

      Creates a {@link PropertyIDMap} backed by another map.

      - * + * * @param map The instance to be created is backed by this map. */ public PropertyIDMap(final Map map) @@ -291,7 +291,7 @@ public class PropertyIDMap extends HashMap { */ public Object put(final long id, final String idString) { - return put(new Long(id), idString); + return put(Long.valueOf(id), idString); } @@ -305,7 +305,7 @@ public class PropertyIDMap extends HashMap { */ public Object get(final long id) { - return get(new Long(id)); + return get(Long.valueOf(id)); } @@ -392,5 +392,4 @@ public class PropertyIDMap extends HashMap { System.out.println("s1: " + s1); System.out.println("s2: " + s2); } - } diff --git a/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java b/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java index 70e75a57e3..5e21bdf58e 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java @@ -73,7 +73,7 @@ public class FormatTrackingHSSFListener implements HSSFListener { public void processRecordInternally(Record record) { if (record instanceof FormatRecord) { FormatRecord fr = (FormatRecord) record; - _customFormatRecords.put(new Integer(fr.getIndexCode()), fr); + _customFormatRecords.put(Integer.valueOf(fr.getIndexCode()), fr); } if (record instanceof ExtendedFormatRecord) { ExtendedFormatRecord xr = (ExtendedFormatRecord) record; @@ -117,7 +117,7 @@ public class FormatTrackingHSSFListener implements HSSFListener { public String getFormatString(int formatIndex) { String format = null; if (formatIndex >= HSSFDataFormat.getNumberOfBuiltinBuiltinFormats()) { - FormatRecord tfr = _customFormatRecords.get(new Integer(formatIndex)); + FormatRecord tfr = _customFormatRecords.get(Integer.valueOf(formatIndex)); if (tfr == null) { System.err.println("Requested format at index " + formatIndex + ", but it wasn't found"); diff --git a/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java b/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java index e297e59bc5..af23a2c495 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.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 @@ -16,12 +15,12 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hssf.eventusermodel; import java.util.HashMap; import java.util.List; import java.util.ArrayList; +import java.util.Map; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RecordFactory; @@ -37,71 +36,54 @@ import org.apache.poi.hssf.record.RecordFactory; * @author Andrew C. Oliver (acoliver at apache dot org) * @author Carey Sublette (careysub@earthling.net) */ +public class HSSFRequest { + private final Map> _records; -public class HSSFRequest -{ - private HashMap records; - - /** Creates a new instance of HSSFRequest */ - - public HSSFRequest() - { - records = - new HashMap(50); // most folks won't listen for too many of these - } - - /** - * add an event listener for a particular record type. The trick is you have to know - * what the records are for or just start with our examples and build on them. Alternatively, - * you CAN call addListenerForAllRecords and you'll recieve ALL record events in one listener, - * but if you like to squeeze every last byte of efficiency out of life you my not like this. - * (its sure as heck what I plan to do) - * - * @see #addListenerForAllRecords(HSSFListener) - * - * @param lsnr for the event - * @param sid identifier for the record type this is the .sid static member on the individual records - * for example req.addListener(myListener, BOFRecord.sid) - */ + /** Creates a new instance of HSSFRequest */ + public HSSFRequest() { + _records = new HashMap>(50); // most folks won't listen for too many of these + } - public void addListener(HSSFListener lsnr, short sid) - { - List list = null; - Object obj = records.get(new Short(sid)); - - if (obj != null) - { - list = ( List ) obj; - } - else - { - list = new ArrayList( - 1); // probably most people will use one listener - list.add(lsnr); - records.put(new Short(sid), list); - } - } + /** + * add an event listener for a particular record type. The trick is you have to know + * what the records are for or just start with our examples and build on them. Alternatively, + * you CAN call addListenerForAllRecords and you'll receive ALL record events in one listener, + * but if you like to squeeze every last byte of efficiency out of life you my not like this. + * (its sure as heck what I plan to do) + * + * @see #addListenerForAllRecords(HSSFListener) + * + * @param lsnr for the event + * @param sid identifier for the record type this is the .sid static member on the individual records + * for example req.addListener(myListener, BOFRecord.sid) + */ + public void addListener(HSSFListener lsnr, short sid) { + List list = _records.get(Short.valueOf(sid)); - /** - * This is the equivilent of calling addListener(myListener, sid) for EVERY - * record in the org.apache.poi.hssf.record package. This is for lazy - * people like me. You can call this more than once with more than one listener, but - * that seems like a bad thing to do from a practice-perspective unless you have a - * compelling reason to do so (like maybe you send the event two places or log it or - * something?). - * - * @param lsnr a single listener to associate with ALL records - */ + if (list == null) { + list = new ArrayList(1); // probably most people will use one listener + _records.put(Short.valueOf(sid), list); + } + list.add(lsnr); + } - public void addListenerForAllRecords(HSSFListener lsnr) - { - short[] rectypes = RecordFactory.getAllKnownRecordSIDs(); + /** + * This is the equivalent of calling addListener(myListener, sid) for EVERY + * record in the org.apache.poi.hssf.record package. This is for lazy + * people like me. You can call this more than once with more than one listener, but + * that seems like a bad thing to do from a practice-perspective unless you have a + * compelling reason to do so (like maybe you send the event two places or log it or + * something?). + * + * @param lsnr a single listener to associate with ALL records + */ + public void addListenerForAllRecords(HSSFListener lsnr) { + short[] rectypes = RecordFactory.getAllKnownRecordSIDs(); - for (int k = 0; k < rectypes.length; k++) - { - addListener(lsnr, rectypes[ k ]); - } - } + for (int k = 0; k < rectypes.length; k++) { + addListener(lsnr, rectypes[k]); + } + } /** * Called by HSSFEventFactory, passes the Record to each listener associated with @@ -112,32 +94,26 @@ public class HSSFRequest * @return numeric user-specified result code. If zero continue processing. * @throws HSSFUserException User exception condition */ - - protected short processRecord(Record rec) throws HSSFUserException - { - Object obj = records.get(new Short(rec.getSid())); - short userCode = 0; - - if (obj != null) - { - List listeners = ( List ) obj; - - for (int k = 0; k < listeners.size(); k++) - { - Object listenObj = listeners.get(k); - if (listenObj instanceof AbortableHSSFListener) - { - AbortableHSSFListener listener = ( AbortableHSSFListener ) listenObj; - userCode = listener.abortableProcessRecord(rec); - if (userCode!=0) break; - } - else - { - HSSFListener listener = ( HSSFListener ) listenObj; + protected short processRecord(Record rec) throws HSSFUserException { + Object obj = _records.get(Short.valueOf(rec.getSid())); + short userCode = 0; + + if (obj != null) { + List listeners = (List) obj; + + for (int k = 0; k < listeners.size(); k++) { + Object listenObj = listeners.get(k); + if (listenObj instanceof AbortableHSSFListener) { + AbortableHSSFListener listener = (AbortableHSSFListener) listenObj; + userCode = listener.abortableProcessRecord(rec); + if (userCode != 0) + break; + } else { + HSSFListener listener = (HSSFListener) listenObj; listener.processRecord(rec); } - } - } - return userCode; - } + } + } + return userCode; + } } diff --git a/src/java/org/apache/poi/hssf/model/DrawingManager.java b/src/java/org/apache/poi/hssf/model/DrawingManager.java index f2b5c5b6e4..8229b40a5b 100644 --- a/src/java/org/apache/poi/hssf/model/DrawingManager.java +++ b/src/java/org/apache/poi/hssf/model/DrawingManager.java @@ -48,7 +48,7 @@ public class DrawingManager dg.setLastMSOSPID( -1 ); dgg.addCluster( dgId, 0 ); dgg.setDrawingsSaved( dgg.getDrawingsSaved() + 1 ); - dgMap.put( new Short( dgId ), dg ); + dgMap.put( Short.valueOf( dgId ), dg ); return dg; } @@ -60,7 +60,7 @@ public class DrawingManager public int allocateShapeId(short drawingGroupId) { // Get the last shape id for this drawing group. - EscherDgRecord dg = (EscherDgRecord) dgMap.get(new Short(drawingGroupId)); + EscherDgRecord dg = (EscherDgRecord) dgMap.get(Short.valueOf(drawingGroupId)); int lastShapeId = dg.getLastMSOSPID(); diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 916272ecaf..df8d616d89 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -1031,7 +1031,7 @@ public final class Sheet implements Model { public void setColumnWidth(int column, int width) { if(width > 255*256) throw new IllegalArgumentException("The maximum column width for an individual cell is 255 characters."); - setColumn(column, null, new Integer(width), null, null, null); + setColumn(column, null, Integer.valueOf(width), null, null, null); } /** @@ -1059,7 +1059,7 @@ public final class Sheet implements Model { setColumn( column, null, null, null, Boolean.valueOf(hidden), null); } public void setDefaultColumnStyle(int column, int styleIndex) { - setColumn(column, new Short((short)styleIndex), null, null, null, null); + setColumn(column, Short.valueOf((short)styleIndex), null, null, null, null); } private void setColumn(int column, Short xfStyle, Integer width, Integer level, Boolean hidden, Boolean collapsed) { diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java index 91cbaf4c6a..812f719e8d 100644 --- a/src/java/org/apache/poi/hssf/model/Workbook.java +++ b/src/java/org/apache/poi/hssf/model/Workbook.java @@ -180,7 +180,7 @@ public final class Workbook implements Model { public static Workbook createWorkbook(List recs) { if (log.check( POILogger.DEBUG )) log.log(DEBUG, "Workbook (readfile) created with reclen=", - new Integer(recs.size())); + Integer.valueOf(recs.size())); Workbook retval = new Workbook(); List records = new ArrayList(recs.size() / 3); retval.records.setRecords(records); @@ -517,8 +517,8 @@ public final class Workbook implements Model { public void setSheetBof(int sheetIndex, int pos) { if (log.check( POILogger.DEBUG )) - log.log(DEBUG, "setting bof for sheetnum =", new Integer(sheetIndex), - " at pos=", new Integer(pos)); + log.log(DEBUG, "setting bof for sheetnum =", Integer.valueOf(sheetIndex), + " at pos=", Integer.valueOf(pos)); checkSheets(sheetIndex); getBoundSheetRec(sheetIndex) .setPositionOfBof(pos); @@ -757,7 +757,7 @@ public final class Workbook implements Model { public int getNumSheets() { if (log.check( POILogger.DEBUG )) - log.log(DEBUG, "getNumSheets=", new Integer(boundsheets.size())); + log.log(DEBUG, "getNumSheets=", Integer.valueOf(boundsheets.size())); return boundsheets.size(); } @@ -769,7 +769,7 @@ public final class Workbook implements Model { public int getNumExFormats() { if (log.check( POILogger.DEBUG )) - log.log(DEBUG, "getXF=", new Integer(numxfs)); + log.log(DEBUG, "getXF=", Integer.valueOf(numxfs)); return numxfs; } @@ -903,7 +903,7 @@ public final class Workbook implements Model { UnicodeString retval = sst.getString(str); if (log.check( POILogger.DEBUG )) - log.log(DEBUG, "Returning SST for index=", new Integer(str), + log.log(DEBUG, "Returning SST for index=", Integer.valueOf(str), " String= ", retval); return retval; } diff --git a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java index c14b9fe0f1..cebae81282 100644 --- a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java @@ -6,7 +6,7 @@ (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -48,15 +48,15 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { private Ptg field_2_refPtg; /** for when the 'formula' doesn't parse properly */ private byte[] field_2_unknownFormulaData; - /** note- this byte is not present in the encoding if the string length is zero */ + /** note- this byte is not present in the encoding if the string length is zero */ private boolean field_3_unicode_flag; // Flags whether the string is Unicode. private String field_4_ole_classname; // Classname of the embedded OLE document (e.g. Word.Document.8) /** Formulas often have a single non-zero trailing byte. * This is in a similar position to he pre-streamId padding - * It is unknown if the value is important (it seems to mirror a value a few bytes earlier) + * It is unknown if the value is important (it seems to mirror a value a few bytes earlier) * */ private Byte field_4_unknownByte; - private Integer field_5_stream_id; // ID of the OLE stream containing the actual data. + private Integer field_5_stream_id; // ID of the OLE stream containing the actual data. private byte[] field_6_unknown; @@ -131,7 +131,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { int b = in.readByte(); remaining -= LittleEndian.BYTE_SIZE; if (field_2_refPtg != null && field_4_ole_classname == null) { - field_4_unknownByte = new Byte((byte)b); + field_4_unknownByte = Byte.valueOf((byte)b); } } int nUnexpectedPadding = remaining - dataLenAfterFormula; @@ -144,7 +144,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { // Fetch the stream ID if (dataLenAfterFormula >= 4) { - field_5_stream_id = new Integer(in.readInt()); + field_5_stream_id = Integer.valueOf(in.readInt()); remaining -= LittleEndian.INT_SIZE; } else { field_5_stream_id = null; @@ -158,7 +158,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { switch(ptgSid) { case AreaPtg.sid: return new AreaPtg(in); case Area3DPtg.sid: return new Area3DPtg(in); - case RefPtg.sid: return new RefPtg(in); + case RefPtg.sid: return new RefPtg(in); case Ref3DPtg.sid: return new Ref3DPtg(in); } return null; @@ -175,11 +175,11 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { in.readFully(result); return result; } - + private int getStreamIDOffset(int formulaSize) { int result = 2 + 4; // formulaSize + f2unknown_int result += formulaSize; - + int stringLen; if (field_4_ole_classname == null) { // don't write 0x03, stringLen, flag, text @@ -198,16 +198,16 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { } // pad to next 2 byte boundary if ((result % 2) != 0) { - result ++; + result ++; } return result; } - + private int getDataSize(int idOffset) { int result = 2 + idOffset; // 2 for idOffset short field itself if (field_5_stream_id != null) { - result += 4; + result += 4; } return result + field_6_unknown.length; } @@ -222,7 +222,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { int formulaSize = field_2_refPtg == null ? field_2_unknownFormulaData.length : field_2_refPtg.getSize(); int idOffset = getStreamIDOffset(formulaSize); int dataSize = getDataSize(idOffset); - + out.writeShort(sid); out.writeShort(dataSize); @@ -238,7 +238,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { } else { field_2_refPtg.write(out); } - pos += formulaSize; + pos += formulaSize; int stringLen; if (field_4_ole_classname == null) { @@ -251,16 +251,16 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { out.writeShort(stringLen); pos+=2; if (stringLen > 0) { - out.writeByte(field_3_unicode_flag ? 0x01 : 0x00); - pos+=1; - - if (field_3_unicode_flag) { - StringUtil.putUnicodeLE(field_4_ole_classname, out); - pos += stringLen * 2; - } else { - StringUtil.putCompressedUnicode(field_4_ole_classname, out); - pos += stringLen; - } + out.writeByte(field_3_unicode_flag ? 0x01 : 0x00); + pos+=1; + + if (field_3_unicode_flag) { + StringUtil.putUnicodeLE(field_4_ole_classname, out); + pos += stringLen * 2; + } else { + StringUtil.putCompressedUnicode(field_4_ole_classname, out); + pos += stringLen; + } } } @@ -272,12 +272,12 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { case 0: break; default: - throw new IllegalStateException("Bad padding calculation (" + idOffset + ", " + pos + ")"); + throw new IllegalStateException("Bad padding calculation (" + idOffset + ", " + pos + ")"); } if (field_5_stream_id != null) { out.writeInt(field_5_stream_id.intValue()); - pos += 4; + pos += 4; } out.write(field_6_unknown); } diff --git a/src/java/org/apache/poi/hssf/record/EscherAggregate.java b/src/java/org/apache/poi/hssf/record/EscherAggregate.java index 4b94f281af..811daa5738 100644 --- a/src/java/org/apache/poi/hssf/record/EscherAggregate.java +++ b/src/java/org/apache/poi/hssf/record/EscherAggregate.java @@ -434,7 +434,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord { { if ( recordId == EscherClientDataRecord.RECORD_ID || recordId == EscherTextboxRecord.RECORD_ID ) { - spEndingOffsets.add( new Integer( offset ) ); + spEndingOffsets.add( Integer.valueOf( offset ) ); shapes.add( record ); } } diff --git a/src/java/org/apache/poi/hssf/record/NoteRecord.java b/src/java/org/apache/poi/hssf/record/NoteRecord.java index f5c8d6acd9..35f81ebfe7 100644 --- a/src/java/org/apache/poi/hssf/record/NoteRecord.java +++ b/src/java/org/apache/poi/hssf/record/NoteRecord.java @@ -40,7 +40,7 @@ public final class NoteRecord extends StandardRecord { */ public final static short NOTE_VISIBLE = 0x2; - private static final Byte DEFAULT_PADDING = new Byte((byte)0); + private static final Byte DEFAULT_PADDING = Byte.valueOf((byte)0); private int field_1_row; private int field_2_col; @@ -50,9 +50,9 @@ public final class NoteRecord extends StandardRecord { private String field_6_author; /** * Saves padding byte value to reduce delta during round-trip serialization.
      - * + * * The documentation is not clear about how padding should work. In any case - * Excel(2007) does something different. + * Excel(2007) does something different. */ private Byte field_7_padding; @@ -89,7 +89,7 @@ public final class NoteRecord extends StandardRecord { field_6_author = StringUtil.readCompressedUnicode(in, length); } if (in.available() == 1) { - field_7_padding = new Byte(in.readByte()); + field_7_padding = Byte.valueOf(in.readByte()); } } diff --git a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java index d0f6e2af0b..fe182d05c0 100644 --- a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java +++ b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java @@ -90,7 +90,7 @@ public abstract class PageBreakRecord extends StandardRecord { for(int k = 0; k < nBreaks; k++) { Break br = new Break(in); _breaks.add(br); - _breakMap.put(new Integer(br.main), br); + _breakMap.put(Integer.valueOf(br.main), br); } } @@ -160,7 +160,7 @@ public abstract class PageBreakRecord extends StandardRecord { */ public void addBreak(int main, int subFrom, int subTo) { - Integer key = new Integer(main); + Integer key = Integer.valueOf(main); Break region = _breakMap.get(key); if(region == null) { region = new Break(main, subFrom, subTo); @@ -178,7 +178,7 @@ public abstract class PageBreakRecord extends StandardRecord { * @param main (zero-based) */ public final void removeBreak(int main) { - Integer rowKey = new Integer(main); + Integer rowKey = Integer.valueOf(main); Break region = _breakMap.get(rowKey); _breaks.remove(region); _breakMap.remove(rowKey); @@ -190,7 +190,7 @@ public abstract class PageBreakRecord extends StandardRecord { * @return The Break or null if no break exists at the row/col specified. */ public final Break getBreak(int main) { - Integer rowKey = new Integer(main); + Integer rowKey = Integer.valueOf(main); return _breakMap.get(rowKey); } diff --git a/src/java/org/apache/poi/hssf/record/RecordFactory.java b/src/java/org/apache/poi/hssf/record/RecordFactory.java index 904ed17e4a..3d200e7ef4 100644 --- a/src/java/org/apache/poi/hssf/record/RecordFactory.java +++ b/src/java/org/apache/poi/hssf/record/RecordFactory.java @@ -227,7 +227,7 @@ public final class RecordFactory { * null if the specified record is not interpreted by POI. */ public static Class getRecordClass(int sid) { - I_RecordCreator rc = _recordCreatorsById.get(new Integer(sid)); + I_RecordCreator rc = _recordCreatorsById.get(Integer.valueOf(sid)); if (rc == null) { return null; } @@ -254,7 +254,7 @@ public final class RecordFactory { } public static Record createSingleRecord(RecordInputStream in) { - I_RecordCreator constructor = _recordCreatorsById.get(new Integer(in.getSid())); + I_RecordCreator constructor = _recordCreatorsById.get(Integer.valueOf(in.getSid())); if (constructor == null) { return new UnknownRecord(in); @@ -346,7 +346,7 @@ public final class RecordFactory { throw new RecordFormatException( "Unable to determine record types"); } - Integer key = new Integer(sid); + Integer key = Integer.valueOf(sid); if (result.containsKey(key)) { Class prevClass = result.get(key).getRecordClass(); throw new RuntimeException("duplicate record sid 0x" + Integer.toHexString(sid).toUpperCase() @@ -354,7 +354,7 @@ public final class RecordFactory { } result.put(key, new ReflectionRecordCreator(constructor)); } -// result.put(new Integer(0x0406), result.get(new Integer(0x06))); +// result.put(Integer.valueOf(0x0406), result.get(Integer.valueOf(0x06))); return result; } diff --git a/src/java/org/apache/poi/hssf/record/SubRecord.java b/src/java/org/apache/poi/hssf/record/SubRecord.java index 689e4fcd55..108a847dbd 100644 --- a/src/java/org/apache/poi/hssf/record/SubRecord.java +++ b/src/java/org/apache/poi/hssf/record/SubRecord.java @@ -143,7 +143,7 @@ public abstract class SubRecord { _linkPtg = readRefPtg(buf); switch (linkSize - formulaSize - 6) { case 1: - _unknownByte6 = new Byte(in.readByte()); + _unknownByte6 = Byte.valueOf(in.readByte()); break; case 0: _unknownByte6 = null; diff --git a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java index bd3e008892..06fb3e4319 100644 --- a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java @@ -30,7 +30,7 @@ import org.apache.poi.util.HexDump; * followed by two or more continue records unless there is no actual text. The * first continue records contain the text data and the last continue record * contains the formatting runs.

      - * + * * @author Glen Stampoultzis (glens at apache.org) */ public final class TextObjectRecord extends ContinuableRecord { @@ -68,7 +68,7 @@ public final class TextObjectRecord extends ContinuableRecord { /* * Note - the next three fields are very similar to those on * EmbededObjectRefSubRecord(ftPictFmla 0x0009) - * + * * some observed values for the 4 bytes preceding the formula: C0 5E 86 03 * C0 11 AC 02 80 F1 8A 03 D4 F0 8A 03 */ @@ -76,7 +76,7 @@ public final class TextObjectRecord extends ContinuableRecord { /** expect tRef, tRef3D, tArea, tArea3D or tName */ private Ptg _linkRefPtg; /** - * Not clear if needed . Excel seems to be OK if this byte is not present. + * Not clear if needed . Excel seems to be OK if this byte is not present. * Value is often the same as the earlier firstColumn byte. */ private Byte _unknownPostFormulaByte; @@ -108,7 +108,7 @@ public final class TextObjectRecord extends ContinuableRecord { } _linkRefPtg = ptgs[0]; if (in.remaining() > 0) { - _unknownPostFormulaByte = new Byte(in.readByte()); + _unknownPostFormulaByte = Byte.valueOf(in.readByte()); } else { _unknownPostFormulaByte = null; } @@ -161,7 +161,7 @@ public final class TextObjectRecord extends ContinuableRecord { } private void serializeTXORecord(ContinuableRecordOutput out) { - + out.writeShort(field_1_options); out.writeShort(field_2_textOrientation); out.writeShort(field_3_reserved4); @@ -170,7 +170,7 @@ public final class TextObjectRecord extends ContinuableRecord { out.writeShort(_text.length()); out.writeShort(getFormattingDataLength()); out.writeInt(field_8_reserved7); - + if (_linkRefPtg != null) { int formulaSize = _linkRefPtg.getSize(); out.writeShort(formulaSize); @@ -194,12 +194,12 @@ public final class TextObjectRecord extends ContinuableRecord { serializeTXORecord(out); if (_text.getString().length() > 0) { serializeTrailingRecords(out); - } + } } private int getFormattingDataLength() { if (_text.length() < 1) { - // important - no formatting data if text is empty + // important - no formatting data if text is empty return 0; } return (_text.numFormattingRuns() + 1) * FORMAT_RUN_ENCODED_SIZE; @@ -262,7 +262,7 @@ public final class TextObjectRecord extends ContinuableRecord { /** * Get the text orientation field for the TextObjectBase record. - * + * * @return One of TEXT_ORIENTATION_NONE TEXT_ORIENTATION_TOP_TO_BOTTOM * TEXT_ORIENTATION_ROT_RIGHT TEXT_ORIENTATION_ROT_LEFT */ @@ -272,7 +272,7 @@ public final class TextObjectRecord extends ContinuableRecord { /** * Set the text orientation field for the TextObjectBase record. - * + * * @param textOrientation * One of TEXT_ORIENTATION_NONE TEXT_ORIENTATION_TOP_TO_BOTTOM * TEXT_ORIENTATION_ROT_RIGHT TEXT_ORIENTATION_ROT_LEFT @@ -288,7 +288,7 @@ public final class TextObjectRecord extends ContinuableRecord { public void setStr(HSSFRichTextString str) { _text = str; } - + public Ptg getLinkRefPtg() { return _linkRefPtg; } diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java index d1dfe30c50..1b356fb3e5 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java @@ -30,11 +30,11 @@ import org.apache.poi.hssf.record.ColumnInfoRecord; */ public final class ColumnInfoRecordsAggregate extends RecordAggregate { /** - * List of {@link ColumnInfoRecord}s assumed to be in order + * List of {@link ColumnInfoRecord}s assumed to be in order */ private final List records; - - + + private static final class CIRComparator implements Comparator { public static final Comparator instance = new CIRComparator(); private CIRComparator() { @@ -299,7 +299,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { } - public void setColumn(int targetColumnIx, Short xfIndex, Integer width, + public void setColumn(int targetColumnIx, Short xfIndex, Integer width, Integer level, Boolean hidden, Boolean collapsed) { ColumnInfoRecord ci = null; int k = 0; @@ -370,18 +370,18 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { ColumnInfoRecord ciMid = copyColInfo(ci); ColumnInfoRecord ciEnd = copyColInfo(ci); int lastcolumn = ci.getLastColumn(); - + ciStart.setLastColumn(targetColumnIx - 1); ciMid.setFirstColumn(targetColumnIx); ciMid.setLastColumn(targetColumnIx); setColumnInfoFields(ciMid, xfIndex, width, level, hidden, collapsed); insertColumn(++k, ciMid); - + ciEnd.setFirstColumn(targetColumnIx+1); ciEnd.setLastColumn(lastcolumn); insertColumn(++k, ciEnd); - // no need to attemptMergeColInfoRecords because we + // no need to attemptMergeColInfoRecords because we // know both on each side are different } } @@ -389,7 +389,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { /** * Sets all non null fields into the ci parameter. */ - private static void setColumnInfoFields(ColumnInfoRecord ci, Short xfStyle, Integer width, + private static void setColumnInfoFields(ColumnInfoRecord ci, Short xfStyle, Integer width, Integer level, Boolean hidden, Boolean collapsed) { if (xfStyle != null) { ci.setXFIndex(xfStyle.shortValue()); @@ -429,13 +429,13 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { } /** - * Attempts to merge the col info record at the specified index + * Attempts to merge the col info record at the specified index * with either or both of its neighbours */ private void attemptMergeColInfoRecords(int colInfoIx) { int nRecords = records.size(); if (colInfoIx < 0 || colInfoIx >= nRecords) { - throw new IllegalArgumentException("colInfoIx " + colInfoIx + throw new IllegalArgumentException("colInfoIx " + colInfoIx + " is out of range (0.." + (nRecords-1) + ")"); } ColumnInfoRecord currentCol = getColInfo(colInfoIx); @@ -466,7 +466,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { * Creates an outline group for the specified columns, by setting the level * field for each col info record in the range. {@link ColumnInfoRecord}s * may be created, split or merged as a result of this operation. - * + * * @param fromColumnIx * group from this column (inclusive) * @param toColumnIx @@ -493,7 +493,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate { level = Math.min(7, level); colInfoSearchStartIdx = Math.max(0, colInfoIdx - 1); // -1 just in case this column is collapsed later. } - setColumn(i, null, null, new Integer(level), null, null); + setColumn(i, null, null, Integer.valueOf(level), null, null); } } /** diff --git a/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java index 1d10332cb5..5b9393719a 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java @@ -114,8 +114,8 @@ public final class RowRecordsAggregate extends RecordAggregate { _unknownRecords.add(rec); } public void insertRow(RowRecord row) { - // Integer integer = new Integer(row.getRowNumber()); - _rowRecords.put(new Integer(row.getRowNumber()), row); + // Integer integer = Integer.valueOf(row.getRowNumber()); + _rowRecords.put(Integer.valueOf(row.getRowNumber()), row); if ((row.getRowNumber() < _firstrow) || (_firstrow == -1)) { _firstrow = row.getRowNumber(); } @@ -127,7 +127,7 @@ public final class RowRecordsAggregate extends RecordAggregate { public void removeRow(RowRecord row) { int rowIndex = row.getRowNumber(); _valuesAgg.removeAllCellsValuesForRow(rowIndex); - Integer key = new Integer(rowIndex); + Integer key = Integer.valueOf(rowIndex); RowRecord rr = _rowRecords.remove(key); if (rr == null) { throw new RuntimeException("Invalid row index (" + key.intValue() + ")"); @@ -143,7 +143,7 @@ public final class RowRecordsAggregate extends RecordAggregate { if (rowIndex < 0 || rowIndex > maxrow) { throw new IllegalArgumentException("The row number must be between 0 and " + maxrow); } - return _rowRecords.get(new Integer(rowIndex)); + return _rowRecords.get(Integer.valueOf(rowIndex)); } public int getPhysicalNumberOfRows() diff --git a/src/java/org/apache/poi/hssf/record/formula/function/FunctionDataBuilder.java b/src/java/org/apache/poi/hssf/record/formula/function/FunctionDataBuilder.java index 789be63240..5f173a12db 100644 --- a/src/java/org/apache/poi/hssf/record/formula/function/FunctionDataBuilder.java +++ b/src/java/org/apache/poi/hssf/record/formula/function/FunctionDataBuilder.java @@ -25,7 +25,7 @@ import java.util.Set; /** * Temporarily collects FunctionMetadata instances for creation of a * FunctionMetadataRegistry. - * + * * @author Josh Micich */ final class FunctionDataBuilder { @@ -46,10 +46,10 @@ final class FunctionDataBuilder { byte returnClassCode, byte[] parameterClassCodes, boolean hasFootnote) { FunctionMetadata fm = new FunctionMetadata(functionIndex, functionName, minParams, maxParams, returnClassCode, parameterClassCodes); - - Integer indexKey = new Integer(functionIndex); - - + + Integer indexKey = Integer.valueOf(functionIndex); + + if(functionIndex > _maxFunctionIndex) { _maxFunctionIndex = functionIndex; } @@ -60,7 +60,7 @@ final class FunctionDataBuilder { if(!hasFootnote || !_mutatingFunctionIndexes.contains(indexKey)) { throw new RuntimeException("Multiple entries for function name '" + functionName + "'"); } - _functionDataByIndex.remove(new Integer(prevFM.getIndex())); + _functionDataByIndex.remove(Integer.valueOf(prevFM.getIndex())); } prevFM = (FunctionMetadata) _functionDataByIndex.get(indexKey); if(prevFM != null) { @@ -85,7 +85,7 @@ final class FunctionDataBuilder { FunctionMetadata fd = jumbledArray[i]; fdIndexArray[fd.getIndex()] = fd; } - + return new FunctionMetadataRegistry(fdIndexArray, _functionDataByName); } -} \ No newline at end of file +} diff --git a/src/java/org/apache/poi/hssf/usermodel/FontDetails.java b/src/java/org/apache/poi/hssf/usermodel/FontDetails.java index 910bead93b..f9b2bc8138 100644 --- a/src/java/org/apache/poi/hssf/usermodel/FontDetails.java +++ b/src/java/org/apache/poi/hssf/usermodel/FontDetails.java @@ -57,7 +57,7 @@ public class FontDetails public void addChar( char c, int width ) { - charWidths.put(new Character(c), new Integer(width)); + charWidths.put(new Character(c), Integer.valueOf(width)); } /** @@ -78,7 +78,7 @@ public class FontDetails { for ( int i = 0; i < characters.length; i++ ) { - charWidths.put( new Character(characters[i]), new Integer(widths[i])); + charWidths.put( new Character(characters[i]), Integer.valueOf(widths[i])); } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java index 1443bc715f..8ee2010300 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java @@ -79,6 +79,7 @@ public class HSSFPictureData implements PictureData /** * @see #getFormat + * @return 'wmf', 'jpeg' etc depending on the format. never null */ public String suggestFileExtension() { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index f4501e619f..d526d6de9d 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -149,7 +149,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { if (log.check( POILogger.DEBUG )) log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ", - new Long(timestart)); + Long.valueOf(timestart)); HSSFRow lastrow = null; // Add every cell to its row @@ -180,12 +180,12 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { hrow.createCellFromRecord( cval ); if (log.check( POILogger.DEBUG )) log.log( DEBUG, "record took ", - new Long( System.currentTimeMillis() - cellstart ) ); + Long.valueOf( System.currentTimeMillis() - cellstart ) ); } if (log.check( POILogger.DEBUG )) log.log(DEBUG, "total sheet cell creation took ", - new Long(System.currentTimeMillis() - timestart)); + Long.valueOf(System.currentTimeMillis() - timestart)); } /** @@ -231,7 +231,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { } if (_rows.size() > 0) { - Integer key = new Integer(row.getRowNum()); + Integer key = Integer.valueOf(row.getRowNum()); HSSFRow removedRow = _rows.remove(key); if (removedRow != row) { //should not happen if the input argument is valid @@ -296,7 +296,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { private void addRow(HSSFRow row, boolean addLow) { - _rows.put(new Integer(row.getRowNum()), row); + _rows.put(Integer.valueOf(row.getRowNum()), row); if (addLow) { _sheet.addRow(row.getRowRecord()); @@ -319,7 +319,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet { * @return HSSFRow representing the row number or null if its not defined on the sheet */ public HSSFRow getRow(int rowIndex) { - return _rows.get(new Integer(rowIndex)); + return _rows.get(Integer.valueOf(rowIndex)); } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index cb772c9b84..3d81c478f4 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1081,7 +1081,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm // So we don't confuse users, give them back // the same object every time, but create // them lazily - Short sIdx = new Short(idx); + Short sIdx = Short.valueOf(idx); if(fonts.containsKey(sIdx)) { return (HSSFFont)fonts.get(sIdx); } diff --git a/src/java/org/apache/poi/hssf/util/HSSFColor.java b/src/java/org/apache/poi/hssf/util/HSSFColor.java index d19cc95147..6c1e77ec6e 100644 --- a/src/java/org/apache/poi/hssf/util/HSSFColor.java +++ b/src/java/org/apache/poi/hssf/util/HSSFColor.java @@ -63,7 +63,7 @@ public class HSSFColor { for (int i = 0; i < colors.length; i++) { HSSFColor color = colors[i]; - Integer index1 = new Integer(color.getIndex()); + Integer index1 = Integer.valueOf(color.getIndex()); if (result.containsKey(index1)) { HSSFColor prevColor = (HSSFColor)result.get(index1); throw new RuntimeException("Dup color index (" + index1 @@ -111,7 +111,7 @@ public class HSSFColor { } catch (IllegalAccessException e) { throw new RuntimeException(e); } - return new Integer(s.intValue()); + return Integer.valueOf(s.intValue()); } private static HSSFColor[] getAllColors() { diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java index ed8abb7dfa..66da4ca252 100644 --- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java @@ -192,7 +192,7 @@ public final class WorkbookEvaluator { if (sheetIndex < 0) { throw new RuntimeException("Specified sheet from a different book"); } - result = new Integer(sheetIndex); + result = Integer.valueOf(sheetIndex); _sheetIndexesBySheet.put(sheet, result); } return result.intValue(); @@ -214,7 +214,7 @@ public final class WorkbookEvaluator { if (sheetIndex < 0) { return -1; } - result = new Integer(sheetIndex); + result = Integer.valueOf(sheetIndex); _sheetIndexesByName.put(sheetName, result); } return result.intValue(); diff --git a/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java b/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java index fdb5c99b49..e9eebaff41 100644 --- a/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java +++ b/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java @@ -67,9 +67,9 @@ import java.util.Map; *

      * * @author Yegor Kozlov - * - * Modified 6/17/09 by Stanislav Shor - positive formats don't need starting '(' - * + * + * Modified 6/17/09 by Stanislav Shor - positive formats don't need starting '(' + * */ public final class BuiltinFormats { /** @@ -142,7 +142,7 @@ public final class BuiltinFormats { public static Map getBuiltinFormats() { Map result = new LinkedHashMap(); for (int i=0; i<_formats.length; i++) { - result.put(new Integer(i), _formats[i]); + result.put(Integer.valueOf(i), _formats[i]); } return result; } diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index f402a0cfab..bb7ef000e4 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -147,7 +147,7 @@ public class DataFormatter { if (format != null) { return format; } - if (formatStr.equals("General") || formatStr.equals("@")) { + if ("General".equals(formatStr) || "@".equals(formatStr)) { if (DataFormatter.isWholeNumber(cellValue)) { return generalWholeNumFormat; } @@ -257,7 +257,7 @@ public class DataFormatter { if(mIsMonth) { sb.append('M'); ms.add( - new Integer(sb.length() -1) + Integer.valueOf(sb.length() -1) ); } else { sb.append('m'); diff --git a/src/java/org/apache/poi/ss/util/SheetReferences.java b/src/java/org/apache/poi/ss/util/SheetReferences.java index 74b84f5f26..028538a89d 100644 --- a/src/java/org/apache/poi/ss/util/SheetReferences.java +++ b/src/java/org/apache/poi/ss/util/SheetReferences.java @@ -34,13 +34,12 @@ public class SheetReferences { map = new HashMap(5); } - + public void addSheetReference(String sheetName, int number) { - map.put(new Integer(number), sheetName); - } + map.put(Integer.valueOf(number), sheetName); + } public String getSheetName(int number) { - return (String)map.get(new Integer(number)); + return (String)map.get(Integer.valueOf(number)); } - } diff --git a/src/java/org/apache/poi/util/BitFieldFactory.java b/src/java/org/apache/poi/util/BitFieldFactory.java index a0da1fedd6..d022ee66ce 100644 --- a/src/java/org/apache/poi/util/BitFieldFactory.java +++ b/src/java/org/apache/poi/util/BitFieldFactory.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -27,18 +26,15 @@ import java.util.*; * @author Jason Height (jheight at apache dot org) */ -public class BitFieldFactory -{ +public class BitFieldFactory { private static Map instances = new HashMap(); - - public static BitField getInstance(final int mask) { - BitField f = (BitField)instances.get(new Integer(mask)); + + public static BitField getInstance(int mask) { + BitField f = (BitField)instances.get(Integer.valueOf(mask)); if (f == null) { f = new BitField(mask); - instances.put(new Integer(mask), f); + instances.put(Integer.valueOf(mask), f); } return f; } - -} // end public class BitFieldFactory - +} diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java index 91632e8fc5..fa7ecb5c4b 100644 --- a/src/java/org/apache/poi/util/HexRead.java +++ b/src/java/org/apache/poi/util/HexRead.java @@ -62,7 +62,7 @@ public class HexRead * @see #readData(String) */ public static byte[] readData(InputStream stream, String section ) throws IOException { - + try { StringBuffer sectionText = new StringBuffer(); @@ -128,7 +128,7 @@ public class HexRead characterCount++; if ( characterCount == 2 ) { - bytes.add( new Byte( b ) ); + bytes.add( Byte.valueOf( b ) ); characterCount = 0; b = (byte) 0; } @@ -151,7 +151,7 @@ public class HexRead characterCount++; if ( characterCount == 2 ) { - bytes.add( new Byte( b ) ); + bytes.add( Byte.valueOf( b ) ); characterCount = 0; b = (byte) 0; } diff --git a/src/java/org/apache/poi/util/IntMapper.java b/src/java/org/apache/poi/util/IntMapper.java index 89ae28c631..e4b7d34507 100644 --- a/src/java/org/apache/poi/util/IntMapper.java +++ b/src/java/org/apache/poi/util/IntMapper.java @@ -69,7 +69,7 @@ public class IntMapper { int index = elements.size(); elements.add(value); - valueKeyMap.put(value, new Integer(index)); + valueKeyMap.put(value, Integer.valueOf(index)); return true; } diff --git a/src/java/org/apache/poi/util/POILogger.java b/src/java/org/apache/poi/util/POILogger.java index caf2035ac7..241196ec64 100644 --- a/src/java/org/apache/poi/util/POILogger.java +++ b/src/java/org/apache/poi/util/POILogger.java @@ -601,7 +601,7 @@ public abstract class POILogger { for (int j = 0; j < array.length; j++) { - results.add(new Byte(array[ j ])); + results.add(Byte.valueOf(array[ j ])); } } if (object instanceof char []) @@ -619,7 +619,7 @@ public abstract class POILogger { for (int j = 0; j < array.length; j++) { - results.add(new Short(array[ j ])); + results.add(Short.valueOf(array[ j ])); } } else if (object instanceof int []) @@ -628,7 +628,7 @@ public abstract class POILogger { for (int j = 0; j < array.length; j++) { - results.add(new Integer(array[ j ])); + results.add(Integer.valueOf(array[ j ])); } } else if (object instanceof long []) @@ -637,7 +637,7 @@ public abstract class POILogger { for (int j = 0; j < array.length; j++) { - results.add(new Long(array[ j ])); + results.add(Long.valueOf(array[ j ])); } } else if (object instanceof float []) diff --git a/src/java/org/apache/poi/util/StringUtil.java b/src/java/org/apache/poi/util/StringUtil.java index c61eb2f644..4a2cbabc72 100644 --- a/src/java/org/apache/poi/util/StringUtil.java +++ b/src/java/org/apache/poi/util/StringUtil.java @@ -24,7 +24,7 @@ import java.text.NumberFormat; import org.apache.poi.hssf.record.RecordInputStream; /** * Title: String Utility Description: Collection of string handling utilities

      - * + * * Note - none of the methods in this class deals with {@link org.apache.poi.hssf.record.ContinueRecord}s. For such * functionality, consider using {@link RecordInputStream } * @@ -52,7 +52,7 @@ public class StringUtil { * byte array. it is assumed that string[ offset ] and string[ offset + * 1 ] contain the first 16-bit unicode character * @param len the length of the final string - * @return the converted string + * @return the converted string, never null. * @exception ArrayIndexOutOfBoundsException if offset is out of bounds for * the byte array (i.e., is negative or is greater than or equal to * string.length) @@ -87,7 +87,7 @@ public class StringUtil { * { 0x16, 0x00 } -0x16 * * @param string the byte array to be converted - * @return the converted string + * @return the converted string, never null */ public static String getFromUnicodeLE(byte[] string) { if(string.length == 0) { return ""; } @@ -132,7 +132,7 @@ public class StringUtil { * For this encoding, the is16BitFlag is always present even if nChars==0. */ public static String readUnicodeString(LittleEndianInput in) { - + int nChars = in.readUShort(); byte flag = in.readByte(); if ((flag & 0x01) == 0) { @@ -148,17 +148,17 @@ public class StringUtil { * * For this encoding, the is16BitFlag is always present even if nChars==0. *
      - * This method should be used when the nChars field is not stored - * as a ushort immediately before the is16BitFlag. Otherwise, {@link - * #readUnicodeString(LittleEndianInput)} can be used. + * This method should be used when the nChars field is not stored + * as a ushort immediately before the is16BitFlag. Otherwise, {@link + * #readUnicodeString(LittleEndianInput)} can be used. */ public static String readUnicodeString(LittleEndianInput in, int nChars) { byte is16Bit = in.readByte(); if ((is16Bit & 0x01) == 0) { return readCompressedUnicode(in, nChars); } - return readUnicodeLE(in, nChars); - } + return readUnicodeLE(in, nChars); + } /** * OutputStream out will get: *

        @@ -169,7 +169,7 @@ public class StringUtil { * For this encoding, the is16BitFlag is always present even if nChars==0. */ public static void writeUnicodeString(LittleEndianOutput out, String value) { - + int nChars = value.length(); out.writeShort(nChars); boolean is16Bit = hasMultibyte(value); @@ -188,11 +188,11 @@ public class StringUtil { *
      * For this encoding, the is16BitFlag is always present even if nChars==0. *
      - * This method should be used when the nChars field is not stored - * as a ushort immediately before the is16BitFlag. Otherwise, {@link - * #writeUnicodeString(LittleEndianOutput, String)} can be used. + * This method should be used when the nChars field is not stored + * as a ushort immediately before the is16BitFlag. Otherwise, {@link + * #writeUnicodeString(LittleEndianOutput, String)} can be used. */ - public static void writeUnicodeStringFlagAndData(LittleEndianOutput out, String value) { + public static void writeUnicodeStringFlagAndData(LittleEndianOutput out, String value) { boolean is16Bit = hasMultibyte(value); out.writeByte(is16Bit ? 0x01 : 0x00); if (is16Bit) { @@ -201,7 +201,7 @@ public class StringUtil { putCompressedUnicode(value, out); } } - + /** * @return the number of bytes that would be written by {@link #writeUnicodeString(LittleEndianOutput, String)} */ @@ -267,7 +267,7 @@ public class StringUtil { } out.write(bytes); } - + public static String readUnicodeLE(LittleEndianInput in, int nChars) { char[] buf = new char[nChars]; for (int i = 0; i < buf.length; i++) { @@ -360,7 +360,7 @@ public class StringUtil { /** * check the parameter has multibyte character - * + * * @param value string to check * @return boolean result true:string has at least one multibyte character */ @@ -378,7 +378,7 @@ public class StringUtil { /** * Checks to see if a given String needs to be represented as Unicode - * + * * @param value * @return true if string needs Unicode to be represented. */ diff --git a/src/ooxml/java/org/apache/poi/POIXMLProperties.java b/src/ooxml/java/org/apache/poi/POIXMLProperties.java index c62b57db36..45e17a2df6 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLProperties.java +++ b/src/ooxml/java/org/apache/poi/POIXMLProperties.java @@ -37,7 +37,7 @@ import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty; /** - * Wrapper around the two different kinds of OOXML properties + * Wrapper around the two different kinds of OOXML properties * a document can have */ public class POIXMLProperties { @@ -46,123 +46,123 @@ public class POIXMLProperties { private ExtendedProperties ext; private CustomProperties cust; - private PackagePart extPart; - private PackagePart custPart; + private PackagePart extPart; + private PackagePart custPart; - private static final org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument NEW_EXT_INSTANCE; - private static final org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument NEW_CUST_INSTANCE; - static { - NEW_EXT_INSTANCE = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.newInstance(); - NEW_EXT_INSTANCE.addNewProperties(); + private static final org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument NEW_EXT_INSTANCE; + private static final org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument NEW_CUST_INSTANCE; + static { + NEW_EXT_INSTANCE = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.newInstance(); + NEW_EXT_INSTANCE.addNewProperties(); - NEW_CUST_INSTANCE = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.newInstance(); - NEW_CUST_INSTANCE.addNewProperties(); - } + NEW_CUST_INSTANCE = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.newInstance(); + NEW_CUST_INSTANCE.addNewProperties(); + } - public POIXMLProperties(OPCPackage docPackage) throws IOException, OpenXML4JException, XmlException { + public POIXMLProperties(OPCPackage docPackage) throws IOException, OpenXML4JException, XmlException { this.pkg = docPackage; - + // Core properties - core = new CoreProperties((PackagePropertiesPart)pkg.getPackageProperties() ); - + core = new CoreProperties((PackagePropertiesPart)pkg.getPackageProperties() ); + // Extended properties PackageRelationshipCollection extRel = pkg.getRelationshipsByType(POIXMLDocument.EXTENDED_PROPERTIES_REL_TYPE); if(extRel.size() == 1) { - extPart = pkg.getPart( extRel.getRelationship(0)); - org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse( - extPart.getInputStream() + extPart = pkg.getPart( extRel.getRelationship(0)); + org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse( + extPart.getInputStream() ); ext = new ExtendedProperties(props); } else { - extPart = null; - ext = new ExtendedProperties((org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument)NEW_EXT_INSTANCE.copy()); - } - + extPart = null; + ext = new ExtendedProperties((org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument)NEW_EXT_INSTANCE.copy()); + } + // Custom properties PackageRelationshipCollection custRel = pkg.getRelationshipsByType(POIXMLDocument.CUSTOM_PROPERTIES_REL_TYPE); if(custRel.size() == 1) { - custPart = pkg.getPart( custRel.getRelationship(0)); - org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse( + custPart = pkg.getPart( custRel.getRelationship(0)); + org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse( custPart.getInputStream() ); cust = new CustomProperties(props); } else { - custPart = null; - cust = new CustomProperties((org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument)NEW_CUST_INSTANCE.copy()); + custPart = null; + cust = new CustomProperties((org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument)NEW_CUST_INSTANCE.copy()); } } - + /** * Returns the core document properties */ public CoreProperties getCoreProperties() { return core; } - + /** * Returns the extended document properties */ public ExtendedProperties getExtendedProperties() { return ext; } - + /** * Returns the custom document properties */ public CustomProperties getCustomProperties() { return cust; } - + /** * Commit changes to the underlying OPC package */ public void commit() throws IOException{ - if(extPart == null && !NEW_EXT_INSTANCE.toString().equals(ext.props.toString())){ - try { - PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/app.xml"); - pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"); - extPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.extended-properties+xml"); - } catch (InvalidFormatException e){ - throw new POIXMLException(e); - } - } - if(custPart == null && !NEW_CUST_INSTANCE.toString().equals(cust.props.toString())){ - try { - PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/custom.xml"); - pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"); - custPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.custom-properties+xml"); - } catch (InvalidFormatException e){ - throw new POIXMLException(e); - } - } - if(extPart != null){ - XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); - xmlOptions.setSaveSuggestedPrefixes(map); - - OutputStream out = extPart.getOutputStream(); - ext.props.save(out, xmlOptions); - out.close(); - } - if(custPart != null){ - XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); - - Map map = new HashMap(); - map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); - xmlOptions.setSaveSuggestedPrefixes(map); - - OutputStream out = custPart.getOutputStream(); - cust.props.save(out, xmlOptions); - out.close(); - } + if(extPart == null && !NEW_EXT_INSTANCE.toString().equals(ext.props.toString())){ + try { + PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/app.xml"); + pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"); + extPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.extended-properties+xml"); + } catch (InvalidFormatException e){ + throw new POIXMLException(e); + } + } + if(custPart == null && !NEW_CUST_INSTANCE.toString().equals(cust.props.toString())){ + try { + PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/custom.xml"); + pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"); + custPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.custom-properties+xml"); + } catch (InvalidFormatException e){ + throw new POIXMLException(e); + } + } + if(extPart != null){ + XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + + Map map = new HashMap(); + map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); + xmlOptions.setSaveSuggestedPrefixes(map); + + OutputStream out = extPart.getOutputStream(); + ext.props.save(out, xmlOptions); + out.close(); + } + if(custPart != null){ + XmlOptions xmlOptions = new XmlOptions(POIXMLDocumentPart.DEFAULT_XML_OPTIONS); + + Map map = new HashMap(); + map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt"); + xmlOptions.setSaveSuggestedPrefixes(map); + + OutputStream out = custPart.getOutputStream(); + cust.props.save(out, xmlOptions); + out.close(); + } } - + /** * The core document properties */ @@ -171,7 +171,7 @@ public class POIXMLProperties { private CoreProperties(PackagePropertiesPart part) { this.part = part; } - + public String getCategory() { return part.getCategoryProperty().getValue(); } @@ -252,17 +252,17 @@ public class POIXMLProperties { } public void setRevision(String revision) { try { - new Long(revision); + Long.valueOf(revision); part.setRevisionProperty(revision); } catch (NumberFormatException e) {} } - + public PackagePropertiesPart getUnderlyingProperties() { return part; } } - + /** * Extended document properties */ @@ -271,115 +271,115 @@ public class POIXMLProperties { private ExtendedProperties(org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props) { this.props = props; } - + public org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties getUnderlyingProperties() { return props.getProperties(); } } - + /** * Custom document properties */ public class CustomProperties { - /** - * Each custom property element contains an fmtid attribute - * with the same GUID value ({D5CDD505-2E9C-101B-9397-08002B2CF9AE}). - */ - public static final String FORMAT_ID = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"; + /** + * Each custom property element contains an fmtid attribute + * with the same GUID value ({D5CDD505-2E9C-101B-9397-08002B2CF9AE}). + */ + public static final String FORMAT_ID = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"; - private org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props; + private org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props; private CustomProperties(org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props) { this.props = props; } - + public org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties getUnderlyingProperties() { return props.getProperties(); } - /** - * Add a new property - * - * @param name the property name - * @throws IllegalArgumentException if a property with this name already exists - */ - private CTProperty add(String name) { - if(contains(name)) { - throw new IllegalArgumentException("A property with this name " + - "already exists in the custom properties"); - } - - CTProperty p = props.getProperties().addNewProperty(); - int pid = nextPid(); - p.setPid(pid); - p.setFmtid(FORMAT_ID); - p.setName(name); - return p; - } - - /** - * Add a new string property - * - * @throws IllegalArgumentException if a property with this name already exists - */ - public void addProperty(String name, String value){ - CTProperty p = add(name); - p.setLpwstr(value); - } - - /** - * Add a new double property - * - * @throws IllegalArgumentException if a property with this name already exists - */ - public void addProperty(String name, double value){ - CTProperty p = add(name); - p.setR8(value); - } - - /** - * Add a new integer property - * - * @throws IllegalArgumentException if a property with this name already exists - */ - public void addProperty(String name, int value){ - CTProperty p = add(name); - p.setI4(value); - } - - /** - * Add a new boolean property - * - * @throws IllegalArgumentException if a property with this name already exists - */ - public void addProperty(String name, boolean value){ - CTProperty p = add(name); - p.setBool(value); - } - - /** - * Generate next id that uniquely relates a custom property - * - * @return next property id starting with 2 - */ - protected int nextPid(){ - int propid = 1; - for(CTProperty p : props.getProperties().getPropertyArray()){ - if(p.getPid() > propid) propid = p.getPid(); - } - return propid + 1; - } - - /** - * Check if a property with this name already exists in the collection of custom properties - * - * @param name the name to check - * @return whether a property with the given name exists in the custom properties - */ - public boolean contains(String name){ - for(CTProperty p : props.getProperties().getPropertyArray()){ - if(p.getName().equals(name)) return true; - } - return false; - } - } + /** + * Add a new property + * + * @param name the property name + * @throws IllegalArgumentException if a property with this name already exists + */ + private CTProperty add(String name) { + if(contains(name)) { + throw new IllegalArgumentException("A property with this name " + + "already exists in the custom properties"); + } + + CTProperty p = props.getProperties().addNewProperty(); + int pid = nextPid(); + p.setPid(pid); + p.setFmtid(FORMAT_ID); + p.setName(name); + return p; + } + + /** + * Add a new string property + * + * @throws IllegalArgumentException if a property with this name already exists + */ + public void addProperty(String name, String value){ + CTProperty p = add(name); + p.setLpwstr(value); + } + + /** + * Add a new double property + * + * @throws IllegalArgumentException if a property with this name already exists + */ + public void addProperty(String name, double value){ + CTProperty p = add(name); + p.setR8(value); + } + + /** + * Add a new integer property + * + * @throws IllegalArgumentException if a property with this name already exists + */ + public void addProperty(String name, int value){ + CTProperty p = add(name); + p.setI4(value); + } + + /** + * Add a new boolean property + * + * @throws IllegalArgumentException if a property with this name already exists + */ + public void addProperty(String name, boolean value){ + CTProperty p = add(name); + p.setBool(value); + } + + /** + * Generate next id that uniquely relates a custom property + * + * @return next property id starting with 2 + */ + protected int nextPid(){ + int propid = 1; + for(CTProperty p : props.getProperties().getPropertyArray()){ + if(p.getPid() > propid) propid = p.getPid(); + } + return propid + 1; + } + + /** + * Check if a property with this name already exists in the collection of custom properties + * + * @param name the name to check + * @return whether a property with the given name exists in the custom properties + */ + public boolean contains(String name){ + for(CTProperty p : props.getProperties().getPropertyArray()){ + if(p.getName().equals(name)) return true; + } + return false; + } + } } diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index 53cb5d6677..04272e36cc 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -58,15 +58,15 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** - * + * * Maps an XLSX to an XML according to one of the mapping defined. - * - * + * + * * The output XML Schema must respect this limitations: - * + * *
        *
      • all mandatory elements and attributes must be mapped (enable validation to check this)
      • - * + * *
      • no <any> in complex type/element declaration
      • *
      • no <anyAttribute> attributes declaration
      • *
      • no recursive structures: recursive structures can't be nested more than one level
      • @@ -74,31 +74,26 @@ import org.xml.sax.SAXException; *
      • no mixed content: an element can't contain simple text and child element(s) together
      • *
      • no <substitutionGroup> in complex type/element declaration
      • *
      - * - * @author Roberto Manicardi - * - * * + * @author Roberto Manicardi */ - - public class XSSFExportToXml implements Comparator{ - + private XSSFMap map; - + /** * Creates a new exporter and sets the mapping to be used when generating the XML output document - * + * * @param map the mapping rule to be used */ - public XSSFExportToXml(XSSFMap map){ + public XSSFExportToXml(XSSFMap map) { this.map = map; } - + /** - * - * Exports the data in an XML stream - * + * + * Exports the data in an XML stream + * * @param os OutputStream in which will contain the output XML * @param validate if true, validates the XML againts the XML Schema * @throws SAXException @@ -106,252 +101,242 @@ public class XSSFExportToXml implements Comparator{ public void exportToXML(OutputStream os, boolean validate) throws SAXException{ exportToXML(os,"UTF-8", validate); } - + private Document getEmptyDocument() throws ParserConfigurationException{ - - + DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); - Document doc = docBuilder.newDocument(); + DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); + Document doc = docBuilder.newDocument(); - - - return doc; + return doc; } - + /** * Exports the data in an XML stream - * + * * @param os OutputStream in which will contain the output XML - * @param encoding the output charset encoding + * @param encoding the output charset encoding * @param validate if true, validates the XML againts the XML Schema * @throws SAXException * @throws InvalidFormatException */ - public void exportToXML(OutputStream os, String encoding, boolean validate) throws SAXException{ List singleXMLCells = map.getRelatedSingleXMLCell(); List
      tables = map.getRelatedTables(); - + String rootElement = map.getCtMap().getRootElement(); - + try{ - + Document doc = getEmptyDocument(); - - Element root = null; - - if(isNamespaceDeclared()){ - root=doc.createElementNS(getNamespace(),rootElement); - }else{ - root=doc.createElement(rootElement); - } - doc.appendChild(root); - - - List xpaths = new Vector(); - Map singleXmlCellsMappings = new HashMap(); - Map tableMappings = new HashMap(); - - for(XSSFSingleXmlCell simpleXmlCell : singleXMLCells){ - xpaths.add(simpleXmlCell.getXpath()); - singleXmlCellsMappings.put(simpleXmlCell.getXpath(), simpleXmlCell); - } - for(Table table : tables){ - String commonXPath = table.getCommonXpath(); - xpaths.add(commonXPath); - tableMappings.put(commonXPath, table); - } - - - Collections.sort(xpaths,this); - - for(String xpath : xpaths){ - - XSSFSingleXmlCell simpleXmlCell = singleXmlCellsMappings.get(xpath); - Table table = tableMappings.get(xpath); - - if(!xpath.matches(".*\\[.*")){ - - // Exports elements and attributes mapped with simpleXmlCell - if(simpleXmlCell!=null){ - XSSFCell cell = simpleXmlCell.getReferencedCell(); - if(cell!=null){ - Node currentNode = getNodeByXPath(xpath,doc.getFirstChild(),doc,false); - STXmlDataType.Enum dataType = simpleXmlCell.getXmlDataType(); - mapCellOnNode(cell,currentNode,dataType); - } - } - - // Exports elements and attributes mapped with tables - if(table!=null){ - - List tableColumns = table.getXmlColumnPrs(); - - XSSFSheet sheet = table.getXSSFSheet(); - - int startRow = table.getStartCellReference().getRow(); - // In mappings created with Microsoft Excel the first row contains the table header and must be skipped - startRow +=1; - - int endRow = table.getEndCellReference().getRow(); - - for(int i = startRow; i<= endRow; i++){ - XSSFRow row = sheet.getRow(i); - - Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true); - - short startColumnIndex = table.getStartCellReference().getCol(); - for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++){ - XSSFCell cell = row.getCell(j); - if(cell!=null){ - XSSFXmlColumnPr pointer = tableColumns.get(j-startColumnIndex); - String localXPath = pointer.getLocalXPath(); - Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false); - STXmlDataType.Enum dataType = pointer.getXmlDataType(); - - - mapCellOnNode(cell,currentNode,dataType); - } - - } - - } - - - - } - }else{ - // TODO: implement filtering management in xpath - } - } - - boolean isValid = true; - if(validate){ - isValid =isValid(doc); - } - - - - if(isValid){ - + + Element root = null; + + if (isNamespaceDeclared()) { + root=doc.createElementNS(getNamespace(),rootElement); + } else { + root=doc.createElement(rootElement); + } + doc.appendChild(root); + + + List xpaths = new Vector(); + Map singleXmlCellsMappings = new HashMap(); + Map tableMappings = new HashMap(); + + for(XSSFSingleXmlCell simpleXmlCell : singleXMLCells) { + xpaths.add(simpleXmlCell.getXpath()); + singleXmlCellsMappings.put(simpleXmlCell.getXpath(), simpleXmlCell); + } + for(Table table : tables) { + String commonXPath = table.getCommonXpath(); + xpaths.add(commonXPath); + tableMappings.put(commonXPath, table); + } + + + Collections.sort(xpaths,this); + + for(String xpath : xpaths) { + + XSSFSingleXmlCell simpleXmlCell = singleXmlCellsMappings.get(xpath); + Table table = tableMappings.get(xpath); + + if (!xpath.matches(".*\\[.*")) { + + // Exports elements and attributes mapped with simpleXmlCell + if (simpleXmlCell!=null) { + XSSFCell cell = simpleXmlCell.getReferencedCell(); + if (cell!=null) { + Node currentNode = getNodeByXPath(xpath,doc.getFirstChild(),doc,false); + STXmlDataType.Enum dataType = simpleXmlCell.getXmlDataType(); + mapCellOnNode(cell,currentNode,dataType); + } + } + + // Exports elements and attributes mapped with tables + if (table!=null) { + + List tableColumns = table.getXmlColumnPrs(); + + XSSFSheet sheet = table.getXSSFSheet(); + + int startRow = table.getStartCellReference().getRow(); + // In mappings created with Microsoft Excel the first row contains the table header and must be skipped + startRow +=1; + + int endRow = table.getEndCellReference().getRow(); + + for(int i = startRow; i<= endRow; i++) { + XSSFRow row = sheet.getRow(i); + + Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true); + + short startColumnIndex = table.getStartCellReference().getCol(); + for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++) { + XSSFCell cell = row.getCell(j); + if (cell!=null) { + XSSFXmlColumnPr pointer = tableColumns.get(j-startColumnIndex); + String localXPath = pointer.getLocalXPath(); + Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false); + STXmlDataType.Enum dataType = pointer.getXmlDataType(); + + + mapCellOnNode(cell,currentNode,dataType); + } + + } + + } + + + + } + } else { + // TODO: implement filtering management in xpath + } + } + + boolean isValid = true; + if (validate) { + isValid =isValid(doc); + } + + + + if (isValid) { + ///////////////// - //Output the XML - - //set up a transformer - TransformerFactory transfac = TransformerFactory.newInstance(); - Transformer trans = transfac.newTransformer(); - trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - trans.setOutputProperty(OutputKeys.INDENT, "yes"); - trans.setOutputProperty(OutputKeys.ENCODING, encoding); - - //create string from xml tree - - StreamResult result = new StreamResult(os); - DOMSource source = new DOMSource(doc); - trans.transform(source, result); - - } - }catch(ParserConfigurationException e){ + //Output the XML + + //set up a transformer + TransformerFactory transfac = TransformerFactory.newInstance(); + Transformer trans = transfac.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + trans.setOutputProperty(OutputKeys.ENCODING, encoding); + + //create string from xml tree + + StreamResult result = new StreamResult(os); + DOMSource source = new DOMSource(doc); + trans.transform(source, result); + + } + }catch(ParserConfigurationException e) { e.printStackTrace(); - }catch(TransformerException e){ + }catch(TransformerException e) { e.printStackTrace(); } - + } - + /** * Validate the generated XML against the XML Schema associated with the XSSFMap - * + * * @param xml the XML to validate * @return */ - private boolean isValid(Document xml) throws SAXException{ boolean isValid = false; try{ - String language = XMLConstants.W3C_XML_SCHEMA_NS_URI; - SchemaFactory factory = SchemaFactory.newInstance(language); - - Source source = new DOMSource(map.getSchema()); - Schema schema = factory.newSchema(source); - Validator validator = schema.newValidator(); - validator.validate(new DOMSource(xml)); - //if no exceptions where raised, the document is valid - isValid=true; - - - }catch(IOException e){ + String language = XMLConstants.W3C_XML_SCHEMA_NS_URI; + SchemaFactory factory = SchemaFactory.newInstance(language); + + Source source = new DOMSource(map.getSchema()); + Schema schema = factory.newSchema(source); + Validator validator = schema.newValidator(); + validator.validate(new DOMSource(xml)); + //if no exceptions where raised, the document is valid + isValid=true; + + + } catch(IOException e) { e.printStackTrace(); } - return isValid; + return isValid; } - - - private void mapCellOnNode(XSSFCell cell, Node node, STXmlDataType.Enum outputDataType){ - - + + + private void mapCellOnNode(XSSFCell cell, Node node, STXmlDataType.Enum outputDataType) { + String value =""; - switch (cell.getCellType()){ - + switch (cell.getCellType()) { + case XSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case XSSFCell.CELL_TYPE_BOOLEAN: value += cell.getBooleanCellValue(); break; case XSSFCell.CELL_TYPE_ERROR: value = cell.getErrorCellString(); break; case XSSFCell.CELL_TYPE_FORMULA: value = cell.getStringCellValue(); break; case XSSFCell.CELL_TYPE_NUMERIC: value += cell.getRawValue(); break; default: ; - + } - if(node instanceof Element){ + if (node instanceof Element) { Element currentElement = (Element) node; currentElement.setTextContent(value); - }else{ + } else { node.setNodeValue(value); - } - - + } } - - private String removeNamespace(String elementName){ + + private String removeNamespace(String elementName) { return elementName.matches(".*:.*")?elementName.split(":")[1]:elementName; } - - - - private Node getNodeByXPath(String xpath,Node rootNode,Document doc,boolean createMultipleInstances){ + + + + private Node getNodeByXPath(String xpath,Node rootNode,Document doc,boolean createMultipleInstances) { String[] xpathTokens = xpath.split("/"); - - + + Node currentNode =rootNode; // The first token is empty, the second is the root node - for(int i =2; i{ String attributeName = axisName.substring(1); NamedNodeMap attributesMap = currentNode.getAttributes(); Node attribute = attributesMap.getNamedItem(attributeName); - if(attribute==null){ + if (attribute==null) { attribute = doc.createAttribute(attributeName); attributesMap.setNamedItem(attribute); } @@ -369,9 +354,9 @@ public class XSSFExportToXml implements Comparator{ private Node createElement(Document doc, Node currentNode, String axisName) { Node selectedNode; - if(isNamespaceDeclared()){ + if (isNamespaceDeclared()) { selectedNode =doc.createElementNS(getNamespace(),axisName); - }else{ + } else { selectedNode =doc.createElement(axisName); } currentNode.appendChild(selectedNode); @@ -380,123 +365,113 @@ public class XSSFExportToXml implements Comparator{ private Node selectNode(String axisName, NodeList list) { Node selectedNode = null; - for(int j=0;j rightIndex){ - result = 1; + }if ( leftIndex > rightIndex) { + result = 1; } - }else{ + } else { // NOTE: the xpath doesn't match correctly in the schema } - - } - } - - - - + return result; } - - private int indexOfElementInComplexType(String elementName,Node complexType){ - + + private int indexOfElementInComplexType(String elementName,Node complexType) { + NodeList list = complexType.getChildNodes(); int indexOf = -1; - - for(int i=0; i< list.getLength();i++){ + + for(int i=0; i< list.getLength();i++) { Node node = list.item(i); - if(node instanceof Element){ - if(node.getLocalName().equals("element")){ + if (node instanceof Element) { + if (node.getLocalName().equals("element")) { Node nameAttribute = node.getAttributes().getNamedItem("name"); - if(nameAttribute.getNodeValue().equals(removeNamespace(elementName))){ + if (nameAttribute.getNodeValue().equals(removeNamespace(elementName))) { indexOf = i; break; } - + } } } - return indexOf; - } - - private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode){ + + private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) { Node complexTypeNode = null; - + String elementNameWithoutNamespace = removeNamespace(elementName); - + NodeList list = localComplexTypeRootNode.getChildNodes(); String complexTypeName = ""; - - - for(int i=0; i< list.getLength();i++){ + + + for(int i=0; i< list.getLength();i++) { Node node = list.item(i); - if( node instanceof Element){ - if(node.getLocalName().equals("element")){ + if ( node instanceof Element) { + if (node.getLocalName().equals("element")) { Node nameAttribute = node.getAttributes().getNamedItem("name"); - if(nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)){ + if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) { Node complexTypeAttribute = node.getAttributes().getNamedItem("type"); - if(complexTypeAttribute!=null){ + if (complexTypeAttribute!=null) { complexTypeName = complexTypeAttribute.getNodeValue(); break; } @@ -505,40 +480,35 @@ public class XSSFExportToXml implements Comparator{ } } // Note: we expect that all the complex types are defined at root level - if(!complexTypeName.equals("")){ + if (!"".equals(complexTypeName)) { NodeList complexTypeList = xmlSchema.getChildNodes(); - for(int i=0; i< complexTypeList.getLength();i++){ + for(int i=0; i< complexTypeList.getLength();i++) { Node node = list.item(i); - if( node instanceof Element){ - if(node.getLocalName().equals("complexType")){ + if ( node instanceof Element) { + if (node.getLocalName().equals("complexType")) { Node nameAttribute = node.getAttributes().getNamedItem("name"); - if(nameAttribute.getNodeValue().equals(complexTypeName)){ - + if (nameAttribute.getNodeValue().equals(complexTypeName)) { + NodeList complexTypeChildList =node.getChildNodes(); - for(int j=0; j imap = new HashMap(); static { for (Borders p : values()) { - imap.put(new Integer(p.getValue()), p); + imap.put(Integer.valueOf(p.getValue()), p); } } public static Borders valueOf(int type) { - Borders pBorder = imap.get(new Integer(type)); + Borders pBorder = imap.get(Integer.valueOf(type)); if (pBorder == null) { throw new IllegalArgumentException("Unknown paragraph border: " + type); } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java index 123fa1165e..5f44cc6381 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/TOC.java @@ -23,13 +23,13 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTabTlc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTheme; public class TOC { - + CTSdtBlock block; - + public TOC() { this(CTSdtBlock.Factory.newInstance()); } - + public TOC(CTSdtBlock block) { this.block = block; CTSdtPr sdtPr = block.addNewSdtPr(); @@ -55,11 +55,11 @@ public class TOC { p.addNewPPr().addNewPStyle().setVal("TOCHeading"); p.addNewR().addNewT().set("Table of Contents"); } - + public CTSdtBlock getBlock() { return this.block; } - + public void addRow(int level, String title, int page, String bookmarkRef) { CTSdtContentBlock contentBlock = this.block.getSdtContent(); CTP p = contentBlock.addNewP(); @@ -96,11 +96,9 @@ public class TOC { // page number run run = p.addNewR(); run.addNewRPr().addNewNoProof(); - run.addNewT().set(new Integer(page).toString()); + run.addNewT().set(Integer.valueOf(page).toString()); run = p.addNewR(); run.addNewRPr().addNewNoProof(); run.addNewFldChar().setFldCharType(STFldCharType.END); - } - } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 6a5f5c1c9b..19faaf0085 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -66,7 +66,7 @@ public class XWPFDocument extends POIXMLDocument { //build a tree of POIXMLDocumentParts, this document being the root load(XWPFFactory.getInstance()); } - + public XWPFDocument(InputStream is) throws IOException { super(PackageHelper.open(is)); @@ -97,7 +97,7 @@ public class XWPFDocument extends POIXMLDocument { initFootnotes(); // filling paragraph list - for (CTP p : body.getPArray()) { + for (CTP p : body.getPArray()) { paragraphs.add(new XWPFParagraph(p, this)); } @@ -128,7 +128,7 @@ public class XWPFDocument extends POIXMLDocument { private void initHyperlinks(){ // Get the hyperlinks // TODO: make me optional/separated in private function - try { + try { Iterator relIter = getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator(); while(relIter.hasNext()) { @@ -164,7 +164,7 @@ public class XWPFDocument extends POIXMLDocument { */ protected static OPCPackage newPackage() { try { - OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile()); + OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile()); // Main part PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName()); // Create main part relationship @@ -355,13 +355,13 @@ public class XWPFDocument extends POIXMLDocument { /** * Create an empty table with one row and one column as default. - * + * * @return a new table */ public XWPFTable createTable(){ return new XWPFTable(this, ctDocument.getBody().addNewTbl()); } - + /** * Create an empty table with a number of rows and cols specified * @param rows @@ -369,26 +369,25 @@ public class XWPFDocument extends POIXMLDocument { * @return table */ public XWPFTable createTable(int rows, int cols) { - return new XWPFTable(this, ctDocument.getBody().addNewTbl(), rows, cols); + return new XWPFTable(this, ctDocument.getBody().addNewTbl(), rows, cols); } - + public void createTOC() { - CTSdtBlock block = this.getDocument().getBody().addNewSdt(); - TOC toc = new TOC(block); - int i = 1; - for (Iterator iterator = getParagraphsIterator() ; iterator.hasNext() ; ) { - XWPFParagraph par = iterator.next(); - String parStyle = par.getStyle(); - if (parStyle != null && parStyle.substring(0, 7).equals("Heading")) { - try { - int level = new Integer(parStyle.substring("Heading".length())); - toc.addRow(level, par.getText(), 1, "112723803"); - } - catch (NumberFormatException e) { - e.printStackTrace(); - } - } - } + CTSdtBlock block = this.getDocument().getBody().addNewSdt(); + TOC toc = new TOC(block); + int i = 1; + for (Iterator iterator = getParagraphsIterator() ; iterator.hasNext() ; ) { + XWPFParagraph par = iterator.next(); + String parStyle = par.getStyle(); + if (parStyle != null && parStyle.substring(0, 7).equals("Heading")) { + try { + int level = Integer.valueOf(parStyle.substring("Heading".length())); + toc.addRow(level, par.getText(), 1, "112723803"); + } + catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } } } - 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 5a1afa6a6a..3a4651d4f6 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java @@ -394,7 +394,7 @@ public final class WordDocument { byte[] chpx = new byte[size]; System.arraycopy(fkp, ++chpxOffset, chpx, 0, size); - //_papTable.put(new Integer(fcStart), papx); + //_papTable.put(Integer.valueOf(fcStart), papx); _characterTable.add(new ChpxNode(fcStart, fcEnd, chpx)); } @@ -734,12 +734,12 @@ public final class WordDocument { lineWidth += 10 * tempString.length();//metrics.stringWidth(tempString); if(lineWidth > pageWidth) { - lineHeights.add(new Integer(maxHeight)); + lineHeights.add(Integer.valueOf(maxHeight)); maxHeight = 0; lineWidth = 0; } } - lineHeights.add(new Integer(maxHeight)); + lineHeights.add(Integer.valueOf(maxHeight)); } int sum = 0; size = lineHeights.size(); diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java index 76ff9b2c37..d9a8d481b1 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/data/ListTables.java @@ -51,14 +51,14 @@ public final class ListTables LFOLVL lfolvl = override._levels[x]; if(lfolvl._fFormatting) { - LST lst = (LST)_lists.get(new Integer(override._lsid)); + LST lst = (LST)_lists.get(Integer.valueOf(override._lsid)); LVL lvl = lfolvl._override; lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); return lvl; } else if(lfolvl._fStartAt) { - LST lst = (LST)_lists.get(new Integer(override._lsid)); + LST lst = (LST)_lists.get(Integer.valueOf(override._lsid)); LVL lvl = lst._levels[level]; LVL newLvl = (LVL)lvl.clone(); newLvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); @@ -68,7 +68,7 @@ public final class ListTables } } - LST lst = (LST)_lists.get(new Integer(override._lsid)); + LST lst = (LST)_lists.get(Integer.valueOf(override._lsid)); LVL lvl = lst._levels[level]; lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); return lvl; @@ -89,7 +89,7 @@ public final class ListTables byte code = plcflst[2 + 26 + (x * 28)]; lst._fSimpleList = StyleSheet.getFlag(code & 0x01); //lstArray[x] = lst; - _lists.put(new Integer(lst._lsid), lst); + _lists.put(Integer.valueOf(lst._lsid), lst); if(lst._fSimpleList) { diff --git a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java index 95ba6fbda8..39e8d1e868 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/extractor/util/BTreeSet.java @@ -161,7 +161,7 @@ public final class BTreeSet extends AbstractSet implements Set { while (temp._entries[0].child != null) { temp = temp._entries[0].child; - parentIndex.push(new Integer(0)); + parentIndex.push(Integer.valueOf(0)); } return temp; @@ -193,11 +193,11 @@ public final class BTreeSet extends AbstractSet implements Set { // else - You're not a leaf so simply find and return the successor of lastReturned currentNode = currentNode._entries[index].child; - parentIndex.push(new Integer(index)); + parentIndex.push(Integer.valueOf(index)); while (currentNode._entries[0].child != null) { currentNode = currentNode._entries[0].child; - parentIndex.push(new Integer(0)); + parentIndex.push(Integer.valueOf(0)); } index = 1; diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java index 1b61045d71..f137944a66 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/HDFObjectFactory.java @@ -345,7 +345,7 @@ public final class HDFObjectFactory { byte[] chpx = new byte[size]; System.arraycopy(fkp, ++chpxOffset, chpx, 0, size); - //_papTable.put(new Integer(fcStart), papx); + //_papTable.put(Integer.valueOf(fcStart), papx); _characterRuns.add(new ChpxNode(fcStart, fcEnd, chpx)); } diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java index e8dbead571..8107210a67 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/hdftypes/ListTables.java @@ -51,14 +51,14 @@ public final class ListTables implements HDFType LFOLVL lfolvl = override._levels[x]; if(lfolvl._fFormatting) { - LST lst = (LST)_lists.get(new Integer(override._lsid)); + LST lst = (LST)_lists.get(Integer.valueOf(override._lsid)); LVL lvl = lfolvl._override; lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); return lvl; } else if(lfolvl._fStartAt) { - LST lst = (LST)_lists.get(new Integer(override._lsid)); + LST lst = (LST)_lists.get(Integer.valueOf(override._lsid)); LVL lvl = lst._levels[level]; LVL newLvl = (LVL)lvl.clone(); newLvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); @@ -68,7 +68,7 @@ public final class ListTables implements HDFType } } - LST lst = (LST)_lists.get(new Integer(override._lsid)); + LST lst = (LST)_lists.get(Integer.valueOf(override._lsid)); LVL lvl = lst._levels[level]; lvl._istd = Utils.convertBytesToShort(lst._rgistd, level * 2); return lvl; @@ -89,7 +89,7 @@ public final class ListTables implements HDFType byte code = plcflst[2 + 26 + (x * 28)]; lst._fSimpleList = StyleSheet.getFlag(code & 0x01); //lstArray[x] = lst; - _lists.put(new Integer(lst._lsid), lst); + _lists.put(Integer.valueOf(lst._lsid), lst); if(lst._fSimpleList) { diff --git a/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java b/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java index 994fe09868..a9241f914e 100644 --- a/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java +++ b/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java @@ -235,7 +235,7 @@ public final class BTreeSet extends AbstractSet while (temp.entries[0].child != null) { temp = temp.entries[0].child; - parentIndex.push(new Integer(0)); + parentIndex.push(Integer.valueOf(0)); } return temp; @@ -272,12 +272,12 @@ public final class BTreeSet extends AbstractSet // else - You're not a leaf so simply find and return the successor of lastReturned currentNode = currentNode.entries[index].child; - parentIndex.push(new Integer(index)); + parentIndex.push(Integer.valueOf(index)); while (currentNode.entries[0].child != null) { currentNode = currentNode.entries[0].child; - parentIndex.push(new Integer(0)); + parentIndex.push(Integer.valueOf(0)); } index = 1; diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java index bb37e47b18..64314ee5f0 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java @@ -166,10 +166,10 @@ public final class Chunk { // Types 0->7 = a flat at bit 0->7 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: int val = contents[offset] & (1< 0) ); + command.value = Boolean.valueOf(val > 0); break; case 8: - command.value = new Byte( contents[offset] ); + command.value = Byte.valueOf(contents[offset]); break; case 9: command.value = new Double( @@ -195,12 +195,12 @@ public final class Chunk { command.value = StringUtil.getFromUnicodeLE(contents, startsAt, strLen); break; case 25: - command.value = new Short( + command.value = Short.valueOf( LittleEndian.getShort(contents, offset) ); break; case 26: - command.value = new Integer( + command.value = Integer.valueOf( LittleEndian.getInt(contents, offset) ); break; @@ -273,7 +273,7 @@ public final class Chunk { } private void setOffset(int offset) { this.offset = offset; - value = new Integer(offset); + value = Integer.valueOf(offset); } } } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index d2779c88b0..3bc35883d6 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -98,7 +98,7 @@ public final class ChunkFactory { defsL.toArray(new CommandDefinition[defsL.size()]); // Add to the hashtable - chunkCommandDefinitions.put(new Integer(chunkType), defs); + chunkCommandDefinitions.put(Integer.valueOf(chunkType), defs); } inp.close(); cpd.close(); @@ -171,7 +171,7 @@ public final class ChunkFactory { // Feed in the stuff from chunks_parse_cmds.tbl CommandDefinition[] defs = (CommandDefinition[]) - chunkCommandDefinitions.get(new Integer(header.getType())); + chunkCommandDefinitions.get(Integer.valueOf(header.getType())); if(defs == null) defs = new CommandDefinition[0]; chunk.commandDefinitions = defs; diff --git a/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java index c5e01646a8..00152134f6 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/EncryptedSlideShow.java @@ -117,7 +117,7 @@ public final class EncryptedSlideShow int offset = ( (Integer)pph.getSlideLocationsLookup().get( - new Integer(maxSlideId) + Integer.valueOf(maxSlideId) ) ).intValue(); Record r3 = Record.buildRecordAtOffset( hss.getUnderlyingBytes(), diff --git a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java index df4d291f51..17d999991f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java @@ -231,11 +231,11 @@ public final class HSLFSlideShow extends POIDocument { HashMap offset2id = new HashMap(); while (usrOffset != 0){ UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset); - lst.add(new Integer(usrOffset)); + lst.add(Integer.valueOf(usrOffset)); int psrOffset = usr.getPersistPointersOffset(); PersistPtrHolder ptr = (PersistPtrHolder)Record.buildRecordAtOffset(docstream, psrOffset); - lst.add(new Integer(psrOffset)); + lst.add(Integer.valueOf(psrOffset)); Hashtable entries = ptr.getSlideLocationsLookup(); for (Iterator it = entries.keySet().iterator(); it.hasNext(); ) { Integer id = (Integer)it.next(); @@ -401,7 +401,7 @@ public final class HSLFSlideShow extends POIDocument { int oldPos = pdr.getLastOnDiskOffset(); int newPos = baos.size(); pdr.setLastOnDiskOffset(newPos); - oldToNewPositions.put(new Integer(oldPos),new Integer(newPos)); + oldToNewPositions.put(Integer.valueOf(oldPos),Integer.valueOf(newPos)); //System.out.println(oldPos + " -> " + newPos); } @@ -438,7 +438,7 @@ public final class HSLFSlideShow extends POIDocument { // Update and write out the Current User atom int oldLastUserEditAtomPos = (int)currentUser.getCurrentEditOffset(); - Integer newLastUserEditAtomPos = (Integer)oldToNewPositions.get(new Integer(oldLastUserEditAtomPos)); + Integer newLastUserEditAtomPos = (Integer)oldToNewPositions.get(Integer.valueOf(oldLastUserEditAtomPos)); if(newLastUserEditAtomPos == null) { throw new HSLFException("Couldn't find the new location of the UserEditAtom that used to be at " + oldLastUserEditAtomPos); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java index 584ee1f29a..48d8352eaf 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java @@ -124,7 +124,7 @@ public final class SlideIdListing { int[] sheetIDs = pph.getKnownSlideIDs(); Hashtable sheetOffsets = pph.getSlideLocationsLookup(); for(int j=0; jnull */ public String getText() { return StringUtil.getFromUnicodeLE(_text); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java index 4a32d76e0b..cc514ed46d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -98,10 +98,10 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom System.arraycopy(_ptrData,0,newPtrData,0,_ptrData.length); // Add to the slide location lookup hash - _slideLocations.put(new Integer(slideID), new Integer(posOnDisk)); + _slideLocations.put(Integer.valueOf(slideID), Integer.valueOf(posOnDisk)); // Add to the ptrData offset lookup hash - _slideOffsetDataLocation.put(new Integer(slideID), - new Integer(_ptrData.length + 4)); + _slideOffsetDataLocation.put(Integer.valueOf(slideID), + Integer.valueOf(_ptrData.length + 4)); // Build the info block // First 20 bits = offset number = slide ID @@ -163,8 +163,8 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom for(int i=0; i 0) { @@ -160,7 +160,7 @@ public final class FIBFieldHandler { UnhandledDataStructure unhandled = new UnhandledDataStructure( tableStream, dsOffset, dsSize); - _unknownMap.put(new Integer(x), unhandled); + _unknownMap.put(Integer.valueOf(x), unhandled); } } } @@ -208,7 +208,7 @@ public final class FIBFieldHandler for (int x = 0; x < length; x++) { - UnhandledDataStructure ds = (UnhandledDataStructure)_unknownMap.get(new Integer(x)); + UnhandledDataStructure ds = (UnhandledDataStructure)_unknownMap.get(Integer.valueOf(x)); if (ds != null) { LittleEndian.putInt(mainStream, offset, tableStream.getOffset()); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java index 5f25e8bb59..b1578e3869 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java @@ -48,13 +48,13 @@ public final class FSPATable FSPA fspa = new FSPA(property.getBytes(), 0); _shapes.add(fspa); - _shapeIndexesByPropertyStart.put(new Integer(property.getStart()), new Integer(i)); + _shapeIndexesByPropertyStart.put(Integer.valueOf(property.getStart()), Integer.valueOf(i)); } } public FSPA getFspaFromCp(int cp) { - Integer idx = (Integer)_shapeIndexesByPropertyStart.get(new Integer(cp)); + Integer idx = (Integer)_shapeIndexesByPropertyStart.get(Integer.valueOf(cp)); if (idx == null) { return null; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index 01b95354b3..6c09b49aca 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -58,18 +58,18 @@ public final class FileInformationBlock extends FIBAbstractType public void fillVariableFields(byte[] mainDocument, byte[] tableStream) { HashSet fieldSet = new HashSet(); - fieldSet.add(new Integer(FIBFieldHandler.STSHF)); - fieldSet.add(new Integer(FIBFieldHandler.CLX)); - fieldSet.add(new Integer(FIBFieldHandler.DOP)); - fieldSet.add(new Integer(FIBFieldHandler.PLCFBTECHPX)); - fieldSet.add(new Integer(FIBFieldHandler.PLCFBTEPAPX)); - fieldSet.add(new Integer(FIBFieldHandler.PLCFSED)); - fieldSet.add(new Integer(FIBFieldHandler.PLCFLST)); - fieldSet.add(new Integer(FIBFieldHandler.PLFLFO)); - fieldSet.add(new Integer(FIBFieldHandler.PLCFFLDMOM)); - fieldSet.add(new Integer(FIBFieldHandler.STTBFFFN)); - fieldSet.add(new Integer(FIBFieldHandler.STTBSAVEDBY)); - fieldSet.add(new Integer(FIBFieldHandler.MODIFIED)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.STSHF)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.CLX)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.DOP)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFBTECHPX)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFBTEPAPX)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFSED)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFLST)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.PLFLFO)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.PLCFFLDMOM)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBFFFN)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.STTBSAVEDBY)); + fieldSet.add(Integer.valueOf(FIBFieldHandler.MODIFIED)); _shortHandler = new FIBShortHandler(mainDocument); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java index 45e9fabc3d..fd72d42270 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java @@ -58,7 +58,7 @@ public final class ListTables for (int x = 0; x < length; x++) { ListData lst = new ListData(tableStream, lstOffset); - _listMap.put(new Integer(lst.getLsid()), lst); + _listMap.put(Integer.valueOf(lst.getLsid()), lst); lstOffset += LIST_DATA_SIZE; int num = lst.numLevels(); @@ -96,12 +96,12 @@ public final class ListTables public int addList(ListData lst, ListFormatOverride override) { int lsid = lst.getLsid(); - while (_listMap.get(new Integer(lsid)) != null) + while (_listMap.get(Integer.valueOf(lsid)) != null) { lsid = lst.resetListID(); override.setLsid(lsid); } - _listMap.put(new Integer(lsid), lst); + _listMap.put(Integer.valueOf(lsid), lst); _overrideList.add(override); return lsid; } @@ -190,7 +190,7 @@ public final class ListTables public ListLevel getLevel(int listID, int level) { - ListData lst = (ListData)_listMap.get(new Integer(listID)); + ListData lst = (ListData)_listMap.get(Integer.valueOf(listID)); if(level < lst.numLevels()) { ListLevel lvl = lst.getLevels()[level]; return lvl; @@ -201,7 +201,7 @@ public final class ListTables public ListData getListData(int listID) { - return (ListData) _listMap.get(new Integer(listID)); + return (ListData) _listMap.get(Integer.valueOf(listID)); } public boolean equals(Object obj) 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 fc0fdf813e..c53daff04f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -400,12 +400,12 @@ public final class ParagraphSprmUncompressor HashMap tabMap = new HashMap(); for (int x = 0; x < tabPositions.length; x++) { - tabMap.put(new Integer(tabPositions[x]), new Byte(tabDescriptors[x])); + tabMap.put(Integer.valueOf(tabPositions[x]), Byte.valueOf(tabDescriptors[x])); } for (int x = 0; x < delSize; x++) { - tabMap.remove(new Integer(LittleEndian.getShort(grpprl, offset))); + tabMap.remove(Integer.valueOf(LittleEndian.getShort(grpprl, offset))); offset += LittleEndian.SHORT_SIZE; } @@ -413,8 +413,8 @@ public final class ParagraphSprmUncompressor int start = offset; for (int x = 0; x < addSize; x++) { - Integer key = new Integer(LittleEndian.getShort(grpprl, offset)); - Byte val = new Byte(grpprl[start + ((LittleEndian.SHORT_SIZE * addSize) + x)]); + Integer key = Integer.valueOf(LittleEndian.getShort(grpprl, offset)); + Byte val = Byte.valueOf(grpprl[start + ((LittleEndian.SHORT_SIZE * addSize) + x)]); tabMap.put(key, val); offset += LittleEndian.SHORT_SIZE; } @@ -452,20 +452,20 @@ public final class ParagraphSprmUncompressor // HashMap tabMap = new HashMap(); // for (int x = 0; x < tabPositions.length; x++) // { -// tabMap.put(new Integer(tabPositions[x]), new Byte(tabDescriptors[x])); +// tabMap.put(Integer.valueOf(tabPositions[x]), Byte.valueOf(tabDescriptors[x])); // } // // for (int x = 0; x < delSize; x++) // { -// tabMap.remove(new Integer(LittleEndian.getInt(grpprl, offset))); +// tabMap.remove(Integer.valueOf(LittleEndian.getInt(grpprl, offset))); // offset += LittleEndian.INT_SIZE;; // } // // int addSize = grpprl[offset++]; // for (int x = 0; x < addSize; x++) // { -// Integer key = new Integer(LittleEndian.getInt(grpprl, offset)); -// Byte val = new Byte(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]); +// Integer key = Integer.valueOf(LittleEndian.getInt(grpprl, offset)); +// Byte val = Byte.valueOf(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]); // tabMap.put(key, val); // offset += LittleEndian.INT_SIZE; // } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java index 4590e551ce..ae76116a41 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java @@ -59,16 +59,16 @@ public final class TestReWriteSanity extends TestCase { Record[] r = wss.getRecords(); Hashtable pp = new Hashtable(); Hashtable ue = new Hashtable(); - ue.put(new Integer(0),new Integer(0)); // Will show 0 if first + ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first int pos = 0; int lastUEPos = -1; for(int i=0; i notesMap = new HashMap(); - notesMap.put(new Integer(4), "For decades before calculators"); - notesMap.put(new Integer(5), "Several commercial applications"); - notesMap.put(new Integer(6), "There are three variations of LNS that are discussed here"); - notesMap.put(new Integer(7), "Although multiply and square root are easier"); - notesMap.put(new Integer(8), "The bus Z is split into Z_H and Z_L"); + notesMap.put(Integer.valueOf(4), "For decades before calculators"); + notesMap.put(Integer.valueOf(5), "Several commercial applications"); + notesMap.put(Integer.valueOf(6), "There are three variations of LNS that are discussed here"); + notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier"); + notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L"); Slide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++) { - Integer slideNumber = new Integer(slide[i].getSlideNumber()); + Integer slideNumber = Integer.valueOf(slide[i].getSlideNumber()); Notes notes = slide[i].getNotesSheet(); if (notesMap.containsKey(slideNumber)){ assertNotNull(notes); diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java index 8d94d2df6e..63bde0c2de 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java @@ -43,117 +43,80 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java * This class tests reading and writing of meta data. No actual document is created. All information - * is stored in a virtal document in a ByteArrayOutputStream + * is stored in a virtual document in a ByteArrayOutputStream * @author Matthias G\u00fcnter */ -public class TestMetaDataIPI extends TestCase{ - - private ByteArrayOutputStream bout= null; //our store - private POIFSFileSystem poifs=null; - DirectoryEntry dir = null; - DocumentSummaryInformation dsi=null; - SummaryInformation si=null; - - - - /** - * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the - * SummaryInformation to reasonable values - */ - public void setUp(){ - bout=new ByteArrayOutputStream(); - poifs= new POIFSFileSystem(); - dir = poifs.getRoot(); - dsi=null; - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - dsi = new DocumentSummaryInformation(ps); - - - } - catch (FileNotFoundException ex) - { - /* There is no document summary information yet. We have to create a - * new one. */ - dsi = PropertySetFactory.newDocumentSummaryInformation(); - assertNotNull(dsi); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } catch (NoPropertySetStreamException e) { - e.printStackTrace(); - fail(); - } catch (MarkUnsupportedException e) { - e.printStackTrace(); - fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); - fail(); - } - assertNotNull(dsi); - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - si = new SummaryInformation(ps); - - - } - catch (FileNotFoundException ex) - { - /* There is no document summary information yet. We have to create a - * new one. */ - si = PropertySetFactory.newSummaryInformation(); - assertNotNull(si); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } catch (NoPropertySetStreamException e) { - e.printStackTrace(); - fail(); - } catch (MarkUnsupportedException e) { - e.printStackTrace(); - fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); - fail(); +public final class TestMetaDataIPI extends TestCase{ + + private ByteArrayOutputStream bout; //our store + private POIFSFileSystem poifs; + private DirectoryEntry dir; + private DocumentSummaryInformation dsi; + private SummaryInformation si; + + + + /** + * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the + * SummaryInformation to reasonable values + */ + public void setUp() { + bout = new ByteArrayOutputStream(); + poifs = new POIFSFileSystem(); + dir = poifs.getRoot(); + dsi = null; + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + dsi = new DocumentSummaryInformation(ps); + + } catch (FileNotFoundException ex) { + /* + * There is no document summary information yet. We have to create a + * new one. + */ + dsi = PropertySetFactory.newDocumentSummaryInformation(); + assertNotNull(dsi); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + assertNotNull(dsi); + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(SummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + si = new SummaryInformation(ps); + + } catch (FileNotFoundException ex) { + /* + * There is no document summary information yet. We have to create a + * new one. + */ + si = PropertySetFactory.newSummaryInformation(); + assertNotNull(si); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + assertNotNull(dsi); } - assertNotNull(dsi); - - - } - - /** - * Setting a lot of things to null. - */ - public void tearDown(){ - bout=null; - poifs=null; - dir=null; - dsi=null; - - } - - - /** - * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream. - * When finished writing information this method is used in the tests to - * start reading from the created document and then the see if the results match. - * - */ - public void closeAndReOpen(){ - - try { + + /** + * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream. + * When finished writing information this method is used in the tests to + * start reading from the created document and then the see if the results match. + */ + public void closeAndReOpen() { + + try { dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME); - si.write(dir,SummaryInformation.DEFAULT_STREAM_NAME); + si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME); } catch (WritingNotSupportedException e) { e.printStackTrace(); fail(); @@ -162,659 +125,592 @@ public class TestMetaDataIPI extends TestCase{ fail(); } - si=null; - dsi=null; + si = null; + dsi = null; try { - poifs.writeFilesystem(bout); bout.flush(); - } catch (IOException e) { - e.printStackTrace(); fail(); } - - InputStream is=new ByteArrayInputStream(bout.toByteArray()); - assertNotNull(is); - POIFSFileSystem poifs=null; + + InputStream is = new ByteArrayInputStream(bout.toByteArray()); + assertNotNull(is); + POIFSFileSystem poifs = null; try { poifs = new POIFSFileSystem(is); } catch (IOException e) { - e.printStackTrace(); fail(); } - try { + try { is.close(); } catch (IOException e) { e.printStackTrace(); fail(); } - assertNotNull(poifs); - /* Read the document summary information. */ - DirectoryEntry dir = poifs.getRoot(); - - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - dsi = new DocumentSummaryInformation(ps); - } - catch (FileNotFoundException ex) - { - fail(); - } catch (IOException e) { - e.printStackTrace(); + assertNotNull(poifs); + /* Read the document summary information. */ + DirectoryEntry dir = poifs.getRoot(); + + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + dsi = new DocumentSummaryInformation(ps); + } catch (FileNotFoundException ex) { fail(); - } catch (NoPropertySetStreamException e) { + } catch (Exception e) { e.printStackTrace(); fail(); - } catch (MarkUnsupportedException e) { + } + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(SummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + si = new SummaryInformation(ps); + + } catch (FileNotFoundException ex) { + /* + * There is no document summary information yet. We have to create a + * new one. + */ + si = PropertySetFactory.newSummaryInformation(); + assertNotNull(si); + } catch (Exception e) { e.printStackTrace(); fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); + } + } + + /** + * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it + */ + public void testOne() { + + // DocumentSummaryInformation + dsi.setCompany("xxxCompanyxxx"); + dsi.setManager("xxxManagerxxx"); + dsi.setCategory("xxxCategoryxxx"); + + // SummaryInformation + si.setTitle("xxxTitlexxx"); + si.setAuthor("xxxAuthorxxx"); + si.setComments("xxxCommentsxxx"); + si.setKeywords("xxxKeyWordsxxx"); + si.setSubject("xxxSubjectxxx"); + + // Custom Properties (in DocumentSummaryInformation + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put("Key1", "Value1"); + customProperties.put("Schl\u00fcssel2", "Wert2"); + customProperties.put("Sample Integer", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.TRUE); + Date date = new Date(); + customProperties.put("Sample Date", date); + customProperties.put("Sample Double", new Double(-1.0001)); + customProperties.put("Sample Negative Integer", new Integer(-100000)); + + dsi.setCustomProperties(customProperties); + + // start reading + closeAndReOpen(); + + // testing + assertNotNull(dsi); + assertNotNull(si); + + assertEquals("Category", "xxxCategoryxxx", dsi.getCategory()); + assertEquals("Company", "xxxCompanyxxx", dsi.getCompany()); + assertEquals("Manager", "xxxManagerxxx", dsi.getManager()); + + assertEquals("", "xxxAuthorxxx", si.getAuthor()); + assertEquals("", "xxxTitlexxx", si.getTitle()); + assertEquals("", "xxxCommentsxxx", si.getComments()); + assertEquals("", "xxxKeyWordsxxx", si.getKeywords()); + assertEquals("", "xxxSubjectxxx", si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { fail(); } - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - si = new SummaryInformation(ps); - - - } - catch (FileNotFoundException ex) - { - /* There is no document summary information yet. We have to create a - * new one. */ - si = PropertySetFactory.newSummaryInformation(); - assertNotNull(si); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } catch (NoPropertySetStreamException e) { - e.printStackTrace(); - fail(); - } catch (MarkUnsupportedException e) { - e.printStackTrace(); - fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); - fail(); - } - } - - /** - * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it - * - */ - public void testOne(){ - - //DocumentSummaryInformation - dsi.setCompany("xxxCompanyxxx"); - dsi.setManager("xxxManagerxxx"); - dsi.setCategory("xxxCategoryxxx"); - - //SummaryInformation - si.setTitle("xxxTitlexxx"); - si.setAuthor("xxxAuthorxxx"); - si.setComments("xxxCommentsxxx"); - si.setKeywords("xxxKeyWordsxxx"); - si.setSubject("xxxSubjectxxx"); - - //Custom Properties (in DocumentSummaryInformation - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put("Key1", "Value1"); - customProperties.put("Schl\u00fcssel2", "Wert2"); - customProperties.put("Sample Integer", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); - Date date=new Date(); - customProperties.put("Sample Date", date); - customProperties.put("Sample Double", new Double(-1.0001)); - customProperties.put("Sample Negative Integer", new Integer(-100000)); - - dsi.setCustomProperties(customProperties); - - //start reading - closeAndReOpen(); - - //testing - assertNotNull(dsi); - assertNotNull(si); - - assertEquals("Category","xxxCategoryxxx",dsi.getCategory()); - assertEquals("Company","xxxCompanyxxx",dsi.getCompany()); - assertEquals("Manager","xxxManagerxxx",dsi.getManager()); - - assertEquals("","xxxAuthorxxx",si.getAuthor()); - assertEquals("","xxxTitlexxx",si.getTitle()); - assertEquals("","xxxCommentsxxx",si.getComments()); - assertEquals("","xxxKeyWordsxxx",si.getKeywords()); - assertEquals("","xxxSubjectxxx",si.getSubject()); - - - /* Read the custom properties. If there are no custom properties yet, - * the application has to create a new CustomProperties object. It will - * serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - String a1=(String) customProperties.get("Key1"); - assertEquals("Key1","Value1",a1); - String a2=(String) customProperties.get("Schl\u00fcssel2"); - assertEquals("Schl\u00fcssel2","Wert2",a2); - Integer a3=(Integer) customProperties.get("Sample Integer"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(true),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); - - Double a6=(Double) customProperties.get("Sample Double"); - assertEquals("Custom Float",new Double(-1.0001),a6); - - Integer a7=(Integer) customProperties.get("Sample Negative Integer"); - assertEquals("Neg", new Integer(-100000),a7); - } - - - /** - * multiplies a string - * @param s Input String - * @return the multiplied String - */ - public String elongate(String s){ - StringBuffer sb=new StringBuffer(); - for (int i=0;i<10000;i++){ - sb.append(s); - sb.append(" "); - } - return sb.toString(); - } - - - - /** - * Test very long input in each of the fields (approx 30-60KB each) - * - */ -public void testTwo(){ - - String company=elongate("company"); - String manager=elongate("manager"); - String category=elongate("category"); - String title=elongate("title"); - String author=elongate("author"); - String comments=elongate("comments"); - String keywords=elongate("keywords"); - String subject=elongate("subject"); - String p1=elongate("p1"); - String p2=elongate("p2"); - String k1=elongate("k1"); - String k2=elongate("k2"); - - dsi.setCompany(company); - dsi.setManager(manager); - dsi.setCategory(category); - - si.setTitle(title); - si.setAuthor(author); - si.setComments(comments); - si.setKeywords(keywords); - si.setSubject(subject); - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put(k1, p1); - customProperties.put(k2, p2); - customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); - Date date=new Date(); - customProperties.put("Sample Date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertEquals("Category",category,dsi.getCategory()); - assertEquals("Company",company,dsi.getCompany()); - assertEquals("Manager",manager,dsi.getManager()); - - assertEquals("",author,si.getAuthor()); - assertEquals("",title,si.getTitle()); - assertEquals("",comments,si.getComments()); - assertEquals("",keywords,si.getKeywords()); - assertEquals("",subject,si.getSubject()); - - - /* Read the custom properties. If there are no custom properties - * yet, the application has to create a new CustomProperties object. - * It will serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - String a1=(String) customProperties.get(k1); - assertEquals("Key1",p1,a1); - String a2=(String) customProperties.get(k2); - assertEquals("Schl\u00fcssel2",p2,a2); - Integer a3=(Integer) customProperties.get("Sample Number"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(true),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); + /* Insert some custom properties into the container. */ + String a1 = (String) customProperties.get("Key1"); + assertEquals("Key1", "Value1", a1); + String a2 = (String) customProperties.get("Schl\u00fcssel2"); + assertEquals("Schl\u00fcssel2", "Wert2", a2); + Integer a3 = (Integer) customProperties.get("Sample Integer"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.TRUE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); + + Double a6 = (Double) customProperties.get("Sample Double"); + assertEquals("Custom Float", new Double(-1.0001), a6); + + Integer a7 = (Integer) customProperties.get("Sample Negative Integer"); + assertEquals("Neg", new Integer(-100000), a7); + } + /** + * multiplies a string + * @param s Input String + * @return the multiplied String + */ + private static String elongate(String s) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < 10000; i++) { + sb.append(s); + sb.append(" "); + } + return sb.toString(); } - -/** - * adds strange characters to the string - * @param s Input String - * @return the multiplied String - */ -public String strangize(String s){ - StringBuffer sb=new StringBuffer(); - String[] umlaute= {"\u00e4","\u00fc","\u00f6","\u00dc","$","\u00d6","\u00dc","\u00c9","\u00d6","@","\u00e7","&"}; - char j=0; - Random rand=new Random(); - for (int i=0;i<5;i++){ - sb.append(s); - sb.append(" "); - j=(char) rand.nextInt(220); - j+=33; - // System.out.println(j); - sb.append(">"); - sb.append(new Character(j)); - sb.append("="); - sb.append(umlaute[rand.nextInt(umlaute.length)]); - sb.append("<"); - } - - return sb.toString(); -} + /** + * Test very long input in each of the fields (approx 30-60KB each) + */ + public void testTwo() { + + String company = elongate("company"); + String manager = elongate("manager"); + String category = elongate("category"); + String title = elongate("title"); + String author = elongate("author"); + String comments = elongate("comments"); + String keywords = elongate("keywords"); + String subject = elongate("subject"); + String p1 = elongate("p1"); + String p2 = elongate("p2"); + String k1 = elongate("k1"); + String k2 = elongate("k2"); + + dsi.setCompany(company); + dsi.setManager(manager); + dsi.setCategory(category); + + si.setTitle(title); + si.setAuthor(author); + si.setComments(comments); + si.setKeywords(keywords); + si.setSubject(subject); + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + /* Insert some custom properties into the container. */ + customProperties.put(k1, p1); + customProperties.put(k2, p2); + customProperties.put("Sample Number", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.TRUE); + Date date = new Date(); + customProperties.put("Sample Date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertEquals("Category", category, dsi.getCategory()); + assertEquals("Company", company, dsi.getCompany()); + assertEquals("Manager", manager, dsi.getManager()); + + assertEquals("", author, si.getAuthor()); + assertEquals("", title, si.getTitle()); + assertEquals("", comments, si.getComments()); + assertEquals("", keywords, si.getKeywords()); + assertEquals("", subject, si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } -/** - * Tests with strange characters in keys and data (Umlaute etc.) - * - */ -public void testThree(){ - - String company=strangize("company"); - String manager=strangize("manager"); - String category=strangize("category"); - String title=strangize("title"); - String author=strangize("author"); - String comments=strangize("comments"); - String keywords=strangize("keywords"); - String subject=strangize("subject"); - String p1=strangize("p1"); - String p2=strangize("p2"); - String k1=strangize("k1"); - String k2=strangize("k2"); - - dsi.setCompany(company); - dsi.setManager(manager); - dsi.setCategory(category); - - si.setTitle(title); - si.setAuthor(author); - si.setComments(comments); - si.setKeywords(keywords); - si.setSubject(subject); - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put(k1, p1); - customProperties.put(k2, p2); - customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(false)); - Date date=new Date(0); - customProperties.put("Sample Date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertEquals("Category",category,dsi.getCategory()); - assertEquals("Company",company,dsi.getCompany()); - assertEquals("Manager",manager,dsi.getManager()); - - assertEquals("",author,si.getAuthor()); - assertEquals("",title,si.getTitle()); - assertEquals("",comments,si.getComments()); - assertEquals("",keywords,si.getKeywords()); - assertEquals("",subject,si.getSubject()); - - - /* Read the custom properties. If there are no custom properties yet, - * the application has to create a new CustomProperties object. It will - * serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - // System.out.println(k1); - String a1=(String) customProperties.get(k1); - assertEquals("Key1",p1,a1); - String a2=(String) customProperties.get(k2); - assertEquals("Schl\u00fcssel2",p2,a2); - Integer a3=(Integer) customProperties.get("Sample Number"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(false),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); - + /* Insert some custom properties into the container. */ + String a1 = (String) customProperties.get(k1); + assertEquals("Key1", p1, a1); + String a2 = (String) customProperties.get(k2); + assertEquals("Schl\u00fcssel2", p2, a2); + Integer a3 = (Integer) customProperties.get("Sample Number"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.TRUE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); } - - /** - * Iterative testing: writing, reading etc. - * - */ - public void testFour(){ - for (int i=1;i<100;i++){ - setUp(); - testThree(); - tearDown(); - } - } - - - /** - * adds strange characters to the string with the adding of unicode characters - * @param s Input String - * @return the multiplied String - */ - public String strangizeU(String s){ - - StringBuffer sb=new StringBuffer(); - String[] umlaute= {"\u00e4","\u00fc","\u00f6","\u00dc","$","\u00d6","\u00dc","\u00c9","\u00d6","@","\u00e7","&"}; - char j=0; - Random rand=new Random(); - for (int i=0;i<5;i++){ - sb.append(s); - sb.append(" "); - j=(char) rand.nextInt(220); - j+=33; - // System.out.println(j); - sb.append(">"); - sb.append(new Character(j)); - sb.append("="); - sb.append(umlaute[rand.nextInt(umlaute.length)]); - sb.append("<"); - } - sb.append("\u00e4\u00f6\u00fc\uD840\uDC00"); - return sb.toString(); - } - /** - * Unicode test - * - */ - public void testUnicode(){ - String company=strangizeU("company"); - String manager=strangizeU("manager"); - String category=strangizeU("category"); - String title=strangizeU("title"); - String author=strangizeU("author"); - String comments=strangizeU("comments"); - String keywords=strangizeU("keywords"); - String subject=strangizeU("subject"); - String p1=strangizeU("p1"); - String p2=strangizeU("p2"); - String k1=strangizeU("k1"); - String k2=strangizeU("k2"); - - dsi.setCompany(company); - dsi.setManager(manager); - dsi.setCategory(category); - - si.setTitle(title); - si.setAuthor(author); - si.setComments(comments); - si.setKeywords(keywords); - si.setSubject(subject); - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put(k1, p1); - customProperties.put(k2, p2); - customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); - Date date=new Date(); - customProperties.put("Sample Date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertEquals("Category",category,dsi.getCategory()); - assertEquals("Company",company,dsi.getCompany()); - assertEquals("Manager",manager,dsi.getManager()); - - assertEquals("",author,si.getAuthor()); - assertEquals("",title,si.getTitle()); - assertEquals("",comments,si.getComments()); - assertEquals("",keywords,si.getKeywords()); - assertEquals("",subject,si.getSubject()); - - - /* Read the custom properties. If there are no custom properties yet, - * the application has to create a new CustomProperties object. It will - * serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - // System.out.println(k1); - String a1=(String) customProperties.get(k1); - assertEquals("Key1",p1,a1); - String a2=(String) customProperties.get(k2); - assertEquals("Schl\u00fcssel2",p2,a2); - Integer a3=(Integer) customProperties.get("Sample Number"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(true),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); - - - - } - - - /** - * Iterative testing of the unicode test - * + + /** + * adds strange characters to the string + * @param s Input String + * @return the multiplied String + */ + private static String strangize(String s) { + StringBuffer sb = new StringBuffer(); + String[] umlaute = { "\u00e4", "\u00fc", "\u00f6", "\u00dc", "$", "\u00d6", "\u00dc", + "\u00c9", "\u00d6", "@", "\u00e7", "&" }; + char j = 0; + Random rand = new Random(0); // TODO - no Random - tests should be completely deterministic + for (int i = 0; i < 5; i++) { + sb.append(s); + sb.append(" "); + j = (char) rand.nextInt(220); + j += 33; + // System.out.println(j); + sb.append(">"); + sb.append(new Character(j)); + sb.append("="); + sb.append(umlaute[rand.nextInt(umlaute.length)]); + sb.append("<"); + } + + return sb.toString(); + } + + + /** + * Tests with strange characters in keys and data (Umlaute etc.) + */ + public void testThree() { + + String company = strangize("company"); + String manager = strangize("manager"); + String category = strangize("category"); + String title = strangize("title"); + String author = strangize("author"); + String comments = strangize("comments"); + String keywords = strangize("keywords"); + String subject = strangize("subject"); + String p1 = strangize("p1"); + String p2 = strangize("p2"); + String k1 = strangize("k1"); + String k2 = strangize("k2"); + + dsi.setCompany(company); + dsi.setManager(manager); + dsi.setCategory(category); + + si.setTitle(title); + si.setAuthor(author); + si.setComments(comments); + si.setKeywords(keywords); + si.setSubject(subject); + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put(k1, p1); + customProperties.put(k2, p2); + customProperties.put("Sample Number", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.FALSE); + Date date = new Date(0); + customProperties.put("Sample Date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertEquals("Category", category, dsi.getCategory()); + assertEquals("Company", company, dsi.getCompany()); + assertEquals("Manager", manager, dsi.getManager()); + + assertEquals("", author, si.getAuthor()); + assertEquals("", title, si.getTitle()); + assertEquals("", comments, si.getComments()); + assertEquals("", keywords, si.getKeywords()); + assertEquals("", subject, si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } + + /* Insert some custom properties into the container. */ + // System.out.println(k1); + String a1 = (String) customProperties.get(k1); + assertEquals("Key1", p1, a1); + String a2 = (String) customProperties.get(k2); + assertEquals("Schl\u00fcssel2", p2, a2); + Integer a3 = (Integer) customProperties.get("Sample Number"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.FALSE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); + + } + + /** + * Iterative testing: writing, reading etc. + */ + public void testFour() { + for (int i = 1; i < 100; i++) { + setUp(); + testThree(); + } + } + + + + /** + * adds strange characters to the string with the adding of unicode characters + * @param s Input String + * @return the multiplied String */ - public void testSix(){ - for (int i=1;i<100;i++){ - setUp(); - testUnicode(); - tearDown(); - } - } - + private static String strangizeU(String s) { + + StringBuffer sb = new StringBuffer(); + String[] umlaute = { "\u00e4", "\u00fc", "\u00f6", "\u00dc", "$", "\u00d6", "\u00dc", + "\u00c9", "\u00d6", "@", "\u00e7", "&" }; + char j = 0; + Random rand = new Random(0); // TODO - no Random - tests should be completely deterministic + for (int i = 0; i < 5; i++) { + sb.append(s); + sb.append(" "); + j = (char) rand.nextInt(220); + j += 33; + // System.out.println(j); + sb.append(">"); + sb.append(new Character(j)); + sb.append("="); + sb.append(umlaute[rand.nextInt(umlaute.length)]); + sb.append("<"); + } + sb.append("\u00e4\u00f6\u00fc\uD840\uDC00"); + return sb.toString(); + } + + /** + * Unicode test + */ + public void testUnicode() { + String company = strangizeU("company"); + String manager = strangizeU("manager"); + String category = strangizeU("category"); + String title = strangizeU("title"); + String author = strangizeU("author"); + String comments = strangizeU("comments"); + String keywords = strangizeU("keywords"); + String subject = strangizeU("subject"); + String p1 = strangizeU("p1"); + String p2 = strangizeU("p2"); + String k1 = strangizeU("k1"); + String k2 = strangizeU("k2"); + + dsi.setCompany(company); + dsi.setManager(manager); + dsi.setCategory(category); + + si.setTitle(title); + si.setAuthor(author); + si.setComments(comments); + si.setKeywords(keywords); + si.setSubject(subject); + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put(k1, p1); + customProperties.put(k2, p2); + customProperties.put("Sample Number", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.TRUE); + Date date = new Date(); + customProperties.put("Sample Date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertEquals("Category", category, dsi.getCategory()); + assertEquals("Company", company, dsi.getCompany()); + assertEquals("Manager", manager, dsi.getManager()); + + assertEquals("", author, si.getAuthor()); + assertEquals("", title, si.getTitle()); + assertEquals("", comments, si.getComments()); + assertEquals("", keywords, si.getKeywords()); + assertEquals("", subject, si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } + + /* Insert some custom properties into the container. */ + // System.out.println(k1); + String a1 = (String) customProperties.get(k1); + assertEquals("Key1", p1, a1); + String a2 = (String) customProperties.get(k2); + assertEquals("Schl\u00fcssel2", p2, a2); + Integer a3 = (Integer) customProperties.get("Sample Number"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.TRUE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); + } + /** - * Tests conversion in custom fields and errors - * - */ - public void testConvAndExistance(){ - - - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put("int", new Integer(12345)); - customProperties.put("negint", new Integer(-12345)); - customProperties.put("long", new Long(12345)); - customProperties.put("neglong", new Long(-12345)); - customProperties.put("boolean", new Boolean(true)); - customProperties.put("string", "a String"); - //customProperties.put("float", new Float(12345.0)); is not valid - //customProperties.put("negfloat", new Float(-12345.1)); is not valid - customProperties.put("double", new Double(12345.2)); - customProperties.put("negdouble", new Double(-12345.3)); - //customProperties.put("char", new Character('a')); is not valid - - Date date=new Date(); - customProperties.put("date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertNull(dsi.getCategory()); - assertNull(dsi.getCompany()); - assertNull(dsi.getManager()); - - assertNull(si.getAuthor()); - assertNull(si.getTitle()); - assertNull(si.getComments()); - assertNull(si.getKeywords()); - assertNull(si.getSubject()); - - - /* Read the custom properties. If there are no custom properties - * yet, the application has to create a new CustomProperties object. - * It will serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - - Integer a3=(Integer) customProperties.get("int"); - assertEquals("int",new Integer(12345),a3); - - a3=(Integer) customProperties.get("negint"); - assertEquals("negint",new Integer(-12345),a3); - - Long al=(Long) customProperties.get("neglong"); - assertEquals("neglong",new Long(-12345),al); - - al=(Long) customProperties.get("long"); - assertEquals("long",new Long(12345),al); - - Boolean a4=(Boolean) customProperties.get("boolean"); - assertEquals("boolean",new Boolean(true),a4); - - Date a5=(Date) customProperties.get("date"); - assertEquals("Custom Date:",date,a5); - - Double d=(Double) customProperties.get("double"); - assertEquals("int",new Double(12345.2),d); - - d=(Double) customProperties.get("negdouble"); - assertEquals("string",new Double(-12345.3),d); - - String s=(String) customProperties.get("string"); - assertEquals("sring","a String",s); - - Object o=null; - - o=customProperties.get("string"); - if (!(o instanceof String)){ - fail(); - } - o=customProperties.get("boolean"); - if (!(o instanceof Boolean)){ - fail(); - } - - o=customProperties.get("int"); - if (!(o instanceof Integer)){ - fail(); - } - o=customProperties.get("negint"); - if (!(o instanceof Integer)){ - fail(); - } - - o=customProperties.get("long"); - if (!(o instanceof Long)){ - fail(); - } - o=customProperties.get("neglong"); - if (!(o instanceof Long)){ - fail(); - } - - o=customProperties.get("double"); - if (!(o instanceof Double)){ - fail(); - } - o=customProperties.get("negdouble"); - if (!(o instanceof Double)){ - fail(); - } - - o=customProperties.get("date"); - if (!(o instanceof Date)){ - fail(); - } - } - - - -} \ No newline at end of file + * Iterative testing of the unicode test + * + */ + public void testSix() { + for (int i = 1; i < 100; i++) { + setUp(); + testUnicode(); + } + } + + + /** + * Tests conversion in custom fields and errors + */ + public void testConvAndExistence() { + + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put("int", new Integer(12345)); + customProperties.put("negint", new Integer(-12345)); + customProperties.put("long", new Long(12345)); + customProperties.put("neglong", new Long(-12345)); + customProperties.put("boolean", Boolean.TRUE); + customProperties.put("string", "a String"); + // customProperties.put("float", new Float(12345.0)); is not valid + // customProperties.put("negfloat", new Float(-12345.1)); is not valid + customProperties.put("double", new Double(12345.2)); + customProperties.put("negdouble", new Double(-12345.3)); + // customProperties.put("char", new Character('a')); is not valid + + Date date = new Date(); + customProperties.put("date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertNull(dsi.getCategory()); + assertNull(dsi.getCompany()); + assertNull(dsi.getManager()); + + assertNull(si.getAuthor()); + assertNull(si.getTitle()); + assertNull(si.getComments()); + assertNull(si.getKeywords()); + assertNull(si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } + + /* Insert some custom properties into the container. */ + + Integer a3 = (Integer) customProperties.get("int"); + assertEquals("int", new Integer(12345), a3); + + a3 = (Integer) customProperties.get("negint"); + assertEquals("negint", new Integer(-12345), a3); + + Long al = (Long) customProperties.get("neglong"); + assertEquals("neglong", new Long(-12345), al); + + al = (Long) customProperties.get("long"); + assertEquals("long", new Long(12345), al); + + Boolean a4 = (Boolean) customProperties.get("boolean"); + assertEquals("boolean", Boolean.TRUE, a4); + + Date a5 = (Date) customProperties.get("date"); + assertEquals("Custom Date:", date, a5); + + Double d = (Double) customProperties.get("double"); + assertEquals("int", new Double(12345.2), d); + + d = (Double) customProperties.get("negdouble"); + assertEquals("string", new Double(-12345.3), d); + + String s = (String) customProperties.get("string"); + assertEquals("sring", "a String", s); + + + assertTrue(customProperties.get("string") instanceof String); + assertTrue(customProperties.get("boolean") instanceof Boolean); + assertTrue(customProperties.get("int") instanceof Integer); + assertTrue(customProperties.get("negint") instanceof Integer); + assertTrue(customProperties.get("long") instanceof Long); + assertTrue(customProperties.get("neglong") instanceof Long); + assertTrue(customProperties.get("double") instanceof Double); + assertTrue(customProperties.get("negdouble") instanceof Double); + assertTrue(customProperties.get("date") instanceof Date); + } +} diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java index 581ff14381..cdd74f79fc 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java @@ -53,7 +53,7 @@ public class TestUnicode extends TestCase { /** *

      Read a the test file from the "data" directory.

      - * + * * @exception FileNotFoundException if the file to be read does not exist. * @exception IOException if any other I/O exception occurs */ @@ -68,7 +68,7 @@ public class TestUnicode extends TestCase { *

      Tests the {@link PropertySet} methods. The test file has two * property set: the first one is a {@link SummaryInformation}, * the second one is a {@link DocumentSummaryInformation}.

      - * + * * @exception IOException if an I/O exception occurs * @exception HPSFException if an HPSF exception occurs */ @@ -82,9 +82,9 @@ public class TestUnicode extends TestCase { Assert.assertEquals(ps.getSectionCount(), 2); Section s = (Section) ps.getSections().get(1); Assert.assertEquals(s.getProperty(1), - new Integer(Constants.CP_UTF16)); + Integer.valueOf(Constants.CP_UTF16)); Assert.assertEquals(s.getProperty(2), - new Integer(-96070278)); + Integer.valueOf(-96070278)); Assert.assertEquals(s.getProperty(3), "MCon_Info zu Office bei Schreiner"); Assert.assertEquals(s.getProperty(4), diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java index f824ffb7bc..eabda72d5b 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java @@ -107,7 +107,7 @@ public class TestWrite extends TestCase /** *

      Writes an empty property set to a POIFS and reads it back * in.

      - * + * * @exception IOException if an I/O exception occurs */ public void testNoFormatID() throws IOException @@ -150,7 +150,7 @@ public class TestWrite extends TestCase /** *

      Writes an empty property set to a POIFS and reads it back * in.

      - * + * * @exception IOException if an I/O exception occurs * @exception UnsupportedVariantTypeException if HPSF does not yet support * a variant type to be written @@ -190,7 +190,7 @@ public class TestWrite extends TestCase /** *

      Writes a simple property set with a SummaryInformation section to a * POIFS and reads it back in.

      - * + * * @exception IOException if an I/O exception occurs * @exception UnsupportedVariantTypeException if HPSF does not yet support * a variant type to be written @@ -199,30 +199,30 @@ public class TestWrite extends TestCase throws IOException, UnsupportedVariantTypeException { final String AUTHOR = "Rainer Klute"; - final String TITLE = "Test Document"; + final String TITLE = "Test Document"; final File dataDir = _samples.getFile(""); final File filename = new File(dataDir, POI_FS); filename.deleteOnExit(); final OutputStream out = new FileOutputStream(filename); final POIFSFileSystem poiFs = new POIFSFileSystem(); - + final MutablePropertySet ps = new MutablePropertySet(); final MutableSection si = new MutableSection(); si.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); ps.getSections().set(0, si); - + final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_AUTHOR); p.setType(Variant.VT_LPWSTR); p.setValue(AUTHOR); si.setProperty(p); si.setProperty(PropertyIDMap.PID_TITLE, Variant.VT_LPSTR, TITLE); - + poiFs.createDocument(ps.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); poiFs.writeFilesystem(out); out.close(); - + /* Read the POIFS: */ final PropertySet[] psa = new PropertySet[1]; final POIFSReader r = new POIFSReader(); @@ -240,7 +240,7 @@ public class TestWrite extends TestCase fail(org.apache.poi.hpsf.Util.toString(ex)); } } - + }, SummaryInformation.DEFAULT_STREAM_NAME); r.read(new FileInputStream(filename)); @@ -259,7 +259,7 @@ public class TestWrite extends TestCase /** *

      Writes a simple property set with two sections to a POIFS and reads it * back in.

      - * + * * @exception IOException if an I/O exception occurs * @exception WritingNotSupportedException if HPSF does not yet support * a variant type to be written @@ -365,7 +365,7 @@ public class TestWrite extends TestCase { Throwable t = null; final int codepage = CODEPAGE_DEFAULT; - if (!hasProperDefaultCharset()) + if (!hasProperDefaultCharset()) { System.err.println(IMPROPER_DEFAULT_CHARSET_MESSAGE + " This testcase is skipped."); @@ -375,8 +375,8 @@ public class TestWrite extends TestCase try { check(Variant.VT_EMPTY, null, codepage); - check(Variant.VT_BOOL, new Boolean(true), codepage); - check(Variant.VT_BOOL, new Boolean(false), codepage); + check(Variant.VT_BOOL, Boolean.TRUE, codepage); + check(Variant.VT_BOOL, Boolean.FALSE, codepage); check(Variant.VT_CF, new byte[]{0}, codepage); check(Variant.VT_CF, new byte[]{0, 1}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2}, codepage); @@ -385,11 +385,11 @@ public class TestWrite extends TestCase check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage); - check(Variant.VT_I4, new Integer(27), codepage); - check(Variant.VT_I8, new Long(28), codepage); + check(Variant.VT_I4, Integer.valueOf(27), codepage); + check(Variant.VT_I8, Long.valueOf(28), codepage); check(Variant.VT_R8, new Double(29.0), codepage); - check(Variant.VT_I4, new Integer(-27), codepage); - check(Variant.VT_I8, new Long(-28), codepage); + check(Variant.VT_I4, Integer.valueOf(-27), codepage); + check(Variant.VT_I8, Long.valueOf(-28), codepage); check(Variant.VT_R8, new Double(-29.0), codepage); check(Variant.VT_FILETIME, new Date(), codepage); check(Variant.VT_I4, new Integer(Integer.MAX_VALUE), codepage); @@ -460,7 +460,7 @@ public class TestWrite extends TestCase for (int i = 0; i < validCodepages.length; i++) { final int cp = validCodepages[i]; - if (cp == -1 && !hasProperDefaultCharset()) + if (cp == -1 && !hasProperDefaultCharset()) { System.err.println(IMPROPER_DEFAULT_CHARSET_MESSAGE + " This testcase is skipped for the default codepage."); @@ -590,10 +590,10 @@ public class TestWrite extends TestCase * @param codepage The codepage to use for writing and reading. * @throws UnsupportedVariantTypeException if the variant is not supported. * @throws IOException if an I/O exception occurs. - * @throws ReadingNotSupportedException - * @throws UnsupportedEncodingException + * @throws ReadingNotSupportedException + * @throws UnsupportedEncodingException */ - private void check(final long variantType, final Object value, + private void check(final long variantType, final Object value, final int codepage) throws UnsupportedVariantTypeException, IOException, ReadingNotSupportedException, UnsupportedEncodingException @@ -651,17 +651,17 @@ public class TestWrite extends TestCase *

      This test method does a write and read back test with all POI * filesystems in the "data" directory by performing the following * actions for each file:

      - * + * *
        - * + * *
      • Read its property set streams.

      • - * + * *
      • Create a new POI filesystem containing the origin file's * property set streams.

      • - * + * *
      • Read the property set streams from the POI filesystem just * created.

      • - * + * *
      • Compare each property set stream with the corresponding one from * the origin file and check whether they are equal.

      • * @@ -731,7 +731,7 @@ public class TestWrite extends TestCase final InputStream in2 = new ByteArrayInputStream(bytes2); final PropertySet ps1 = PropertySetFactory.create(in1); final PropertySet ps2 = PropertySetFactory.create(in2); - + /* Compare the property set stream with the corresponding one * from the origin file and check whether they are equal. */ assertEquals("Equality for file " + f.getName(), ps1, ps2); @@ -761,14 +761,14 @@ public class TestWrite extends TestCase final MutablePropertySet ps1 = new MutablePropertySet(); final MutableSection s = (MutableSection) ps1.getSections().get(0); final Map m = new HashMap(3, 1.0f); - m.put(new Long(1), "String 1"); - m.put(new Long(2), "String 2"); - m.put(new Long(3), "String 3"); + m.put(Long.valueOf(1), "String 1"); + m.put(Long.valueOf(2), "String 2"); + m.put(Long.valueOf(3), "String 3"); s.setDictionary(m); s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); int codepage = Constants.CP_UNICODE; s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(codepage)); + Integer.valueOf(codepage)); poiFs.createDocument(ps1.toInputStream(), "Test"); poiFs.writeFilesystem(out); out.close(); @@ -813,14 +813,14 @@ public class TestWrite extends TestCase final MutablePropertySet ps1 = new MutablePropertySet(); final MutableSection s = (MutableSection) ps1.getSections().get(0); final Map m = new HashMap(3, 1.0f); - m.put(new Long(1), "String 1"); - m.put(new Long(2), "String 2"); - m.put(new Long(3), "String 3"); + m.put(Long.valueOf(1), "String 1"); + m.put(Long.valueOf(2), "String 2"); + m.put(Long.valueOf(3), "String 3"); s.setDictionary(m); s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); int codepage = 12345; s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(codepage)); + Integer.valueOf(codepage)); poiFs.createDocument(ps1.toInputStream(), "Test"); poiFs.writeFilesystem(out); out.close(); diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java index ca3b0864ba..ad6e1237cf 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java @@ -58,7 +58,7 @@ import org.apache.poi.POIDataSamples; /** *

        Tests HPSF's high-level writing functionality for the well-known property * set "SummaryInformation" and "DocumentSummaryInformation".

        - * + * * @author Rainer Klute * klute@rainer-klute.de */ @@ -83,11 +83,6 @@ public class TestWriteWellKnown extends TestCase { * pointed to by the "POI.testdata.path" system property, trying to extract * the document summary information stream in the root directory and calling * its get... methods.

        - * @throws IOException - * @throws FileNotFoundException - * @throws MarkUnsupportedException - * @throws NoPropertySetStreamException - * @throws UnexpectedPropertySetTypeException */ public void testReadDocumentSummaryInformation() throws FileNotFoundException, IOException, @@ -131,7 +126,7 @@ public class TestWriteWellKnown extends TestCase { final DocumentInputStream dis = new DocumentInputStream(dsiEntry); final PropertySet ps = new PropertySet(dis); final DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); - + /* Execute the get... methods. */ dsi.getByteCount(); dsi.getByteOrder(); @@ -159,43 +154,43 @@ public class TestWriteWellKnown extends TestCase { *

        This test method test the writing of properties in the well-known * property set streams "SummaryInformation" and * "DocumentSummaryInformation" by performing the following steps:

        - * + * *
          - * + * *
        1. Read a test document doc1 into a POI filesystem.

        2. - * + * *
        3. Read the summary information stream and the document summary * information stream from the POI filesystem.

        4. - * + * *
        5. Write all properties supported by HPSF to the summary * information (e.g. author, edit date, application name) and to the * document summary information (e.g. company, manager).

        6. - * + * *
        7. Write the summary information stream and the document summary * information stream to the POI filesystem.

        8. - * + * *
        9. Write the POI filesystem to a (temporary) file doc2 * and close the latter.

        10. - * + * *
        11. Open doc2 for reading and check summary information * and document summary information. All properties written before must be * found in the property streams of doc2 and have the correct * values.

        12. - * + * *
        13. Remove all properties supported by HPSF from the summary * information (e.g. author, edit date, application name) and from the * document summary information (e.g. company, manager).

        14. - * + * *
        15. Write the summary information stream and the document summary * information stream to the POI filesystem.

        16. - * + * *
        17. Write the POI filesystem to a (temporary) file doc3 * and close the latter.

        18. - * + * *
        19. Open doc3 for reading and check summary information * and document summary information. All properties removed before must not * be found in the property streams of doc3.

        - * + * * @throws IOException if some I/O error occurred. * @throws MarkUnsupportedException * @throws NoPropertySetStreamException @@ -209,17 +204,17 @@ public class TestWriteWellKnown extends TestCase { POIDataSamples _samples = POIDataSamples.getHPSFInstance(); final File dataDir = _samples.getFile(""); final File doc1 = new File(dataDir, POI_FS); - + /* Read a test document doc1 into a POI filesystem. */ POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc1)); DirectoryEntry dir = poifs.getRoot(); DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - + /* * Read the summary information stream and the document summary * information stream from the POI filesystem. - * + * * Please note that the result consists of SummaryInformation and * DocumentSummaryInformation instances which are in memory only. To * make them permanent they have to be written to a POI filesystem @@ -232,7 +227,7 @@ public class TestWriteWellKnown extends TestCase { dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); - + /* * Write all properties supported by HPSF to the summary information * (e.g. author, edit date, application name) and to the document @@ -245,7 +240,7 @@ public class TestWriteWellKnown extends TestCase { final long time2 = cal.getTimeInMillis(); cal.set(2002, 8, 8, 8, 8, 8); final long time3 = cal.getTimeInMillis(); - + int nr = 4711; final String P_APPLICATION_NAME = "ApplicationName"; final String P_AUTHOR = "Author"; @@ -265,7 +260,7 @@ public class TestWriteWellKnown extends TestCase { // FIXME (byte array properties not yet implemented): final byte[] P_THUMBNAIL = new byte[123]; final String P_TITLE = "Title"; final int P_WORD_COUNT = ++nr; - + final int P_BYTE_COUNT = ++nr; final String P_CATEGORY = "Category"; final String P_COMPANY = "Company"; @@ -296,7 +291,7 @@ public class TestWriteWellKnown extends TestCase { final Long MIN_LONG = new Long(Long.MIN_VALUE); final Double MAX_DOUBLE = new Double(Double.MAX_VALUE); final Double MIN_DOUBLE = new Double(Double.MIN_VALUE); - + si.setApplicationName(P_APPLICATION_NAME); si.setAuthor(P_AUTHOR); si.setCharCount(P_CHAR_COUNT); @@ -315,7 +310,7 @@ public class TestWriteWellKnown extends TestCase { // FIXME (byte array properties not yet implemented): si.setThumbnail(P_THUMBNAIL); si.setTitle(P_TITLE); si.setWordCount(P_WORD_COUNT); - + dsi.setByteCount(P_BYTE_COUNT); dsi.setCategory(P_CATEGORY); dsi.setCompany(P_COMPANY); @@ -345,7 +340,7 @@ public class TestWriteWellKnown extends TestCase { customProperties.put("negative_Integer", NEGATIVE_INTEGER); customProperties.put("negative_Long", NEGATIVE_LONG); customProperties.put("negative_Double", NEGATIVE_DOUBLE); - customProperties.put("Boolean", new Boolean(true)); + customProperties.put("Boolean", Boolean.TRUE); customProperties.put("Date", now); customProperties.put("max_Integer", MAX_INTEGER); customProperties.put("min_Integer", MIN_INTEGER); @@ -378,14 +373,14 @@ public class TestWriteWellKnown extends TestCase { dir = poifs.getRoot(); siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - + dis = new DocumentInputStream(siEntry); ps = new PropertySet(dis); si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); dsi = new DocumentSummaryInformation(ps); - + assertEquals(P_APPLICATION_NAME, si.getApplicationName()); assertEquals(P_AUTHOR, si.getAuthor()); assertEquals(P_CHAR_COUNT, si.getCharCount()); @@ -404,7 +399,7 @@ public class TestWriteWellKnown extends TestCase { // FIXME (byte array properties not yet implemented): assertEquals(P_THUMBNAIL, si.getThumbnail()); assertEquals(P_TITLE, si.getTitle()); assertEquals(P_WORD_COUNT, si.getWordCount()); - + assertEquals(P_BYTE_COUNT, dsi.getByteCount()); assertEquals(P_CATEGORY, dsi.getCategory()); assertEquals(P_COMPANY, dsi.getCompany()); @@ -434,7 +429,7 @@ public class TestWriteWellKnown extends TestCase { assertEquals(NEGATIVE_INTEGER, cps.get("negative_Integer")); assertEquals(NEGATIVE_LONG, cps.get("negative_Long")); assertEquals(NEGATIVE_DOUBLE, cps.get("negative_Double")); - assertEquals(new Boolean(true), cps.get("Boolean")); + assertEquals(Boolean.TRUE, cps.get("Boolean")); assertEquals(now, cps.get("Date")); assertEquals(MAX_INTEGER, cps.get("max_Integer")); assertEquals(MIN_INTEGER, cps.get("min_Integer")); @@ -464,7 +459,7 @@ public class TestWriteWellKnown extends TestCase { si.removeThumbnail(); si.removeTitle(); si.removeWordCount(); - + dsi.removeByteCount(); dsi.removeCategory(); dsi.removeCompany(); @@ -481,14 +476,14 @@ public class TestWriteWellKnown extends TestCase { dsi.removePresentationFormat(); dsi.removeScale(); dsi.removeSlideCount(); - - /* + + /* *
      • Write the summary information stream and the document summary * information stream to the POI filesystem. */ si.write(dir, siEntry.getName()); dsi.write(dir, dsiEntry.getName()); - - /* + + /* *

      • Write the POI filesystem to a (temporary) file doc3 * and close the latter. */ final File doc3 = File.createTempFile("POI_HPSF_Test.", ".tmp"); @@ -496,8 +491,8 @@ public class TestWriteWellKnown extends TestCase { out = new FileOutputStream(doc3); poifs.writeFilesystem(out); out.close(); - - /* + + /* * Open doc3 for reading and check summary information * and document summary information. All properties removed before must not * be found in the property streams of doc3. @@ -506,14 +501,14 @@ public class TestWriteWellKnown extends TestCase { dir = poifs.getRoot(); siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - + dis = new DocumentInputStream(siEntry); ps = new PropertySet(dis); si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); dsi = new DocumentSummaryInformation(ps); - + assertEquals(null, si.getApplicationName()); assertEquals(null, si.getAuthor()); assertEquals(0, si.getCharCount()); @@ -537,7 +532,7 @@ public class TestWriteWellKnown extends TestCase { assertEquals(null, si.getTitle()); assertEquals(0, si.getWordCount()); assertTrue(si.wasNull()); - + assertEquals(0, dsi.getByteCount()); assertTrue(dsi.wasNull()); assertEquals(null, dsi.getCategory()); @@ -611,7 +606,7 @@ public class TestWriteWellKnown extends TestCase { else dsi = PropertySetFactory.newDocumentSummaryInformation(); final CustomProperties cps = dsi.getCustomProperties(); - + if (cps == null) /* The document does not have custom properties. */ return; @@ -663,14 +658,14 @@ public class TestWriteWellKnown extends TestCase { assertEquals(1, cps.size()); Object v1 = cps.get(KEY); assertEquals(VALUE_1, v1); - + /* After adding a custom property with the same name the size must still * be one. */ cps.put(KEY, VALUE_2); assertEquals(1, cps.size()); Object v2 = cps.get(KEY); assertEquals(VALUE_2, v2); - + /* Removing the custom property must return the remove property and * reduce the size to 0. */ cp = (CustomProperty) cps.remove(KEY); @@ -715,7 +710,7 @@ public class TestWriteWellKnown extends TestCase { p.setType(Variant.VT_LPWSTR); p.setValue(VALUE_1); s.setProperty(p); - dictionary.put(new Long(ID_1), NAME_1); + dictionary.put(Long.valueOf(ID_1), NAME_1); s.setDictionary(dictionary); cps = dsi.getCustomProperties(); assertEquals(1, cps.size()); @@ -723,7 +718,7 @@ public class TestWriteWellKnown extends TestCase { /* Add another custom property. */ s.setProperty(ID_2, Variant.VT_LPWSTR, VALUE_1); - dictionary.put(new Long(ID_2), NAME_1); + dictionary.put(Long.valueOf(ID_2), NAME_1); s.setDictionary(dictionary); cps = dsi.getCustomProperties(); assertEquals(1, cps.size()); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java b/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java index 7702fce3d4..c3a026c211 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java @@ -56,7 +56,7 @@ import org.xml.sax.helpers.XMLReaderFactory; * the file 'functionMetadata.txt'. There are more than 300 built-in functions in Excel and the * intention of this class is to make it easier to maintain the metadata, by extracting it from * a reliable source. - * + * * @author Josh Micich */ public final class ExcelFileFormatDocFunctionExtractor { @@ -65,10 +65,10 @@ public final class ExcelFileFormatDocFunctionExtractor { /** * For simplicity, the output file is strictly simple ASCII. - * This method detects any unexpected characters. + * This method detects any unexpected characters. */ /* package */ static boolean isSimpleAscii(char c) { - + if (c>=0x21 && c<=0x7E) { // everything from '!' to '~' (includes letters, digits, punctuation return true; @@ -83,8 +83,8 @@ public final class ExcelFileFormatDocFunctionExtractor { } return false; } - - + + private static final class FunctionData { // special characters from the ooo document private static final int CHAR_ELLIPSIS_8230 = 8230; @@ -148,7 +148,7 @@ public final class ExcelFileFormatDocFunctionExtractor { return b ? "x" : ""; } } - + private static final class FunctionDataCollector { private final Map _allFunctionsByIndex; @@ -156,7 +156,7 @@ public final class ExcelFileFormatDocFunctionExtractor { private final Set _groupFunctionIndexes; private final Set _groupFunctionNames; private final PrintStream _ps; - + public FunctionDataCollector(PrintStream ps) { _ps = ps; _allFunctionsByIndex = new HashMap(); @@ -168,19 +168,19 @@ public final class ExcelFileFormatDocFunctionExtractor { public void addFuntion(int funcIx, boolean hasFootnote, String funcName, int minParams, int maxParams, String returnClass, String paramClasses, String volatileFlagStr) { boolean isVolatile = volatileFlagStr.length() > 0; - - Integer funcIxKey = new Integer(funcIx); + + Integer funcIxKey = Integer.valueOf(funcIx); if(!_groupFunctionIndexes.add(funcIxKey)) { throw new RuntimeException("Duplicate function index (" + funcIx + ")"); } if(!_groupFunctionNames.add(funcName)) { throw new RuntimeException("Duplicate function name '" + funcName + "'"); } - + checkRedefinedFunction(hasFootnote, funcName, funcIxKey); - FunctionData fd = new FunctionData(funcIx, hasFootnote, funcName, + FunctionData fd = new FunctionData(funcIx, hasFootnote, funcName, minParams, maxParams, returnClass, paramClasses, isVolatile); - + _allFunctionsByIndex.put(funcIxKey, fd); _allFunctionsByName.put(funcName, fd); } @@ -195,7 +195,7 @@ public final class ExcelFileFormatDocFunctionExtractor { fdPrev = (FunctionData) _allFunctionsByIndex.get(funcIxKey); if(fdPrev != null) { if(!fdPrev.hasFootnote() || !hasNote) { - throw new RuntimeException("changing function [" + throw new RuntimeException("changing function [" + funcIxKey + "] definition without foot-note"); } _allFunctionsByName.remove(fdPrev.getName()); @@ -204,10 +204,10 @@ public final class ExcelFileFormatDocFunctionExtractor { fdPrev = (FunctionData) _allFunctionsByName.get(funcName); if(fdPrev != null) { if(!fdPrev.hasFootnote() || !hasNote) { - throw new RuntimeException("changing function '" + throw new RuntimeException("changing function '" + funcName + "' definition without foot-note"); } - _allFunctionsByIndex.remove(new Integer(fdPrev.getIndex())); + _allFunctionsByIndex.remove(Integer.valueOf(fdPrev.getIndex())); } } @@ -217,7 +217,7 @@ public final class ExcelFileFormatDocFunctionExtractor { _groupFunctionIndexes.clear(); _groupFunctionNames.clear(); Arrays.sort(keys); - + _ps.println("# " + headingText); for (int i = 0; i < keys.length; i++) { FunctionData fd = (FunctionData) _allFunctionsByIndex.get(keys[i]); @@ -225,25 +225,25 @@ public final class ExcelFileFormatDocFunctionExtractor { } } } - + /** - * To avoid drag-in - parse XML using only JDK. + * To avoid drag-in - parse XML using only JDK. */ private static class EFFDocHandler implements ContentHandler { private static final String[] HEADING_PATH_NAMES = { - "office:document-content", "office:body", "office:text", "text:h", + "office:document-content", "office:body", "office:text", "text:h", }; private static final String[] TABLE_BASE_PATH_NAMES = { - "office:document-content", "office:body", "office:text", "table:table", + "office:document-content", "office:body", "office:text", "table:table", }; private static final String[] TABLE_ROW_RELPATH_NAMES = { - "table:table-row", + "table:table-row", }; private static final String[] TABLE_CELL_RELPATH_NAMES = { - "table:table-row", "table:table-cell", "text:p", + "table:table-row", "table:table-cell", "text:p", }; // after May 2008 there was one more style applied to the footnotes - private static final String[] NOTE_REF_RELPATH_NAMES_OLD = { + private static final String[] NOTE_REF_RELPATH_NAMES_OLD = { "table:table-row", "table:table-cell", "text:p", "text:span", "text:note-ref", }; private static final String[] NOTE_REF_RELPATH_NAMES = { @@ -255,7 +255,7 @@ public final class ExcelFileFormatDocFunctionExtractor { /** true only when parsing the target tables */ private boolean _isInsideTable; - private final List _rowData; + private final List _rowData; private final StringBuffer _textNodeBuffer; private final List _rowNoteFlags; private boolean _cellHasNote; @@ -304,7 +304,7 @@ public final class ExcelFileFormatDocFunctionExtractor { if(matchesPath(0, HEADING_PATH_NAMES)) { _lastHeadingText = _textNodeBuffer.toString().trim(); _textNodeBuffer.setLength(0); - } + } if(_isInsideTable) { if(matchesTargetPath()) { _fdc.endTableGroup(_lastHeadingText); @@ -350,7 +350,7 @@ public final class ExcelFileFormatDocFunctionExtractor { String returnClass = cellData[i + 4]; String paramClasses = cellData[i + 5]; String volatileFlagStr = cellData[i + 6]; - + _fdc.addFuntion(funcIx, hasFootnote, funcName, minParams, maxParams, returnClass, paramClasses, volatileFlagStr); } private static int parseInt(String valStr) { @@ -412,7 +412,7 @@ public final class ExcelFileFormatDocFunctionExtractor { private static void extractFunctionData(FunctionDataCollector fdc, InputStream is) { XMLReader xr; - + try { // First up, try the default one xr = XMLReaderFactory.createXMLReader(); @@ -460,7 +460,7 @@ public final class ExcelFileFormatDocFunctionExtractor { public void write(byte[] b, int off, int len) throws IOException { for (int i = 0; i < len; i++) { checkByte(b[i + off]); - + } _os.write(b, off, len); } @@ -483,7 +483,7 @@ public final class ExcelFileFormatDocFunctionExtractor { } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); } - + outputLicenseHeader(ps); Class genClass = ExcelFileFormatDocFunctionExtractor.class; ps.println("# Created by (" + genClass.getName() + ")"); @@ -504,7 +504,7 @@ public final class ExcelFileFormatDocFunctionExtractor { throw new RuntimeException(e); } ps.close(); - + String canonicalOutputFileName; try { canonicalOutputFileName = outFile.getCanonicalPath(); @@ -554,7 +554,7 @@ public final class ExcelFileFormatDocFunctionExtractor { InputStream is = new FileInputStream(f); while(true) { int bytesRead = is.read(buf); - if(bytesRead<1) { + if(bytesRead<1) { break; } m.update(buf, 0, bytesRead); @@ -563,7 +563,7 @@ public final class ExcelFileFormatDocFunctionExtractor { } catch (IOException e) { throw new RuntimeException(e); } - + return "0x" + new BigInteger(1, m.digest()).toString(16); } @@ -585,7 +585,7 @@ public final class ExcelFileFormatDocFunctionExtractor { OutputStream os = new FileOutputStream(result); while(true) { int bytesRead = is.read(buf); - if(bytesRead<1) { + if(bytesRead<1) { break; } os.write(buf, 0, bytesRead); @@ -609,7 +609,7 @@ public final class ExcelFileFormatDocFunctionExtractor { processFile(effDocFile, outFile); return; } - + File tempEFFDocFile = downloadSourceFile(); processFile(tempEFFDocFile, outFile); tempEFFDocFile.delete(); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java b/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java index 45ae4ac362..b9f39a03c6 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java @@ -6,7 +6,7 @@ (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -23,24 +23,24 @@ import java.util.ArrayList; import java.util.List; /** - * Utility class to help test code verify that generated files do not differ from proof copies in + * Utility class to help test code verify that generated files do not differ from proof copies in * any significant detail. Normally this task would be simple except for the presence of artifacts - * in the file that change every time it is generated. Usually these volatile artifacts are + * in the file that change every time it is generated. Usually these volatile artifacts are * time-stamps, user names, or other machine dependent parameters. - * + * * @author Josh Micich */ public final class StreamUtility { /** * Compares two streams with expected differences in specified regions. The streams are - * expected to be of equal length and comparison is always byte for byte. That is - - * differences can only involve exchanging each individual byte for another single byte.
        - * Both input streams are closed. - * - * @param allowableDifferenceRegions array of integer pairs: (offset, length). + * expected to be of equal length and comparison is always byte for byte. That is - + * differences can only involve exchanging each individual byte for another single byte.
        + * Both input streams are closed. + * + * @param allowableDifferenceRegions array of integer pairs: (offset, length). * Any differences encountered in these regions of the streams will be ignored - * @return null if streams are identical, else the + * @return null if streams are identical, else the * byte indexes of differing data. If streams were different lengths, * the returned indexes will be -1 and the length of the shorter stream */ @@ -51,36 +51,36 @@ public final class StreamUtility { } boolean success = false; int[] result; - try { - result = diffInternal(isA, isB, allowableDifferenceRegions); - success = true; - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - close(isA, success); - close(isB, success); - } - return result; + try { + result = diffInternal(isA, isB, allowableDifferenceRegions); + success = true; + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + close(isA, success); + close(isB, success); + } + return result; } /** * @param success false if the outer method is throwing an exception. */ - private static void close(InputStream is, boolean success) { - try { - is.close(); - } catch (IOException e) { - if(success) { - // this is a new error. ok to throw - throw new RuntimeException(e); - } - // else don't subvert original exception. just print stack trace for this one - e.printStackTrace(); - } - } + private static void close(InputStream is, boolean success) { + try { + is.close(); + } catch (IOException e) { + if(success) { + // this is a new error. ok to throw + throw new RuntimeException(e); + } + // else don't subvert original exception. just print stack trace for this one + e.printStackTrace(); + } + } - private static int[] diffInternal(InputStream isA, InputStream isB, int[] allowableDifferenceRegions) - throws IOException { + private static int[] diffInternal(InputStream isA, InputStream isB, int[] allowableDifferenceRegions) + throws IOException { int offset = 0; List temp = new ArrayList(); while (true) { @@ -97,11 +97,11 @@ public final class StreamUtility { return new int[] { -1, offset, }; } if (b != b2 && !isIgnoredRegion(allowableDifferenceRegions, offset)) { - temp.add(new Integer(offset)); + temp.add(Integer.valueOf(offset)); } offset++; } - } + } private static boolean isIgnoredRegion(int[] allowableDifferenceRegions, int offset) { for (int i = 0; i < allowableDifferenceRegions.length; i+=2) { @@ -121,7 +121,7 @@ public final class StreamUtility { } Integer[] boxInts = new Integer[nItems]; temp.toArray(boxInts); - + int[] result = new int[nItems]; for (int i = 0; i < result.length; i++) { result[i] = boxInts[i].intValue(); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java index 8eeb64c7c6..b1c21dd373 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java @@ -40,7 +40,7 @@ public abstract class BaseTestDataFormat extends TestCase { Map formats = BuiltinFormats.getBuiltinFormats(); for (int idx : formats.keySet()) { - String fmt = formats.get(new Integer(idx)); + String fmt = formats.get(Integer.valueOf(idx)); assertEquals(idx, df.getFormat(fmt)); } diff --git a/src/testcases/org/apache/poi/util/LocalTestNode.java b/src/testcases/org/apache/poi/util/LocalTestNode.java index 2f1ae62649..6eaaed5901 100644 --- a/src/testcases/org/apache/poi/util/LocalTestNode.java +++ b/src/testcases/org/apache/poi/util/LocalTestNode.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -33,7 +32,7 @@ class LocalTestNode LocalTestNode(final int key) { - _key = new Integer(key); + _key = Integer.valueOf(key); _value = String.valueOf(key); } @@ -118,7 +117,6 @@ class LocalTestNode /** * @return hash code */ - public int hashCode() { return getKey().hashCode() ^ getValue().hashCode(); diff --git a/src/testcases/org/apache/poi/util/TestArrayUtil.java b/src/testcases/org/apache/poi/util/TestArrayUtil.java index 7a517e3c6b..2af0481513 100644 --- a/src/testcases/org/apache/poi/util/TestArrayUtil.java +++ b/src/testcases/org/apache/poi/util/TestArrayUtil.java @@ -15,261 +15,264 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.util; -import junit.framework.*; +import junit.framework.TestCase; /** * Unit test for ArrayUtil * * @author Nick Burch */ -public class TestArrayUtil extends TestCase -{ +public class TestArrayUtil extends TestCase { /** * Test to ensure that our own arraycopy behaves as it should do */ public void testarraycopy() { byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04 }; - + // Test copy whole thing byte[] dest = new byte[4]; ArrayUtil.arraycopy(bytes, 0, dest, 0, 4); - + assertEquals(dest.length, bytes.length); for(int i=0; i