01: //** Copyright Statement ***************************************************
02: //The Salmon Open Framework for Internet Applications (SOFIA)
03: // Copyright (C) 1999 - 2002, Salmon LLC
04: //
05: // This program is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU General Public License version 2
07: // as published by the Free Software Foundation;
08: //
09: // This program 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 General Public License for more details.
13: //
14: // You should have received a copy of the GNU General Public License
15: // along with this program; if not, write to the Free Software
16: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: //
18: // For more information please visit http://www.salmonllc.com
19: //** End Copyright Statement ***************************************************
20: package com.salmonllc.forms;
21:
22: /////////////////////////
23: //$Archive: /JADE/SourceCode/com/salmonllc/forms/CriteriaString.java $
24: //$Author: Dan $
25: //$Revision: 9 $
26: //$Modtime: 10/30/02 2:58p $
27: /////////////////////////
28: /**
29: * Implements a string for SQL-command criteria. The point of this class is to
30: * manage connectors such as "and".
31: */
32: public class CriteriaString {
33: private String _stAnd;
34: private String _buf;
35:
36: /**
37: * CriteriaString constructor comment.
38: */
39: public CriteriaString() {
40: super ();
41: reset();
42: }
43:
44: /**
45: * Adds a sub-criteria preceded by "and" if necessary.
46: * @param s java.lang.String
47: */
48: public void and(String s) {
49: if ((s != null) && (s.length() > 0)) {
50: String ss = s.trim().substring(0, 3).toUpperCase();
51: if (!ss.equals("AND"))
52: _buf += _stAnd;
53: _buf += s;
54: _stAnd = " and ";
55: }
56: }
57:
58: /**
59: * Returns length of internal string buffer.
60: * @return int
61: */
62: public int length() {
63: return _buf.length();
64: }
65:
66: /**
67: * Resets internal state.
68: */
69: public void reset() {
70: _stAnd = "";
71: _buf = "";
72: }
73:
74: /**
75: * Convert to String.
76: * @return java.lang.String
77: */
78: public String toString() {
79: if (_buf.length() == 0)
80: return null;
81: else
82: return _buf;
83: }
84: }
|