Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.history
Class HistoryReaderImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.history.HistoryReaderImpl
All Implemented Interfaces:
HistoryReader

public class HistoryReaderImpl
extends Object
implements HistoryReader

Author:
Alexander Pelov, Damian Minkov, Yana Stamcheva

Constructor Summary
protected HistoryReaderImpl(HistoryImpl historyImpl)
          Creates an instance of HistoryReaderImpl.
 
Method Summary
 void addSearchProgressListener(HistorySearchProgressListener listener)
          Adding progress listener for monitoring progress of search process
 int countRecords()
          Count the number of messages that a search will return Actually only the last file is parsed and its nodes are counted.
(package private) static HistoryRecord filterByKeyword(NodeList propertyNodes, long timestamp, String[] keywords, String field, boolean caseSensitive)
          If there is keyword restriction and doesn't match the conditions return null.
(package private) static Vector<String> filterFilesByDate(Iterator<String> filelist, Date startDate, Date endDate)
          Used to limit the files if any starting or ending date exist So only few files to be searched.
(package private) static Vector<String> filterFilesByDate(Iterator<String> filelist, Date startDate, Date endDate, boolean reverseOrder)
          Used to limit the files if any starting or ending date exist So only few files to be searched.
 QueryResultSet<HistoryRecord> findByEndDate(Date endDate)
          Searches the history for all records with timestamp before endDate.
 QueryResultSet<HistoryRecord> findByKeyword(String keyword, String field)
          Searches the history for all records containing the keyword.
 QueryResultSet<HistoryRecord> findByKeyword(String keyword, String field, boolean caseSensitive)
          Searches the history for all records containing the keyword.
 QueryResultSet<HistoryRecord> findByKeywords(String[] keywords, String field)
          Searches the history for all records containing all keywords.
 QueryResultSet<HistoryRecord> findByKeywords(String[] keywords, String field, boolean caseSensitive)
          Searches the history for all records containing all keywords.
 QueryResultSet<HistoryRecord> findByPeriod(Date startDate, Date endDate)
          Searches the history for all records with timestamp between startDate and endDate.
 QueryResultSet<HistoryRecord> findByPeriod(Date startDate, Date endDate, String[] keywords, String field)
          Searches for all history records containing all keywords, with timestamp between startDate and endDate.
 QueryResultSet<HistoryRecord> findByPeriod(Date startDate, Date endDate, String[] keywords, String field, boolean caseSensitive)
          Searches for all history records containing all keywords, with timestamp between startDate and endDate.
 QueryResultSet<HistoryRecord> findByStartDate(Date startDate)
          Searches the history for all records with timestamp after startDate.
 QueryResultSet<HistoryRecord> findFirstRecordsAfter(Date date, int count)
          Returns the supplied number of recent messages after the given date
 QueryResultSet<HistoryRecord> findLast(int count)
          Returns the last count messages.
 QueryResultSet<HistoryRecord> findLastRecordsBefore(Date date, int count)
          Returns the supplied number of recent messages before the given date
(package private) static boolean isInPeriod(long timestamp, Date startDate, Date endDate)
          Evaluetes does timestamp is in the given time period.
(package private) static boolean matchKeyword(String value, String[] keywords, boolean caseSensitive)
          Check if a value is in the given keyword(s) If no keyword(s) given must return true
 void removeSearchProgressListener(HistorySearchProgressListener listener)
          Removing progress listener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HistoryReaderImpl

protected HistoryReaderImpl(HistoryImpl historyImpl)
Creates an instance of HistoryReaderImpl.

Parameters:
historyImpl - the parent History implementation
Method Detail

findByStartDate

public QueryResultSet<HistoryRecord> findByStartDate(Date startDate)
                                              throws RuntimeException
Searches the history for all records with timestamp after startDate.

Specified by:
findByStartDate in interface HistoryReader
Parameters:
startDate - the date after all records will be returned
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByEndDate

public QueryResultSet<HistoryRecord> findByEndDate(Date endDate)
                                            throws RuntimeException
Searches the history for all records with timestamp before endDate.

Specified by:
findByEndDate in interface HistoryReader
Parameters:
endDate - the date before which all records will be returned
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByPeriod

public QueryResultSet<HistoryRecord> findByPeriod(Date startDate,
                                                  Date endDate)
                                           throws RuntimeException
Searches the history for all records with timestamp between startDate and endDate.

Specified by:
findByPeriod in interface HistoryReader
Parameters:
startDate - start of the interval in which we search
endDate - end of the interval in which we search
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByKeyword

public QueryResultSet<HistoryRecord> findByKeyword(String keyword,
                                                   String field)
                                            throws RuntimeException
Searches the history for all records containing the keyword.

Specified by:
findByKeyword in interface HistoryReader
Parameters:
keyword - the keyword to search for
field - the field where to look for the keyword
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByKeywords

public QueryResultSet<HistoryRecord> findByKeywords(String[] keywords,
                                                    String field)
                                             throws RuntimeException
Searches the history for all records containing all keywords.

Specified by:
findByKeywords in interface HistoryReader
Parameters:
keywords - array of keywords we search for
field - the field where to look for the keyword
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByPeriod

public QueryResultSet<HistoryRecord> findByPeriod(Date startDate,
                                                  Date endDate,
                                                  String[] keywords,
                                                  String field)
                                           throws UnsupportedOperationException
Searches for all history records containing all keywords, with timestamp between startDate and endDate.

Specified by:
findByPeriod in interface HistoryReader
Parameters:
startDate - start of the interval in which we search
endDate - end of the interval in which we search
keywords - array of keywords we search for
field - the field where to look for the keyword
Returns:
the found records
Throws:
UnsupportedOperationException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findLast

public QueryResultSet<HistoryRecord> findLast(int count)
                                       throws RuntimeException
Returns the last count messages. No progress firing as this method is supposed to be used in message windows and is supposed to be as quick as it can.

Specified by:
findLast in interface HistoryReader
Parameters:
count - int
Returns:
QueryResultSet
Throws:
RuntimeException

findByKeyword

public QueryResultSet<HistoryRecord> findByKeyword(String keyword,
                                                   String field,
                                                   boolean caseSensitive)
                                            throws RuntimeException
Searches the history for all records containing the keyword.

Specified by:
findByKeyword in interface HistoryReader
Parameters:
keyword - the keyword to search for
field - the field where to look for the keyword
caseSensitive - is keywords search case sensitive
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByKeywords

public QueryResultSet<HistoryRecord> findByKeywords(String[] keywords,
                                                    String field,
                                                    boolean caseSensitive)
                                             throws RuntimeException
Searches the history for all records containing all keywords.

Specified by:
findByKeywords in interface HistoryReader
Parameters:
keywords - array of keywords we search for
field - the field where to look for the keyword
caseSensitive - is keywords search case sensitive
Returns:
the found records
Throws:
RuntimeException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findByPeriod

public QueryResultSet<HistoryRecord> findByPeriod(Date startDate,
                                                  Date endDate,
                                                  String[] keywords,
                                                  String field,
                                                  boolean caseSensitive)
                                           throws UnsupportedOperationException
Searches for all history records containing all keywords, with timestamp between startDate and endDate.

Specified by:
findByPeriod in interface HistoryReader
Parameters:
startDate - start of the interval in which we search
endDate - end of the interval in which we search
keywords - array of keywords we search for
field - the field where to look for the keyword
caseSensitive - is keywords search case sensitive
Returns:
the found records
Throws:
UnsupportedOperationException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

findFirstRecordsAfter

public QueryResultSet<HistoryRecord> findFirstRecordsAfter(Date date,
                                                           int count)
                                                    throws RuntimeException
Returns the supplied number of recent messages after the given date

Specified by:
findFirstRecordsAfter in interface HistoryReader
Parameters:
date - messages after date
count - messages count
Returns:
QueryResultSet the found records
Throws:
RuntimeException

findLastRecordsBefore

public QueryResultSet<HistoryRecord> findLastRecordsBefore(Date date,
                                                           int count)
                                                    throws RuntimeException
Returns the supplied number of recent messages before the given date

Specified by:
findLastRecordsBefore in interface HistoryReader
Parameters:
date - messages before date
count - messages count
Returns:
QueryResultSet the found records
Throws:
RuntimeException

isInPeriod

static boolean isInPeriod(long timestamp,
                          Date startDate,
                          Date endDate)
Evaluetes does timestamp is in the given time period.

Parameters:
timestamp - Date
startDate - Date the start of the period
endDate - Date the end of the period
Returns:
boolean

filterByKeyword

static HistoryRecord filterByKeyword(NodeList propertyNodes,
                                     long timestamp,
                                     String[] keywords,
                                     String field,
                                     boolean caseSensitive)
If there is keyword restriction and doesn't match the conditions return null. Otherwise return the HistoryRecord corresponding the given nodes.

Parameters:
propertyNodes - NodeList
timestamp - Date
keywords - String[]
field - String
caseSensitive - boolean
Returns:
HistoryRecord

matchKeyword

static boolean matchKeyword(String value,
                            String[] keywords,
                            boolean caseSensitive)
Check if a value is in the given keyword(s) If no keyword(s) given must return true

Parameters:
value - String
keywords - String[]
caseSensitive - boolean
Returns:
boolean

filterFilesByDate

static Vector<String> filterFilesByDate(Iterator<String> filelist,
                                        Date startDate,
                                        Date endDate)
Used to limit the files if any starting or ending date exist So only few files to be searched.

Parameters:
filelist - Iterator
startDate - Date
endDate - Date
Returns:
Iterator

filterFilesByDate

static Vector<String> filterFilesByDate(Iterator<String> filelist,
                                        Date startDate,
                                        Date endDate,
                                        boolean reverseOrder)
Used to limit the files if any starting or ending date exist So only few files to be searched.

Parameters:
filelist - Iterator
startDate - Date
endDate - Date
reverseOrder - reverse order of files
Returns:
Vector

addSearchProgressListener

public void addSearchProgressListener(HistorySearchProgressListener listener)
Adding progress listener for monitoring progress of search process

Specified by:
addSearchProgressListener in interface HistoryReader
Parameters:
listener - HistorySearchProgressListener

removeSearchProgressListener

public void removeSearchProgressListener(HistorySearchProgressListener listener)
Removing progress listener

Specified by:
removeSearchProgressListener in interface HistoryReader
Parameters:
listener - HistorySearchProgressListener

countRecords

public int countRecords()
                 throws UnsupportedOperationException
Count the number of messages that a search will return Actually only the last file is parsed and its nodes are counted. We accept that the other files are full with max records, this way we escape parsing all files which will significantly slow the process and for one search will parse the files twice.

Specified by:
countRecords in interface HistoryReader
Returns:
the number of searched messages
Throws:
UnsupportedOperationException - Thrown if an exception occurs during the execution of the query, such as internal IO error.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.