1 /*
2 * Copyright 2012-2017 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.web.base;
17
18 import javax.servlet.ServletContext;
19
20 import org.codelibs.fess.exception.UserRoleLoginException;
21 import org.dbflute.optional.OptionalThing;
22 import org.lastaflute.di.util.LdiFileUtil;
23 import org.lastaflute.web.login.LoginManager;
24 import org.lastaflute.web.response.ActionResponse;
25 import org.lastaflute.web.ruts.process.ActionRuntime;
26 import org.lastaflute.web.util.LaServletContextUtil;
27
28 /**
29 * @author codelibs
30 * @author jflute
31 */
32 public abstract class FessAdminAction extends FessBaseAction {
33
34 // ===================================================================================
35 // Small Helper
36 // ============
37
38 @Override
39 protected void setupHtmlData(final ActionRuntime runtime) {
40 super.setupHtmlData(runtime);
41 systemHelper.setupAdminHtmlData(this, runtime);
42 }
43
44 protected void write(final String path, final byte[] data) {
45 LdiFileUtil.write(path, data);
46 }
47
48 protected ServletContext getServletContext() {
49 return LaServletContextUtil.getServletContext();
50 }
51
52 // ===================================================================================
53 // Document
54 // ========
55 /**
56 * {@inheritDoc} <br>
57 * Application Origin Methods:
58 * <pre>
59 * <span style="font-size: 130%; color: #553000">[Small Helper]</span>
60 * o saveInfo() <span style="color: #3F7E5E">// save messages to session</span>
61 * o write() <span style="color: #3F7E5E">// write text to specified file</span>
62 * o copyBeanToBean() <span style="color: #3F7E5E">// copy bean to bean by BeanUtil</span>
63 * o getServletContext() <span style="color: #3F7E5E">// get servlet context</span>
64 * </pre>
65 */
66 @Override
67 public void document1_CallableSuperMethod() {
68 super.document1_CallableSuperMethod();
69 }
70
71 // ===================================================================================
72 // User Info
73 // =========
74 @Override
75 protected OptionalThing<LoginManager> myLoginManager() {
76 return OptionalThing.of(fessLoginAssist);
77 }
78
79 // ===================================================================================
80 // Hook
81 // ======
82 @Override
83 public ActionResponse godHandPrologue(final ActionRuntime runtime) {
84 try {
85 return super.godHandPrologue(runtime);
86 } catch (final UserRoleLoginException e) {
87 return redirect(e.getActionClass());
88 }
89 }
90
91 @Override
92 public ActionResponse hookBefore(final ActionRuntime runtime) {
93 final String requestPath = runtime.getRequestPath();
94 final String executeName = runtime.getExecuteMethod().getName();
95 activityHelper.access(getUserBean(), requestPath, executeName);
96 return super.hookBefore(runtime);
97 }
98
99 @Override
100 public void hookFinally(final ActionRuntime runtime) {
101 super.hookFinally(runtime);
102 }
103
104 }