001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.unifiedGui.validator;
032:
033: import java.util.regex.*;
034:
035: import de.ug2t.kernel.*;
036:
037: /**
038: * @author Dirk
039: *
040: * date: 26.06.2004
041: *
042: * <p>
043: * Purpose:
044: * </p>
045: */
046:
047: public final class UnRegExpValidator extends AUnValidator {
048: private Pattern pem_papttern = null;
049: private String pem_matchString = null;
050: private String pem_message = null;
051:
052: private static final String NOT_MATCHED = "VALUE: [$VAL] does not match pattern: [$PAT]";
053:
054: /**
055: *
056: */
057: public UnRegExpValidator(String xPattern) {
058: this .pem_matchString = xPattern;
059: this .pem_papttern = Pattern.compile(xPattern);
060: }
061:
062: public UnRegExpValidator(String xPattern, String xErrorMessage) {
063: this (xPattern);
064: this .pem_message = xErrorMessage;
065: }
066:
067: /**
068: * <p>
069: * Does...
070: * </p>
071: * <p>
072: *
073: * @return a Type with
074: * </p>
075: * <p>
076: * @param
077: * </p>
078: */
079: public String pcmf_validateMethod(Object xtoValidate) {
080: if (xtoValidate == null) {
081: String l_raw = null;
082:
083: if (this .pem_message != null)
084: l_raw = this .pem_message;
085: else
086: l_raw = NOT_MATCHED;
087:
088: String l_res = KeTools.pcmf_stringSingleSubst(l_raw,
089: "$VAL", "null");
090: l_res = KeTools.pcmf_stringSingleSubst(l_raw, "$PAT",
091: pem_matchString);
092:
093: return (l_res);
094: } else if (this .pem_papttern.matcher(xtoValidate.toString())
095: .matches() == false) {
096: String l_raw = null;
097:
098: if (this .pem_message != null)
099: l_raw = this .pem_message;
100: else
101: l_raw = NOT_MATCHED;
102:
103: String l_res = KeTools.pcmf_stringSingleSubst(l_raw,
104: "$VAL", "null");
105: l_res = KeTools.pcmf_stringSingleSubst(l_raw, "$PAT",
106: pem_matchString);
107:
108: return (l_res);
109: } else
110: return (null);
111: }
112:
113: public void pcmf_setPattern(String xPattern) {
114: this.pem_matchString = xPattern;
115: this.pem_papttern = Pattern.compile(xPattern);
116: }
117: }
|