1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.inline;
35
36 import info.magnolia.cms.core.AggregationState;
37 import info.magnolia.cms.gui.control.Button;
38 import info.magnolia.cms.i18n.I18nContentSupport;
39 import info.magnolia.cms.i18n.I18nContentSupportFactory;
40 import info.magnolia.cms.i18n.MessagesManager;
41 import info.magnolia.cms.security.Permission;
42 import info.magnolia.cms.security.PermissionUtil;
43 import info.magnolia.context.MgnlContext;
44
45 import java.io.IOException;
46 import java.io.Writer;
47
48 import javax.jcr.Node;
49 import javax.jcr.RepositoryException;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.jsp.JspWriter;
52
53 import org.apache.commons.lang.StringUtils;
54
55
56
57
58
59
60 public class ButtonEdit extends Button {
61 private String label = "buttons.edit";
62 private String dialogPath;
63 private String dialog;
64
65 private final I18nContentSupport i18nSupport = I18nContentSupportFactory.getI18nSupport();
66
67 public ButtonEdit() {
68 }
69
70
71
72
73 @Deprecated
74 public ButtonEdit(HttpServletRequest request) {
75 }
76
77
78
79
80 @Deprecated
81 public ButtonEdit(HttpServletRequest request, String path, String nodeCollectionName, String nodeName, String dialog) {
82 this(path, nodeCollectionName, nodeName, dialog);
83 }
84
85 public ButtonEdit(String path, String nodeCollectionName, String nodeName, String dialog) {
86 this.setPath(path);
87 this.setNodeCollectionName(nodeCollectionName);
88 this.setNodeName(nodeName);
89 this.setDialog(dialog);
90 }
91
92
93
94
95 @Deprecated
96 public void setDefaultOnclick(HttpServletRequest request) {
97 setDefaultOnclick();
98 }
99
100 public void setDefaultOnclick() {
101 String nodeCollectionName = this.getNodeCollectionName();
102 if (nodeCollectionName == null) {
103 nodeCollectionName = StringUtils.EMPTY;
104 }
105 String nodeName = this.getNodeName();
106 if (nodeName == null) {
107 nodeName = StringUtils.EMPTY;
108 }
109
110 String repository = MgnlContext.getAggregationState().getRepository();
111 this.setOnclick("mgnlOpenDialog('"
112 + this.getPath()
113 + "','"
114 + nodeCollectionName
115 + "','"
116 + nodeName
117 + "','"
118 + this.getDialog()
119 + "','"
120 + repository
121 + "',"
122 + (dialogPath != null ? "'" + dialogPath + "'" : "null")
123 + ", null"
124 + ", null"
125 + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"")
126 +");");
127 }
128
129 @Override
130 public String getLabel() {
131 return MessagesManager.getWithDefault(label, label);
132 }
133
134 @Override
135 public void setLabel(String s) {
136 this.label = s;
137 }
138
139 public void setDialogPath(String dialogPath) {
140 this.dialogPath = dialogPath;
141 }
142
143 public void setDialog (String dialog) {
144 this.dialog = dialog;
145 }
146
147 public String getDialog () {
148 return this.dialog;
149 }
150
151
152
153
154 @Deprecated
155 public void drawHtml(JspWriter out) throws IOException {
156 drawHtml((Writer)out);
157 }
158
159
160
161
162 public void drawHtml(Writer out) throws IOException {
163 if (this.getRequest() != null) {
164 final AggregationState aggregationState = MgnlContext.getAggregationState();
165 final Node mainContent = aggregationState.getMainContent().getJCRNode();
166 boolean isGranted;
167 try {
168 isGranted = PermissionUtil.isGranted(mainContent.getSession(), mainContent.getPath(), Permission.SET);
169 } catch (RepositoryException e) {
170
171 throw new RuntimeException(e);
172 }
173 if (!aggregationState.isPreviewMode() && isGranted) {
174 println(out, this.getHtml());
175 }
176 }
177 }
178 }