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.module.admininterface;
35
36 import info.magnolia.cms.beans.runtime.MultipartForm;
37 import info.magnolia.cms.i18n.Messages;
38 import info.magnolia.cms.i18n.MessagesManager;
39 import info.magnolia.cms.servlets.CommandBasedMVCServletHandler;
40 import info.magnolia.cms.util.RequestFormUtil;
41 import info.magnolia.context.MgnlContext;
42 import org.apache.commons.lang.StringUtils;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48
49
50
51
52
53
54
55
56 public abstract class PageMVCHandler extends CommandBasedMVCServletHandler {
57
58
59
60
61 Logger log = LoggerFactory.getLogger(PageMVCHandler.class);
62
63
64
65
66 protected static final String COMMAND_PARAMETER_NAME = "command";
67
68 protected static final String COMMAND_SHOW = "show";
69
70 protected static final String VIEW_SHOW = "show";
71
72
73
74
75 private MultipartForm form;
76
77
78
79
80 private Messages msgs;
81
82
83
84
85 private RequestFormUtil params;
86
87
88
89
90 private String i18nBasename = MessagesManager.DEFAULT_BASENAME;
91
92
93
94
95
96
97
98 public PageMVCHandler(String name, HttpServletRequest request, HttpServletResponse response) {
99 super(name, request, response);
100
101 setForm(MgnlContext.getPostedForm());
102 setParams(new RequestFormUtil(request, getForm()));
103 }
104
105
106
107
108
109
110 @Override
111 public void init() {
112 super.init();
113 if (StringUtils.isEmpty(this.getCommand())) {
114 this.setCommand(COMMAND_SHOW);
115 }
116 }
117
118
119
120
121
122 public String show() {
123 return VIEW_SHOW;
124 }
125
126
127
128
129 protected void setForm(MultipartForm form) {
130 this.form = form;
131 }
132
133
134
135
136 protected MultipartForm getForm() {
137 return form;
138 }
139
140
141
142
143 protected void setMsgs(Messages msgs) {
144 this.msgs = msgs;
145 }
146
147
148
149
150 protected Messages getMsgs() {
151 if(msgs == null){
152 msgs = MessagesManager.getMessages(getI18nBasename());
153 }
154 return msgs;
155 }
156
157
158
159
160 protected void setParams(RequestFormUtil params) {
161 this.params = params;
162 }
163
164
165
166
167 protected RequestFormUtil getParams() {
168 return params;
169 }
170
171
172 public String getI18nBasename() {
173 return this.i18nBasename;
174 }
175
176
177 public void setI18nBasename(String basename) {
178 this.i18nBasename = basename;
179 }
180 }