View Javadoc
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.es.config.exentity;
17  
18  import java.util.regex.Matcher;
19  import java.util.regex.Pattern;
20  
21  import org.codelibs.core.lang.StringUtil;
22  import org.codelibs.fess.es.config.bsentity.BsPathMapping;
23  
24  /**
25   * @author FreeGen
26   */
27  public class PathMapping extends BsPathMapping {
28  
29      private static final long serialVersionUID = 1L;
30  
31      private Pattern regexPattern;
32  
33      private Pattern userAgentPattern;
34  
35      public String getId() {
36          return asDocMeta().id();
37      }
38  
39      public void setId(final String id) {
40          asDocMeta().id(id);
41      }
42  
43      public Long getVersionNo() {
44          return asDocMeta().version();
45      }
46  
47      public void setVersionNo(final Long version) {
48          asDocMeta().version(version);
49      }
50  
51      public Matcher getMatcher(final CharSequence input) {
52          if (regexPattern == null) {
53              regexPattern = Pattern.compile(getRegex());
54          }
55          return regexPattern.matcher(input);
56      }
57  
58      public boolean hasUAMathcer() {
59          return StringUtil.isNotBlank(getUserAgent());
60      }
61  
62      public Matcher getUAMatcher(final CharSequence input) {
63          if (!hasUAMathcer()) {
64              return null;
65          }
66  
67          if (userAgentPattern == null) {
68              userAgentPattern = Pattern.compile(getUserAgent());
69          }
70          return userAgentPattern.matcher(input);
71      }
72  
73      @Override
74      public String toString() {
75          return "PathMapping [regexPattern=" + regexPattern + ", createdBy=" + createdBy + ", createdTime=" + createdTime + ", processType="
76                  + processType + ", regex=" + regex + ", replacement=" + replacement + ", sortOrder=" + sortOrder + ", userAgent="
77                  + userAgent + ", updatedBy=" + updatedBy + ", updatedTime=" + updatedTime + ", docMeta=" + docMeta + "]";
78      }
79  }