]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Cat/Utils.pm
added a common entityize function to prevent the contining spread
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Cat / Utils.pm
1 package OpenILS::Application::Cat::Utils;
2 use strict; use warnings;
3 use OpenILS::Application::AppUtils;
4 use OpenILS::Utils::Fieldmapper;
5 use XML::LibXML;
6 use XML::LibXSLT;
7 use OpenSRF::Utils::SettingsParser;
8 use OpenILS::Utils::FlatXML;
9 use OpenILS::Utils::ModsParser;
10
11 my $mods_utils = OpenILS::Utils::ModsParser->new();
12
13
14
15 # -----------------------------------------------------------------------
16 # XXX This code is all deprecated.  Remove any traces and delete
17 # -----------------------------------------------------------------------
18
19
20
21 sub new {
22         my($class) = @_;
23         $class = ref($class) || $class;
24         return bless( {}, $class );
25 }
26
27
28 # ---------------------------------------------------------------------------
29 # Converts an XML nodeset into a tree
30 # This method expects a blessed Fieldmapper::biblio::record_node object 
31 sub nodeset2tree {
32         my($class, $nodeset) = @_;
33
34         for my $child (@$nodeset) {
35                 next unless ($child and defined($child->parent_node));
36                 my $parent = $nodeset->[$child->parent_node];
37                 if( ! $parent ) {
38                         warn "No Parent For " . $child->intra_doc_id() . "\n";
39                 }
40                 $parent->children([]) unless defined($parent->children); 
41                 $child->isnew(0);
42                 $child->isdeleted(0);
43                 push( @{$parent->children}, $child );
44         }
45
46         return $nodeset->[0];
47 }
48
49
50 # ---------------------------------------------------------------------------
51 # Converts a tree into an xml nodeset
52 # This method expects a blessed Fieldmapper::biblio::record_node object 
53
54 sub tree2nodeset {
55
56         my($self, $node, $newnodes) = @_;
57         return $newnodes unless $node;
58
59         if(!$newnodes) { $newnodes = []; }
60         push( @$newnodes, $node );
61
62         if( $node->children() ) {
63
64                 for my $child (@{ $node->children() }) {
65
66                         new Fieldmapper::biblio::record_node ($child);
67                         if(!defined($child->parent_node)) {
68                                 $child->parent_node($node->intra_doc_id); 
69                                 $child->ischanged(1); #just to be sure
70                         }
71                         $self->tree2nodeset( $child, $newnodes );
72                 }
73         }
74
75         $node->children([]); #we don't need them hanging around
76         return $newnodes;
77 }
78
79
80 # Removes any deleted nodes from the tree
81 sub clean_nodeset {
82
83         my($self, $nodeset) = @_;
84         my @newnodes = ();
85         for my $node (@$nodeset) {
86                 if(!$node->isdeleted() ) {
87                         push @newnodes, $node;
88                 }
89         }
90
91         return \@newnodes;
92 }
93
94
95
96
97 1;