01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.analysis;
17:
18: import java.util.Map;
19:
20: /**
21: * Simple abstract implementation that handles init arg processing.
22: *
23: * @author yonik
24: * @version $Id: BaseTokenFilterFactory.java 472574 2006-11-08 18:25:52Z yonik $
25: */
26: public abstract class BaseTokenFilterFactory implements
27: TokenFilterFactory {
28: /** The init args */
29: protected Map<String, String> args;
30:
31: public void init(Map<String, String> args) {
32: this .args = args;
33: }
34:
35: public Map<String, String> getArgs() {
36: return args;
37: }
38:
39: // TODO: move these somewhere that tokenizers and others
40: // can also use them...
41: protected int getInt(String name) {
42: return getInt(name, -1, false);
43: }
44:
45: protected int getInt(String name, int defaultVal) {
46: return getInt(name, defaultVal, true);
47: }
48:
49: protected int getInt(String name, int defaultVal, boolean useDefault) {
50: String s = args.get(name);
51: if (s == null) {
52: if (useDefault)
53: return defaultVal;
54: throw new RuntimeException(
55: "Configuration Error: missing parameter '" + name
56: + "'");
57: }
58: return Integer.parseInt(s);
59: }
60:
61: protected boolean getBoolean(String name, boolean defaultVal) {
62: return getBoolean(name, defaultVal, true);
63: }
64:
65: protected boolean getBoolean(String name, boolean defaultVal,
66: boolean useDefault) {
67: String s = args.get(name);
68: if (s == null) {
69: if (useDefault)
70: return defaultVal;
71: throw new RuntimeException(
72: "Configuration Error: missing parameter '" + name
73: + "'");
74: }
75: return Boolean.parseBoolean(s);
76: }
77:
78: }
|