001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/csw/capabilities/CatalogueGetCapabilitiesDocument.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.csw.capabilities; 044 045 import java.util.HashMap; 046 047 import org.deegree.framework.xml.ElementList; 048 import org.deegree.framework.xml.XMLParsingException; 049 import org.deegree.framework.xml.XMLTools; 050 import org.deegree.i18n.Messages; 051 import org.deegree.ogcbase.CommonNamespaces; 052 import org.deegree.ogcbase.OGCDocument; 053 import org.deegree.ogcwebservices.InvalidParameterValueException; 054 import org.deegree.ogcwebservices.csw.CSWPropertiesAccess; 055 import org.w3c.dom.Element; 056 057 /** 058 * Parser for "csw:GetCapabilities" requests. 059 * 060 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a> 061 * 062 * @author last edited by: $Author: apoth $ 063 * 064 * @version 2.0, $Revision: 9386 $, $Date: 2008-01-03 17:02:25 +0100 (Do, 03 Jan 2008) $ 065 * 066 * @since 2.0 067 */ 068 public class CatalogueGetCapabilitiesDocument extends OGCDocument { 069 070 private static final long serialVersionUID = -7155778875151820291L; 071 072 /** 073 * Parses the underlying document into a <code>GetCapabilities</code> request object. 074 * 075 * @param id 076 * @return corresponding <code>GetCapabilities</code> object 077 * @throws XMLParsingException 078 * @throws InvalidParameterValueException 079 * @throws InvalidParameterValueException 080 */ 081 public CatalogueGetCapabilities parse( String id ) 082 throws XMLParsingException, InvalidParameterValueException { 083 084 String version = CSWPropertiesAccess.getString( "DEFAULTVERSION" ); 085 String service = null; 086 String updateSeq = null; 087 String[] acceptVersions = null; 088 String[] acceptFormats = null; 089 String[] sections = null; 090 Element root = this.getRootElement(); 091 092 // 'service'-attribute (required, must be CSW) 093 service = XMLTools.getAttrValue( root, null, "service", null ); 094 if ( service == null ) { 095 throw new XMLParsingException( "Mandatory attribute 'service' is missing" ); 096 } else if ( !service.equals( "CSW" ) ) { 097 throw new XMLParsingException( "Attribute 'service' must be 'CSW'" ); 098 } 099 // 'updateSequence'-attribute (optional) 100 updateSeq = XMLTools.getAttrValue( root, null, "updateSequence", null ); 101 102 // '<csw:AcceptVersions>'-element (optional) 103 Element acceptVersionsElement = XMLTools.getChildElement( "AcceptVersions", CommonNamespaces.CSWNS, root ); 104 if ( acceptVersionsElement != null ) { 105 acceptVersions = XMLTools.getRequiredNodesAsStrings( acceptVersionsElement, "csw:Version", nsContext ); 106 version = CatalogueGetCapabilities.validateVersion( acceptVersions ); 107 if ( version == null ) { 108 throw new InvalidParameterValueException( Messages.get( "CSW_UNSUPPORTED_VERSION" ) ); 109 } 110 } 111 LOG.logInfo( "process with version:", version ); 112 113 // '<csw:AcceptFormats>'-element (optional) 114 Element acceptFormatsElement = XMLTools.getChildElement( "AcceptFormats", CommonNamespaces.CSWNS, root ); 115 if ( acceptFormatsElement != null ) { 116 ElementList formatsList = XMLTools.getChildElements( "OutputFormat", CommonNamespaces.CSWNS, 117 acceptFormatsElement ); 118 acceptFormats = new String[formatsList.getLength()]; 119 for ( int i = 0; i < acceptFormats.length; i++ ) { 120 acceptFormats[i] = XMLTools.getStringValue( formatsList.item( i ) ); 121 } 122 } 123 124 // '<csw:Sections>'-element (optional) 125 Element sectionsElement = XMLTools.getChildElement( "Sections", CommonNamespaces.CSWNS, root ); 126 if ( sectionsElement != null ) { 127 ElementList sectionList = XMLTools.getChildElements( "Section", CommonNamespaces.CSWNS, sectionsElement ); 128 sections = new String[sectionList.getLength()]; 129 for ( int i = 0; i < sections.length; i++ ) { 130 sections[i] = XMLTools.getStringValue( sectionList.item( i ) ); 131 } 132 } 133 134 return new CatalogueGetCapabilities( id, updateSeq, version, acceptVersions, acceptFormats, sections, 135 new HashMap<String, String>() ); 136 } 137 138 }