import of rt 3.0.4
[freeside.git] / rt / lib / RT / URI / base.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
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
10 # from www.gnu.org.
11
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.
16
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.
21
22
23 # END LICENSE BLOCK
24 package RT::URI::base;
25
26 use strict;
27 use base qw(RT::Base);
28
29 =head1 NAME
30
31 RT::URI::base
32
33 =head1 DESCRIPTION
34
35 A baseclass (and fallback) RT::URI handler. Every URI handler needs to 
36 handle the API presented here
37
38 =cut
39
40
41 =head1 API
42
43 =head2 new
44
45 Create a new URI handler
46
47 =cut
48
49 sub new {
50     my $proto = shift;
51     my $class = ref($proto) || $proto;
52     my $self  = {};
53     bless( $self, $class );
54     $self->CurrentUser(@_);
55     return ($self);
56 }
57
58 sub ParseObject  {
59     my $self = shift;
60     my $obj = shift;
61     $self->{'uri'} = "unknown-object:".ref($obj);
62
63
64 }
65
66
67
68 sub ParseURI { 
69     my $self = shift;
70     my $uri = shift;
71
72     if ($uri =~  /^(.*?):/) { 
73         $self->{'scheme'} = $1;
74     }
75     $self->{'uri'} = $uri;
76    
77     
78 }
79
80
81 sub Object {
82     my $self = shift;
83     return undef;
84
85 }
86
87 sub URI {
88     my $self = shift;
89     return($self->{'uri'});
90 }
91
92 sub Scheme { 
93     my $self = shift;
94     return($self->{'scheme'});
95
96 }
97
98 sub HREF {
99     my $self = shift;
100     return($self->{'href'} || $self->{'uri'});
101 }
102
103 sub IsLocal {
104     my $self = shift;
105     return undef;
106 }
107
108 =head2 AsString
109
110 Return a "pretty" string representing the URI object.
111
112 This is meant to be used like this:
113
114  % $re = $uri->Resolver;
115  <A HREF="<% $re->HREF %>"><% $re->AsString %></A>
116
117 =cut
118
119 sub AsString {
120     my $self = shift;
121     return $self->URI;
122 }
123
124 eval "require RT::URI::base_Vendor";
125 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI/base_Vendor.pm});
126 eval "require RT::URI::base_Local";
127 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI/base_Local.pm});
128
129 1;