001    // $HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wcs/configuration/WCSConfigurationDocument.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 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: 9345 $
071     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
072     * @author last edited by: $Author: apoth $
073     * 
074     * $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 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    
198                    try {
199                        url = resolve( s ); 
200                    } catch (Exception e) {
201                            throw new XMLParsingException( "<Configuration> element in CoverageOfferingBrief "
202                                                            + "section isn't a valid URL: " + s);
203                    }
204    
205                    return new CoverageOfferingBrief(name, label, desc, mLink, llEnv, keywords, url);
206            }
207    
208    }