View Javadoc

1   /*
2    * $Id: InitDefinitionsTag.java 421151 2006-07-12 06:07:14Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  package org.apache.struts.tiles.taglib;
21  
22  import javax.servlet.jsp.JspException;
23  import javax.servlet.jsp.tagext.TagSupport;
24  
25  import org.apache.struts.tiles.DefinitionsFactory;
26  import org.apache.struts.tiles.DefinitionsFactoryConfig;
27  import org.apache.struts.tiles.DefinitionsFactoryException;
28  import org.apache.struts.tiles.TilesUtil;
29  
30    /***
31     * Init definitions factory.
32     */
33  public class InitDefinitionsTag extends TagSupport
34      implements ComponentConstants {
35  
36  
37    private String filename = null;
38    private String classname = null;
39  
40    /***
41     * Default constructor.
42     */
43    public InitDefinitionsTag() {
44      super();
45    }
46  
47      /***
48       * Release all allocated resources.
49       */
50      public void release() {
51  
52          super.release();
53          filename = null;
54      }
55  
56      /***
57       * Set file.
58       */
59    public void setFile(String name){
60      this.filename = name;
61    }
62  
63      /***
64       * Set classname.
65       */
66    public void setClassname(String classname){
67      this.classname = classname;
68    }
69  
70      /***
71       * Do start tag.
72       */
73    public int doStartTag() throws JspException
74    {
75    DefinitionsFactory factory =
76        TilesUtil.getDefinitionsFactory(pageContext.getRequest(),
77            pageContext.getServletContext());
78    if(factory != null )
79      return SKIP_BODY;
80  
81    DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
82    factoryConfig.setFactoryClassname( classname );
83    factoryConfig.setDefinitionConfigFiles( filename );
84  
85    try
86      {
87      factory = TilesUtil.createDefinitionsFactory(
88          pageContext.getServletContext(), factoryConfig);
89      }
90     catch( DefinitionsFactoryException ex )
91        {
92        ex.printStackTrace();
93        throw new JspException( ex );
94        }
95    return SKIP_BODY;
96    }
97  
98      /***
99       * Do end tag.
100      */
101   public int doEndTag() throws JspException {
102     return EVAL_PAGE;
103   }
104 
105 }