Statistics
| Revision:

svn-gvsig-desktop / tags / Root_v061 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / languages / CommonQueryLanguage.java @ 4812

History | View | Annotate | Download (4.01 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalogClient.languages;
43
import java.util.Iterator;
44
import java.util.StringTokenizer;
45

    
46
/**
47
 * This class is used to create a Common Query Language query.
48
 * See the specification for more information.
49
 * 
50
 * 
51
 * @author Jorge Piera Llodra (piera_jor@gva.es)
52
 * @see http://www.loc.gov/z3950/agency/zing/cql/
53
 */
54
public class CommonQueryLanguage extends AbstractGeneralLanguage {
55

    
56
/**
57
 * 
58
 * 
59
 * 
60
 * @param parameter 
61
 * @param line 
62
 * @param concordancia 
63
 */
64
    public void addClauses(String parameter, String line, String concordancia,String operator) {        
65
        currentClause = null;
66
        
67
        Iterator values = parseValues(line, concordancia);
68
        addClauses(parameter, values, concordancia,operator);
69
    } 
70

    
71
/**
72
 * 
73
 * 
74
 * 
75
 * @param parameter 
76
 * @param values 
77
 * @param concordancia 
78
 */
79
    public void addClauses(String parameter, Iterator values, String concordancia, String operator) {        
80
        while (values.hasNext())
81
            addTerm(parameter, (String) values.next(), concordancia);
82
        addCurrentClauseQuery(operator);
83
    } 
84

    
85
/**
86
 * It adds a new search field to the string
87
 * 
88
 * 
89
 * @param parameter 
90
 * @param value 
91
 * @param concordancia 
92
 */
93
    private void addTerm(String parameter, String value, String concordancia) {        
94
        StringBuffer term = new StringBuffer();
95
        term.append(parameter + "=" + cutWord(value, concordancia));
96
        if (currentClause == null) {
97
            currentClause = term.toString();
98
        } else {
99
            currentClause = "(" + currentClause + " " +
100
                getOperator(concordancia) + " " + term.toString() + ")";
101
            
102
        }          
103
    } 
104

    
105
/**
106
 * 
107
 * 
108
 */
109
    protected void addCurrentClauseQuery(String operator) {        
110
        if (currentClause != null) {
111
            if (currentQuery == null) {
112
                currentQuery = currentClause;
113
            } else {
114
                currentQuery = "(" + currentQuery + " " +
115
                operator  + " " + currentClause + ")";
116
            }
117
        }
118
    } 
119

    
120
/**
121
 * 
122
 * 
123
 * 
124
 * @return 
125
 */
126
    public String toString() {        
127
        return currentQuery;
128
    } 
129

    
130
/**
131
 * 
132
 * 
133
 * 
134
 * @return 
135
 * @param line 
136
 * @param titleKeys 
137
 */
138
    public String cutWord(String line, String titleKeys) {        
139
        
140
        if (titleKeys.equals("E")) {
141
            StringTokenizer sti = new StringTokenizer(line, " ", true);
142
            boolean first = true;
143
            String token = "";
144
            while (sti.hasMoreTokens()) {
145
                String currentToken = sti.nextToken();
146
                if (first) {
147
                    token = currentToken;
148
                    first = !first;
149
                } else if (!(currentToken.equals(" "))) {
150
                    token = "(" + token + " and " + currentToken + ")";
151
                }
152
            }
153
            return token;
154
        }
155
        return line;
156
    } 
157
 }