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.
24 package RT::URI::fsck_com_rt;
32 @ISA = qw/RT::URI::base/;
39 Returns the prefix for a local ticket URI
43 use_ok("RT::URI::fsck_com_rt");
44 my $uri = RT::URI::fsck_com_rt->new($RT::SystemUser);
51 ok (UNIVERSAL::isa($uri,RT::URI::fsck_com_rt), "It's an RT::URI::fsck_com_rt");
53 ok ($uri->isa('RT::URI::base'), "It's an RT::URI::base");
54 ok ($uri->isa('RT::Base'), "It's an RT::Base");
56 is ($uri->LocalURIPrefix , 'fsck.com-rt://example.com/ticket/');
66 my $prefix = $self->Scheme. "://$RT::Organization/ticket/";
74 =head2 URIForObject RT::Ticket
76 Returns the RT URI for a local RT::Ticket object
80 my $ticket = RT::Ticket->new($RT::SystemUser);
82 my $uri = RT::URI::fsck_com_rt->new($ticket->CurrentUser);
83 is($uri->LocalURIPrefix . "1" , $uri->URIForObject($ticket));
94 return ($self->LocalURIPrefix. $obj->Id);
98 =head2 ParseObject $TicketObj
100 When handed an RT::Ticekt object, figure out its URI
109 When handed an fsck.com-rt: URI, figures out things like whether its a local ticket
121 if ($uri =~ /^(\d+)$/) {
122 $ticket = RT::Ticket->new($self->CurrentUser);
124 $self->{'uri'} = $ticket->URI;
127 $self->{'uri'} = $uri;
132 #If it's a local URI, load the ticket object and return its URI
133 if ( $self->IsLocal) {
135 my $local_uri_prefix = $self->LocalURIPrefix;
136 if ($self->{'uri'} =~ /^$local_uri_prefix(\d+)$/) {
140 $ticket = RT::Ticket->new( $self->CurrentUser );
143 #If we couldn't find a ticket, return undef.
144 unless ( defined $ticket->Id ) {
152 $self->{'object'} = $ticket;
153 if ( UNIVERSAL::can( $ticket, 'Id' ) ) {
154 return ( $ticket->Id );
163 Returns true if this URI is for a local ticket.
164 Returns undef otherwise.
172 my $local_uri_prefix = $self->LocalURIPrefix;
173 if ($self->{'uri'} =~ /^$local_uri_prefix/) {
185 Returns the object for this URI, if it's local. Otherwise returns undef.
191 return ($self->{'object'});
197 Return the URI scheme for RT tickets
204 return "fsck.com-rt";
209 If this is a local ticket, return an HTTP url to it.
210 Otherwise, return its URI
217 if ($self->IsLocal) {
218 return ( $RT::WebURL . "Ticket/Display.html?id=".$self->Object->Id);
227 Returns either a localized string 'ticket #23' or the full URI if the object is not local
233 if ($self->IsLocal) {
234 return $self->loc("ticket #[_1]", $self->Object->Id);
238 return $self->Object->URI;
242 eval "require RT::URI::fsck_com_rt_Vendor";
243 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI/fsck_com_rt_Vendor.pm});
244 eval "require RT::URI::fsck_com_rt_Local";
245 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI/fsck_com_rt_Local.pm});