Fix the FileUrl macro.

This commit is contained in:
Colin Kuskie 2010-01-27 21:50:06 -08:00
parent 9ef7ee79fa
commit 972ba033ec

View file

@ -14,6 +14,7 @@ use strict;
use WebGUI::Asset; use WebGUI::Asset;
use WebGUI::Storage; use WebGUI::Storage;
use WebGUI::International; use WebGUI::International;
use WebGUI::Exception;
=head1 NAME =head1 NAME
@ -40,23 +41,23 @@ The URL to the Asset.
=cut =cut
sub process { sub process {
my $session = shift; my $session = shift;
my $url = shift; my $url = shift;
my $asset = WebGUI::Asset->newByUrl($session,$url); my $asset = eval { WebGUI::Asset->newByUrl($session,$url); };
my $i18n = WebGUI::International->new($session, 'Macro_FileUrl'); my $i18n = WebGUI::International->new($session, 'Macro_FileUrl');
if (not defined $asset) { if (Exception::Class->caught()) {
return $i18n->get('invalid url'); return $i18n->get('invalid url');
} }
my $storageId = $asset->get('storageId'); my $storageId = $asset->storageId;
if (not defined $storageId) { if (not defined $storageId) {
return $i18n->get('no storage'); return $i18n->get('no storage');
} }
my $filename = $asset->get('filename'); my $filename = $asset->filename;
if (not defined $filename) { if (not defined $filename) {
return $i18n->get('no filename'); return $i18n->get('no filename');
} }
my $storage = WebGUI::Storage->get($session,$storageId); my $storage = WebGUI::Storage->get($session,$storageId);
return $storage->getUrl($filename); return $storage->getUrl($filename);
} }