Author: matts Date: Fri Aug 4 05:43:14 2006 New Revision: 428710 URL: http://svn.apache.org/viewvc?rev=428710&view=rev Log: Patches to update to XML::LibXML 1.59 API
Removed: xml/axkit/trunk/lib/Apache/AxKit/LibXMLSupport.pm Modified: xml/axkit/trunk/MANIFEST xml/axkit/trunk/lib/Apache/AxKit/Language/HtmlDoc.pm xml/axkit/trunk/lib/Apache/AxKit/Language/LibXSLT.pm xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm xml/axkit/trunk/lib/Apache/AxKit/Provider.pm Modified: xml/axkit/trunk/MANIFEST URL: http://svn.apache.org/viewvc/xml/axkit/trunk/MANIFEST?rev=428710&r1=428709&r2=428710&view=diff ============================================================================== --- xml/axkit/trunk/MANIFEST (original) +++ xml/axkit/trunk/MANIFEST Fri Aug 4 05:43:14 2006 @@ -142,7 +142,8 @@ lib/Apache/AxKit/Language/XSP/Preload.pm lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm lib/Apache/AxKit/Language/XSP/TaglibHelper.pm -lib/Apache/AxKit/LibXMLSupport.pm +lib/Apache/AxKit/LibXMLCallbacks.pm +lib/Apache/AxKit/LibXML.pm lib/Apache/AxKit/Makefile.PL lib/Apache/AxKit/MediaChooser/WAPCheck.pm lib/Apache/AxKit/Plugin/Fragment.pm Modified: xml/axkit/trunk/lib/Apache/AxKit/Language/HtmlDoc.pm URL: http://svn.apache.org/viewvc/xml/axkit/trunk/lib/Apache/AxKit/Language/HtmlDoc.pm?rev=428710&r1=428709&r2=428710&view=diff ============================================================================== --- xml/axkit/trunk/lib/Apache/AxKit/Language/HtmlDoc.pm (original) +++ xml/axkit/trunk/lib/Apache/AxKit/Language/HtmlDoc.pm Fri Aug 4 05:43:14 2006 @@ -25,7 +25,8 @@ use Apache::Constants qw(:common); use Apache::Request; use Apache::AxKit::Language; -use Apache::AxKit::LibXMLSupport; +use Apache::AxKit::LibXML; +use Apache::AxKit::LibXMLCallbacks; use Apache::AxKit::Provider; use XML::LibXSLT; use IPC::Run qw(run); @@ -40,16 +41,15 @@ my $class = shift; my ($r, $xml_provider, undef, $last_in_chain) = @_; - my $parser = XML::LibXML->new(); - local($XML::LibXML::match_cb, $XML::LibXML::open_cb, - $XML::LibXML::read_cb, $XML::LibXML::close_cb); - Apache::AxKit::LibXMLSupport->reset(); + my $parser = Apache::AxKit::LibXML->new(); + $parser->expand_xinclude(1); my $dom; my $source_text; if ($dom = $r->pnotes('dom_tree')) { ; - } elsif ($source_text = $r->pnotes('xml_string')) { + } + elsif ($source_text = $r->pnotes('xml_string')) { $dom = $parser->parse_string($source_text, $r->uri()); } else { @@ -60,7 +60,6 @@ } $dom = $parser->parse_string($source_text, $r->uri()); } - $dom->process_xinclude(); my $style_dom = $parser->parse_string(<< 'EOX','.'); <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> @@ -69,7 +68,9 @@ <xsl:template match="text()"><xsl:value-of select="."/></xsl:template> </xsl:stylesheet> EOX - my $stylesheet = XML::LibXSLT->parse_stylesheet($style_dom); + my $xslt = XML::LibXSLT->new(); + $xslt->input_callbacks( Apache::AxKit::LibXMLCallbacks->input_callbacks() ); + $stylesheet = $xslt->parse_stylesheet($style_dom); my $results = $stylesheet->transform($dom); my $result; Modified: xml/axkit/trunk/lib/Apache/AxKit/Language/LibXSLT.pm URL: http://svn.apache.org/viewvc/xml/axkit/trunk/lib/Apache/AxKit/Language/LibXSLT.pm?rev=428710&r1=428709&r2=428710&view=diff ============================================================================== --- xml/axkit/trunk/lib/Apache/AxKit/Language/LibXSLT.pm (original) +++ xml/axkit/trunk/lib/Apache/AxKit/Language/LibXSLT.pm Fri Aug 4 05:43:14 2006 @@ -25,7 +25,8 @@ use Apache::Request; use Apache::AxKit::Language; use Apache::AxKit::Provider; -use Apache::AxKit::LibXMLSupport; +use Apache::AxKit::LibXML; +use Apache::AxKit::LibXMLCallbacks; use File::Basename qw(dirname); @ISA = 'Apache::AxKit::Language'; @@ -62,11 +63,9 @@ $xmlstring = $r->pnotes('xml_string'); } - my $parser = XML::LibXML->new(); + my $parser = Apache::AxKit::LibXML->new(); $parser->expand_entities(1); - local($XML::LibXML::match_cb, $XML::LibXML::open_cb, - $XML::LibXML::read_cb, $XML::LibXML::close_cb); - Apache::AxKit::LibXMLSupport->reset(); + $parser->expand_xinclude(1); local $Apache::AxKit::LibXMLSupport::provider_cb = sub { my $r = shift; @@ -82,8 +81,6 @@ $xml_doc = $parser->parse_string($xmlstring, $r->uri()); } - $xml_doc->process_xinclude(); - AxKit::Debug(7, "[LibXSLT] parsing stylesheet"); my $stylesheet; @@ -111,9 +108,8 @@ AxKit::Debug(7, "[LibXSLT] parsing stylesheet $style_uri"); my $style_doc = $style->get_dom(); - local($XML::LibXML::match_cb, $XML::LibXML::open_cb, - $XML::LibXML::read_cb, $XML::LibXML::close_cb); - Apache::AxKit::LibXMLSupport->reset(); + my $xslt = XML::LibXSLT->new(); + $xslt->input_callbacks( Apache::AxKit::LibXMLCallbacks->input_callbacks() ); local $Apache::AxKit::LibXMLSupport::provider_cb = sub { my $r = shift; @@ -122,7 +118,7 @@ return $provider; }; - $stylesheet = XML::LibXSLT->parse_stylesheet($style_doc); + $stylesheet = $xslt->parse_stylesheet($style_doc); unless ($r->dir_config('AxDisableXSLTStylesheetCache')) { $style_cache{$style->key()} = Modified: xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm URL: http://svn.apache.org/viewvc/xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm?rev=428710&r1=428709&r2=428710&view=diff ============================================================================== --- xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm (original) +++ xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm Fri Aug 4 05:43:14 2006 @@ -19,6 +19,7 @@ use strict; use AxKit; +use Apache::AxKit::LibXML; use Apache::AxKit::Language; use Apache::Request; use Apache::AxKit::Exception; @@ -1079,7 +1080,7 @@ package AxKit::XSP::SAXParser; use XML::LibXML 1.30; -use Apache::AxKit::LibXMLSupport; +use Apache::AxKit::LibXML; sub new { my ($type, %self) = @_; @@ -1092,11 +1093,9 @@ my $doc; if (ref($thing) ne 'XML::LibXML::Document') { - my $parser = XML::LibXML->new(); - local($XML::LibXML::match_cb, $XML::LibXML::open_cb, - $XML::LibXML::read_cb, $XML::LibXML::close_cb); - Apache::AxKit::LibXMLSupport->reset($parser); + my $parser = Apache::AxKit::LibXML->new(); $parser->expand_entities(1); + $parser->expand_xinclude(1); eval { $parser->line_numbers(1); AxKit::Debug(6,"enabled line numbers"); @@ -1108,9 +1107,9 @@ else { $doc = $parser->parse_string($thing); } - AxKit::Debug(10, 'XSP: Parser returned doc'); - $doc->process_xinclude; - } else { + AxKit::Debug(9, 'XSP: Parser returned doc'); + } + else { $doc = $thing; } Modified: xml/axkit/trunk/lib/Apache/AxKit/Provider.pm URL: http://svn.apache.org/viewvc/xml/axkit/trunk/lib/Apache/AxKit/Provider.pm?rev=428710&r1=428709&r2=428710&view=diff ============================================================================== --- xml/axkit/trunk/lib/Apache/AxKit/Provider.pm (original) +++ xml/axkit/trunk/lib/Apache/AxKit/Provider.pm Fri Aug 4 05:43:14 2006 @@ -19,6 +19,7 @@ use strict; use Apache::AxKit::Exception; +use Apache::AxKit::LibXML; use Apache::Constants qw(OK DECLINED); use AxKit; @@ -82,7 +83,7 @@ my $str = get_provider(@_)->get_strref; - return $$str; + return $str; } # end of protocol utilities @@ -163,39 +164,36 @@ require Apache::AxKit::LibXMLSupport; AxKit::Debug(8, "Provider::get_dom"); - my $parser = XML::LibXML->new(); + my $parser = Apache::AxKit::LibXML->new(); $parser->expand_entities(1); $parser->expand_xinclude(1); - local($XML::LibXML::match_cb, $XML::LibXML::open_cb, - $XML::LibXML::read_cb, $XML::LibXML::close_cb); - Apache::AxKit::LibXMLSupport->reset($parser); my $r = $self->apache_request(); my $xml_doc; if ($str) { - use bytes; + use bytes; AxKit::Debug(8, "Provider::get_dom/parse_string($str, ", $self->get_document_uri(), ")"); $xml_doc = $parser->parse_string($str, $self->get_document_uri()) || throw Apache::AxKit::Exception::Error( -text => "XML::LibXML->parse_string returned nothing!" ); - } else { - eval { - my $fh = $self->get_fh(); - AxKit::Debug(8, "Provider::get_dom/parse_fh($fh, ", $self->get_document_uri(), ")"); - $xml_doc = $parser->parse_fh($fh, $self->get_document_uri()); - }; - if ($@) { - use bytes; - my $xmlstring = ${$self->get_strref()}; - AxKit::Debug(8, "Provider::get_dom/parse_strref($xmlstring, ", $self->get_document_uri(), ")"); - $xml_doc = $parser->parse_string($xmlstring, $self->get_document_uri()) || - throw Apache::AxKit::Exception::Error( - -text => "XML::LibXML->parse_string returned nothing!" - ); - } - } + } else { + eval { + my $fh = $self->get_fh(); + AxKit::Debug(8, "Provider::get_dom/parse_fh($fh, ", $self->get_document_uri(), ")"); + $xml_doc = $parser->parse_fh($fh, $self->get_document_uri()); + }; + if ($@) { + use bytes; + my $xmlstring = ${$self->get_strref()}; + AxKit::Debug(8, "Provider::get_dom/parse_strref($xmlstring, ", $self->get_document_uri(), ")"); + $xml_doc = $parser->parse_string($xmlstring, $self->get_document_uri()) || + throw Apache::AxKit::Exception::Error( + -text => "XML::LibXML->parse_string returned nothing!" + ); + } + } return $xml_doc; } @@ -266,7 +264,7 @@ undef $pref_style; } - my @styles; + my @styles; my $key = $self->key(); # need to extract the following from the XML file: @@ -274,22 +272,22 @@ # DTD filename # Root element name (including namespace) # use three element array @$vals - - my ($doctype, $dtd, $root, $xml_styles) = $self->get_xml_info( $media, $pref_style ); - - $xml_styles = [] if $AxKit::Cfg->IgnoreStylePI(); - - foreach my $style (@$xml_styles) { - $style->{title} ||= '#default'; - } - - # Let GetMatchingProcessors to process the @$styles array - { - local $^W; # suppress "Use of uninitialized value" warnings - AxKit::Debug(4, "Calling GetMatchingProcessors with ($media, $pref_style, $doctype, $dtd, $root)"); - } + + my ($doctype, $dtd, $root, $xml_styles) = $self->get_xml_info( $media, $pref_style ); + + $xml_styles = [] if $AxKit::Cfg->IgnoreStylePI(); + + foreach my $style (@$xml_styles) { + $style->{title} ||= '#default'; + } + + # Let GetMatchingProcessors to process the @$styles array + { + local $^W; # suppress "Use of uninitialized value" warnings + AxKit::Debug(4, "Calling GetMatchingProcessors with ($media, $pref_style, $doctype, $dtd, $root)"); + } - @styles = $AxKit::Cfg->GetMatchingProcessors($media, $pref_style, $doctype, $dtd, $root, $xml_styles, $self); + @styles = $AxKit::Cfg->GetMatchingProcessors($media, $pref_style, $doctype, $dtd, $root, $xml_styles, $self); if ([EMAIL PROTECTED]) { throw Apache::AxKit::Exception::Declined( reason => "No styles defined for '$key'" ); @@ -325,34 +323,34 @@ } sub get_xml_info{ - my ($self, $media, $pref_style ) = @_; - - # This is where the sniffing of the xml content happens. - - my $r = $self->apache_request(); - my @ret; - eval{ - my $fh = $self->get_fh(); - my $pos = eval { tell $fh; }; - if($@) { - # fh is not seekable, thus we must slurp file at this point. - undef $@; - local($/) = undef; - my $string = <$fh>; - $r->pnotes('xml_string', $string); - @ret = parse_xml_info( $r, undef, \$string, $media, $pref_style); - } else { - # seekable. - @ret = parse_xml_info( $r, $fh, undef, $media, $pref_style); - seek $fh, 0, $pos; - } - }; - if($@) { - my $str_ref = $self->get_strref(); - $r->pnotes('xml_string', ${$str_ref}); - @ret = parse_xml_info( $r, undef, $str_ref, $media, $pref_style); - } - return @ret; + my ($self, $media, $pref_style ) = @_; + + # This is where the sniffing of the xml content happens. + + my $r = $self->apache_request(); + my @ret; + eval{ + my $fh = $self->get_fh(); + my $pos = eval { tell $fh; }; + if($@) { + # fh is not seekable, thus we must slurp file at this point. + undef $@; + local($/) = undef; + my $string = <$fh>; + $r->pnotes('xml_string', $string); + @ret = parse_xml_info( $r, undef, \$string, $media, $pref_style); + } else { + # seekable. + @ret = parse_xml_info( $r, $fh, undef, $media, $pref_style); + seek $fh, 0, $pos; + } + }; + if($@) { + my $str_ref = $self->get_strref(); + $r->pnotes('xml_string', ${$str_ref}); + @ret = parse_xml_info( $r, undef, $str_ref, $media, $pref_style); + } + return @ret; } sub parse_xml_info{ @@ -364,53 +362,53 @@ my $xml_styles = []; my $vals = []; - my @styles; + my @styles; + + if (defined &Apache::AxKit::Provider::xs_get_styles_fh) { + AxKit::Debug(2, "using XS get_styles (libxml2)"); + my ($xs_styles, $doctype, $dtd, $root) = xs_get_styles($r, $fh, $str_ref, $media, $pref_style); + @$xml_styles = @$xs_styles unless $AxKit::Cfg->IgnoreStylePI(); + @$vals = ($doctype, $dtd, $root); + } + else { + require XML::Parser; + + AxKit::Debug(4, "get_styles: creating XML::Parser"); + + my $handlers = { + Start => \&parse_start, + Doctype => \&parse_dtd, + $AxKit::Cfg->IgnoreStylePI() ? () : (Proc => \&parse_pi), + }; - if (defined &Apache::AxKit::Provider::xs_get_styles_fh) { - AxKit::Debug(2, "using XS get_styles (libxml2)"); - my ($xs_styles, $doctype, $dtd, $root) = xs_get_styles($r, $fh, $str_ref, $media, $pref_style); - @$xml_styles = @$xs_styles unless $AxKit::Cfg->IgnoreStylePI(); - @$vals = ($doctype, $dtd, $root); - } - else { - require XML::Parser; - - AxKit::Debug(4, "get_styles: creating XML::Parser"); - - my $handlers = { - Start => \&parse_start, - Doctype => \&parse_dtd, - $AxKit::Cfg->IgnoreStylePI() ? () : (Proc => \&parse_pi), - }; - - my $xml_parser = XML::Parser->new( - Namespaces => 1, - ErrorContext => 2, - Handlers => $handlers, - ); - - my $to_parse = $fh || ${$str_ref}; - #eval { - # $to_parse = $provider->get_fh(); - #}; - #if ($@) { - # $to_parse = ${ $provider->get_strref(); }; - #} - - AxKit::Debug(4, "get_styles: calling XML::Parser->parse()"); - $xml_parser->parse( - $to_parse, - XMLStyle_preferred => $pref_style, - XMLStyle_media => $media, - XMLStyle_style => $xml_styles, - XMLStyle_vals => $vals, - XMLStyle_style_screen => [], - ); - - AxKit::Debug(4, "get_styles: parse returned successfully"); - } - - return (@$vals, $xml_styles); + my $xml_parser = XML::Parser->new( + Namespaces => 1, + ErrorContext => 2, + Handlers => $handlers, + ); + + my $to_parse = $fh || ${$str_ref}; + #eval { + # $to_parse = $provider->get_fh(); + #}; + #if ($@) { + # $to_parse = ${ $provider->get_strref(); }; + #} + + AxKit::Debug(4, "get_styles: calling XML::Parser->parse()"); + $xml_parser->parse( + $to_parse, + XMLStyle_preferred => $pref_style, + XMLStyle_media => $media, + XMLStyle_style => $xml_styles, + XMLStyle_vals => $vals, + XMLStyle_style_screen => [], + ); + + AxKit::Debug(4, "get_styles: parse returned successfully"); + } + + return (@$vals, $xml_styles); } sub xs_get_styles {