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