www.pudn.com > gvSIG-1_1-rc1-src.zip > CSWMessages.java
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
*
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
*
* For more information, contact:
*
* Generalitat Valenciana
* Conselleria d'Infraestructures i Transport
* Av. Blasco Ibáñez, 50
* 46010 VALENCIA
* SPAIN
*
* +34 963862235
* gvsig@gva.es
* www.gvsig.gva.es
*
* or
*
* IVER T.I. S.A
* Salamanca 50
* 46005 Valencia
* Spain
*
* +34 963163400
* dac@iver.es
*/
package es.gva.cit.catalogClient.csw.drivers;
import java.net.URL;
import es.gva.cit.catalogClient.csw.filters.CSWFilter;
import es.gva.cit.catalogClient.drivers.IProtocolMessages;
import es.gva.cit.catalogClient.protocols.SOAPProtocol;
import es.gva.cit.catalogClient.querys.Query;
import es.gva.cit.catalogClient.schemas.Schemas;
import es.gva.cit.catalogClient.utils.Strings;
import org.apache.commons.httpclient.NameValuePair;
/**
* This class has methods that return the CSW opearions messages.
*
*
* @author Jorge Piera Llodra (piera_jor@gva.es)
*/
public class CSWMessages implements IProtocolMessages {
private static URL url = null;
/**
*
*
*/
private CSWCatalogServiceDriver driver;
/**
*
*
*
* @param driver
*/
public CSWMessages(CSWCatalogServiceDriver driver) {
this.driver = driver;
}
/* (non-Javadoc)
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPGETCapabilities()
*/
/**
*
*
*
* @return
* @param upper
*/
public NameValuePair[] getHTTPGETCapabilities(boolean upper) {
NameValuePair nvp1 = null;
if (upper){
nvp1 = new NameValuePair("request", "GetCapabilities");
}else{
nvp1 = new NameValuePair("request", "getCapabilities");
}
NameValuePair nvp2 = new NameValuePair("service", driver.getService());
NameValuePair nvp3 = new NameValuePair("acceptversion", driver.getVersion());
return new NameValuePair[] { nvp1, nvp2, nvp3 };
}
/* (non-Javadoc)
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPGETDescribeRecords()
*/
/**
*
*
*
* @return
*/
public NameValuePair[] getHTTPGETDescribeRecords() {
NameValuePair nvp1 = new NameValuePair("request", "describeRecord");
NameValuePair nvp2 = new NameValuePair("version", driver.getVersion());
NameValuePair nvp3 = new NameValuePair("outputformat",
driver.getOutputFormat());
NameValuePair nvp4 = new NameValuePair("schemalanguage", "XMLSCHEMA");
NameValuePair nvp5 = new NameValuePair("typename",
driver.getTypeNames()[0]);
NameValuePair nvp6 = new NameValuePair("namespace",
"csw:http://www.opengis.org/csw");
return new NameValuePair[] { nvp1, nvp2, nvp3, nvp4, nvp5, nvp6 };
}
/* (non-Javadoc)
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPGETRecords(es.gva.cit.catalogClient.querys.Query, int)
*/
/**
*
*
*
* @return
* @param query
* @param firstRecord
*/
public NameValuePair[] getHTTPGETRecords(Query query, int firstRecord) {
NameValuePair nvp1 = new NameValuePair("request", "GetRecords");
NameValuePair nvp2 = new NameValuePair("version", driver.getVersion());
NameValuePair nvp3 = new NameValuePair("service", "CSW");
NameValuePair nvp4 = new NameValuePair("TypeNames",Strings.getComaSeparated(driver.getTypeNames()));
NameValuePair nvp5 = new NameValuePair("outputschema",
driver.getOutputSchema()[0]);
NameValuePair nvp6 = new NameValuePair("namespace",
"csw:http://www.opengis.org/csw");
NameValuePair nvp7 = new NameValuePair("elementsetname", "full");
NameValuePair nvp8 = new NameValuePair("constraintlanguage", "FILTER");
NameValuePair nvp9 = new NameValuePair("constraint",
new CSWFilter().getQuery(query,driver.getServerProfile()));
return new NameValuePair[] {
nvp1, nvp2, nvp3, nvp4, nvp5, nvp6, nvp7, nvp8, nvp9
};
}
/* (non-Javadoc)
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPPOSTCapabilities()
*/
/**
*
*
*
* @return
*/
public String getHTTPPOSTCapabilities() {
return "" +
"" +
"" + driver.getVersion() + " " + " " +
"" +
"text/xml " + " " +
" ";
}
/* (non-Javadoc)
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPPOSTDescribeRecords()
*/
/**
*
*
*
* @return
*/
public String getHTTPPOSTDescribeRecords() {
return "" +
"csw:record " +
" ";
}
/* (non-Javadoc)
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPPOSTRecords(es.gva.cit.catalogClient.querys.Query, int)
*/
/**
*
*
*
* @return
* @param query
* @param firstRecord
*/
public String getHTTPPOSTRecords(Query query, int firstRecord) {
StringBuffer answer = new StringBuffer();
answer.append("");
if (url.getHost().equals("laits.gmu.edu")){
answer.append("" +
"" + getElementSetNameLabel(query.getSearchType()));
if ((driver.getService().equals("CSW"))){
answer.append("");
}else{
answer.append("");
}
answer.append(new CSWFilter().getQuery(query,driver.getServerProfile()) +
" " +
" ");
if (url.getHost().equals("laits.gmu.edu")){
answer.append(" ");
}else{
answer.append("");
}
return answer.toString();
}
/**
* The IDEC server has some different labels
*
*
* @return
*/
private String getElementSetNameLabel(int searchType) {
if (url.getHost().equals("laits.gmu.edu")){
StringBuffer buffer = new StringBuffer();
buffer.append("");
if (searchType == Query.SEARCH_DATA){
buffer.append("/DataGranule");
}else{
buffer.append("/Service");
}
buffer.append(" ");
return buffer.toString();
}
StringBuffer buffer = new StringBuffer();
if (driver.getServerProfile().equals(Schemas.EBRIM)){
buffer.append("");
}else{
buffer.append("");
}
buffer.append(getMaxSetName(driver.getElementSetName()) + " ");
return buffer.toString();
}
/**
* It returns the maximum element set name
*
*
* @return
* @param elementSetName
*/
private String getMaxSetName(String[] elementSetName) {
if ((driver.getService().equals("http://www.opengis.net/cat/csw"))){
return "full";
}
if (elementSetName == null){
return "summary";
}
for (int i=0 ; i