001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wfs/operation/WFSGetCapabilities.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.wfs.operation;
037    
038    import java.util.Map;
039    
040    import org.deegree.framework.util.KVP2Map;
041    import org.deegree.ogcwebservices.InvalidParameterValueException;
042    import org.deegree.ogcwebservices.MissingParameterValueException;
043    import org.deegree.ogcwebservices.OGCWebServiceException;
044    import org.deegree.ogcwebservices.getcapabilities.GetCapabilities;
045    import org.deegree.ogcwebservices.wfs.WFService;
046    import org.w3c.dom.Element;
047    
048    /**
049     * Represents a GetCapabilities request to a web feature service.
050     * <p>
051     * The GetCapabilities request is used to query a capabilities document from a web feature service.
052     *
053     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
054     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
055     * @author last edited by: $Author: mschneider $
056     *
057     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
058     */
059    public class WFSGetCapabilities extends GetCapabilities {
060    
061        private static final long serialVersionUID = 3581485156939911513L;
062    
063        /**
064         * Creates a new <code>WFSGetCapabilities</code> instance. with a wfs version of {@link WFService#VERSION}.
065         *
066         * @param id
067         *            request identifier
068         * @param updateSeq
069         * @param acceptVersions
070         * @param sections
071         * @param acceptFormats
072         * @param vendoreSpec
073         */
074        WFSGetCapabilities( String id, String updateSeq, String[] acceptVersions, String[] sections,
075                            String[] acceptFormats, Map<String, String> vendoreSpec ) {
076            this( id, WFService.VERSION, updateSeq, acceptVersions, sections, acceptFormats, vendoreSpec );
077        }
078    
079        /**
080         * Creates a new <code>WFSGetCapabilities</code> instance.
081         *
082         * @param id
083         *            request identifier
084         * @param version
085         *            the version of the request. (e.g 1.0.0 or 1.1.0)
086         * @param updateSeq
087         * @param acceptVersions
088         * @param sections
089         * @param acceptFormats
090         * @param vendoreSpec
091         */
092        WFSGetCapabilities( String id, String version, String updateSeq, String[] acceptVersions, String[] sections,
093                            String[] acceptFormats, Map<String, String> vendoreSpec ) {
094            super( id, version, updateSeq, acceptVersions, sections, acceptFormats, vendoreSpec );
095        }
096    
097        /**
098         * Creates a <code>WFSGetCapabilities</code> instance from a document that contains the DOM representation of the
099         * request.
100         *
101         * @param id
102         * @param root
103         *            element that contains the DOM representation of the request
104         * @return transaction instance
105         * @throws OGCWebServiceException
106         */
107        public static WFSGetCapabilities create( String id, Element root )
108                                throws OGCWebServiceException {
109            WFSGetCapabilitiesDocument doc = new WFSGetCapabilitiesDocument();
110            doc.setRootElement( root );
111            WFSGetCapabilities request;
112            try {
113                request = doc.parse( id );
114            } catch ( Exception e ) {
115                throw new OGCWebServiceException( "WFSGetCapabilities", e.getMessage() );
116            }
117            return request;
118        }
119    
120        /**
121         * Creates a new <code>WFSGetCapabilities</code> instance from the given key-value pair encoded request.
122         *
123         * @param id
124         *            request identifier
125         * @param request
126         * @return new <code>WFSGetCapabilities</code> request
127         * @throws InvalidParameterValueException
128         * @throws MissingParameterValueException
129         */
130        public static WFSGetCapabilities create( String id, String request )
131                                throws MissingParameterValueException, InvalidParameterValueException {
132            Map<String, String> map = KVP2Map.toMap( request );
133            map.put( "ID", id );
134            return create( map );
135        }
136    
137        /**
138         * Creates a new <code>WFSGetCapabilities</code> request from the given map.
139         *
140         * @param request
141         * @return new <code>WFSGetCapabilities</code> request
142         * @throws MissingParameterValueException
143         * @throws InvalidParameterValueException
144         */
145        public static WFSGetCapabilities create( Map<String, String> request )
146                                throws MissingParameterValueException, InvalidParameterValueException {
147    
148            String service = getRequiredParam( "SERVICE", request );
149            if ( !service.equals( "WFS" ) ) {
150                throw new InvalidParameterValueException( "WFSGetCapabilities", "Parameter 'service' must be 'WFS'." );
151            }
152            String version = request.get( "VERSION" );
153            String av = request.get( "ACCEPTVERSIONS" );
154            String[] acceptVersions = av == null ? null : av.split( "," );
155            String sec = request.get( "SECTIONS" );
156            String[] sections = sec == null ? null : sec.split( "," );
157            String updateSequence = getParam( "UPDATESEQUENCE", request, "" );
158            String af = request.get( "ACCEPTFORMATS" );
159            String[] acceptFormats = af == null ? new String[] { "text/xml" } : af.split( "," );
160    
161            // TODO generate unique request id
162            String id = null;
163            if ( version == null || "".equals( version.trim() ) ) {
164                return new WFSGetCapabilities( id, updateSequence, acceptVersions, sections, acceptFormats, request );
165            }
166            return new WFSGetCapabilities( id, version, updateSequence, acceptVersions, sections, acceptFormats, request );
167        }
168    
169        /**
170         * Returns the service name (WFS).
171         *
172         * @return the service name (WFS).
173         */
174        public String getServiceName() {
175            return "WFS";
176        }
177    }