svn-gvsig-desktop / tags / v1_1_Build_1013 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / languages / BasicEncodingRules.java @ 13521
History | View | Annotate | Download (4.58 KB)
1 | 3566 | jorpiell | |
---|---|---|---|
2 | 2820 | jorpiell | /* 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 | 2047 | luisw | package es.gva.cit.catalogClient.languages; |
43 | import java.util.Iterator; |
||
44 | |||
45 | /**
|
||
46 | 3566 | jorpiell | * This class is used to create a Basic Encoding Rules (BER) query.
|
47 | 2921 | jorpiell | * See the specification for more information.
|
48 | *
|
||
49 | 3566 | jorpiell | *
|
50 | 2820 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
51 | 3566 | jorpiell | * @see http://www.loc.gov/z3950/agency/
|
52 | 2047 | luisw | */
|
53 | 2724 | jorpiell | public class BasicEncodingRules extends AbstractGeneralLanguage { |
54 | 2047 | luisw | |
55 | 3566 | jorpiell | /**
|
56 | * It adds a new clause to the query
|
||
57 | *
|
||
58 | *
|
||
59 | * @param use It is a number that represent an attribute (4=Title,62=abstract,...)
|
||
60 | * @param structure It defines the attribute type (1=Phrase,2=wors,...)
|
||
61 | * @param relation Relation between the attribute and the query (1=LessThan,3=equal,...)
|
||
62 | * @param line String with the user introduced value
|
||
63 | * @param concordancia Relationship between different words of the same field (more than one words)
|
||
64 | * E,A o Y --> Exact, All, anY
|
||
65 | * @param operator Relationship between fields (title, abstract)
|
||
66 | * 'and' or 'or'
|
||
67 | */
|
||
68 | public void addClauses(String use, String structure, String relation, String line, String concordancia, String operator) { |
||
69 | currentClause = null;
|
||
70 | 2921 | jorpiell | //Cut the words
|
71 | 2724 | jorpiell | Iterator values = parseValues(line, concordancia);
|
72 | 2985 | jorpiell | addClauses(use, structure, relation, values, concordancia,operator); |
73 | 3566 | jorpiell | } |
74 | |||
75 | /**
|
||
76 | * It realize the same function than the "addClauses(String use, String structure
|
||
77 | * String relation,String line, String concordancia)" function, but the words
|
||
78 | * to find are in a vector.
|
||
79 | *
|
||
80 | *
|
||
81 | * @param use
|
||
82 | * @param structure
|
||
83 | * @param relation
|
||
84 | * @param values
|
||
85 | * @param concordancia
|
||
86 | * @param operator
|
||
87 | */
|
||
88 | public void addClauses(String use, String structure, String relation, Iterator values, String concordancia, String operator) { |
||
89 | 2724 | jorpiell | while (values.hasNext())
|
90 | addTerm(use, structure, relation, (String) values.next(),
|
||
91 | getOperator(concordancia)); |
||
92 | 2985 | jorpiell | addCurrentClauseQuery(operator); |
93 | 3566 | jorpiell | } |
94 | 2724 | jorpiell | |
95 | 3566 | jorpiell | /**
|
96 | * Add a new serch field
|
||
97 | *
|
||
98 | *
|
||
99 | * @param use BER use
|
||
100 | * @param structure BER structure
|
||
101 | * @param relation BER relation
|
||
102 | * @param value Filed value
|
||
103 | * @param operator "and" or "or"
|
||
104 | */
|
||
105 | private void addTerm(String use, String structure, String relation, String value, String operator) { |
||
106 | 2724 | jorpiell | StringBuffer term = new StringBuffer(); |
107 | if (use != null) { |
||
108 | term.append("@attr 1=" + use + " "); |
||
109 | } |
||
110 | if (structure != null) { |
||
111 | term.append("@attr 4=" + structure + " "); |
||
112 | } |
||
113 | if (relation != null) { |
||
114 | term.append("@attr 2=" + relation + " "); |
||
115 | } |
||
116 | term.append("\"" + value + "\" "); |
||
117 | if (currentClause == null) { |
||
118 | currentClause = term.toString(); |
||
119 | } else {
|
||
120 | currentClause = "@" + operator + " " + currentClause + " " + term; |
||
121 | } |
||
122 | 3566 | jorpiell | } |
123 | |||
124 | /**
|
||
125 | * It adds a new query to the current query.
|
||
126 | *
|
||
127 | *
|
||
128 | * @param operator 'and' or 'or'. Relation between fields
|
||
129 | */
|
||
130 | protected void addCurrentClauseQuery(String operator) { |
||
131 | 2724 | jorpiell | if (currentClause != null) { |
132 | if (currentQuery == null) { |
||
133 | currentQuery = currentClause; |
||
134 | } else {
|
||
135 | 2985 | jorpiell | currentQuery = "@" + operator + " " + currentQuery + " " + currentClause; |
136 | 2724 | jorpiell | } |
137 | } |
||
138 | 3566 | jorpiell | } |
139 | |||
140 | /**
|
||
141 | * It returns the complete BER query
|
||
142 | *
|
||
143 | *
|
||
144 | * @return
|
||
145 | */
|
||
146 | 7400 | jorpiell | public String toString(String database) { |
147 | if ((database == null) || (database.equals(""))){ |
||
148 | database = "geo";
|
||
149 | } |
||
150 | return "@attrset bib-1 " + currentQuery; |
||
151 | 3566 | jorpiell | } |
152 | } |