001 //$HeadURL$
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.csw.discovery;
038
039 import java.io.IOException;
040 import java.net.URL;
041 import java.util.Map;
042
043 import org.deegree.framework.util.StringTools;
044 import org.deegree.framework.xml.XMLTools;
045 import org.deegree.i18n.Messages;
046 import org.deegree.ogcbase.ExceptionCode;
047 import org.deegree.ogcwebservices.InvalidParameterValueException;
048 import org.deegree.ogcwebservices.OGCWebServiceException;
049 import org.w3c.dom.Node;
050 import org.xml.sax.SAXException;
051
052 /**
053 *
054 *
055 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
056 * @author last edited by: $Author: poth $
057 *
058 * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
059 */
060 public class GetRecordByIdDocument_2_0_2 extends GetRecordByIdDocument {
061
062 private static final long serialVersionUID = 2120122323030885033L;
063
064 private static final String XML_TEMPLATE = "GetRecordByIdTemplate2.0.2.xml";
065
066 @Override
067 GetRecordById parse( String id )
068 throws OGCWebServiceException {
069
070 String version = null;
071 Map<String, String> vendorSpecificParameters = null;
072 String[] ids = null;
073 String elementSetName = null;
074
075 try {
076 // '<csw202:GetRecords>'-element (required)
077 Node contextNode = XMLTools.getRequiredNode( this.getRootElement(), "self::csw202:GetRecordById", nsContext );
078
079 // 'service'-attribute (required, must be CSW)
080 String service = XMLTools.getRequiredNodeAsString( contextNode, "@service", nsContext );
081 if ( !service.equals( "CSW" ) ) {
082 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
083 throw new InvalidParameterValueException( "GetRecordById", "'service' must be 'CSW'", code );
084 }
085
086 // 'version'-attribute (required)
087 version = XMLTools.getRequiredNodeAsString( contextNode, "@version", nsContext );
088 if ( !"2.0.2".equals( version ) ) {
089 throw new OGCWebServiceException( "GetRecordByIdDocument_2_0_2",
090 Messages.getMessage( "CSW_NOT_SUPPORTED_VERSION",
091 GetRecords.DEFAULT_VERSION, "2.0.2", version ),
092 ExceptionCode.INVALIDPARAMETERVALUE );
093 }
094
095 // '<csw:ResponseHandler>'-elements (optional)
096 ids = XMLTools.getNodesAsStrings( contextNode, "csw202:Id", nsContext );
097
098 // '<csw:ElementSetName>'-element (optional)
099 Node elementSetNameElement = XMLTools.getNode( contextNode, "csw202:ElementSetName", nsContext );
100
101 if ( elementSetNameElement != null ) {
102 // must contain one of the values 'brief', 'summary' or
103 // 'full'
104 elementSetName = XMLTools.getRequiredNodeAsString( elementSetNameElement, "text()", nsContext,
105 new String[] { "brief", "summary", "full" } );
106
107 } else {
108 elementSetName = "summary";
109 }
110 // in the future the vendorSpecificParameters
111 vendorSpecificParameters = parseDRMParams( this.getRootElement() );
112 } catch ( Exception e ) {
113 ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
114 throw new OGCWebServiceException( "GetRecordByIdDocument_2_0_2", StringTools.stackTraceToString( e ), code );
115 }
116
117 return new GetRecordById( id, version, vendorSpecificParameters, ids, elementSetName );
118 }
119
120 /*
121 * (non-Javadoc)
122 *
123 * @see org.deegree.framework.xml.XMLFragment#createEmptyDocument()
124 */
125 @Override
126 void createEmptyDocument()
127 throws IOException, SAXException {
128 URL url = GetRecordByIdDocument.class.getResource( XML_TEMPLATE );
129 if ( url == null ) {
130 throw new IOException( "The resource '" + XML_TEMPLATE + " could not be found." );
131 }
132 load( url );
133 }
134
135 }