View Javadoc
1   /*
2    * Copyright 2012-2019 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.annotation.Resource;
19  import javax.servlet.ServletContext;
20  
21  import org.codelibs.fess.exception.UserRoleLoginException;
22  import org.codelibs.fess.helper.CrawlingConfigHelper;
23  import org.dbflute.optional.OptionalThing;
24  import org.lastaflute.di.util.LdiFileUtil;
25  import org.lastaflute.web.login.LoginManager;
26  import org.lastaflute.web.response.ActionResponse;
27  import org.lastaflute.web.ruts.process.ActionRuntime;
28  import org.lastaflute.web.util.LaServletContextUtil;
29  
30  /**
31   * @author codelibs
32   * @author jflute
33   */
34  public abstract class FessAdminAction extends FessBaseAction {
35  
36      // ===================================================================================
37      //                                                                           Attribute
38      //                                                                           =========
39      @Resource
40      protected CrawlingConfigHelper crawlingConfigHelper;
41  
42      // ===================================================================================
43      //                                                                        Small Helper
44      //                                                                        ============
45  
46      @Override
47      protected void setupHtmlData(final ActionRuntime runtime) {
48          super.setupHtmlData(runtime);
49          systemHelper.setupAdminHtmlData(this, runtime);
50      }
51  
52      protected void write(final String path, final byte[] data) {
53          LdiFileUtil.write(path, data);
54      }
55  
56      protected ServletContext getServletContext() {
57          return LaServletContextUtil.getServletContext();
58      }
59  
60      // ===================================================================================
61      //                                                                            Document
62      //                                                                            ========
63      /**
64       * {@inheritDoc} <br>
65       * Application Origin Methods:
66       * <pre>
67       * <span style="font-size: 130%; color: #553000">[Small Helper]</span>
68       * o saveInfo() <span style="color: #3F7E5E">// save messages to session</span>
69       * o write() <span style="color: #3F7E5E">// write text to specified file</span>
70       * o copyBeanToBean() <span style="color: #3F7E5E">// copy bean to bean by BeanUtil</span>
71       * o getServletContext() <span style="color: #3F7E5E">// get servlet context</span>
72       * </pre>
73       */
74      @Override
75      public void document1_CallableSuperMethod() {
76          super.document1_CallableSuperMethod();
77      }
78  
79      // ===================================================================================
80      //                                                                           User Info
81      //                                                                           =========
82      @Override
83      protected OptionalThing<LoginManager> myLoginManager() {
84          return OptionalThing.of(fessLoginAssist);
85      }
86  
87      // ===================================================================================
88      //                                                                               Hook
89      //                                                                              ======
90      @Override
91      public ActionResponse godHandPrologue(final ActionRuntime runtime) {
92          try {
93              return super.godHandPrologue(runtime);
94          } catch (final UserRoleLoginException e) {
95              return redirect(e.getActionClass());
96          }
97      }
98  
99      @Override
100     public ActionResponse hookBefore(final ActionRuntime runtime) {
101         final String requestPath = runtime.getRequestPath();
102         final String executeName = runtime.getExecuteMethod().getName();
103         activityHelper.access(getUserBean(), requestPath, executeName);
104         return super.hookBefore(runtime);
105     }
106 
107     @Override
108     public void hookFinally(final ActionRuntime runtime) {
109         super.hookFinally(runtime);
110     }
111 
112 }