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.Bar;
38 import info.magnolia.cms.gui.control.Button;
39 import info.magnolia.cms.i18n.I18nContentSupport;
40 import info.magnolia.cms.i18n.I18nContentSupportFactory;
41 import info.magnolia.cms.i18n.MessagesManager;
42 import info.magnolia.cms.security.Permission;
43 import info.magnolia.cms.security.PermissionUtil;
44 import info.magnolia.context.MgnlContext;
45
46 import java.io.IOException;
47 import java.io.Writer;
48
49 import javax.jcr.Node;
50 import javax.jcr.RepositoryException;
51 import javax.servlet.http.HttpServletRequest;
52 import javax.servlet.jsp.JspWriter;
53
54 import org.apache.commons.lang.StringUtils;
55
56
57
58
59
60
61 public class BarNew extends Bar {
62
63 private String paragraph;
64
65 private Button buttonNew = new Button();
66
67 private final I18nContentSupport i18nSupport = I18nContentSupportFactory.getI18nSupport();
68
69
70
71
72 @Deprecated
73 public BarNew(HttpServletRequest request) {
74 }
75
76 public BarNew() {
77
78 }
79
80
81
82
83 public void setDefaultButtons() {
84 this.setButtonNew();
85 }
86
87
88
89
90 public void placeDefaultButtons() {
91 if (this.getButtonNew() != null) {
92 this.getButtonsLeft().add(0, this.getButtonNew());
93 }
94 }
95
96 public Button getButtonNew() {
97 return this.buttonNew;
98 }
99
100 public void setButtonNew(Button b) {
101 this.buttonNew = b;
102 }
103
104 public void setButtonNew() {
105 this.setButtonNew(this.getPath(), this.getNodeCollectionName(StringUtils.EMPTY), this
106 .getNodeName(StringUtils.EMPTY), this.getParagraph());
107 }
108
109
110
111
112
113
114
115
116 public void setButtonNew(String path, String nodeCollectionName, String nodeName, String paragraph) {
117 Button b = new Button();
118 final String labelKey = StringUtils.isBlank(paragraph) ? "buttons.noparagraph" : "buttons.new";
119 b.setLabel(MessagesManager.getMessages().get(labelKey));
120 String repository = MgnlContext.getAggregationState().getRepository();
121
122 if (StringUtils.contains(paragraph, ',')) {
123 b.setOnclick(onClickForNewButton(path, nodeCollectionName, nodeName, paragraph, repository, "selectParagraph"));
124 } else if (StringUtils.isNotBlank(paragraph)) {
125
126 b.setOnclick(onClickForNewButton(path, nodeCollectionName, nodeName, paragraph, repository, "editParagraph"));
127 }
128 this.setButtonNew(b);
129 }
130
131 protected String onClickForNewButton(String path, String nodeCollectionName, String nodeName, String paragraph, String repository, String dialogName) {
132 return "mgnlOpenDialog('"
133 + path
134 + "','"
135 + nodeCollectionName
136 + "','"
137 + nodeName
138 + "','"
139 + paragraph
140 + "','"
141 + repository
142 + "','.magnolia/dialogs/" + dialogName + ".html'"
143 + ", null"
144 + ", null"
145 + (i18nSupport.isEnabled()? ", '" + i18nSupport.getLocale().toString() + "'":"")
146 +");";
147 }
148
149
150
151
152 @Deprecated
153 public void drawHtml(JspWriter out) throws IOException {
154 drawHtml((Writer) out);
155 }
156
157
158
159
160 public void drawHtml(Writer out) throws IOException {
161 final AggregationState aggregationState = MgnlContext.getAggregationState();
162 final Node mainContent = aggregationState.getMainContent().getJCRNode();
163 boolean isGranted;
164 try {
165 isGranted = PermissionUtil.isGranted(mainContent.getSession(), mainContent.getPath(), Permission.SET);
166 } catch (RepositoryException e) {
167
168 throw new RuntimeException(e);
169 }
170 if (!aggregationState.isPreviewMode() && isGranted) {
171 this.setEvent("onmousedown", "mgnlMoveNodeEnd(this,'" + this.getPath() + "');");
172 this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);");
173 this.setEvent("onmouseout", "mgnlMoveNodeReset(this);");
174 this.setId(this.getNodeCollectionName() + "__" + this.getNodeName());
175 println(out, this.getHtml());
176 }
177 }
178
179 public String getParagraph() {
180 return this.paragraph;
181 }
182
183 public void setParagraph(String paragraph) {
184 this.paragraph = paragraph;
185 }
186 }