1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.dict;
17
18 import java.util.Base64;
19 import java.util.Date;
20 import java.util.regex.Pattern;
21
22 import org.codelibs.fess.Constants;
23
24 public abstract class DictionaryCreator {
25 protected Pattern pattern;
26
27 protected DictionaryManager dictionaryManager;
28
29 public DictionaryCreator(final String pattern) {
30 this.pattern = Pattern.compile(pattern);
31 }
32
33 public DictionaryFile<? extends DictionaryItem> create(final String path, final Date timestamp) {
34 if (!isTarget(path)) {
35 return null;
36 }
37
38 return newDictionaryFile(encodePath(path), path, timestamp);
39 }
40
41 protected String encodePath(final String path) {
42 return Base64.getUrlEncoder().encodeToString(path.getBytes(Constants.CHARSET_UTF_8));
43 }
44
45 protected boolean isTarget(final String path) {
46 return pattern.matcher(path).find();
47 }
48
49 protected abstract DictionaryFile<? extends DictionaryItem> newDictionaryFile(String id, String path, Date timestamp);
50
51 public void setDictionaryManager(final DictionaryManager dictionaryManager) {
52 this.dictionaryManager = dictionaryManager;
53 }
54 }