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.beans.config.ServerConfiguration;
37 import info.magnolia.cms.core.AggregationState;
38 import info.magnolia.cms.gui.control.Bar;
39 import info.magnolia.cms.gui.control.Button;
40 import info.magnolia.cms.gui.control.Control;
41 import info.magnolia.cms.gui.control.ControlImpl;
42 import info.magnolia.cms.gui.i18n.I18nAuthoringSupport;
43 import info.magnolia.cms.gui.misc.Sources;
44 import info.magnolia.cms.i18n.MessagesManager;
45 import info.magnolia.cms.security.Permission;
46 import info.magnolia.cms.security.PermissionUtil;
47 import info.magnolia.context.MgnlContext;
48
49 import java.io.IOException;
50 import java.io.Writer;
51
52 import javax.jcr.Node;
53 import javax.jcr.RepositoryException;
54 import javax.servlet.http.HttpServletRequest;
55 import javax.servlet.jsp.JspWriter;
56
57
58
59
60
61
62 public class BarMain extends Bar {
63
64 private Button buttonEditView = new Button();
65
66 private Button buttonPreview = new ButtonEdit();
67
68 private Button buttonProperties = new Button();
69
70 private Button buttonSiteAdmin = new Button();
71
72 private Control languageChooser;
73
74 private String dialog;
75
76 private int top;
77
78 private int left;
79
80 private String width = "100%";
81
82 private boolean overlay = true;
83
84
85
86
87 private boolean adminButtonVisible = true;
88
89
90
91
92 @Deprecated
93 public BarMain(HttpServletRequest request) {
94 }
95
96
97
98
99 @Deprecated
100 public BarMain(HttpServletRequest request, String path, String nodeCollectionName, String nodeName, String paragraph) {
101 this(path, nodeCollectionName, nodeName, paragraph);
102 }
103
104 public BarMain(String path, String nodeCollectionName, String nodeName, String dialog) {
105 this.setPath(path);
106 this.setNodeCollectionName(nodeCollectionName);
107 this.setNodeName(nodeName);
108 this.setDialog(dialog);
109 }
110
111 public BarMain() {
112 }
113
114
115
116
117 public void setDefaultButtons() {
118 this.setButtonEditView();
119 this.setButtonPreview();
120 this.setButtonSiteAdmin();
121 this.setButtonProperties();
122 this.setLanguageChooser();
123 }
124
125
126
127
128 public void placeDefaultButtons() {
129 if (this.isAdminButtonVisible()) {
130 this.getButtonsLeft().add(0, this.getButtonSiteAdmin());
131 }
132 this.getButtonsLeft().add(0, this.getButtonPreview());
133
134 if(this.languageChooser != null){
135 getButtonsRight().add(this.languageChooser);
136 getButtonsRight().add(new ControlImpl(){
137 @Override
138 public String getHtml() {
139 return " ";
140 }
141 });
142 }
143
144 if (this.getDialog() != null) {
145 this.getButtonsRight().add(this.getButtonProperties());
146 }
147 }
148
149 public Button getButtonProperties() {
150 return this.buttonProperties;
151 }
152
153 public void setButtonProperties(Button b) {
154 this.buttonProperties = b;
155 }
156
157 public void setButtonProperties() {
158 this.setButtonProperties(this.getPath(), this.getDialog());
159 }
160
161
162
163
164
165
166
167 public void setButtonProperties(String path, String dialog) {
168 ButtonEdit b = new ButtonEdit();
169 b.setLabel(MessagesManager.get("buttons.properties"));
170 b.setPath(path);
171 b.setDialog(dialog);
172 b.setDefaultOnclick();
173 this.setButtonProperties(b);
174 }
175
176 public Button getButtonPreview() {
177 return this.buttonPreview;
178 }
179
180 public void setButtonPreview(Button b) {
181 this.buttonPreview = b;
182 }
183
184
185
186
187 public void setButtonPreview() {
188 Button b = new Button();
189 b.setLabel(MessagesManager.get("buttons.preview"));
190 b.setOnclick("mgnlPreview(true);");
191 this.setButtonPreview(b);
192 }
193
194 public Button getButtonEditView() {
195 return this.buttonEditView;
196 }
197
198 public void setButtonEditView(Button b) {
199 this.buttonEditView = b;
200 }
201
202
203
204
205 public void setButtonEditView() {
206 Button b = new Button();
207 b.setLabel(MessagesManager.get("buttons.preview.hidden"));
208 b.setOnclick("mgnlPreview(false);");
209 this.setButtonEditView(b);
210 }
211
212 public Button getButtonSiteAdmin() {
213 return this.buttonSiteAdmin;
214 }
215
216 public void setButtonSiteAdmin(Button b) {
217 this.buttonSiteAdmin = b;
218 }
219
220 public void setButtonSiteAdmin() {
221 this.setButtonSiteAdmin(this.getPath());
222 }
223
224
225
226
227
228 public void setButtonSiteAdmin(String path) {
229 Button b = new Button();
230 b.setLabel(MessagesManager.get("buttons.admincentral"));
231 String repository = MgnlContext.getAggregationState().getRepository();
232 b.setOnclick("MgnlAdminCentral.showTree('"+repository+"','" + path + "');");
233 this.setButtonSiteAdmin(b);
234 }
235
236 protected void setLanguageChooser() {
237 I18nAuthoringSupport i18nAuthoringSupport = I18nAuthoringSupport.Factory.getInstance();
238 if(i18nAuthoringSupport.isEnabled()){
239 languageChooser = i18nAuthoringSupport.getLanguageChooser();
240 }
241 }
242
243 public Control getLanguageChooser() {
244 return this.languageChooser;
245 }
246
247 public void setLanguageChooser(Control languageChooser) {
248 this.languageChooser = languageChooser;
249 }
250
251 public void setTop(int i) {
252 this.top = i;
253 }
254
255 public int getTop() {
256 return this.top;
257 }
258
259 public void setLeft(int i) {
260 this.left = i;
261 }
262
263 public int getLeft() {
264 return this.left;
265 }
266
267 public void setWidth(String s) {
268 this.width = s;
269 }
270
271 public String getWidth() {
272 return this.width;
273 }
274
275
276
277
278 public void setOverlay(boolean b) {
279 this.overlay = b;
280 }
281
282 public boolean getOverlay() {
283 return this.overlay;
284 }
285
286 public String getDialog() {
287 return this.dialog;
288 }
289
290 public void setDialog(String dialog) {
291 this.dialog = dialog;
292 }
293
294
295
296
297 @Deprecated
298 public void drawHtml(JspWriter out) throws IOException {
299 drawHtml((Writer) out);
300 }
301
302
303
304
305 public void drawHtml(Writer out) throws IOException {
306 if (ServerConfiguration.getInstance().isAdmin()) {
307
308 final AggregationState aggregationState = MgnlContext.getAggregationState();
309 final Node mainContent = aggregationState.getMainContent().getJCRNode();
310 boolean isGranted;
311 try {
312 isGranted = PermissionUtil.isGranted(mainContent.getSession(), mainContent.getPath(), Permission.SET);
313 } catch (RepositoryException e) {
314
315 throw new RuntimeException(e);
316 }
317 if (isGranted) {
318
319
320 if (this.getRequest().getAttribute(Sources.REQUEST_LINKS_DRAWN) == null) {
321 this.drawHtmlLinks(out);
322 this.getRequest().setAttribute(Sources.REQUEST_LINKS_DRAWN, Boolean.TRUE);
323 }
324
325 int top = this.getTop();
326 int left = this.getLeft();
327
328 if (!aggregationState.isPreviewMode()) {
329
330 this.setSmall(false);
331 if (this.getOverlay()) {
332 println(out, "<div class=\"mgnlMainbar\" style=\"top:"
333 + top
334 + "px;left:"
335 + left
336 + "px;width:"
337 + this.getWidth()
338 + ";\">");
339 }
340 println(out, this.getHtml());
341 if (this.getOverlay()) {
342 println(out, "</div>");
343 }
344 }
345 else {
346
347 top += 4;
348 left += 4;
349 println(out, "<div class=\"mgnlMainbarPreview\" style=\"top:" + top + "px;left:" + left + "px;\">");
350 println(out, this.getButtonEditView().getHtml());
351 println(out, "</div>");
352 }
353 }
354 }
355 }
356
357
358
359
360 @Deprecated
361 public void drawHtmlLinks(JspWriter out) throws IOException {
362 drawHtmlLinks((Writer) out);
363 }
364
365
366
367
368 public void drawHtmlLinks(Writer out) throws IOException {
369 println(out, new Sources(this.getRequest().getContextPath()).getHtmlCss());
370 println(out, new Sources(this.getRequest().getContextPath()).getHtmlJs());
371 }
372
373 public boolean isAdminButtonVisible() {
374 return this.adminButtonVisible;
375 }
376
377 public void setAdminButtonVisible(boolean adminButtonVisible) {
378 this.adminButtonVisible = adminButtonVisible;
379 }
380 }