001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wfs/operation/AbstractWFSRequestDocument.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 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 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.wfs.operation;
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.datatypes.QualifiedName;
051 import org.deegree.framework.xml.XMLParsingException;
052 import org.deegree.framework.xml.XMLTools;
053 import org.deegree.i18n.Messages;
054 import org.deegree.ogcbase.OGCDocument;
055 import org.deegree.ogcwebservices.wfs.WFService;
056 import org.w3c.dom.Element;
057
058 /**
059 * Abstract base class for WFS request documents / parsers.
060 *
061 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
062 * @author last edited by: $Author: apoth $
063 *
064 * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
065 */
066 public class AbstractWFSRequestDocument extends OGCDocument {
067
068 private static final long serialVersionUID = -3826447710328793808L;
069
070 private static String SERVICE_NAME = "WFS";
071
072 /**
073 * Checks that the "service" attribute in the root node matches the expected value (WFS).
074 *
075 * @throws XMLParsingException
076 */
077 protected void checkServiceAttribute()
078 throws XMLParsingException {
079 String service = XMLTools.getNodeAsString( getRootElement(), "@service", nsContext,
080 SERVICE_NAME );
081 if ( !SERVICE_NAME.equals( service ) ) {
082 throw new XMLParsingException( "Service attribute must be '" + SERVICE_NAME + "'." );
083 }
084 }
085
086 /**
087 * Parses and checks the "version" attribute in the root node (can be "1.0.0" or "1.1.0"). If it is not
088 * present, "1.1.0" is returned.
089 *
090 * @return version
091 * @throws XMLParsingException
092 */
093 protected String checkVersionAttribute()
094 throws XMLParsingException {
095 String version = XMLTools.getNodeAsString( this.getRootElement(), "@version", nsContext,
096 WFService.VERSION );
097 if ( !WFService.VERSION.equals( version ) && !"1.0.0".equals( version ) ) {
098 String msg = Messages.getMessage( "WFS_REQUEST_UNSUPPORTED_VERSION", version,
099 "1.0.0 and " + WFService.VERSION );
100 throw new XMLParsingException( msg );
101 }
102 return version;
103 }
104
105 /**
106 * Transform an array of strings to an array of qualified names.
107 *
108 * TODO adapt style (parseXYZ)
109 *
110 * @param values
111 * @param element
112 * @return QualifiedNames
113 * @throws XMLParsingException
114 */
115 protected QualifiedName[] transformToQualifiedNames( String[] values, Element element )
116 throws XMLParsingException {
117 QualifiedName[] typeNames = new QualifiedName[values.length];
118 for ( int i = 0; i < values.length; i++ ) {
119 int idx = values[i].indexOf( ":" );
120 if ( idx != -1 ) {
121 String prefix = values[i].substring( 0, idx );
122 String name = values[i].substring( idx + 1 );
123 URI uri;
124 try {
125 uri = XMLTools.getNamespaceForPrefix( prefix, element );
126 } catch ( URISyntaxException e ) {
127 throw new XMLParsingException( e.getMessage(), e );
128 }
129 typeNames[i] = new QualifiedName( prefix, name, uri );
130 } else {
131 typeNames[i] = new QualifiedName( values[i] );
132 }
133 }
134 return typeNames;
135 }
136
137 protected Map<String, String> parseDRMParams( Element root )
138 throws XMLParsingException {
139 String user = XMLTools.getNodeAsString( root, "@user", nsContext, null );
140 String password = XMLTools.getNodeAsString( root, "@password", nsContext, null );
141 String sessionID = XMLTools.getNodeAsString( root, "@sessionID", nsContext, null );
142 Map<String, String> vendorSpecificParam = new HashMap<String, String>();
143 vendorSpecificParam.put( "USER", user );
144 vendorSpecificParam.put( "PASSWORD", password );
145 vendorSpecificParam.put( "SESSIONID", sessionID );
146 return vendorSpecificParam;
147 }
148 }