View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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      // Tag interface
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  }