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