001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/csw/capabilities/CatalogueGetCapabilitiesDocument.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 package org.deegree.ogcwebservices.csw.capabilities;
037
038 import java.util.HashMap;
039
040 import org.deegree.framework.log.ILogger;
041 import org.deegree.framework.log.LoggerFactory;
042 import org.deegree.framework.xml.ElementList;
043 import org.deegree.framework.xml.XMLParsingException;
044 import org.deegree.framework.xml.XMLTools;
045 import org.deegree.i18n.Messages;
046 import org.deegree.ogcbase.CommonNamespaces;
047 import org.deegree.ogcbase.OGCDocument;
048 import org.deegree.ogcwebservices.InvalidParameterValueException;
049 import org.deegree.ogcwebservices.csw.CSWPropertiesAccess;
050 import org.w3c.dom.Element;
051
052 /**
053 * Parser for "csw:GetCapabilities" requests.
054 *
055 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
056 *
057 * @author last edited by: $Author: mschneider $
058 *
059 * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
060 *
061 * @since 2.0
062 */
063 public class CatalogueGetCapabilitiesDocument extends OGCDocument {
064
065 private static final long serialVersionUID = -7155778875151820291L;
066
067 private static ILogger LOG = LoggerFactory.getLogger( CatalogueGetCapabilitiesDocument.class );
068
069 /**
070 * Parses the underlying document into a <code>GetCapabilities</code> request object.
071 *
072 * @param id
073 * @return corresponding <code>GetCapabilities</code> object
074 * @throws XMLParsingException
075 * @throws InvalidParameterValueException
076 * @throws InvalidParameterValueException
077 */
078 public CatalogueGetCapabilities parse( String id )
079 throws XMLParsingException, InvalidParameterValueException {
080
081 String version = CSWPropertiesAccess.getString( "DEFAULTVERSION" );
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 version = CatalogueGetCapabilities.validateVersion( acceptVersions );
104 if ( version == null ) {
105 throw new InvalidParameterValueException( Messages.get( "CSW_UNSUPPORTED_VERSION" ) );
106 }
107 }
108 LOG.logInfo( "process with version:", version );
109
110 // '<csw:AcceptFormats>'-element (optional)
111 Element acceptFormatsElement = XMLTools.getChildElement( "AcceptFormats", CommonNamespaces.CSWNS, root );
112 if ( acceptFormatsElement != null ) {
113 ElementList formatsList = XMLTools.getChildElements( "OutputFormat", CommonNamespaces.CSWNS,
114 acceptFormatsElement );
115 acceptFormats = new String[formatsList.getLength()];
116 for ( int i = 0; i < acceptFormats.length; i++ ) {
117 acceptFormats[i] = XMLTools.getStringValue( formatsList.item( i ) );
118 }
119 }
120
121 // '<csw:Sections>'-element (optional)
122 Element sectionsElement = XMLTools.getChildElement( "Sections", CommonNamespaces.CSWNS, root );
123 if ( sectionsElement != null ) {
124 ElementList sectionList = XMLTools.getChildElements( "Section", CommonNamespaces.CSWNS, sectionsElement );
125 sections = new String[sectionList.getLength()];
126 for ( int i = 0; i < sections.length; i++ ) {
127 sections[i] = XMLTools.getStringValue( sectionList.item( i ) );
128 }
129 }
130
131 return new CatalogueGetCapabilities( id, updateSeq, version, acceptVersions, acceptFormats, sections,
132 new HashMap<String, String>() );
133 }
134
135 }