001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wmps/operation/DescribeTemplate.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.deegree.ogcbase.CommonNamespaces;
044 import org.deegree.ogcwebservices.InconsistentRequestException;
045 import org.w3c.dom.Element;
046
047 /**
048 * Can be requested as KVP:
049 * <p>
050 * ...?request=DescribeTemplate&version=1.0.0&template=MyTemplate
051 * </p>
052 * or as XML:
053 * <p>
054 *
055 * <pre>
056 * ...
057 * </pre>
058 *
059 * </p>
060 *
061 * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
062 * @author last edited by: $Author: apoth $
063 *
064 * @version $Revision: 21672 $, $Date: 2009-12-29 09:44:20 +0100 (Di, 29 Dez 2009) $
065 */
066 public class DescribeTemplate extends WMPSRequestBase {
067
068 private static final long serialVersionUID = 536568315562438781L;
069
070 private String template;
071
072 /**
073 *
074 * @param id
075 * @param version
076 * @param template
077 * @param vendorSpecificParameter
078 */
079 public DescribeTemplate( String id, String version, String template, Map<String, String> vendorSpecificParameter ) {
080 super( version, id, vendorSpecificParameter );
081 this.template = template;
082 }
083
084 /**
085 *
086 * @param parameter
087 * @return new {@link DescribeTemplate}
088 * @throws InconsistentRequestException
089 */
090 public static DescribeTemplate create( Map<String, String> parameter ) throws InconsistentRequestException{
091 String id = "" + System.currentTimeMillis();
092 String version = retrieveVersionParameter( parameter );
093 String tempplate = retrieveTemplateParameter( parameter );
094 return new DescribeTemplate( id, version, tempplate, parameter );
095 }
096
097 /**
098 *
099 * @param request
100 * @return new {@link DescribeTemplate}
101 * @throws XMLParsingException
102 */
103 public static DescribeTemplate create( Element request )
104 throws XMLParsingException {
105 String id = "" + System.currentTimeMillis();
106 String version;
107 try {
108 version = XMLTools.getRequiredAttrValue( "version", null, request );
109 } catch ( Exception e ) {
110 throw new XMLParsingException( "Error parsing required attribute 'Version'. " + e.getMessage() );
111 }
112 String template = null;
113 try {
114 version = XMLTools.getRequiredNodeAsString( request, "deegreewmps:Template",
115 CommonNamespaces.getNamespaceContext() );
116 } catch ( Exception e ) {
117 throw new XMLParsingException( "Error parsing required element 'Template'. " + e.getMessage() );
118 }
119 return new DescribeTemplate( id, version, template, new HashMap<String, String>() );
120 }
121
122 /**
123 * Parse 'Version' Parameter.
124 *
125 * @param model
126 * @return String version (default=1.0.0)
127 */
128 private static String retrieveVersionParameter( Map<String, String> model ) {
129
130 String version = null;
131 if ( model.containsKey( "VERSION" ) ) {
132 version = (String) model.remove( "VERSION" );
133 }
134 if ( version == null ) {
135 /** default value set as per the WMPS draft specifications. */
136 version = "1.0.0";
137 }
138
139 return version;
140 }
141
142 /**
143 * Parse 'Template' Parameter.
144 *
145 * @param model
146 * @return template to describe
147 * @throws InconsistentRequestException
148 */
149 private static String retrieveTemplateParameter( Map<String, String> model ) throws InconsistentRequestException{
150
151 String template = null;
152 if ( model.containsKey( "TEMPLATE" ) ) {
153 template = (String) model.remove( "TEMPLATE" );
154 }
155 if ( template == null ) {
156 throw new InconsistentRequestException( "parameter template must be set" );
157 }
158
159 return template;
160 }
161
162 /**
163 *
164 * @return template name
165 */
166 public String getTemplate() {
167 return template;
168 }
169
170 }