    001    //$HeadURL: $
    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
    037    package org.deegree.ogcwebservices.wcts.operation;
    038
    039    import java.util.ArrayList;
    040    import java.util.Arrays;
    041    import java.util.List;
    042    import java.util.Map;
    043
    044    import org.deegree.i18n.Messages;
    045    import org.deegree.ogcbase.ExceptionCode;
    046    import org.deegree.ogcwebservices.OGCWebServiceException;
    047
    048    /**
    049     * <code>WCTSGetCapabilities</code> bean representation of a GetCapabilities request, xml-dom or kvp encoded.
    050     *
    051     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
    052     *
    053     * @author last edited by: $Author:$
    054     *
    055     * @version $Revision:$, $Date:$
    056     *
    057     */
    058    public class WCTSGetCapabilities extends WCTSRequestBase {
    059
    060        private static final long serialVersionUID = 6951749192378539154L;
    061
    062        private final String updateSequence;
    063
    064        private final List<String> acceptedVersions;
    065
    066        private final List<String> sections;
    067
    068        private final List<String> acceptedFormats;
    069
    070        /**
    071         * @param id
    072         *            of the request
    073         * @param updateSequence
    074         * @param acceptedVersions
    075         * @param sections
    076         * @param acceptedFormats
    077         */
    078        public WCTSGetCapabilities( String id, String updateSequence, List<String> acceptedVersions, List<String> sections,
    079                                    List<String> acceptedFormats ) {
    080            super( id, null );
    081            if ( updateSequence == null ) {
    082                updateSequence = new String();
    083            }
    084            if ( acceptedVersions == null ) {
    085                acceptedVersions = new ArrayList<String>();
    086            }
    087            if ( sections == null ) {
    088                sections = new ArrayList<String>();
    089            } else {
    090                String[] secs = new String[sections.size()];
    091                sections.toArray( secs );
    092                for( int i = 0; i< secs.length; ++i ){
    093                    if( secs[i] != null ){
    094                        secs[i] = secs[i].toLowerCase();
    095                    }
    096                }
    097                sections.clear();
    098                sections = Arrays.asList( secs );
    099            }
    100            if ( acceptedFormats == null ) {
    101                acceptedFormats = new ArrayList<String>();
    102            }
    103            this.updateSequence = updateSequence;
    104            this.acceptedVersions = acceptedVersions;
    105            this.sections = sections;
    106
    107            this.acceptedFormats = acceptedFormats;
    108        }
    109
    110        /**
    111         * @return the updateSequence, can be empty but never <code>null</code>
    112         */
    113        public final String getUpdateSequence() {
    114            return updateSequence;
    115        }
    116
    117        /**
    118         * @return the acceptedVersions, can be empty but never <code>null</code>
    119         */
    120        public final List<String> getAcceptedVersions() {
    121            return acceptedVersions;
    122        }
    123
    124        /**
    125         * @return the sections, can be empty but never <code>null</code>, all sections are lower cased.
    126         */
    127        public final List<String> getSections() {
    128            return sections;
    129        }
    130
    131        /**
    132         * @return the acceptedFormats, can be empty but never <code>null</code>
    133         */
    134        public final List<String> getAcceptedFormats() {
    135            return acceptedFormats;
    136        }
    137
    138        /**
    139         * Create a {@link WCTSGetCapabilities}-request by extracting the values from the map, and calling the constructor
    140         * with these values.
    141         *
    142         * @param requestID
    143         *            service internal id for this request.
    144         * @param map
    145         *            to extract requested values from.
    146         * @return the bean representation
    147         * @throws OGCWebServiceException
    148         *             if the map is <code>null</code> or has size==0, or the service,request parameters have none
    149         *             accepted values.
    150         */
    151        public static WCTSGetCapabilities create( String requestID, Map<String, String> map )
    152                                                                                             throws OGCWebServiceException {
    153            if ( map == null || map.size() == 0 ) {
    154                throw new OGCWebServiceException( Messages.getMessage( "WCTS_REQUESTMAP_NULL" ),
    155                                                  ExceptionCode.MISSINGPARAMETERVALUE );
    156            }
    157            String service = map.get( "SERVICE" );
    158            if ( service == null || !"WCTS".equals( service ) ) {
    159                throw new OGCWebServiceException( Messages.getMessage( "WCTS_NO_VERSION_KVP", service ),
    160                                                  ExceptionCode.MISSINGPARAMETERVALUE );
    161            }
    162            String request = map.get( "REQUEST" );
    163            if ( request == null || !"getcapabilities".equalsIgnoreCase( request ) ) {
    164                throw new OGCWebServiceException( Messages.getMessage( "WCTS_NO_REQUEST_KVP", "GetCapabilities" ),
    165                                                  ( request == null ? ExceptionCode.MISSINGPARAMETERVALUE
    166                                                                   : ExceptionCode.OPERATIONNOTSUPPORTED ) );
    167            }
    168
    169            String tmp = map.get( "ACCEPTVERSIONS" );
    170            List<String> acceptedVersions = new ArrayList<String>(10);
    171            if( tmp != null && !"".equals( tmp.trim() ) ){
    172                String[] splitter = tmp.split( ",");
    173                for( String split : splitter ){
    174                    if( split != null && !"".equals( split.trim() ) ){
    175                        acceptedVersions.add( split.trim() );
    176                    }
    177                }
    178            }
    179
    180            tmp = map.get( "SECTIONS" );
    181            List<String> sections = new ArrayList<String>(10);
    182            if( tmp != null && !"".equals( tmp.trim() ) ){
    183                String[] splitter = tmp.split( ",");
    184                for( String split : splitter ){
    185                    if( split != null && !"".equals( split.trim() ) ){
    186                        sections.add( split.trim() );
    187                    }
    188                }
    189            }
    190
    191            tmp = map.get( "ACCEPTFORMATS" );
    192            List<String> acceptedFormats = new ArrayList<String>(10);
    193            if( tmp != null && !"".equals( tmp.trim() ) ){
    194                String[] splitter = tmp.split( ",");
    195                for( String split : splitter ){
    196                    if( split != null && !"".equals( split.trim() ) ){
    197                        acceptedFormats.add( split.trim() );
    198                    }
    199                }
    200
    201            }
    202
    203            String updateSequence = map.get( "UPDATESEQUENCE" );
    204
    205            return new WCTSGetCapabilities( requestID, updateSequence, acceptedVersions, sections, acceptedFormats );
    206        }
    207
    208    }