01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.generator.casters;
21:
22: import java.util.ArrayList;
23:
24: import org.apache.oro.text.regex.MalformedPatternException;
25: import org.apache.oro.text.regex.Perl5Compiler;
26: import org.apache.oro.text.regex.Perl5Pattern;
27:
28: import de.schlund.pfixcore.generator.IWrapperParamCaster;
29: import de.schlund.pfixcore.generator.SimpleCheck;
30: import de.schlund.pfixxml.RequestParam;
31: import de.schlund.util.statuscodes.StatusCode;
32: import de.schlund.util.statuscodes.StatusCodeLib;
33:
34: /**
35: * ToPerl5Pattern.java
36: *
37: *
38: * Created: Sun Mar 10 15:51:47 2002
39: *
40: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
41: *
42: *
43: */
44:
45: public class ToPerl5Pattern extends SimpleCheck implements
46: IWrapperParamCaster {
47: private Perl5Pattern[] value = null;
48: private final static Perl5Compiler compiler = new Perl5Compiler();
49: private StatusCode scode;
50:
51: public ToPerl5Pattern() {
52: scode = StatusCodeLib.PFIXCORE_GENERATOR_CASTER_ERR_TO_P5PATTERN;
53: }
54:
55: public void put_scode_casterror(String fqscode) {
56: scode = StatusCodeLib.getStatusCodeByName(fqscode);
57: }
58:
59: // implementation of de.schlund.pfixcore.generator.IWrapperParamCaster interface
60:
61: /**
62: *
63: * @return <description>
64: */
65: public Object[] getValue() {
66: return value;
67: }
68:
69: /**
70: *
71: * @param param <description>
72: */
73: public void castValue(RequestParam[] param) {
74: reset();
75: Perl5Pattern val;
76: ArrayList<Perl5Pattern> patterns = new ArrayList<Perl5Pattern>();
77: for (int i = 0; i < param.length; i++) {
78: try {
79: val = tryCompile(param[i].getValue());
80: patterns.add(val);
81: } catch (MalformedPatternException e) {
82: val = null;
83: addSCode(scode);
84: break;
85: }
86: }
87: if (!errorHappened()) {
88: value = (Perl5Pattern[]) patterns
89: .toArray(new Perl5Pattern[] {});
90: }
91: }
92:
93: private synchronized Perl5Pattern tryCompile(String in)
94: throws MalformedPatternException {
95: return (Perl5Pattern) compiler.compile(in,
96: Perl5Compiler.CASE_INSENSITIVE_MASK);
97: }
98:
99: }// ToPerl5Pattern
|