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