From: <pva...@us...> - 2009-03-17 08:13:23
|
Revision: 2548 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=2548&view=rev Author: pvalsecc Date: 2009-03-17 08:13:20 +0000 (Tue, 17 Mar 2009) Log Message: ----------- Switch to the POST method for POST queries Modified Paths: -------------- sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/geocat.js sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/searchTools.js Modified: sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/geocat.js =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/geocat.js 2009-03-16 21:33:04 UTC (rev 2547) +++ sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/geocat.js 2009-03-17 08:13:20 UTC (rev 2548) @@ -248,10 +248,10 @@ target.innerHTML = "Search failed: <br />" + result.responseText; }, - processSearchResults: function(result, query) { + processSearchResults: function(result, getQuery) { var target = OpenLayers.Util.getElement("searchResults"); geocat.showContours(result.responseXML); - searchTools.transformXML(result.responseXML, geocat.getResultsTemplate(query), target); + searchTools.transformXML(result.responseXML, geocat.getResultsTemplate(getQuery), target); geocat.transformSortBy(); geocat.transformURIButtons(target); geocat.metadataSelectInfo('selected=status'); @@ -261,7 +261,7 @@ Ext.getCmp('refineWidget').expand(true); }, - processRefinement: function(result) { + processRefinement: function(result, getQuery) { var refineRemove = OpenLayers.Util.getElement("refineRemove"); refineRemove.innerHTML = ""; @@ -312,17 +312,13 @@ refinementWithNoResultsDisplay: function() { // Search - var query = searchTools.buildCSWQueryFromForm(Ext.getCmp('searchForm'), 1, geocat.sortBy, geocat.addGeographicFilter); - OpenLayers.Request.GET({ - url: geocat.baseUrl + "srv/" + translate('languageIso3') + "/csw", - params: query, - success: function(result) { - geocat.processRefinement(result); - }, - failure: function() { - alert ("Search failed."); - } - }); + searchTools.doCSWQueryFromForm('searchForm', + geocat.baseUrl + "srv/" + translate('languageIso3') + "/csw", 1, + geocat.processRefinement, //success + function() { //failure + alert ("Search failed."); + }, + geocat.addGeographicFilter); Ext.getCmp('refineWidget').expand(true); }, @@ -1428,22 +1424,17 @@ gotoPage: function(recordNum) { geocat.startSearch(); var url = geocat.baseUrl + "srv/" + translate('languageIso3') + "/csw"; - var query = searchTools.buildCSWQueryFromForm(Ext.getCmp('searchForm'), recordNum, geocat.sortBy, function(values, resultingFilters) { - geocat.addGeographicFilter(values, resultingFilters); - for (var key in geocat.refineWidget.refinements) { - geocat.refineWidget.refinements[key].forEach(function(filter) { - searchTools.addFiltersFromPropertyMap(filter, resultingFilters) + searchTools.doCSWQueryFromForm('searchForm', url, recordNum, + geocat.processSearchResults, + geocat.failedSearch, + function(values, resultingFilters) { + geocat.addGeographicFilter(values, resultingFilters); + for (var key in geocat.refineWidget.refinements) { + geocat.refineWidget.refinements[key].forEach(function(filter) { + searchTools.addFiltersFromPropertyMap(filter, resultingFilters); + }); + } }); - } - }); - OpenLayers.Request.GET({ - url: url, - params: query, - success: function(result) { - geocat.processSearchResults(result, query); - }, - failure: geocat.failedSearch - }); }, openLink: function(id, protocol, link) { @@ -1679,20 +1670,21 @@ Ext.getCmp('searchBt').handler(); } }, - getResultsTemplate: function(query) { + getResultsTemplate: function(getQuery) { var newQuery = OpenLayers.Util.applyDefaults({ maxRecords: 1000, startPosition: 1 - }, query); + }, getQuery); var q = OpenLayers.Util.getParameterString(newQuery); q = q.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); var exportLinks = ''; - for (i=0; i<geocat.exportResultModes.length; i++) + for (i=0; i<geocat.exportResultModes.length; i++) { exportLinks += '<a href="csw.' + geocat.exportResultModes[i] + '?' + (geocat.exportResultModes[i]!='pdf'?'outputSchema=own&':'') + // Only pdf is based on a common format, others are schemas based. q + '" target="export"><img height="16px" src="../../images/' + geocat.exportResultModes[i] + '.gif"/></a>'; + } var xslhead = '<?xml version="1.0" encoding="UTF-8"?>\n' + Modified: sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/searchTools.js =================================================================== --- sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/searchTools.js 2009-03-16 21:33:04 UTC (rev 2547) +++ sandbox/geocat.ch/trunk/web/geonetwork/scripts/mapfishIntegration/searchTools.js 2009-03-17 08:13:20 UTC (rev 2548) @@ -2,19 +2,13 @@ * Non-geocat specific stuff that could be reused */ var searchTools = { + cswMethod: 'POST', + createSearchButton: function(formId, url, onClick, onSuccess, onFailure, refineWidget, addFilters) { function onButtonClick() { onClick(); refineWidget.refinements = {}; - var query = searchTools.buildCSWQueryFromForm(Ext.getCmp(formId), 1, geocat.sortBy, addFilters); - OpenLayers.Request.GET({ - url: url, - params: query, - success: function(result) { - onSuccess(result, query); - }, - failure: onFailure - }); + searchTools.doCSWQueryFromForm(formId, url, 1, onSuccess, onFailure, addFilters); } return { @@ -34,6 +28,30 @@ }; }, + doCSWQueryFromForm: function(formId, url, recordNum, onSuccess, onFailure, addFilters) { + var query = searchTools.buildCSWQueryFromForm(searchTools.cswMethod, Ext.getCmp(formId), recordNum, geocat.sortBy, addFilters); + if (searchTools.cswMethod == 'POST') { + var getQuery = searchTools.buildCSWQueryFromForm('GET', Ext.getCmp(formId), recordNum, geocat.sortBy, addFilters); + OpenLayers.Request.POST({ + url: url, + data: query, + success: function(result) { + onSuccess(result, getQuery); + }, + failure: onFailure + }); + } else { + OpenLayers.Request.GET({ + url: url, + params: query, + success: function(result) { + onSuccess(result, query); + }, + failure: onFailure + }); + } + }, + /** * It's assumed the field name follow a convention. It starts with a letter, * followed by an underscore. The letters are: @@ -45,7 +63,7 @@ * E##: Equals with a specified similarity * G: Geometry by ID */ - buildCSWQueryFromForm: function(form, startRecord, sortBy, addFilters) { + buildCSWQueryFromForm: function(method, form, startRecord, sortBy, addFilters) { var values = searchTools.getFormValues(form); var filters = []; @@ -65,7 +83,11 @@ filters: filters }); - return searchTools.buildCSWQuery(and, startRecord, sortBy); + if (method == 'POST') { + return searchTools.buildCSWQueryPOST(and, startRecord, sortBy); + } else { + return searchTools.buildCSWQueryGET(and, startRecord, sortBy); + } }, addFiltersFromPropertyMap: function(values, filters) { @@ -130,8 +152,40 @@ title: {name: 'title', order: 'A'} }, - buildCSWQuery: function(filter, startRecord, sortBy) { + buildCSWQueryPOST: function(filter, startRecord, sortBy) { + var result = '<?xml version="1.0" encoding="UTF-8"?>\n'+ + '<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" resultType="results_with_summary" startPosition="'+startRecord+'" maxRecords="'+geocat.nbResultPerPage+'">\n'+ + ' <csw:Query>\n'+ + ' <csw:ElementSetName>full</csw:ElementSetName>\n'; + + if (sortBy) { + var searchInfo = searchTools.sortByMappings[sortBy]; + result+= ' <ogc:SortBy xmlns:ogc="http://www.opengis.net/ogc">\n'+ + ' <ogc:SortProperty>\n'+ + ' <ogc:PropertyName>'+searchInfo.name+'</ogc:PropertyName>\n'+ + ' <ogc:SortOrder>'+searchInfo.order+'</ogc:SortOrder>\n'+ + ' </ogc:SortProperty>\n'+ + ' </ogc:SortBy>\n'; + } + + if (filter) { + var filterXML = new OpenLayers.Format.XML().write( + new OpenLayers.Format.Filter().write(filter)); + filterXML = filterXML.replace(/^<\?xml[^?]*\?>/, ""); + result+= ' <csw:Constraint version="1.1.0">\n'; + result+=filterXML; + result+= ' </csw:Constraint>\n'; + } + + result += ' </csw:Query>\n'+ + '</csw:GetRecords>'; + + return result; + }, + + buildCSWQueryGET: function(filter, startRecord, sortBy) { + var result = { request: 'GetRecords', service:'CSW', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |