diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-03-27 14:03:16 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-03-27 14:03:16 +0000 |
commit | 37791e4bdfc706aa5684745594260f243b4be7ee (patch) | |
tree | a8dd8d0976fc478074d52cd3de79e0e6b5e6a33a /src/excelant/java | |
parent | 2bb3839bfe3e3bacff79f8157465633e311239ce (diff) | |
download | poi-37791e4bdfc706aa5684745594260f243b4be7ee.tar.gz poi-37791e4bdfc706aa5684745594260f243b4be7ee.zip |
65206 - Migrate ant / maven to gradle build
update gradle files and project structure along https://github.com/centic9/poi/tree/gradle_build
remove eclipse IDE project files
remove obsolete record generator files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1888111 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant/java')
14 files changed, 0 insertions, 1500 deletions
diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java deleted file mode 100644 index eb446dfde6..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntEvaluateCell.java +++ /dev/null @@ -1,141 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.poi.ss.excelant.util.ExcelAntEvaluationResult; -import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; - -/** - * Instances of this class are used to evaluate a single cell. This is usually - * after some values have been set. The evaluation is actually performed - * by a WorkbookUtil instance. The evaluate() method of the WorkbookUtil - * class returns an EvaluationResult which encapsulates the results and - * information from the evaluation. - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - - * - */ -public class ExcelAntEvaluateCell extends Task { - - private String cell ; - private double expectedValue ; - private double precision ; - private double globalPrecision ; - private boolean requiredToPass; - - - private ExcelAntEvaluationResult result ; - - private ExcelAntWorkbookUtil wbUtil ; - - private boolean showDelta; - - - public ExcelAntEvaluateCell() {} - - protected void setWorkbookUtil( ExcelAntWorkbookUtil wb ) { - wbUtil = wb ; - } - - public void setShowDelta( boolean value ) { - showDelta = value ; - } - - protected boolean showDelta() { - return showDelta ; - } - - public void setCell(String cell) { - this.cell = cell; - } - - public void setRequiredToPass( boolean val ) { - requiredToPass = val ; - } - - protected boolean requiredToPass() { - return requiredToPass ; - } - - public void setExpectedValue(double expectedValue) { - this.expectedValue = expectedValue; - } - - public void setPrecision(double precision) { - this.precision = precision; - } - - protected void setGlobalPrecision( double prec ) { - globalPrecision = prec ; - } - - protected String getCell() { - return cell; - } - - protected double getExpectedValue() { - return expectedValue; - } - - @SuppressWarnings("squid:S4275") - protected double getPrecision() { - // if there is a globalPrecision we will use it unless there is also - // precision set at the evaluate level, then we use that. If there - // is not a globalPrecision, we will use the local precision. - log( "test precision = " + precision + "\tglobal precision = " + globalPrecision, Project.MSG_VERBOSE ) ; - if( globalPrecision > 0 ) { - if( precision > 0 ) { - log( "Using evaluate precision of " + precision + " over the " + - "global precision of " + globalPrecision, Project.MSG_VERBOSE ) ; - return precision ; - } else { - log( "Using global precision of " + globalPrecision, Project.MSG_VERBOSE ) ; - return globalPrecision ; - } - } else { - log( "Using evaluate precision of " + precision, Project.MSG_VERBOSE ) ; - return precision ; - } - } - - @Override - public void execute() throws BuildException { - result = wbUtil.evaluateCell(cell, expectedValue, getPrecision() ) ; - - StringBuilder sb = new StringBuilder() ; - sb.append( "evaluation of cell " ) ; - sb.append( cell ) ; - sb.append( " resulted in " ) ; - sb.append( result.getReturnValue() ) ; - if(showDelta) { - sb.append(" with a delta of ").append(result.getDelta()); - } - - log( sb.toString(), Project.MSG_DEBUG) ; - - } - - public ExcelAntEvaluationResult getResult() { - return result ; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java deleted file mode 100644 index 75892aa738..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntHandlerTask.java +++ /dev/null @@ -1,76 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; - -/** - * This is the class that backs the <handler> tag in the Ant task. - * <p> - * Its purpose is to provide a way to manipulate a workbook in the course - * of an ExcelAnt task. The idea being to model a way for test writers to - * simulate the behaviors of the workbook. - * <p> - * Suppose, for example, you have a workbook that has a worksheet that - * reacts to values entered or selected by the user. It's possible in - * Excel to change other cells based on this but this isn't easily possible - * in POI. In ExcelAnt we handle this using the Handler, which is a Java - * class you write to manipulate the workbook. - * <p> - * In order to use this tag you must write a class that implements the - * <code>IExcelAntWorkbookHandler</code> interface. After writing the - * class you should package it and it's dependencies into a jar file to - * add as library in your Ant build file. - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public class ExcelAntHandlerTask extends Task { - - private String className ; - - private ExcelAntWorkbookUtil wbUtil ; - - public void setClassName( String cName ) { - className = cName ; - } - - protected void setEAWorkbookUtil( ExcelAntWorkbookUtil wkbkUtil ) { - wbUtil = wkbkUtil ; - } - - @Override - public void execute() throws BuildException { - log( "handling the workbook with class " + className, Project.MSG_INFO ) ; - try { - Class<?> clazz = Class.forName( className ) ; - Object handlerObj = clazz.getDeclaredConstructor().newInstance() ; - if( handlerObj instanceof IExcelAntWorkbookHandler ) { - IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ; - iHandler.setWorkbook( wbUtil.getWorkbook() ) ; - iHandler.execute() ; - } - } catch( Exception e ) { - throw new BuildException( e.getMessage(), e ) ; - } - } - } diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntPrecision.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntPrecision.java deleted file mode 100644 index 0739ef5833..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntPrecision.java +++ /dev/null @@ -1,39 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.tools.ant.taskdefs.Typedef; - -/** - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public class ExcelAntPrecision extends Typedef { - - private double value ; - - public void setValue( double precision ) { - value = precision ; - } - - public double getValue() { - return value ; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java deleted file mode 100644 index e62f0623d9..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSet.java +++ /dev/null @@ -1,48 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; -import org.apache.tools.ant.Task; - -/** - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public abstract class ExcelAntSet extends Task { - - protected String cellStr ; - - protected ExcelAntWorkbookUtil wbUtil ; - - public void setCell( String cellName ) { - cellStr = cellName ; - } - - public String getCell() { - return cellStr ; - } - - - public void setWorkbookUtil( ExcelAntWorkbookUtil wb ) { - wbUtil = wb ; - } - -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java deleted file mode 100644 index 2451a61e68..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetDoubleCell.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * Class for use in an Ant build script that sets the value of an Excel - * sheet cell using the cell id ('Sheet Name'!cellId). - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public class ExcelAntSetDoubleCell extends ExcelAntSet { - private double cellValue; - - public ExcelAntSetDoubleCell() {} - - /** - * Set the value of the specified cell as the double passed in. - * @param value The double-value that should be set when this task is executed. - */ - public void setValue( double value ) { - cellValue = value ; - } - - /** - * Return the cell value as a double. - * @return The double-value of the cell as populated via setValue(), null - * if the value was not set yet. - */ - public double getCellValue() { - return cellValue; - } - - @Override - public void execute() throws BuildException { - wbUtil.setDoubleValue(cellStr, cellValue ) ; - - log( "set cell " + cellStr + " to value " + cellValue + " as double.", Project.MSG_DEBUG ) ; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetFormulaCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetFormulaCell.java deleted file mode 100644 index 8dc599b104..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetFormulaCell.java +++ /dev/null @@ -1,53 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * Class for use in an Ant build script that sets the formula of an Excel - * sheet cell using the cell id ('Sheet Name'!cellId). - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public class ExcelAntSetFormulaCell extends ExcelAntSet { - - - private String cellValue ; - - public ExcelAntSetFormulaCell() {} - - public void setValue( String value ) { - cellValue = value ; - } - - protected String getCellValue() { - return cellValue; - } - - @Override - public void execute() throws BuildException { - - wbUtil.setFormulaValue( cellStr, cellValue ) ; - - log( "set cell " + cellStr + " to formula " + cellValue, Project.MSG_DEBUG ) ; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java deleted file mode 100644 index e1ab047fbf..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntSetStringCell.java +++ /dev/null @@ -1,59 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * Class for use in an Ant build script that sets the value of an Excel - * sheet cell using the cell id ('Sheet Name'!cellId). - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public class ExcelAntSetStringCell extends ExcelAntSet { - private String stringValue ; - - public ExcelAntSetStringCell() {} - - /** - * Set the value of the cell to the String passed in. - * @param value The string-value that should be set when this task is executed. - */ - public void setValue(String value ) { - stringValue = value ; - } - - /** - * Return the value that will be set into the cell. - * @return The string-value of the cell as populated via setValue(), null - * if the value was not set yet. - */ - public String getCellValue() { - return stringValue; - } - - @Override - public void execute() throws BuildException { - wbUtil.setStringValue(cellStr, stringValue ) ; - - log( "set cell " + cellStr + " to value " + stringValue + " as String.", Project.MSG_DEBUG ) ; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java deleted file mode 100644 index 4fc7a80508..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java +++ /dev/null @@ -1,155 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.LinkedList; -import java.util.Locale; - -import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; -import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; - -/** - * Ant task class for testing Excel workbook cells. - */ -public class ExcelAntTask extends Task { - - public static final String VERSION = "0.5.0" ; - - private String excelFileName ; - - private boolean failOnError; - - private ExcelAntWorkbookUtil workbookUtil ; - - private ExcelAntPrecision precision ; - - private LinkedList<ExcelAntTest> tests ; - private LinkedList<ExcelAntUserDefinedFunction> functions ; - - public ExcelAntTask() { - tests = new LinkedList<>() ; - functions = new LinkedList<>() ; - } - - public void addPrecision( ExcelAntPrecision prec ) { - precision = prec ; - } - - public void setFailOnError( boolean value ) { - failOnError = value ; - } - public void setFileName( String fileName ) { - excelFileName = fileName ; - } - - public void addTest( ExcelAntTest testElement ) { - tests.add( testElement ) ; - } - - public void addUdf( ExcelAntUserDefinedFunction def ) { - functions.add( def ) ; - } - - @Override - public void execute() throws BuildException { - checkClassPath(); - - int totalCount = 0 ; - int successCount = 0 ; - - StringBuilder versionBffr = new StringBuilder() ; - versionBffr.append( "ExcelAnt version " ) ; - versionBffr.append( VERSION ) ; - versionBffr.append( " Copyright 2011" ) ; - SimpleDateFormat sdf = new SimpleDateFormat( "yyyy", Locale.ROOT ) ; - double currYear = Double.parseDouble( sdf.format( new Date() ) ); - if( currYear > 2011 ) { - versionBffr.append( "-" ) ; - versionBffr.append( currYear ) ; - } - log( versionBffr.toString(), Project.MSG_INFO ) ; - - log( "Using input file: " + excelFileName, Project.MSG_INFO ) ; - - workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName); - - for (ExcelAntTest test : tests) { - log("executing test: " + test.getName(), Project.MSG_DEBUG); - - if (workbookUtil == null) { - workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName); - } - - for (ExcelAntUserDefinedFunction eaUdf : functions) { - try { - workbookUtil.addFunction(eaUdf.getFunctionAlias(), eaUdf.getClassName()); - } catch (Exception e) { - throw new BuildException(e.getMessage(), e); - } - } - test.setWorkbookUtil(workbookUtil); - - if (precision != null && precision.getValue() > 0) { - log("setting precision for the test " + test.getName(), Project.MSG_VERBOSE); - test.setPrecision(precision.getValue()); - } - - test.execute(); - - if (test.didTestPass()) { - successCount++; - } else { - if (failOnError) { - throw new BuildException("Test " + test.getName() + " failed."); - } - } - totalCount++; - - workbookUtil = null; - } - - if( !tests.isEmpty() ) { - log( successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO ); - } - workbookUtil = null; - } - - - /** - * ExcelAnt depends on external libraries not included in the Ant distribution. - * Give user a sensible message if any if the required jars are missing. - */ - private void checkClassPath(){ - try { - Class.forName("org.apache.poi.hssf.usermodel.HSSFWorkbook"); - Class.forName("org.apache.poi.ss.usermodel.WorkbookFactory"); - } catch (Exception e) { - throw new BuildException( - "The <classpath> for <excelant> must include poi.jar and poi-ooxml.jar " + - "if not in Ant's own classpath. Processing .xlsx spreadsheets requires " + - "additional poi-ooxml-lite.jar, xmlbeans.jar" , - e, getLocation()); - } - - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java deleted file mode 100644 index 2fd45cab15..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.function.Supplier; - -import org.apache.poi.ss.excelant.util.ExcelAntEvaluationResult; -import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; - -/** - * This class represents a single test. In order for the test any and all - * ExcelAntEvaluateCell evaluations must pass. Therefore it is recommended - * that you use only 1 evaluator but you can use more if you choose. - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -@SuppressWarnings("unused") -public class ExcelAntTest extends Task{ - private LinkedList<ExcelAntEvaluateCell> evaluators; - - private LinkedList<Task> testTasks; - - private String name; - - private double globalPrecision; - - private boolean showSuccessDetails; - - private boolean showFailureDetail; - LinkedList<String> failureMessages; - - - private ExcelAntWorkbookUtil workbookUtil; - - private boolean passed = true; - - - public ExcelAntTest() { - evaluators = new LinkedList<>(); - failureMessages = new LinkedList<>(); - testTasks = new LinkedList<>(); - } - - public void setPrecision( double precision ) { - globalPrecision = precision; - } - - public void setWorkbookUtil( ExcelAntWorkbookUtil wbUtil ) { - workbookUtil = wbUtil; - } - - - public void setShowFailureDetail( boolean value ) { - showFailureDetail = value; - } - - public void setName( String nm ) { - name = nm; - } - - public String getName() { - return name; - } - - public void setShowSuccessDetails( boolean details ) { - showSuccessDetails = details; - } - - public boolean showSuccessDetails() { - return showSuccessDetails; - } - - public void addSetDouble( ExcelAntSetDoubleCell setter ) { - addSetter( setter ); - } - - public void addSetString( ExcelAntSetStringCell setter ){ - addSetter( setter ); - } - - public void addSetFormula( ExcelAntSetFormulaCell setter ) { - addSetter( setter ); - } - - public void addHandler( ExcelAntHandlerTask handler ) { - testTasks.add( handler ); - } - - private void addSetter( ExcelAntSet setter ) { - testTasks.add( setter ); - } - - public void addEvaluate( ExcelAntEvaluateCell evaluator ) { - testTasks.add( evaluator ); - } - - protected LinkedList<ExcelAntEvaluateCell> getEvaluators() { - return evaluators; - } - - @Override - public void execute() throws BuildException { - - Iterator<Task> taskIt = testTasks.iterator(); - - int testCount = evaluators.size(); - int failureCount = 0; - - // roll over all sub task elements in one loop. This allows the - // ordering of the sub elements to be considered. - while( taskIt.hasNext() ) { - Task task = taskIt.next(); - - // log( task.getClass().getName(), Project.MSG_INFO ); - - if( task instanceof ExcelAntSet ) { - ExcelAntSet set = (ExcelAntSet) task; - set.setWorkbookUtil(workbookUtil); - set.execute(); - } - - if( task instanceof ExcelAntHandlerTask ) { - ExcelAntHandlerTask handler = (ExcelAntHandlerTask)task; - handler.setEAWorkbookUtil(workbookUtil ); - handler.execute(); - } - - if (task instanceof ExcelAntEvaluateCell ) { - ExcelAntEvaluateCell eval = (ExcelAntEvaluateCell)task; - eval.setWorkbookUtil( workbookUtil ); - - if( globalPrecision > 0 ) { - log( "setting globalPrecision to " + globalPrecision + " in the evaluator", Project.MSG_VERBOSE ); - eval.setGlobalPrecision( globalPrecision ); - } - - try { - eval.execute(); - ExcelAntEvaluationResult result = eval.getResult(); - - Supplier<String> details = () -> - result.getCellName() + ". It evaluated to " + - result.getReturnValue() + " when the value of " + - eval.getExpectedValue() + " with precision of " + - eval.getPrecision(); - - if( result.didTestPass() && !result.evaluationCompleteWithError()) { - if(showSuccessDetails) { - log("Succeeded when evaluating " + details.get(), Project.MSG_INFO ); - } - } else { - if(showFailureDetail) { - failureMessages.add( "\tFailed to evaluate cell " + details.get() + " was expected." ); - } - passed = false; - failureCount++; - - if(eval.requiredToPass()) { - throw new BuildException( "\tFailed to evaluate cell " + details.get() + " was expected." ); - } - } - } catch( NullPointerException npe ) { - // this means the cell reference in the test is bad. - log( "Cell assignment " + eval.getCell() + " in test " + getName() + - " appears to point to an empy cell. Please check the " + - " reference in the ant script.", Project.MSG_ERR ); - } - } - } - - if(!passed) { - log( "Test named " + name + " failed because " + failureCount + - " of " + testCount + " evaluations failed to " + - "evaluate correctly.", - Project.MSG_ERR ); - if(showFailureDetail && failureMessages.size() > 0 ) { - for (String failureMessage : failureMessages) { - log(failureMessage, Project.MSG_ERR); - } - } - } - } - - public boolean didTestPass() { - - return passed; - } - } diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java deleted file mode 100644 index f96a01f996..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntUserDefinedFunction.java +++ /dev/null @@ -1,62 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.tools.ant.taskdefs.Typedef; - -/** - * This class encapsulates the Strings necessary to create the User Defined - * Function instances that will be passed to POI's Evaluator instance. - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public class ExcelAntUserDefinedFunction extends Typedef { - - - private String functionAlias ; - - private String className ; - - - public ExcelAntUserDefinedFunction() {} - - protected String getFunctionAlias() { - return functionAlias; - } - - public void setFunctionAlias(String functionAlias) { - this.functionAlias = functionAlias; - } - - protected String getClassName() { - // workaround for IBM JDK assigning the classname to the lowercase instance provided by Definer!?! - // I could not find out why that happens, the wrong assignment seems to be done somewhere deep inside Ant itself - // or even in IBM JDK as Oracle JDK does not have this problem. - if(className == null) { - return getClassname(); - } - - return className; - } - - public void setClassName(String className) { - this.className = className; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java b/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java deleted file mode 100644 index c8db7008d6..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/IExcelAntWorkbookHandler.java +++ /dev/null @@ -1,42 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant; - -import org.apache.poi.ss.usermodel.Workbook; - - -/** - * In Excel there are many ways to handle manipulating a workbook based - * on some arbitrary user action (onChange, etc). You use this interface - * to create classes that will handle the workbook in whatever manner is needed - * that cannot be handled by POI. - * <p> - * For example, suppose that in Excel when you update a cell the workbook - * does some calculations and updates other cells based on that change. In - * ExcelAnt you would set the value of the cell then write your own handler - * then call that from your Ant task after the set task. - * - * @author Jon Svede ( jon [at] loquatic [dot] com ) - * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) - * - */ -public interface IExcelAntWorkbookHandler { - public void setWorkbook( Workbook workbook ) ; - - public void execute() ; -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntEvaluationResult.java b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntEvaluationResult.java deleted file mode 100644 index 4eecd4faeb..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntEvaluationResult.java +++ /dev/null @@ -1,112 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant.util; - -/** - * A simple class that encapsulates information about a cell evaluation - * from POI. - * - * @author Jon Svede (jon [at] loquatic [dot] com) - * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov) - * - */ -public class ExcelAntEvaluationResult { - - /** - * This boolean flag is used to determine if the evaluation completed - * without error. This alone doesn't ensure that the evaluation was - * successful. - */ - private boolean evaluationCompletedWithError ; - - /** - * This boolean flag is used to determine if the result was within - * the specified precision. - */ - private boolean didPass ; - - /** - * This is the actual value returned from the evaluation. - */ - private double returnValue ; - - /** - * Any error message String values that need to be returned. - */ - private String errorMessage ; - - /** - * Stores the absolute value of the delta for this evaluation. - */ - private double actualDelta ; - - /** - * This stores the fully qualified cell name (sheetName!cellId). - */ - private String cellName ; - - - - public ExcelAntEvaluationResult(boolean completedWithError, - boolean passed, - double retValue, - String errMessage, - double delta, - String cellId) { - - evaluationCompletedWithError = completedWithError; - didPass = passed; - returnValue = retValue; - errorMessage = errMessage; - actualDelta = delta ; - cellName = cellId ; - } - - public double getReturnValue() { - return returnValue; - } - - public String getErrorMessage() { - return errorMessage; - } - - public boolean didTestPass() { - return didPass ; - } - - public boolean evaluationCompleteWithError() { - return evaluationCompletedWithError ; - } - - public double getDelta() { - return actualDelta ; - } - - public String getCellName() { - return cellName ; - } - - @Override - public String toString() { - return "ExcelAntEvaluationResult [evaluationCompletedWithError=" - + evaluationCompletedWithError + ", didPass=" + didPass - + ", returnValue=" + returnValue + ", errorMessage=" - + errorMessage + ", actualDelta=" + actualDelta + ", cellName=" - + cellName + "]"; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java deleted file mode 100644 index ee3f443228..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java +++ /dev/null @@ -1,384 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant.util; - -import java.io.FileInputStream; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.formula.functions.FreeRefFunction; -import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; -import org.apache.poi.ss.formula.udf.DefaultUDFFinder; -import org.apache.poi.ss.formula.udf.UDFFinder; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellValue; -import org.apache.poi.ss.usermodel.FormulaError; -import org.apache.poi.ss.usermodel.FormulaEvaluator; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; -import org.apache.poi.ss.util.CellReference; -import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Typedef; - -/** - * 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 String excelFileName; - - private Workbook workbook; - - private final Map<String, FreeRefFunction> xlsMacroList = new HashMap<>(); - - /** - * 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 The fully qualified path of the Excel file. - * @throws BuildException If the workbook cannot be loaded. - */ - protected ExcelAntWorkbookUtil(String fName) { - excelFileName = fName; - loadWorkbook(); - - } - - /** - * Constructs an instance based on a Workbook instance. - * - * @param wb The Workbook to use for this instance. - */ - protected ExcelAntWorkbookUtil(Workbook wb) { - workbook = wb; - } - - /** - * Loads the member variable workbook based on the fileName variable. - * @return The opened Workbook-instance - * @throws BuildException If the workbook cannot be loaded. - */ - private Workbook loadWorkbook() { - if (excelFileName == null) { - throw new BuildException("fileName attribute must be set!", getLocation()); - } - - try { - try (FileInputStream fis = new FileInputStream(excelFileName)) { - workbook = WorkbookFactory.create(fis); - } - } 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. - * @param name The name of the function to add - * @param clazzName The class which implements this function - * @throws ClassNotFoundException if the class cannot be found - * @throws InstantiationException if the class cannot be constructed - * @throws IllegalAccessException if the constructor or the class is not accessible - */ - public void addFunction(String name, String clazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { - Class<?> clazzInst = Class.forName(clazzName); - Object newInst = clazzInst.getDeclaredConstructor().newInstance(); - if(newInst instanceof FreeRefFunction) { - addFunction(name, (FreeRefFunction)newInst); - } - - } - - /** - * Updates the internal HashMap of functions with instance and alias passed - * in. - * - * @param name the name of the function to replace - * @param func the function to use - */ - protected void addFunction(String name, FreeRefFunction func) { - xlsMacroList.put(name, func); - } - - /** - * returns a UDFFinder that contains all of the functions added. - * - * @return An instance of {@link UDFFinder} which can be used to - * lookup functions - */ - protected UDFFinder getFunctions() { - - String[] names = new String[xlsMacroList.size()]; - FreeRefFunction[] functions = new FreeRefFunction[xlsMacroList.size()]; - - int x = 0; - for(Map.Entry<String, FreeRefFunction> entry : xlsMacroList.entrySet()) { - names[x] = entry.getKey(); - functions[x] = entry.getValue(); - } - - UDFFinder udff1 = new DefaultUDFFinder(names, functions); - - return new AggregatingUDFFinder(udff1); - - } - - /** - * Returns a formula evaluator that is loaded with the functions that - * have been supplied. - * - * @param fileName Specifies if XSSF or HSSF should be used for - * the evaluator - * @return A {@link FormulaEvaluator} constructed accordingly - */ - protected FormulaEvaluator getEvaluator(String fileName) { - FormulaEvaluator evaluator; - if (fileName.endsWith(".xlsx")) { - if(xlsMacroList.size() > 0) { - evaluator = XSSFFormulaEvaluator.create((XSSFWorkbook) workbook, - null, - getFunctions()); - } - evaluator = new XSSFFormulaEvaluator((XSSFWorkbook) workbook); - } else { - if(xlsMacroList.size() > 0) { - evaluator = HSSFFormulaEvaluator.create((HSSFWorkbook)workbook, - null, - getFunctions()); - } - - evaluator = new HSSFFormulaEvaluator((HSSFWorkbook) workbook); - } - - return evaluator; - - } - - /** - * Returns the Workbook instance associated with this WorkbookUtil. - * - * @return - */ - public Workbook getWorkbook() { - return workbook; - } - - /** - * 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 List<String> getSheets() { - ArrayList<String> sheets = new ArrayList<>(); - - 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 - */ - public void setDoubleValue(String cellName, double value) { - log("starting setCellValue()", Project.MSG_DEBUG); - Cell cell = getCell(cellName); - log("working on cell: " + cell, Project.MSG_DEBUG); - cell.setCellValue(value); - log("after cell.setCellValue()", Project.MSG_DEBUG); - - log("set cell " + cellName + " to value " + value, Project.MSG_DEBUG); - } - - /** - * 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); - } - - /** - * Utility method for setting the value of a Cell with a Formula. - * - * @param cellName - * @param formula - */ - public void setFormulaValue(String cellName, String formula) { - Cell cell = getCell(cellName); - cell.setCellFormula(formula); - } - - /** - * Utility method for setting the value of a Cell with a Date. - * @param cellName - * @param date - */ - public void setDateValue(String cellName, Date date) { - Cell cell = getCell(cellName); - cell.setCellValue(date); - } - /** - * Uses a String in standard Excel format (SheetName!CellId) to locate a - * cell and evaluate it. - * - * @param cellName - * @param expectedValue - * @param precision - */ - public ExcelAntEvaluationResult evaluateCell(String cellName, double expectedValue, - double precision) { - - ExcelAntEvaluationResult evalResults = null; - - Cell cell = getCell(cellName); - - FormulaEvaluator evaluator = getEvaluator(excelFileName); - - - CellValue resultOfEval = evaluator.evaluate(cell); - - if (resultOfEval.getErrorValue() == 0) { - // the evaluation did not encounter errors - double result = resultOfEval.getNumberValue(); - double delta = Math.abs(result - expectedValue); - if (delta > precision) { - evalResults = new ExcelAntEvaluationResult(false, false, - resultOfEval.getNumberValue(), - "Results was out of range based on precision " + " of " - + precision + ". Delta was actually " + delta, delta, cellName); - } else { - evalResults = new ExcelAntEvaluationResult(false, true, - resultOfEval.getNumberValue(), - "Evaluation passed without error within in range.", delta, cellName); - } - } else { - String errorMeaning = null; - try { - errorMeaning = FormulaError.forInt(resultOfEval.getErrorValue()).getString(); - } catch(IllegalArgumentException iae) { - errorMeaning = "unknown error code: " + - Byte.toString(resultOfEval.getErrorValue()); - } - - evalResults = new ExcelAntEvaluationResult(true, false, - resultOfEval.getNumberValue(), - "Evaluation failed due to an evaluation error of " - + resultOfEval.getErrorValue() - + " which is " - + errorMeaning, 0, cellName); - } - - return evalResults; - } - - /** - * Returns a Cell as a String value. - * - * @param cellName - * @return - */ - public String getCellAsString(String cellName) { - Cell cell = getCell(cellName); - return cell.getStringCellValue(); - } - - - /** - * Returns the value of the Cell as a double. - * - * @param cellName - * @return - */ - public double getCellAsDouble(String cellName) { - Cell cell = getCell(cellName); - return cell.getNumericCellValue(); - } - /** - * 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); - if(sheet == null) { - throw new BuildException("Sheet not found: " + 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); - } - - return cell; - } -} diff --git a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java b/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java deleted file mode 100644 index 113f0390f7..0000000000 --- a/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.ss.excelant.util; - -import java.util.HashMap; -import java.util.Map; - - -/** - * This is a factory class maps file names to WorkbookUtil instances. This - * helps ExcelAnt be more efficient when being run many times in an Ant build. - * - * @author Jon Svede (jon [at] loquatic [dot] com) - * @author Brian Bush (brian [dot] bush [at] nrel [dot] gov) - * - */ -public final class ExcelAntWorkbookUtilFactory { - - private static Map<String, ExcelAntWorkbookUtil> workbookUtilMap; - - private ExcelAntWorkbookUtilFactory() { - } - - /** - * Using the fileName, check the internal map to see if an instance - * of the WorkbookUtil exists. If not, then add an instance to the map. - * - * @param fileName The filename to use as key to look for the ExcelAntWorkbookUtil. - * @return An instance of ExcelAntWorkbookUtil associated with the filename or - * a freshly instantiated one if none did exist before. - */ - public static ExcelAntWorkbookUtil getInstance(String fileName) { - if(workbookUtilMap == null) { - workbookUtilMap = new HashMap<>(); - } - - if(workbookUtilMap.containsKey(fileName)) { - return workbookUtilMap.get(fileName); - } - - ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil(fileName); - workbookUtilMap.put(fileName, wbu); - return wbu; - } -} |