1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: subst_template.pl,v $
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 #*************************************************************************
37 sub readRedirectionValues
($);
40 "Usage is: \n subst_template.pl configTemplate redirections policyConfig
42 configTemplate: The config file which is used for the policy assembly. It
43 contains place holders for the binding redirection.
45 redirections: file containing the values for oldVersion and newVersion tags
46 which are used in the BindingRedirect element of the config files.
48 policyConfig: Name of the file in which we want to write the config file.
52 if (scalar @ARGV < 3) {
58 my %redirectionValue = readRedirectionValues
($ARGV[1]);
59 #print "|$_| |$redirectionValue{$_}|\n", for keys %redirectionValue;
62 #Read config file in which we will replace the versions
64 open TEMPLATE
, $ARGV[0] or die $!;
65 my $templ = <TEMPLATE
>;
67 #Open the config file we are goint to write to
68 open CONFIG
, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
70 #No substitute the place holders for oldVersion and new Version in the config template with
71 #the values obtained from the redirections file
72 for (keys %redirectionValue) {
73 $templ=~ s/\b$_\b/$redirectionValue{$_}/;
75 #Write the config file
78 #Reads the key value pairs from the files, which name must be passed in
79 #the parameter. The file contains lines of the form name=value, for example
80 #CLI_TYPES_OLD_VERSION=1.1.0.0-1.1.1.0
81 sub readRedirectionValues
($)
83 #Read in the values for the version redirection
84 open REDIR
, $_[0] or die $!;
86 my %redirectionValues;
93 if (length($trimmed = trim
($_)) == 0) {
97 #Skip comment symbol: #
98 if ($trimmed =~ /^#/) {
102 my @lineParts = split /=/,$_;
104 #Check if we have valid name value pairs.
105 if (scalar @lineParts != 2) {
106 print "Error: Values in $ARGV[1] are not correct (Entries must have the form name=value). Invalid line: \n$_\n";
110 #Trim the strings and check if they still contain characters
111 my $name = trim
($lineParts[0]);
112 my $value = trim
($lineParts[1]);
113 if (length($name) == 0 || length($value) == 0) {
114 print "Error: Values in $ARGV[1] are not correct. Invalid line: \n$_\n";
118 #Check if we have duplicate key names
119 for (keys %redirectionValues) {
121 print "Error: Values in $ARGV[1] are not correct. The name $_ is not unique.\n";
126 $redirectionValues{$name} = $value;
128 return %redirectionValues;