public class ClassID
{
public static final ClassID OLE10_PACKAGE = new ClassID("{0003000C-0000-0000-C000-000000000046}");
- public static final ClassID PPT_SHOW = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
- public static final ClassID XLS_WORKBOOK = new ClassID("{00020841-0000-0000-C000-000000000046}");
- public static final ClassID TXT_ONLY = new ClassID("{5e941d80-bf96-11cd-b579-08002b30bfeb}"); // ???
- public static final ClassID EXCEL97 = new ClassID("{00020820-0000-0000-C000-000000000046}");
- public static final ClassID EXCEL95 = new ClassID("{00020810-0000-0000-C000-000000000046}");
- public static final ClassID WORD97 = new ClassID("{00020906-0000-0000-C000-000000000046}");
- public static final ClassID WORD95 = new ClassID("{00020900-0000-0000-C000-000000000046}");
- public static final ClassID POWERPOINT97 = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
- public static final ClassID POWERPOINT95 = new ClassID("{EA7BAE70-FB3B-11CD-A903-00AA00510EA3}");
- public static final ClassID EQUATION30 = new ClassID("{0002CE02-0000-0000-C000-000000000046}");
+ public static final ClassID PPT_SHOW = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
+ public static final ClassID XLS_WORKBOOK = new ClassID("{00020841-0000-0000-C000-000000000046}");
+ public static final ClassID TXT_ONLY = new ClassID("{5e941d80-bf96-11cd-b579-08002b30bfeb}");
+ public static final ClassID EXCEL97 = new ClassID("{00020820-0000-0000-C000-000000000046}");
+ public static final ClassID EXCEL95 = new ClassID("{00020810-0000-0000-C000-000000000046}");
+ public static final ClassID WORD97 = new ClassID("{00020906-0000-0000-C000-000000000046}");
+ public static final ClassID WORD95 = new ClassID("{00020900-0000-0000-C000-000000000046}");
+ public static final ClassID POWERPOINT97 = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
+ public static final ClassID POWERPOINT95 = new ClassID("{EA7BAE70-FB3B-11CD-A903-00AA00510EA3}");
+ public static final ClassID EQUATION30 = new ClassID("{0002CE02-0000-0000-C000-000000000046}");
/**
*
* @param o the object to compare this <code>PropertySet</code> with
* @return <code>true</code> if the objects are equal, else
- * <code>false</code>.</p>
+ * <code>false</code>.
*/
+ @Override
public boolean equals(final Object o)
{
if (o == null || !(o instanceof ClassID))
/**
* @see Object#hashCode()
*/
+ @Override
public int hashCode()
{
return new String(bytes, StringUtil.UTF8).hashCode();
*
* @return String representation of the Class ID represented by this object.
*/
+ @Override
public String toString()
{
StringBuffer sbClassId = new StringBuffer(38);
* <p>This class is not thread-safe; concurrent access to instances of this
* class must be synchronized.</p>
*
- * <p>While this class is roughly HashMap<Long,CustomProperty>, that's the
+ * <p>While this class is roughly HashMap<Long,CustomProperty>, that's the
* internal representation. To external calls, it should appear as
- * HashMap<String,Object> mapping between Names and Custom Property Values.</p>
+ * HashMap<String,Object> mapping between Names and Custom Property Values.</p>
*/
@SuppressWarnings("serial")
public class CustomProperties extends HashMap<Object,CustomProperty>
/**
* <p>Maps property IDs to property names.</p>
*/
- private Map<Long,String> dictionaryIDToName = new HashMap<Long,String>();
+ private final Map<Long,String> dictionaryIDToName = new HashMap<Long,String>();
/**
* <p>Maps property names to property IDs.</p>
*/
- private Map<String,Long> dictionaryNameToID = new HashMap<String,Long>();
+ private final Map<String,Long> dictionaryNameToID = new HashMap<String,Long>();
/**
* <p>Tells whether this object is pure or not.</p>
* <p>Puts a {@link CustomProperty} into this map. It is assumed that the
* {@link CustomProperty} already has a valid ID. Otherwise use
* {@link #put(CustomProperty)}.</p>
+ *
+ * @param name the property name
+ * @param cp the property
+ *
+ * @return the previous property stored under this name
*/
public CustomProperty put(final String name, final CustomProperty cp)
{
else
{
long max = 1;
- for (final Iterator<Long> i = dictionaryIDToName.keySet().iterator(); i.hasNext();)
- {
- final long id = i.next().longValue();
+ for (Long long1 : dictionaryIDToName.keySet()) {
+ final long id = long1.longValue();
if (id > max)
max = id;
}
}
/**
- * Returns a set of all the names of our
- * custom properties. Equivalent to
- * {@link #nameSet()}
+ * Returns a set of all the names of our custom properties.
+ * Equivalent to {@link #nameSet()}
+ *
+ * @return a set of all the names of our custom properties
*/
+ @Override
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public Set keySet() {
return dictionaryNameToID.keySet();
}
/**
- * Returns a set of all the names of our
- * custom properties
+ * Returns a set of all the names of our custom properties
+ *
+ * @return a set of all the names of our custom properties
*/
public Set<String> nameSet() {
return dictionaryNameToID.keySet();
}
/**
- * Returns a set of all the IDs of our
- * custom properties
+ * Returns a set of all the IDs of our custom properties
+ *
+ * @return a set of all the IDs of our custom properties
*/
public Set<String> idSet() {
return dictionaryNameToID.keySet();
/**
* Checks against both String Name and Long ID
*/
+ @Override
public boolean containsKey(Object key) {
if(key instanceof Long) {
return super.containsKey(key);
/**
* Checks against both the property, and its values.
*/
+ @Override
public boolean containsValue(Object value) {
if(value instanceof CustomProperty) {
return super.containsValue(value);
/* Write the section list, i.e. the references to the sections. Each
* entry in the section list consist of the section's class ID and the
* section's offset relative to the beginning of the stream. */
- offset += nrSections * (ClassID.LENGTH + LittleEndian.INT_SIZE);
+ offset += nrSections * (ClassID.LENGTH + LittleEndianConsts.INT_SIZE);
final int sectionsBegin = offset;
for (final Section section : sections)
{
* @param name The document's name. If there is already a document with the
* same name in the directory the latter will be overwritten.
*
- * @throws WritingNotSupportedException
- * @throws IOException
+ * @throws WritingNotSupportedException if the filesystem doesn't support writing
+ * @throws IOException if the old entry can't be deleted or the new entry be written
*/
public void write(final DirectoryEntry dir, final String name)
throws WritingNotSupportedException, IOException
public abstract class SpecialPropertySet extends MutablePropertySet
{
/**
- * The id to name mapping of the properties
- * in this set.
+ * The id to name mapping of the properties in this set.
+ *
+ * @return the id to name mapping of the properties in this set
*/
public abstract PropertyIDMap getPropertySetIDMap();
* <p>The "real" property set <code>SpecialPropertySet</code>
* delegates to.</p>
*/
- private MutablePropertySet delegate;
+ private final MutablePropertySet delegate;
/**
* @see PropertySet#getByteOrder
*/
+ @Override
public int getByteOrder()
{
return delegate.getByteOrder();
/**
* @see PropertySet#getFormat
*/
+ @Override
public int getFormat()
{
return delegate.getFormat();
/**
* @see PropertySet#getOSVersion
*/
+ @Override
public int getOSVersion()
{
return delegate.getOSVersion();
/**
* @see PropertySet#getClassID
*/
+ @Override
public ClassID getClassID()
{
return delegate.getClassID();
/**
* @see PropertySet#getSectionCount
*/
+ @Override
public int getSectionCount()
{
return delegate.getSectionCount();
/**
* @see PropertySet#getSections
*/
+ @Override
public List<Section> getSections()
{
return delegate.getSections();
/**
* @see PropertySet#isSummaryInformation
*/
+ @Override
public boolean isSummaryInformation()
{
return delegate.isSummaryInformation();
/**
* @see PropertySet#isDocumentSummaryInformation
*/
+ @Override
public boolean isDocumentSummaryInformation()
{
return delegate.isDocumentSummaryInformation();
/**
* @see PropertySet#getSingleSection
*/
+ @Override
public Section getFirstSection()
{
return delegate.getFirstSection();
/**
* @see org.apache.poi.hpsf.MutablePropertySet#addSection(org.apache.poi.hpsf.Section)
*/
+ @Override
public void addSection(final Section section)
{
delegate.addSection(section);
/**
* @see org.apache.poi.hpsf.MutablePropertySet#clearSections()
*/
+ @Override
public void clearSections()
{
delegate.clearSections();
/**
* @see org.apache.poi.hpsf.MutablePropertySet#setByteOrder(int)
*/
+ @Override
public void setByteOrder(final int byteOrder)
{
delegate.setByteOrder(byteOrder);
/**
* @see org.apache.poi.hpsf.MutablePropertySet#setClassID(org.apache.poi.hpsf.ClassID)
*/
+ @Override
public void setClassID(final ClassID classID)
{
delegate.setClassID(classID);
/**
* @see org.apache.poi.hpsf.MutablePropertySet#setFormat(int)
*/
+ @Override
public void setFormat(final int format)
{
delegate.setFormat(format);
/**
* @see org.apache.poi.hpsf.MutablePropertySet#setOSVersion(int)
*/
+ @Override
public void setOSVersion(final int osVersion)
{
delegate.setOSVersion(osVersion);
/**
* @see org.apache.poi.hpsf.MutablePropertySet#toInputStream()
*/
+ @Override
public InputStream toInputStream() throws IOException, WritingNotSupportedException
{
return delegate.toInputStream();
/**
* @see org.apache.poi.hpsf.MutablePropertySet#write(org.apache.poi.poifs.filesystem.DirectoryEntry, java.lang.String)
*/
+ @Override
public void write(final DirectoryEntry dir, final String name) throws WritingNotSupportedException, IOException
{
delegate.write(dir, name);
/**
* @see org.apache.poi.hpsf.MutablePropertySet#write(java.io.OutputStream)
*/
+ @Override
public void write(final OutputStream out) throws WritingNotSupportedException, IOException
{
delegate.write(out);
/**
* @see org.apache.poi.hpsf.PropertySet#equals(java.lang.Object)
*/
+ @Override
public boolean equals(final Object o)
{
return delegate.equals(o);
/**
* @see org.apache.poi.hpsf.PropertySet#getProperties()
*/
+ @Override
public Property[] getProperties() throws NoSingleSectionException
{
return delegate.getProperties();
/**
* @see org.apache.poi.hpsf.PropertySet#getProperty(int)
*/
+ @Override
protected Object getProperty(final int id) throws NoSingleSectionException
{
return delegate.getProperty(id);
/**
* @see org.apache.poi.hpsf.PropertySet#getPropertyBooleanValue(int)
*/
+ @Override
protected boolean getPropertyBooleanValue(final int id) throws NoSingleSectionException
{
return delegate.getPropertyBooleanValue(id);
/**
* @see org.apache.poi.hpsf.PropertySet#getPropertyIntValue(int)
*/
+ @Override
protected int getPropertyIntValue(final int id) throws NoSingleSectionException
{
return delegate.getPropertyIntValue(id);
/**
* Fetches the property with the given ID, then does its
* best to return it as a String
+ *
+ * @param propertyId the property id
+ *
* @return The property as a String, or null if unavailable
*/
protected String getPropertyStringValue(final int propertyId) {
/**
* @see org.apache.poi.hpsf.PropertySet#hashCode()
*/
+ @Override
public int hashCode()
{
return delegate.hashCode();
/**
* @see org.apache.poi.hpsf.PropertySet#toString()
*/
+ @Override
public String toString()
{
return delegate.toString();
/**
* @see org.apache.poi.hpsf.PropertySet#wasNull()
*/
+ @Override
public boolean wasNull() throws NoSingleSectionException
{
return delegate.wasNull();
/**
* Associates the string representation of a section
* format ID with a {@link PropertyIDMap}
+ *
+ * @param key the key of the PropertyIDMap
+ * @param value the PropertyIDMap itself
+ *
+ * @return the previous PropertyIDMap stored under this key, or {@code null} if there wasn't one
*/
protected PropertyIDMap put(String key, PropertyIDMap value) {
return (PropertyIDMap)super.put(key, value);
/**
* Create an array of records from an input stream
*
- *@param is the InputStream from which the records will be obtained
- *@return an array of Records created from the InputStream
- *@exception org.apache.poi.util.RecordFormatException on error processing the InputStream
+ * @param is the InputStream from which the records will be obtained
+ * @param ps the PrintWriter to output the record data
+ * @param recListener the record listener to notify about read records
+ * @param dumpInterpretedRecords if {@code true}, the read records will be written to the PrintWriter
+ *
+ * @return an array of Records created from the InputStream
+ * @exception org.apache.poi.util.RecordFormatException on error processing the InputStream
*/
public static Record[] createRecords(InputStream is, PrintWriter ps, BiffRecordListener recListener, boolean dumpInterpretedRecords)
throws org.apache.poi.util.RecordFormatException {
* <b>Usage</b>:<p>
*
* BiffViewer [--biffhex] [--noint] [--noescher] [--out] <fileName><p>
- * BiffViewer --rawhex [--out] <fileName><p>
- * <p>
+ * BiffViewer --rawhex [--out] <fileName>
*
* <table summary="BiffViewer options">
* <tr><td>--biffhex</td><td>show hex dump of each BIFF record</td></tr>
* <tr><td>--escher</td><td>turn on deserialization of escher records (default is off)</td></tr>
* <tr><td>--noheader</td><td>do not print record header (default is on)</td></tr>
* </table>
+ *
+ * @param args the command line arguments
*
+ * @throws IOException if the file doesn't exist or contained errors
+ * @throws CommandParseException if the command line contained errors
*/
public static void main(String[] args) throws IOException, CommandParseException {
// args = new String[] { "--out", "", };
_headers = new ArrayList<String>();
}
- public void processRecord(int globalOffset, int recordCounter, int sid, int dataSize,
+ @Override
+ public void processRecord(int globalOffset, int recordCounter, int sid, int dataSize,
byte[] data) {
String header = formatRecordDetails(globalOffset, sid, dataSize, recordCounter);
if(!_noHeader) _headers.add(header);
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.ss.formula.ptg.ExpPtg;
import org.apache.poi.ss.formula.ptg.FuncPtg;
-import org.apache.poi.ss.formula.ptg.OperationPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
/**
/**
* Method run
- * @throws IOException
- *
- *
- * @exception Exception
- *
+ *
+ * @throws IOException if the file contained errors
*/
-
public void run() throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
InputStream is = BiffViewer.getPOIFSInputStream(fs);
/**
* Method parseFormulaRecord
*
- *
- * @param record
- *
+ * @param record the record to be parsed
*/
-
public void parseFormulaRecord(FormulaRecord record)
{
System.out.println("==============================");
StringBuffer buf = new StringBuffer();
Ptg[] tokens = record.getParsedExpression();
- for (int i = 0; i < tokens.length; i++) {
- Ptg token = tokens[i];
- buf.append( token.toFormulaString());
+ for (Ptg token : tokens) {
+ buf.append( token.toFormulaString());
switch (token.getPtgClass()) {
case Ptg.CLASS_REF :
buf.append("(R)");
/**
* Method setFile
*
- *
- * @param file
- *
+ * @param file the file to process
*/
public void setFile(String file)
* pass me a filename and I'll try and parse the formulas from it
*
* @param args pass one argument with the filename or --help
- * @throws IOException
- * @throws Exception
- *
+ * @throws IOException if the file can't be read or contained errors
*/
-
public static void main(String args[]) throws IOException
{
if ((args == null) || (args.length >2 )
/**
* Process a Record. This method is called by the
* EventRecordFactory when a record is returned.
+ *
+ * @param rec the record to be processed
+ *
* @return boolean specifying whether the effort was a success.
*/
public boolean processRecord(Record rec);
* this version sends {@link ERFListener#processRecord(Record) } messages to
* the supplied listener. Record notifications are sent one record behind
* to ensure that {@link ContinueRecord}s are processed first.
- *
- * @author Andrew C. Oliver (acoliver@apache.org) - probably to blame for the bugs (so yank his chain on the list)
- * @author Marc Johnson (mjohnson at apache dot org) - methods taken from RecordFactory
- * @author Glen Stampoultzis (glens at apache.org) - methods taken from RecordFactory
- * @author Csaba Nagy (ncsaba at yahoo dot com)
*/
public final class EventRecordFactory {
private final short[] _sids;
/**
+ * Create an EventRecordFactory
*
+ * @param listener the listener to be informed about events
* @param sids an array of Record.sid values identifying the records
* the listener will work with. Alternatively if this is "null" then
* all records are passed. For all 'known' record types use {@link RecordFactory#getAllKnownRecordSIDs()}
recStream.nextRecord();
Record[] recs = RecordFactory.createRecord(recStream); // handle MulRK records
if (recs.length > 1) {
- for (int k = 0; k < recs.length; k++) {
+ for (Record rec : recs) {
if ( last_record != null ) {
if (!processRecord(last_record)) {
return;
}
}
- last_record = recs[ k ]; // do to keep the algorithm homogeneous...you can't
+ last_record = rec; // do to keep the algorithm homogeneous...you can't
} // actually continue a number record anyhow.
} else {
Record record = recs[ 0 ];
* It is never called by HSSFEventFactory or HSSFRequest.
* You should implement #abortableProcessRecord instead
*/
- public void processRecord(Record record)
+ @Override
+ public void processRecord(Record record)
{
}
*
* Note that HSSFEventFactory will not call the inherited process
*
+ * @param record the record to be processed
+ *
* @return result code of zero for continued processing.
*
* @throws HSSFUserException User code can throw this to abort
// Core Workbook records go first
if(bounds != null) {
- for(int i=0; i<bounds.length; i++) {
- wbRecords.add(bounds[i]);
+ for (BoundSheetRecord bound : bounds) {
+ wbRecords.add(bound);
}
}
if(sst != null) {
if(externs != null) {
wbRecords.add(SupBookRecord.createInternalReferences(
(short)externs.length));
- for(int i=0; i<externs.length; i++) {
- wbRecords.add(externs[i]);
+ for (ExternSheetRecord extern : externs) {
+ wbRecords.add(extern);
}
}
* them once required.
*/
public static class SheetRecordCollectingListener implements HSSFListener {
- private HSSFListener childListener;
- private List<BoundSheetRecord> boundSheetRecords = new ArrayList<BoundSheetRecord>();
- private List<ExternSheetRecord> externSheetRecords = new ArrayList<ExternSheetRecord>();
+ private final HSSFListener childListener;
+ private final List<BoundSheetRecord> boundSheetRecords = new ArrayList<BoundSheetRecord>();
+ private final List<ExternSheetRecord> externSheetRecords = new ArrayList<ExternSheetRecord>();
private SSTRecord sstRecord = null;
public SheetRecordCollectingListener(HSSFListener childListener) {
* Process this record ourselves, and then
* pass it on to our child listener
*/
- public void processRecord(Record record) {
+ @Override
+ public void processRecord(Record record) {
// Handle it ourselves
processRecordInternally(record);
/**
* Process the record ourselves, but do not
* pass it on to the child Listener.
+ *
+ * @param record the record to be processed
*/
public void processRecordInternally(Record record) {
if(record instanceof BoundSheetRecord) {
/**
* Creates a format tracking wrapper around the given listener, using
* the {@link Locale#getDefault() default locale} for the formats.
+ *
+ * @param childListener the listener to be wrapped
*/
public FormatTrackingHSSFListener(HSSFListener childListener) {
this(childListener, LocaleUtil.getUserLocale());
/**
* Creates a format tracking wrapper around the given listener, using
* the given locale for the formats.
+ *
+ * @param childListener the listener to be wrapped
+ * @param locale the locale for the formats
*/
public FormatTrackingHSSFListener(
HSSFListener childListener, Locale locale) {
/**
* Process this record ourselves, and then pass it on to our child listener
*/
- public void processRecord(Record record) {
+ @Override
+ public void processRecord(Record record) {
// Handle it ourselves
processRecordInternally(record);
* Process the record ourselves, but do not pass it on to the child
* Listener.
*
- * @param record
+ * @param record the record to be processed
*/
public void processRecordInternally(Record record) {
if (record instanceof FormatRecord) {
}
/**
- * Formats the given numeric of date Cell's contents as a String, in as
+ * Formats the given numeric of date cells contents as a String, in as
* close as we can to the way that Excel would do so. Uses the various
* format records to manage this.
*
* TODO - move this to a central class in such a way that hssf.usermodel can
* make use of it too
+ *
+ * @param cell the cell
+ *
+ * @return the given numeric of date cells contents as a String
*/
public String formatNumberDateCell(CellValueRecordInterface cell) {
double value;
/**
* Returns the format string, eg $##.##, for the given number format index.
+ *
+ * @param formatIndex the format index
+ *
+ * @return the format string
*/
public String getFormatString(int formatIndex) {
String format = null;
/**
* Returns the format string, eg $##.##, used by your cell
+ *
+ * @param cell the cell
+ *
+ * @return the format string
*/
public String getFormatString(CellValueRecordInterface cell) {
int formatIndex = getFormatIndex(cell);
}
/**
- * Returns the index of the format string, used by your cell, or -1 if none
- * found
+ * Returns the index of the format string, used by your cell, or -1 if none found
+ *
+ * @param cell the cell
+ *
+ * @return the index of the format string
*/
public int getFormatIndex(CellValueRecordInterface cell) {
ExtendedFormatRecord xfr = _xfRecords.get(cell.getXFIndex());
*
* @param req an Instance of HSSFRequest which has your registered listeners
* @param fs a POIFS filesystem containing your workbook
+ *
+ * @throws IOException if the workbook contained errors
*/
public void processWorkbookEvents(HSSFRequest req, POIFSFileSystem fs) throws IOException {
processWorkbookEvents(req, fs.getRoot());
*
* @param req an Instance of HSSFRequest which has your registered listeners
* @param dir a DirectoryNode containing your workbook
+ *
+ * @throws IOException if the workbook contained errors
*/
public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException {
// some old documents have "WORKBOOK" or "BOOK"
}
InputStream in = dir.createDocumentInputStream(name);
- processEvents(req, in);
+ try {
+ processEvents(req, in);
+ } finally {
+ in.close();
+ }
}
/**
* @param req an Instance of HSSFRequest which has your registered listeners
* @param fs a POIFS filesystem containing your workbook
* @return numeric user-specified result code.
+ *
+ * @throws HSSFUserException if the processing should be aborted
+ * @throws IOException if the workbook contained errors
*/
public short abortableProcessWorkbookEvents(HSSFRequest req, POIFSFileSystem fs)
throws IOException, HSSFUserException {
* @param req an Instance of HSSFRequest which has your registered listeners
* @param dir a DirectoryNode containing your workbook
* @return numeric user-specified result code.
+ *
+ * @throws HSSFUserException if the processing should be aborted
+ * @throws IOException if the workbook contained errors
*/
public short abortableProcessWorkbookEvents(HSSFRequest req, DirectoryNode dir)
throws IOException, HSSFUserException {
InputStream in = dir.createDocumentInputStream("Workbook");
- return abortableProcessEvents(req, in);
+ try {
+ return abortableProcessEvents(req, in);
+ } finally {
+ in.close();
+ }
}
/**
* @param req an Instance of HSSFRequest which has your registered listeners
* @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
* @return numeric user-specified result code.
+ *
+ * @throws HSSFUserException if the processing should be aborted
*/
public short abortableProcessEvents(HSSFRequest req, InputStream in)
throws HSSFUserException {
/**
* process an HSSF Record. Called when a record occurs in an HSSF file.
+ *
+ * @param record the record to be processed
*/
-
public void processRecord(Record record);
}
public void addListenerForAllRecords(HSSFListener lsnr) {
short[] rectypes = RecordFactory.getAllKnownRecordSIDs();
- for (int k = 0; k < rectypes.length; k++) {
- addListener(lsnr, rectypes[k]);
+ for (short rectype : rectypes) {
+ addListener(lsnr, rectype);
}
}
/**
* Called by HSSFEventFactory, passes the Record to each listener associated with
* a record.sid.
- *
- * Exception and return value added 2002-04-19 by Carey Sublette
+ *
+ * @param rec the record to be processed
*
* @return numeric user-specified result code. If zero continue processing.
* @throws HSSFUserException User exception condition
/**
* <p>Creates a new {@link HSSFUserException} with a message
* string.</p>
+ *
+ * @param msg the error message
*/
public HSSFUserException(final String msg)
{
/**
* <p>Creates a new {@link HSSFUserException} with a reason.</p>
+ *
+ * @param reason the causing exception
*/
public HSSFUserException(final Throwable reason)
{
/**
* <p>Creates a new {@link HSSFUserException} with a message string
* and a reason.</p>
+ *
+ * @param msg the error message
+ * @param reason the causing exception
*/
public HSSFUserException(final String msg, final Throwable reason)
{
* <p>Returns the {@link Throwable} that caused this exception to
* be thrown or <code>null</code> if there was no such {@link
* Throwable}.</p>
+ *
+ * @return the reason
*/
public Throwable getReason()
{
* cell record for this row.
*/
public final class LastCellOfRowDummyRecord extends DummyRecordBase {
- private int row;
- private int lastColumnNumber;
+ private final int row;
+ private final int lastColumnNumber;
public LastCellOfRowDummyRecord(int row, int lastColumnNumber) {
this.row = row;
/**
* Returns the (0 based) number of the row we are
* currently working on.
+ *
+ * @return the (0 based) number of the row
*/
- public int getRow() { return row; }
+ public int getRow() {
+ return row;
+ }
+
/**
* Returns the (0 based) number of the last column
* seen for this row. You should have already been
* called with that record.
* This is -1 in the case of there being no columns
* for the row.
+ *
+ * @return the (0 based) number of the last column
*/
- public int getLastColumnNumber() { return lastColumnNumber; }
+ public int getLastColumnNumber() {
+ return lastColumnNumber;
+ }
+ @Override
public String toString() {
return "End-of-Row for Row=" + row + " at Column=" + lastColumnNumber;
}
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HeaderFooter;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
* @see <a href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/eventusermodel/examples/XLS2CSVmra.java">XLS2CSVmra</a>
*/
public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.poi.ss.extractor.ExcelExtractor {
- private HSSFWorkbook _wb;
- private HSSFDataFormatter _formatter;
+ private final HSSFWorkbook _wb;
+ private final HSSFDataFormatter _formatter;
private boolean _includeSheetNames = true;
private boolean _shouldEvaluateFormulas = true;
private boolean _includeCellComments = false;
/**
* Command line extractor.
- * @throws IOException
+ *
+ * @param args the command line parameters
+ *
+ * @throws IOException if the file can't be read or contains errors
*/
public static void main(String[] args) throws IOException {
extractor.close();
wb.close();
}
- /**
- * Should sheet names be included? Default is true
- */
- public void setIncludeSheetNames(boolean includeSheetNames) {
+
+ @Override
+ public void setIncludeSheetNames(boolean includeSheetNames) {
_includeSheetNames = includeSheetNames;
}
- /**
- * Should we return the formula itself, and not
- * the result it produces? Default is false
- */
- public void setFormulasNotResults(boolean formulasNotResults) {
+
+ @Override
+ public void setFormulasNotResults(boolean formulasNotResults) {
_shouldEvaluateFormulas = !formulasNotResults;
}
- /**
- * Should cell comments be included? Default is false
- */
- public void setIncludeCellComments(boolean includeCellComments) {
+
+ @Override
+ public void setIncludeCellComments(boolean includeCellComments) {
_includeCellComments = includeCellComments;
}
+
/**
* Should blank cells be output? Default is to only
* output cells that are present in the file and are
* non-blank.
+ *
+ * @param includeBlankCells {@code true} if blank cells should be included
*/
public void setIncludeBlankCells(boolean includeBlankCells) {
_includeBlankCells = includeBlankCells;
}
- /**
- * Should headers and footers be included in the output?
- * Default is to include them.
- */
- public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
+
+ @Override
+ public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
_includeHeadersFooters = includeHeadersFooters;
}
- /**
- * Retrieves the text contents of the file
- */
- public String getText() {
+ @Override
+ public String getText() {
StringBuffer text = new StringBuffer();
// We don't care about the difference between
outputContents = _includeBlankCells;
} else {
switch(cell.getCellType()) {
- case HSSFCell.CELL_TYPE_STRING:
+ case Cell.CELL_TYPE_STRING:
text.append(cell.getRichStringCellValue().getString());
break;
- case HSSFCell.CELL_TYPE_NUMERIC:
+ case Cell.CELL_TYPE_NUMERIC:
text.append(
_formatter.formatCellValue(cell)
);
break;
- case HSSFCell.CELL_TYPE_BOOLEAN:
+ case Cell.CELL_TYPE_BOOLEAN:
text.append(cell.getBooleanCellValue());
break;
- case HSSFCell.CELL_TYPE_ERROR:
+ case Cell.CELL_TYPE_ERROR:
text.append(ErrorEval.getText(cell.getErrorCellValue()));
break;
- case HSSFCell.CELL_TYPE_FORMULA:
+ case Cell.CELL_TYPE_FORMULA:
if(!_shouldEvaluateFormulas) {
text.append(cell.getCellFormula());
} else {
switch(cell.getCachedFormulaResultType()) {
- case HSSFCell.CELL_TYPE_STRING:
+ case Cell.CELL_TYPE_STRING:
HSSFRichTextString str = cell.getRichStringCellValue();
if(str != null && str.length() > 0) {
text.append(str.toString());
}
break;
- case HSSFCell.CELL_TYPE_NUMERIC:
+ case Cell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle();
double nVal = cell.getNumericCellValue();
short df = style.getDataFormat();
String dfs = style.getDataFormatString();
text.append(_formatter.formatRawCellContents(nVal, df, dfs));
break;
- case HSSFCell.CELL_TYPE_BOOLEAN:
+ case Cell.CELL_TYPE_BOOLEAN:
text.append(cell.getBooleanCellValue());
break;
- case HSSFCell.CELL_TYPE_ERROR:
+ case Cell.CELL_TYPE_ERROR:
text.append(ErrorEval.getText(cell.getErrorCellValue()));
break;
default:
/**
* The Biff version, largely corresponding to the Excel version
+ *
+ * @return the Biff version
*/
public int getBiffVersion() {
return biffVersion;
}
+
/**
* The kind of the file, one of {@link BOFRecord#TYPE_WORKSHEET},
* {@link BOFRecord#TYPE_CHART}, {@link BOFRecord#TYPE_EXCEL_4_MACRO}
* or {@link BOFRecord#TYPE_WORKSPACE_FILE}
+ *
+ * @return the file type
*/
public int getFileType() {
return fileType;
/**
* Retrieves the text contents of the file, as best we can
* for these old file formats
+ *
+ * @return the text contents of the file
*/
public String getText() {
StringBuffer text = new StringBuffer();
import java.io.ByteArrayInputStream;
/**
- * Title: Record
- * Description: All HSSF Records inherit from this class.
- * @author Andrew C. Oliver
- * @author Marc Johnson (mjohnson at apache dot org)
- * @author Jason Height (jheight at chariot dot net dot au)
+ * All HSSF Records inherit from this class.
*/
public abstract class Record extends RecordBase {
/**
* return the non static version of the id for this record.
+ *
+ * @return he id for this record
*/
-
public abstract short getSid();
@Override
* internal counts / ids in them. For those which
* do, a full model-aware cloning is needed, which
* allocates new ids / counts as needed.
+ *
+ * @return the cloned current record
*/
public Record cloneViaReserialise() {
// Do it via a re-serialization
/**
* Common base class of {@link Record} and {@link org.apache.poi.hssf.record.aggregates.RecordAggregate}
- *
- * @author Josh Micich
*/
public abstract class RecordBase {
/**
/**
* gives the current serialized size of the record. Should include the sid
* and reclength (4 bytes).
+ *
+ * @return the record size
*/
public abstract int getRecordSize();
}
*/
public interface ExcelExtractor {
/**
- * Should sheet names be included? Default is true
+ * Should sheet names be included?
+ * Default is true
+ *
+ * @param includeSheetNames {@code true} if the sheet names should be included
*/
public void setIncludeSheetNames(boolean includeSheetNames);
/**
- * Should we return the formula itself, and not
- * the result it produces? Default is false
+ * Should we return the formula itself, and not the result it produces?
+ * Default is false
+ *
+ * @param formulasNotResults {@code true} if the formula itself is returned
*/
public void setFormulasNotResults(boolean formulasNotResults);
/**
* Should headers and footers be included in the output?
* Default is true
+ *
+ * @param includeHeadersFooters {@code true} if headers and footers should be included
*/
public void setIncludeHeadersFooters(boolean includeHeadersFooters);
/**
- * Should cell comments be included? Default is false
+ * Should cell comments be included?
+ * Default is false
+ *
+ * @param includeCellComments {@code true} if cell comments should be included
*/
public void setIncludeCellComments(boolean includeCellComments);
/**
- * Retreives the text contents of the file
+ * Retrieves the text contents of the file
+ *
+ * @return the text contents of the file
*/
public String getText();
}
* they're all related to each other.
*/
public class OOXMLLister {
- private OPCPackage container;
- private PrintStream disp;
+ private final OPCPackage container;
+ private final PrintStream disp;
public OOXMLLister(OPCPackage container) {
this(container, System.out);
*
* @param part the PackagePart
* @return the size of the PackagePart
+ *
+ * @throws IOException if the part can't be read
*/
public static long getSize(PackagePart part) throws IOException {
InputStream in = part.getInputStream();