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

Author:
David Masclet Useful methods for importer

Field Summary
static java.lang.String ALLCOUTRY_FILENAME
          the all country dump file name
static java.lang.String COUNTRY_FILE_ACCEPT_REGEX_STRING
          The regexp that every country file dump matches
static java.lang.String EXCLUDED_README_FILENAME
          The readme filename (it must not be processed)
protected static org.slf4j.Logger logger
           
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 boolean isDirectoryAccessible(java.lang.String directoryPath)
           
static java.io.File[] listCountryFilesToImport(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

COUNTRY_FILE_ACCEPT_REGEX_STRING

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

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

logger

protected static final org.slf4j.Logger logger
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
See Also:
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
See Also:
ZIP_FILE_ACCEPT_REGEX_STRING

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 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.

isDirectoryAccessible

public static boolean isDirectoryAccessible(java.lang.String directoryPath)
Parameters:
directoryPath - The directory to check. it can be absolute or relative
Returns:
true if the path is a directory (not a file) AND exists AND is writable

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 © 2009. All Rights Reserved.