View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  /**
24   *
25   */
26  package com.gisgraphy.importer;
27  
28  import java.io.File;
29  import java.io.IOException;
30  import java.util.List;
31  
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  import com.gisgraphy.helper.Untar;
36  
37  
38  /**
39   * Retrieve The Geonames files from a server
40   * 
41   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
42   */
43  public class OpenStreetMapHouseNumberFileRetriever extends AbstractFileRetriever {
44  
45  	protected static final Logger logger = LoggerFactory.getLogger(OpenStreetMapHouseNumberFileRetriever.class);
46  	
47      private Untar untar;
48      
49      public String getcurrentExtractedFileNameIntoArchive(){
50  	return untar == null? null : untar.getCurrentFileNameIntoArchiveExtracted();
51      }
52     
53      /* (non-Javadoc)
54       * @see com.gisgraphy.domain.geoloc.importer.AbstractFileRetriever#getDownloadDirectory()
55       */
56      public String getDownloadDirectory() {
57  	return importerConfig.getOpenStreetMapHouseNumberDir();
58      }
59  
60      /* (non-Javadoc)
61       * @see com.gisgraphy.domain.geoloc.importer.AbstractFileRetriever#getDownloadBaseUrl()
62       */
63      public String getDownloadBaseUrl() {
64  	return importerConfig
65  	    .getOpenstreetMaphouseNumbersDownloadURL();
66      }
67      
68      /* (non-Javadoc)
69       * @see com.gisgraphy.domain.geoloc.importer.AbstractFileRetriever#decompressFiles()
70       */
71      public void decompressFiles() throws IOException {
72  	File[] filesToUntar = getFilesToDecompress();
73  	File destDirectory = new File(getDownloadDirectory());
74  	for (int i = 0; i < filesToUntar.length; i++) {
75  	    try {
76  			untar = new Untar(filesToUntar[i].getAbsolutePath(),destDirectory);
77  			untar.untar();
78  		} catch (Exception e) {
79  			logger.error(filesToUntar[i].getAbsolutePath()+" is not a valid tar file");
80  		}
81  	}
82  
83  	// for log purpose
84  	File[] filesToImport = ImporterHelper
85  		.listCountryFilesToImport(getDownloadDirectory());
86  
87  	for (int i = 0; i < filesToImport.length; i++) {
88  	    logger.info("the files " + filesToImport[i].getName()
89  		    + " will be imported for openstreetMap house number");
90  	}
91      }
92  
93      /* (non-Javadoc)
94       * @see com.gisgraphy.domain.geoloc.importer.AbstractFileRetriever#shouldBeSkipped()
95       */
96      @Override
97      public boolean shouldBeSkipped() {
98  	return !importerConfig.isOpenstreetmapHouseNumberImporterEnabled();
99      }
100 
101     /* (non-Javadoc)
102      * @see com.gisgraphy.domain.geoloc.importer.AbstractFileRetriever#getFilesToDownload()
103      */
104     @Override
105     List<String> getFilesToDownload() {
106 	return importerConfig.getOpenStreetMapHouseNumberDownloadFilesListFromOption();
107     }
108 
109     @Override
110     public File[] getFilesToDecompress() throws IOException {
111 	return ImporterHelper.listTarFiles(getDownloadDirectory());
112     }
113 
114     @Override
115     public boolean isFileNotFoundTolerant() {
116 	return false;
117     }
118 
119 }