merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / par2script / undefine.pm
blob4c2433509e5f598d91577432e846507425326779
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: undefine.pm,v $
11 # $Revision: 1.6 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package par2script::undefine;
34 use par2script::globals;
36 ##########################################################
37 # Removing in the script all the gids, that are listed
38 # in undefine scp files
39 ##########################################################
41 sub undefine_gids
43 my ($parfilecontent) = @_;
45 my $item;
46 foreach $item ( @par2script::globals::allitems )
48 my $unitem = "Un$item";
50 for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ )
52 if ( ${$parfilecontent}[$i] =~ /^\s*$unitem\s*(\w+?)\s*$/ )
54 my $gid = $1;
55 delete($par2script::globals::definitions{$item}->{$gid});
61 ##########################################################
62 # Collecting all subdirectories of a specified directory
63 ##########################################################
65 sub collect_children_dirs
67 my ($gid, $collector) = @_;
69 my $diritem = "Directory";
70 my $parentkey = "ParentID";
72 if ( exists($par2script::globals::definitions{$diritem}) )
74 my $onedefinition;
76 foreach $onedefinition (keys %{$par2script::globals::definitions{$diritem}})
78 if ( $par2script::globals::definitions{$diritem}->{$onedefinition}->{$parentkey} eq $gid )
80 push(@{$collector}, $onedefinition);
81 collect_children_dirs($onedefinition, $collector);
87 ##########################################################
88 # Removing in the script complete profiles.
89 # This includes the Profile and its ProfileItems.
90 ##########################################################
92 sub remove_complete_item
94 my ($item, $parfilecontent) = @_;
96 my $removeitem = "Remove$item";
97 my $dependentkey = "";
98 my $collect_children = 0;
99 my @gidcollector = ();
100 my @dependentitems = ();
102 if ( $item eq "Profile" )
104 @dependentitems = ("ProfileItem");
105 $dependentkey = "ProfileID";
107 elsif ( $item eq "Directory" )
109 @dependentitems = ("File", "Shortcut", "Unixlink");
110 $dependentkey = "Dir";
111 $collect_children = 1;
114 for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ )
116 if ( ${$parfilecontent}[$i] =~ /^\s*$removeitem\s*(\w+?)\s*$/ )
118 my $onegid = $1;
119 push(@gidcollector, $onegid);
120 if ( $collect_children ) { collect_children_dirs($onegid, \@gidcollector); }
122 my $gid;
123 foreach $gid (@gidcollector)
125 delete($par2script::globals::definitions{$item}->{$gid});
127 # also deleting all dependent items, for example "ProfileItems" whose "ProfileID" is this "Profile"
128 my $depitem;
129 foreach $depitem ( @dependentitems )
131 if ( exists($par2script::globals::definitions{$depitem}) )
133 my $onedefinition;
134 foreach $onedefinition (keys %{$par2script::globals::definitions{$depitem}})
136 if ( $par2script::globals::definitions{$depitem}->{$onedefinition}->{$dependentkey} eq $gid )
138 delete($par2script::globals::definitions{$depitem}->{$onedefinition});