#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#---------------------------------------------------------------
package BookPub::Catalog::Import::Process::Fetcher::FileHandler::ONIX;
use strict;
use warnings;

use File::Path;
use Data::Dumper;

use lib '/app/tools/common/lib';
use lib '/app/tools/bookpub/lib';
use Common::Assert;
use BookPub::DB::Item::CatalogImportItem::File;

use base 'BookPub::Catalog::Import::Process::Fetcher::FileHandler';

sub _processLocalFile {
    my ($self) = @_;

    # Run these files through a formatter, since our parser is stupid.
    #
    my $path = $self->localFile();

    #    `/usr/bin/xmllint --format $path > $path.pretty`;
    `/app/tools/bookpub/bin/catalog_import/xmlindent < $path > $path.pretty`;
    rename( "$path.pretty", $path );

    my $catalogImportID = $self->{_fetcher}->_catalogImportID();

    my $importFileRec = BookPub::DB::Item::CatalogImportItem::File->Create(
        catalog_import_id => $catalogImportID,
        file_path         => $self->localFile(),
    );
    $importFileRec->save();
}

1;
