001: //$HeadURL: $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.ogcwebservices.wcts.operation;
040:
041: import java.util.ArrayList;
042: import java.util.Arrays;
043: import java.util.List;
044: import java.util.Map;
045:
046: import org.deegree.i18n.Messages;
047: import org.deegree.ogcbase.ExceptionCode;
048: import org.deegree.ogcwebservices.OGCWebServiceException;
049:
050: /**
051: * <code>WCTSGetCapabilities</code> bean representation of a GetCapabilities request, xml-dom or kvp encoded.
052: *
053: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
054: *
055: * @author last edited by: $Author:$
056: *
057: * @version $Revision:$, $Date:$
058: *
059: */
060: public class WCTSGetCapabilities extends WCTSRequestBase {
061:
062: private static final long serialVersionUID = 6951749192378539154L;
063:
064: private final String updateSequence;
065:
066: private final List<String> acceptedVersions;
067:
068: private final List<String> sections;
069:
070: private final List<String> acceptedFormats;
071:
072: /**
073: * @param id
074: * of the request
075: * @param updateSequence
076: * @param acceptedVersions
077: * @param sections
078: * @param acceptedFormats
079: */
080: public WCTSGetCapabilities(String id, String updateSequence,
081: List<String> acceptedVersions, List<String> sections,
082: List<String> acceptedFormats) {
083: super (id, null);
084: if (updateSequence == null) {
085: updateSequence = new String();
086: }
087: if (acceptedVersions == null) {
088: acceptedVersions = new ArrayList<String>();
089: }
090: if (sections == null) {
091: sections = new ArrayList<String>();
092: } else {
093: String[] secs = new String[sections.size()];
094: sections.toArray(secs);
095: for (int i = 0; i < secs.length; ++i) {
096: if (secs[i] != null) {
097: secs[i] = secs[i].toLowerCase();
098: }
099: }
100: sections.clear();
101: sections = Arrays.asList(secs);
102: }
103: if (acceptedFormats == null) {
104: acceptedFormats = new ArrayList<String>();
105: }
106: this .updateSequence = updateSequence;
107: this .acceptedVersions = acceptedVersions;
108: this .sections = sections;
109:
110: this .acceptedFormats = acceptedFormats;
111: }
112:
113: /**
114: * @return the updateSequence, can be empty but never <code>null</code>
115: */
116: public final String getUpdateSequence() {
117: return updateSequence;
118: }
119:
120: /**
121: * @return the acceptedVersions, can be empty but never <code>null</code>
122: */
123: public final List<String> getAcceptedVersions() {
124: return acceptedVersions;
125: }
126:
127: /**
128: * @return the sections, can be empty but never <code>null</code>, all sections are lower cased.
129: */
130: public final List<String> getSections() {
131: return sections;
132: }
133:
134: /**
135: * @return the acceptedFormats, can be empty but never <code>null</code>
136: */
137: public final List<String> getAcceptedFormats() {
138: return acceptedFormats;
139: }
140:
141: /**
142: * Create a {@link WCTSGetCapabilities}-request by extracting the values from the map, and calling the constructor
143: * with these values.
144: *
145: * @param requestID
146: * service internal id for this request.
147: * @param map
148: * to extract requested values from.
149: * @return the bean representation
150: * @throws OGCWebServiceException
151: * if the map is <code>null</code> or has size==0, or the service,request parameters have none
152: * accepted values.
153: */
154: public static WCTSGetCapabilities create(String requestID,
155: Map<String, String> map) throws OGCWebServiceException {
156: if (map == null || map.size() == 0) {
157: throw new OGCWebServiceException(Messages
158: .getMessage("WCTS_REQUESTMAP_NULL"),
159: ExceptionCode.MISSINGPARAMETERVALUE);
160: }
161: String service = map.get("SERVICE");
162: if (service == null || !"WCTS".equals(service)) {
163: throw new OGCWebServiceException(Messages.getMessage(
164: "WCTS_NO_VERSION_KVP", service),
165: ExceptionCode.MISSINGPARAMETERVALUE);
166: }
167: String request = map.get("REQUEST");
168: if (request == null
169: || !"getcapabilities".equalsIgnoreCase(request)) {
170: throw new OGCWebServiceException(
171: Messages.getMessage("WCTS_NO_REQUEST_KVP",
172: "GetCapabilities"),
173: (request == null ? ExceptionCode.MISSINGPARAMETERVALUE
174: : ExceptionCode.OPERATIONNOTSUPPORTED));
175: }
176:
177: String tmp = map.get("ACCEPTVERSIONS");
178: List<String> acceptedVersions = new ArrayList<String>(10);
179: if (tmp != null && !"".equals(tmp.trim())) {
180: String[] splitter = tmp.split(",");
181: for (String split : splitter) {
182: if (split != null && !"".equals(split.trim())) {
183: acceptedVersions.add(split.trim());
184: }
185: }
186: }
187:
188: tmp = map.get("SECTIONS");
189: List<String> sections = new ArrayList<String>(10);
190: if (tmp != null && !"".equals(tmp.trim())) {
191: String[] splitter = tmp.split(",");
192: for (String split : splitter) {
193: if (split != null && !"".equals(split.trim())) {
194: sections.add(split.trim());
195: }
196: }
197: }
198:
199: tmp = map.get("ACCEPTFORMATS");
200: List<String> acceptedFormats = new ArrayList<String>(10);
201: if (tmp != null && !"".equals(tmp.trim())) {
202: String[] splitter = tmp.split(",");
203: for (String split : splitter) {
204: if (split != null && !"".equals(split.trim())) {
205: acceptedFormats.add(split.trim());
206: }
207: }
208:
209: }
210:
211: String updateSequence = map.get("UPDATESEQUENCE");
212:
213: return new WCTSGetCapabilities(requestID, updateSequence,
214: acceptedVersions, sections, acceptedFormats);
215: }
216:
217: }
|