001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/owscommon_1_1_0/OWSCommonCapabilitiesDocument.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    
037    package org.deegree.owscommon_1_1_0;
038    
039    import static org.deegree.framework.xml.XMLTools.getElement;
040    import static org.deegree.framework.xml.XMLTools.getElements;
041    import static org.deegree.framework.xml.XMLTools.getNodeAsString;
042    import static org.deegree.framework.xml.XMLTools.getNodesAsStringList;
043    import static org.deegree.framework.xml.XMLTools.getRequiredElement;
044    import static org.deegree.framework.xml.XMLTools.getRequiredNodeAsString;
045    import static org.deegree.ogcbase.CommonNamespaces.XLINK_PREFIX;
046    
047    import java.util.ArrayList;
048    import java.util.List;
049    
050    import org.deegree.framework.util.Pair;
051    import org.deegree.framework.xml.XMLParsingException;
052    import org.w3c.dom.Element;
053    
054    /**
055     * <code>OWSCapabilitesDocument</code> parses the ows_1_1_0 Capabilities profile.
056     *
057     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
058     *
059     * @author last edited by: $Author: mschneider $
060     *
061     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
062     *
063     */
064    
065    public abstract class OWSCommonCapabilitiesDocument extends CommonsDocument {
066    
067        /**
068         * @return the ServiceIdentification bean or <code>null</code> if ServiceIdentification
069         *         element is <code>null</code>;
070         * @throws XMLParsingException
071         *             if something could not be parsed.
072         */
073        public ServiceIdentification parseServiceIdentification()
074                                throws XMLParsingException {
075            Element serviceIdentification = getElement( getRootElement(), PRE_OWS + "ServiceIdentification", nsContext );
076            if ( serviceIdentification == null ) {
077                return null;
078            }
079            List<String> title = getNodesAsStringList( serviceIdentification, PRE_OWS + "Title", nsContext );
080            List<String> abstracts = getNodesAsStringList( serviceIdentification, PRE_OWS + "Abstract", nsContext );
081            List<Element> kws = getElements( serviceIdentification, PRE_OWS + "Keywords", nsContext );
082            // Pair<List<keywords>, codetype>
083            List<Keywords> keywords = new ArrayList<Keywords>( ( ( kws == null ) ? 0 : kws.size() ) );
084            if ( kws != null ) {
085                for ( Element keyword : kws ) {
086                    keywords.add( parseKeywords( keyword ) );
087                }
088            }
089            Pair<String, String> serviceType = new Pair<String, String>(
090                                                                         getRequiredNodeAsString( serviceIdentification,
091                                                                                                  PRE_OWS + "ServiceType",
092                                                                                                  nsContext ),
093                                                                         getNodeAsString(
094                                                                                          serviceIdentification,
095                                                                                          PRE_OWS
096                                                                                                                  + "ServiceType/@codeSpace",
097                                                                                          nsContext, null ) );
098            List<String> serviceTypeVersions = getNodesAsStringList( serviceIdentification, PRE_OWS + "ServiceTypeVersion",
099                                                                     nsContext );
100            if ( serviceTypeVersions.size() == 0 ) {
101                throw new XMLParsingException( PRE_OWS + "ServiceTypeVersion must be present at least once." );
102            }
103            List<String> profiles = getNodesAsStringList( serviceIdentification, PRE_OWS + "Profile", nsContext );
104            String fees = getNodeAsString( serviceIdentification, PRE_OWS + "Fees", nsContext, null );
105            List<String> accessConstraints = getNodesAsStringList( serviceIdentification, PRE_OWS + "AccessConstraints",
106                                                                   nsContext );
107            return new ServiceIdentification( title, abstracts, keywords, serviceType, serviceTypeVersions, profiles, fees,
108                                              accessConstraints );
109        }
110    
111        /**
112         * @return the ServiceProvider bean or <code>null</code> if the ServiceProvider element is
113         *         <code>null</code>;
114         * @throws XMLParsingException
115         */
116        public ServiceProvider parseServiceProvider()
117                                throws XMLParsingException {
118            Element serviceProvider = getElement( getRootElement(), PRE_OWS + "ServiceProvider", nsContext );
119            if ( serviceProvider == null ) {
120                return null;
121            }
122            String providerName = getRequiredNodeAsString( serviceProvider, PRE_OWS + "ProviderName", nsContext );
123            String providerSite = getNodeAsString( serviceProvider, PRE_OWS + "ProviderSite/@" + XLINK_PREFIX + ":href",
124                                                   nsContext, null );
125            ServiceContact serviceContact = parseServiceContact( getRequiredElement( serviceProvider, PRE_OWS
126                                                                                                      + "ServiceContact",
127                                                                                     nsContext ) );
128            return new ServiceProvider( providerName, providerSite, serviceContact );
129        }
130    
131        /**
132         * @return the OperationsMetadata bean or <code>null</code> if the OperationsMetadata element
133         *         is <code>null</code>;
134         * @throws XMLParsingException
135         */
136        public OperationsMetadata parseOperationsMetadata()
137                                throws XMLParsingException {
138            Element operationsMetadata = getElement( getRootElement(), PRE_OWS + "OperationsMetadata", nsContext );
139            if ( operationsMetadata == null ) {
140                return null;
141            }
142            List<Operation> operations = parseOperations( getElements( operationsMetadata, PRE_OWS + "Operation", nsContext ) );
143            List<Element> params = getElements( operationsMetadata, PRE_OWS + "Parameter", nsContext );
144            List<DomainType> parameters = new ArrayList<DomainType>();
145            if ( params != null && params.size() > 0 ) {
146                for ( Element param : params ) {
147                    DomainType t = parseDomainType( param );
148                    if ( t != null ) {
149                        parameters.add( t );
150                    }
151                }
152            }
153    
154            List<Element> consts = getElements( operationsMetadata, PRE_OWS + "Constraint", nsContext );
155            List<DomainType> constraints = new ArrayList<DomainType>();
156            if ( params != null && params.size() > 0 ) {
157                for ( Element ce : consts ) {
158                    DomainType t = parseDomainType( ce );
159                    if ( t != null ) {
160                        constraints.add( t );
161                    }
162                }
163            }
164            Element extendedCapabilities = getElement( operationsMetadata, PRE_OWS + "ExtendedCapabilities", nsContext );
165    
166            return new OperationsMetadata( operations, parameters, constraints, extendedCapabilities );
167    
168        }
169    
170    }