001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wfs/operation/AbstractWFSRequestDocument.java $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 Department of Geography, University of Bonn 006 and 007 lat/lon GmbH 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 package org.deegree.ogcwebservices.wfs.operation; 037 038 import java.net.URI; 039 import java.net.URISyntaxException; 040 import java.util.HashMap; 041 import java.util.Map; 042 043 import org.deegree.datatypes.QualifiedName; 044 import org.deegree.framework.xml.XMLParsingException; 045 import org.deegree.framework.xml.XMLTools; 046 import org.deegree.i18n.Messages; 047 import org.deegree.ogcbase.OGCDocument; 048 import org.deegree.ogcwebservices.InvalidParameterValueException; 049 import org.deegree.ogcwebservices.wfs.WFService; 050 import org.w3c.dom.Element; 051 052 /** 053 * Abstract base class for WFS request documents / parsers. 054 * 055 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a> 056 * @author last edited by: $Author: mschneider $ 057 * 058 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 059 */ 060 public class AbstractWFSRequestDocument extends OGCDocument { 061 062 private static final long serialVersionUID = -3826447710328793808L; 063 064 private static String SERVICE_NAME = "WFS"; 065 066 /** 067 * Checks that the "service" attribute in the root node matches the expected value (WFS). 068 * 069 * @throws XMLParsingException 070 */ 071 protected void checkServiceAttribute() 072 throws InvalidParameterValueException, XMLParsingException { 073 String service = XMLTools.getNodeAsString( getRootElement(), "@service", nsContext, SERVICE_NAME ); 074 if ( service.equals( "" ) ) { 075 service = SERVICE_NAME; 076 } 077 if ( !SERVICE_NAME.equals( service ) ) { 078 throw new InvalidParameterValueException( "service", "Service attribute must be '" + SERVICE_NAME + "'." ); 079 } 080 } 081 082 /** 083 * Parses and checks the "version" attribute in the root node (can be "1.0.0" or "1.1.0"). If it is not present, 084 * "1.1.0" is returned. 085 * 086 * @return version 087 * @throws XMLParsingException 088 */ 089 protected String checkVersionAttribute() 090 throws XMLParsingException, InvalidParameterValueException { 091 String version = XMLTools.getNodeAsString( this.getRootElement(), "@version", nsContext, WFService.VERSION ); 092 if ( version.equals( "" ) ) { 093 version = WFService.VERSION; 094 } 095 if ( !WFService.VERSION.equals( version ) && !"1.0.0".equals( version ) ) { 096 String msg = Messages.getMessage( "WFS_REQUEST_UNSUPPORTED_VERSION", version, "1.0.0 and " 097 + WFService.VERSION ); 098 throw new InvalidParameterValueException( "version", msg ); 099 } 100 return version; 101 } 102 103 /** 104 * Transform an array of strings to an array of qualified names. 105 * 106 * TODO adapt style (parseXYZ) 107 * 108 * @param values 109 * @param element 110 * @return QualifiedNames 111 * @throws XMLParsingException 112 */ 113 protected QualifiedName[] transformToQualifiedNames( String[] values, Element element ) 114 throws XMLParsingException { 115 QualifiedName[] typeNames = new QualifiedName[values.length]; 116 for ( int i = 0; i < values.length; i++ ) { 117 int idx = values[i].indexOf( ":" ); 118 if ( idx != -1 ) { 119 String prefix = values[i].substring( 0, idx ); 120 String name = values[i].substring( idx + 1 ); 121 URI uri; 122 try { 123 uri = XMLTools.getNamespaceForPrefix( prefix, element ); 124 } catch ( URISyntaxException e ) { 125 throw new XMLParsingException( e.getMessage(), e ); 126 } 127 typeNames[i] = new QualifiedName( prefix, name, uri ); 128 } else { 129 typeNames[i] = new QualifiedName( values[i] ); 130 } 131 } 132 return typeNames; 133 } 134 135 protected Map<String, String> parseDRMParams( Element root ) 136 throws XMLParsingException { 137 String user = XMLTools.getNodeAsString( root, "@user", nsContext, null ); 138 String password = XMLTools.getNodeAsString( root, "@password", nsContext, null ); 139 String sessionID = XMLTools.getNodeAsString( root, "@sessionID", nsContext, null ); 140 Map<String, String> vendorSpecificParam = new HashMap<String, String>(); 141 vendorSpecificParam.put( "USER", user ); 142 vendorSpecificParam.put( "PASSWORD", password ); 143 vendorSpecificParam.put( "SESSIONID", sessionID ); 144 return vendorSpecificParam; 145 } 146 }