001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wfs/operation/GetGmlObject.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 037 package org.deegree.ogcwebservices.wfs.operation; 038 039 import static java.lang.Integer.parseInt; 040 import static org.deegree.framework.log.LoggerFactory.getLogger; 041 import static org.deegree.framework.xml.XMLTools.getRequiredNodeAsString; 042 import static org.deegree.i18n.Messages.get; 043 import static org.deegree.ogcbase.CommonNamespaces.getNamespaceContext; 044 045 import java.util.Map; 046 047 import org.deegree.framework.log.ILogger; 048 import org.deegree.framework.xml.NamespaceContext; 049 import org.deegree.framework.xml.XMLParsingException; 050 import org.deegree.ogcwebservices.InconsistentRequestException; 051 import org.deegree.ogcwebservices.InvalidParameterValueException; 052 import org.deegree.ogcwebservices.MissingParameterValueException; 053 import org.deegree.ogcwebservices.OGCWebServiceException; 054 import org.deegree.ogcwebservices.OGCWebServiceRequest; 055 import org.w3c.dom.Element; 056 057 /** 058 * <code>GetGmlObject</code> 059 * 060 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a> 061 * @author last edited by: $Author: mschneider $ 062 * 063 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 064 */ 065 public class GetGmlObject extends AbstractWFSRequest { 066 067 private static final long serialVersionUID = 1050888585238239416L; 068 069 private static final NamespaceContext nsContext = getNamespaceContext(); 070 071 private static final ILogger LOG = getLogger( GetGmlObject.class ); 072 073 private int depth; 074 075 private int expiry; 076 077 private String objectId; 078 079 private GetGmlObject( int depth, int expiry, String objectId, String version, String id, String handle, 080 Map<String, String> vendorSpecificParameter ) { 081 super( version, id, handle, vendorSpecificParameter ); 082 this.depth = depth; 083 this.expiry = expiry; 084 this.objectId = objectId; 085 } 086 087 /** 088 * @param map 089 * @return a new request object 090 * @throws MissingParameterValueException 091 * @throws InconsistentRequestException 092 * @throws InvalidParameterValueException 093 */ 094 public static GetGmlObject create( Map<String, String> map ) 095 throws InconsistentRequestException, MissingParameterValueException, 096 InvalidParameterValueException { 097 checkServiceParameter( map ); 098 099 String id = map.get( "ID" ); 100 String version = checkVersionParameter( map ); 101 102 String depth = map.get( "TRAVERSEXLINKDEPTH" ); 103 if ( depth == null || depth.length() == 0 ) { 104 throw new MissingParameterValueException( "traversexlinkdepth", get( "WFS_MISSING_PARAMETER_VALUE", 105 "TRAVERSEXLINKDEPTH" ) ); 106 } 107 int idepth; 108 try { 109 idepth = parseInt( depth ); 110 } catch ( NumberFormatException nfe ) { 111 throw new InvalidParameterValueException( "traversexlinkdepth", get( "WFS_INVALID_PARAMETER_VALUE", 112 "TRAVERSEXLINKDEPTH", depth ) ); 113 } 114 115 String expiry = map.get( "TRAVERSEXLINKEXPIRY" ); 116 int iexpiry = -1; 117 if ( expiry != null && expiry.length() > 0 ) { 118 try { 119 iexpiry = parseInt( expiry ); 120 } catch ( NumberFormatException nfe ) { 121 throw new InvalidParameterValueException( "traversexlinkexpiry", get( "WFS_INVALID_PARAMETER_VALUE", 122 "TRAVERSEXLINKEXPIRY", expiry ) ); 123 } 124 } 125 126 String objectId = map.get( "GMLOBJECTID" ); 127 if ( objectId == null || objectId.length() == 0 ) { 128 throw new MissingParameterValueException( "gmlobjectid", get( "WFS_MISSING_PARAMETER_VALUE", "GMLOBJECTID" ) ); 129 } 130 131 return new GetGmlObject( idepth, iexpiry, objectId, version, id, null, map ); 132 } 133 134 /** 135 * Output format parameter is ignored by this method (it will always be GML3 anyway). 136 * 137 * @param id 138 * @param root 139 * @return a new request 140 * @throws OGCWebServiceException 141 */ 142 public static OGCWebServiceRequest create( String id, Element root ) 143 throws OGCWebServiceException { 144 try { 145 String objectId = getRequiredNodeAsString( root, "ogc:GmlObjectId/@gml:id", nsContext ); 146 String version = root.getAttribute( "version" ); 147 148 String depth = root.getAttribute( "traverseXlinkDepth" ); 149 if ( depth == null || depth.length() == 0 ) { 150 throw new MissingParameterValueException( "traversexlinkdepth", get( "WFS_MISSING_PARAMETER_VALUE", 151 "TRAVERSEXLINKDEPTH" ) ); 152 } 153 int idepth; 154 try { 155 idepth = parseInt( depth ); 156 } catch ( NumberFormatException nfe ) { 157 throw new InvalidParameterValueException( "traversexlinkdepth", get( "WFS_INVALID_PARAMETER_VALUE", 158 "TRAVERSEXLINKDEPTH", depth ) ); 159 } 160 161 String expiry = root.getAttribute( "traverseXlinkExpiry" ); 162 int iexpiry = -1; 163 if ( expiry != null && expiry.length() > 0 ) { 164 try { 165 iexpiry = parseInt( expiry ); 166 } catch ( NumberFormatException nfe ) { 167 throw new InvalidParameterValueException( "traversexlinkexpiry", 168 get( "WFS_INVALID_PARAMETER_VALUE", 169 "TRAVERSEXLINKEXPIRY", expiry ) ); 170 } 171 } 172 173 return new GetGmlObject( idepth, iexpiry, objectId, version, id, null, null ); 174 } catch ( XMLParsingException e ) { 175 LOG.logDebug( "Stack trace: ", e ); 176 throw new OGCWebServiceException( "getgmlobject", get( "WFS_REQUEST_NOT_PARSED", e.getMessage() ) ); 177 } 178 } 179 180 /** 181 * @return the TRAVERSEXLINKDEPTH parameter value 182 */ 183 public int getXLinkDepth() { 184 return depth; 185 } 186 187 /** 188 * @return the TRAVERSEXLINKEXPIRY parameter value, or -1 if not set 189 */ 190 public int getXLinkExpiry() { 191 return expiry; 192 } 193 194 /** 195 * @return the GMLOBJECTID parameter value 196 */ 197 public String getObjectId() { 198 return objectId; 199 } 200 201 }