KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > inline > ButtonEdit


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.gui.inline;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.gui.control.Button;
17 import info.magnolia.cms.i18n.MessagesManager;
18 import info.magnolia.cms.security.Permission;
19 import info.magnolia.cms.util.Resource;
20
21 import java.io.IOException JavaDoc;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.jsp.JspWriter JavaDoc;
25
26 import org.apache.commons.lang.StringUtils;
27
28
29 /**
30  * @author Vinzenz Wyser
31  * @version 2.0
32  */

33 public class ButtonEdit extends Button {
34
35     String JavaDoc label = "buttons.edit"; //$NON-NLS-1$
36

37     public ButtonEdit() {
38     }
39
40     public ButtonEdit(HttpServletRequest JavaDoc request) {
41         this.setRequest(request);
42     }
43
44     public ButtonEdit(
45         HttpServletRequest JavaDoc request,
46         String JavaDoc path,
47         String JavaDoc nodeCollectionName,
48         String JavaDoc nodeName,
49         String JavaDoc paragraph) {
50         this.setRequest(request);
51         this.setPath(path);
52         this.setNodeCollectionName(nodeCollectionName);
53         this.setNodeName(nodeName);
54         this.setParagraph(paragraph);
55     }
56
57     public void setDefaultOnclick(HttpServletRequest JavaDoc request) {
58         String JavaDoc nodeCollectionName = this.getNodeCollectionName();
59         if (nodeCollectionName == null) {
60             nodeCollectionName = StringUtils.EMPTY;
61         }
62         String JavaDoc nodeName = this.getNodeName();
63         if (nodeName == null) {
64             nodeName = StringUtils.EMPTY;
65         }
66
67         String JavaDoc repository = (String JavaDoc) getRequest().getAttribute(info.magnolia.cms.core.Aggregator.REPOSITORY);
68         this.setOnclick("mgnlOpenDialog('" //$NON-NLS-1$
69
+ this.getPath()
70             + "','" //$NON-NLS-1$
71
+ nodeCollectionName
72             + "','" //$NON-NLS-1$
73
+ nodeName
74             + "','" //$NON-NLS-1$
75
+ this.getParagraph()
76             + "','" //$NON-NLS-1$
77
+ repository
78             + "');"); //$NON-NLS-1$
79
}
80
81     public String JavaDoc getLabel() {
82         return MessagesManager.getWithDefault(label, label);
83     }
84
85     public void setLabel(String JavaDoc s) {
86         this.label = s;
87     }
88
89     /**
90      * <p>
91      * draws the edit button
92      * </p>
93      * <p>
94      * request has to be set!
95      * </p>
96      */

97     public void drawHtml(JspWriter JavaDoc out) throws IOException JavaDoc {
98         if (this.getRequest() != null) {
99             boolean isGranted = Resource.getActivePage(this.getRequest()).isGranted(Permission.SET);
100             if (!Resource.showPreview(this.getRequest()) && isGranted) {
101                 out.println(this.getHtml());
102             }
103         }
104     }
105 }
106
Popular Tags