001 //$HeadURL: $
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.ogcwebservices.wcts.configuration;
038
039 import java.io.IOException;
040 import java.net.URL;
041
042 import org.deegree.framework.log.ILogger;
043 import org.deegree.framework.log.LoggerFactory;
044 import org.deegree.framework.xml.XMLParsingException;
045 import org.deegree.framework.xml.XMLTools;
046 import org.deegree.ogcbase.CommonNamespaces;
047 import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
048 import org.deegree.ogcwebservices.wcts.capabilities.Content;
049 import org.deegree.ogcwebservices.wcts.capabilities.WCTSCapabilities;
050 import org.deegree.ogcwebservices.wcts.capabilities.WCTSCapabilitiesDocument;
051 import org.w3c.dom.Element;
052 import org.xml.sax.SAXException;
053
054 /**
055 * <code>WCTSConfigurationDocument</code> loads an xml-dom-document and creates a {@link WCTSConfiguration}
056 * bean-representation.
057 *
058 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
059 *
060 * @author last edited by: $Author:$
061 *
062 * @version $Revision:$, $Date:$
063 *
064 */
065 public class WCTSConfigurationDocument extends WCTSCapabilitiesDocument {
066
067 private static ILogger LOG = LoggerFactory.getLogger( WCTSConfigurationDocument.class );
068
069 /**
070 *
071 */
072 private static final long serialVersionUID = -4585404178146440716L;
073
074 /**
075 * @param configURL
076 * to load from.
077 * @throws SAXException
078 * if an xml parsing error has been detected.
079 * @throws IOException
080 * if the file could not be loaded.
081 */
082 public WCTSConfigurationDocument( URL configURL ) throws IOException, SAXException {
083 super.load( configURL );
084 }
085
086 /**
087 * @return a new instance of a {@link WCTSConfiguration}
088 * @throws InvalidCapabilitiesException
089 * if the configuration contains erroneous xml.
090 */
091 public WCTSConfiguration parseConfiguration()
092 throws InvalidCapabilitiesException {
093
094 WCTSDeegreeParams deegreeParams = parseDeegreeParams();
095 WCTSConfiguration config = new WCTSConfiguration(
096 (WCTSCapabilities) parseCapabilities( deegreeParams.getConfiguredCRSProvider() ),
097 deegreeParams );
098 if ( deegreeParams.createDefaultTransformationsDescription() ) {
099 LOG.logDebug( "Creating descriptions for the default Transformations." );
100 Content capCon = config.getContents();
101 if ( capCon != null ) {
102 capCon.describeDefaultTransformations( deegreeParams.getTransformationPrefix() );
103 }
104 }
105 return config;
106 }
107
108 /**
109 * @return the deegreeparam section of the configuration.
110 * @throws XMLParsingException
111 */
112 private WCTSDeegreeParams parseDeegreeParams() {
113 Element root = getRootElement();
114 WCTSDeegreeParams result = null;
115 Element deegreeParams;
116 try {
117 deegreeParams = XMLTools.getElement( root, CommonNamespaces.DEEGREEWCTS_PREFIX + ":deegreeParams",
118 nsContext );
119 if ( deegreeParams != null ) {
120 int updateSequence = XMLTools.getNodeAsInt( deegreeParams, CommonNamespaces.DEEGREEWCTS_PREFIX
121 + ":updateSequence", nsContext, -1 );
122
123 if ( updateSequence > -1 && updateSequence < 60 ) {
124 // one hour
125 updateSequence = 60;
126 }
127 updateSequence *= 60000;
128 LOG.logInfo( "Content cache will be updated every: " + ( updateSequence / 3600000d ) + " hours" );
129
130 String provider = XMLTools.getNodeAsString( deegreeParams, CommonNamespaces.DEEGREEWCTS_PREFIX
131 + ":crsProvider", nsContext, null );
132 LOG.logDebug( "Using configured crs provider:" + provider );
133 String transformPrefix = XMLTools.getNodeAsString( deegreeParams, CommonNamespaces.DEEGREEWCTS_PREFIX
134 + ":transformationIDPrefix",
135 nsContext, null );
136
137 boolean useDeegreeTransformType = XMLTools.getNodeAsBoolean(
138 deegreeParams,
139 CommonNamespaces.DEEGREEWCTS_PREFIX
140 + ":useDeegreeTransformType",
141 nsContext, true );
142 boolean createDefaultTransformations = XMLTools.getNodeAsBoolean(
143 deegreeParams,
144 CommonNamespaces.DEEGREEWCTS_PREFIX
145 + ":createDefaultTransformationDescriptions",
146 nsContext, true );
147 result = new WCTSDeegreeParams( updateSequence, provider, transformPrefix, useDeegreeTransformType,
148 createDefaultTransformations );
149 }
150 } catch ( XMLParsingException e ) {
151 LOG.logError( e );
152 }
153 if ( result == null ) {
154 result = new WCTSDeegreeParams();
155 }
156 return result;
157 }
158
159 }