1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.util;
18
19 import java.io.File;
20
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 {@link File} from a given name.
28 *
29 * @author <a href="mailto:dion@apache.org">dIon Gillard</a>
30 * @version $Revision: 155420 $
31 */
32 public class FileTag extends TagSupport {
33
34 /*** The file to place into the context */
35 private String name;
36
37 /*** The variable name to place the file into */
38 private String var;
39
40
41
42 public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException {
43 boolean available = false;
44
45 if (name == null) {
46 throw new MissingAttributeException("name must be specified");
47 }
48
49 if (var == null) {
50 throw new MissingAttributeException("var must be specified");
51 }
52
53 File newFile = new File(name);
54 getContext().setVariable(var, newFile);
55 }
56
57 /***
58 * Name of the file to be placed into the context
59 * @param name The fileName to set
60 */
61 public void setName(String name) {
62 this.name = name;
63 }
64
65 /***
66 * Name of the variable to contain the file
67 * @param var The var to set
68 */
69 public void setVar(String var) {
70 this.var = var;
71 }
72
73 }