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 | 3566 | jorpiell | |
---|---|---|---|
2 | 3593 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | 2820 | jorpiell | *
|
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 | 3593 | jorpiell | * Av. Blasco Ib??ez, 50
|
25 | 2820 | jorpiell | * 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 | 2145 | jorpiell | package es.gva.cit.catalogClient.languages; |
43 | import java.util.Iterator; |
||
44 | import java.util.StringTokenizer; |
||
45 | |||
46 | /**
|
||
47 | 3566 | jorpiell | * This class is used to create a Common Query Language query.
|
48 | 2921 | jorpiell | * See the specification for more information.
|
49 | *
|
||
50 | 3566 | jorpiell | *
|
51 | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
||
52 | 2953 | jorpiell | * @see http://www.loc.gov/z3950/agency/zing/cql/
|
53 | 2145 | jorpiell | */
|
54 | 2724 | jorpiell | public class CommonQueryLanguage extends AbstractGeneralLanguage { |
55 | 3566 | jorpiell | |
56 | /**
|
||
57 | *
|
||
58 | *
|
||
59 | *
|
||
60 | * @param parameter
|
||
61 | * @param line
|
||
62 | * @param concordancia
|
||
63 | */
|
||
64 | 3891 | jorpiell | public void addClauses(String parameter, String line, String concordancia,String operator) { |
65 | 2724 | jorpiell | currentClause = null;
|
66 | 2921 | jorpiell | |
67 | 2724 | jorpiell | Iterator values = parseValues(line, concordancia);
|
68 | 3891 | jorpiell | addClauses(parameter, values, concordancia,operator); |
69 | 3566 | jorpiell | } |
70 | 2724 | jorpiell | |
71 | 3566 | jorpiell | /**
|
72 | *
|
||
73 | *
|
||
74 | *
|
||
75 | * @param parameter
|
||
76 | * @param values
|
||
77 | * @param concordancia
|
||
78 | */
|
||
79 | 3891 | jorpiell | public void addClauses(String parameter, Iterator values, String concordancia, String operator) { |
80 | 2724 | jorpiell | while (values.hasNext())
|
81 | addTerm(parameter, (String) values.next(), concordancia);
|
||
82 | 3891 | jorpiell | addCurrentClauseQuery(operator); |
83 | 3566 | jorpiell | } |
84 | 2724 | jorpiell | |
85 | 3566 | jorpiell | /**
|
86 | 3595 | jorpiell | * It adds a new search field to the string
|
87 | 3566 | jorpiell | *
|
88 | 3613 | jorpiell | *
|
89 | 3566 | jorpiell | * @param parameter
|
90 | * @param value
|
||
91 | * @param concordancia
|
||
92 | */
|
||
93 | private void addTerm(String parameter, String value, String concordancia) { |
||
94 | 2724 | jorpiell | 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 | 3891 | jorpiell | |
102 | } |
||
103 | 3566 | jorpiell | } |
104 | 2724 | jorpiell | |
105 | 3566 | jorpiell | /**
|
106 | *
|
||
107 | *
|
||
108 | */
|
||
109 | 3891 | jorpiell | protected void addCurrentClauseQuery(String operator) { |
110 | 2724 | jorpiell | if (currentClause != null) { |
111 | if (currentQuery == null) { |
||
112 | currentQuery = currentClause; |
||
113 | } else {
|
||
114 | 3891 | jorpiell | currentQuery = "(" + currentQuery + " " + |
115 | operator + " " + currentClause + ")"; |
||
116 | 2724 | jorpiell | } |
117 | } |
||
118 | 3566 | jorpiell | } |
119 | 2724 | jorpiell | |
120 | 3566 | jorpiell | /**
|
121 | *
|
||
122 | *
|
||
123 | *
|
||
124 | * @return
|
||
125 | */
|
||
126 | public String toString() { |
||
127 | 2724 | jorpiell | return currentQuery;
|
128 | 3566 | jorpiell | } |
129 | 2724 | jorpiell | |
130 | 3566 | jorpiell | /**
|
131 | *
|
||
132 | *
|
||
133 | *
|
||
134 | * @return
|
||
135 | * @param line
|
||
136 | * @param titleKeys
|
||
137 | */
|
||
138 | public String cutWord(String line, String titleKeys) { |
||
139 | 3509 | jorpiell | |
140 | 2724 | jorpiell | 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 | 3566 | jorpiell | } |
157 | } |