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.es.config.exentity;
17  
18  import java.util.Map;
19  
20  import org.apache.http.auth.UsernamePasswordCredentials;
21  import org.codelibs.core.lang.StringUtil;
22  import org.codelibs.fess.crawler.client.CrawlerClientFactory;
23  import org.codelibs.fess.crawler.client.http.HcHttpClient;
24  import org.codelibs.fess.mylasta.direction.FessConfig;
25  import org.codelibs.fess.util.ComponentUtil;
26  
27  public interface CrawlingConfig {
28  
29      String getId();
30  
31      String getName();
32  
33      String[] getPermissions();
34  
35      String[] getVirtualHosts();
36  
37      String getDocumentBoost();
38  
39      String getIndexingTarget(String input);
40  
41      String getConfigId();
42  
43      Integer getTimeToLive();
44  
45      Map<String, Object> initializeClientFactory(CrawlerClientFactory crawlerClientFactory);
46  
47      Map<String, String> getConfigParameterMap(ConfigName name);
48  
49      default void initializeDefaultHttpProxy(final Map<String, Object> paramMap) {
50          final FessConfig fessConfig = ComponentUtil.getFessConfig();
51          final String proxyHost = fessConfig.getHttpProxyHost();
52          final String proxyPort = fessConfig.getHttpProxyPort();
53          if (StringUtil.isNotBlank(proxyHost) && StringUtil.isNotBlank(proxyPort)) {
54              paramMap.put(HcHttpClient.PROXY_HOST_PROPERTY, proxyHost);
55              paramMap.put(HcHttpClient.PROXY_PORT_PROPERTY, proxyPort);
56              final String proxyUsername = fessConfig.getHttpProxyUsername();
57              final String proxyPassword = fessConfig.getHttpProxyPassword();
58              if (proxyUsername != null && proxyPassword != null) {
59                  paramMap.put(HcHttpClient.PROXY_CREDENTIALS_PROPERTY, new UsernamePasswordCredentials(proxyUsername, proxyPassword));
60              }
61  
62          }
63      }
64  
65      public enum ConfigType {
66          WEB("W"), FILE("F"), DATA("D");
67  
68          private final String typePrefix;
69  
70          ConfigType(final String typePrefix) {
71              this.typePrefix = typePrefix;
72          }
73  
74          public String getTypePrefix() {
75              return typePrefix;
76          }
77  
78          String getConfigId(final String id) {
79              if (id == null) {
80                  return null;
81              }
82              return typePrefix + id.toString();
83          }
84      }
85  
86      public enum ConfigName {
87          CLIENT, XPATH, META, VALUE, SCRIPT, FIELD, CONFIG;
88      }
89  }