# Copyright (C) 2007 Stephane Galland # # 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; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. =pod =head1 NAME Bib2HTML::JabRef::JabRef - A translator to support JabRef format. =head1 DESCRIPTION Bib2HTML::JabRef::JabRef is a Perl module, which permits to translate bibTeX data according to the JabRef format. =head1 SYNOPSYS my $j = Bib2HTML::JabRef::JabRef->new() ; $j->parser(content); =cut package Bib2HTML::JabRef::JabRef; @ISA = ('Exporter'); @EXPORT = qw(); @EXPORT_OK = qw(); use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); use Exporter; use Carp ; #------------------------------------------------------ # # Global vars # #------------------------------------------------------ # Version number of JabRef Translator my $VERSION = "1.0" ; #------------------------------------------------------ # # Constructor # #------------------------------------------------------ sub new() : method { my $proto = shift; my $class = ref($proto) || $proto; my $self = {} ; bless($self,$class); return $self; } #------------------------------------------------------ # # Translation API # #------------------------------------------------------ =pod =item * parse($) Translate the specified content which must be a reference to an hashtable given by a parser. =cut sub parse($) : method { my $self = shift ; $self->parseComments(@{$_[0]->{'comments'}}); if (($self->{'variables'}{'groupsversion'} !~ /^\s*([0-9]+)\s*;\s*$/)|| (int($1) < 3)) { Bib2HTML::General::Error::syserr( "the JabRef translator does not support groups' version below 3.0" ) ; } # Treat the groups if ($self->{'variables'}{'groupstree'}) { my %categoryAssignation = $self->assignCategories($self->{'variables'}{'groupstree'}); $self->createCategories(\%categoryAssignation,$_[0]->{'entries'}); } } #------------------------------------------------------ # # Tool API # #------------------------------------------------------ =pod =item * createCategories(\%$) Add the categories to each bibtex entries. =cut sub createCategories(\%$) { my $self = shift; foreach my $key (keys(%{$_[0]})) { if (exists $_[1]->{"$key"}) { my $newcategories = join(':',@{$_[0]->{"$key"}}); if ($_[1]->{"$key"}{'fields'}{'domains'}) { $newcategories .= ":".$_[1]->{"$key"}{'fields'}{'domains'}; } $_[1]->{"$key"}{'fields'}{'domains'} = "$newcategories"; } } } =pod =item * assignCategories($) Parse the JabRef group list and replies the assignations for each bibtex entry. =cut sub assignCategories($) { my $self = shift; my $jabrefgroups = "$_[0]"; my %assignments = (); my @categories = (); while (($jabrefgroups)&& ($jabrefgroups =~ /^\s*([0-9]+)\s+([^:]*):(.*?)(?{'variables'}{lc("$1")} = "$2"; } } } 1; __END__ =back =head1 COPYRIGHT (c) Copyright 2007 Stéphane Galland Egalland@arakhne.orgE, under GPL. =head1 AUTHORS =over =item * Conceived and initially developed by Stéphane Galland Egalland@arakhne.orgE. =back =head1 SEE ALSO bib2html.pl