###############################################################################
#
# BaseDBDriver.pm -- base class for all the database drivers
# A component of the Greenstone digital library software from the New Zealand
# Digital Library Project at the University of Waikato, New Zealand.
#
# Copyright (C) 1999-2015 New Zealand Digital Library Project
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
# Ave, Cambridge, MA 02139, USA.
#
###############################################################################

package BaseDBDriver;

# Pragma
use strict;

# Libaries
use gsprintf 'gsprintf';

###############################################################################
## Private Functions
###############################################################################


## @function _convert_infodb_hash_to_string(hashmap)
#
sub _convert_infodb_hash_to_string
{
    my $infodb_map = shift(@_);
    my $infodb_entry_value = "";
    foreach my $infodb_value_key (keys(%$infodb_map)) {
        foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) {
            $infodb_entry_value .= "<$infodb_value_key>" . $infodb_value . "\n";
        }
    }
    return $infodb_entry_value;
}
## _convert_infodb_hash_to_string(hashmap) => string ##


## @function _convert_infodb_string_to_hash(string)
#
sub _convert_infodb_string_to_hash
{
    my $infodb_entry_value = shift(@_);
    my $infodb_map = ();

    if (!defined $infodb_entry_value) {
	print STDERR "Warning: No value to convert into a infodb hashtable\n";
    }
    else {
        while ($infodb_entry_value =~ /^<(.*?)>(.*)$/mg) {
            my $infodb_value_key = $1;
            my $infodb_value = $2;

            if (!defined($infodb_map->{$infodb_value_key})) {
                $infodb_map->{$infodb_value_key} = [ $infodb_value ];
            }
            else {
                push(@{$infodb_map->{$infodb_value_key}}, $infodb_value);
            }
	}
    }

    return $infodb_map;
}
## _convert_infodb_string_to_hash(string) => hashmap ##


###############################################################################
## Public Functions
###############################################################################


## @function supports_datestamp()
#
sub supports_datestamp
{
    return 0;
}
## supports_datestamp() => integer ##


## @function supports_merge()
#
sub supports_merge
{
    return 0;
}
## supports_merge() => integer ##


## @function supports_rss()
#
sub supports_rss
{
    return 0;
}
## supports_rss() => integer ##


###############################################################################
## Virtual Functions
###############################################################################


## @function close_infodb_write_handle
#
sub close_infodb_write_handle
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## close_infodb_write_handle ##


## @function delete_infodb_entry
#
sub delete_infodb_entry
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## delete_infodb_entry ##


## @function get_infodb_file_path
#
sub get_infodb_file_path
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## get_infodb_file_path ##


## @function merge_databases
#
sub merge_databases
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## merge_databases ##


## @function open_infodb_write_handle
#
sub open_infodb_write_handle
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## open_infodb_write_handle ##


## @function set_infodb_entry()
#
sub set_infodb_entry
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## set_infodb_entry() => void ##


## @function read_infodb_file
#
sub read_infodb_file
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## read_infodb_file ##


## @function read_infodb_keys
#
sub read_infodb_keys
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## read_infodb_keys ##


## @function write_infodb_entry
#
sub write_infodb_entry
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## write_infodb_entry ##


## @function write_infodb_rawentry
#
sub write_infodb_rawentry
{
    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
    die("\n");
}
## write_infodb_rawentry ##

1;
