org.egothor.duplicity.apps
Class AppsCommon

java.lang.Object
  extended by org.egothor.duplicity.apps.AppsCommon

public class AppsCommon
extends java.lang.Object

Common methods for the duplicity checking applications. The methods help to handle user input, different document input formats,

Author:
Kate�ina Dufkov�

Field Summary
static java.util.Comparator<File> fileComp
          Comparator sorts files alphabetically.
 
Constructor Summary
AppsCommon()
           
 
Method Summary
static int getLastBarrelFromStateFile(java.lang.String index)
          Gets the number of the last barrel in given index.
static long getUID(java.lang.String filename, Tanker tanker)
          Find a unique identificator for the document with given filename.
static boolean getUserApproval()
          Ask the user for approval using commandline, and return the response of the user.
static Barrel openBarrel(java.lang.String input, java.lang.String className)
          Open barrel.
static Document openDocument(java.lang.String location, long uid, java.lang.String fileCharset, boolean lowercase, boolean phonetics, HTMLField.Diacritics diacritics)
          Open document, can handle html and pdf files.
static BarrelReader openDocumentOrBarrelReader(java.lang.String input, boolean directory, java.lang.String className, long uid)
          Open barrel or document in given location for reading.
static void printL(File a, int indentation)
          Print the name of given File to stdout with given indentation.
static void printL(java.lang.String a, int indentation)
          Print the given String to stdout with given indentation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileComp

public static java.util.Comparator<File> fileComp
Comparator sorts files alphabetically.

Constructor Detail

AppsCommon

public AppsCommon()
Method Detail

getUserApproval

public static boolean getUserApproval()
Ask the user for approval using commandline, and return the response of the user.

Returns:
the response of the user

getUID

public static long getUID(java.lang.String filename,
                          Tanker tanker)
Find a unique identificator for the document with given filename. The document identificator will be unused in the given tanker. If the tanker is null, no check for uniqueness will be made.

Parameters:
filename - name of the file in which the document is stored
tanker - tanker to which the document will be appended, and thus the new identificator must be unused in the tanker
Returns:
document identificator not present in the tanker

printL

public static void printL(File a,
                          int indentation)
Print the name of given File to stdout with given indentation.

Parameters:
a - the File to be printed
indentation - the wanted indentation level

printL

public static void printL(java.lang.String a,
                          int indentation)
Print the given String to stdout with given indentation.

Parameters:
a - the String to be printed
indentation - the wanted indentation level

openDocumentOrBarrelReader

public static BarrelReader openDocumentOrBarrelReader(java.lang.String input,
                                                      boolean directory,
                                                      java.lang.String className,
                                                      long uid)
Open barrel or document in given location for reading. Uses given class to read the barrel.

Parameters:
input - path to the input
directory - sign if the input is directory or regular file
className - class to be used to read the barrel
uid - identifier to be set to document
Returns:
BarrelReader instance, or null if the file type is unknown or if the construction of the barrel from class className fails

openBarrel

public static Barrel openBarrel(java.lang.String input,
                                java.lang.String className)
Open barrel. Uses given class to read the barrel.

Parameters:
input - path to the input
className - class to be used to read the barrel
Returns:
Barrel instance, or null if the construction of the barrel from class className fails

openDocument

public static Document openDocument(java.lang.String location,
                                    long uid,
                                    java.lang.String fileCharset,
                                    boolean lowercase,
                                    boolean phonetics,
                                    HTMLField.Diacritics diacritics)
Open document, can handle html and pdf files.

Parameters:
location - path to the file with the document
uid - identifier to be set to document
fileCharset - charecter set to be used to read the document
lowercase - sign if lowercase filter should be used to process the file
phonetics - sign if phonetics filter should be used to process the file
diacritics - the diacritics to be used to process the file
Returns:
Document instance, or null if the file type is unknown

getLastBarrelFromStateFile

public static int getLastBarrelFromStateFile(java.lang.String index)
Gets the number of the last barrel in given index. It reads the "state" file in the index directory and returns the value of the "slotter.last" property.

Parameters:
index - directory where the index is stored
Returns:
number of the last barrel