001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/csw/capabilities/CatalogueGetCapabilitiesDocument.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2007 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.ogcbase.CommonNamespaces;
051 import org.deegree.ogcbase.OGCDocument;
052 import org.deegree.ogcwebservices.InvalidParameterValueException;
053 import org.w3c.dom.Element;
054
055 /**
056 * Parser for "csw:GetCapabilities" requests.
057 *
058 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
059 *
060 * @author last edited by: $Author: apoth $
061 *
062 * @version 2.0, $Revision: 6845 $, $Date: 2007-05-07 11:28:14 +0200 (Mo, 07 Mai 2007) $
063 *
064 * @since 2.0
065 */
066 public class CatalogueGetCapabilitiesDocument extends OGCDocument {
067
068 private static final long serialVersionUID = -7155778875151820291L;
069
070 /**
071 * Parses the underlying document into a <code>GetCapabilities</code> request object.
072 *
073 * @param id
074 * @return corresponding <code>GetCapabilities</code> object
075 * @throws XMLParsingException
076 * @throws InvalidParameterValueException
077 */
078 public CatalogueGetCapabilities parse( String id )
079 throws XMLParsingException {
080
081 String version = "2.0.0";
082 String service = null;
083 String updateSeq = null;
084 String[] acceptVersions = null;
085 String[] acceptFormats = null;
086 String[] sections = null;
087 Element root = this.getRootElement();
088
089 // 'service'-attribute (required, must be CSW)
090 service = XMLTools.getAttrValue( root, null, "service", null );
091 if ( service == null ) {
092 throw new XMLParsingException( "Mandatory attribute 'service' is missing" );
093 } else if ( !service.equals( "CSW" ) ) {
094 throw new XMLParsingException( "Attribute 'service' must be 'CSW'" );
095 }
096 // 'updateSequence'-attribute (optional)
097 updateSeq = XMLTools.getAttrValue( root, null, "updateSequence", null );
098
099 // '<csw:AcceptVersions>'-element (optional)
100 Element acceptVersionsElement = XMLTools.getChildElement( "AcceptVersions", CommonNamespaces.CSWNS, root );
101 if ( acceptVersionsElement != null ) {
102 acceptVersions = XMLTools.getRequiredNodesAsStrings( acceptVersionsElement, "csw:Version", nsContext );
103 }
104
105 // '<csw:AcceptFormats>'-element (optional)
106 Element acceptFormatsElement = XMLTools.getChildElement( "AcceptFormats", CommonNamespaces.CSWNS, root );
107 if ( acceptFormatsElement != null ) {
108 ElementList formatsList = XMLTools.getChildElements( "OutputFormat", CommonNamespaces.CSWNS,
109 acceptFormatsElement );
110 acceptFormats = new String[formatsList.getLength()];
111 for ( int i = 0; i < acceptFormats.length; i++ ) {
112 acceptFormats[i] = XMLTools.getStringValue( formatsList.item( i ) );
113 }
114 }
115
116 // '<csw:Sections>'-element (optional)
117 Element sectionsElement = XMLTools.getChildElement( "Sections", CommonNamespaces.CSWNS, root );
118 if ( sectionsElement != null ) {
119 ElementList sectionList = XMLTools.getChildElements( "Section", CommonNamespaces.CSWNS, sectionsElement );
120 sections = new String[sectionList.getLength()];
121 for ( int i = 0; i < sections.length; i++ ) {
122 sections[i] = XMLTools.getStringValue( sectionList.item( i ) );
123 }
124 }
125
126 return new CatalogueGetCapabilities( id, updateSeq, version, acceptVersions, acceptFormats, sections,
127 new HashMap<String, String>() );
128 }
129
130 }