001 // $HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wcs/configuration/WCSConfigurationDocument.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstr. 19
030 53115 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042
043 ---------------------------------------------------------------------------*/
044 package org.deegree.ogcwebservices.wcs.configuration;
045
046 import java.io.IOException;
047 import java.net.URL;
048 import java.util.List;
049
050 import org.deegree.framework.log.ILogger;
051 import org.deegree.framework.log.LoggerFactory;
052 import org.deegree.framework.util.StringTools;
053 import org.deegree.framework.xml.XMLParsingException;
054 import org.deegree.framework.xml.XMLTools;
055 import org.deegree.model.metadata.iso19115.Keywords;
056 import org.deegree.model.metadata.iso19115.OnlineResource;
057 import org.deegree.ogcbase.CommonNamespaces;
058 import org.deegree.ogcbase.OGCException;
059 import org.deegree.ogcwebservices.LonLatEnvelope;
060 import org.deegree.ogcwebservices.MetadataLink;
061 import org.deegree.ogcwebservices.OGCWebServiceException;
062 import org.deegree.ogcwebservices.wcs.CoverageOfferingBrief;
063 import org.deegree.ogcwebservices.wcs.getcapabilities.WCSCapabilitiesDocument;
064 import org.w3c.dom.Element;
065 import org.xml.sax.SAXException;
066
067 /**
068 *
069 *
070 * @version $Revision: 6259 $
071 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
072 * @author last edited by: $Author: bezema $
073 *
074 * $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
075 */
076 public class WCSConfigurationDocument extends WCSCapabilitiesDocument {
077
078 private static final long serialVersionUID = -5962651588545478145L;
079
080 protected static final ILogger LOG = LoggerFactory.getLogger( WCSConfigurationDocument.class );
081
082 private static final String PRE_DEEGREE = CommonNamespaces.DEEGREEWCS_PREFIX+":";
083 private static final String PRE_WCS = CommonNamespaces.WCS_PREFIX+":";
084
085 /**
086 *
087 */
088 public static final String XML_TEMPLATE = "WCSConfigurationTemplate.xml";
089
090
091 @Override
092 public void createEmptyDocument() throws IOException, SAXException {
093 URL url = WCSConfigurationDocument.class.getResource(XML_TEMPLATE);
094 if (url == null) {
095 throw new IOException( "The resource '" + XML_TEMPLATE
096 + " could not be found.");
097 }
098 load(url);
099 }
100
101 /**
102 * creates the deegreeParams section of the WCS capabilities/configuration.
103 * If a 'common' WCS capabilities is encapsulated by the
104 * <tt>WCSCapabilitieDocument</tt> this method returns <tt>null</tt>
105 *
106 * @return the data
107 * @throws InvalidConfigurationException
108 */
109 public WCSDeegreeParams getDeegreeParamsSection()
110 throws InvalidConfigurationException {
111 try {
112 Element element = (Element)XMLTools.getRequiredNode( getRootElement(), PRE_DEEGREE+"deegreeParam", nsContext );
113 // if (element == null) {
114 // throw new InvalidConfigurationException( "DeegreeParams section is missing" );
115 // }
116 //OnlineResource defOLR = parseOnLineResource(XMLTools.getRequiredChildElement( "DefaultOnlineResource", DGRNS, element ));
117 OnlineResource defOLR = parseOnLineResource((Element)XMLTools.getRequiredNode( element, PRE_DEEGREE + "DefaultOnlineResource", nsContext) );
118 //String tmp = XMLTools.getStringValue( "CacheSize", DGRNS, element, "100" );
119 int cache = XMLTools.getNodeAsInt( element, PRE_DEEGREE+"CacheSize", nsContext, 100 );
120 // int cache = Integer.parseInt(tmp);
121 // tmp = XMLTools.getStringValue( "RequestTimeLimit", DGRNS, element, "5" );
122 // int timeLimit = Integer.parseInt(tmp);
123 int timeLimit = XMLTools.getNodeAsInt( element, PRE_DEEGREE+"RequestTimeLimit", nsContext, 5 );
124 Element dataDirs = (Element)XMLTools.getRequiredNode( element, PRE_DEEGREE+"DataDirectoryList", nsContext );
125 String[] dirList = XMLTools.getNodesAsStrings(dataDirs, PRE_DEEGREE+"DataDirectory", nsContext);
126 //
127 if ( dirList.length > 0 ) {
128 StringBuffer sb = new StringBuffer(400);
129 sb.append("<DataDirectoryList> evaluation is not suporrted yet, skipping following dirs:\n" );
130 for( int i = 0; i < dirList.length; ++i )
131 sb.append( '\t' + dirList[i] + ((i+1<dirList.length)?'\n':' '));
132 LOG.logInfo( sb.toString() );
133 }
134 WCSDeegreeParams wcsDP = new WCSDeegreeParams(defOLR, cache, timeLimit, dirList );
135 LOG.logDebug( "(WCSConfig.getDeegreeParamsSection): " + wcsDP);
136 return wcsDP;
137 } catch (XMLParsingException e) {
138 String s = e.getMessage();
139 throw new InvalidConfigurationException(
140 "Error while parsing the DeegreeParams "
141 + "Section of the WCS capabilities\n" + s
142 + StringTools.stackTraceToString(e));
143 }
144 }
145
146 // /**
147 // * returns an array containing a list of default datadirectories parsed by
148 // * the WCS for coverage configurations
149 // *
150 // * @param element
151 // * @return created array of data directory names
152 // * @throws XMLParsingException
153 // */
154 // private String[] getDirectoryList(Element element ) {
155 // ElementList el = XMLTools.getChildElements( "DataDirectory", DGRNS, element );
156 // String[] dirList = new String[el.getLength()];
157 // for (int i = 0; i < dirList.length; i++) {
158 // dirList[i] = XMLTools.getStringValue(el.item(i));
159 // }
160 // return dirList;
161 // }
162
163 /**
164 * creates a <tt>CoverageOfferingBrief</tt> object from the passed element
165 * encapsulating one CoverageOfferingBrief part of the WCS ContentMetadata
166 * section
167 *
168 * @param element
169 * @return created <tt>CoverageOfferingBrief</tt>
170 * @throws XMLParsingException
171 * @throws OGCWebServiceException
172 * @throws OGCException
173 */
174 @Override
175 protected CoverageOfferingBrief parseCoverageOfferingBrief(Element element )
176 throws XMLParsingException, OGCWebServiceException, OGCException {
177 //Element elem = XMLTools.getChildElement( "metadataLink", WCSNS, element );
178 Element elem = (Element)XMLTools.getNode( element, PRE_WCS+"metadataLink", nsContext );
179 MetadataLink mLink = parseMetadataLink(elem);
180 String desc = XMLTools.getNodeAsString( element, PRE_WCS+"description", nsContext, null);
181 //String name = XMLTools.getRequiredStringValue( "name", WCSNS, element );
182 String name = XMLTools.getRequiredNodeAsString( element, PRE_WCS+"name", nsContext );
183 //String label = XMLTools.getRequiredStringValue( "label", WCSNS, element );
184 String label = XMLTools.getRequiredNodeAsString( element, PRE_WCS+"label", nsContext );
185 //elem = XMLTools.getChildElement( "lonLatEnvelope", WCSNS, element );
186 elem = (Element)XMLTools.getNode( element, PRE_WCS+"lonLatEnvelope", nsContext );
187 LonLatEnvelope llEnv = parseLonLatEnvelope(elem);
188 //ElementList el = XMLTools.getChildElements( "keywords", WCSNS, element );
189 List el = XMLTools.getNodes( element, PRE_WCS+"keywords", nsContext );
190 Keywords[] keywords = new Keywords[el.size()];
191 for( int i = 0; i< el.size(); ++i ){
192 keywords[i] = parseKeywords( (Element) el.get(i), WCSNS);
193 }
194 //Keywords[] keywords = parseKeywords(el, WCSNS);
195 String s = XMLTools.getRequiredNodeAsString(element, PRE_DEEGREE+"Configuration", nsContext );
196 URL url = null;
197 // if (s == null) {
198 // throw new XMLParsingException( "<Configuration> element is required "
199 // + "in CoverageOfferingBrief section" );
200 // }
201 try {
202 url = resolve( s );
203 } catch (Exception e) {
204 throw new XMLParsingException( "<Configuration> element in CoverageOfferingBrief "
205 + "section isn't a valid URL: " + s);
206 }
207
208 return new CoverageOfferingBrief(name, label, desc, mLink, llEnv, keywords, url);
209 }
210
211 }
212 /*******************************************************************************
213 * Changes to this class. What the people have been up to: $Log:
214 * WCSConfigurationDocument.java,v $ Revision 1.10 2004/07/06 16:44:25
215 * mschneider More work on CatalogConfiguration and
216 * CatalogConfigurationDocument. This includes the hierarchy of these classes.
217 *
218 * Revision 1.9 2004/07/05 13:42:38 mschneider Changed deegreeParam to
219 * deegreeParams wherever it is used.
220 *
221 * Revision 1.8 2004/07/05 06:15:00 ap no message
222 *
223 * Revision 1.7 2004/07/02 15:36:11 ap no message
224 *
225 * Revision 1.6 2004/06/30 15:16:05 mschneider Refactoring of XMLTools.
226 *
227 * Revision 1.5 2004/06/08 07:01:51 ap no message
228 *
229 * Revision 1.4 2004/05/26 10:16:40 ap no message
230 *
231 * Revision 1.3 2004/05/25 14:57:52 ap no message
232 *
233 * Revision 1.2 2004/05/25 07:19:13 ap no message
234 *
235 * Revision 1.1 2004/05/24 06:54:39 ap no message
236 *
237 *
238 ******************************************************************************/