1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweirpackage installer::configuration;
29*cdf0e10cSrcweir
30*cdf0e10cSrcweiruse Cwd;
31*cdf0e10cSrcweiruse installer::converter;
32*cdf0e10cSrcweiruse installer::existence;
33*cdf0e10cSrcweiruse installer::exiter;
34*cdf0e10cSrcweiruse installer::files;
35*cdf0e10cSrcweiruse installer::globals;
36*cdf0e10cSrcweiruse installer::logger;
37*cdf0e10cSrcweiruse installer::remover;
38*cdf0e10cSrcweiruse installer::systemactions;
39*cdf0e10cSrcweir
40*cdf0e10cSrcweir################################################################################
41*cdf0e10cSrcweir# Getting package from configurationitem (for instance: org.openoffice.Office)
42*cdf0e10cSrcweir# Getting name from configurationitem (for instance: Common)
43*cdf0e10cSrcweir################################################################################
44*cdf0e10cSrcweir
45*cdf0e10cSrcweirsub analyze_path_of_configurationitem
46*cdf0e10cSrcweir{
47*cdf0e10cSrcweir	my ($configurationitemsref) = @_;
48*cdf0e10cSrcweir
49*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::analyze_path_of_configurationitem : $#{$configurationitemsref}"); }
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir	my ($startpath, $nodes, $name, $packagename, $onenode, $first, $second, $third, $bracketnode);
52*cdf0e10cSrcweir
53*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$configurationitemsref}; $i++ )
54*cdf0e10cSrcweir	{
55*cdf0e10cSrcweir		my $oneconfig = ${$configurationitemsref}[$i];
56*cdf0e10cSrcweir		my $path = $oneconfig->{'Path'};
57*cdf0e10cSrcweir
58*cdf0e10cSrcweir		installer::remover::remove_leading_and_ending_slashes(\$path);	# in scp are some path beginning with "/"
59*cdf0e10cSrcweir
60*cdf0e10cSrcweir		if ( $path =~ /^\s*(.*?)\/(.*)\s*$/ )
61*cdf0e10cSrcweir		{
62*cdf0e10cSrcweir			$startpath = $1;
63*cdf0e10cSrcweir			$nodes = $2;
64*cdf0e10cSrcweir		}
65*cdf0e10cSrcweir		else
66*cdf0e10cSrcweir		{
67*cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Unknown format of ConfigurationItem path: $path", "analyze_path_of_configurationitem");
68*cdf0e10cSrcweir		}
69*cdf0e10cSrcweir
70*cdf0e10cSrcweir		# Startpath is now: org.openoffice.Setup
71*cdf0e10cSrcweir		# Nodes is now: Office/Factories/com.sun.star.chart.ChartDocument
72*cdf0e10cSrcweir
73*cdf0e10cSrcweir		# Dividing the startpath into package (org.openoffic) and name (Setup).
74*cdf0e10cSrcweir
75*cdf0e10cSrcweir		$oneconfig->{'startpath'} = $startpath;	# saving the startpath into the hash
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir		if ( $startpath =~ /^\s*(\S*)\.(\S*?)\s*$/ )
78*cdf0e10cSrcweir		{
79*cdf0e10cSrcweir			$packagename = $1;
80*cdf0e10cSrcweir			$name = $2;
81*cdf0e10cSrcweir			$oneconfig->{'name'} = $name;
82*cdf0e10cSrcweir			$oneconfig->{'packagename'} = $packagename;
83*cdf0e10cSrcweir		}
84*cdf0e10cSrcweir		else
85*cdf0e10cSrcweir		{
86*cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: Unknown format of ConfigurationItem startpath: $startpath", "analyze_path_of_configurationitem");
87*cdf0e10cSrcweir		}
88*cdf0e10cSrcweir
89*cdf0e10cSrcweir		# Collecting all nodes
90*cdf0e10cSrcweir
91*cdf0e10cSrcweir		installer::remover::remove_leading_and_ending_slashes(\$nodes);
92*cdf0e10cSrcweir
93*cdf0e10cSrcweir		my $counter = 1;
94*cdf0e10cSrcweir
95*cdf0e10cSrcweir		# Attention: Do not trust the slash
96*cdf0e10cSrcweir		# Filters/Filter['StarWriter 5.0 Vorlage/Template']
97*cdf0e10cSrcweir		# Menus/New/*['m10']/Title
98*cdf0e10cSrcweir
99*cdf0e10cSrcweir		if ( $nodes =~ /^(.*\[\')(.*\/.*)(\'\].*)$/ )
100*cdf0e10cSrcweir		{
101*cdf0e10cSrcweir			$first = $1;
102*cdf0e10cSrcweir			$second = $2;
103*cdf0e10cSrcweir			$third = $3;
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir			$second =~ s/\//SUBSTITUTEDSLASH/g;	# substituting "/" to "SUBSTITUTEDSLASH"
106*cdf0e10cSrcweir			$nodes = $first . $second . $third;
107*cdf0e10cSrcweir		}
108*cdf0e10cSrcweir
109*cdf0e10cSrcweir		while ( $nodes =~ /\// )
110*cdf0e10cSrcweir		{
111*cdf0e10cSrcweir			if ($nodes =~ /^\s*(.*?)\/(.*)\s*$/ )
112*cdf0e10cSrcweir			{
113*cdf0e10cSrcweir				$onenode = $1;
114*cdf0e10cSrcweir				$nodes = $2;
115*cdf0e10cSrcweir				$nodename = "node". $counter;
116*cdf0e10cSrcweir
117*cdf0e10cSrcweir				# Special handling for filters. Difference between:
118*cdf0e10cSrcweir				# Filter['StarWriter 5.0 Vorlage/Template']	without oor:op="replace"
119*cdf0e10cSrcweir				# *['m10'] with oor:op="replace"
120*cdf0e10cSrcweir
121*cdf0e10cSrcweir				if ( $onenode =~ /^\s*Filter\[\'(.*)\'\].*$/ ) { $oneconfig->{'isfilter'} = 1; }
122*cdf0e10cSrcweir
123*cdf0e10cSrcweir				# Changing the nodes with brackets:
124*cdf0e10cSrcweir				# Filter['StarWriter 5.0 Vorlage/Template']
125*cdf0e10cSrcweir				# *['m10']
126*cdf0e10cSrcweir
127*cdf0e10cSrcweir				if ( $onenode =~ /^.*\[\'(.*)\'\].*$/ )
128*cdf0e10cSrcweir				{
129*cdf0e10cSrcweir					$onenode = $1;
130*cdf0e10cSrcweir					$bracketnode = "bracket_" . $nodename;
131*cdf0e10cSrcweir					$oneconfig->{$bracketnode} = 1;
132*cdf0e10cSrcweir				}
133*cdf0e10cSrcweir
134*cdf0e10cSrcweir				$onenode =~ s/SUBSTITUTEDSLASH/\//g;	# substituting "SUBSTITUTEDSLASH" to "/"
135*cdf0e10cSrcweir				$oneconfig->{$nodename} = $onenode;
136*cdf0e10cSrcweir
137*cdf0e10cSrcweir				# special handling for nodes "Factories"
138*cdf0e10cSrcweir
139*cdf0e10cSrcweir				if ( $onenode eq "Factories" ) { $oneconfig->{'factoriesnode'} = $counter; }
140*cdf0e10cSrcweir				else { $oneconfig->{'factoriesnode'} = -99; }
141*cdf0e10cSrcweir			}
142*cdf0e10cSrcweir
143*cdf0e10cSrcweir			$counter++
144*cdf0e10cSrcweir		}
145*cdf0e10cSrcweir
146*cdf0e10cSrcweir		# and the final node
147*cdf0e10cSrcweir
148*cdf0e10cSrcweir		if ( $nodes =~ /^\s*Filter\[\'(.*)\'\].*$/ ) { $oneconfig->{'isfilter'} = 1; }
149*cdf0e10cSrcweir
150*cdf0e10cSrcweir		$nodename = "node". $counter;
151*cdf0e10cSrcweir
152*cdf0e10cSrcweir		if ( $nodes =~ /^.*\[\'(.*)\'\].*$/ )
153*cdf0e10cSrcweir		{
154*cdf0e10cSrcweir			$nodes = $1;
155*cdf0e10cSrcweir			$bracketnode = "bracket_" . $nodename;
156*cdf0e10cSrcweir			$oneconfig->{$bracketnode} = 1;
157*cdf0e10cSrcweir		}
158*cdf0e10cSrcweir
159*cdf0e10cSrcweir		$nodes =~ s/SUBSTITUTEDSLASH/\//g;	# substituting "SUBSTITUTEDSLASH" to "/"
160*cdf0e10cSrcweir
161*cdf0e10cSrcweir		if (($nodes eq "Name") || ($nodes eq "Title"))	# isocodes below "Name" or "Title"
162*cdf0e10cSrcweir		{
163*cdf0e10cSrcweir			# if the last node $nodes is "Name" or "Title", it is a Property, not a name! See Common.xcu
164*cdf0e10cSrcweir
165*cdf0e10cSrcweir			$oneconfig->{'isisocode'} = 1;
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir			if ( $nodes eq "Name" ) { $oneconfig->{'isname'} = 1; }
168*cdf0e10cSrcweir			if ( $nodes eq "Title" ) { $oneconfig->{'istitle'} = 1;	}
169*cdf0e10cSrcweir			$counter--;		# decreasing the counter, because "Name" and "Title" are no nodes
170*cdf0e10cSrcweir		}
171*cdf0e10cSrcweir		else
172*cdf0e10cSrcweir		{
173*cdf0e10cSrcweir			$oneconfig->{$nodename} = $nodes;
174*cdf0e10cSrcweir			$oneconfig->{'isisocode'} = 0;
175*cdf0e10cSrcweir		}
176*cdf0e10cSrcweir
177*cdf0e10cSrcweir		# special handling for nodes "Factories"
178*cdf0e10cSrcweir
179*cdf0e10cSrcweir		if ( $onenode eq "Factories" ) { $oneconfig->{'factoriesnode'} = $counter; }
180*cdf0e10cSrcweir		else { $oneconfig->{'factoriesnode'} = -99; }
181*cdf0e10cSrcweir
182*cdf0e10cSrcweir		# saving the number of nodes
183*cdf0e10cSrcweir
184*cdf0e10cSrcweir		$oneconfig->{'nodenumber'} = $counter;
185*cdf0e10cSrcweir	}
186*cdf0e10cSrcweir}
187*cdf0e10cSrcweir
188*cdf0e10cSrcweir####################################################################
189*cdf0e10cSrcweir# Inserting the start block into a configuration file
190*cdf0e10cSrcweir####################################################################
191*cdf0e10cSrcweir
192*cdf0e10cSrcweirsub insert_start_block_into_configfile
193*cdf0e10cSrcweir{
194*cdf0e10cSrcweir	my ($configfileref, $oneconfig) = @_;
195*cdf0e10cSrcweir
196*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::insert_start_block_into_configfile : $#{$configfileref} : $oneconfig->{'name'}"); }
197*cdf0e10cSrcweir
198*cdf0e10cSrcweir	my $line = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
199*cdf0e10cSrcweir	push( @{$configfileref}, $line);
200*cdf0e10cSrcweir
201*cdf0e10cSrcweir	$line = '<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:install="http://openoffice.org/2004/installation" oor:name="FILENAME" oor:package="PACKAGENAME">' . "\n";
202*cdf0e10cSrcweir	my $packagename = $oneconfig->{'packagename'};
203*cdf0e10cSrcweir	my $name = $oneconfig->{'name'};
204*cdf0e10cSrcweir	$line =~ s/PACKAGENAME/$packagename/g;
205*cdf0e10cSrcweir	$line =~ s/FILENAME/$name/g;
206*cdf0e10cSrcweir	push( @{$configfileref}, $line);
207*cdf0e10cSrcweir
208*cdf0e10cSrcweir	$line = "\n";
209*cdf0e10cSrcweir	push( @{$configfileref}, $line);
210*cdf0e10cSrcweir}
211*cdf0e10cSrcweir
212*cdf0e10cSrcweir####################################################################
213*cdf0e10cSrcweir# Inserting the end block into a configuration file
214*cdf0e10cSrcweir####################################################################
215*cdf0e10cSrcweir
216*cdf0e10cSrcweirsub insert_end_block_into_configfile
217*cdf0e10cSrcweir{
218*cdf0e10cSrcweir	my ($configfileref) = @_;
219*cdf0e10cSrcweir
220*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::insert_end_block_into_configfile : $#{$configfileref}"); }
221*cdf0e10cSrcweir
222*cdf0e10cSrcweir	my $line = "\n" . '</oor:component-data>' . "\n";
223*cdf0e10cSrcweir	push( @{$configfileref}, $line);
224*cdf0e10cSrcweir}
225*cdf0e10cSrcweir
226*cdf0e10cSrcweir##############################################################
227*cdf0e10cSrcweir# Getting the content of a node
228*cdf0e10cSrcweir##############################################################
229*cdf0e10cSrcweir
230*cdf0e10cSrcweirsub get_node_content
231*cdf0e10cSrcweir{
232*cdf0e10cSrcweir	my ($nodeline) = @_;
233*cdf0e10cSrcweir
234*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::get_node_content : $nodeline"); }
235*cdf0e10cSrcweir
236*cdf0e10cSrcweir	my $content = "";
237*cdf0e10cSrcweir
238*cdf0e10cSrcweir	if ( $nodeline =~ /name\=\"(.*?)\"/ )
239*cdf0e10cSrcweir	{
240*cdf0e10cSrcweir		$content = $1;
241*cdf0e10cSrcweir	}
242*cdf0e10cSrcweir	else
243*cdf0e10cSrcweir	{
244*cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Impossible error in function get_node_content!", "get_node_content");
245*cdf0e10cSrcweir	}
246*cdf0e10cSrcweir
247*cdf0e10cSrcweir	return \$content;
248*cdf0e10cSrcweir}
249*cdf0e10cSrcweir
250*cdf0e10cSrcweir##############################################################
251*cdf0e10cSrcweir# Getting the line number of an existing node
252*cdf0e10cSrcweir# Return "-1" if node does not exist
253*cdf0e10cSrcweir##############################################################
254*cdf0e10cSrcweir
255*cdf0e10cSrcweirsub get_node_line_number
256*cdf0e10cSrcweir{
257*cdf0e10cSrcweir	my ($nodecount, $oneconfig, $oneconfigfileref) = @_;
258*cdf0e10cSrcweir
259*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::get_node_line_number : $nodecount : $oneconfig->{'name'} : $#{$oneconfigfileref}"); }
260*cdf0e10cSrcweir
261*cdf0e10cSrcweir	my $linenumber = -1;	# the node does not exists, if returnvalue is "-1"
262*cdf0e10cSrcweir
263*cdf0e10cSrcweir	# Attention: Take care of the two title nodes:
264*cdf0e10cSrcweir	# Path=org.openoffice.Office.Common/Menus/Wizard/*['m14']/Title
265*cdf0e10cSrcweir	# Path=org.openoffice.Office.Common/Menus/Wizard/*['m15']/Title
266*cdf0e10cSrcweir	# -> every subnode has to be identical
267*cdf0e10cSrcweir
268*cdf0e10cSrcweir	# creating the allnodes string from $oneconfig
269*cdf0e10cSrcweir
270*cdf0e10cSrcweir	my $allnodes = "";
271*cdf0e10cSrcweir
272*cdf0e10cSrcweir	for ( my $i = 1; $i <= $nodecount; $i++ )
273*cdf0e10cSrcweir	{
274*cdf0e10cSrcweir		my $nodename = "node" . $i;
275*cdf0e10cSrcweir		$allnodes .= $oneconfig->{$nodename} . "/";
276*cdf0e10cSrcweir	}
277*cdf0e10cSrcweir
278*cdf0e10cSrcweir	installer::remover::remove_leading_and_ending_slashes(\$allnodes);	# exactly this string has to be found  in the following iteration
279*cdf0e10cSrcweir
280*cdf0e10cSrcweir	# Iterating over the already built configuration file
281*cdf0e10cSrcweir
282*cdf0e10cSrcweir	my @allnodes = ();
283*cdf0e10cSrcweir
284*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$oneconfigfileref}; $i++ )
285*cdf0e10cSrcweir	{
286*cdf0e10cSrcweir		my $line = ${$oneconfigfileref}[$i];
287*cdf0e10cSrcweir		installer::remover::remove_leading_and_ending_whitespaces(\$line);
288*cdf0e10cSrcweir		my $nodechanged = 0;
289*cdf0e10cSrcweir
290*cdf0e10cSrcweir		if ( $line =~ /^\s*\<node/ )	# opening node
291*cdf0e10cSrcweir		{
292*cdf0e10cSrcweir			$nodechanged = 1;
293*cdf0e10cSrcweir			my $nodecontentref = get_node_content($line);
294*cdf0e10cSrcweir			push(@allnodes, $$nodecontentref);	# collecting all nodes in an array
295*cdf0e10cSrcweir		}
296*cdf0e10cSrcweir
297*cdf0e10cSrcweir		if ( $line =~ /^\s*\<\/node/ )	# ending node
298*cdf0e10cSrcweir		{
299*cdf0e10cSrcweir			$nodechanged = 1;
300*cdf0e10cSrcweir			pop(@allnodes);		# removing the last node from the array
301*cdf0e10cSrcweir		}
302*cdf0e10cSrcweir
303*cdf0e10cSrcweir		if (( $nodechanged ) && ($#allnodes > -1))	# a node was found and the node array is not empty
304*cdf0e10cSrcweir		{
305*cdf0e10cSrcweir			# creating the string to compare with the string $allnodes
306*cdf0e10cSrcweir
307*cdf0e10cSrcweir			my $nodestring = "";
308*cdf0e10cSrcweir
309*cdf0e10cSrcweir			for ( my $j = 0; $j <= $#allnodes; $j++ )
310*cdf0e10cSrcweir			{
311*cdf0e10cSrcweir				$nodestring .= $allnodes[$j] . "/";
312*cdf0e10cSrcweir			}
313*cdf0e10cSrcweir
314*cdf0e10cSrcweir			installer::remover::remove_leading_and_ending_slashes(\$nodestring);
315*cdf0e10cSrcweir
316*cdf0e10cSrcweir			if ( $nodestring eq $allnodes )
317*cdf0e10cSrcweir			{
318*cdf0e10cSrcweir				# that is exactly the same node
319*cdf0e10cSrcweir
320*cdf0e10cSrcweir				$linenumber = $i;
321*cdf0e10cSrcweir				$linenumber++;	# increasing the linenumber
322*cdf0e10cSrcweir				last;
323*cdf0e10cSrcweir
324*cdf0e10cSrcweir			}
325*cdf0e10cSrcweir		}
326*cdf0e10cSrcweir	}
327*cdf0e10cSrcweir
328*cdf0e10cSrcweir	return $linenumber;
329*cdf0e10cSrcweir}
330*cdf0e10cSrcweir
331*cdf0e10cSrcweir##############################################################
332*cdf0e10cSrcweir# Inserting one configurationitem into the configurationfile
333*cdf0e10cSrcweir##############################################################
334*cdf0e10cSrcweir
335*cdf0e10cSrcweirsub insert_into_config_file
336*cdf0e10cSrcweir{
337*cdf0e10cSrcweir	my ($oneconfig, $oneconfigfileref) = @_;
338*cdf0e10cSrcweir
339*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::insert_into_config_file : $oneconfig->{'nodenumber'} : $#{$oneconfigfileref}"); }
340*cdf0e10cSrcweir
341*cdf0e10cSrcweir	my ($nodename, $nodecontent, $newnodeline, $bracketkey, $line, $insertline);
342*cdf0e10cSrcweir
343*cdf0e10cSrcweir	# interpreting the nodes, keys and values
344*cdf0e10cSrcweir
345*cdf0e10cSrcweir	my $nodeline = '<node oor:name="NODECONTENT" REPLACEPART >' . "\n";
346*cdf0e10cSrcweir	my $propline = '<prop oor:name="KEYCONTENT" REPLACEPART TYPEPART>' . "\n";
347*cdf0e10cSrcweir	my $valueline = '<value SEPARATORPART>VALUECONTENT</value>' . "\n";
348*cdf0e10cSrcweir	my $langvalueline = '<value xml:lang="SAVEDLANGUAGE">VALUECONTENT</value>' . "\n";
349*cdf0e10cSrcweir	my $propendline = '</prop>' . "\n";
350*cdf0e10cSrcweir	my $nodeendline = '</node>' . "\n";
351*cdf0e10cSrcweir
352*cdf0e10cSrcweir	my $replacepart = 'oor:op="replace"';
353*cdf0e10cSrcweir	my $typepart = 'oor:type="xs:VALUETYPE"';	# VALUETYPE can be "string", "boolean", ...
354*cdf0e10cSrcweir
355*cdf0e10cSrcweir	my $nodecount = $oneconfig->{'nodenumber'};
356*cdf0e10cSrcweir	my $styles = $oneconfig->{'Styles'};
357*cdf0e10cSrcweir
358*cdf0e10cSrcweir	for ( my $i = 1; $i <= $nodecount; $i++ )
359*cdf0e10cSrcweir	{
360*cdf0e10cSrcweir		$insertline = get_node_line_number($i, $oneconfig, $oneconfigfileref);
361*cdf0e10cSrcweir
362*cdf0e10cSrcweir		if ( $insertline == -1)	# if true, the node does not exist
363*cdf0e10cSrcweir		{
364*cdf0e10cSrcweir			$nodename = "node" . $i;
365*cdf0e10cSrcweir			$nodecontent = $oneconfig->{$nodename};
366*cdf0e10cSrcweir			$newnodeline = $nodeline;
367*cdf0e10cSrcweir
368*cdf0e10cSrcweir			$newnodeline =~ s/NODECONTENT/$nodecontent/g;
369*cdf0e10cSrcweir
370*cdf0e10cSrcweir			# Case1:
371*cdf0e10cSrcweir			# Nodes with brackets, need the replacepart 'oor:op="replace"'
372*cdf0e10cSrcweir			# Bracket node is set for each node with: bracket_node1=1, bracket_node2=1, ...
373*cdf0e10cSrcweir			# Case a: <node oor:name="m0" oor:op="replace">		(Common.xcu needs oor:op="replace")
374*cdf0e10cSrcweir			# Case b: <node oor:name="Ami Pro 1.x-3.1 (W4W)">	(TypeDetection.xcu does not need oor:op="replace")
375*cdf0e10cSrcweir			# For case b introducting a special case for Filters
376*cdf0e10cSrcweir
377*cdf0e10cSrcweir			$bracketkey = "bracket_" . $nodename;
378*cdf0e10cSrcweir
379*cdf0e10cSrcweir			my $localbracketkey = 0;
380*cdf0e10cSrcweir
381*cdf0e10cSrcweir			if ( $oneconfig->{$bracketkey} ) { $localbracketkey = $oneconfig->{$bracketkey}; }
382*cdf0e10cSrcweir
383*cdf0e10cSrcweir			if ( $localbracketkey == 1 )	# 'oor:op="replace"' is needed
384*cdf0e10cSrcweir			{
385*cdf0e10cSrcweir				my $isfilter = 0;
386*cdf0e10cSrcweir				if ( $oneconfig->{'isfilter'} ) { $isfilter = $oneconfig->{'isfilter'}; }
387*cdf0e10cSrcweir
388*cdf0e10cSrcweir				if ( $isfilter == 1 )	# this is a filter
389*cdf0e10cSrcweir				{
390*cdf0e10cSrcweir					$newnodeline =~ s/REPLACEPART//;
391*cdf0e10cSrcweir				}
392*cdf0e10cSrcweir				else
393*cdf0e10cSrcweir				{
394*cdf0e10cSrcweir					$newnodeline =~ s/REPLACEPART/$replacepart/;
395*cdf0e10cSrcweir				}
396*cdf0e10cSrcweir
397*cdf0e10cSrcweir				$newnodeline =~ s/\s*\>/\>/;	# removing resulting whitespaces
398*cdf0e10cSrcweir			}
399*cdf0e10cSrcweir
400*cdf0e10cSrcweir			# Case2:
401*cdf0e10cSrcweir			# Nodes below a Node "Factories", also need the replacepart 'oor:op="replace"'
402*cdf0e10cSrcweir			# This is saved in $oneconfig->{'factoriesnode'}. If not set, the value is "-99"
403*cdf0e10cSrcweir
404*cdf0e10cSrcweir			if ( $i == $oneconfig->{'factoriesnode'} )
405*cdf0e10cSrcweir			{
406*cdf0e10cSrcweir				$newnodeline =~ s/REPLACEPART/$replacepart/;
407*cdf0e10cSrcweir				$newnodeline =~ s/\s*\>/\>/;	# removing resulting whitespaces
408*cdf0e10cSrcweir			}
409*cdf0e10cSrcweir
410*cdf0e10cSrcweir			# Case3:
411*cdf0e10cSrcweir			# In all other cases, REPLACEPART in nodes can be removed
412*cdf0e10cSrcweir
413*cdf0e10cSrcweir			$newnodeline =~ s/REPLACEPART//;
414*cdf0e10cSrcweir			$newnodeline =~ s/\s*\>/\>/;	# removing resulting whitespaces
415*cdf0e10cSrcweir
416*cdf0e10cSrcweir			# Finding the correct place for inserting the node
417*cdf0e10cSrcweir
418*cdf0e10cSrcweir			if ( $i == 1 )	# this is a toplevel node
419*cdf0e10cSrcweir			{
420*cdf0e10cSrcweir				push(@{$oneconfigfileref}, $newnodeline);
421*cdf0e10cSrcweir				push(@{$oneconfigfileref}, $nodeendline);
422*cdf0e10cSrcweir			}
423*cdf0e10cSrcweir			else
424*cdf0e10cSrcweir			{
425*cdf0e10cSrcweir				# searching for the parent node
426*cdf0e10cSrcweir
427*cdf0e10cSrcweir				my $parentnumber = $i-1;
428*cdf0e10cSrcweir				$insertline = get_node_line_number($parentnumber, $oneconfig, $oneconfigfileref);
429*cdf0e10cSrcweir				splice(@{$oneconfigfileref}, $insertline, 0, ($newnodeline, $nodeendline));
430*cdf0e10cSrcweir			}
431*cdf0e10cSrcweir		}
432*cdf0e10cSrcweir	}
433*cdf0e10cSrcweir
434*cdf0e10cSrcweir	# Setting variables $isbracketnode and $isfactorynode for the properties
435*cdf0e10cSrcweir
436*cdf0e10cSrcweir
437*cdf0e10cSrcweir	my $isbracketnode = 0;
438*cdf0e10cSrcweir	my $isfactorynode = 0;
439*cdf0e10cSrcweir
440*cdf0e10cSrcweir	for ( my $i = 1; $i <= $nodecount; $i++ )
441*cdf0e10cSrcweir	{
442*cdf0e10cSrcweir		$nodename = "node" . $i;
443*cdf0e10cSrcweir		$bracketkey = "bracket_" . $nodename;
444*cdf0e10cSrcweir
445*cdf0e10cSrcweir		my $localbracketkey = 0;
446*cdf0e10cSrcweir		if ( $oneconfig->{$bracketkey} ) { $localbracketkey = $oneconfig->{$bracketkey}; }
447*cdf0e10cSrcweir
448*cdf0e10cSrcweir		if ( $localbracketkey == 1 ) { $isbracketnode = 1;	}
449*cdf0e10cSrcweir		if ( $i == $oneconfig->{'factoriesnode'} ) { $isfactorynode = 1; }
450*cdf0e10cSrcweir	}
451*cdf0e10cSrcweir
452*cdf0e10cSrcweir	# now all nodes exist, and the key and value can be inserted into the configfile
453*cdf0e10cSrcweir	# the next line contains the key, for instance: <prop oor:name="UseDefaultMailer" oor:type="xs:boolean">
454*cdf0e10cSrcweir	# my $propline = '<prop oor:name="KEYCONTENT" REPLACEPART TYPEPART>' . "\n";
455*cdf0e10cSrcweir	# The type is only needed, if a replace is set.
456*cdf0e10cSrcweir
457*cdf0e10cSrcweir	my $newpropline = $propline;
458*cdf0e10cSrcweir
459*cdf0e10cSrcweir	# Replacement of KEYCONTENT, REPLACEPART and TYPEPART
460*cdf0e10cSrcweir
461*cdf0e10cSrcweir	# Case 1:
462*cdf0e10cSrcweir	# Properties with oor:name="Name" (Common.xcu) are simply <prop oor:name="Name">
463*cdf0e10cSrcweir	# The information about such a property is stored in $oneconfig->{'isisocode'}
464*cdf0e10cSrcweir
465*cdf0e10cSrcweir	if ( $oneconfig->{'isisocode'} )
466*cdf0e10cSrcweir	{
467*cdf0e10cSrcweir		if ( $oneconfig->{'isname'} ) { $newpropline =~ s/KEYCONTENT/Name/; }		# The property name is always "Name"
468*cdf0e10cSrcweir		if ( $oneconfig->{'istitle'} ) { $newpropline =~ s/KEYCONTENT/Title/; }		# The property name is always "Title"
469*cdf0e10cSrcweir		$newpropline =~ s/REPLACEPART//;
470*cdf0e10cSrcweir		$newpropline =~ s/TYPEPART//;
471*cdf0e10cSrcweir		$newpropline =~ s/\s*\>/\>/;	# removing resulting whitespaces
472*cdf0e10cSrcweir	}
473*cdf0e10cSrcweir
474*cdf0e10cSrcweir	# Begin of all other cases
475*cdf0e10cSrcweir
476*cdf0e10cSrcweir	my $key = $oneconfig->{'Key'};
477*cdf0e10cSrcweir	$newpropline =~ s/KEYCONTENT/$key/;
478*cdf0e10cSrcweir
479*cdf0e10cSrcweir	my $valuetype;
480*cdf0e10cSrcweir
481*cdf0e10cSrcweir	if ( $styles =~ /CFG_STRING\b/ ) { $valuetype = "string"; }
482*cdf0e10cSrcweir	elsif ( $styles =~ /CFG_NUMERIC/ ) { $valuetype = "int"; }
483*cdf0e10cSrcweir	elsif ( $styles =~ /CFG_BOOLEAN/ ) { $valuetype = "boolean"; }
484*cdf0e10cSrcweir	elsif ( $styles =~ /CFG_STRINGLIST/ ) { $valuetype = "string-list"; }
485*cdf0e10cSrcweir#	elsif ( $styles =~ /CFG_STRINGLIST/ ) { $valuetype = "string-list oor:separator=\"\|\""; }
486*cdf0e10cSrcweir	else
487*cdf0e10cSrcweir	{
488*cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Unknown configuration value type: $styles", "insert_into_config_file");
489*cdf0e10cSrcweir	}
490*cdf0e10cSrcweir
491*cdf0e10cSrcweir	# Case 2:
492*cdf0e10cSrcweir	# Properties below a node "Factories" do not need a 'oor:op="replace"' and a 'oor:type="xs:VALUETYPE"'
493*cdf0e10cSrcweir
494*cdf0e10cSrcweir	if ( $isfactorynode )
495*cdf0e10cSrcweir	{
496*cdf0e10cSrcweir		$newpropline =~ s/REPLACEPART//;
497*cdf0e10cSrcweir		$newpropline =~ s/TYPEPART//;
498*cdf0e10cSrcweir		$newpropline =~ s/\s*\>/\>/;	# removing resulting whitespaces
499*cdf0e10cSrcweir	}
500*cdf0e10cSrcweir
501*cdf0e10cSrcweir	# Case 3:
502*cdf0e10cSrcweir	# Properties below a "bracket" node do not need a 'oor:op="replace"', except they are iso-codes
503*cdf0e10cSrcweir	# Assumption here: They are multilingual
504*cdf0e10cSrcweir
505*cdf0e10cSrcweir	if ( $isbracketnode )
506*cdf0e10cSrcweir	{
507*cdf0e10cSrcweir		my $localtypepart = $typepart;
508*cdf0e10cSrcweir		$localtypepart =~ s/VALUETYPE/$valuetype/;
509*cdf0e10cSrcweir		$newpropline =~ s/TYPEPART/$localtypepart/;
510*cdf0e10cSrcweir
511*cdf0e10cSrcweir		if ( $oneconfig->{'ismultilingual'} )	# This is solved by "Name" and "Title"
512*cdf0e10cSrcweir		{
513*cdf0e10cSrcweir			$newpropline =~ s/REPLACEPART/$replacepart/;
514*cdf0e10cSrcweir		}
515*cdf0e10cSrcweir		else
516*cdf0e10cSrcweir		{
517*cdf0e10cSrcweir			$newpropline =~ s/REPLACEPART//;
518*cdf0e10cSrcweir		}
519*cdf0e10cSrcweir
520*cdf0e10cSrcweir		$newpropline =~ s/\s*\>/\>/;	# removing resulting whitespaces
521*cdf0e10cSrcweir	}
522*cdf0e10cSrcweir
523*cdf0e10cSrcweir	# Case 4:
524*cdf0e10cSrcweir	# if the flag CREATE is set, the properties get 'oor:op="replace"' and 'oor:type="xs:VALUETYPE"'
525*cdf0e10cSrcweir
526*cdf0e10cSrcweir	if (( $styles =~ /\bCREATE\b/ ) && (!($isbracketnode)))
527*cdf0e10cSrcweir	{
528*cdf0e10cSrcweir		# my $typepart = 'oor:type="xs:VALUETYPE"';	# VALUETYPE can be "string", "boolean", ...
529*cdf0e10cSrcweir
530*cdf0e10cSrcweir		my $localtypepart = $typepart;
531*cdf0e10cSrcweir		$localtypepart =~ s/VALUETYPE/$valuetype/;
532*cdf0e10cSrcweir
533*cdf0e10cSrcweir		$newpropline =~ s/TYPEPART/$localtypepart/;
534*cdf0e10cSrcweir		$newpropline =~ s/REPLACEPART/$replacepart/;
535*cdf0e10cSrcweir		$newpropline =~ s/\s*\>/\>/;	# removing resulting whitespaces
536*cdf0e10cSrcweir	}
537*cdf0e10cSrcweir
538*cdf0e10cSrcweir	# Case 5:
539*cdf0e10cSrcweir	# all other ConfigurationItems do not need 'oor:op="replace"' and 'oor:type="xs:VALUETYPE"'
540*cdf0e10cSrcweir
541*cdf0e10cSrcweir	$newpropline =~ s/REPLACEPART//;
542*cdf0e10cSrcweir	$newpropline =~ s/TYPEPART//;
543*cdf0e10cSrcweir	$newpropline =~ s/\s*\>/\>/;	# removing resulting whitespaces
544*cdf0e10cSrcweir
545*cdf0e10cSrcweir	# finally the value can be set
546*cdf0e10cSrcweir
547*cdf0e10cSrcweir	my $value = $oneconfig->{'Value'};
548*cdf0e10cSrcweir
549*cdf0e10cSrcweir	# Some values in setup script are written during installation process by the setup. These
550*cdf0e10cSrcweir	# have values like "<title>". This will lead to an error, because of the brackets. Therefore the
551*cdf0e10cSrcweir	# brackets have to be removed.
552*cdf0e10cSrcweir
553*cdf0e10cSrcweir	# ToDo: Substituting the setup replace variables
554*cdf0e10cSrcweir
555*cdf0e10cSrcweir	# replace_setting_variables();
556*cdf0e10cSrcweir
557*cdf0e10cSrcweir	$value =~ s/^\s*\<//;
558*cdf0e10cSrcweir	$value =~ s/\>\s*$//;
559*cdf0e10cSrcweir
560*cdf0e10cSrcweir	# Deal with list separators
561*cdf0e10cSrcweir	my $separatorpart = '';
562*cdf0e10cSrcweir	if ( ($valuetype eq "string-list") && ($value =~ /\|/) )
563*cdf0e10cSrcweir    {
564*cdf0e10cSrcweir	    $separatorpart = 'oor:separator="|"';
565*cdf0e10cSrcweir    }
566*cdf0e10cSrcweir
567*cdf0e10cSrcweir	# Fake: substituting german umlauts
568*cdf0e10cSrcweir
569*cdf0e10cSrcweir	$value =~ s/\�/ae/;
570*cdf0e10cSrcweir	$value =~ s/\�/oe/;
571*cdf0e10cSrcweir	$value =~ s/\�/ue/;
572*cdf0e10cSrcweir	$value =~ s/\�/AE/;
573*cdf0e10cSrcweir	$value =~ s/\�/OE/;
574*cdf0e10cSrcweir	$value =~ s/\�/UE/;
575*cdf0e10cSrcweir
576*cdf0e10cSrcweir	my $newvalueline;
577*cdf0e10cSrcweir
578*cdf0e10cSrcweir	if (!($oneconfig->{'isisocode'} ))	# this is the simpe case
579*cdf0e10cSrcweir	{
580*cdf0e10cSrcweir		# my $valueline = '<value SEPARATORPART>VALUECONTENT</value>' . "\n";
581*cdf0e10cSrcweir		$newvalueline = $valueline;
582*cdf0e10cSrcweir		$newvalueline =~ s/VALUECONTENT/$value/g;
583*cdf0e10cSrcweir		$newvalueline =~ s/SEPARATORPART/$separatorpart/;
584*cdf0e10cSrcweir	}
585*cdf0e10cSrcweir	else
586*cdf0e10cSrcweir	{
587*cdf0e10cSrcweir		# my $langvalueline = '<value xml:lang="SAVEDLANGUAGE">VALUECONTENT</value>' . "\n";
588*cdf0e10cSrcweir		$newvalueline = $langvalueline;
589*cdf0e10cSrcweir		$newvalueline =~ s/VALUECONTENT/$value/;
590*cdf0e10cSrcweir		my $savedlanguage = $oneconfig->{'Key'};
591*cdf0e10cSrcweir		$newvalueline =~ s/SAVEDLANGUAGE/$savedlanguage/;
592*cdf0e10cSrcweir	}
593*cdf0e10cSrcweir
594*cdf0e10cSrcweir	# For language dependent values, it is possible, that the property already exist.
595*cdf0e10cSrcweir	# In this case the prop must not be created again and only the value has to be included:
596*cdf0e10cSrcweir	# <prop oor:name="Name">
597*cdf0e10cSrcweir	#  <value xml:lang="de">OpenOffice.org 2.0 Diagramm</value>
598*cdf0e10cSrcweir	#  <value xml:lang="en-US">OpenOffice.org 2.0 Chart</value>
599*cdf0e10cSrcweir	# </prop>
600*cdf0e10cSrcweir
601*cdf0e10cSrcweir	# The key has to be written after the line, containing the complete node
602*cdf0e10cSrcweir
603*cdf0e10cSrcweir	$insertline = get_node_line_number($nodecount, $oneconfig, $oneconfigfileref);
604*cdf0e10cSrcweir
605*cdf0e10cSrcweir	if ( $oneconfig->{'ismultilingual'} )
606*cdf0e10cSrcweir	{
607*cdf0e10cSrcweir		if ( $newpropline eq ${$oneconfigfileref}[$insertline] )
608*cdf0e10cSrcweir		{
609*cdf0e10cSrcweir			if (!($newvalueline eq ${$oneconfigfileref}[$insertline+1]))	# only include, if the value not already exists (example: value="FALSE" for many languages)
610*cdf0e10cSrcweir			{
611*cdf0e10cSrcweir				splice(@{$oneconfigfileref}, $insertline+1, 0, ($newvalueline));	# only the value needs to be added
612*cdf0e10cSrcweir			}
613*cdf0e10cSrcweir		}
614*cdf0e10cSrcweir		else
615*cdf0e10cSrcweir		{
616*cdf0e10cSrcweir			splice(@{$oneconfigfileref}, $insertline, 0, ($newpropline, $newvalueline, $propendline));
617*cdf0e10cSrcweir		}
618*cdf0e10cSrcweir	}
619*cdf0e10cSrcweir	else
620*cdf0e10cSrcweir	{
621*cdf0e10cSrcweir		splice(@{$oneconfigfileref}, $insertline, 0, ($newpropline, $newvalueline, $propendline));
622*cdf0e10cSrcweir	}
623*cdf0e10cSrcweir
624*cdf0e10cSrcweir	return $oneconfigfileref;
625*cdf0e10cSrcweir}
626*cdf0e10cSrcweir
627*cdf0e10cSrcweir##########################################################
628*cdf0e10cSrcweir# Inserting tabs for better view into configuration file
629*cdf0e10cSrcweir##########################################################
630*cdf0e10cSrcweir
631*cdf0e10cSrcweirsub insert_tabs_into_configfile
632*cdf0e10cSrcweir{
633*cdf0e10cSrcweir	my ($configfileref) = @_;
634*cdf0e10cSrcweir
635*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::insert_tabs_into_configfile : $#{$configfileref}"); }
636*cdf0e10cSrcweir
637*cdf0e10cSrcweir	my $counter = 0;
638*cdf0e10cSrcweir
639*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$configfileref}; $i++ )
640*cdf0e10cSrcweir	{
641*cdf0e10cSrcweir		my $line = ${$configfileref}[$i];
642*cdf0e10cSrcweir		my $linebefore = ${$configfileref}[$i-1];
643*cdf0e10cSrcweir
644*cdf0e10cSrcweir		if (( $line =~ /^\s*\<node/ ) || ( $line =~ /^\s*\<prop/ ))
645*cdf0e10cSrcweir		{
646*cdf0e10cSrcweir			if ((!( $linebefore =~ /^\s*\<\/node/ )) && (!( $linebefore =~ /^\s*\<\/prop/ )))		# do not increase after "</node" and after "</prop"
647*cdf0e10cSrcweir			{
648*cdf0e10cSrcweir				$counter++;
649*cdf0e10cSrcweir			}
650*cdf0e10cSrcweir		}
651*cdf0e10cSrcweir
652*cdf0e10cSrcweir		if ( $line =~ /^\s*\<value/ )
653*cdf0e10cSrcweir		{
654*cdf0e10cSrcweir			if (!($linebefore =~ /^\s*\<value/ ))		# do not increase counter with "<value>" after "<value>" (multilingual configitems)
655*cdf0e10cSrcweir			{
656*cdf0e10cSrcweir				$counter++;
657*cdf0e10cSrcweir			}
658*cdf0e10cSrcweir		}
659*cdf0e10cSrcweir
660*cdf0e10cSrcweir		if (( $line =~ /^\s*\<\/node\>/ ) || ( $line =~ /^\s*\<\/prop\>/ ))
661*cdf0e10cSrcweir		{
662*cdf0e10cSrcweir			if ((!( $linebefore =~ /^\s*\<node/ )) && (!( $linebefore =~ /^\s*\<prop/ )))		# do not decrease after "<node" and after "<prop"
663*cdf0e10cSrcweir			{
664*cdf0e10cSrcweir				$counter--;
665*cdf0e10cSrcweir			}
666*cdf0e10cSrcweir		}
667*cdf0e10cSrcweir
668*cdf0e10cSrcweir		if ($counter > 0)
669*cdf0e10cSrcweir		{
670*cdf0e10cSrcweir			for ( my $j = 0; $j < $counter; $j++ )
671*cdf0e10cSrcweir			{
672*cdf0e10cSrcweir				$line = "\t" . $line;
673*cdf0e10cSrcweir			}
674*cdf0e10cSrcweir		}
675*cdf0e10cSrcweir
676*cdf0e10cSrcweir		${$configfileref}[$i] = $line;
677*cdf0e10cSrcweir	}
678*cdf0e10cSrcweir}
679*cdf0e10cSrcweir
680*cdf0e10cSrcweir######################################################################
681*cdf0e10cSrcweir# Collecting all different configuration items (Files and Modules)
682*cdf0e10cSrcweir######################################################################
683*cdf0e10cSrcweir
684*cdf0e10cSrcweirsub collect_all_configuration_items
685*cdf0e10cSrcweir{
686*cdf0e10cSrcweir	my ($configurationitemsref, $item) = @_;
687*cdf0e10cSrcweir
688*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::collect_all_configuration_items : $#{$configurationitemsref} : $item"); }
689*cdf0e10cSrcweir
690*cdf0e10cSrcweir	my @allitems = ();
691*cdf0e10cSrcweir
692*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$configurationitemsref}; $i++ )
693*cdf0e10cSrcweir	{
694*cdf0e10cSrcweir		my $oneconfig = ${$configurationitemsref}[$i];
695*cdf0e10cSrcweir
696*cdf0e10cSrcweir		if (! installer::existence::exists_in_array($oneconfig->{$item}, \@allitems))
697*cdf0e10cSrcweir		{
698*cdf0e10cSrcweir			push(@allitems, $oneconfig->{$item});
699*cdf0e10cSrcweir		}
700*cdf0e10cSrcweir	}
701*cdf0e10cSrcweir
702*cdf0e10cSrcweir	return \@allitems;
703*cdf0e10cSrcweir}
704*cdf0e10cSrcweir
705*cdf0e10cSrcweir######################################################################
706*cdf0e10cSrcweir# Collecting all module specific configuration items
707*cdf0e10cSrcweir######################################################################
708*cdf0e10cSrcweir
709*cdf0e10cSrcweirsub get_all_configitems_at_module
710*cdf0e10cSrcweir{
711*cdf0e10cSrcweir	my ($moduleid, $configurationitemsref) = @_;
712*cdf0e10cSrcweir
713*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::get_all_configitems_at_module : $moduleid : $#{$configurationitemsref}"); }
714*cdf0e10cSrcweir
715*cdf0e10cSrcweir	my @moduleconfigurationitems = ();
716*cdf0e10cSrcweir
717*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$configurationitemsref}; $i++ )
718*cdf0e10cSrcweir	{
719*cdf0e10cSrcweir		my $oneconfig = ${$configurationitemsref}[$i];
720*cdf0e10cSrcweir
721*cdf0e10cSrcweir		if ( $oneconfig->{'ModuleID'} eq $moduleid )
722*cdf0e10cSrcweir		{
723*cdf0e10cSrcweir			push(@moduleconfigurationitems, $oneconfig);
724*cdf0e10cSrcweir		}
725*cdf0e10cSrcweir	}
726*cdf0e10cSrcweir
727*cdf0e10cSrcweir	return \@moduleconfigurationitems;
728*cdf0e10cSrcweir}
729*cdf0e10cSrcweir
730*cdf0e10cSrcweir#######################################################
731*cdf0e10cSrcweir# Saving and zipping the created configurationfile
732*cdf0e10cSrcweir#######################################################
733*cdf0e10cSrcweir
734*cdf0e10cSrcweirsub save_and_zip_configfile
735*cdf0e10cSrcweir{
736*cdf0e10cSrcweir	my ($oneconfigfileref, $onefile, $onemodule, $configdir) = @_;
737*cdf0e10cSrcweir
738*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::save_and_zip_configfile : $#{$oneconfigfileref} : $onefile : $onemodule : $configdir"); }
739*cdf0e10cSrcweir
740*cdf0e10cSrcweir	my $savefilename = $onefile;
741*cdf0e10cSrcweir	$savefilename =~ s/\./\_/g;
742*cdf0e10cSrcweir	$savefilename = $savefilename . "_" . $onemodule;
743*cdf0e10cSrcweir	$savefilename = $savefilename . ".xcu";
744*cdf0e10cSrcweir	my $shortsavefilename = $savefilename;
745*cdf0e10cSrcweir
746*cdf0e10cSrcweir	$savefilename = $configdir . $installer::globals::separator . $savefilename;
747*cdf0e10cSrcweir
748*cdf0e10cSrcweir	installer::files::save_file($savefilename, $oneconfigfileref);
749*cdf0e10cSrcweir
750*cdf0e10cSrcweir	# zipping the configfile
751*cdf0e10cSrcweir
752*cdf0e10cSrcweir	my $returnvalue = 1;
753*cdf0e10cSrcweir
754*cdf0e10cSrcweir	my $zipfilename = $shortsavefilename;
755*cdf0e10cSrcweir	$zipfilename =~ s/\.xcu/\.zip/;
756*cdf0e10cSrcweir
757*cdf0e10cSrcweir	my $currentdir = cwd();
758*cdf0e10cSrcweir	if ( $installer::globals::iswin ) { $currentdir =~ s/\//\\/g; }
759*cdf0e10cSrcweir
760*cdf0e10cSrcweir	chdir($configdir);
761*cdf0e10cSrcweir
762*cdf0e10cSrcweir 	my $systemcall = "$installer::globals::zippath -q -m $zipfilename $shortsavefilename";
763*cdf0e10cSrcweir	$returnvalue = system($systemcall);
764*cdf0e10cSrcweir
765*cdf0e10cSrcweir	chdir($currentdir);
766*cdf0e10cSrcweir
767*cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
768*cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
769*cdf0e10cSrcweir
770*cdf0e10cSrcweir	if ($returnvalue)
771*cdf0e10cSrcweir	{
772*cdf0e10cSrcweir		$infoline = "ERROR: Could not zip $savefilename to $zipfilename\n";
773*cdf0e10cSrcweir	}
774*cdf0e10cSrcweir	else
775*cdf0e10cSrcweir	{
776*cdf0e10cSrcweir		$infoline = "SUCCESS: Zipped file $savefilename to $zipfilename\n";
777*cdf0e10cSrcweir	}
778*cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
779*cdf0e10cSrcweir
780*cdf0e10cSrcweir	return $zipfilename;
781*cdf0e10cSrcweir}
782*cdf0e10cSrcweir
783*cdf0e10cSrcweir#####################################################################
784*cdf0e10cSrcweir# Adding the newly created configuration file into the file list
785*cdf0e10cSrcweir#####################################################################
786*cdf0e10cSrcweir
787*cdf0e10cSrcweirsub add_zipfile_into_filelist
788*cdf0e10cSrcweir{
789*cdf0e10cSrcweir	my ($zipfilename, $configdir, $filesarrayref, $onemodule) = @_;
790*cdf0e10cSrcweir
791*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::add_zipfile_into_filelist: $zipfilename : $configdir : $#{$filesarrayref} : $onemodule"); }
792*cdf0e10cSrcweir
793*cdf0e10cSrcweir	my $longzipfilename = $configdir . $installer::globals::separator . $zipfilename;
794*cdf0e10cSrcweir	my $gid = "gid_" . $zipfilename;
795*cdf0e10cSrcweir	$gid =~ s/\./\_/g;
796*cdf0e10cSrcweir
797*cdf0e10cSrcweir	my %configfile = ();
798*cdf0e10cSrcweir
799*cdf0e10cSrcweir	# Taking the base data from the "gid_File_Lib_Vcl"
800*cdf0e10cSrcweir
801*cdf0e10cSrcweir	my $vclgid = "gid_File_Lib_Vcl";
802*cdf0e10cSrcweir	my $vclfile = installer::existence::get_specified_file($filesarrayref, $vclgid);
803*cdf0e10cSrcweir
804*cdf0e10cSrcweir	# copying all base data
805*cdf0e10cSrcweir	installer::converter::copy_item_object($vclfile, \%configfile);
806*cdf0e10cSrcweir
807*cdf0e10cSrcweir	# and overriding all new data
808*cdf0e10cSrcweir	$configfile{'ismultilingual'} = 0;
809*cdf0e10cSrcweir	$configfile{'sourcepath'} = $longzipfilename;
810*cdf0e10cSrcweir	$configfile{'Name'} = $zipfilename;
811*cdf0e10cSrcweir	$configfile{'UnixRights'} = "644";
812*cdf0e10cSrcweir	$configfile{'gid'} = $gid;
813*cdf0e10cSrcweir	$configfile{'Dir'} = "gid_Dir_Share_Uno_Packages";
814*cdf0e10cSrcweir	$configfile{'destination'} = "share" . $installer::globals::separator . "uno_packages" . $installer::globals::separator . $zipfilename;
815*cdf0e10cSrcweir	$configfile{'modules'} = $onemodule;	# assigning the file to the correct module!
816*cdf0e10cSrcweir
817*cdf0e10cSrcweir	push(@{$filesarrayref}, \%configfile);
818*cdf0e10cSrcweir}
819*cdf0e10cSrcweir
820*cdf0e10cSrcweir#######################################################
821*cdf0e10cSrcweir# Creating configuration files from configurationitems
822*cdf0e10cSrcweir#######################################################
823*cdf0e10cSrcweir
824*cdf0e10cSrcweirsub create_configuration_files
825*cdf0e10cSrcweir{
826*cdf0e10cSrcweir	my ($configurationitemsref, $filesarrayref, $languagestringref) = @_;
827*cdf0e10cSrcweir
828*cdf0e10cSrcweir	if ( $installer::globals::debug ) { installer::logger::debuginfo("installer::configuration::create_configuration_files: $#{$configurationitemsref} : $#{$filesarrayref} : $$languagestringref"); }
829*cdf0e10cSrcweir
830*cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating configuration files:");
831*cdf0e10cSrcweir
832*cdf0e10cSrcweir	# creating the directory
833*cdf0e10cSrcweir
834*cdf0e10cSrcweir	my $configdir = installer::systemactions::create_directories("configfiles", $languagestringref);
835*cdf0e10cSrcweir
836*cdf0e10cSrcweir	$configdir = installer::converter::make_path_conform($configdir);
837*cdf0e10cSrcweir
838*cdf0e10cSrcweir	# collecting an array of all modules
839*cdf0e10cSrcweir	my $allmodules = collect_all_configuration_items($configurationitemsref, "ModuleID");
840*cdf0e10cSrcweir
841*cdf0e10cSrcweir	# iterating over all modules
842*cdf0e10cSrcweir
843*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
844*cdf0e10cSrcweir	{
845*cdf0e10cSrcweir		my $onemodule = ${$allmodules}[$i];
846*cdf0e10cSrcweir
847*cdf0e10cSrcweir		my $moduleconfigitems = get_all_configitems_at_module($onemodule, $configurationitemsref);
848*cdf0e10cSrcweir
849*cdf0e10cSrcweir		# collecting an array of all "startpath". This are all different files (org.openoffice.Office.Common).
850*cdf0e10cSrcweir		my $allfiles = collect_all_configuration_items($moduleconfigitems, "startpath");
851*cdf0e10cSrcweir
852*cdf0e10cSrcweir		# iteration over all files
853*cdf0e10cSrcweir
854*cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$allfiles}; $j++ )
855*cdf0e10cSrcweir		{
856*cdf0e10cSrcweir			my $onefile = ${$allfiles}[$j];
857*cdf0e10cSrcweir
858*cdf0e10cSrcweir			my @oneconfigfile = ();
859*cdf0e10cSrcweir			my $oneconfigfileref = \@oneconfigfile;
860*cdf0e10cSrcweir
861*cdf0e10cSrcweir			my $startblockwritten = 0;
862*cdf0e10cSrcweir
863*cdf0e10cSrcweir			for ( my $k = 0; $k <= $#{$moduleconfigitems}; $k++ )
864*cdf0e10cSrcweir			{
865*cdf0e10cSrcweir				my $oneconfig = ${$moduleconfigitems}[$k];
866*cdf0e10cSrcweir
867*cdf0e10cSrcweir				my $startpath = $oneconfig->{'startpath'};
868*cdf0e10cSrcweir
869*cdf0e10cSrcweir				if ($startpath eq $onefile)
870*cdf0e10cSrcweir				{
871*cdf0e10cSrcweir					if (!($startblockwritten))	# writing some global lines into the xcu file
872*cdf0e10cSrcweir					{
873*cdf0e10cSrcweir						insert_start_block_into_configfile($oneconfigfileref, $oneconfig);
874*cdf0e10cSrcweir						$startblockwritten = 1;
875*cdf0e10cSrcweir					}
876*cdf0e10cSrcweir
877*cdf0e10cSrcweir					$oneconfigfileref = insert_into_config_file($oneconfig, $oneconfigfileref);
878*cdf0e10cSrcweir				}
879*cdf0e10cSrcweir			}
880*cdf0e10cSrcweir
881*cdf0e10cSrcweir			insert_end_block_into_configfile($oneconfigfileref);
882*cdf0e10cSrcweir
883*cdf0e10cSrcweir			# inserting tabs for nice appearance
884*cdf0e10cSrcweir			insert_tabs_into_configfile($oneconfigfileref);
885*cdf0e10cSrcweir
886*cdf0e10cSrcweir			# saving the configfile
887*cdf0e10cSrcweir			my $zipfilename = save_and_zip_configfile($oneconfigfileref, $onefile, $onemodule, $configdir);
888*cdf0e10cSrcweir
889*cdf0e10cSrcweir			# adding the zipped configfile to the list of installed files
890*cdf0e10cSrcweir			# Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
891*cdf0e10cSrcweir
892*cdf0e10cSrcweir			add_zipfile_into_filelist($zipfilename, $configdir, $filesarrayref, $onemodule);
893*cdf0e10cSrcweir		}
894*cdf0e10cSrcweir	}
895*cdf0e10cSrcweir
896*cdf0e10cSrcweir	my $infoline = "\n";
897*cdf0e10cSrcweir	push( @installer::globals::logfileinfo, $infoline);
898*cdf0e10cSrcweir
899*cdf0e10cSrcweir}
900*cdf0e10cSrcweir
901*cdf0e10cSrcweir1;
902