KickJava   Java API By Example, From Geeks To Geeks.

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


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-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.taglibs;
14
15 import info.magnolia.cms.gui.inline.BarNew;
16 import info.magnolia.cms.i18n.MessagesManager;
17 import info.magnolia.cms.util.Resource;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.log4j.Logger;
26
27
28 /**
29  * @author Sameer Charles
30  * @version $Revision: 1209 $ ($Author: fgiust $)
31  */

32 public class NewBar extends TagSupport JavaDoc {
33
34     /**
35      * Stable serialVersionUID.
36      */

37     private static final long serialVersionUID = 222L;
38
39     private static final String JavaDoc DEFAULT_NEW_LABEL = "buttons.new"; //$NON-NLS-1$
40

41     /**
42      * Logger.
43      */

44     private static Logger log = Logger.getLogger(NewBar.class);
45
46     private String JavaDoc contentNodeCollectionName;
47
48     private String JavaDoc paragraph;
49
50     private String JavaDoc newLabel;
51
52     /**
53      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
54      */

55     public int doStartTag() {
56         return EVAL_BODY_INCLUDE;
57     }
58
59     /**
60      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
61      */

62     public int doEndTag() {
63         /*
64          * if (!ServerInfo.isAdmin() || Resource.showPreview(this.request)) return EVAL_PAGE; if
65          * (!Resource.getActivePage(this.request).isGranted(Permission.WRITE_PROPERTY)) return EVAL_PAGE;
66          */

67         try {
68             this.display();
69         }
70         catch (Exception JavaDoc e) {
71             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
72
}
73         return EVAL_PAGE;
74     }
75
76     /**
77      * <p>
78      * set working container list
79      * </p>
80      * @param name , comtainer list name
81      */

82     public void setContentNodeCollectionName(String JavaDoc name) {
83         this.contentNodeCollectionName = name;
84     }
85
86     public String JavaDoc getContentNodeCollectionName() {
87         return this.contentNodeCollectionName;
88     }
89
90     /**
91      * <p>
92      * get the content path (Page or Node)
93      * </p>
94      * @return String path
95      */

96     private String JavaDoc getPath() {
97         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
98         try {
99             return Resource.getCurrentActivePage(request).getHandle();
100         }
101         catch (Exception JavaDoc re) {
102             return StringUtils.EMPTY;
103         }
104     }
105
106     /**
107      * @deprecated
108      * <p>
109      * set the tapes which defines all paragraps available in this contentNode collection
110      * </p>
111      * @param list , comma seperated list of all allowed paragraphs
112      */

113     public void setParFiles(String JavaDoc list) {
114         this.paragraph = list;
115     }
116
117     /**
118      * <p>
119      * comma separeted list of paragraphs
120      * </p>
121      * @param list , comma seperated list of all allowed paragraphs
122      */

123     public void setParagraph(String JavaDoc list) {
124         this.paragraph = list;
125     }
126
127     /**
128      * @return String paragraph (type of par)
129      */

130     private String JavaDoc getParagraph() {
131         return this.paragraph;
132     }
133
134     /**
135      * <p>
136      * set the new label
137      * </p>
138      * @param label
139      */

140     public void setNewLabel(String JavaDoc label) {
141         this.newLabel = label;
142     }
143
144     /**
145      * @return String , label for the new bar
146      */

147     private String JavaDoc getNewLabel() {
148         String JavaDoc defStr = MessagesManager.getMessages(this.pageContext).get(DEFAULT_NEW_LABEL);
149         // String defStr = LocaleSupport.getLocalizedMessage(this.pageContext, DEFAULT_NEW_LABEL);
150
return StringUtils.defaultString(this.newLabel, defStr);
151     }
152
153     /**
154      * <p>
155      * displays new bar
156      * </p>
157      * @throws java.io.IOException
158      */

159     private void display() throws IOException JavaDoc {
160         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
161         BarNew bar = new BarNew(request);
162         bar.setPath(this.getPath());
163         bar.setParagraph(this.getParagraph());
164         bar.setNodeCollectionName(this.getContentNodeCollectionName());
165         bar.setNodeName("mgnlNew"); //$NON-NLS-1$
166
bar.setDefaultButtons();
167         if (this.getNewLabel() != null) {
168             if (StringUtils.isEmpty(this.getNewLabel())) {
169                 bar.setButtonNew(null);
170             }
171             else {
172                 bar.getButtonNew().setLabel(this.getNewLabel());
173             }
174         }
175         bar.placeDefaultButtons();
176         bar.drawHtml(pageContext.getOut());
177     }
178
179     /**
180      * @see javax.servlet.jsp.tagext.TagSupport#release()
181      */

182     public void release() {
183         super.release();
184         this.contentNodeCollectionName = null;
185         this.paragraph = null;
186         this.newLabel = null;
187     }
188 }
189
Popular Tags