You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by jw...@apache.org on 2003/09/17 23:58:39 UTC

cvs commit: xml-axkit/lib/Apache/AxKit/Provider File.pm FileWrite.pm

jwalt       2003/09/17 14:58:39

  Modified:    .        Changes Makefile.PL
               lib/Apache/AxKit LibXMLSupport.pm Provider.pm
               lib/Apache/AxKit/Language XPathScript.pm
               lib/Apache/AxKit/Provider File.pm FileWrite.pm
  Log:
  - create pseudo-url registry
  - add changelog entries for recent modifications
  
  Revision  Changes    Path
  1.15      +5 -0      xml-axkit/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/xml-axkit/Changes,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Changes	16 Jul 2003 15:06:19 -0000	1.14
  +++ Changes	17 Sep 2003 21:58:38 -0000	1.15
  @@ -1,4 +1,9 @@
   AxKit Changes
  +x.x.x
  + - Extended SimpleTaglib with several new features
  + - Added pseudo-protocol registry
  + - fixed some bugs
  +
   1.6.2
    - Made processors added via AxAddDynamicProcessor appear in their proper
      order based on the order in which they appear in the config files
  
  
  
  1.23      +6 -1      xml-axkit/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  RCS file: /home/cvs/xml-axkit/Makefile.PL,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Makefile.PL	17 Jul 2003 16:34:49 -0000	1.22
  +++ Makefile.PL	17 Sep 2003 21:58:38 -0000	1.23
  @@ -87,6 +87,11 @@
           -default => 0,
           'XML::LibXML'     => '1.51',
       ],
  +    "Optional modules required for some features of SimpleTaglib" => [
  +        -default => 0,
  +        'XML::Smart'     => '1.3',
  +        'WeakRef'     => '0',
  +    ],
       "Optional module required for LibXSLT engine" => [
           -default => 0,
           'XML::LibXSLT'    => '1.49',
  
  
  
  1.4       +5 -33     xml-axkit/lib/Apache/AxKit/LibXMLSupport.pm
  
  Index: LibXMLSupport.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/LibXMLSupport.pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LibXMLSupport.pm	28 Jul 2003 22:53:20 -0000	1.3
  +++ LibXMLSupport.pm	17 Sep 2003 21:58:38 -0000	1.4
  @@ -7,8 +7,6 @@
   
   use vars qw($provider_cb);
   
  -$provider_cb = \&get_provider;
  -
   sub reset {
       my $class = shift;
       $XML::LibXML::match_cb = \&match_uri;
  @@ -17,43 +15,17 @@
       $XML::LibXML::open_cb = \&open_uri;
   }
   
  -# Default provider callback
  -sub get_provider {
  -    my $r = shift;
  -    my $provider = Apache::AxKit::Provider->new_content_provider($r);
  -    return $provider;
  -}
  -
   sub match_uri {
       my $uri = shift;
       AxKit::Debug(8, "LibXSLT match_uri: $uri");
  -    return 1 if $uri =~ /^(axkit|xmldb):/;
  -    return $uri !~ /^\w+:/; # only handle URI's without a scheme
  +    return 0 if $uri =~ /^(https?|ftp|file):/; # don't handle URI's supported by libxml
  +    return 1 if !($uri =~ /^([a-zA-Z0-9]+):/);
  +    return Apache::AxKit::Provider::has_protocol($1);
   }
   
   sub open_uri {
       my $uri = shift || './';
  -    AxKit::Debug(8, "LibXSLT open_content_uri: $uri");
  -    
  -    if ($uri =~ /^axkit:/) {
  -        return AxKit::get_axkit_uri($uri);
  -    } elsif ($uri =~ /^xmldb:/) {
  -        return Apache::AxKit::Provider::XMLDB::get_xmldb_uri($uri);
  -    }
  -    
  -    # create a subrequest, so we get the right AxKit::Cfg for the URI
  -    my $apache = AxKit::Apache->request;
  -    my $sub = $apache->lookup_uri(AxKit::FromUTF8($uri));
  -    local $AxKit::Cfg = Apache::AxKit::ConfigReader->new($sub);
  -    
  -    my $provider = $provider_cb->($sub);
  -    my $str = $provider->get_strref;
  -    
  -    undef $provider;
  -    undef $apache;
  -    undef $sub;
  -    
  -    return $$str;
  +    return Apache::AxKit::Provider::get_uri($uri,AxKit::Apache->request(),$provider_cb);
   }
   
   sub close_uri {
  
  
  
  1.17      +64 -1     xml-axkit/lib/Apache/AxKit/Provider.pm
  
  Index: Provider.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Provider.pm,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Provider.pm	4 Sep 2003 19:32:16 -0000	1.16
  +++ Provider.pm	17 Sep 2003 21:58:38 -0000	1.17
  @@ -8,6 +8,69 @@
   
   # use vars qw/$COUNT/;
   
  +# protocol registry
  +
  +my %pseudo_protocols =
  +  (
  +   'axkit' => \&AxKit::get_axkit_uri,
  +   );
  +
  +sub register_protocol {
  +    my ($protocol, $handler) = @_;
  +    $pseudo_protocols{lc($protocol)} = $handler;
  +}
  +
  +sub has_protocol {
  +    exists $pseudo_protocols{lc($_[0])};
  +}
  +
  +# end of protocol registry
  +
  +sub get_provider {
  +    my ($uri,$r,$provider_cb) = @_;
  +    AxKit::Debug(8,"get_provider: $uri");
  +    my ($protocol) = ($uri =~ m/^([a-zA-Z0-9]+):/);
  +    if ($protocol) {
  +        throw Apache::AxKit::Exception::Error(-text => "this resource has no provider ($uri)") if !ref($pseudo_protocols{$protocol});
  +        return $pseudo_protocols{$protocol}->new_provider($r, uri => $uri);
  +    } elsif (substr($uri,0,1) ne '/') { # resolve relative URIs -- FIXME: does $r->lookup_uri do this for us?
  +        my $base = AxKit::ToUTF8($r->uri());
  +        $base =~ s{[^/]*$}{};
  +        $uri = $base.$uri;
  +        $uri =~ s/\?.*$//;
  +        $uri =~ s{/./}{/}g;
  +        $uri =~ s{/[^/]+/+../}{/}g;
  +        AxKit::Debug(8,"Absolute URI: ".$uri);
  +    }
  +    
  +    # create a subrequest, so we get the right AxKit::Cfg for the URI
  +    my $sub = $r->lookup_uri($uri);
  +    local $AxKit::Cfg = Apache::AxKit::ConfigReader->new($sub);
  +    
  +    return ($provider_cb?$provider_cb->($sub):__PACKAGE__->new_content_provider($sub));
  +}
  +
  +sub get_uri {
  +    my ($uri,$r,$provider_cb) = @_;
  +    my ($protocol) = ($uri =~ m/^([a-zA-Z0-9]+):/);
  +    if ($protocol && ref($pseudo_protocols{$protocol})) {
  +        return $pseudo_protocols{$protocol}->($uri,$r);
  +    }
  +    
  +    my $str = get_provider(@_)->get_strref;
  +    
  +    return $$str;
  +}
  +
  +# end of protocol utilities
  +
  +sub new_provider { # make this just "new"? (would be logical, but probably breaks things...)
  +    my ($self, $r, @args) = @_;
  +    my $provider = bless { apache => $r }, $self;
  +    $provider->init(@args);
  +    return $provider;
  +}
  +
   sub new_style_provider {
       my $class = shift;
       my $apache = shift;
  
  
  
  1.11      +10 -39    xml-axkit/lib/Apache/AxKit/Language/XPathScript.pm
  
  Index: XPathScript.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XPathScript.pm,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XPathScript.pm	29 Jan 2003 01:35:50 -0000	1.10
  +++ XPathScript.pm	17 Sep 2003 21:58:38 -0000	1.11
  @@ -324,46 +324,17 @@
       my $results = XML::XPath::NodeSet->new();
       my $uri = $params[0];
       my $newdoc;
  -    if ($uri =~ /^axkit:/) {
  -        $newdoc = $parser->parse( AxKit::get_axkit_uri($uri) );
  -    } elsif ($uri =~ /^xmldb:/) {
  -        $newdoc = $parser->parse( Apache::AxKit::Provider::XMLDB::get_xmldb_uri($uri) );
  -    }
  -    elsif ($uri =~ /^\w\w+:/) { # assume it's scheme://foo uri
  -        eval {
  -            # warn "Trying to parse $params[0]\n";
  -            $newdoc = $parser->parse(
  -                    $Apache::AxKit::Language::XPathScript::local_ent_handler->(
  -                        undef, undef, $uri
  -                    )
  -                );
  -            # warn "Parsed OK into $newdoc\n";
  -        };
  -        if (my $E = $@) {
  -            if ($E->isa('Apache::AxKit::Exception::IO')) {
  -                AxKit::Debug(2, $E);
  -            }
  -            else {
  -                throw Apache::AxKit::Exception::Error(-text => "Parse of '$uri' failed: $E");
  -            };
  +    eval {
  +        $newdoc = $parser->parse(Apache::AxKit::Provider::get_uri($uri));
  +    };
  +    if (my $E = $@) {
  +        if ($E->isa('Apache::AxKit::Exception::IO')) {
  +            AxKit::Debug(2, $E);
           }
  +        else {
  +            throw Apache::AxKit::Exception::Error(-text => "Parse of '$uri' failed: $E");
  +        };
       }
  -    else {
  -        AxKit::Debug(3, "Parsing local: $uri\n");
  -        
  -        # create a subrequest, so we get the right AxKit::Cfg for the URI
  -        my $apache = AxKit::Apache->request;
  -        my $sub = $apache->lookup_uri(AxKit::FromUTF8($uri));
  -        local $AxKit::Cfg = Apache::AxKit::ConfigReader->new($sub);
  -        
  -        my $provider = Apache::AxKit::Provider->new_content_provider($sub);
  -        
  -        $newdoc = get_source_tree($provider, $parser);
  -        undef $provider;
  -        undef $apache;
  -        undef $sub;
  -    }
  -
       $results->push($newdoc) if $newdoc;
       #AxKit::Debug(8, "XPathScript: document() returning");
       return $results;
  
  
  
  1.15      +2 -1      xml-axkit/lib/Apache/AxKit/Provider/File.pm
  
  Index: File.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Provider/File.pm,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- File.pm	17 Feb 2003 10:47:00 -0000	1.14
  +++ File.pm	17 Sep 2003 21:58:38 -0000	1.15
  @@ -14,6 +14,7 @@
   use File::Spec;
   use Fcntl qw(O_RDONLY LOCK_SH);
   
  +Apache::AxKit::Provider::register_protocol('file',__PACKAGE__);
   
   sub init {
       my $self = shift;
  
  
  
  1.2       +3 -1      xml-axkit/lib/Apache/AxKit/Provider/FileWrite.pm
  
  Index: FileWrite.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Provider/FileWrite.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileWrite.pm	9 Jun 2002 22:47:36 -0000	1.1
  +++ FileWrite.pm	17 Sep 2003 21:58:38 -0000	1.2
  @@ -8,6 +8,8 @@
   use Apache::AxKit::Exception;
   use Fcntl;
   
  +Apache::AxKit::Provider::register_protocol('file',__PACKAGE__);
  +
   sub get_fh {
           my $self = shift;
           if ($_[0] && !$self->_is_dir()) {
  
  
  

Re: cvs commit: xml-axkit/lib/Apache/AxKit/Provider File.pm FileWrite.pm

Posted by Kip Hampton <kh...@totalcinema.com>.
jwalt@apache.org wrote:
> jwalt       2003/09/17 14:58:39
> 
>   Modified:    .        Changes Makefile.PL
>                lib/Apache/AxKit LibXMLSupport.pm Provider.pm
>                lib/Apache/AxKit/Language XPathScript.pm
>                lib/Apache/AxKit/Provider File.pm FileWrite.pm
>   Log:
>   - create pseudo-url registry

What is this "pseudo-uri registry", where was it discussed and agreed 
upon as a good idea and, if you can't point to that, what made you think 
that cramming someting in like this without a consensus would just be okay?

That's not the way things work around here, cowboy.

-kip