From c04aaeb1d7953befaef442179ab64352d3b85aeb Mon Sep 17 00:00:00 2001 From: "ian%hixie.ch" Date: Fri, 5 Apr 2002 20:17:34 +0000 Subject: [PATCH] Make the File string data source capable of looking for file-based templates in two locations, one specific to the app and one relative to the library. This allows PLIF to ship with default templates for various screens and thus makes it easier to bootstrap a simple app. git-svn-id: svn://10.0.0.236/trunk@118280 18797224-902f-48f8-a5cc-f745e15eee43 --- .../PLIF/PLIF/DataSource/FileStrings.pm | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/mozilla/webtools/PLIF/PLIF/DataSource/FileStrings.pm b/mozilla/webtools/PLIF/PLIF/DataSource/FileStrings.pm index 68be7777e74..da2ec4a2e4d 100644 --- a/mozilla/webtools/PLIF/PLIF/DataSource/FileStrings.pm +++ b/mozilla/webtools/PLIF/PLIF/DataSource/FileStrings.pm @@ -47,43 +47,55 @@ sub provides { return ($service eq 'dataSource.strings.default' or $class->SUPER::provides($service)); } +sub init { + my $self = shift; + my($app) = @_; + $self->SUPER::init(@_); + require File::Basename; import File::Basename; # DEPENDENCY +} + sub getDefaultString { my $self = shift; my($app, $protocol, $string) = @_; - my $filename; + my @filenames = (); # XXX THIS IS PLATFORM SPECIFIC CODE XXX if ($^O eq 'linux') { foreach my $piece ($protocol, $string) { $piece =~ s/[^a-zA-Z\/0-9.]/_/gos; } - $filename = "output/$protocol/$string"; + # create a path relative to the application + push(@filenames, "output/$protocol/$string"); + # and a patch relative to the PLIF library + push(@filenames, dirname(__FILE__)."/../../output/$protocol/$string"); } else { $self->error(0, "Platform '$^O' not supported yet."); } # XXX END OF PLATFORM SPECIFIC CODE XXX - if (-f $filename) { - local *FILE; # ugh - $self->assert(open(FILE, "<$filename"), 1, "Could not open output template file '$filename' for reading: $!"); - # get the data type (platform's line delimiter) - local $/ = "\n"; - my @data; - my $line; - while (defined($line = )) { - chomp($line); - if ($line eq '') { - # stop this when we reach the first blank line - last; + foreach my $filename (@filenames) { + if (-f $filename) { + local *FILE; # ugh + $self->assert(open(FILE, "<$filename"), 1, "Could not open output template file '$filename' for reading: $!"); + # get the data type (platform's line delimiter) + local $/ = "\n"; + my @data; + my $line; + while (defined($line = )) { + chomp($line); + if ($line eq '') { + # stop this when we reach the first blank line + last; + } + push(@data, $line); } - push(@data, $line); + # and then slurp entire file (no record delimiter) + local $/ = undef; + push(@data, ); + $self->assert(close(FILE), 3, "Could not close output template file '$filename': $!"); + return @data; } - # and then slurp entire file (no record delimiter) - local $/ = undef; - push(@data, ); - $self->assert(close(FILE), 3, "Could not close output template file '$filename': $!"); - return @data; - } else { - # file does not exist - $self->dump(9, "No file for string '$string' in protocol '$protocol' (looking for '$filename')"); - return; # no can do, sir } + # no file exists + local $" = '\', \''; + $self->dump(9, "No file found for string '$string' in protocol '$protocol' (looking for '@filenames')"); + return; # no can do, sir }