001    // $HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcwebservices/wcs/configuration/WCSConfigurationDocument.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.wcs.configuration;
037    
038    import java.io.IOException;
039    import java.net.URL;
040    import java.util.List;
041    
042    import org.deegree.framework.log.ILogger;
043    import org.deegree.framework.log.LoggerFactory;
044    import org.deegree.framework.util.StringTools;
045    import org.deegree.framework.xml.XMLParsingException;
046    import org.deegree.framework.xml.XMLTools;
047    import org.deegree.model.metadata.iso19115.Keywords;
048    import org.deegree.model.metadata.iso19115.OnlineResource;
049    import org.deegree.ogcbase.CommonNamespaces;
050    import org.deegree.ogcbase.OGCException;
051    import org.deegree.ogcwebservices.LonLatEnvelope;
052    import org.deegree.ogcwebservices.MetadataLink;
053    import org.deegree.ogcwebservices.OGCWebServiceException;
054    import org.deegree.ogcwebservices.wcs.CoverageOfferingBrief;
055    import org.deegree.ogcwebservices.wcs.getcapabilities.WCSCapabilitiesDocument;
056    import org.w3c.dom.Element;
057    import org.xml.sax.SAXException;
058    
059    /**
060     * 
061     * 
062     * @version $Revision: 20592 $
063     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
064     * @author last edited by: $Author: rbezema $
065     * 
066     *         $Revision: 20592 $, $Date: 2009-11-05 13:24:27 +0100 (Do, 05. Nov 2009) $
067     */
068    public class WCSConfigurationDocument extends WCSCapabilitiesDocument {
069    
070        private static final long serialVersionUID = -5962651588545478145L;
071    
072        protected static final ILogger LOG = LoggerFactory.getLogger( WCSConfigurationDocument.class );
073    
074        private static final String PRE_DEEGREE = CommonNamespaces.DEEGREEWCS_PREFIX + ":";
075    
076        private static final String PRE_WCS = CommonNamespaces.WCS_PREFIX + ":";
077    
078        /**
079         *
080         */
081        public static final String XML_TEMPLATE = "WCSConfigurationTemplate.xml";
082    
083        @Override
084        public void createEmptyDocument()
085                                throws IOException, SAXException {
086            URL url = WCSConfigurationDocument.class.getResource( XML_TEMPLATE );
087            if ( url == null ) {
088                throw new IOException( "The resource '" + XML_TEMPLATE + " could not be found." );
089            }
090            load( url );
091        }
092    
093        /**
094         * creates the deegreeParams section of the WCS capabilities/configuration. If a 'common' WCS capabilities is
095         * encapsulated by the <tt>WCSCapabilitieDocument</tt> this method returns <tt>null</tt>
096         * 
097         * @return the data
098         * @throws InvalidConfigurationException
099         */
100        public WCSDeegreeParams getDeegreeParamsSection()
101                                throws InvalidConfigurationException {
102            try {
103                Element element = (Element) XMLTools.getRequiredNode( getRootElement(), PRE_DEEGREE + "deegreeParam",
104                                                                      nsContext );
105                // if (element == null) {
106                // throw new InvalidConfigurationException( "DeegreeParams section is missing" );
107                // }
108                // OnlineResource defOLR = parseOnLineResource(XMLTools.getRequiredChildElement(
109                // "DefaultOnlineResource", DGRNS, element ));
110                OnlineResource defOLR = parseOnLineResource( (Element) XMLTools.getRequiredNode(
111                                                                                                 element,
112                                                                                                 PRE_DEEGREE
113                                                                                                                         + "DefaultOnlineResource",
114                                                                                                 nsContext ) );
115                // String tmp = XMLTools.getStringValue( "CacheSize", DGRNS, element, "100" );
116                int cache = XMLTools.getNodeAsInt( element, PRE_DEEGREE + "CacheSize", nsContext, 100 );
117                // int cache = Integer.parseInt(tmp);
118                // tmp = XMLTools.getStringValue( "RequestTimeLimit", DGRNS, element, "5" );
119                // int timeLimit = Integer.parseInt(tmp);
120                int timeLimit = XMLTools.getNodeAsInt( element, PRE_DEEGREE + "RequestTimeLimit", nsContext, 5 );
121                Element dataDirs = (Element) XMLTools.getRequiredNode( element, PRE_DEEGREE + "DataDirectoryList",
122                                                                       nsContext );
123                String[] dirList = XMLTools.getNodesAsStrings( dataDirs, PRE_DEEGREE + "DataDirectory", nsContext );
124                //
125                if ( dirList.length > 0 ) {
126                    StringBuffer sb = new StringBuffer( 400 );
127                    sb.append( "<DataDirectoryList> evaluation is not suporrrted yet, skipping following dirs:\n" );
128                    for ( int i = 0; i < dirList.length; ++i )
129                        sb.append( '\t' + dirList[i] + ( ( i + 1 < dirList.length ) ? '\n' : ' ' ) );
130                    LOG.logInfo( sb.toString() );
131                }
132                WCSDeegreeParams wcsDP = new WCSDeegreeParams( defOLR, cache, timeLimit, dirList );
133                LOG.logDebug( "(WCSConfig.getDeegreeParamsSection): " + wcsDP );
134                return wcsDP;
135            } catch ( XMLParsingException e ) {
136                String s = e.getMessage();
137                throw new InvalidConfigurationException( "Error while parsing the DeegreeParams "
138                                                         + "Section of the WCS capabilities\n" + s
139                                                         + StringTools.stackTraceToString( e ) );
140            }
141        }
142    
143        // /**
144        // * returns an array containing a list of default datadirectories parsed by
145        // * the WCS for coverage configurations
146        // *
147        // * @param element
148        // * @return created array of data directory names
149        // * @throws XMLParsingException
150        // */
151        // private String[] getDirectoryList(Element element ) {
152        // ElementList el = XMLTools.getChildElements( "DataDirectory", DGRNS, element );
153        // String[] dirList = new String[el.getLength()];
154        // for (int i = 0; i < dirList.length; i++) {
155        // dirList[i] = XMLTools.getStringValue(el.item(i));
156        // }
157        // return dirList;
158        // }
159    
160        /**
161         * creates a <tt>CoverageOfferingBrief</tt> object from the passed element encapsulating one CoverageOfferingBrief
162         * part of the WCS ContentMetadata section
163         * 
164         * @param element
165         * @return created <tt>CoverageOfferingBrief</tt>
166         * @throws XMLParsingException
167         * @throws OGCWebServiceException
168         * @throws OGCException
169         */
170        @Override
171        protected CoverageOfferingBrief parseCoverageOfferingBrief( Element element )
172                                throws XMLParsingException, OGCWebServiceException, OGCException {
173            // Element elem = XMLTools.getChildElement( "metadataLink", WCSNS, element );
174            Element elem = (Element) XMLTools.getNode( element, PRE_WCS + "metadataLink", nsContext );
175            MetadataLink mLink = parseMetadataLink( elem );
176            String desc = XMLTools.getNodeAsString( element, PRE_WCS + "description", nsContext, null );
177            // String name = XMLTools.getRequiredStringValue( "name", WCSNS, element );
178            String name = XMLTools.getRequiredNodeAsString( element, PRE_WCS + "name", nsContext );
179            // String label = XMLTools.getRequiredStringValue( "label", WCSNS, element );
180            String label = XMLTools.getRequiredNodeAsString( element, PRE_WCS + "label", nsContext );
181            // elem = XMLTools.getChildElement( "lonLatEnvelope", WCSNS, element );
182            elem = (Element) XMLTools.getNode( element, PRE_WCS + "lonLatEnvelope", nsContext );
183            LonLatEnvelope llEnv = parseLonLatEnvelope( elem );
184            // ElementList el = XMLTools.getChildElements( "keywords", WCSNS, element );
185            List el = XMLTools.getNodes( element, PRE_WCS + "keywords", nsContext );
186            Keywords[] keywords = new Keywords[el.size()];
187            for ( int i = 0; i < el.size(); ++i ) {
188                keywords[i] = parseKeywords( (Element) el.get( i ), WCSNS );
189            }
190            // Keywords[] keywords = parseKeywords(el, WCSNS);
191            String s = XMLTools.getRequiredNodeAsString( element, PRE_DEEGREE + "Configuration", nsContext );
192            URL url = null;
193    
194            try {
195                url = resolve( s );
196            } catch ( Exception e ) {
197                throw new XMLParsingException( "<Configuration> element in CoverageOfferingBrief "
198                                               + "section isn't a valid URL: " + s );
199            }
200    
201            return new CoverageOfferingBrief( name, label, desc, mLink, llEnv, keywords, url );
202        }
203    
204    }