KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tag > optionTransfer > OptionTransferTag


1  /**
2   * Copyright 2004-2005 uitags
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 package net.sf.uitags.tag.optionTransfer;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22
23 import net.sf.uitags.tag.AbstractUiTag;
24 import net.sf.uitags.util.Template;
25
26 /**
27  * Provides grouping of option transfer suites.
28  *
29  * @author hgani
30  * @version $Id$
31  */

32 public class OptionTransferTag extends AbstractUiTag {
33
34   ///////////////////////////////
35
////////// Constants //////////
36
///////////////////////////////
37

38   /**
39    * Serial Version UID.
40    */

41   private static final long serialVersionUID = 100L;
42
43
44   ////////////////////////////
45
////////// Fields //////////
46
////////////////////////////
47

48   /**
49    * List of code generated by child tags, which is to be included
50    * somewhere in the parent's generated code.
51    */

52   private List JavaDoc childJsCodeList;
53   /**
54    * Template for printing necessary javascript code.
55    */

56   private Template template;
57
58   void registerCategoryLister(String JavaDoc listerId, String JavaDoc listerName) {
59     this.template.map("categoryId", listerId);
60     this.template.map("categoryName", listerName);
61   }
62
63   void registerSourceLister(String JavaDoc listerId, String JavaDoc listerName) {
64     this.template.map("sourceId", listerId);
65     this.template.map("sourceName", listerName);
66   }
67
68   void registerTargetLister(String JavaDoc listerId, String JavaDoc listerName) {
69     this.template.map("targetId", listerId);
70     this.template.map("targetName", listerName);
71   }
72
73
74   ///////////////////////////////
75
////////// Tag logic //////////
76
///////////////////////////////
77

78   /**
79    * This method initializes some variables to be used for interaction
80    * with the child tags. It also returns a flag to tell the servlet
81    * engine to buffer the content of this tag's body.
82    *
83    * @see javax.servlet.jsp.tagext.Tag#doStartTag()
84    * @return <code>EVAL_BODY_BUFFERED</code>
85    * @throws JspException to communicate error
86    */

87   public int doStartTag() throws JspException JavaDoc {
88     // Reset the variables that are going to be used after this point.
89
this.template = Template.forName(Template.OPTION_TRANSFER);
90     this.childJsCodeList = new ArrayList JavaDoc();
91
92     makeVisibleToChildren();
93     return EVAL_BODY_INCLUDE;
94   }
95
96   // Can only print HTML code in this method, because we need to process
97
// all the child tags first.
98
/**
99    * Prints necessary Javascript code.
100    *
101    * @see javax.servlet.jsp.tagext.Tag#doEndTag()
102    * @return <code>EVAL_PAGE</code>
103    * @throws JspException to communicate error
104    */

105   public int doEndTag() throws JspException JavaDoc {
106     this.template.map("jsCodeList", this.childJsCodeList);
107     println(this.template.evalToString());
108
109     makeInvisibleFromChildren();
110     return EVAL_PAGE;
111   }
112
113   public void addChildJsCode(String JavaDoc code) {
114     this.childJsCodeList.add(code);
115   }
116 }
117
Popular Tags