001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/sos/capabilities/SOSGetCapabilities.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 Aennchenstraße 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 lat/lon GmbH
036 Aennchenstraße 19
037 53177 Bonn
038 Germany
039 E-Mail: greve@giub.uni-bonn.de
040
041 ---------------------------------------------------------------------------*/
042 package org.deegree.ogcwebservices.sos.capabilities;
043
044 import java.util.HashMap;
045 import java.util.Map;
046
047 import org.deegree.framework.util.StringTools;
048 import org.deegree.framework.xml.NamespaceContext;
049 import org.deegree.framework.xml.XMLParsingException;
050 import org.deegree.framework.xml.XMLTools;
051 import org.deegree.ogcbase.CommonNamespaces;
052 import org.deegree.ogcwebservices.OGCWebServiceException;
053 import org.deegree.ogcwebservices.getcapabilities.GetCapabilities;
054 import org.w3c.dom.Document;
055
056 /**
057 * represents a sOs getCapabilities Request
058 *
059 * @author <a href="mailto:mkulbe@lat-lon.de">Matthias Kulbe </a>
060 * @author last edited by: $Author:wanhoff$
061 *
062 * @version $Revision: 9345 $, $Date:20.03.2007$
063 */
064 public class SOSGetCapabilities extends GetCapabilities {
065
066 private static final NamespaceContext nsContext = CommonNamespaces.getNamespaceContext();
067
068 /**
069 * creates a GetCapabilities Request from a KVP Map
070 *
071 * @param map
072 * @return
073 */
074 public static SOSGetCapabilities create( Map<String, String> map ) {
075
076 String id = getParam( "ID", map, "" + System.currentTimeMillis() );
077
078 // optional
079 //String version = getParam( "VERSION", map, null );
080
081 // optional
082 String updateSequence = getParam( "UPDATESEQUENCE", map, null );
083
084 // optional and unbounded
085 String[] sections = null;
086 if ( map.get( "SECTIONS" ) != null ) {
087 String tmp = getParam( "SECTIONS", map, null );
088 sections = StringTools.toArray( tmp, ",", false );
089 }
090
091 // optional and unbounded
092 String[] acceptVersions = null;
093 if ( map.get( "ACCEPTVERSIONS" ) != null ) {
094 String tmp = getParam( "ACCEPTVERSIONS", map, null );
095 acceptVersions = StringTools.toArray( tmp, ",", false );
096 }
097
098 // optional and unbounded
099 String[] acceptFormats = null;
100 if ( map.get( "ACCEPTFORMATS" ) != null ) {
101 String tmp = getParam( "ACCEPTFORMATS", map, null );
102 acceptFormats = StringTools.toArray( tmp, ",", false );
103 }
104
105 return new SOSGetCapabilities( id, updateSequence, acceptVersions, sections, acceptFormats,
106 map );
107
108 }
109
110 /**
111 * creates GetCapabilities Request from XML
112 *
113 * @param id
114 * @param doc
115 * @return
116 * @throws OGCWebServiceException
117 *
118 */
119 public static SOSGetCapabilities create( String id, Document doc )
120 throws OGCWebServiceException {
121
122 try {
123 // optional
124 // String version = XMLTools.getNodeAsString( doc, "ows:GetCapabilities/@version",
125 // nsContext,
126 // null );
127
128 // optional
129 String updateSequence = XMLTools.getNodeAsString(
130 doc,
131 "ows:GetCapabilities/@updateSequence",
132 nsContext, null );
133
134 // optional and unbounded
135 String[] sections = XMLTools.getNodesAsStrings(
136 doc,
137 "ows:GetCapabilities/ows:Sections/ows:Section/text()",
138 nsContext );
139
140 // optional and unbounded
141 String[] acceptVersions = XMLTools.getNodesAsStrings(
142 doc,
143 "ows:GetCapabilities/ows:AcceptVersions/ows:Version/text()",
144 nsContext );
145
146 // optional and unbounded
147 String[] acceptFormats = XMLTools.getNodesAsStrings(
148 doc,
149 "ows:GetCapabilities/ows:AcceptFormats/ows:OutputFormat/text()",
150 nsContext );
151
152 return new SOSGetCapabilities( id, updateSequence, acceptVersions, sections,
153 acceptFormats, new HashMap<String, String>() );
154
155 } catch ( XMLParsingException e ) {
156 e.printStackTrace();
157 throw new OGCWebServiceException( "sos webservice failure" );
158 }
159 }
160
161 /**
162 * creates GetCapabilities Request
163 *
164 * @param sections
165 * @param acceptFormats
166 * @param acceptVersions
167 * @param id
168 * @param updateSequence
169 * @param vendoreSpec
170 * @return
171 *
172 */
173 public static SOSGetCapabilities create( String id, String[] sections, String[] acceptFormats,
174 String[] acceptVersions, String updateSequence,
175 Map<String, String> vendoreSpec ) {
176 return new SOSGetCapabilities( id, updateSequence, acceptVersions, sections, acceptFormats,
177 vendoreSpec );
178 }
179
180 /**
181 * @param id
182 * @param updateSequence
183 * @param acceptVersions
184 * @param sections
185 * @param acceptFormats
186 * @param vendoreSpec
187 */
188 public SOSGetCapabilities( String id, String updateSequence, String[] acceptVersions,
189 String[] sections, String[] acceptFormats,
190 Map<String, String> vendoreSpec ) {
191 super( id, null, updateSequence, acceptVersions, sections, acceptFormats, vendoreSpec );
192 }
193
194 /**
195 * fixed 'SOS'
196 *
197 * @return the String "SOS"
198 */
199 public String getServiceName() {
200 return "SOS";
201 }
202 }