Author: aaime
Date: 2012-06-16 10:08:04 -0700 (Sat, 16 Jun 2012)
New Revision: 38811
Added:
   trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/MetadataURL.java
Modified:
   trunk/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java
   trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/WMSComplexTypes.java
   trunk/modules/extension/wms/src/test/java/org/geotools/data/wms/xml/test/WMSSchemaTest.java
   trunk/modules/extension/wms/src/test/resources/org/geotools/data/wms/xml/test/test-data/1.3.0Capabilities.xml
Log:
[GEOT-4148] Getcapabilities MetadataURL added for layers, patch by Meine Toonen
Modified: trunk/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java
===================================================================
--- trunk/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java	2012-06-16 16:45:48 UTC (rev 38810)
+++ trunk/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java	2012-06-16 17:08:04 UTC (rev 38811)
@@ -30,6 +30,7 @@
 
 import org.geotools.data.wms.xml.Dimension;
 import org.geotools.data.wms.xml.Extent;
+import org.geotools.data.wms.xml.MetadataURL;
 import org.geotools.geometry.GeneralEnvelope;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.referencing.CRS;
@@ -155,6 +156,8 @@
      */
     private Map<CoordinateReferenceSystem, Envelope> envelopeCache = Collections
             .synchronizedMap(new WeakHashMap<CoordinateReferenceSystem, Envelope>());
+    
+    private List<MetadataURL> metadataURL;
 
     /**
      * Called to clear the internal cache of this layer; and any children.
@@ -932,6 +935,15 @@
     public void setCascaded(int cascadedValue) {
         this.cascaded = cascadedValue;
     }
+
+    public List<MetadataURL> getMetadataURL() {
+        return metadataURL;
+    }
+
+    public void setMetadataURL(List<MetadataURL> metadataURL) {
+        this.metadataURL = metadataURL;
+    }
+
     
     @Override
     public String toString() {
Added: trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/MetadataURL.java
===================================================================
--- trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/MetadataURL.java	                        (rev 0)
+++ trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/MetadataURL.java	2012-06-16 17:08:04 UTC (rev 38811)
@@ -0,0 +1,72 @@
+/*
+ *    GeoTools - The Open Source Java GIS Toolkit
+ *    http://geotools.org
+ *
+ *    (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
+ *    
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License as published by the Free Software Foundation;
+ *    version 2.1 of the License.
+ *
+ *    This library 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
+ *    Lesser General Public License for more details.
+ */
+package org.geotools.data.wms.xml;
+
+import java.net.URL;
+
+/**
+ * A Map Server may use zero or more MetadataURL elements to offer detailed,
+ *   standardized metadata about the data underneath a particular layer. The type
+ *   attribute indicates the standard to which the metadata complies.  Two types
+ *  are defined at present: 'TC211' = ISO TC211 19115; 'FGDC' = FGDC CSDGM.  The
+ *   format element indicates how the metadata is structured. -->
+ *   <!ELEMENT MetadataURL (Format, OnlineResource) >
+ *   <!ATTLIST MetadataURL
+ *           type ( TC211 | FGDC ) #REQUIRED>
+ * @author Meine Toonen mei...@b3...
+ */
+public class MetadataURL {
+    
+    protected URL url;
+    protected String type;
+    protected String format;
+
+    public MetadataURL(URL url, String type, String format) {
+        this.url = url;
+        this.type = type;
+        this.format = format;
+    }
+    
+    public String getFormat() {
+        return format;
+    }
+
+    public void setFormat(String format) {
+        this.format = format;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public URL getUrl() {
+        return url;
+    }
+
+    public void setUrl(URL url) {
+        this.url = url;
+    }
+
+    @Override
+    public String toString() {
+        return "MetadataURL{" + "url=" + url + ", type=" + type + '}';
+    }
+}
Modified: trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/WMSComplexTypes.java
===================================================================
--- trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/WMSComplexTypes.java	2012-06-16 16:45:48 UTC (rev 38810)
+++ trunk/modules/extension/wms/src/main/java/org/geotools/data/wms/xml/WMSComplexTypes.java	2012-06-16 17:08:04 UTC (rev 38811)
@@ -2598,6 +2598,7 @@
 			HashMap dimensions = new HashMap();
 			HashMap extents = new HashMap();
 			List styles = new ArrayList();
+			List metadataURLS = new ArrayList();
 
 			for (int i = 0; i < value.length; i++) {
 				if (sameName(elems[0], value[i])) {
@@ -2656,9 +2657,10 @@
 				// if (sameName(elems[11], value[i])) {
 				// //TODO identifier ignored
 				// }
-				// if (sameName(elems[12], value[i])) {
-				// //TODO metadataURL ignore
-				// }
+				 if (sameName(elems[12], value[i])) {
+					MetadataURL metadataUrl = (MetadataURL)value[i].getValue();
+					metadataURLS.add(metadataUrl);
+				 }
 				// if (sameName(elems[13], value[i])) {
 				// //TODO dataURL ignored
 				// }
@@ -2696,6 +2698,7 @@
 			layer.setDimensions(dimensions);
 			layer.setExtents(extents);
 			layer.setStyles(styles);
+			layer.setMetadataURL(metadataURLS);
             
             layer.setChildren((Layer[]) childLayers.toArray(new Layer[childLayers.size()]));
 
@@ -3639,7 +3642,12 @@
 		public Object getValue(Element element, ElementValue[] value,
 				Attributes attrs, Map hints) throws SAXException,
 				OperationNotSupportedException {
-			return null;
+                    String type = attrs.getValue("type").toString();
+                    URL url = (URL)value[1].getValue();
+                    String format = (String)(((Object[])value[0].getValue())[0]);
+                    MetadataURL metadataURL = new MetadataURL( url, type, format);
+                  
+                    return metadataURL;
 			// throw new OperationNotSupportedException();
 		}
 
Modified: trunk/modules/extension/wms/src/test/java/org/geotools/data/wms/xml/test/WMSSchemaTest.java
===================================================================
--- trunk/modules/extension/wms/src/test/java/org/geotools/data/wms/xml/test/WMSSchemaTest.java	2012-06-16 16:45:48 UTC (rev 38810)
+++ trunk/modules/extension/wms/src/test/java/org/geotools/data/wms/xml/test/WMSSchemaTest.java	2012-06-16 17:08:04 UTC (rev 38811)
@@ -121,6 +121,9 @@
 		assertTrue(layer.isQueryable());
 		assertEquals(layer.getName(), "Bathymetry");
 		assertEquals(layer.getTitle(), "Bathymetry");
+		assertEquals(layer.getMetadataURL().get(0).getUrl().toString(), "http://www.example.com/?");
+		assertEquals(layer.getMetadataURL().get(0).getFormat(), "text/html");
+		assertEquals(layer.getMetadataURL().get(0).getType(), "FGDC");
 		assertEquals(layer.getStyles().get(0).getLegendURLs().get(0), "http://www.osgeo.org/sites/all/themes/osgeo/logo.png");
 		
 		// Added test to verify inheritance, should be same as previous llbbox
Modified: trunk/modules/extension/wms/src/test/resources/org/geotools/data/wms/xml/test/test-data/1.3.0Capabilities.xml
===================================================================
--- trunk/modules/extension/wms/src/test/resources/org/geotools/data/wms/xml/test/test-data/1.3.0Capabilities.xml	2012-06-16 16:45:48 UTC (rev 38810)
+++ trunk/modules/extension/wms/src/test/resources/org/geotools/data/wms/xml/test/test-data/1.3.0Capabilities.xml	2012-06-16 17:08:04 UTC (rev 38811)
@@ -101,6 +101,10 @@
 				<Name>Bathymetry</Name>
 				<Title>Bathymetry</Title>
 				<BoundingBox CRS="CRS:84" minx="-180" miny="-90" maxx="180" maxy="90"/>				
+				<MetadataURL type="FGDC">
+					<Format>text/html</Format>
+					<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.example.com/?"/>
+				</MetadataURL>
 				<Style>
 					<Name>default</Name>
 					<Title>default</Title>
 |