View Javadoc
1   /*
2    * Copyright 2012-2025 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.admin.webconfig;
17  
18  import org.codelibs.core.lang.StringUtil;
19  import org.codelibs.fess.Constants;
20  import org.codelibs.fess.app.web.CrudMode;
21  import org.codelibs.fess.mylasta.direction.FessConfig;
22  import org.codelibs.fess.util.ComponentUtil;
23  import org.codelibs.fess.validation.CustomSize;
24  import org.codelibs.fess.validation.UriType;
25  import org.codelibs.fess.validation.UriTypeValidator.ProtocolType;
26  import org.lastaflute.web.validation.Required;
27  import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
28  
29  import jakarta.validation.constraints.Max;
30  import jakarta.validation.constraints.Min;
31  import jakarta.validation.constraints.Size;
32  
33  /**
34   * The create form for Web Config.
35   *
36   */
37  public class CreateForm {
38  
39      /**
40       * Default constructor.
41       */
42      public CreateForm() {
43          // Empty constructor
44      }
45  
46      /**
47       * The label type IDs associated with this web configuration.
48       */
49      public String[] labelTypeIds;
50  
51      /**
52       * The CRUD mode for the form.
53       */
54      @ValidateTypeFailure
55      public Integer crudMode;
56  
57      /**
58       * The name of the web configuration.
59       */
60      @Required
61      @Size(max = 200)
62      public String name;
63  
64      /**
65       * The description of the web configuration.
66       */
67      @Size(max = 1000)
68      public String description;
69  
70      /**
71       * The URLs to be crawled by this web configuration.
72       */
73      @Required
74      @UriType(protocolType = ProtocolType.WEB)
75      @CustomSize(maxKey = "form.admin.max.input.size")
76      public String urls;
77  
78      /**
79       * URL patterns to include during crawling.
80       */
81      @CustomSize(maxKey = "form.admin.max.input.size")
82      public String includedUrls;
83  
84      /**
85       * URL patterns to exclude during crawling.
86       */
87      @CustomSize(maxKey = "form.admin.max.input.size")
88      public String excludedUrls;
89  
90      /**
91       * Document URL patterns to include in search index.
92       */
93      @CustomSize(maxKey = "form.admin.max.input.size")
94      public String includedDocUrls;
95  
96      /**
97       * Document URL patterns to exclude from search index.
98       */
99      @CustomSize(maxKey = "form.admin.max.input.size")
100     public String excludedDocUrls;
101 
102     /**
103      * Additional configuration parameters for the crawler.
104      */
105     @CustomSize(maxKey = "form.admin.max.input.size")
106     public String configParameter;
107 
108     /**
109      * The maximum crawling depth from the starting URLs.
110      */
111     @Min(value = 0)
112     @Max(value = 2147483647)
113     @ValidateTypeFailure
114     public Integer depth;
115 
116     /**
117      * The maximum number of URLs to access during crawling.
118      */
119     @Min(value = 0)
120     @Max(value = 9223372036854775807L)
121     @ValidateTypeFailure
122     public Long maxAccessCount;
123 
124     /**
125      * The user agent string to use during crawling.
126      */
127     @Required
128     @Size(max = 200)
129     public String userAgent;
130 
131     /**
132      * The number of crawler threads to use.
133      */
134     @Required
135     @Min(value = 1)
136     @Max(value = 2147483647)
137     @ValidateTypeFailure
138     public Integer numOfThread;
139 
140     /**
141      * The interval time between requests in milliseconds.
142      */
143     @Required
144     @Min(value = 0)
145     @Max(value = 2147483647)
146     @ValidateTypeFailure
147     public Integer intervalTime;
148 
149     /**
150      * The boost value for documents from this web configuration.
151      */
152     @Required
153     @ValidateTypeFailure
154     public Float boost;
155 
156     /**
157      * Whether this web configuration is available for crawling.
158      */
159     @Required
160     @Size(max = 5)
161     public String available;
162 
163     /**
164      * Permissions required to access documents from this configuration.
165      */
166     @CustomSize(maxKey = "form.admin.max.input.size")
167     public String permissions;
168 
169     /**
170      * Virtual host names for this web configuration.
171      */
172     @CustomSize(maxKey = "form.admin.max.input.size")
173     public String virtualHosts;
174 
175     /**
176      * The sort order for this web configuration.
177      */
178     @Required
179     @Min(value = 0)
180     @Max(value = 2147483647)
181     @ValidateTypeFailure
182     public Integer sortOrder;
183 
184     /**
185      * The user who created this web configuration.
186      */
187     @Size(max = 1000)
188     public String createdBy;
189 
190     /**
191      * The timestamp when this web configuration was created.
192      */
193     @ValidateTypeFailure
194     public Long createdTime;
195 
196     /**
197      * Initializes the form with default values for creating a new web configuration.
198      */
199     public void initialize() {
200         crudMode = CrudMode.CREATE;
201         final FessConfig fessConfig = ComponentUtil.getFessConfig();
202         includedUrls = fessConfig.getCrawlerDocumentHtmlDefaultIncludeIndexPatterns();
203         excludedUrls = fessConfig.getCrawlerDocumentHtmlDefaultExcludeIndexPatterns();
204         includedDocUrls = fessConfig.getCrawlerDocumentHtmlDefaultIncludeSearchPatterns();
205         excludedDocUrls = fessConfig.getCrawlerDocumentHtmlDefaultExcludeSearchPatterns();
206         boost = 1.0f;
207         if (StringUtil.isBlank(userAgent)) {
208             userAgent = fessConfig.getUserAgentName();
209         }
210         numOfThread = Constants.DEFAULT_NUM_OF_THREAD_FOR_WEB;
211         intervalTime = Constants.DEFAULT_INTERVAL_TIME_FOR_WEB;
212         sortOrder = 0;
213         createdBy = ComponentUtil.getSystemHelper().getUsername();
214         createdTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
215         permissions = fessConfig.getSearchDefaultDisplayPermission();
216     }
217 }