Statistics
| Revision:

root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / adl / filters / ADLFilter.java @ 15558

History | View | Annotate | Download (3.97 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.gazetteer.adl.filters;
43
import java.util.Vector;
44

    
45
import es.gva.cit.catalog.utils.Strings;
46
import es.gva.cit.gazetteer.adl.languages.AdlLanguage;
47
import es.gva.cit.gazetteer.filters.AbstractFilter;
48
import es.gva.cit.gazetteer.querys.GazetteerQuery;
49

    
50
/**
51
 * This class create a query using the gazetteer query language used by
52
 * ADL
53
 * 
54
 * 
55
 * @author Jorge Piera Llodra (piera_jor@gva.es)
56
 * @see http://www.alexandria.ucsb.edu/gazetteer/protocol/
57
 */
58
public class ADLFilter extends AbstractFilter {
59
        private boolean withAccents = true;
60
/**
61
 * 
62
 * 
63
 */
64
    public  ADLFilter(boolean withAccents) {        
65
        super();
66
        this.withAccents = withAccents;
67
    } 
68

    
69
/**
70
 * 
71
 * 
72
 * 
73
 * @return 
74
 * @param query 
75
 */
76
    public String getQuery(GazetteerQuery query) {        
77
        AdlLanguage filter = new AdlLanguage();
78
                
79
        if (query.getName() != null) {
80
                if (query.getOptions().getSearch().isWithAccents()){
81
                        Vector v = Strings.allWordForms(query.getName(),withAccents);
82
                        for (int i=0 ; i<v.size() ; i++){
83
                                String str = (String)v.get(i);
84
                                filter.addClauses("title",str,query.getNameFilter(),"or");
85
                        }                        
86
                }else{
87
                        filter.addClauses("title",query.getName(),query.getNameFilter(),"and");
88
                }                
89
        }  
90
                
91
        if ((query.getFeatures() != null) && (query.getFeatures().length != 0)){
92
            if (!(query.getFeatures()[0].getName().equals("ThesaurusRoot")))
93
                filter.addClauses("thesaurus",query.getFeatures()[0].getName(),"E","and");
94
        }
95
        
96
        if ((query.getCoordinates() != null) && (query.isCoordinatesClicked())){
97
            String sNorth = query.getCoordinates().getUly();
98
            String sWest = query.getCoordinates().getUlx();
99
            String sSouth = query.getCoordinates().getBry();
100
            String sEast = query.getCoordinates().getBrx();
101
            String sCoordinates = sWest + "," + sSouth + " " + sEast + "," + sNorth;
102
            
103
            filter.addClauses("coordinates",sCoordinates,"E",getRelation(query.getCoordinatesFilter()));
104
        }
105
              
106
        return filter.toString();
107
    } 
108

    
109
/**
110
 * Return a value for the option of the 'Coordenates Filter'
111
 * 
112
 * @param relation String in the combo. Possible values:
113
 * encloses
114
 * overlaps
115
 * fullyOutsideOf
116
 * equals
117
 * 
118
 * @return String
119
 * Possible values:
120
 * overlaps
121
 * within
122
 * contains
123
 * @param relacion 
124
 */
125
    private static String getRelation(String relacion) {        
126
        if (relacion.equals("igual")) {
127
            return "contains";
128
        }
129
        if (relacion.equals("contiene")) {
130
            return "contains";
131
        }
132
        if (relacion.equals("incluye")) {
133
            return "within";
134
            
135
        } else {
136
            return "overlaps";
137
        }
138
    } 
139
 }