001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/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 08:22:25 -0800 (Thu, 27 Dec 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,
076: Map<String, String> vendorSpecificParameter) {
077: super (version, id, vendorSpecificParameter);
078: }
079:
080: /**
081: * returns 'CSW' as service name
082: */
083: public String getServiceName() {
084: return "CSW";
085: }
086:
087: /**
088: * Extracts the namespace-mappings from the given parameter as specified for the
089: * NAMESPACE-parameter in the KVP-encoding.
090: * <p>
091: * Please note that the expected syntax of the CSW NAMESPACE parameter differs from the
092: * NAMESPACE parameter used in the WFS specification.
093: *
094: * @param nsString
095: * contains a list of [prefix:]uri-entries, the entries of the list are separated by
096: * the ','-character
097: * @return keys are Strings (prefixes), values are URIs
098: * @throws InvalidParameterValueException
099: */
100: protected static Map<String, URI> getNSMappings(String nsString)
101: throws InvalidParameterValueException {
102: Map<String, URI> map = new HashMap<String, URI>();
103: if (nsString != null) {
104: String[] mappings = StringTools.toArray(nsString, ",",
105: false);
106: for (int i = 0; i < mappings.length; i++) {
107: int idx = mappings[i].indexOf(":");
108: String prefix = "";
109: String value = null;
110: if (idx == -1) {
111: value = mappings[i];
112: } else {
113: prefix = mappings[i].substring(0, idx);
114: if (idx == mappings[i].length() - 1) {
115: throw new InvalidParameterValueException(
116: "Value '"
117: + nsString
118: + "' for parameter NAMESPACE is invalid: Prefix "
119: + prefix
120: + " is mapped to an empty namespace.");
121: }
122: value = mappings[i].substring(idx + 1, mappings[i]
123: .length());
124: }
125: URI uri = null;
126: try {
127: uri = new URI(value);
128: } catch (URISyntaxException e) {
129: throw new InvalidParameterValueException(
130: "Value '"
131: + nsString
132: + "' for parameter NAMESPACE is invalid: Prefix "
133: + prefix
134: + " is not mapped to a valid URI.");
135: }
136: map.put(prefix, uri);
137: }
138: }
139: return map;
140: }
141: }
|