    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/ogcwebservices/wmps/operation/GetAvailableTemplates.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.wmps.operation;
    037
    038    import java.util.HashMap;
    039    import java.util.Map;
    040
    041    import org.deegree.framework.xml.XMLParsingException;
    042    import org.deegree.framework.xml.XMLTools;
    043    import org.w3c.dom.Element;
    044
    045    /**
    046     * Can be requested as KVP:
    047     * <p>
    048     * ...?request=GetAvailableTemplates&version=1.0.0
    049     * </p>
    050     * or as XML:
    051     * <p>
    052     *
    053     * <pre>
    054     * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    055     * &lt;deegreewmps:GetAvailableTemplates xmlns:deegreewmps=&quot;http://www.deegree.org/wmps&quot; version=&quot;1.0.0&quot;/&gt;
    056     * </pre>
    057     *
    058     * </p>
    059     *
    060     * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
    061     * @author last edited by: $Author: apoth $
    062     *
    063     * @version $Revision: 20967 $, $Date: 2009-11-23 16:49:00 +0100 (Mo, 23. Nov 2009) $
    064     */
    065    public class GetAvailableTemplates extends WMPSRequestBase {
    066
    067        private static final long serialVersionUID = 1210026775322614277L;
    068
    069        /**
    070         * @param id
    071         * @param version
    072         * @param vendorSpecificParameter
    073         */
    074        public GetAvailableTemplates( String id, String version, Map<String, String> vendorSpecificParameter ) {
    075            super( version, id, vendorSpecificParameter );
    076        }
    077
    078        /**
    079         *
    080         * @param parameter
    081         * @return new {@link GetAvailableTemplates}
    082         */
    083        public static GetAvailableTemplates create( Map<String, String> parameter ) {
    084            String id = "" + System.currentTimeMillis();
    085            String version = retrieveVersionParameter( parameter );
    086            return new GetAvailableTemplates( id, version, parameter );
    087        }
    088
    089        /**
    090         *
    091         * @param request
    092         * @return new {@link GetAvailableTemplates}
    093         * @throws XMLParsingException
    094         */
    095        public static GetAvailableTemplates create( Element request )
    096                                throws XMLParsingException {
    097            String id = "" + System.currentTimeMillis();
    098            String version;
    099            try {
    100                version = XMLTools.getRequiredAttrValue( "version", null, request );
    101            } catch ( XMLParsingException e ) {
    102                throw new XMLParsingException( "Error parsing required attribute parameter 'Version'. " + e.getMessage() );
    103            }
    104            return new GetAvailableTemplates( id, version, new HashMap<String, String>() );
    105        }
    106
    107        /**
    108         * Parse 'Version' Parameter.
    109         *
    110         * @param model
    111         * @return String version (default=1.0.0)
    112         */
    113        private static String retrieveVersionParameter( Map<String, String> model ) {
    114
    115            String version = null;
    116            if ( model.containsKey( "VERSION" ) ) {
    117                version = (String) model.remove( "VERSION" );
    118            }
    119            if ( version == null ) {
    120                /** default value set as per the WMPS draft specifications. */
    121                version = "1.0.0";
    122            }
    123
    124            return version;
    125        }
    126
    127    }