001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/OWSUtils.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; 037 038 import java.net.URL; 039 import java.util.List; 040 041 import org.deegree.datatypes.QualifiedName; 042 import org.deegree.ogcwebservices.getcapabilities.GetCapabilities; 043 import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities; 044 import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilities; 045 import org.deegree.ogcwebservices.wfs.capabilities.WFSOperationsMetadata; 046 import org.deegree.ogcwebservices.wfs.operation.GetFeature; 047 import org.deegree.ogcwebservices.wfs.operation.GetFeatureWithLock; 048 import org.deegree.ogcwebservices.wfs.operation.Lock; 049 import org.deegree.ogcwebservices.wfs.operation.transaction.Transaction; 050 import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilities; 051 import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo; 052 import org.deegree.ogcwebservices.wms.operation.GetLegendGraphic; 053 import org.deegree.ogcwebservices.wms.operation.GetMap; 054 import org.deegree.owscommon_new.DCP; 055 import org.deegree.owscommon_new.HTTP; 056 import org.deegree.owscommon_new.Operation; 057 import org.deegree.owscommon_new.OperationsMetadata; 058 059 /** 060 * 061 * 062 * 063 * @version $Revision: 18195 $ 064 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 065 * @author last edited by: $Author: mschneider $ 066 * 067 * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $ 068 * 069 * @since 2.0 070 */ 071 public class OWSUtils { 072 073 /** 074 * according to OGC WMS 1.3 Testsuite a URL to a service operation via HTTPGet must end with '?' 075 * or '&' 076 * 077 * @param href 078 * @return the parameter, changed to fulfill the spec 079 */ 080 public static String validateHTTPGetBaseURL( String href ) { 081 if ( !href.endsWith( "/" ) ) { 082 if ( href.indexOf( '?' ) < 0 ) { 083 href = href + '?'; 084 } else if ( !href.endsWith( "&" ) && !href.endsWith( "?" ) ) { 085 href = href + '&'; 086 } 087 } 088 return href; 089 } 090 091 /** 092 * the method return the first HTTPGet URL for a Operation within the pass capabilities 093 * document. If No URL can be found (e.g. the service does not support the operation via HTTP 094 * Get) <code>null</code> will be returned 095 * 096 * @param capabilities 097 * @param clss 098 * @return see above 099 */ 100 public synchronized static URL getHTTPGetOperationURL( OGCCapabilities capabilities, Class clss ) { 101 URL url = null; 102 if ( capabilities instanceof WMSCapabilities ) { 103 url = getHTTPGetOperationURL( (WMSCapabilities) capabilities, clss ); 104 } else if ( capabilities instanceof WFSCapabilities ) { 105 url = getHTTPGetOperationURL( (WFSCapabilities) capabilities, clss ); 106 } else { 107 // TODO 108 // support more service types 109 // possibly use generic base capabilities to extract it 110 } 111 return url; 112 113 } 114 115 /** 116 * @see #getHTTPGetOperationURL(OGCCapabilities, Class) 117 * @param capabilities 118 * @param clss 119 * @return the first operation URL 120 */ 121 private synchronized static URL getHTTPGetOperationURL( WMSCapabilities capabilities, Class clss ) { 122 123 OperationsMetadata om = capabilities.getOperationMetadata(); 124 List<DCP> dcps = null; 125 if ( clss.equals( GetMap.class ) ) { 126 Operation op = om.getOperation( new QualifiedName( "GetMap" ) ); 127 if ( op == null ) { 128 op = om.getOperation( new QualifiedName( "map" ) ); 129 } 130 dcps = op.getDCP(); 131 } else if ( clss.equals( GetCapabilities.class ) ) { 132 Operation op = om.getOperation( new QualifiedName( "GetCapabilities" ) ); 133 if ( op == null ) { 134 op = om.getOperation( new QualifiedName( "capabilities" ) ); 135 } 136 dcps = op.getDCP(); 137 } else if ( clss.equals( GetFeatureInfo.class ) ) { 138 Operation op = om.getOperation( new QualifiedName( "GetFeatureInfo" ) ); 139 if ( op == null ) { 140 op = om.getOperation( new QualifiedName( "FeatureInfo" ) ); 141 } 142 dcps = op.getDCP(); 143 } else if ( clss.equals( GetLegendGraphic.class ) ) { 144 Operation op = om.getOperation( new QualifiedName( "GetLegendGraphic" ) ); 145 dcps = op.getDCP(); 146 } 147 148 // search for the first HTTP Get link 149 if ( dcps == null ) { 150 return null; 151 } 152 for ( DCP dcp : dcps ) { 153 if ( dcp instanceof HTTP ) { 154 HTTP http = (HTTP) dcp; 155 List<URL> urls = http.getGetOnlineResources(); 156 if ( urls.size() > 0 ) { 157 return urls.get( 0 ); 158 } 159 } 160 } 161 162 return null; 163 164 } 165 166 /** 167 * @see #getHTTPGetOperationURL(OGCCapabilities, Class) 168 * @param capabilities 169 * @param clss 170 * @return the first operation URL 171 */ 172 private synchronized static URL getHTTPGetOperationURL( WFSCapabilities capabilities, Class clss ) { 173 174 URL url = null; 175 WFSOperationsMetadata om = (WFSOperationsMetadata) capabilities.getOperationsMetadata(); 176 if ( clss.equals( GetCapabilities.class ) ) { 177 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getGetCapabilitiesOperation().getDCPs()[0].getProtocol(); 178 url = http.getGetOnlineResources()[0]; 179 } else if ( clss.equals( GetFeature.class ) ) { 180 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getGetFeature().getDCPs()[0].getProtocol(); 181 url = http.getGetOnlineResources()[0]; 182 } else if ( clss.equals( GetFeatureWithLock.class ) ) { 183 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getGetFeatureWithLock().getDCPs()[0].getProtocol(); 184 url = http.getGetOnlineResources()[0]; 185 } else if ( clss.equals( Lock.class ) ) { 186 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getLockFeature().getDCPs()[0].getProtocol(); 187 url = http.getGetOnlineResources()[0]; 188 } else if ( clss.equals( Transaction.class ) ) { 189 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getTransaction().getDCPs()[0].getProtocol(); 190 url = http.getGetOnlineResources()[0]; 191 } 192 return url; 193 } 194 195 /** 196 * the method return the first HTTPPost URL for a Operation within the pass capabilities 197 * document. If No URL can be found (e.g. the service does not support the operation via HTTP 198 * Get) <code>null</code> will be returned 199 * 200 * @param capabilities 201 * @param clss 202 * @return the first HTTPPost URL for a Operation within the pass capabilities document. If No 203 * URL can be found (e.g. the service does not support the operation via HTTP Get) 204 * <code>null</code> will be returned 205 */ 206 public synchronized static URL getHTTPPostOperationURL( OGCCapabilities capabilities, Class clss ) { 207 URL url = null; 208 if ( capabilities instanceof WFSCapabilities ) { 209 url = getHTTPPostOperationURL( (WFSCapabilities) capabilities, clss ); 210 } else { 211 // TODO 212 // support more service types 213 // possibly use generic base capabilities to extract it 214 } 215 return url; 216 } 217 218 /** 219 * @see #getHTTPPostOperationURL(OGCCapabilities, Class) 220 * @param capabilities 221 * @param clss 222 * @return the first operation URL 223 */ 224 private synchronized static URL getHTTPPostOperationURL( WFSCapabilities capabilities, Class clss ) { 225 226 URL url = null; 227 WFSOperationsMetadata om = (WFSOperationsMetadata) capabilities.getOperationsMetadata(); 228 if ( clss.equals( GetCapabilities.class ) ) { 229 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getGetCapabilitiesOperation().getDCPs()[0].getProtocol(); 230 url = http.getPostOnlineResources()[0]; 231 } else if ( clss.equals( GetFeature.class ) ) { 232 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getGetFeature().getDCPs()[0].getProtocol(); 233 url = http.getPostOnlineResources()[0]; 234 } else if ( clss.equals( GetFeatureWithLock.class ) ) { 235 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getGetFeatureWithLock().getDCPs()[0].getProtocol(); 236 url = http.getPostOnlineResources()[0]; 237 } else if ( clss.equals( Lock.class ) ) { 238 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getLockFeature().getDCPs()[0].getProtocol(); 239 url = http.getPostOnlineResources()[0]; 240 } else if ( clss.equals( Transaction.class ) ) { 241 org.deegree.ogcwebservices.getcapabilities.HTTP http = (org.deegree.ogcwebservices.getcapabilities.HTTP) om.getTransaction().getDCPs()[0].getProtocol(); 242 url = http.getPostOnlineResources()[0]; 243 } 244 return url; 245 } 246 247 }