root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / catalog / csw / messages / CSWAbstractMessages.java @ 15558
History | View | Annotate | Download (10.7 KB)
1 |
package es.gva.cit.catalog.csw.messages; |
---|---|
2 |
|
3 |
import org.apache.commons.httpclient.NameValuePair; |
4 |
import org.gvsig.i18n.Messages; |
5 |
|
6 |
import com.iver.utiles.swing.jcomboServer.ServerData; |
7 |
|
8 |
import es.gva.cit.catalog.csw.drivers.CSWCapabilities; |
9 |
import es.gva.cit.catalog.csw.drivers.profiles.CSWAbstractProfile; |
10 |
import es.gva.cit.catalog.csw.parsers.CSWConstants; |
11 |
import es.gva.cit.catalog.languages.FilterEncoding; |
12 |
import es.gva.cit.catalog.querys.CatalogQuery; |
13 |
import es.gva.cit.catalog.querys.Search; |
14 |
import es.gva.cit.catalog.utils.CatalogConstants; |
15 |
import es.gva.cit.catalog.utils.Strings; |
16 |
|
17 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
18 |
*
|
19 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
20 |
*
|
21 |
* This program is free software; you can redistribute it and/or
|
22 |
* modify it under the terms of the GNU General Public License
|
23 |
* as published by the Free Software Foundation; either version 2
|
24 |
* of the License, or (at your option) any later version.
|
25 |
*
|
26 |
* This program is distributed in the hope that it will be useful,
|
27 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29 |
* GNU General Public License for more details.
|
30 |
*
|
31 |
* You should have received a copy of the GNU General Public License
|
32 |
* along with this program; if not, write to the Free Software
|
33 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
34 |
*
|
35 |
* For more information, contact:
|
36 |
*
|
37 |
* Generalitat Valenciana
|
38 |
* Conselleria d'Infraestructures i Transport
|
39 |
* Av. Blasco Ib??ez, 50
|
40 |
* 46010 VALENCIA
|
41 |
* SPAIN
|
42 |
*
|
43 |
* +34 963862235
|
44 |
* gvsig@gva.es
|
45 |
* www.gvsig.gva.es
|
46 |
*
|
47 |
* or
|
48 |
*
|
49 |
* IVER T.I. S.A
|
50 |
* Salamanca 50
|
51 |
* 46005 Valencia
|
52 |
* Spain
|
53 |
*
|
54 |
* +34 963163400
|
55 |
* dac@iver.es
|
56 |
*/
|
57 |
/* CVS MESSAGES:
|
58 |
*
|
59 |
* $Id$
|
60 |
* $Log$
|
61 |
*
|
62 |
*/
|
63 |
/**
|
64 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
65 |
*/
|
66 |
public abstract class CSWAbstractMessages { |
67 |
private CSWCapabilities capabilities = null; |
68 |
private CatalogQuery query = null; |
69 |
private CSWAbstractProfile profile = null; |
70 |
|
71 |
/**
|
72 |
* @param profile
|
73 |
* The profile to create the query
|
74 |
*/
|
75 |
public CSWAbstractMessages(CSWAbstractProfile profile) {
|
76 |
super();
|
77 |
this.profile = profile;
|
78 |
} |
79 |
|
80 |
public static NameValuePair[] getHTTPGETCapabilities() { |
81 |
NameValuePair nvp1 = new NameValuePair("request", CSWConstants.OPERATION_GETCAPABILITIES); |
82 |
NameValuePair nvp2 = new NameValuePair("service", ServerData.SERVER_SUBTYPE_CATALOG_CSW); |
83 |
NameValuePair nvp3 = new NameValuePair("acceptFormats","text/xml"); |
84 |
return new NameValuePair[] { nvp1, nvp2, nvp3 }; |
85 |
} |
86 |
|
87 |
public static NameValuePair[] getHTTPGETDescribeRecord(String version) { |
88 |
NameValuePair nvp1 = new NameValuePair("request", CSWConstants.OPERATION_DESCRIBERECORD); |
89 |
NameValuePair nvp2 = new NameValuePair("service", ServerData.SERVER_SUBTYPE_CATALOG_CSW); |
90 |
NameValuePair nvp3 = new NameValuePair("version", version); |
91 |
return new NameValuePair[] { nvp1, nvp2, nvp3 }; |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Creates and returns the GetRecords request
|
96 |
* @param query
|
97 |
* @param firstRecord
|
98 |
* @return
|
99 |
*/
|
100 |
public String getHTTPPostGetRecordsMessage(CSWCapabilities capabilities, CatalogQuery query, ServerData serverData, int firstRecord) { |
101 |
this.capabilities = capabilities;
|
102 |
this.query = query;
|
103 |
profile.setServerData(serverData); |
104 |
StringBuffer buffer = new StringBuffer(); |
105 |
buffer.append(createGetRecordsHeader(firstRecord)); |
106 |
return buffer.toString();
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* Create the GetRecords header.
|
111 |
* @param firstRecord
|
112 |
* @return
|
113 |
*/
|
114 |
private String createGetRecordsHeader(int firstRecord){ |
115 |
StringBuffer buffer = new StringBuffer(); |
116 |
buffer.append(CatalogConstants.XML_HEADER_ENCODING); |
117 |
buffer.append("<" + CSWConstants.CSW_NAMESPACE +
|
118 |
":" + CSWConstants.CSW_GET_RECORDS);
|
119 |
buffer.append(" " + CSWConstants.CSW_SERVICE + "=\"" + ServerData.SERVER_SUBTYPE_CATALOG_CSW + "\" "); |
120 |
buffer.append(CSWConstants.CSW_VERSION + "=\"" + capabilities.getVersion() + "\" "); |
121 |
buffer.append(CatalogConstants.XML_NS + "=\"" +CSWConstants.CSW_NAMESPACE_URI + "\" "); |
122 |
buffer.append(CatalogConstants.XML_NS + ":" + CSWConstants.CSW_NAMESPACE +
|
123 |
"=\"" + CSWConstants.CSW_NAMESPACE_URI + "\" "); |
124 |
buffer.append(CatalogConstants.XML_NS + ":" + CSWConstants.OGC_NAMESPACE +
|
125 |
"=\"" + CSWConstants.OGC_NAMESPACE_URI + "\" "); |
126 |
buffer.append(CatalogConstants.XML_NS + ":" + CSWConstants.GML_NAMESPACE +
|
127 |
"=\"" + CSWConstants.GML_NAMESPACE_URI + "\" "); |
128 |
buffer.append(CSWConstants.CSW_START_POSITION + "='" + firstRecord + "' "); |
129 |
buffer.append(CSWConstants.CSW_MAX_RECORDS + "='10' ");
|
130 |
if (capabilities.getOutputFormat() != null){ |
131 |
buffer.append(CSWConstants.CSW_OUTPUTFORMAT + "=\"" + capabilities.getOutputFormat() + "\" "); |
132 |
} |
133 |
if (getOutputSchema(capabilities.getOutputSchema()) != null){ |
134 |
buffer.append(CSWConstants.CSW_OUTPUTSCHEMA + "=\"" + getOutputSchema(capabilities.getOutputSchema()) + "\" "); |
135 |
}else{
|
136 |
buffer.append(CSWConstants.CSW_OUTPUTSCHEMA + "=\"csw:IsoRecord\" ");
|
137 |
} |
138 |
buffer.append("resultType=\"" +
|
139 |
getResultType(capabilities.getResultType()) + "\">");
|
140 |
buffer.append(createGetRecordsQuery()); |
141 |
buffer.append("</" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.OPERATION_GETRECORDS + ">"); |
142 |
return buffer.toString();
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Returns a common reslut type if the getCapabilities doesn't have
|
147 |
* one. Sometimes it works.
|
148 |
*
|
149 |
*
|
150 |
* @return Just one String
|
151 |
* @param resultType The array of result types parsed.
|
152 |
*/
|
153 |
private String getResultType(String[] resultType) { |
154 |
if (resultType == null) |
155 |
return "results"; |
156 |
|
157 |
for (int i=0 ; i<resultType.length ; i++){ |
158 |
|
159 |
} |
160 |
return resultType[0]; |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Returns the OutputSchema. If the ISO19115 is supported,
|
165 |
* we prefer this
|
166 |
* @param OutputFormat The array of outputFormats parsed.
|
167 |
* @return Just one String
|
168 |
* @param outputSchemas
|
169 |
*/
|
170 |
private String getOutputSchema(String[] outputSchemas) { |
171 |
if (outputSchemas == null){ |
172 |
return null; |
173 |
} |
174 |
return outputSchemas[0]; |
175 |
} |
176 |
|
177 |
/**
|
178 |
* @return the Query xml sub tree of the GetRecords
|
179 |
* operation
|
180 |
*/
|
181 |
private String createGetRecordsQuery(){ |
182 |
StringBuffer buffer = new StringBuffer(); |
183 |
buffer.append("<" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.QUERY + " "); |
184 |
if (capabilities.getTypeNames() != null){ |
185 |
buffer.append(CSWConstants.TYPENAMES + "=\"" +
|
186 |
Strings.getBlankSeparated(capabilities.getTypeNames()) + "\"");
|
187 |
} |
188 |
buffer.append(">");
|
189 |
buffer.append(getElementSetNameLabel(query.getService())); |
190 |
buffer.append(createGetRecordsConstraint()); |
191 |
buffer.append("</" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.QUERY + ">"); |
192 |
return buffer.toString();
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Create and return the ElementName and the ElementSetName tags
|
197 |
* @param searchType
|
198 |
* @return
|
199 |
*/
|
200 |
private String getElementSetNameLabel(Search searchType) { |
201 |
StringBuffer buffer = new StringBuffer(); |
202 |
buffer.append("<" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.ELEMENTSETNAME + ">"); |
203 |
buffer.append(CSWConstants.FULL); |
204 |
buffer.append("</" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.ELEMENTSETNAME + ">"); |
205 |
if (profile.getElementName() != null){ |
206 |
buffer.append("<" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.ELEMENTNAME + ">"); |
207 |
buffer.append(profile.getElementName()); |
208 |
buffer.append("</" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.ELEMENTNAME + ">"); |
209 |
} |
210 |
return buffer.toString();
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* @return the Constarint xml sub tree of the GetRecords
|
215 |
* operation
|
216 |
*/
|
217 |
protected String createGetRecordsConstraint(){ |
218 |
StringBuffer buffer = new StringBuffer(); |
219 |
buffer.append("<" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.CONSTRAINT); |
220 |
buffer.append(" " + CSWConstants.VERSION + "='" + getContraintVersion() + "'>"); |
221 |
buffer.append(createFilterEncoding()); |
222 |
buffer.append("</" + CSWConstants.CSW_NAMESPACE + ":" + CSWConstants.CONSTRAINT + ">"); |
223 |
return buffer.toString();
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* @return the constraint version
|
228 |
*/
|
229 |
protected abstract String getContraintVersion(); |
230 |
|
231 |
/**
|
232 |
* Creates the filter encoding query
|
233 |
* @param query
|
234 |
* @return
|
235 |
*/
|
236 |
private String createFilterEncoding(){ |
237 |
FilterEncoding filter = new FilterEncoding();
|
238 |
if (query.getTitle() != null){ |
239 |
filter.addClauses(profile.getTitle(), |
240 |
query.getTitle(), |
241 |
query.getTitleFilter(), |
242 |
FilterEncoding.PROPERTY_IS_LIKE, |
243 |
FilterEncoding.TYPE_LITERAL, |
244 |
FilterEncoding.AND); |
245 |
} |
246 |
if (query.isMinimized()){
|
247 |
if (query.getAbstract() != null) { |
248 |
filter.addClauses(profile.getAbstract(), |
249 |
query.getAbstract(), |
250 |
FilterEncoding.ANY_WORDS, |
251 |
FilterEncoding.PROPERTY_IS_LIKE, |
252 |
FilterEncoding.TYPE_LITERAL, |
253 |
FilterEncoding.OR); |
254 |
} |
255 |
}else{
|
256 |
if (query.getAbstract() != null) { |
257 |
filter.addClauses(profile.getAbstract(), |
258 |
query.getAbstract(), |
259 |
FilterEncoding.ANY_WORDS); |
260 |
} |
261 |
if (query.getThemeKey() != null) { |
262 |
filter.addClauses(profile.getKeywords(), query.getThemeKey(), |
263 |
FilterEncoding.ANY_WORDS); |
264 |
|
265 |
} |
266 |
if ((query.getTopic() != null) && (!query.getTopic().equals(Messages.getText("cathegoryAny")))) { |
267 |
filter.addClauses(profile.getTopic(), profile.getTopicValue(query.getTopic()), |
268 |
FilterEncoding.EXACT_WORDS); |
269 |
} |
270 |
if (query.getScale() != null) { |
271 |
filter.addClauses(profile.getScale(), query.getScale(), |
272 |
FilterEncoding.EXACT_WORDS); |
273 |
} |
274 |
if (query.getProvider() != null) { |
275 |
filter.addClauses(profile.getProvider(), |
276 |
filter.getWildCard() + query.getProvider() + filter.getWildCard(), |
277 |
FilterEncoding.EXACT_WORDS, |
278 |
FilterEncoding.PROPERTY_IS_EQUALS_TO, |
279 |
FilterEncoding.TYPE_LITERAL, |
280 |
FilterEncoding.AND); |
281 |
} |
282 |
|
283 |
if (query.getDateFrom() != null) { |
284 |
filter.addClauses(profile.getDateFrom(), query.getDateFrom(), |
285 |
FilterEncoding.EXACT_WORDS, |
286 |
FilterEncoding.PROPERTY_IS_GREATER_THAN, |
287 |
FilterEncoding.TYPE_LITERAL, |
288 |
FilterEncoding.AND); |
289 |
} |
290 |
if (query.getDateTo() != null) { |
291 |
filter.addClauses(profile.getDateTo(), query.getDateTo(), |
292 |
FilterEncoding.EXACT_WORDS, |
293 |
FilterEncoding.PROPERTY_IS_LESS_THAN, |
294 |
FilterEncoding.TYPE_LITERAL, |
295 |
FilterEncoding.AND); |
296 |
} |
297 |
} |
298 |
if ((query.getCoordenates() != null) && (query.isCoordinatesClicked())){ |
299 |
filter.addBoundingBox(query.getCoordenates(), profile.getCoordinates(), |
300 |
getCoordinatesOption(query.getCoordenatesFilter())); |
301 |
|
302 |
} |
303 |
return filter.toString();
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* This function returns true only when the user has choosen the
|
308 |
* "Fully Outside Of" of the coordinates option.
|
309 |
* @param coordinatesOption
|
310 |
* @return
|
311 |
*/
|
312 |
private boolean getCoordinatesOption(String coordinatesOption) { |
313 |
if ((coordinatesOption.equals(Messages.getText("coordinatesEqual"))) || |
314 |
(coordinatesOption.equals(Messages.getText("coordinatesContains"))) ||
|
315 |
(coordinatesOption.equals(Messages.getText("coordinatesEnclose"))))
|
316 |
return false; |
317 |
|
318 |
return true; |
319 |
} |
320 |
} |