Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / languages / BasicEncodingRules.java @ 2985

History | View | Annotate | Download (4.66 KB)

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

    
43
import java.util.Iterator;
44

    
45
/**
46
 * This class is used to create a Basic Encoding Rules (BER) query. 
47
 * See the specification for more information.
48
 * 
49
 * @see http://www.loc.gov/z3950/agency/
50
 * @author Jorge Piera Llodra (piera_jor@gva.es)
51
 */
52
public class BasicEncodingRules extends AbstractGeneralLanguage {
53
    /**
54
     * It adds a new clause to the query 
55
     * @param use
56
     * It is a number that represent an attribute (4=Title,62=abstract,...)
57
     * @param structure
58
     * It defines the attribute type (1=Phrase,2=wors,...)
59
     * @param relation
60
     * Relation between the attribute and the query (1=LessThan,3=equal,...)
61
     * @param line
62
     * String with the user introduced value 
63
     * @param concordancia
64
     * Relationship between different words of the same field (more than one words)
65
     * E,A o Y --> Exact, All, anY
66
     * @param operator
67
     * Relationship between fields (title, abstract)
68
     * 'and' or 'or'
69
     */
70
    public void addClauses(String use, String structure, String relation,
71
        String line, String concordancia,String operator) {
72
        currentClause = null;
73

    
74
        //Cut the words
75
        Iterator values = parseValues(line, concordancia);
76
        addClauses(use, structure, relation, values, concordancia,operator);
77
    }
78
    
79
    /**
80
     * It realize the same function than the "addClauses(String use, String structure
81
     *        String relation,String line, String concordancia)" function, but the words 
82
     *  to find are in a vector. 
83
     * @param use
84
     * @param structure
85
     * @param relation
86
     * @param values
87
     * @param concordancia
88
     * @param operator
89
     * 
90
     */
91
    public void addClauses(String use, String structure, String relation,
92
        Iterator values, String concordancia, String operator) {
93
        while (values.hasNext())
94
            addTerm(use, structure, relation, (String) values.next(),
95
                getOperator(concordancia));
96

    
97
        addCurrentClauseQuery(operator);
98
    }
99

    
100
    /**
101
     * Add a new serch field
102
     * @param use
103
     * BER use
104
     * @param structure
105
     * BER structure
106
     * @param relation
107
     * BER relation
108
     * @param value
109
     * Filed value
110
     * @param operator
111
     * "and" or "or"
112
     */
113
    private void addTerm(String use, String structure, String relation,
114
        String value, String operator) {
115
        StringBuffer term = new StringBuffer();
116

    
117
        if (use != null) {
118
            term.append("@attr 1=" + use + " ");
119
        }
120

    
121
        if (structure != null) {
122
            term.append("@attr 4=" + structure + " ");
123
        }
124

    
125
        if (relation != null) {
126
            term.append("@attr 2=" + relation + " ");
127
        }
128

    
129
        term.append("\"" + value + "\" ");
130

    
131
        if (currentClause == null) {
132
            currentClause = term.toString();
133
        } else {
134
            currentClause = "@" + operator + " " + currentClause + " " + term;
135
        }
136
    }
137
    
138
    /**
139
     * It adds a new query to the current query.
140
     *
141
     * @param operator
142
     * 'and' or 'or'. Relation between fields
143
     */
144
        
145
    protected void addCurrentClauseQuery(String operator) {
146
        if (currentClause != null) {
147
            if (currentQuery == null) {
148
                currentQuery = currentClause;
149
            } else {
150
                currentQuery = "@" + operator + " " + currentQuery + " " + currentClause;
151
            }
152
        }
153
    }
154
    
155
   /**
156
    * It returns the complete BER query 
157
    */
158
    public String toString() {
159
        return "@attrset geo " + currentQuery;
160
    }
161
}