3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 # (Except where explictly superceded by other copyright notices)
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
39 This class provides a base class for URIs, such as those handled
53 Create a new RT::URI object.
60 my $class = ref($proto) || $proto;
62 bless( $self, $class );
64 $self->CurrentUser(@_);
73 =head2 FromObject <Object>
75 Given a local object, such as an RT::Ticket or an RT::FM::Article, this routine will return a URI for
84 return undef unless $obj->can('URI');
85 return $self->FromURI($obj->URI);
94 Returns a local object id for this content. You are expected to know
95 what sort of object this is the Id of
97 Returns true if everything is ok, otherwise false
105 return undef unless ($uri);
108 # Special case: integers passed in as URIs must be ticket ids
109 if ($uri =~ /^(\d+)$/) {
110 $scheme = "fsck.com-rt";
111 } elsif ($uri =~ /^((?:\w|\.|-)+?):/) {
115 $RT::Logger->warning("$self Could not determine a URI scheme for $uri");
119 # load up a resolver object for this scheme
120 $self->_GetResolver($scheme);
122 unless ($self->Resolver->ParseURI($uri)) {
123 $RT::Logger->warning("Resolver ".ref($self->Resolver)." could not parse $uri");
124 $self->{resolver} = undef; # clear resolver
136 =private _GetResolver <scheme>
138 Gets an RT URI resolver for the scheme <scheme>.
139 Falls back to a null resolver. RT::URI::base.
147 $scheme =~ s/(\.|-)/_/g;
152 require RT::URI::$scheme;
153 \$resolver = RT::URI::$scheme->new(\$self->CurrentUser);
157 $self->{'resolver'} = $resolver;
159 $self->{'resolver'} = RT::URI::base->new($self->CurrentUser);
170 Returns a local object id for this content. You are expected to know what sort of object this is the Id
177 return ($self->Resolver->Scheme);
185 Returns a local object id for this content. You are expected to know what sort of object this is the Id
192 return ($self->Resolver->URI);
201 Returns a local object for this content. This will usually be an RT::Ticket or somesuch
208 return($self->Resolver->Object);
219 Returns a local object for this content. This will usually be an RT::Ticket or somesuch
225 return $self->Resolver->IsLocal;
234 Returns this URI's URI resolver object
241 return ($self->{'resolver'});
244 eval "require RT::URI_Vendor";
245 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI_Vendor.pm});
246 eval "require RT::URI_Local";
247 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI_Local.pm});