fixed #30873
@@ -1,56 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright 2009-2013 the Fess 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 | - | |
17 | -package jp.sf.fess.suggest.converter; | |
18 | - | |
19 | -import java.util.ArrayList; | |
20 | -import java.util.List; | |
21 | - | |
22 | -public class SymbolConveter implements SuggestConverter { | |
23 | - | |
24 | - protected List<String> symbolList = new ArrayList<String>(); | |
25 | - | |
26 | - protected String symbolPrefix; | |
27 | - | |
28 | - protected String symbolSuffix; | |
29 | - | |
30 | - public SymbolConveter() { | |
31 | - this("__ID", "__"); | |
32 | - } | |
33 | - | |
34 | - public SymbolConveter(final String prefix, final String suffix) { | |
35 | - symbolPrefix = prefix; | |
36 | - symbolSuffix = suffix; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public String convert(final String query) { | |
41 | - | |
42 | - String target = query; | |
43 | - for (int i = 0; i < symbolList.size(); i++) { | |
44 | - target = target.replaceAll(symbolList.get(i), symbolPrefix | |
45 | - + Integer.valueOf(i) + symbolSuffix); | |
46 | - } | |
47 | - return target; | |
48 | - } | |
49 | - | |
50 | - public void addSymbol(final String symbol) { | |
51 | - if (symbol != null) { | |
52 | - symbolList.add(symbol); | |
53 | - } | |
54 | - } | |
55 | - | |
56 | -} |
@@ -0,0 +1,61 @@ | ||
1 | +/* | |
2 | + * Copyright 2009-2013 the Fess 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 | + | |
17 | +package jp.sf.fess.suggest.converter; | |
18 | + | |
19 | +import java.util.ArrayList; | |
20 | +import java.util.List; | |
21 | + | |
22 | +import org.apache.commons.lang.StringEscapeUtils; | |
23 | + | |
24 | +public class SymbolConverter implements SuggestConverter { | |
25 | + | |
26 | + protected List<String> symbolList = new ArrayList<String>(); | |
27 | + | |
28 | + protected String symbolPrefix; | |
29 | + | |
30 | + protected String symbolSuffix; | |
31 | + | |
32 | + public SymbolConverter() { | |
33 | + this("__ID", "__"); | |
34 | + } | |
35 | + | |
36 | + public SymbolConverter(final String prefix, final String suffix) { | |
37 | + symbolPrefix = prefix; | |
38 | + symbolSuffix = suffix; | |
39 | + } | |
40 | + | |
41 | + @Override | |
42 | + public String convert(final String query) { | |
43 | + | |
44 | + String target = query; | |
45 | + for (int i = 0; i < symbolList.size(); i++) { | |
46 | + target = target.replace(symbolList.get(i), | |
47 | + symbolPrefix + Integer.valueOf(i) + symbolSuffix); | |
48 | + } | |
49 | + return target; | |
50 | + } | |
51 | + | |
52 | + public void addSymbol(final String[] symbols) { | |
53 | + if (symbols == null || symbols.length == 0) { | |
54 | + return; | |
55 | + } | |
56 | + | |
57 | + for (final String symbol : symbols) { | |
58 | + symbolList.add(StringEscapeUtils.unescapeHtml(symbol)); | |
59 | + } | |
60 | + } | |
61 | +} |