You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExcelAntHandlerTask.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.excelant;
  16. import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
  17. import org.apache.tools.ant.BuildException;
  18. import org.apache.tools.ant.Project;
  19. import org.apache.tools.ant.Task;
  20. /**
  21. * This is the class that backs the <handler> tag in the Ant task.
  22. *
  23. * @author Jon Svede ( jon [at] loquatic [dot] com )
  24. * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
  25. *
  26. */
  27. public class ExcelAntHandlerTask extends Task {
  28. private String className ;
  29. private ExcelAntWorkbookUtil wbUtil ;
  30. public void setClassName( String cName ) {
  31. className = cName ;
  32. }
  33. protected void setEAWorkbookUtil( ExcelAntWorkbookUtil wkbkUtil ) {
  34. wbUtil = wkbkUtil ;
  35. }
  36. public void execute() throws BuildException {
  37. log( "handling the workbook with class " + className, Project.MSG_INFO ) ;
  38. try {
  39. Class clazz = Class.forName( className ) ;
  40. Object handlerObj = clazz.newInstance() ;
  41. if( handlerObj instanceof IExcelAntWorkbookHandler ) {
  42. IExcelAntWorkbookHandler iHandler = (IExcelAntWorkbookHandler)handlerObj ;
  43. iHandler.setWorkbook( wbUtil.getWorkbook() ) ;
  44. iHandler.execute() ;
  45. }
  46. } catch( Exception e ) {
  47. throw new BuildException( e.getMessage(), e ) ;
  48. }
  49. }
  50. }