001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/csw/AbstractCSWRequest.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.csw;
037    
038    import java.net.URI;
039    import java.net.URISyntaxException;
040    import java.util.HashMap;
041    import java.util.Map;
042    
043    import org.deegree.framework.util.StringTools;
044    import org.deegree.ogcwebservices.AbstractOGCWebServiceRequest;
045    import org.deegree.ogcwebservices.InvalidParameterValueException;
046    
047    /**
048     * Abstract base class for requests to catalogue services (CSW).
049     *
050     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
051     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
052     *
053     * @author last edited by: $Author: mschneider $
054     *
055     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
056     *
057     * @since 2.0
058     */
059    public class AbstractCSWRequest extends AbstractOGCWebServiceRequest {
060    
061        private static final long serialVersionUID = 726077635012162899L;
062    
063        /**
064         * @param version
065         * @param id
066         * @param vendorSpecificParameter
067         */
068        public AbstractCSWRequest( String version, String id, Map<String, String> vendorSpecificParameter ) {
069            super( version, id, vendorSpecificParameter );
070        }
071    
072        /**
073         * returns 'CSW' as service name
074         */
075        public String getServiceName() {
076            return "CSW";
077        }
078    
079        /**
080         * Extracts the namespace-mappings from the given parameter as specified for the
081         * NAMESPACE-parameter in the KVP-encoding.
082         * <p>
083         * Please note that the expected syntax of the CSW NAMESPACE parameter differs from the
084         * NAMESPACE parameter used in the WFS specification.
085         *
086         * @param nsString
087         *            contains a list of [prefix:]uri-entries, the entries of the list are separated by
088         *            the ','-character
089         * @return keys are Strings (prefixes), values are URIs
090         * @throws InvalidParameterValueException
091         */
092        protected static Map<String, URI> getNSMappings( String nsString )
093                                throws InvalidParameterValueException {
094            Map<String, URI> map = new HashMap<String, URI>();
095            if ( nsString != null ) {
096                String[] mappings = StringTools.toArray( nsString, ",", false );
097                for ( int i = 0; i < mappings.length; i++ ) {
098                    int idx = mappings[i].indexOf( ":" );
099                    String prefix = "";
100                    String value = null;
101                    if ( idx == -1 ) {
102                        value = mappings[i];
103                    } else {
104                        prefix = mappings[i].substring( 0, idx );
105                        if ( idx == mappings[i].length() - 1 ) {
106                            throw new InvalidParameterValueException( "Value '" + nsString
107                                                                      + "' for parameter NAMESPACE is invalid: Prefix "
108                                                                      + prefix + " is mapped to an empty namespace." );
109                        }
110                        value = mappings[i].substring( idx + 1, mappings[i].length() );
111                    }
112                    URI uri = null;
113                    try {
114                        uri = new URI( value );
115                    } catch ( URISyntaxException e ) {
116                        throw new InvalidParameterValueException( "Value '" + nsString
117                                                                  + "' for parameter NAMESPACE is invalid: Prefix "
118                                                                  + prefix + " is not mapped to a valid URI." );
119                    }
120                    map.put( prefix, uri );
121                }
122            }
123            return map;
124        }
125    }