    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.csw.discovery;
    038
    039    import java.net.URI;
    040    import java.net.URISyntaxException;
    041    import java.util.Map;
    042
    043    import org.deegree.framework.log.ILogger;
    044    import org.deegree.framework.log.LoggerFactory;
    045    import org.deegree.i18n.Messages;
    046    import org.deegree.ogcwebservices.OGCRequestFactory;
    047    import org.deegree.ogcwebservices.OGCWebServiceException;
    048    import org.deegree.ogcwebservices.csw.AbstractCSWRequest;
    049    import org.deegree.ogcwebservices.csw.CSWExceptionCode;
    050
    051    /**
    052     * The <code>GetRepositoryItem</code> class encapsulates the data of a request for a repository
    053     * item.
    054     *
    055     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
    056     *
    057     * @author last edited by: $Author:$
    058     *
    059     * @version $Revision:$, $Date:$
    060     *
    061     */
    062
    063    public class GetRepositoryItem extends AbstractCSWRequest {
    064
    065        /**
    066         *
    067         */
    068        private static final long serialVersionUID = 6140080070986019397L;
    069
    070        private static ILogger LOG = LoggerFactory.getLogger( GetRepositoryItem.class );
    071
    072        private URI reposItem;
    073
    074        private String service;
    075
    076        /**
    077         * Creates a new <code>GetRepositoryItem</code> instance.
    078         *
    079         * @param id
    080         * @param version
    081         * @param vendorSpecificParameters
    082         * @param reposItem
    083         *            some uri identifying some ebrim extrinsic object
    084         */
    085        public GetRepositoryItem( String id, String version, Map<String, String> vendorSpecificParameters, URI reposItem ) {
    086            super( version, id, vendorSpecificParameters );
    087            this.service = OGCRequestFactory.CSW_SERVICE_NAME_EBRIM;
    088            this.reposItem = reposItem;
    089        }
    090
    091        /**
    092         * @param id
    093         *            of the request
    094         * @param version
    095         *            of the csw
    096         */
    097        public GetRepositoryItem( String id, String version ) {
    098            super( version, id, null );
    099        }
    100
    101        /**
    102         * Creates a new <code>GetRepositoryItem</code> instance from the values stored in the
    103         * submitted Map. Keys (parameter names) in the Map must be uppercase.
    104         *
    105         * @TODO evaluate vendorSpecificParameter
    106         *
    107         * @param kvp
    108         *            Map containing the parameters
    109         * @return a GetRepositoryItem instance with given id and values from the kvp
    110         * @exception OGCWebServiceException
    111         */
    112        public static GetRepositoryItem create( Map<String, String> kvp )
    113                                throws OGCWebServiceException {
    114
    115            String service = getRequiredParam( "SERVICE", kvp );
    116            if ( !OGCRequestFactory.CSW_SERVICE_NAME_EBRIM.equals( service ) ) {
    117                throw new OGCWebServiceException( Messages.getMessage( "CSW_INVALID_REQUEST_PARAM", "service",
    118                                                                       OGCRequestFactory.CSW_SERVICE_NAME_EBRIM, service ),
    119                                                  CSWExceptionCode.WRS_INVALIDREQUEST );
    120            }
    121
    122            String request = getRequiredParam( "REQUEST", kvp );
    123            if ( !"GetRepositoryItem".equals( request ) ) {
    124                throw new OGCWebServiceException( Messages.getMessage( "CSW_INVALID_REQUEST_PARAM", "request",
    125                                                                       "GetRepositoryItem", request ),
    126                                                  CSWExceptionCode.WRS_INVALIDREQUEST );
    127            }
    128
    129            String requestID = getParam( "REQUESTID", kvp, "0" );
    130
    131            String id = getRequiredParam( "ID", kvp );
    132            URI reposItem = null;
    133            try {
    134                reposItem = new URI( id );
    135            } catch ( URISyntaxException urise ) {
    136                throw new OGCWebServiceException( Messages.getMessage( "CSW_INVALID_REQUEST_PARAM", "id",
    137                                                                       "some kind of valid repository URI", id ),
    138                                                  CSWExceptionCode.WRS_INVALIDREQUEST );
    139            }
    140            LOG.logDebug( "GetRepositoryItem id=" + reposItem );
    141
    142            // for GetRepositoryItem default version is 2.0.1 because ebRIM profile set up
    143            // on CSW 2.0.1 specification
    144            String version = getParam( "REQUESTID", kvp, "2.0.1" );
    145
    146            return new GetRepositoryItem( requestID, version, kvp, reposItem );
    147        }
    148
    149        /**
    150         * @return the value 'urn:x-ogc:specification:cswebrim:Service:OGC-CSW:ebRIM'
    151         */
    152        @Override
    153        public String getServiceName() {
    154            return service;
    155        }
    156
    157        /**
    158         * @return the requested repository Item's id.
    159         */
    160        public URI getRepositoryItemID() {
    161            return reposItem;
    162        }
    163    }