com.gisgraphy.domain.geoloc.importer
Class ImporterHelper

java.lang.Object
  extended by com.gisgraphy.domain.geoloc.importer.ImporterHelper

public class ImporterHelper
extends java.lang.Object

Useful methods for importer

Author:
David Masclet

Field Summary
static java.lang.String ALLCOUTRY_FILENAME
          the all country dump file name
static java.io.FileFilter countryFileFilter
           
static java.lang.String EXCLUDED_README_FILENAME
          The readme filename (it must not be processed)
static java.lang.String GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING
          The regexp that every country file dump matches
protected static org.slf4j.Logger logger
           
static java.lang.String OPENSTREETMAP_US_FILE_ACCEPT_REGEX_STRING
           
static java.lang.String TAR_BZ2_FILE_ACCEPT_REGEX_STRING
           
static java.lang.String ZIP_FILE_ACCEPT_REGEX_STRING
          The regexp that every zipped country file dump matches
 
Constructor Summary
ImporterHelper()
           
 
Method Summary
static java.util.List<java.util.regex.Pattern> compileRegex(java.lang.String regexpSemiColumnSeparated)
           
static java.lang.String[] correctLastAdmCodeIfPossible(java.lang.String[] fields)
           
static void download(java.lang.String address, java.lang.String localFileName)
           
static java.lang.String formatSeconds(long secsIn)
           
static long getHttpFileSize(java.lang.String URL)
           
static java.io.File[] listCountryFilesToImport(java.lang.String directoryPath)
           
static java.io.File[] listTarFiles(java.lang.String directoryPath)
           
static java.io.File[] listZipFiles(java.lang.String directoryPath)
           
static void unzipFile(java.io.File file)
          unzip a file in the same directory as the zipped file
static java.lang.String[] virtualizeADMD(java.lang.String[] fields)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXCLUDED_README_FILENAME

public static final java.lang.String EXCLUDED_README_FILENAME
The readme filename (it must not be processed)

See Also:
Constant Field Values

ALLCOUTRY_FILENAME

public static final java.lang.String ALLCOUTRY_FILENAME
the all country dump file name

See Also:
Constant Field Values

GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING

public static final java.lang.String GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING
The regexp that every country file dump matches

See Also:
Constant Field Values

OPENSTREETMAP_US_FILE_ACCEPT_REGEX_STRING

public static final java.lang.String OPENSTREETMAP_US_FILE_ACCEPT_REGEX_STRING
See Also:
Constant Field Values

ZIP_FILE_ACCEPT_REGEX_STRING

public static final java.lang.String ZIP_FILE_ACCEPT_REGEX_STRING
The regexp that every zipped country file dump matches

See Also:
Constant Field Values

TAR_BZ2_FILE_ACCEPT_REGEX_STRING

public static final java.lang.String TAR_BZ2_FILE_ACCEPT_REGEX_STRING
See Also:
Constant Field Values

logger

protected static final org.slf4j.Logger logger

countryFileFilter

public static java.io.FileFilter countryFileFilter
Constructor Detail

ImporterHelper

public ImporterHelper()
Method Detail

listCountryFilesToImport

public static java.io.File[] listCountryFilesToImport(java.lang.String directoryPath)
Parameters:
directoryPath - The directory where Geonames files are
Returns:
the allcountries.txt (@see ALLCOUTRY_FILENAME file if present or the list of country file to Import or an empty array if there is no file
See Also:
GEONAMES_COUNTRY_FILE_ACCEPT_REGEX_STRING

listZipFiles

public static java.io.File[] listZipFiles(java.lang.String directoryPath)
Parameters:
directoryPath - The directory where Geonames files are to be downloaded in order to be processed
Returns:
all the zip files present in the specified directory or an empty array if there is no file
See Also:
ZIP_FILE_ACCEPT_REGEX_STRING

listTarFiles

public static java.io.File[] listTarFiles(java.lang.String directoryPath)
Parameters:
directoryPath - The directory where openstreetmap files are to be downloaded in order to be processed
Returns:
all the zip files present in the specified directory or an empty array if there is no file
See Also:
TAR_BZ2_FILE_ACCEPT_REGEX_STRING

getHttpFileSize

public static long getHttpFileSize(java.lang.String URL)
Parameters:
URL - the HTTP URL
Returns:
The size of the HTTP file using HTTP head method.

download

public static void download(java.lang.String address,
                            java.lang.String localFileName)
Parameters:
address - the address of the file to be downloaded
localFileName - the local file name (with absolute path)

unzipFile

public static void unzipFile(java.io.File file)
unzip a file in the same directory as the zipped file

Parameters:
file - The file to unzip

virtualizeADMD

public static java.lang.String[] virtualizeADMD(java.lang.String[] fields)
Parameters:
fields - the fields corresponding to a split line of the csv geonames file
Returns:
the modified fields whith the feature code change to ADM1,ADM2,ADM3,ADM4 according to the ADMcodes. e.g id adm1code and Adm2 code are not null : the feature code will be change to ADM2.

correctLastAdmCodeIfPossible

public static java.lang.String[] correctLastAdmCodeIfPossible(java.lang.String[] fields)

compileRegex

public static java.util.List<java.util.regex.Pattern> compileRegex(java.lang.String regexpSemiColumnSeparated)
Parameters:
regexpSemiColumnSeparated - a string with multiple reqgexp separated by ';'
Returns:
A list of Pattern or null if a regexp are not corrects

formatSeconds

public static java.lang.String formatSeconds(long secsIn)
Parameters:
secsIn - the number of seconds
Returns:
a human reading strings. example :1 hour 6 minuts 40 seconds.


Copyright © 2010. All Rights Reserved.