001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wcs/describecoverage/DescribeCoverage.java $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 Department of Geography, University of Bonn 006 and 007 lat/lon GmbH 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 package org.deegree.ogcwebservices.wcs.describecoverage; 037 038 import java.util.Map; 039 040 import org.deegree.framework.log.ILogger; 041 import org.deegree.framework.log.LoggerFactory; 042 import org.deegree.framework.util.KVP2Map; 043 import org.deegree.framework.util.StringTools; 044 import org.deegree.framework.xml.ElementList; 045 import org.deegree.framework.xml.XMLParsingException; 046 import org.deegree.framework.xml.XMLTools; 047 import org.deegree.ogcbase.CommonNamespaces; 048 import org.deegree.ogcbase.ExceptionCode; 049 import org.deegree.ogcwebservices.InvalidParameterValueException; 050 import org.deegree.ogcwebservices.MissingParameterValueException; 051 import org.deegree.ogcwebservices.OGCWebServiceException; 052 import org.deegree.ogcwebservices.wcs.WCSException; 053 import org.deegree.ogcwebservices.wcs.WCSExceptionCode; 054 import org.deegree.ogcwebservices.wcs.WCSRequestBase; 055 import org.w3c.dom.Document; 056 import org.w3c.dom.Element; 057 058 /** 059 * A DescribeCoverage request lists the coverages to be described, identified by the Coverage 060 * parameter. A request that lists no coverages shall be interpreted as requesting descriptions of 061 * all coverages that a WCS can serve. 062 * 063 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 064 * @author last edited by: $Author: mschneider $ 065 * 066 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 067 */ 068 public class DescribeCoverage extends WCSRequestBase { 069 070 private static final ILogger LOG = LoggerFactory.getLogger( DescribeCoverage.class ); 071 072 private String[] coverages = null; 073 074 /** 075 * creates a DescribeCoverage request from its KVP representation 076 * 077 * @param map 078 * request 079 * @return created <tt>DescribeCoverage</tt> 080 * @throws OGCWebServiceException 081 * will be thrown if something general is wrong 082 * @throws MissingParameterValueException 083 * @throws InvalidParameterValueException 084 * @throws WCSException 085 * will be thrown if a WCS/DescribeCoverage specific part of the request is 086 * erroreous 087 */ 088 public static DescribeCoverage create( Map map ) 089 throws OGCWebServiceException, MissingParameterValueException, 090 InvalidParameterValueException { 091 092 String version = (String) map.get( "VERSION" ); 093 if ( version == null ) { 094 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 095 throw new MissingParameterValueException( "DescribeCoverage", "'version' is missing", code ); 096 } 097 if ( !version.equals( "1.0.0" ) ) { 098 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 099 throw new InvalidParameterValueException( "DescribeCoverage", "'version' <> 1.0.0", code ); 100 } 101 String service = (String) map.get( "SERVICE" ); 102 if ( service == null ) { 103 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 104 throw new MissingParameterValueException( "DescribeCoverage", "'service' is missing", code ); 105 } 106 if ( !"WCS".equalsIgnoreCase( service ) ) { 107 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 108 throw new InvalidParameterValueException( "DescribeCoverage", "'service' <> WCS", code ); 109 } 110 111 String[] coverages = new String[0]; 112 if ( map.get( "COVERAGE" ) != null ) { 113 String s = (String) map.get( "COVERAGE" ); 114 coverages = StringTools.toArray( s, ",", true ); 115 } 116 117 String id = (String) map.get( "ID" ); 118 119 return new DescribeCoverage( id, version, coverages ); 120 } 121 122 /** 123 * creates a DescribeCoverage request from its KVP representation 124 * 125 * @param id 126 * unique ID of the request 127 * @param kvp 128 * request 129 * @return created <tt>DescribeCoverage</tt> 130 * @throws OGCWebServiceException 131 * will be thrown if something general is wrong 132 * @throws MissingParameterValueException 133 * @throws InvalidParameterValueException 134 * @throws WCSException 135 * will be thrown if a WCS/DescribeCoverage specific part of the request is 136 * erroreous 137 */ 138 public static DescribeCoverage createDescribeCoverage( String id, String kvp ) 139 throws OGCWebServiceException, MissingParameterValueException, 140 InvalidParameterValueException { 141 Map<String, String> map = KVP2Map.toMap( kvp ); 142 map.put( "ID", id ); 143 return create( map ); 144 } 145 146 /** 147 * creates a DescribeCoverage request from its XML representation 148 * 149 * @param id 150 * unique ID of the request 151 * @param doc 152 * XML representation of the request 153 * @return created <tt>DescribeCoverage</tt> 154 * @throws OGCWebServiceException 155 * will be thrown if something general is wrong 156 * @throws MissingParameterValueException 157 * @throws InvalidParameterValueException 158 * @throws WCSException 159 * will be thrown if a WCS/DescribeCoverage specific part of the request is 160 * erroreous 161 */ 162 public static DescribeCoverage create( String id, Document doc ) 163 throws OGCWebServiceException, MissingParameterValueException, 164 InvalidParameterValueException { 165 166 String[] coverages = null; 167 String version = null; 168 try { 169 Element root = XMLTools.getRequiredChildElement( "DescribeCoverage", CommonNamespaces.WCSNS, doc ); 170 171 version = XMLTools.getAttrValue( root, null, "version", null ); 172 if ( version == null ) { 173 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 174 throw new MissingParameterValueException( "DescribeCoverage", "'version' is missing", code ); 175 } 176 if ( !version.equals( "1.0.0" ) ) { 177 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 178 throw new InvalidParameterValueException( "DescribeCoverage", "'version' <> 1.0.0", code ); 179 } 180 181 String service = XMLTools.getAttrValue( root, null, "service", null ); 182 if ( service == null ) { 183 ExceptionCode code = ExceptionCode.MISSINGPARAMETERVALUE; 184 throw new MissingParameterValueException( "DescribeCoverage", "'service' is missing", code ); 185 } 186 if ( !"WCS".equalsIgnoreCase( service ) ) { 187 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE; 188 throw new InvalidParameterValueException( "DescribeCoverage", "'service' <> WCS", code ); 189 } 190 191 ElementList el = XMLTools.getChildElements( "Coverage", CommonNamespaces.WCSNS, root ); 192 coverages = new String[el.getLength()]; 193 for ( int i = 0; i < coverages.length; i++ ) { 194 coverages[i] = XMLTools.getStringValue( el.item( i ) ); 195 } 196 } catch ( XMLParsingException e ) { 197 ExceptionCode code = WCSExceptionCode.INVALID_FORMAT; 198 throw new WCSException( "DescribeCoverage", e.toString(), code ); 199 } 200 201 return new DescribeCoverage( id, version, coverages ); 202 } 203 204 /** 205 * @param id 206 * unique ID of the request 207 * @param version 208 * Request protocol version 209 * @param coverages 210 * list of coverages to describe (identified by their name values in the Capabilities 211 * response). If <tt>null</tt> or length == 0 all coverages of the service 212 * instances will be described 213 */ 214 public DescribeCoverage( String id, String version, String[] coverages ) { 215 super( id, version ); 216 this.coverages = coverages; 217 } 218 219 /** 220 * @return Returns the coverages. 221 * 222 */ 223 public String[] getCoverages() { 224 return coverages; 225 } 226 227 @Override 228 public String getRequestParameter() 229 throws OGCWebServiceException { 230 StringBuffer sb = new StringBuffer(1000); 231 sb.append( "Service=WCS&REQUEST=DescribeCoverage&VERSION=1.0.0&coverage=" ); 232 if ( coverages != null ) { 233 for ( int i = 0; i < coverages.length; i++ ) { 234 sb.append( coverages[i] ); 235 if ( i < coverages.length - 1 ) { 236 sb.append( ',' ); 237 } 238 } 239 } 240 241 LOG.logDebug( "DescribeCoverage parameter", sb ); 242 243 return sb.toString(); 244 } 245 246 }