001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/csw/capabilities/CatalogueGetCapabilities.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstr. 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042
043 ---------------------------------------------------------------------------*/
044 package org.deegree.ogcwebservices.csw.capabilities;
045
046 import java.util.Map;
047
048 import org.deegree.framework.log.ILogger;
049 import org.deegree.framework.log.LoggerFactory;
050 import org.deegree.framework.util.StringTools;
051 import org.deegree.i18n.Messages;
052 import org.deegree.ogcbase.ExceptionCode;
053 import org.deegree.ogcwebservices.InvalidParameterValueException;
054 import org.deegree.ogcwebservices.OGCWebServiceException;
055 import org.deegree.ogcwebservices.csw.CSWPropertiesAccess;
056 import org.deegree.ogcwebservices.getcapabilities.GetCapabilities;
057 import org.w3c.dom.Element;
058
059 /**
060 * Class representation of an <code>OGC-GetCapabilities</code> request in <code>CSW</code>
061 * flavour.
062 * <p>
063 * Special to the <code>CSW</code> version of the <code>GetCapabilities</code> request are these
064 * two additional parameters: <table border="1">
065 * <tr>
066 * <th>Name</th>
067 * <th>Occurences</th>
068 * <th>Function</th>
069 * </tr>
070 * <tr>
071 * <td>AcceptVersions</td>
072 * <td align="center">0|1</td>
073 * <td>Protocol versions supported by this service.</td>
074 * </tr>
075 * <tr>
076 * <td>AcceptFormats</td>
077 * <td align="center">0|1</td>
078 * <td>Formats accepted by this service.</td>
079 * </tr>
080 * </table>
081 *
082 * @since 2.0
083 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
084 * @version $Revision: 9386 $
085 */
086 public class CatalogueGetCapabilities extends GetCapabilities {
087
088 private static final long serialVersionUID = 7690283041658363481L;
089
090 private static final ILogger LOG = LoggerFactory.getLogger( CatalogueGetCapabilities.class );
091
092 /**
093 * Creates a new <code>CatalogueGetCapabilities</code> instance.
094 *
095 * @param id
096 * request identifier
097 * @param updateSequence
098 * @param version
099 * @param acceptVersions
100 * @param acceptFormats
101 * @param sections
102 * @param vendoreSpec
103 */
104 CatalogueGetCapabilities( String id, String updateSequence, String version, String[] acceptVersions,
105 String[] acceptFormats, String[] sections, Map<String, String> vendoreSpec ) {
106 super( id, version, updateSequence, acceptVersions, sections, acceptFormats, vendoreSpec );
107 }
108
109 /**
110 * Creates a <code>CatalogGetCapabilities</code> request from its KVP representation.
111 *
112 * @param kvp
113 * Map containing the key-value pairs
114 * @return created <code>CatalogGetCapabilities</code> object
115 * @throws InvalidParameterValueException
116 */
117 public static CatalogueGetCapabilities create( Map<String, String> kvp )
118 throws InvalidParameterValueException {
119
120 String id = getParam( "ID", kvp, null );
121 // use 2.0.0 as default version
122 String version = getParam( "VERSION", kvp, CSWPropertiesAccess.getString( "DEFAULTVERSION" ) );
123 if ( !"2.0.0".equals( version ) && !"2.0.1".equals( version ) && !"2.0.2".equals( version ) ) {
124 throw new InvalidParameterValueException( Messages.get( "CSW_UNSUPPORTED_VERSION" ) );
125 }
126 String updateSequence = getParam( "UPDATESEQUENCE", kvp, null );
127 String[] acceptVersions = null;
128 if ( kvp.get( "ACCEPTVERSIONS" ) != null ) {
129 String tmp = getParam( "ACCEPTVERSIONS", kvp, null );
130
131 acceptVersions = StringTools.toArray( tmp, ",", false );
132 version = CatalogueGetCapabilities.validateVersion( acceptVersions );
133 if ( version == null ) {
134 throw new InvalidParameterValueException( Messages.get( "CSW_UNSUPPORTED_VERSION" ) );
135 }
136 }
137 LOG.logInfo( "process with version:", version );
138 String[] acceptFormats = null;
139 if ( kvp.get( "OUTPUTFORMAT" ) != null ) {
140 String tmp = getParam( "OUTPUTFORMAT", kvp, null );
141 acceptFormats = StringTools.toArray( tmp, ",", false );
142 }
143 String[] sections = null;
144 if ( kvp.get( "SECTIONS" ) != null ) {
145 String tmp = getParam( "SECTIONS", kvp, null );
146 sections = StringTools.toArray( tmp, ",", false );
147 }
148 return new CatalogueGetCapabilities( id, updateSequence, version, acceptVersions, acceptFormats, sections, kvp );
149
150 }
151
152 /**
153 * Creates a <code>CatalogGetCapabilities</code> request from its XML representation.
154 *
155 * @param id
156 * unique ID of the request
157 * @param root
158 * XML representation of the request
159 * @return created <code>CatalogGetCapabilities</code> object
160 * @throws OGCWebServiceException
161 * thrown if something in the request is wrong
162 */
163 public static CatalogueGetCapabilities create( String id, Element root )
164 throws OGCWebServiceException {
165
166 CatalogueGetCapabilitiesDocument doc = new CatalogueGetCapabilitiesDocument();
167 doc.setRootElement( root );
168 CatalogueGetCapabilities request;
169 try {
170 request = doc.parse( id );
171 } catch ( Exception e ) {
172 LOG.logError( e.getMessage(), e );
173 ExceptionCode code = ExceptionCode.INVALID_FORMAT;
174 throw new OGCWebServiceException( "CatalogGetCapabilities", e.getMessage(), code );
175 }
176 return request;
177 }
178
179 /**
180 * returns WCS as service name
181 */
182 public String getServiceName() {
183 return "CSW";
184 }
185
186 /**
187 *
188 * @param acceptVersions
189 * @return the highst supported version or <code>null</code> if none of the passed versions is
190 * supported
191 */
192 static String validateVersion( String[] acceptVersions ) {
193 String version = null;
194 for ( int i = 0; i < acceptVersions.length; i++ ) {
195 if ( acceptVersions[i].equals( "2.0.0" ) || acceptVersions[i].equals( "2.0.1" )
196 || acceptVersions[i].equals( "2.0.2" ) ) {
197 if ( version == null ) {
198 version = acceptVersions[i];
199 }
200 if ( acceptVersions[i].compareTo( version ) > 0 ) {
201 version = acceptVersions[i];
202 }
203 }
204 }
205
206 return version;
207 }
208 }