svn-gvsig-desktop / branches / v10 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / csw / filters / CSWFilter.java @ 8604
History | View | Annotate | Download (8.42 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.catalogClient.csw.filters; |
43 |
import org.gvsig.i18n.Messages; |
44 |
|
45 |
import es.gva.cit.catalogClient.csw.drivers.CSWMessages; |
46 |
import es.gva.cit.catalogClient.filters.AbstractFilter; |
47 |
import es.gva.cit.catalogClient.filters.AdditionalClauses; |
48 |
import es.gva.cit.catalogClient.languages.FilterEncoding; |
49 |
import es.gva.cit.catalogClient.querys.Query; |
50 |
import es.gva.cit.catalogClient.schemas.DublinCoreSchema; |
51 |
import es.gva.cit.catalogClient.schemas.EbRIMSchema; |
52 |
import es.gva.cit.catalogClient.schemas.ISO19115Schema; |
53 |
import es.gva.cit.catalogClient.schemas.ISchemas; |
54 |
import es.gva.cit.catalogClient.schemas.Schemas; |
55 |
import es.gva.cit.catalogClient.utils.Strings; |
56 |
|
57 |
/**
|
58 |
* This class creates a CSW query. It can create querys using the Filter Encoding Language with ebXML or ISO19115/19119 profiles
|
59 |
*
|
60 |
*
|
61 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
62 |
*/
|
63 |
public class CSWFilter extends AbstractFilter { |
64 |
/**
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
private ISchemas equiv = null; |
69 |
|
70 |
/**
|
71 |
*
|
72 |
*
|
73 |
*/
|
74 |
public CSWFilter() {
|
75 |
super();
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* Return a CQL-Text query
|
80 |
*
|
81 |
*
|
82 |
* @param query
|
83 |
* @return String
|
84 |
* @param profile
|
85 |
*/
|
86 |
public String getQuery(Query query, String profile) { |
87 |
String pregunta = null; |
88 |
setProfile(profile); |
89 |
FilterEncoding filter = new FilterEncoding("ogc:", "*", "?", "\\", |
90 |
"xmlns:ogc=\"http://www.opengis.net/ogc\"");
|
91 |
|
92 |
addAdditionalClauses(filter); |
93 |
|
94 |
if (query.getTitle() != null) { |
95 |
if (CSWMessages.getUrl().getHost().equals("laits.gmu.edu")){ |
96 |
if (query.getSearchType() == Query.SEARCH_DATA){ |
97 |
StringBuffer buffer = new StringBuffer(); |
98 |
buffer.append("<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\">");
|
99 |
buffer.append("<ogc:PropertyIsLike wildCard=\"*\" singleChar=\"?\" escapeChar=\"\\\">");
|
100 |
buffer.append("<ogc:PropertyName>/DataGranule/name</ogc:PropertyName>");
|
101 |
buffer.append("<ogc:Literal>*" + query.getTitle() + "*</ogc:Literal>"); |
102 |
buffer.append("</ogc:PropertyIsLike>");
|
103 |
buffer.append("</ogc:Filter>");
|
104 |
return buffer.toString();
|
105 |
}else{
|
106 |
StringBuffer buffer = new StringBuffer(); |
107 |
buffer.append("<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\">");
|
108 |
buffer.append("<ogc:And>");
|
109 |
buffer.append("<ogc:PropertyIsEqualTo>");
|
110 |
buffer.append("<ogc:PropertyName>/Service/@id</ogc:PropertyName>");
|
111 |
buffer.append("<ogc:PropertyName>/Classification/@classifiedObject</ogc:PropertyName>");
|
112 |
buffer.append("</ogc:PropertyIsEqualTo>");
|
113 |
buffer.append("<ogc:PropertyIsEqualTo>");
|
114 |
buffer.append("<ogc:PropertyName>/Classification/@classificationNode</ogc:PropertyName>");
|
115 |
buffer.append("<ogc:PropertyName>/ClassificationNode/@id</ogc:PropertyName>");
|
116 |
buffer.append("</ogc:PropertyIsEqualTo>");
|
117 |
buffer.append("<ogc:PropertyIsEqualTo>");
|
118 |
buffer.append("<ogc:PropertyName>/ClassificationNode/@code</ogc:PropertyName>");
|
119 |
buffer.append("<ogc:Literal>" + query.getTitle() + "</ogc:Literal>"); |
120 |
buffer.append("</ogc:PropertyIsEqualTo>");
|
121 |
buffer.append("</ogc:And>");
|
122 |
buffer.append("</ogc:Filter>");
|
123 |
return buffer.toString();
|
124 |
} |
125 |
}else{
|
126 |
filter.addClauses(equiv.getTitle(), equiv.getTitleValue(query.getTitle(),query.getTitleFilter()), query.getTitleFilter(), |
127 |
"PropertyIsLike", "L", "And"); |
128 |
} |
129 |
} |
130 |
|
131 |
if (query.isMinimized()){
|
132 |
if (query.getAbstract() != null) { |
133 |
filter.addClauses(equiv.getAbstract(), Strings.addAsteriscsFromAnArray(query.getAbstract()), |
134 |
"Y", "PropertyIsLike", "L", "Or"); |
135 |
} |
136 |
}else{
|
137 |
if (query.getAbstract() != null) { |
138 |
filter.addClauses(equiv.getAbstract(), Strings.addAsteriscsFromAnArray(query.getAbstract()), |
139 |
"Y", "PropertyIsLike", "L", "And"); |
140 |
} |
141 |
|
142 |
if (query.getThemeKey() != null) { |
143 |
filter.addClauses(equiv.getThemeKey(), query.getThemeKey(), "Y",
|
144 |
"PropertyIsLike", "L", "And"); |
145 |
} |
146 |
if ((query.getTopic() != null) && (!query.getTopic().equals(Messages.getText("cathegoryAny")))) { |
147 |
filter.addClauses(equiv.getTopic(), equiv.getTopicValue(query.getTopic()), |
148 |
"E", "PropertyIsEqualTo", "L", "And"); |
149 |
} |
150 |
/*
|
151 |
if (this.getScale() != null) {
|
152 |
query.addClauses(equiv.getScale(), this.getScale(), "E");
|
153 |
}
|
154 |
*/
|
155 |
|
156 |
if (query.getProvider() != null) { |
157 |
filter.addClauses(equiv.getProvider(), equiv.getProviderValue(query.getProvider()), |
158 |
"E", "PropertyIsEqualTo" , "L", "And"); |
159 |
} |
160 |
|
161 |
if (query.getDateFrom() != null) { |
162 |
filter.addClauses(equiv.getDateFrom(), query.getDateFrom(), "E", "PropertyIsGeaterThan" ,"L", "And"); |
163 |
} |
164 |
if (query.getDateTo() != null) { |
165 |
filter.addClauses(equiv.getDateTo(), query.getDateTo(), "E", "PropertyIsLessThan", "L", "And"); |
166 |
} |
167 |
} |
168 |
if ((query.getCoordenates() != null) && (query.isCoordinatesClicked())){ |
169 |
filter.addBoundingBox(query.getCoordenates(), equiv.getCoordinates(), getCoordinatesOption(query.getCoordenatesFilter())); |
170 |
|
171 |
} |
172 |
pregunta = filter.toString(); |
173 |
return pregunta;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* This function returns true only when the user has choosen the
|
178 |
* "Fully Outside Of" of the coordinates option.
|
179 |
*
|
180 |
*
|
181 |
* @return
|
182 |
* @param translator
|
183 |
* @param coordinatesOption
|
184 |
*/
|
185 |
public boolean getCoordinatesOption(String coordinatesOption) { |
186 |
if ((coordinatesOption.equals(Messages.getText("coordinatesEqual"))) || |
187 |
(coordinatesOption.equals(Messages.getText("coordinatesContains"))) ||
|
188 |
(coordinatesOption.equals(Messages.getText("coordinatesEnclose"))))
|
189 |
return false; |
190 |
|
191 |
return true; |
192 |
} |
193 |
|
194 |
/**
|
195 |
* It sets the CSW profile
|
196 |
*
|
197 |
*
|
198 |
* @param profile
|
199 |
*/
|
200 |
public void setProfile(String profile) { |
201 |
if (profile.equals(Schemas.ISO19115)) {
|
202 |
setEquiv(new ISO19115Schema());
|
203 |
} else if (profile.equals(Schemas.DUBLINCORE)) |
204 |
setEquiv(new DublinCoreSchema());
|
205 |
else{
|
206 |
setEquiv(new EbRIMSchema());
|
207 |
} |
208 |
} |
209 |
|
210 |
/**
|
211 |
* It adds the aditional clauses (for each profile)
|
212 |
*
|
213 |
*
|
214 |
* @param filter
|
215 |
*/
|
216 |
public void addAdditionalClauses(FilterEncoding filter) { |
217 |
AdditionalClauses[] ac = equiv.getAdditionalClauses(null); |
218 |
for (int i = 0; i < ac.length; i++) |
219 |
filter.addClauses(ac[i].getProperty(), ac[i].getValue(), |
220 |
ac[i].getConcorancia(), ac[i].getRelationship(), ac[i].getType(),"And");
|
221 |
} |
222 |
|
223 |
/**
|
224 |
*
|
225 |
*
|
226 |
*
|
227 |
* @return Returns the equiv.
|
228 |
*/
|
229 |
public ISchemas getEquiv() {
|
230 |
return equiv;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
*
|
235 |
*
|
236 |
*
|
237 |
* @param equiv The equiv to set.
|
238 |
*/
|
239 |
public void setEquiv(ISchemas equiv) { |
240 |
this.equiv = equiv;
|
241 |
} |
242 |
} |