1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2000, 2010 Oracle and/or its affiliates.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # This file is part of OpenOffice.org.
11 # OpenOffice.org is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Lesser General Public License version 3
13 # only, as published by the Free Software Foundation.
15 # OpenOffice.org is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Lesser General Public License version 3 for more details
19 # (a copy is included in the LICENSE file that accompanied this code).
21 # You should have received a copy of the GNU Lesser General Public License
22 # version 3 along with OpenOffice.org. If not, see
23 # <http://www.openoffice.org/license.html>
24 # for a copy of the LGPLv3 License.
26 #*************************************************************************
33 sub readRedirectionValues
($);
36 "Usage is: \n subst_template.pl configTemplate redirections policyConfig
38 configTemplate: The config file which is used for the policy assembly. It
39 contains place holders for the binding redirection.
41 redirections: file containing the values for oldVersion and newVersion tags
42 which are used in the BindingRedirect element of the config files.
44 policyConfig: Name of the file in which we want to write the config file.
48 if (scalar @ARGV < 3) {
54 my %redirectionValue = readRedirectionValues
($ARGV[1]);
55 #print "|$_| |$redirectionValue{$_}|\n", for keys %redirectionValue;
58 #Read config file in which we will replace the versions
60 open TEMPLATE
, $ARGV[0] or die $!;
61 my $templ = <TEMPLATE
>;
63 #Open the config file we are goint to write to
64 open CONFIG
, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
66 #No substitute the place holders for oldVersion and new Version in the config template with
67 #the values obtained from the redirections file
68 for (keys %redirectionValue) {
69 $templ=~ s/\b$_\b/$redirectionValue{$_}/;
71 #Write the config file
74 #Reads the key value pairs from the files, which name must be passed in
75 #the parameter. The file contains lines of the form name=value, for example
76 #CLI_TYPES_OLD_VERSION=1.1.0.0-1.1.1.0
77 sub readRedirectionValues
($)
79 #Read in the values for the version redirection
80 open REDIR
, $_[0] or die $!;
82 my %redirectionValues;
89 if (length($trimmed = trim
($_)) == 0) {
93 #Skip comment symbol: #
94 if ($trimmed =~ /^#/) {
98 my @lineParts = split /=/,$_;
100 #Check if we have valid name value pairs.
101 if (scalar @lineParts != 2) {
102 print "Error: Values in $ARGV[1] are not correct (Entries must have the form name=value). Invalid line: \n$_\n";
106 #Trim the strings and check if they still contain characters
107 my $name = trim
($lineParts[0]);
108 my $value = trim
($lineParts[1]);
109 if (length($name) == 0 || length($value) == 0) {
110 print "Error: Values in $ARGV[1] are not correct. Invalid line: \n$_\n";
114 #Check if we have duplicate key names
115 for (keys %redirectionValues) {
117 print "Error: Values in $ARGV[1] are not correct. The name $_ is not unique.\n";
122 $redirectionValues{$name} = $value;
124 return %redirectionValues;