KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > taglibs > ButtonTag


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.taglibs;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.gui.control.Button;
17 import info.magnolia.cms.util.Resource;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23
24 /**
25  * @author fgiust
26  * @version $Revision: 6341 $ ($Author: philipp $)
27  */

28 public class ButtonTag extends TagSupport JavaDoc {
29
30     /**
31      * Stable serialVersionUID.
32      */

33     private static final long serialVersionUID = 222L;
34
35     /**
36      * Dialog name.
37      */

38     private String JavaDoc dialogName = "xxx";
39
40     /**
41      * Button label.
42      */

43     private String JavaDoc label;
44
45     /**
46      * position (<code>left|right</code>)
47      */

48     private String JavaDoc position;
49
50     /**
51      * Setter for <code>dialogName</code>.
52      * @param dialogName The dialogName to set.
53      */

54     public void setDialogName(String JavaDoc dialogName) {
55         this.dialogName = dialogName;
56     }
57
58     /**
59      * Setter for <code>label</code>.
60      * @param label The label to set.
61      */

62     public void setLabel(String JavaDoc label) {
63         this.label = label;
64     }
65
66     /**
67      * Setter for <code>position</code>.
68      * @param position The position to set.
69      */

70     public void setPosition(String JavaDoc position) {
71         this.position = position;
72     }
73
74     /**
75      * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
76      */

77     public int doEndTag() throws JspException JavaDoc {
78
79         BarTag bartag = (BarTag) findAncestorWithClass(this, BarTag.class);
80         if (bartag == null) {
81             throw new JspException JavaDoc("button tag should be enclosed in a mainbar or newbar tag");
82         }
83
84         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
85
86         Button button = new Button();
87         button.setLabel(label);
88         button.setOnclick("mgnlOpenDialog('"
89             + Resource.getActivePage(request).getHandle()
90             + "','','','"
91             + dialogName
92             + "','"
93             + ContentRepository.WEBSITE
94             + "')");
95
96         if ("right".equalsIgnoreCase(position)) {
97             bartag.addButtonRight(button);
98         }
99         else {
100             bartag.addButtonLeft(button);
101         }
102
103         return EVAL_PAGE;
104     }
105
106     /**
107      * @see javax.servlet.jsp.tagext.TagSupport#release()
108      */

109     public void release() {
110         super.release();
111         this.dialogName = null;
112         this.label = null;
113         this.position = null;
114     }
115
116 }
117
Popular Tags