KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > tags > FormTag


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core.tags;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.servlet.jsp.JspException JavaDoc;
28 import javax.servlet.jsp.JspWriter JavaDoc;
29 import javax.servlet.jsp.PageContext JavaDoc;
30
31 import org.apache.struts.taglib.html.Constants;
32
33 import com.sslexplorer.core.CoreScript;
34
35 /**
36  * @author Brett Smith <brett@3sp.com>
37  */

38 public class FormTag extends org.apache.struts.taglib.html.FormTag {
39     protected String JavaDoc autocomplete;
40     protected List JavaDoc scripts;
41     protected String JavaDoc subFormName;
42     
43     public FormTag() {
44         super();
45         scripts = new ArrayList JavaDoc();
46     }
47
48     
49     /**
50      * @return Returns the autocomplete.
51      */

52     public String JavaDoc getAutocomplete() {
53         return autocomplete;
54     }
55     /**
56      * @param autocomplete The autocomplete to set.
57      */

58     public void setAutocomplete(String JavaDoc autocomplete) {
59         this.autocomplete = autocomplete;
60     }
61
62     /**
63      * @param subFormName sub form name
64      */

65     public void setSubFormName(String JavaDoc subFormName) {
66         this.subFormName = subFormName;
67     }
68     
69     public String JavaDoc getSubFormName() {
70         return subFormName;
71     }
72     
73     /* (non-Javadoc)
74      * @see org.apache.struts.taglib.html.FormTag#renderOtherAttributes(java.lang.StringBuffer)
75      */

76     protected void renderOtherAttributes(StringBuffer JavaDoc results) {
77         super.renderOtherAttributes(results);
78         if(autocomplete != null) {
79             renderAttribute(results, "AUTOCOMPLETE", getAutocomplete());
80         }
81         renderAttribute(results, "accept-charset", System.getProperty("sslexplorer.encoding", "UTF-8"));
82     }
83     
84     /**
85      * Add a script to be rendered at the end of the form
86      *
87      * @param script script to add
88      */

89     public void addScript(CoreScript script) {
90         scripts.add(script);
91     }
92
93
94     /* (non-Javadoc)
95      * @see org.apache.struts.taglib.html.FormTag#doEndTag()
96      */

97     public int doEndTag() throws JspException JavaDoc {
98         pageContext.removeAttribute(Constants.BEAN_KEY, PageContext.REQUEST_SCOPE);
99         pageContext.removeAttribute(Constants.FORM_KEY, PageContext.REQUEST_SCOPE);
100         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
101         for(Iterator JavaDoc i = scripts.iterator(); i.hasNext(); ) {
102             CoreScript script = (CoreScript)i.next();
103             results.append(script.getRenderedHTML());
104         }
105         results.append("</form>");
106         if (this.focus != null && !this.focus.equals("")) {
107             results.append(this.renderFocusJavascript());
108         }
109         JspWriter JavaDoc writer = pageContext.getOut();
110         try {
111             writer.print(results.toString());
112         } catch (IOException JavaDoc e) {
113             throw new JspException JavaDoc(messages.getMessage("common.io", e.toString()));
114         }
115         return (EVAL_PAGE);
116     }
117
118     public void release() {
119         super.release();
120         subFormName = null;
121     }
122
123     protected void lookup() throws JspException JavaDoc {
124         super.lookup();
125         if(subFormName != null) {
126             beanName = subFormName;
127         }
128     }
129 }
130
Popular Tags