KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > tiles > InitDefinitionsTag


1 /*
2  * $Id: InitDefinitionsTag.java 54929 2004-10-16 16:38:42Z germuska $
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.taglib.tiles;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
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 JavaDoc implements ComponentConstants {
34
35
36   private String JavaDoc filename = null;
37   private String JavaDoc classname = null;
38
39   /**
40    * Default constructor.
41    */

42   public InitDefinitionsTag() {
43     super();
44   }
45
46     /**
47      * Release all allocated resources.
48      */

49     public void release() {
50
51         super.release();
52         filename = null;
53     }
54
55     /**
56      * Set file.
57      */

58   public void setFile(String JavaDoc name){
59     this.filename = name;
60   }
61
62     /**
63      * Set classname.
64      */

65   public void setClassname(String JavaDoc classname){
66     this.classname = classname;
67   }
68
69     /**
70      * Do start tag.
71      */

72   public int doStartTag() throws JspException JavaDoc
73   {
74   DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(pageContext.getRequest(),pageContext.getServletContext());
75   if(factory != null )
76     return SKIP_BODY;
77
78   DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
79   factoryConfig.setFactoryClassname( classname );
80   factoryConfig.setDefinitionConfigFiles( filename );
81
82   try
83     {
84     factory = TilesUtil.createDefinitionsFactory(pageContext.getServletContext(), factoryConfig);
85     }
86    catch( DefinitionsFactoryException ex )
87       {
88       ex.printStackTrace();
89       throw new JspException JavaDoc( ex.getMessage() + " See console for details" );
90       }
91   return SKIP_BODY;
92   }
93
94     /**
95      * Do end tag.
96      */

97   public int doEndTag() throws JspException JavaDoc {
98     return EVAL_PAGE;
99   }
100
101 }
102
Popular Tags