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 ma...@apache.org on 2003/01/08 18:09:57 UTC

cvs commit: xml-axkit/lib AxKit.pm

matts       2003/01/08 09:09:56

  Modified:    lib      AxKit.pm
  Log:
  Fixed pnotes problems with subrequests (triggered by axkit:// urls).
  Some tidy up.
  fixed extra output going to browser with axkit:// urls
  
  Revision  Changes    Path
  1.33      +66 -17    xml-axkit/lib/AxKit.pm
  
  Index: AxKit.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/AxKit.pm,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- AxKit.pm	4 Jan 2003 18:11:08 -0000	1.32
  +++ AxKit.pm	8 Jan 2003 17:09:55 -0000	1.33
  @@ -257,6 +257,9 @@
           return $provider->decline();
       }
   
  +    # setup global pnotes.
  +    local $AxKit::Apache::PNOTES = $r->pnotes();
  +    
       if ($r->notes('axkit_passthru')) {
           # slow passthru
           $r->send_http_header('text/xml');
  @@ -378,7 +381,7 @@
   }
   
   sub run_axkit_engine {
  -    my ($r, $provider) = @_;
  +    my ($r, $provider, $no_output) = @_;
       
       # get preferred stylesheet and media type
       my ($preferred, $media) = get_style_and_media();
  @@ -428,11 +431,11 @@
   
       # Store in package variable for other modules
       $AxKit::Cache = $cache;
  -
  +    
       # reconsecrate Apache request object (& STDOUT) into our own class
       bless $r, 'AxKit::Apache';
       tie *STDOUT, 'AxKit::Apache', $r;
  -
  +    
       if (my $charset = $AxKit::Cfg->OutputCharset) {
           AxKit::Debug(5, "Different output charset: $charset");
           if (!$r->notes('axkit_passthru_type')) {
  @@ -455,7 +458,12 @@
       }
       
       # Main grunt of the work done here...
  -    my $return_code = process_request($r, $provider, $AxKit::_CurrentStylesheets);
  +    my $return_code = process_request(
  +        $r,
  +        $provider,
  +        $AxKit::_CurrentStylesheets,
  +        $no_output,
  +    );
   
       save_dependencies($r, $cache);
       
  @@ -487,24 +495,39 @@
   
       my $provider = Apache::AxKit::Provider->new_content_provider($r);
       
  -    my $result_code = run_axkit_engine($r, $provider);
  +    my $result_code = run_axkit_engine(
  +        $r,
  +        $provider,
  +        1, # no output
  +    );
       
       if ($result_code == OK) {
           # results now in $r->pnotes('xml_string') - probably...
  -        # warning; missing caching logic here from deliver_to_browser.
  -        if (not $r->pnotes('xml_string') and $r->pnotes('dom_tree')) {
  -            return $r->pnotes('dom_tree')->toString;
  +        if (length($r->pnotes('xml_string'))) {
  +            my $str = $r->pnotes('xml_string');
  +            AxKit::Debug(10, "get_axkit_uri returning (str): '$str'");
  +            return $str;
  +        }
  +        elsif ($r->pnotes('dom_tree')) {
  +            my $str = $r->pnotes('dom_tree')->toString;
  +            AxKit::Debug(10, "get_axkit_uri returning (dom): '$str'");
  +            return $str;
           }
           else {
  -            return $r->pnotes('xml_string');
  +            throw Apache::AxKit::Exception (
  +                -text => "$uri internal request didn't store anything in dom_tree or xml_string",
  +                );
           }
       }
       elsif ($result_code == DECLINED) {
           # probably came from the cache system. Try and read it.
  +        AxKit::Debug(10, "get_axkit_uri cache read");
           return $AxKit::Cache->read();
       }
       else {
  -        throw Apache::AxKit::Exception ( -text => "$uri internal request returned unknown result code: ".$result_code);
  +        throw Apache::AxKit::Exception (
  +            -text => "$uri internal request returned unknown result code: ".$result_code,
  +        );
       }
   }
   
  @@ -582,7 +605,7 @@
   }
   
   sub process_request {
  -    my ($r, $provider, $styles) = @_;
  +    my ($r, $provider, $styles, $no_output) = @_;
       my $result_code = OK;
   
       my $num_styles = 0;
  @@ -602,6 +625,9 @@
   
       while (@$styles) {
           my $style = shift @$styles;
  +        
  +        my $num_left = @$styles;
  +        my $output_to_browser = ($num_left == 0 && !$no_output);
   
           my $styleprovider = Apache::AxKit::Provider->new_style_provider(
                   $r,
  @@ -635,7 +661,7 @@
                       $r,
                       $provider,
                       $styleprovider,
  -                    !@$styles, # any more left?
  +                    $output_to_browser,
                       );
   	    AxKit::Debug(5, "$mapto\::handler finished with code $retval");
               $result_code = $retval if $retval != OK;
  @@ -781,10 +807,20 @@
   sub deliver_to_browser {
       my ($r, $result_code) = @_;
       $result_code ||= OK;
  +    
  +    AxKit::Debug(4, "delivering to browser");
   
  -    if (not $r->pnotes('xml_string') and $r->pnotes('dom_tree')) {
  +    if (length($r->pnotes('xml_string'))) {
  +        # ok, data is in xml_string
  +        AxKit::Debug(4, "Delivering xml_string");
  +    }
  +    elsif ($r->pnotes('dom_tree')) {
  +        AxKit::Debug(4, "Delivering dom_tree");
           $r->pnotes('xml_string', $r->pnotes('dom_tree')->toString );
       }
  +    else {
  +        AxKit::Debug(5, "Possible cache delivery coming up...");
  +    }
   
       if ($r->content_type eq 'changeme' && !$r->notes('axkit_passthru_type')) {
           $AxKit::Cfg->AllowOutputCharset(1);
  @@ -815,8 +851,9 @@
       }
   
       if ($AxKit::Cache->no_cache() ||
  -            lc($r->dir_config('Filter')) eq 'on' ||
  -            $r->method() eq 'POST') {
  +        lc($r->dir_config('Filter')) eq 'on' ||
  +        $r->method() eq 'POST')
  +    {
           AxKit::Debug(4, "writing xml string to browser");
           my ($transformer, $doit) = get_output_transformer();
           if ($AxKit::Cfg->DoGzip) {
  @@ -938,7 +975,7 @@
   #########################################################################
   
   package AxKit::Apache;
  -use vars qw/@ISA/;
  +use vars qw/@ISA $PNOTES/;
   use Apache;
   use Fcntl qw(:DEFAULT);
   @ISA = ('Apache');
  @@ -1004,6 +1041,18 @@
       $self->notes('headers_sent', 1);
   
       $self->SUPER::send_http_header;
  +}
  +
  +sub pnotes {
  +    my $self = shift;
  +    if (!@_) {
  +        return $PNOTES;
  +    }
  +    my $key = shift;
  +    if (@_) {
  +        return $PNOTES->{$key} = $_[0];
  +    }
  +    return $PNOTES->{$key};
   }
   
   1;