KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > workflow > taglib > FormTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.cms.workflow.taglib;
25
26 import java.text.MessageFormat JavaDoc;
27
28 import javax.servlet.jsp.JspException JavaDoc;
29
30 /**
31  * This class implements the <iw:form> tag, which presents an <form ... /> element
32  * with all the attributes and hidden fields properly initialized
33  * as required by the workflow framework.
34  */

35 public class FormTag extends WorkflowTag
36 {
37     /**
38      * The universal version identifier.
39      */

40     private static final long serialVersionUID = -558848421886366918L;
41
42     /**
43      * The key used for finding the form action in the request.
44      */

45     private static final String JavaDoc ACTION_ADDRESS_PARAMETER = "returnAddress";
46
47     /**
48      * The key used for finding the form action in the request.
49      */

50     private static final String JavaDoc FINISHED_ADDRESS_PARAMETER = "finalReturnAddress";
51
52     /**
53      * The template for the start tag of the form element.
54      */

55     private static final String JavaDoc FORM_START = "<form name=\"form\" id=\"form\" method=\"post\" action=\"{0}\">";
56
57     /**
58      * The template for the hiddens fields needed by all workflows (action and workflow id).
59      */

60     private static final String JavaDoc HIDDEN = "<div><input id=\"{0}\" name=\"{0}\" type=\"hidden\" value=\"{1}\"/></div>";
61
62     /**
63      * The template for the end tag of the form element.
64      */

65     private static final String JavaDoc FORM_END = "</form>";
66
67     /**
68      * Default constructor.
69      */

70     public FormTag()
71     {
72         super();
73     }
74
75     /**
76      * Process the start tag. Writes the start tag of the form element and the required hidden fields
77      * to the output stream.
78      *
79      * @return indication of whether to evaluate the body or not.
80      * @throws JspException if an I/O error occurs when writing to the output stream.
81      */

82     public int doStartTag() throws JspException JavaDoc
83     {
84         write(MessageFormat.format(FORM_START, new Object JavaDoc[] { getActionAddress() }));
85         write(MessageFormat.format(HIDDEN, new Object JavaDoc[] { ACTION_ID_PARAMETER, getActionID() }));
86         write(MessageFormat.format(HIDDEN, new Object JavaDoc[] { FINISHED_ADDRESS_PARAMETER, getFinalReturnAddress() }));
87         write(MessageFormat.format(HIDDEN, new Object JavaDoc[] { WORKFLOW_ID_PARAMETER, getWorkflowID() }));
88         return EVAL_BODY_INCLUDE;
89     }
90
91     /**
92      * Process the end tag. Writes the end tag of the form element to the output stream.
93      *
94      * @return indication of whether to continue evaluating the JSP page.
95      * @throws JspException if an I/O error occurs when writing to the output stream.
96      */

97     public int doEndTag() throws JspException JavaDoc
98     {
99         write(FORM_END);
100         return EVAL_PAGE;
101     }
102
103     /**
104      * Returns the action to use in the form.
105      *
106      * @return the action to use in the form.
107      */

108     private String JavaDoc getActionAddress()
109     {
110         return pageContext.getRequest().getParameter(ACTION_ADDRESS_PARAMETER);
111     }
112
113     /**
114      * Returns the action to use in the form.
115      *
116      * @return the action to use in the form.
117      */

118     private String JavaDoc getFinalReturnAddress()
119     {
120         return pageContext.getRequest().getParameter(FINISHED_ADDRESS_PARAMETER);
121     }
122
123 }
124
Popular Tags