1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.ant;
17
18 import java.lang.reflect.InvocationTargetException;
19
20 import org.apache.commons.beanutils.BeanUtils;
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.MissingAttributeException;
23 import org.apache.commons.jelly.TagSupport;
24 import org.apache.commons.jelly.XMLOutput;
25
26 /***
27 * A tag which creates a new FileScanner bean instance that can be used to
28 * iterate over fileSets
29 *
30 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
31 * @version $Revision: 155420 $
32 */
33 public class FileScannerTag extends TagSupport implements TaskSource {
34
35 /*** The file walker that gets created */
36 private FileScanner fileScanner;
37
38 /*** the variable exported */
39 private String var;
40
41 public FileScannerTag(FileScanner fileScanner) {
42 this.fileScanner = fileScanner;
43 }
44
45
46
47 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
48 fileScanner.setProject(AntTagLibrary.getProject(context));
49
50 fileScanner.clear();
51
52
53 invokeBody(output);
54
55
56 if ( var == null ) {
57 throw new MissingAttributeException( "var" );
58 }
59 context.setVariable( var, fileScanner );
60
61 }
62
63
64
65 public Object getTaskObject() {
66 return fileScanner;
67 }
68
69 /***
70 * Allows nested tags to set a property on the task object of this tag
71 */
72 public void setTaskProperty(String name, Object value) throws JellyTagException {
73 try {
74 BeanUtils.setProperty( fileScanner, name, value );
75 }
76 catch (IllegalAccessException ex) {
77 throw new JellyTagException(ex);
78 }
79 catch (InvocationTargetException ex) {
80 throw new JellyTagException(ex);
81 }
82 }
83
84
85
86
87 /***
88 * @return the Ant task
89 */
90 public FileScanner getFileScanner() {
91 return fileScanner;
92 }
93
94 /*** Sets the name of the variable exported by this tag */
95 public void setVar(String var) {
96 this.var = var;
97 }
98
99 }