svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / csw / filters / CSWFilter.java @ 3510
History | View | Annotate | Download (6.06 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.csw.filters; |
42 |
|
43 |
import es.gva.cit.catalogClient.filters.AbstractFilter; |
44 |
import es.gva.cit.catalogClient.filters.AdditionalClauses; |
45 |
import es.gva.cit.catalogClient.languages.FilterEncoding; |
46 |
import es.gva.cit.catalogClient.querys.Query; |
47 |
import es.gva.cit.catalogClient.schemas.DublinCoreSchema; |
48 |
import es.gva.cit.catalogClient.schemas.EbRIMSchema; |
49 |
import es.gva.cit.catalogClient.schemas.ISchemas; |
50 |
import es.gva.cit.catalogClient.schemas.ISO19115Schema; |
51 |
import es.gva.cit.catalogClient.schemas.Schemas; |
52 |
import es.gva.cit.catalogClient.utils.Strings; |
53 |
|
54 |
|
55 |
/**
|
56 |
* This class creates a CSW query. It can create querys using the
|
57 |
* Filter Encoding Language with ebXML or ISO19115/19119 profiles
|
58 |
*
|
59 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
60 |
*/
|
61 |
public class CSWFilter extends AbstractFilter { |
62 |
private ISchemas equiv = null; |
63 |
|
64 |
public CSWFilter(Query query) { |
65 |
super(query);
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* Return a CQL-Text query
|
70 |
*
|
71 |
* @return String
|
72 |
*/
|
73 |
public String getQuery(String profile) { |
74 |
String pregunta = null; |
75 |
|
76 |
setProfile(profile); |
77 |
|
78 |
FilterEncoding filter = new FilterEncoding("ogc:", "*", "?", "\\", |
79 |
"xmlns:ogc=\"http://www.opengis.net/ogc\"");
|
80 |
|
81 |
addAdditionalClauses(filter); |
82 |
|
83 |
if (query.getTitle() != null) { |
84 |
filter.addClauses(equiv.getTitle(), equiv.getTitleValue(query.getTitle(),query.getTitleFilter()), query.getTitleFilter(), |
85 |
"PropertyIsLike", "L", "And"); |
86 |
} |
87 |
|
88 |
String operator = "And"; |
89 |
|
90 |
if (query.isMinimized())
|
91 |
operator = "Or";
|
92 |
|
93 |
|
94 |
if (query.getAbstract() != null) { |
95 |
filter.addClauses(equiv.getAbstract(), Strings.addAsteriscsFromAnArray(query.getAbstract()), |
96 |
"Y", "PropertyIsLike", "L", operator); |
97 |
} |
98 |
|
99 |
if (query.getThemeKey() != null) { |
100 |
filter.addClauses(equiv.getThemeKey(), query.getThemeKey(), "Y",
|
101 |
"PropertyIsLike", "L", "And"); |
102 |
} |
103 |
|
104 |
if ((query.getTopic() != null) && (!query.getTopic().equals(query.getTranslator().getText("cathegoryAny")))) { |
105 |
filter.addClauses(equiv.getTopic(), equiv.getTopicValue(query.getTopic()), |
106 |
"E", "PropertyIsEqualTo", "L", "And"); |
107 |
} |
108 |
|
109 |
/*
|
110 |
if (this.getScale() != null) {
|
111 |
query.addClauses(equiv.getScale(), this.getScale(), "E");
|
112 |
}
|
113 |
*/
|
114 |
|
115 |
if (query.getProvider() != null) { |
116 |
filter.addClauses(equiv.getProvider(), equiv.getProviderValue(query.getProvider()), |
117 |
"E", "PropertyIsEqualTo" , "L", "And"); |
118 |
} |
119 |
|
120 |
if (query.getDateFrom() != null) { |
121 |
filter.addClauses(equiv.getDateFrom(), query.getDateFrom(), "E", "PropertyIsGeaterThan" ,"L", "And"); |
122 |
} |
123 |
|
124 |
if (query.getDateTo() != null) { |
125 |
filter.addClauses(equiv.getDateTo(), query.getDateTo(), "E", "PropertyIsLessThan", "L", "And"); |
126 |
} |
127 |
|
128 |
if ((query.getCoordenates() != null) && (query.isCoordinatesClicked())){ |
129 |
filter.addBoundingBox(query.getCoordenates(), equiv.getCoordinates(), getCoordinatesOption(query.getCoordenatesFilter())); |
130 |
} |
131 |
|
132 |
pregunta = filter.toString(); |
133 |
|
134 |
return pregunta;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* This function returns true only when the user has choosen the
|
139 |
* "Fully Outside Of" of the coordinates option.
|
140 |
* @param coordinatesOption
|
141 |
* @return
|
142 |
*/
|
143 |
public boolean getCoordinatesOption(String coordinatesOption){ |
144 |
if ((coordinatesOption.equals(query.getTranslator().getText("coordinatesEqual"))) || |
145 |
(coordinatesOption.equals(query.getTranslator().getText("coordinatesContains"))) ||
|
146 |
(coordinatesOption.equals(query.getTranslator().getText("coordinatesEnclose"))))
|
147 |
return false; |
148 |
|
149 |
return true; |
150 |
} |
151 |
|
152 |
/**
|
153 |
* It sets the CSW profile
|
154 |
* @param profile
|
155 |
*/
|
156 |
public void setProfile(String profile) { |
157 |
if (profile.equals(Schemas.ISO19115)) {
|
158 |
setEquiv(new ISO19115Schema());
|
159 |
} else if (profile.equals(Schemas.DUBLINCORE)) |
160 |
setEquiv(new DublinCoreSchema());
|
161 |
else{
|
162 |
setEquiv(new EbRIMSchema());
|
163 |
} |
164 |
} |
165 |
|
166 |
/**
|
167 |
* It adds the aditional clauses (for each profile)
|
168 |
* @param query
|
169 |
*/
|
170 |
public void addAdditionalClauses(FilterEncoding filter) { |
171 |
AdditionalClauses[] ac = equiv.getAdditionalClauses(null); |
172 |
|
173 |
for (int i = 0; i < ac.length; i++) |
174 |
filter.addClauses(ac[i].getProperty(), ac[i].getValue(), |
175 |
ac[i].getConcorancia(), ac[i].getRelationship(), ac[i].getType(),"And");
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* @return Returns the equiv.
|
180 |
*/
|
181 |
public ISchemas getEquiv() {
|
182 |
return equiv;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* @param equiv The equiv to set.
|
187 |
*/
|
188 |
public void setEquiv(ISchemas equiv) { |
189 |
this.equiv = equiv;
|
190 |
} |
191 |
|
192 |
|
193 |
|
194 |
|
195 |
} |