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 public void init() {
111 super.init();
112 if (StringUtils.isEmpty(this.getCommand())) {
113 this.setCommand(COMMAND_SHOW);
114 }
115 }
116
117
118
119
120
121 public String show() {
122 return VIEW_SHOW;
123 }
124
125
126
127
128 protected void setForm(MultipartForm form) {
129 this.form = form;
130 }
131
132
133
134
135 protected MultipartForm getForm() {
136 return form;
137 }
138
139
140
141
142 protected void setMsgs(Messages msgs) {
143 this.msgs = msgs;
144 }
145
146
147
148
149 protected Messages getMsgs() {
150 if(msgs == null){
151 msgs = MessagesManager.getMessages(getI18nBasename());
152 }
153 return msgs;
154 }
155
156
157
158
159 protected void setParams(RequestFormUtil params) {
160 this.params = params;
161 }
162
163
164
165
166 protected RequestFormUtil getParams() {
167 return params;
168 }
169
170
171 public String getI18nBasename() {
172 return this.i18nBasename;
173 }
174
175
176 public void setI18nBasename(String basename) {
177 this.i18nBasename = basename;
178 }
179 }