001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/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 08:22:25 -0800 (Thu, 27 Dec 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() throws XMLParsingException {
078: String service = XMLTools.getNodeAsString(getRootElement(),
079: "@service", nsContext, SERVICE_NAME);
080: if (!SERVICE_NAME.equals(service)) {
081: throw new XMLParsingException("Service attribute must be '"
082: + 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() throws XMLParsingException {
094: String version = XMLTools.getNodeAsString(
095: this .getRootElement(), "@version", nsContext,
096: WFService.VERSION);
097: if (!WFService.VERSION.equals(version)
098: && !"1.0.0".equals(version)) {
099: String msg = Messages.getMessage(
100: "WFS_REQUEST_UNSUPPORTED_VERSION", version,
101: "1.0.0 and " + WFService.VERSION);
102: throw new XMLParsingException(msg);
103: }
104: return version;
105: }
106:
107: /**
108: * Transform an array of strings to an array of qualified names.
109: *
110: * TODO adapt style (parseXYZ)
111: *
112: * @param values
113: * @param element
114: * @return QualifiedNames
115: * @throws XMLParsingException
116: */
117: protected QualifiedName[] transformToQualifiedNames(
118: String[] values, Element element)
119: throws XMLParsingException {
120: QualifiedName[] typeNames = new QualifiedName[values.length];
121: for (int i = 0; i < values.length; i++) {
122: int idx = values[i].indexOf(":");
123: if (idx != -1) {
124: String prefix = values[i].substring(0, idx);
125: String name = values[i].substring(idx + 1);
126: URI uri;
127: try {
128: uri = XMLTools.getNamespaceForPrefix(prefix,
129: element);
130: } catch (URISyntaxException e) {
131: throw new XMLParsingException(e.getMessage(), e);
132: }
133: typeNames[i] = new QualifiedName(prefix, name, uri);
134: } else {
135: typeNames[i] = new QualifiedName(values[i]);
136: }
137: }
138: return typeNames;
139: }
140:
141: protected Map<String, String> parseDRMParams(Element root)
142: throws XMLParsingException {
143: String user = XMLTools.getNodeAsString(root, "@user",
144: nsContext, null);
145: String password = XMLTools.getNodeAsString(root, "@password",
146: nsContext, null);
147: String sessionID = XMLTools.getNodeAsString(root, "@sessionID",
148: nsContext, null);
149: Map<String, String> vendorSpecificParam = new HashMap<String, String>();
150: vendorSpecificParam.put("USER", user);
151: vendorSpecificParam.put("PASSWORD", password);
152: vendorSpecificParam.put("SESSIONID", sessionID);
153: return vendorSpecificParam;
154: }
155: }
|