package Ernad::Editor; use strict; use warnings; use Carp qw(confess); use Data::Dumper qw(Dumper); use File::Basename; use XML::LibXML; use Ernad::Common; ## for historical reasons, as it was called from Final, ## in needs an rs variable with rs->{e} and rs->{repcode} sub update_in_doc { my $doc=shift; my $rs=shift; ## if set, add an editor if it is not there. This is the default in final my $do_add=shift // ''; my $rif_node=$doc->documentElement(); my $e=$rs->{'e'}; my $repcode=$rs->{'repcode'}; my $amf_ns=$e->{'const'}->{'amf_ns'}; my $editor=$e->{'report'}->{$repcode}->{'xml'}->{'editor'} // confess "I have no editor."; if(not ref($editor) eq 'XML::LibXML::Element') { die 'editor is not an element'; } my $collection_node=$rif_node->getChildrenByTagNameNS($amf_ns,'collection')->[0]; # my $old_editor=Ernad::Common::find_editor_element_from_collection($collection_node) // ''; my $old_editor=$e->{'x'}->find_editor_element_from_collection($collection_node) // ''; if($old_editor) { $collection_node->replaceChild($editor,$old_editor); } elsif($do_add) { $collection_node->appendChild($editor); } return $doc; } 1;