View Javadoc
1   /*
2    * Copyright 2012-2021 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.mylasta.direction.sponsor;
17  
18  import org.codelibs.core.lang.StringUtil;
19  import org.codelibs.fess.util.ComponentUtil;
20  import org.dbflute.util.DfTypeUtil;
21  import org.lastaflute.web.path.ActionAdjustmentProvider;
22  import org.lastaflute.web.path.FormMappingOption;
23  
24  /**
25   * @author jflute
26   */
27  public class FessActionAdjustmentProvider implements ActionAdjustmentProvider {
28  
29      // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
30      // you can adjust your actions by overriding
31      // default methods defined at the interface
32      // _/_/_/_/_/_/_/_/_/_/
33  
34      @Override
35      public FormMappingOption adjustFormMapping() {
36          return new FormMappingOption()
37                  .filterSimpleTextParameter((parameter, meta) -> parameter.trim().replace("\r\n", "\n").replace('\r', '\n'));
38      }
39  
40      @Override
41      public String customizeActionMappingRequestPath(final String requestPath) {
42          if (StringUtil.isBlank(requestPath)) {
43              return null;
44          }
45          final String virtualHostKey = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
46          if (StringUtil.isBlank(virtualHostKey)) {
47              return null;
48          }
49          final String prefix = "/" + virtualHostKey;
50          if (requestPath.startsWith(prefix)) {
51              return requestPath.substring(prefix.length());
52          }
53          return null;
54      }
55  
56      @Override
57      public String toString() {
58          return DfTypeUtil.toClassTitle(this) + ":{}";
59      }
60  }