public class RubyOutputStream extends OutputStream {
- //pointer to native ruby VALUE
+ //pointer to native ruby VALUE
protected long rubyIO;
public RubyOutputStream (long rubyIO)
// incRef();
}
- protected void finalize()
+ @Override
+ protected void finalize()
throws Throwable
{
// decRef();
// protected native void incRef();
// protected native void decRef();
- public native void close()
+ @Override
+ public native void close()
throws IOException;
/* (non-Javadoc)
* @see java.io.OutputStream#write(int)
*/
+ @Override
public native void write(int arg0) throws IOException;
}
/**
* A general utility class that abstracts the POI details of loading the
* workbook, accessing and updating cells.
- *
+ *
* @author Jon Svede ( jon [at] loquatic [dot] com )
* @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
- *
+ *
*/
public class ExcelAntWorkbookUtil extends Typedef {
private Workbook workbook;
private HashMap<String, FreeRefFunction> xlsMacroList;
-
+
/**
* Constructs an instance using a String that contains the fully qualified
* path of the Excel file. This constructor initializes a Workbook instance
* based on that file name.
- *
+ *
* @param fName
*/
protected ExcelAntWorkbookUtil(String fName) {
excelFileName = fName;
xlsMacroList = new HashMap<String, FreeRefFunction>() ;
loadWorkbook();
-
+
}
/**
* Constructs an instance based on a Workbook instance.
- *
+ *
* @param wb
*/
protected ExcelAntWorkbookUtil(Workbook wb) {
File workbookFile = new File(excelFileName);
try {
FileInputStream fis = new FileInputStream(workbookFile);
- workbook = WorkbookFactory.create(fis);
+ try {
+ workbook = WorkbookFactory.create(fis);
+ } finally {
+ fis.close();
+ }
} catch(Exception e) {
throw new BuildException("Cannot load file " + excelFileName
+ ". Make sure the path and file permissions are correct.", e);
return workbook ;
}
-
+
/**
- * Used to add a UDF to the evaluator.
+ * Used to add a UDF to the evaluator.
* @param name
* @param clazzName
* @throws ClassNotFoundException
* @throws IllegalAccessException
*/
public void addFunction( String name, String clazzName ) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- Class clazzInst = Class.forName( clazzName ) ;
+ Class<?> clazzInst = Class.forName( clazzName ) ;
Object newInst = clazzInst.newInstance() ;
if( newInst instanceof FreeRefFunction ) {
addFunction( name, (FreeRefFunction)newInst ) ;
}
-
+
}
-
+
/**
* Updates the internal HashMap of functions with instance and alias passed
* in.
- *
+ *
* @param name
* @param func
*/
/**
* returns a UDFFinder that contains all of the functions added.
- *
+ *
* @return
*/
protected UDFFinder getFunctions() {
return udff;
}
-
+
/**
* Returns a formula evaluator that is loaded with the functions that
* have been supplied.
- *
- * @param excelFileName
+ *
+ * @param fileName
* @return
*/
- protected FormulaEvaluator getEvaluator( String excelFileName ) {
+ protected FormulaEvaluator getEvaluator( String fileName ) {
FormulaEvaluator evaluator ;
- if (excelFileName.endsWith(".xlsx")) {
+ if (fileName.endsWith(".xlsx")) {
if( xlsMacroList != null && xlsMacroList.size() > 0 ) {
evaluator = XSSFFormulaEvaluator.create( (XSSFWorkbook) workbook,
null,
/**
* Returns the Workbook instance associated with this WorkbookUtil.
- *
+ *
* @return
*/
public Workbook getWorkbook() {
/**
* Returns the fileName that was used to initialize this instance. May
* return null if the instance was constructed from a Workbook object.
- *
+ *
* @return
*/
public String getFileName() {
return excelFileName;
}
-
+
/**
* Returns the list of sheet names.
- *
+ *
* @return
*/
public ArrayList<String> getSheets() {
ArrayList<String> sheets = new ArrayList<String>() ;
-
+
int sheetCount = workbook.getNumberOfSheets() ;
-
+
for( int x=0; x<sheetCount; x++ ) {
sheets.add( workbook.getSheetName( x ) ) ;
}
-
+
return sheets ;
}
/**
* This method uses a String in standard Excel format (SheetName!CellId) to
* locate the cell and set it to the value of the double in value.
- *
+ *
* @param cellName
* @param value
*/
/**
* Utility method for setting the value of a Cell with a String.
- *
+ *
* @param cellName
* @param value
*/
public void setStringValue( String cellName, String value ) {
Cell cell = getCell(cellName);
- cell.setCellValue(value);
+ cell.setCellValue(value);
}
-
+
/**
* Utility method for setting the value of a Cell with a Formula.
- *
+ *
* @param cellName
* @param formula
*/
Cell cell = getCell(cellName);
cell.setCellFormula( formula );
}
-
+
/**
* Utility method for setting the value of a Cell with a Date.
* @param cellName
/**
* Uses a String in standard Excel format (SheetName!CellId) to locate a
* cell and evaluate it.
- *
+ *
* @param cellName
* @param expectedValue
* @param precision
errorMeaning = ErrorConstants.getText( resultOfEval
.getErrorValue() ) ;
} catch( IllegalArgumentException iae ) {
- errorMeaning = "unknown error code: " +
- Byte.toString( resultOfEval.getErrorValue() ) ;
+ errorMeaning = "unknown error code: " +
+ Byte.toString( resultOfEval.getErrorValue() ) ;
}
-
+
evalResults = new ExcelAntEvaluationResult(false, false,
resultOfEval.getNumberValue(),
"Evaluation failed due to an evaluation error of "
/**
* Returns a Cell as a String value.
- *
+ *
* @param cellName
* @return
*/
}
return "" ;
}
-
-
+
+
/**
* Returns the value of the Cell as a double.
- *
+ *
* @param cellName
* @return
*/
* Returns a cell reference based on a String in standard Excel format
* (SheetName!CellId). This method will create a new cell if the
* requested cell isn't initialized yet.
- *
+ *
* @param cellName
* @return
*/
private Cell getCell(String cellName) {
-
+
CellReference cellRef = new CellReference(cellName);
String sheetName = cellRef.getSheetName();
Sheet sheet = workbook.getSheet(sheetName);
int rowIdx = cellRef.getRow();
int colIdx = cellRef.getCol();
Row row = sheet.getRow(rowIdx);
-
+
if( row == null ) {
row = sheet.createRow( rowIdx ) ;
}
-
+
Cell cell = row.getCell(colIdx);
-
+
if( cell == null ) {
cell = row.createCell( colIdx ) ;
}
/**\r
* This is a factory class maps file names to WorkbookUtil instances. This\r
* helps ExcelAnt be more efficient when being run many times in an Ant build.\r
- * \r
+ *\r
* @author Jon Svede ( jon [at] loquatic [dot] com )\r
* @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )\r
*\r
*/\r
public class ExcelAntWorkbookUtilFactory {\r
- \r
+\r
private static HashMap<String, ExcelAntWorkbookUtil> workbookUtilMap ;\r
- \r
+\r
private static ExcelAntWorkbookUtilFactory factory ;\r
- \r
+\r
private ExcelAntWorkbookUtilFactory() {\r
- workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>() ; \r
+ workbookUtilMap = new HashMap<String, ExcelAntWorkbookUtil>() ;\r
}\r
- \r
+\r
/**\r
- * Using the fileName, check the internal map to see if an instance \r
+ * Using the fileName, check the internal map to see if an instance\r
* of the WorkbookUtil exists. If not, then add an instance to the map.\r
- * \r
+ *\r
* @param fileName\r
* @return\r
*/\r
public static ExcelAntWorkbookUtil getInstance( String fileName ) {\r
- \r
+\r
if( factory == null ) {\r
factory = new ExcelAntWorkbookUtilFactory() ;\r
}\r
- if( workbookUtilMap != null && \r
+ if( workbookUtilMap != null &&\r
workbookUtilMap.containsKey( fileName ) ) {\r
return workbookUtilMap.get( fileName ) ;\r
- } else {\r
- ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil( fileName ) ;\r
- workbookUtilMap.put( fileName, wbu ) ;\r
- return wbu ;\r
}\r
+\r
+ ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil( fileName ) ;\r
+ workbookUtilMap.put( fileName, wbu ) ;\r
+ return wbu ;\r
}\r
\r
}\r
* @param opt The escher records holding the proerties
* @return number of escher options added
*/
- protected int addStandardOptions( HSSFShape shape, EscherOptRecord opt )
+ @Override
+ protected int addStandardOptions( HSSFShape shape, EscherOptRecord opt )
{
super.addStandardOptions(shape, opt);
private static final String[] WORKBOOK_DIR_ENTRY_NAMES = {
"Workbook", // as per BIFF8 spec
"WORKBOOK", // Typically from third party programs
- "BOOK", // Typically odd Crystal Reports exports
+ "BOOK", // Typically odd Crystal Reports exports
};
{
this(directory, preserveNodes);
}
-
+
/**
* given a POI POIFSFileSystem object, and a specific directory
* within it, read in its Workbook and populate the high and
* the Workbook.
*
* @param records a collection of sheet's records.
- * @param offset the offset to search at
+ * @param offset the offset to search at
* @see org.apache.poi.hssf.record.LabelRecord
* @see org.apache.poi.hssf.record.LabelSSTRecord
* @see org.apache.poi.hssf.record.SSTRecord
* deprecated May 2008
* @deprecated use setSelectedTab(int)
*/
- public void setSelectedTab(short index) {
+ @Deprecated
+ public void setSelectedTab(short index) {
setSelectedTab((int)index);
}
public void setSelectedTabs(int[] indexes) {
* deprecated May 2008
* @deprecated - Misleading name - use getActiveSheetIndex()
*/
- public short getSelectedTab() {
+ @Deprecated
+ public short getSelectedTab() {
return (short) getActiveSheetIndex();
}
* deprecated May 2008
* @deprecated - Misleading name - use setFirstVisibleTab()
*/
- public void setDisplayedTab(short index) {
+ @Deprecated
+ public void setDisplayedTab(short index) {
setFirstVisibleTab(index);
}
* deprecated May 2008
* @deprecated - Misleading name - use getFirstVisibleTab()
*/
- public short getDisplayedTab() {
+ @Deprecated
+ public short getDisplayedTab() {
return (short) getFirstVisibleTab();
}
* @deprecated for POI internal use only (formula parsing). This method is likely to
* be removed in future versions of POI.
*/
- public int getExternalSheetIndex(int internalSheetIndex) {
+ @Deprecated
+ public int getExternalSheetIndex(int internalSheetIndex) {
return workbook.checkExternSheet(internalSheetIndex);
}
/**
* @deprecated for POI internal use only (formula rendering). This method is likely to
* be removed in future versions of POI.
*/
- public String findSheetNameFromExternSheet(int externSheetIndex){
+ @Deprecated
+ public String findSheetNameFromExternSheet(int externSheetIndex){
// TODO - don't expose internal ugliness like externSheet indexes to the user model API
return workbook.findSheetNameFromExternSheet(externSheetIndex);
}
* @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
* @return the string representation of the defined or external name
*/
- public String resolveNameXText(int refIndex, int definedNameIndex) {
+ @Deprecated
+ public String resolveNameXText(int refIndex, int definedNameIndex) {
// TODO - make this less cryptic / move elsewhere
return workbook.resolveNameXText(refIndex, definedNameIndex);
}
public HSSFSheet getSheetAt(int index)
{
validateSheetIndex(index);
- return (HSSFSheet) _sheets.get(index);
+ return _sheets.get(index);
}
/**
if (sheetname.equalsIgnoreCase(name))
{
- retval = (HSSFSheet) _sheets.get(k);
+ retval = _sheets.get(k);
}
}
return retval;
* @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows.
- *
+ *
* @deprecated use {@link HSSFSheet#setRepeatingRows(CellRangeAddress)}
* or {@link HSSFSheet#setRepeatingColumns(CellRangeAddress)}
*/
- public void setRepeatingRowsAndColumns(int sheetIndex,
+ @Deprecated
+ public void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn, int endColumn,
int startRow, int endRow) {
HSSFSheet sheet = getSheetAt(sheetIndex);
return -1;
}
-
+
HSSFName createBuiltInName(byte builtinCode, int sheetIndex) {
- NameRecord nameRecord =
+ NameRecord nameRecord =
workbook.createBuiltInName(builtinCode, sheetIndex + 1);
HSSFName newName = new HSSFName(this, nameRecord, null);
names.add(newName);
return newName;
}
-
+
HSSFName getBuiltInName(byte builtinCode, int sheetIndex) {
int index = findExistingBuiltinNameRecordIdx(sheetIndex, builtinCode);
if (index < 0) {
}
}
-
+
/**
* create a new Font and add it to the workbook's font table
* @return new font object
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
*/
- public void write(OutputStream stream)
+ @Override
+ public void write(OutputStream stream)
throws IOException
{
byte[] bytes = getBytes();
/** @deprecated Do not call this method from your applications. Use the methods
* available in the HSSFRow to add string HSSFCells
*/
- public int addSSTString(String string)
+ @Deprecated
+ public int addSSTString(String string)
{
return workbook.addSSTString(new UnicodeString(string));
}
/** @deprecated Do not call this method from your applications. Use the methods
* available in the HSSFRow to get string HSSFCells
*/
- public String getSSTString(int index)
+ @Deprecated
+ public String getSSTString(int index)
{
return workbook.getSSTString(index).getString();
}
if (nameIndex < 0) {
return null;
}
- return (HSSFName) names.get(nameIndex);
+ return names.get(nameIndex);
}
public HSSFName getNameAt(int nameIndex) {
throw new IllegalArgumentException("Specified name index " + nameIndex
+ " is outside the allowable range (0.." + (nNames-1) + ").");
}
- return (HSSFName) names.get(nameIndex);
+ return names.get(nameIndex);
}
public NameRecord getNameRecord(int nameIndex) {
/**
- * As {@link #getNameIndex(String)} is not necessarily unique
+ * As {@link #getNameIndex(String)} is not necessarily unique
* (name + sheet index is unique), this method is more accurate.
- *
+ *
* @param name the name whose index in the list of names of this workbook
* should be looked up.
- * @return an index value >= 0 if the name was found; -1, if the name was
+ * @return an index value >= 0 if the name was found; -1, if the name was
* not found
*/
int getNameIndex(HSSFName name) {
/**
- * As {@link #removeName(String)} is not necessarily unique
+ * As {@link #removeName(String)} is not necessarily unique
* (name + sheet index is unique), this method is more accurate.
- *
+ *
* @param name the name to remove.
*/
void removeName(HSSFName name) {
public int addPicture(byte[] pictureData, int format)
{
initDrawings();
-
+
byte[] uid = DigestUtils.md5(pictureData);
EscherBitmapBlip blipRecord = new EscherBitmapBlip();
blipRecord.setRecordId( (short) ( EscherBitmapBlip.RECORD_ID_START + format ) );
HSSFPictureData picture = new HSSFPictureData(blip);
pictures.add(picture);
}
-
-
+
+
}
// Recursive call.
searchForPictures(escherRecord.getChildRecords(), pictures);
}
-
+
}
/**
}
/**
* Recursively iterates a shape container to get all embedded objects.
- *
+ *
* @param parent the parent.
* @param objects the list of embedded objects to populate.
*/
/**
* Changes an external referenced file to another file.
- * A formular in Excel which refers a cell in another file is saved in two parts:
+ * A formular in Excel which refers a cell in another file is saved in two parts:
* The referenced file is stored in an reference table. the row/cell information is saved separate.
* This method invokation will only change the reference in the lookup-table itself.
* @param oldUrl The old URL to search for and which is to be replaced
/**
* Converts the text meta-data file into a <tt>FunctionMetadataRegistry</tt>
- *
+ *
* @author Josh Micich
*/
final class FunctionMetadataReader {
private static final String METADATA_FILE_NAME = "functionMetadata.txt";
-
+
/** plain ASCII text metadata file uses three dots for ellipsis */
private static final String ELLIPSIS = "...";
// except in these cases
"LOG10", "ATAN2", "DAYS360", "SUMXMY2", "SUMX2MY2", "SUMX2PY2",
};
- private static final Set DIGIT_ENDING_FUNCTION_NAMES_SET = new HashSet(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES));
+ private static final Set<String> DIGIT_ENDING_FUNCTION_NAMES_SET = new HashSet<String>(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES));
public static FunctionMetadataRegistry createRegistry() {
InputStream is = FunctionMetadataReader.class.getResourceAsStream(METADATA_FILE_NAME);
validateFunctionName(functionName);
// TODO - make POI use isVolatile
- fdb.add(functionIndex, functionName, minParams, maxParams,
+ fdb.add(functionIndex, functionName, minParams, maxParams,
returnClassCode, parameterClassCodes, hasNote);
}
-
+
private static byte parseReturnTypeCode(String code) {
if(code.length() == 0) {
}
/**
- * Makes sure that footnote digits from the original OOO document have not been accidentally
+ * Makes sure that footnote digits from the original OOO document have not been accidentally
* left behind
*/
private static void validateFunctionName(String functionName) {
if(DIGIT_ENDING_FUNCTION_NAMES_SET.contains(functionName)) {
return;
}
- throw new RuntimeException("Invalid function name '" + functionName
+ throw new RuntimeException("Invalid function name '" + functionName
+ "' (is footnote number incorrectly appended)");
}
package org.apache.poi.util;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
String cls = arg.replace(".class", "");
try {
- Class test = Class.forName(cls);
+ @SuppressWarnings("unchecked")
+ Class<? extends TestCase> test = (Class<? extends TestCase>) Class.forName(cls);
suite.addTestSuite(test);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
/**
* Copy classes and interfaces declared as members of this class
*/
- for(Class fc : cls.getDeclaredClasses()){
+ for(Class<?> fc : cls.getDeclaredClasses()){
className = fc.getName();
classRef = className.replace('.', '/') + ".class";
destFile = new File(_destDest, classRef);
/**
*
- * @param ptrn the pattern to filter output
+ * @param ptrn the pattern to filter output
* @return the classes loaded by the system class loader keyed by class name
*/
@SuppressWarnings("unchecked")
}
public String getSheetNameByExternSheet(int externSheetIndex) {
- if (externSheetIndex == sheetIndex) return name;
- else return _fpwb.getSheetNameByExternSheet(externSheetIndex);
+ if (externSheetIndex == sheetIndex)
+ return name;
+
+ return _fpwb.getSheetNameByExternSheet(externSheetIndex);
}
public String resolveNameXText(NameXPtg nameXPtg) {