001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wass/was/operation/WASGetCapabilitiesDocument.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.wass.was.operation;
037    
038    import java.util.HashMap;
039    import java.util.regex.Pattern;
040    
041    import org.deegree.framework.xml.XMLFragment;
042    import org.deegree.framework.xml.XMLParsingException;
043    import org.deegree.framework.xml.XMLTools;
044    import org.deegree.i18n.Messages;
045    import org.deegree.ogcbase.CommonNamespaces;
046    import org.w3c.dom.Element;
047    
048    /**
049     * Parser for a WAS GetCapabilities request.
050     *
051     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
052     * @author last edited by: $Author: mschneider $
053     *
054     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
055     *
056     * @since 2.0
057     */
058    
059    public class WASGetCapabilitiesDocument extends XMLFragment {
060    
061        private static final long serialVersionUID = -859662737770813155L;
062    
063        // this pattern matches parametrized mime types, so if something funny happens, this may be the
064        // reason
065        private static Pattern pattern = Pattern.compile( "(application|audio|image|text|video|message|multipart|model)/.+(;\\s*.+=.+)*" );
066    
067        private static final String PRE = CommonNamespaces.OWS_PREFIX;
068    
069        /**
070         * Parses a WASGetCapabilities XML request.
071         *
072         * @param id
073         * @param root
074         * @return a new request object
075         * @throws XMLParsingException
076         */
077        public WASGetCapabilities parseCapabilities( String id, Element root )
078                                throws XMLParsingException {
079    
080    
081            Element acceptVersionsNode = (Element) XMLTools.getNode( root, PRE + "AcceptVersions",
082                                                                     nsContext );
083            String[] acceptVersions = null;
084            if ( acceptVersionsNode != null )
085                acceptVersions = XMLTools.getRequiredNodesAsStrings( acceptVersionsNode, PRE
086                                                                                         + "Version",
087                                                                     nsContext );
088    
089            Element sectionsNode = (Element) XMLTools.getNode( root, PRE + "Sections", nsContext );
090            String[] sections = null;
091            if ( sectionsNode != null )
092                sections = XMLTools.getNodesAsStrings( sectionsNode, PRE + "Section", nsContext );
093    
094            Element acceptFormatsNode = (Element) XMLTools.getNode( root, PRE + "AcceptFormats",
095                                                                    nsContext );
096            String[] acceptFormats = null;
097    
098            if ( acceptFormatsNode != null ) {
099                acceptFormats = XMLTools.getNodesAsStrings( acceptFormatsNode, PRE + "OutputFormat",
100                                                            nsContext );
101    
102                for ( String str : acceptFormats )
103                    if ( !pattern.matcher( str ).matches() )
104                        throw new XMLParsingException(
105                                                       Messages.getMessage( "WASS_ERROR_VALUE_NO_MIMETYPE" ) );
106            }
107    
108            String updateSequence = XMLTools.getNodeAsString( root, "@updateSequence", nsContext, null );
109    
110            String service = XMLTools.getRequiredNodeAsString( root, "@service", nsContext );
111            if ( !service.equals( "WAS" ) )
112                throw new XMLParsingException(
113                                               Messages.getMessage( "WASS_ERROR_NO_SERVICE_ATTRIBUTE" ) );
114    
115            WASGetCapabilities result = new WASGetCapabilities( id, "1.0", updateSequence,
116                                                                acceptVersions, sections, acceptFormats,
117                                                                new HashMap<String,String>() );
118    
119    
120            return result;
121        }
122    
123    }