Permalink
Browse files

start with the latest patch from Trac ticket 87

  • Loading branch information...
Bart van den Eijnden
Bart van den Eijnden committed Jan 9, 2012
1 parent e41922d commit b52d053fb7224cf4a9c630a00392b1e40d561920
@@ -0,0 +1,24 @@
+<html>
+ <head>
+ <title>GeoExt CSW Example</title>
+
+ <script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="http://extjs.com/deploy/dev/examples/shared/examples.css" />
+ <script src="../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+ <script type="text/javascript" src="csw-getrecords.js"></script>
+
+ </head>
+ <body>
+ <h1>CSW Example</h1>
+ <p>This example shows how to load a grid with data from a CSW
+ GetRecords request.</p>
+
+ <p>Note that the js is not minified so it is readable.
+ See <a href="csw-getrecords.js">csw-getrecords.js</a>.</p>
+
+ <div id="cswgrid"></div>
+ </body>
+</html>
View
@@ -0,0 +1,26 @@
+
+Ext.onReady(function() {
+
+ // create store
+ var store = new Ext.data.Store({
+ reader: new GeoExt.data.CSWRecordsReader({
+ fields: ['title', 'subject']
+ }),
+ url: "data/cswrecords.xml",
+ autoLoad: true
+ });
+
+ // create grid to display records from the store
+ var grid = new Ext.grid.GridPanel({
+ title: "CSW Records",
+ store: store,
+ columns: [
+ {id: 'title', header: "Title", dataIndex: "title", sortable: true},
+ {header: "Subject", dataIndex: "subject", sortable: true, width: 300}
+ ],
+ autoExpandColumn: 'title',
+ renderTo: "cswgrid",
+ height: 300,
+ width: 650
+ });
+});
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
+ <csw:SearchStatus timestamp="2009-06-12T11:01:32" />
+ <csw:SearchResults numberOfRecordsMatched="60" numberOfRecordsReturned="60" elementSet="full" nextRecord="0">
+ <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dct="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <dc:title>Globally threatened species of the world</dc:title>
+ <dc:subject>GEMET 2000
+ biodiversity
+ endangered animal species
+ endangered plant species</dc:subject>
+ <dc:subject>None
+ Biology</dc:subject>
+ <dc:subject>None
+ Global</dc:subject>
+ <dct:abstract>Contains information on animals and plants threatened at the global level.</dct:abstract>
+ <dct:modified>20011220</dct:modified>
+ <dc:creator>GeoNetwork test user</dc:creator>
+ <dc:publisher>GeoNetwork test centre</dc:publisher>
+ <dc:rights>None</dc:rights>
+ <dc:rights>No restrictions</dc:rights>
+ <ows:BoundingBox crs="">
+ <ows:LowerCorner>180.0-90.0</ows:LowerCorner>
+ <ows:UpperCorner>-180.090.0</ows:UpperCorner>
+ </ows:BoundingBox>
+ </csw:Record>
+ <csw:Record xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <dc:title xmlns:dct="http://purl.org/dc/terms/">Natural polar ecosystems</dc:title>
+ <dc:creator xmlns:dct="http://purl.org/dc/terms/">GeoNetwork test user</dc:creator>
+ <dc:subject xmlns:dct="http://purl.org/dc/terms/">Antarctic ecosystem</dc:subject>
+ <dc:subject xmlns:dct="http://purl.org/dc/terms/">Arctic ecosystem</dc:subject>
+ <dc:subject xmlns:dct="http://purl.org/dc/terms/">polar ecosystem</dc:subject>
+ <dc:description xmlns:dct="http://purl.org/dc/terms/">A harmonised database of natural ecosystems in the Circumpolar Arctic, based on published vegetation maps.</dc:description>
+ <dc:publisher xmlns:dct="http://purl.org/dc/terms/">GeoNetwork test centre</dc:publisher>
+ <dc:contributor xmlns:dct="http://purl.org/dc/terms/">Unknown</dc:contributor>
+ <dc:date xmlns:dct="http://purl.org/dc/terms/">2000</dc:date>
+ <dc:type xmlns:dct="http://purl.org/dc/terms/">Maps and graphics</dc:type>
+ <dc:format xmlns:dct="http://purl.org/dc/terms/">Web page</dc:format>
+ <dc:identifier xmlns:dct="http://purl.org/dc/terms/">e2987cb0-3090-4a31-b90f-d3d024735ff7</dc:identifier>
+ <dc:source xmlns:dct="http://purl.org/dc/terms/">Compiled from published vegetation maps of the 8 circumpolar countries.</dc:source>
+ <dc:language xmlns:dct="http://purl.org/dc/terms/">en</dc:language>
+ <dc:relation xmlns:dct="http://purl.org/dc/terms/">Unknown</dc:relation>
+ <dc:coverage xmlns:dct="http://purl.org/dc/terms/">North 90, South -90, East 180, West -180. (Global)</dc:coverage>
+ <dc:rights xmlns:dct="http://purl.org/dc/terms/">Access constraints: None. Usage constraints: No restrictions</dc:rights>
+ <dct:modified xmlns:dct="http://purl.org/dc/terms/">2005-03-31T19:13:30</dct:modified>
+ <ows:BoundingBox crs="urn:x-ogc:def:crs:EPSG:6.11:4326">
+ <ows:LowerCorner>-90 -180</ows:LowerCorner>
+ <ows:UpperCorner>90 180</ows:UpperCorner>
+ </ows:BoundingBox>
+ </csw:Record>
+ <csw:Record xmlns:ows="http://www.opengis.net/ows" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:dct="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <dc:identifier>8dfef0e6-969e-4327-b292-5e7047f11808</dc:identifier>
+ <dc:title>Hydrological basins in Europe</dc:title>
+ <dc:subject>watersheds</dc:subject>
+ <dc:subject>Europe</dc:subject>
+ <dct:abstract>Major hydrological basins and their sub-basins. This dataset divides the Europe in zones.</dct:abstract>
+ <dc:language>en</dc:language>
+ <dc:source>None.</dc:source>
+ <ows:BoundingBox crs="::">
+ <ows:LowerCorner>51.1 -34.6</ows:LowerCorner>
+ <ows:UpperCorner>-17.3 38.2</ows:UpperCorner>
+ </ows:BoundingBox>
+ <dc:URI>resources.get?id=&amp;fname=large_s.png&amp;access=public</dc:URI>
+ </csw:Record>
+ <csw:Record xmlns:ows="http://www.opengis.net/ows" xmlns:geonet="http://www.fao.org/geonetwork" xmlns:dct="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <dc:identifier>bd7b3827-d6c4-4bd1-bac3-8e0e388e7a23</dc:identifier>
+ <dc:title>Cours d'eau</dc:title>
+ <dc:type>dataset</dc:type>
+ <dc:format />
+ <dct:abstract />
+ <dc:language />
+ <dc:source />
+ <ows:BoundingBox crs="::">
+ <ows:LowerCorner>180 -90</ows:LowerCorner>
+ <ows:UpperCorner>-180 90</ows:UpperCorner>
+ </ows:BoundingBox>
+ <dc:format />
+ <dc:URI>http://services.sandre.eaufrance.fr/geo/zonage?</dc:URI>
+ </csw:Record>
+ </csw:SearchResults>
+</csw:GetRecordsResponse>
+
View
@@ -81,6 +81,7 @@
"GeoExt/data/WMSDescribeLayerReader.js",
"GeoExt/data/WMSDescribeLayerStore.js",
"GeoExt/data/WMCReader.js",
+ "GeoExt/data/CSWRecordsReader.js",
"GeoExt/widgets/Action.js",
"GeoExt/data/ProtocolProxy.js",
"GeoExt/widgets/FeatureRenderer.js",
@@ -0,0 +1,78 @@
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ *
+ * pending approval */
+
+/** api: (define)
+ * module = GeoExt.data
+ * class = CSWRecordsReader
+ * base_link = `Ext.data.JsonReader <http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader>`_
+ */
+
+Ext.namespace("GeoExt.data");
+
+/** api: constructor
+ * .. class:: CSWRecordsReader(meta, recordType)
+ *
+ * :param meta: ``Object`` Reader configuration.
+ * :param recordType: ``Array | Ext.data.Record`` An array of field
+ * configuration objects or a record object. Default is
+ * :class:`Ext.data.Record`.
+ *
+ * Data reader class to create an array of records from a CSW
+ * GetRecords response.
+ */
+GeoExt.data.CSWRecordsReader = function(meta, recordType) {
+ meta = meta || {};
+ if(!meta.format) {
+ meta.format = new OpenLayers.Format.CSWGetRecords();
+ }
+ if(!meta.root) {
+ meta.root = 'records';
+ }
+
+ // FIXME
+ // There may be information of interest in the getRecords response
+ // namely SearchResults.numberOfRecordsReturned and
+ // SearchResults.numberOfRecordsMatched
+
+ GeoExt.data.CSWRecordsReader.superclass.constructor.call(
+ this, meta, recordType
+ );
+};
+
+Ext.extend(GeoExt.data.CSWRecordsReader, Ext.data.JsonReader, {
+
+ /** private: method[read]
+ * :param request: ``Object`` The XHR object which contains
+ * the parsed XML document.
+ * :return: ``Object`` A data block which is used by an
+ * ``Ext.data.Store`` as a cache of ``Ext.data.Record``
+ * objects.
+ */
+ read: function(request) {
+ var data = request.responseXML;
+ if(!data || !data.documentElement) {
+ data = request.responseText;
+ }
+ return this.readRecords(data);
+ },
+
+ /** private: method[readRecords]
+ * :param data: ``DOMElement | String | Object`` A document
+ * element or XHR response string.
+ * :return: ``Object`` A data block which is used by an
+ * ``Ext.data.Store`` as a cache of ``Ext.data.Record``
+ * objects.
+ */
+ readRecords: function(data) {
+ if(typeof data === "string" || data.nodeType) {
+ data = this.meta.format.read(data);
+ }
+ return GeoExt.data.CSWRecordsReader.superclass.readRecords.call(
+ this, data
+ );
+ }
+});
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html debug="true">
+ <head>
+ <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <script type="text/javascript">
+ function test_constructor(t) {
+ t.plan(5);
+
+ var reader, recordType;
+
+ reader = new GeoExt.data.CSWRecordsReader();
+ t.eq(reader.meta.format.CLASS_NAME, 'OpenLayers.Format.CSWGetRecords.v2_0_2',
+ "ctor creates a format of the correct type if none is given");
+ t.eq(reader.meta.root, 'records',
+ "ctor gives meta.root the good value if none is given");
+
+ recordType = [{name: "extra"}];
+ reader = new GeoExt.data.CSWRecordsReader(null, recordType);
+ t.eq(reader.recordType.prototype.fields.items[0].name, "extra",
+ "ctor creates a record type with the correct field");
+
+ recordType = Ext.data.Record.create([{name: "extra"}]);
+ reader = new GeoExt.data.CSWRecordsReader(null, recordType);
+ t.ok(reader.recordType == recordType,
+ "ctor configures reader with passed record type");
+
+ reader = new GeoExt.data.CSWRecordsReader({fields: [{name: "extra"}]});
+ t.eq(reader.recordType.prototype.fields.items[0].name, "extra",
+ "ctor creates a record type with the correct field");
+ }
+
+ function test_readRecords(t) {
+ t.plan(2);
+
+ var reader, cswRecords, data;
+
+ reader = new GeoExt.data.CSWRecordsReader(null, [{name: "extra"}]);
+ cswRecords = {
+ records: [{
+ extra: 'foo'
+ },{
+ extra: 'bar'
+ }]
+ }
+
+ data = reader.readRecords(cswRecords);
+ t.eq(data.totalRecords, 2,
+ "readRecords returns expected number of records");
+ t.eq(data.records[0].get("extra"), 'foo',
+ "readRecords returns records with expected \"extra\" field");
+ }
+ </script>
+ <body>
+ </body>
+</html>

0 comments on commit b52d053

Please sign in to comment.