matts 2003/02/18 14:37:22
Modified: . MANIFEST Makefile.PL lib/Apache/AxKit Provider.pm lib/Apache/AxKit/Language HtmlDoc.pm LibXSLT.pm XSP.pm Added: lib/Apache/AxKit LibXMLSupport.pm Log: Added get_dom() which results in a lot of code deletion. Added LibXMLSupport.pm which helps in code deletion. Fixed bug in making comments in XSP (Nachoman) Revision Changes Path 1.13 +1 -0 xml-axkit/MANIFEST Index: MANIFEST =================================================================== RCS file: /home/cvs/xml-axkit/MANIFEST,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- MANIFEST 13 Sep 2002 13:04:31 -0000 1.12 +++ MANIFEST 18 Feb 2003 22:37:22 -0000 1.13 @@ -145,6 +145,7 @@ lib/Apache/AxKit/Language/XSP.pm lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm lib/Apache/AxKit/Language/XSP/TaglibHelper.pm +lib/Apache/AxKit/LibXMLSupport.pm lib/Apache/AxKit/Makefile.PL lib/Apache/AxKit/MediaChooser/WAPCheck.pm lib/Apache/AxKit/Plugin/Fragment.pm 1.16 +5 -6 xml-axkit/Makefile.PL Index: Makefile.PL =================================================================== RCS file: /home/cvs/xml-axkit/Makefile.PL,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Makefile.PL 8 Feb 2003 13:48:39 -0000 1.15 +++ Makefile.PL 18 Feb 2003 22:37:22 -0000 1.16 @@ -70,10 +70,6 @@ 'XML::Parser' => '2.27', 'XML::XPath' => '1.00', ], - "Recommended module for speeding up URI requests" => [ - -default => 0, - 'HTTP::GHTTP' => '1.00', - ], "Optional module for using Sablotron XSLT engine" => [ -default => 0, 'XML::Sablotron' => '0.40', @@ -86,7 +82,10 @@ -default => 0, 'XML::LibXSLT' => '1.49', ], - + "Optional for tidying output of AxTraceIntermediate XSP pages" => [ + -default => 0, + 'Perl::Tidy' => '', + ], ); require Apache::src; 1.13 +39 -13 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Provider.pm 5 Jul 2002 19:02:36 -0000 1.12 +++ Provider.pm 18 Feb 2003 22:37:22 -0000 1.13 @@ -5,7 +5,6 @@ use Apache::AxKit::Exception; use Apache::Constants qw(OK DECLINED); -#use XML::Parser; # use vars qw/$COUNT/; @@ -56,6 +55,41 @@ # AxKit::Debug(7, "Provider->DESTROY Count: " . --$COUNT); # } +sub get_strref { + throw Apache::AxKit::Exception::Error ( + -text => "Subclass must implement get_strref" + ); +} + +sub get_fh { + throw Apache::AxKit::Exception::Error ( + -text => "Subclass must implement get_fh" + ); +} + +sub get_dom { + my $self = shift; + require Apache::AxKit::LibXMLSupport; + + my $parser = XML::LibXML->new(); + $parser->expand_entities(1); + Apache::AxKit::LibXMLSupport->reset; + + my $xml_doc; + eval { + my $fh = $self->get_fh(); + $xml_doc = $parser->parse_fh($fh, $self->{apache}->uri()); + }; + if ($@) { + my $xmlstring = ${$self->get_strref()}; + $xml_doc = $parser->parse_string($xmlstring, $self->{apache}->uri()) || + throw Apache::AxKit::Exception::Error( + -text => "XML::LibXML->parse_string returned nothing!" + ); + } + return $xml_doc; +} + sub apache_request { my $self = shift; return $self->{apache}; @@ -85,17 +119,9 @@ if ($pubid) { return ''; # do not bring in public DTD's } - eval { - require HTTP::GHTTP; - }; - if ($@) { - require LWP::Simple; - import LWP::Simple; - return get($sysid) || die "Cannot get $sysid"; - } - my $r = HTTP::GHTTP->new($sysid); - $r->process_request; - return $r->get_body; + require LWP::Simple; + import LWP::Simple; + return get($sysid) || die "Cannot get $sysid"; } elsif ($sysid =~ /^(https|ftp):/) { if ($pubid) { 1.1 xml-axkit/lib/Apache/AxKit/LibXMLSupport.pm Index: LibXMLSupport.pm =================================================================== # $Id: LibXMLSupport.pm,v 1.1 2003/02/18 22:37:22 matts Exp $ package Apache::AxKit::LibXMLSupport; use strict; use XML::LibXML 1.50; use vars qw($provider_cb); $provider_cb = \&get_provider; sub reset { $XML::LibXML::match_cb = \&match_uri; $XML::LibXML::read_cb = \&read_uri; $XML::LibXML::close_cb = \&close_uri; $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 } 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; } sub close_uri { # do nothing } sub read_uri { return substr($_[0], 0, $_[1], ""); } 1; __END__ =head1 NAME Apache::AxKit::LibXMLSupport - XML::LibXML support routines =head1 SYNOPSIS require Apache::AxKit::LibXMLSupport; Apache::AxKit::LibXMLSupport->setup_libxml(); =head1 DESCRIPTION This module sets up some things for using XML::LibXML in AxKit. Specifically this is to do with callbacks. All callbacks look pretty much the same in AxKit, so this module makes them editable in one place. =head1 API There is just one method: C<< Apache::AxKit::LibXMLSupport->setup_libxml() >>. You can pass a parameter, in which case it is a callback to create a provider given a C<$r> (an Apache request object). This is so that you can create the provider in different ways and register the fact that it was created. If you don't provide a callback though a default one will be provided. =cut 1.4 +4 -6 xml-axkit/lib/Apache/AxKit/Language/HtmlDoc.pm Index: HtmlDoc.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/HtmlDoc.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HtmlDoc.pm 17 Jun 2002 23:15:47 -0000 1.3 +++ HtmlDoc.pm 18 Feb 2003 22:37:22 -0000 1.4 @@ -10,8 +10,9 @@ use Apache::Constants qw(:common); use Apache::Request; use Apache::AxKit::Language; -use Apache::AxKit::Language::LibXSLT; +use Apache::AxKit::LibXMLSupport; use Apache::AxKit::Provider; +use XML::LibXSLT; use IPC::Run qw(run); use Cwd; @@ -25,10 +26,7 @@ my ($r, $xml_provider, undef, $last_in_chain) = @_; my $parser = XML::LibXML->new(); - local $XML::LibXML::match_cb = \&Apache::AxKit::Language::LibXSLT::match_uri; - local $XML::LibXML::open_cb = \&Apache::AxKit::Language::LibXSLT::open_content_uri; - local $XML::LibXML::read_cb = \&Apache::AxKit::Language::LibXSLT::read_uri; - local $XML::LibXML::close_cb = \&Apache::AxKit::Language::LibXSLT::close_uri; + Apache::AxKit::LibXMLSupport->reset; my $dom; my $source_text; 1.19 +19 -92 xml-axkit/lib/Apache/AxKit/Language/LibXSLT.pm Index: LibXSLT.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/LibXSLT.pm,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- LibXSLT.pm 29 Jan 2003 13:51:29 -0000 1.18 +++ LibXSLT.pm 18 Feb 2003 22:37:22 -0000 1.19 @@ -10,6 +10,7 @@ use Apache::Request; use Apache::AxKit::Language; use Apache::AxKit::Provider; +use Apache::AxKit::LibXMLSupport; use File::Basename qw(dirname); @ISA = 'Apache::AxKit::Language'; @@ -48,20 +49,16 @@ my $parser = XML::LibXML->new(); $parser->expand_entities(1); - local $XML::LibXML::match_cb = \&match_uri; - local $XML::LibXML::open_cb = \&open_content_uri; - local $XML::LibXML::read_cb = \&read_uri; - local $XML::LibXML::close_cb = \&close_uri; + Apache::AxKit::LibXMLSupport->reset; + local $Apache::AxKit::LibXMLSupport::provider_cb = + sub { + my $r = shift; + my $provider = Apache::AxKit::Provider->new_content_provider($r); + add_depends($provider->key()); + }; if (!$xml_doc && !$xmlstring) { - eval { - my $fh = $xml->get_fh(); - $xml_doc = $parser->parse_fh($fh, $r->uri()); - }; - if ($@) { - $xmlstring = ${$xml->get_strref()}; - $xml_doc = $parser->parse_string($xmlstring, $r->uri()); - } + $xml_doc = $xml->get_dom(); } elsif ($xmlstring) { $xml_doc = $parser->parse_string($xmlstring, $r->uri()); @@ -91,21 +88,19 @@ } if (!$stylesheet || ref($stylesheet) ne 'XML::LibXSLT::Stylesheet') { - my $style_doc; reset_depends(); my $style_uri = $style->apache_request->uri(); AxKit::Debug(7, "[LibXSLT] parsing stylesheet $style_uri"); - eval { - my $fh = $style->get_fh(); - $style_doc = $parser->parse_fh($fh, $style_uri); - }; - if ($@) { - my $stylestring = $style->get_strref(); - $style_doc = $parser->parse_string($$stylestring, $style_uri); - } - - local $XML::LibXML::open_cb = \&open_stylesheet_uri; + my $style_doc = $style->get_dom(); + Apache::AxKit::LibXMLSupport->reset; + local $Apache::AxKit::LibXMLSupport::provider_cb = + sub { + my $r = shift; + my $provider = Apache::AxKit::Provider->new_style_provider($r); + add_depends($provider->key()); + }; + $stylesheet = XML::LibXSLT->parse_stylesheet($style_doc); unless ($r->dir_config('AxDisableXSLTStylesheetCache')) { @@ -150,74 +145,6 @@ ); } return @results; -} - -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 -} - -sub open_content_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 = Apache::AxKit::Provider->new_content_provider($sub); - - add_depends($provider->key()); - my $str = $provider->get_strref; - - undef $provider; - undef $apache; - undef $sub; - - return $$str; -} - -sub open_stylesheet_uri { - my $uri = shift || './'; - AxKit::Debug(8, "LibXSLT open_stylesheet_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 = Apache::AxKit::Provider->new_style_provider($sub); - - add_depends($provider->key()); - my $str = $provider->get_strref; - - undef $provider; - undef $apache; - undef $sub; - - return $$str; -} - -sub close_uri { -} - -sub read_uri { - return substr($_[0], 0, $_[1], ""); } 1; 1.37 +4 -47 xml-axkit/lib/Apache/AxKit/Language/XSP.pm Index: XSP.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XSP.pm,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- XSP.pm 7 Feb 2003 12:20:47 -0000 1.36 +++ XSP.pm 18 Feb 2003 22:37:22 -0000 1.37 @@ -919,6 +919,7 @@ package AxKit::XSP::SAXParser; use XML::LibXML 1.30; +use Apache::AxKit::LibXMLSupport; sub new { my ($type, %self) = @_; @@ -931,10 +932,7 @@ my $doc; my $parser = XML::LibXML->new(); - local $XML::LibXML::match_cb = \&match_uri; - local $XML::LibXML::open_cb = \&open_content_uri; - local $XML::LibXML::read_cb = \&read_uri; - local $XML::LibXML::close_cb = \&close_uri; + Apache::AxKit::LibXMLSupport->reset(); $parser->expand_entities(1); if (ref($thing)) { @@ -958,47 +956,6 @@ $self->{Handler}->end_document($document); } -sub match_uri { - my $uri = shift; - AxKit::Debug(8, "XSP match_uri: $uri"); - return 1 if $uri =~ /^(axkit|xmldb):/; - return $uri !~ /^\w+:/; # only handle URI's without a scheme -} - -sub open_content_uri { - my $uri = shift || './'; - AxKit::Debug(8, "XSP 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 = Apache::AxKit::Provider->new_content_provider($sub); - - AxKit::add_depends($provider->key()); - my $str = $provider->get_strref; - - undef $provider; - undef $apache; - undef $sub; - - return $$str; -} - -sub close_uri { -} - -sub read_uri { - return substr($_[0], 0, $_[1], ""); -} - sub process_node { my ($handler, $node, $encoding) = @_; @@ -1130,7 +1087,7 @@ sub __mk_comment_node { my ($document, $parent, $text) = @_; - my $node = $document->createCommentNode($text); + my $node = $document->createComment($text); $parent->appendChild($node); }