1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
63 This class provides a base class for URIs, such as those handled
77 Create a new RT::URI object.
84 my $class = ref($proto) || $proto;
86 bless( $self, $class );
88 $self->CurrentUser(@_);
97 =head2 FromObject <Object>
99 Given a local object, such as an RT::Ticket or an RT::FM::Article, this routine will return a URI for
108 return undef unless $obj->can('URI');
109 return $self->FromURI($obj->URI);
118 Returns a local object id for this content. You are expected to know
119 what sort of object this is the Id of
121 Returns true if everything is ok, otherwise false
129 return undef unless ($uri);
132 # Special case: integers passed in as URIs must be ticket ids
133 if ($uri =~ /^(\d+)$/) {
134 $scheme = "fsck.com-rt";
135 } elsif ($uri =~ /^((?:\w|\.|-)+?):/) {
139 $RT::Logger->warning("Could not determine a URI scheme for $uri");
143 # load up a resolver object for this scheme
144 $self->_GetResolver($scheme);
146 unless ($self->Resolver->ParseURI($uri)) {
147 $RT::Logger->warning("Resolver ".ref($self->Resolver)." could not parse $uri");
148 $self->{resolver} = RT::URI::base->new( $self->CurrentUser ); # clear resolver
160 =head2 _GetResolver <scheme>
162 Gets an RT URI resolver for the scheme <scheme>.
163 Falls back to a null resolver. RT::URI::base.
171 $scheme =~ s/(\.|-)/_/g;
176 require RT::URI::$scheme;
177 \$resolver = RT::URI::$scheme->new(\$self->CurrentUser);
181 $self->{'resolver'} = $resolver;
183 $self->{'resolver'} = RT::URI::base->new($self->CurrentUser);
194 Returns a local object id for this content. You are expected to know
195 what sort of object this is the Id of
201 return ($self->Resolver->Scheme);
209 Returns a local object id for this content. You are expected to know what sort of object this is the Id
216 return ($self->Resolver->URI);
225 Returns a local object for this content. This will usually be an RT::Ticket or somesuch
232 return($self->Resolver->Object);
243 Returns a local object for this content. This will usually be an RT::Ticket or somesuch
249 return $self->Resolver->IsLocal;
263 return $self->Resolver->HREF;
268 Returns this URI's URI resolver object
275 return ($self->{'resolver'});
278 eval "require RT::URI_Vendor";
279 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI_Vendor.pm});
280 eval "require RT::URI_Local";
281 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI_Local.pm});