1: # -*- perl -*- 2eval 'exec perl -wS $0 ${1+"$@"}' 3 if 0; 4#************************************************************** 5# 6# Licensed to the Apache Software Foundation (ASF) under one 7# or more contributor license agreements. See the NOTICE file 8# distributed with this work for additional information 9# regarding copyright ownership. The ASF licenses this file 10# to you under the Apache License, Version 2.0 (the 11# "License"); you may not use this file except in compliance 12# with the License. You may obtain a copy of the License at 13# 14# http://www.apache.org/licenses/LICENSE-2.0 15# 16# Unless required by applicable law or agreed to in writing, 17# software distributed under the License is distributed on an 18# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19# KIND, either express or implied. See the License for the 20# specific language governing permissions and limitations 21# under the License. 22# 23#************************************************************** 24 25 26 27# create java installer help files in html format for all languages defined in ulf file 28 29use Cwd; 30use File::Copy; 31 32if( $#ARGV < 2 ) 33 { 34 print <<ENDHELP; 35USAGE: $0 <separator> <ulf_file_path> <outputpath> 36 <separator>: separator, used on the platform (slash or backslash) 37 <ulf_file_path>: path, in which the ulf file(s) can be found 38 <outputpath>: path, in which the help files will be created 39ENDHELP 40 exit; 41 } 42 43$separator = $ARGV[0]; 44$inputpath = $ARGV[1]; 45$outputpath = $ARGV[2]; 46 47$inputpath =~ s/\Q$separator\E\s*$//; 48$outputpath =~ s/\Q$separator\E\s*$//; 49 50if ( ! -d $outputpath ) { mkdir $outputpath; } 51 52print "Separator: $separator \n"; 53print "Input path: $inputpath \n"; 54print "Output path: $outputpath \n"; 55 56my $localdir = cwd(); 57 58my $ulffilename = "setupstrings.ulf"; 59my $helpfilename = "helpfilenames.txt"; 60my $defaultlanguage = "en-US"; 61 62$ulffilename = $inputpath . $separator . $ulffilename; 63my $ulffile = read_file($ulffilename); 64 65my $helpfilenames = read_file($helpfilename); 66my $allhelpfilenames = collect_helpfile_names($helpfilenames); 67 68my $alllanguages = get_all_languages($ulffile); 69my @allnewpropertyfiles = (); 70 71for ( my $i = 0; $i <= $#{$allhelpfilenames}; $i++ ) 72{ 73 my $helpfilename = ${$allhelpfilenames}[$i]; 74 75 for ( my $j = 0; $j <= $#{$alllanguages}; $j++ ) 76 { 77 my $language = ${$alllanguages}[$j]; 78 79 # Creating content of help file 80 my $helpfilecontent = collect_helpfile_content($helpfilename, $ulffile, $language); 81 82 # Saving helpfile 83 my $savefilename = $helpfilename . "_" . $language . ".html"; 84 $savefilename = $outputpath . $separator . $savefilename; 85 save_file($savefilename, $helpfilecontent); 86 87 if ( $language eq $defaultlanguage ) 88 { 89 $savefilename = $helpfilename . ".html"; 90 $savefilename = $outputpath . $separator . $savefilename; 91 save_file($savefilename, $helpfilecontent); 92 } 93 } 94} 95 96exit; 97 98sub main::read_directory 99{ 100 my ($dir, $ext) = @_; 101 102 my @content = (); 103 my $direntry; 104 opendir(DIR, $dir); 105 106 foreach $direntry (readdir (DIR)) 107 { 108 next if $direntry eq "."; 109 next if $direntry eq ".."; 110 next if ( ! ( $direntry =~ /\.\Q$ext\E\s*$/ )); 111 112 # my $completeentry = $dir . $separator . $direntry; 113 # push(@content, $completeentry); 114 push(@content, $direntry); 115 } 116 117 closedir(DIR); 118 return \@content; 119} 120 121sub main::read_file 122{ 123 my ($filename) = @_; 124 125 open( IN, "<$filename" ) || die "cannot open $filename"; 126 my @content = <IN>; 127 close( IN ); 128 129 return \@content; 130} 131 132sub main::collect_helpfile_content 133{ 134 my ($helpfilename, $ulffile, $language) = @_; 135 136 my @helpfilecontent = (); 137 my $stringhash = create_string_hash($ulffile, $language); 138 139 # Collecting all strings for one html file. 140 # For "Prologue_de.html" all files need to begin with "STRING_PROLOGUE_X" 141 # The "X" is the ordering number. 142 143 my $basestring = "STRING_" . uc($helpfilename) . "_"; 144 145 for ( my $i = 0; $i <= 10; $i++ ) # 10 strings possible for each html file 146 { 147 my $key = $basestring . $i; 148 if ( exists $stringhash->{$key} ) 149 { 150 my $content = $stringhash->{$key} . "\n<p>\n"; 151 push(@helpfilecontent, $content); 152 } 153 } 154 155 return \@helpfilecontent; 156} 157 158sub main::collect_helpfile_names 159{ 160 my ($helpfilecontent) = @_; 161 162 my @allhelpfiles = (); 163 164 for ( my $i = 0; $i <= $#{$helpfilecontent}; $i++ ) 165 { 166 if ( ${$helpfilecontent}[$i] =~ /^\s*#/ ) { next; } # comment line 167 if ( ${$helpfilecontent}[$i] =~ /^\s*$/ ) { next; } # empty line 168 my $filename = ${$helpfilecontent}[$i]; 169 $filename =~ s/\s//g; 170 push(@allhelpfiles, $filename); 171 } 172 173 return \@allhelpfiles; 174} 175 176sub main::get_all_languages 177{ 178 my ($ulffile) = @_; 179 180 my @languages = (); 181 my $record = 0; 182 183 for ( my $i = 0; $i <= $#{$ulffile}; $i++ ) 184 { 185 if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record )) { last; } 186 if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record == 0 )) { $record = 1; } 187 188 if (( $record ) && ( ${$ulffile}[$i] =~ /^\s*(.+?)\s*\=/ )) 189 { 190 $language = $1; 191 push(@languages, $language); 192 } 193 } 194 195 my $languagestring = ""; 196 for ( my $i = 0; $i <= $#languages; $i++ ) { $languagestring = $languagestring . $languages[$i] . ","; } 197 $languagestring =~ s/,\s*$//; 198 print "Languages: $languagestring\n"; 199 200 return \@languages; 201} 202 203sub main::create_string_hash 204{ 205 my ($ulffile, $language) = @_; 206 207 my %stringhash = (); 208 my $key = ""; 209 my $value_defined = 0; 210 211 for ( my $i = 0; $i <= $#{$ulffile}; $i++ ) 212 { 213 if ( ${$ulffile}[$i] =~ /^\s*\[(.*)\]\s*$/ ) 214 { 215 $key = $1; 216 $value_defined = 0; 217 } 218 219 if (( ${$ulffile}[$i] =~ /^\s*\Q$defaultlanguage\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined )) 220 { 221 $value = $1; # defaulting to english 222 $stringhash{$key} = $value; 223 } 224 225 if (( ${$ulffile}[$i] =~ /^\s*\Q$language\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined )) 226 { 227 $value = $1; 228 $stringhash{$key} = $value; 229 $value_defined = 1; 230 } 231 } 232 233 # additional replacement for ${LANGUAGE}, not defined in ulf file 234 my $languagekey = "LANGUAGE"; 235 $stringhash{$languagekey} = $language; 236 237 # print_hash(\%stringhash); 238 239 return \%stringhash; 240} 241 242sub main::print_hash 243{ 244 my ( $hashref ) = @_; 245 246 print "Hash contains:\n"; 247 248 my $key; 249 foreach $key (keys %{$hashref} ) { print "Key: $key, Value: $hashref->{$key}\n"; } 250} 251 252sub main::save_file 253{ 254 my ($filename, $filecontent) = @_; 255 256 if ( open( OUT, ">$filename" ) ) 257 { 258 print OUT @{$filecontent}; 259 close( OUT); 260 } 261 262 push(@allnewpropertyfiles, $filename); 263 print "Created file: $filename\n"; 264} 265