//$HeadURL$
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2010 by:
 - Department of Geography, University of Bonn -
 and
 - lat/lon GmbH -

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. Klaus Greve
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: info@deegree.org
 ----------------------------------------------------------------------------*/
package org.deegree.services.demo.jsf;

import static org.deegree.commons.utils.io.Zip.unzip;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.deegree.console.ConfigManager;

import lombok.Getter;

/**
 * 
 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
 * @author last edited by: $Author$
 * 
 * @version $Revision$, $Date$
 */
@ManagedBean
@ApplicationScoped
public class DownloadBean {

    private boolean dataDownloaded;

    private File dataDir;

    /**
     * 
     */
    public DownloadBean() {
        dataDir = new File( FacesContext.getCurrentInstance().getExternalContext().getRealPath( "/" )
                            + "/WEB-INF/workspace/data" );
    }

    /**
     * @return the property
     */
    public boolean getDataDownloaded() {
        return dataDownloaded = dataDir.exists() && dataDir.isDirectory();
    }

    /**
     * @return '/index'
     */
    public String download() {
        InputStream is = null;
        try {
            dataDir.mkdirs();
            is = new URL( "http://download.deegree.org/data/deegree3/wms/wms.zip" ).openStream();
            unzip( is, dataDir );
        } catch ( MalformedURLException e ) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch ( IOException e ) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if ( is != null ) {
                try {
                    is.close();
                } catch ( IOException e ) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

        new ConfigManager().applyChanges();

        return "/index";
    }

}

@@ -1387,16 +1387,65 @@
 p.unzip;
+%0Aimport static org.slf4j.LoggerFactory.getLogger;
 %0A%0Aimport
@@ -1698,16 +1698,61 @@
 ntext;%0A%0A
+import org.deegree.commons.utils.ProxyUtils;%0A
 import o
@@ -1789,27 +1789,29 @@
 er;%0A
-%0A
 import 
-lombok.Gett
+org.slf4j.Logg
 er;%0A
@@ -2022,16 +2022,147 @@
 Bean %7B%0A%0A
+    private static final Logger LOG = getLogger( DownloadBean.class );%0A%0A    @SuppressWarnings(%22unused%22)%0A    // for the love of jsf%0A
     priv
@@ -2671,24 +2671,25 @@
 ownload() %7B%0A
+%0A
         Inpu
@@ -2767,16 +2767,46 @@
     is =
+ ProxyUtils.openURLConnection(
  new URL
@@ -2864,21 +2864,27 @@
 s.zip%22 )
-.open
+ ).getInput
 Stream()
@@ -2981,158 +2981,167 @@
     
-// TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D catch ( IOException e ) %7B%0A            // TODO Auto-generated catch block
+LOG.trace( %22Malformed url:%22, e );%0A        %7D catch ( IOException e ) %7B%0A            LOG.warn( %22Trouble when downloading the data: %7B%7D%22, e.getLocalizedMessage() );
 %0A   
@@ -3149,34 +3149,45 @@
         
-e.print
+LOG.trace( %22
 Stack
-T
+ t
 race
-(
+:%22, e 
 );%0A     
@@ -3355,81 +3355,37 @@
     
-// TODO Auto-generated catch block%0A                    e.print
+LOG.trace( %22
 Stack
-T
+ t
 race
-(
+:%22, e 
 );%0A 

use proxy settings when downloading