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/10/20 22:55:36 UTC

cvs commit: xml-axkit/lib AxKit.pm

mach        2003/10/20 13:55:36

  Modified:    lib      Tag: axkit-pipeline-2 AxKit.pm
  Log:
  New Pipeline code. Caching and delivery moved into Pipeline modules.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.53.2.1  +238 -526  xml-axkit/lib/AxKit.pm
  
  Index: AxKit.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/AxKit.pm,v
  retrieving revision 1.53
  retrieving revision 1.53.2.1
  diff -u -r1.53 -r1.53.2.1
  --- AxKit.pm	18 Sep 2003 22:12:33 -0000	1.53
  +++ AxKit.pm	20 Oct 2003 20:55:36 -0000	1.53.2.1
  @@ -1,5 +1,3 @@
  -# $Id$
  -
   package AxKit;
   use strict;
   use vars qw/$VERSION/;
  @@ -16,7 +14,9 @@
   use Apache::AxKit::Provider::File;
   use Apache::AxKit::Provider::Scalar;
   use Apache::AxKit::CharsetConv;
  +use Apache::AxKit::Pipeline;
   use File::Basename ();
  +use Data::Dumper;
   use Compress::Zlib ();
   use Fcntl;
   
  @@ -176,10 +176,12 @@
   
       local $SIG{__DIE__} = sub { AxKit::prep_exception(@_)->throw };
   
  -    # use Carp ();
  -    # local $SIG{'USR2'} = sub { 
  -    #     Carp::confess("caught SIGUSR2!");
  -    # };
  +    use Carp ();
  +     local $SIG{'USR2'} = sub { 
  +         Carp::confess("caught SIGUSR2!");
  +     };
  +    
  +    my $rc = $r->status();
       
       $AxKit::Cfg = Apache::AxKit::ConfigReader->new($r);
   
  @@ -200,12 +202,10 @@
           return $plugin_ret;
       }
   
  -    my $provider = Apache::AxKit::Provider->new_content_provider($r);
  -
  -    return $provider->decline(reason => "passthru set")
  -            if ($r->notes('axkit_passthru') && $r->dir_config('AxFastPassthru'));
  -
  -    return main_handler($r, $provider);
  +	
  +    my $ret = main_handler($r);
  +    $r->status($rc);
  +    return $ret;
   }
   
   #########################################
  @@ -226,15 +226,17 @@
   
       local $SIG{__DIE__} = sub { AxKit::prep_exception(@_)->throw };
   
  -    # use Carp ();
  -    # local $SIG{'USR2'} = sub {
  -    #     Carp::confess("caught SIGUSR2!");
  -    # };
  +     use Carp ();
  +     local $SIG{'USR2'} = sub {
  +         Carp::confess("caught SIGUSR2!");
  +     };
   
       local $AxKit::Cfg;
       local $AxKit::DebugLevel;
       local $Error::Debug;
   
  +	my $rc = $r->status();
  +
       $AxKit::Cfg = Apache::AxKit::ConfigReader->new($r);
   
       if ($AxKit::Cfg->DebugTime) {
  @@ -254,63 +256,49 @@
           return $plugin_ret;
       }
   
  -    my $provider = Apache::AxKit::Provider->new_content_provider($r);
  -
  -    return $provider->decline(reason => "passthru set")
  -            if ($r->notes('axkit_passthru') && $r->dir_config('AxFastPassthru'));
  -
  -    return main_handler($r, $provider);
  +   	my $ret =  main_handler($r );
  +   	$r->status($rc);
  +   	return $ret;
   }
   
   sub main_handler {
  -    my ($r, $provider) = @_;
  -
  -    # Do we process this URL?
  -    # (moved down here from slow_handler because of AxHandleDirs)
  -    AxKit::Debug(2, "checking if we process this resource");
  -    if (!$provider->process()) {
  -        return $provider->decline();
  -    }
  +    my ($r) = @_;
   
       # setup global pnotes.
       local $AxKit::Apache::PNOTES = $r->pnotes();
  -    
  -    if ($r->notes('axkit_passthru')) {
  -        # slow passthru
  -        $r->send_http_header('text/xml');
  -        return DONE if $r->method eq 'HEAD';
  -        eval {
  -            my $fh = $provider->get_fh;
  -            $r->send_fd($fh);
  -        };
  -        if ($@) {
  -            my $str = $provider->get_strref;
  -            $r->print($str);
  -        }
  -        return OK;
  -    }
   
  -    local $AxKit::Cache;
  +    my $provider = Apache::AxKit::Provider->new_content_provider($r);
   
       my $retcode = eval {
  +    
  +    	return $provider->decline(reason => "passthru set")
  +            if (($r->notes('axkit_passthru') == 1 ) && $r->dir_config('AxFastPassthru'));
  +
  +    	# Do we process this URL?
  +    	# (moved down here from slow_handler because of AxHandleDirs)
  +    	AxKit::Debug(2, "checking if we process this resource");
  +    	if (!$provider->process()) {
  +    	    return $provider->decline();
  +    	}
  +    
           # $r->header_out('X-AxKit-Version', $VERSION);
   
           chdir(File::Basename::dirname($r->filename));
   
  -        $AxKit::OrigType = $r->content_type('changeme');
  +#        $AxKit::OrigType = $r->content_type('changeme');
   
           reset_depends();
   
  -        my $result_code = run_axkit_engine($r, $provider);
  +		my $pipeline = build_pipeline($r, $provider, 0);
  +		
  +		return $pipeline->send($r);
   
           # restore $r
  -        if (ref($r) eq 'AxKit::Apache') {
  -            bless $r, 'Apache';
  -            tie *STDOUT, 'Apache', $r;
  -        }
  -
  -        deliver_to_browser($r, $result_code);
  -    };
  +#        if (ref($r) eq 'AxKit::Apache') {
  + #           bless $r, 'Apache';
  + #           tie *STDOUT, 'Apache', $r;
  + #       }
  +   };
       my $E = $@;
       unless ($E) {
           return $retcode;
  @@ -325,26 +313,33 @@
       }
   
       if ($E->isa('Apache::AxKit::Exception::OK')) {
  -        return deliver_to_browser($r); # should return OK
  +    
  +    	warn("CHANGED FUNCTIONALITY - just returning OK");
  +    	return OK;
  +        #return deliver_to_browser($r); # should return OK
       }
       elsif ($E->isa('Apache::AxKit::Exception::Retval')) {
           my $code = $E->{return_code};
       	AxKit::Debug(5, "aborting with code $code");
           return $code;
  -    }
  +    } elsif($E->isa('Apache::AxKit::Exception::Declined')) {
  +		return DECLINED;
  +	}
       
       $r->content_type($AxKit::OrigType)
  -                if $r->content_type() eq 'changeme'; # restore content-type
  -    
  -    if ($E->isa('Apache::AxKit::Exception::Declined')) {
  +    	if $r->content_type() eq 'changeme'; # restore content-type
  +   
  +	
  +    if ($E->isa('Apache::AxKit::Exception::ProviderDeclined')) {
           if ($AxKit::Cfg && $AxKit::Cfg->LogDeclines()) {
               $r->log->warn("[AxKit] [DECLINED] $E->{reason}")
                       if $E->{reason};
           }
           AxKit::Debug(4, "[DECLINED] From: $E->{-file} : $E->{-line}");
           
  -        $r->send_http_header('text/xml');
  +        $r->send_http_header($AxKit::OrigType);
           return DONE if $r->method eq 'HEAD';
  +
           eval {
               my $fh = $provider->get_fh;
               $r->send_fd($fh);
  @@ -397,61 +392,19 @@
       return DECLINED;
   }
   
  -sub run_axkit_engine {
  +sub build_pipeline{
       my ($r, $provider, $no_output) = @_;
       
       # get preferred stylesheet and media type
       my ($preferred, $media) = get_style_and_media();
       AxKit::Debug(2, "media: $media, preferred style: $preferred");
   
  -    # get cache object
  -    my $cache = Apache::AxKit::Cache->new($r, $provider->key() . ($AxKit::Cfg->GzipOutput ? '.gzip' : '') . ($r->path_info() || ''), $preferred, $media, $r->notes('axkit_cache_extra'));
  -
  -    my $recreate = 0; # regenerate from source (not cached)
  -
  -    my $styles = get_styles($media, $preferred, $cache, $provider);
  -
  -    {
  -        local $^W;
  -        if ($preferred && ($styles->[0]{title} ne $preferred)) {
  -            # we selected a style that didn't exist.
  -            # Make sure we default the cache file, otherwise
  -            # we setup a potential DoS
  -            AxKit::Debug(3, "resetting cache with no preferred style ($preferred ne $styles->[0]{title})");
  -            $cache = Apache::AxKit::Cache->new($r, $provider->key() . ($AxKit::Cfg->GzipOutput ? '.gzip' : '') . $r->path_info(), '', $media, $r->notes('axkit_cache_extra'));
  -        }
  -    }
  -
  -    if (!$cache->exists()) {
  -        AxKit::Debug(2, "cache doesn't exist");
  -        # set no_cache header if cache doesn't exist due to no_cache option
  -        $r->no_cache(1) if $cache->no_cache();
  -        $recreate++;
  -    }
  -
  -    if (!$recreate && $AxKit::Cfg->DependencyChecks()) {
  -        $recreate = check_dependencies($r, $provider, $cache);
  -    }
  -
  -    if (!$recreate && $r->method() eq 'POST') {
  -        $recreate++;
  -    }
  -
  -    $AxKit::Charset = $AxKit::Cfg->OutputCharset();
  -
  -    # Store in package variable for other modules
  -    $AxKit::Cache = $cache;
  -    
  -    if (!$recreate) {
  -        AxKit::Debug(1, "delivering cached copy - all conditions met");
  -        return $cache->deliver();
  -    }
  -
  -    AxKit::Debug(1, "some condition failed. recreating output");
  +    my $styles = get_styles($media, $preferred, $provider, $r);
   
       # reconsecrate Apache request object (& STDOUT) into our own class
  -    bless $r, 'AxKit::Apache';
  -    tie *STDOUT, 'AxKit::Apache', $r;
  +
  +#    bless $r, 'AxKit::Apache';
  +#    tie *STDOUT, 'AxKit::Apache', $r;
       
       if (my $charset = $AxKit::Cfg->OutputCharset) {
           AxKit::Debug(5, "Different output charset: $charset");
  @@ -467,26 +420,79 @@
       substr($uri, -length($path_info)) = '' if length($path_info); # trim off the end that many chars (negative offset to substr)
       $r->uri($uri);
       $ENV{PATH_INFO} = $path_info;
  -
  -    {
  -        # copy styles because we blat the copy
  -        my @copy = @$styles;
  -        $AxKit::_CurrentStylesheets = \@copy;
  -    }
  +    
  +	my ($transformer, $doit) = AxKit::get_output_transformer();
  +	my $last_in_chain = !($no_output || $doit || lc($r->dir_config('Filter')) eq 'on' );
  +		
  +	my $pipeline = Apache::AxKit::Pipeline->create_pipeline(
  +		apache 		=> $r, 
  +		provider	=> $provider, 
  +		styles		=> $styles,
  +		lastinchain	=> $last_in_chain
  +	);
  +
  +	return $pipeline;
  +}	
  +
  +#sub run_axkit_engine {
  +#    my ($r, $provider, $no_output) = @_;
  +#    
  +#    # get preferred stylesheet and media type
  +#    my ($preferred, $media) = get_style_and_media();
  +#    AxKit::Debug(2, "media: $media, preferred style: $preferred");#
  +#
  +#    my $styles = get_styles($media, $preferred, $provider, $r);
  +#
  +#    # 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')) {
  +#            $r->content_type("text/html; charset=$charset");
  +#        }
  +#    }
  +    
  +    # This is here so that lookup_uri() works on the real thing
  +    # that we're requesting, not on the thing plus the PATH_INFO
  +#    my $uri = $r->uri();
  +#    my $path_info = $r->path_info();
  +#    substr($uri, -length($path_info)) = '' if length($path_info); # trim off the end that many chars (negative offset to substr)
  +#    $r->uri($uri);
  +#    $ENV{PATH_INFO} = $path_info;
       
       # Main grunt of the work done here...
  -    my $return_code = process_request(
  -        $r,
  -        $provider,
  -        $AxKit::_CurrentStylesheets,
  -        $no_output,
  -    );
  +#    return process_request( $r, $provider, $styles, $no_output );
  +            
  +#}
  +
  +#sub process_request {
  +#    my ($r, $provider, $styles, $no_output) = @_;#
   
  -    save_dependencies($r, $cache);
  +#	my ($transformer, $doit) = AxKit::get_output_transformer();
  +#	my $last_in_chain = !($no_output || $doit || lc($r->dir_config('Filter')) eq 'on' );
  +		
  +#	my $pipeline = Apache::AxKit::Pipeline->create_pipeline(
  +#		apache 		=> $r, 
  +#		provider	=> $provider, 
  +#		styles		=> $styles,
  +#		lastinchain	=> $last_in_chain
  +#	);
  +	 
  +	
  +#	my $str_ref = $pipeline->get_strref( $r, $last_in_chain );	
  +
  +#	my $ret_val = $r->status();
  +	
  +#	AxKit::Debug(5, "pipeline finished with apache status $ret_val");
       
  -    return $return_code;
  -        
  -}
  +#    return $str_ref;
  +#}
  +
  +
  +
   
   sub get_axkit_uri {
       my ($uri) = @_;
  @@ -527,20 +533,18 @@
       }
       
       local $AxKit::Cfg = Apache::AxKit::ConfigReader->new($r);
  -    local $AxKit::Cache;
   
       my $provider = Apache::AxKit::Provider->new_content_provider($r);
       
  -    my $result_code = eval {
  -        run_axkit_engine(
  -            $r,
  -            $provider,
  -            1, # no output
  -        );
  -    };
  +    my $pipeline = build_pipeline($r, $provider, 1); # no output;
  +    
  +    my $str_ref = eval { $pipeline->get_strref($r, 0); };
  +     
  +    my $result_code =  $r->status();
  +     
       if ($@) {
           my $E = $@;
  -        if ($E->isa('Apache::AxKit::Exception::Declined')) {
  +        if ($E->isa('Apache::AxKit::Exception::ProviderDeclined')) {
               if ($AxKit::Cfg && $AxKit::Cfg->LogDeclines()) {
                   $r->log->warn("[AxKit] [DECLINED] $E->{reason}")
                           if $E->{reason};
  @@ -552,14 +556,12 @@
                   my $fh = $provider->get_fh;
                   local $/;
                   $str = <$fh>;
  -                $r->pnotes('xml_string', $str);
  -                $result_code = OK;
  +                $str_ref = \$str;
  +                $result_code = OK;	
               };
               if ($@) {
                   eval {
  -                    my $pstr = $provider->get_strref;
  -                    $str = $$pstr;
  -                    $r->pnotes('xml_string', $str);
  +                    $str_ref = $provider->get_strref;
                       $result_code = OK;
                   };
                   if ($@) {
  @@ -576,34 +578,11 @@
           }
       }
       
  -    if ($result_code == OK) {
  -        # results now in $r->pnotes('xml_string') - probably...
  -        if ( my $str = $r->pnotes('xml_string') ) {
  -            # NB: this is naive, but "0" isn't valid XML anyway
  -            $r->pnotes('xml_string', undef);
  -            AxKit::Debug(10, "get_axkit_uri returning (str): '$str'");
  -            return $str;
  -        }
  -        elsif ($r->pnotes('dom_tree')) {
  -            my $str = $r->pnotes('dom_tree')->toString;
  -            $r->pnotes('dom_tree', undef);
  -            AxKit::Debug(10, "get_axkit_uri returning (dom): '$str'");
  -            return $str;
  -        }
  -        else {
  -            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 {
  +	if($result_code == 200 || $result_code eq OK) {
  +		return ${$str_ref};
  +	}  else {
           throw Apache::AxKit::Exception (
  -            -text => "$uri internal request returned unknown result code: ".$result_code,
  +            -text => "$uri internal request returned unknown result code: ".$r->status(),
           );
       }
   }
  @@ -611,11 +590,10 @@
   sub process_error {
       my ($r, $E, $error_styles) = @_;
       
  -    bless $r, 'AxKit::Apache';
  -    tie *STDOUT, 'AxKit::Apache', $r;
  +#    bless $r, 'AxKit::Apache';
  +#    tie *STDOUT, 'AxKit::Apache', $r;
   
       $r->dir_config->set(AxNoCache => 1);
  -    $AxKit::Cache = Apache::AxKit::Cache->new($r, 'error', '', '', '');
       
       $r->content_type("text/html; charset=UTF-8"); # set a default for errors
   
  @@ -623,18 +601,27 @@
   
       my $provider = Apache::AxKit::Provider::Scalar->new(
               $r, $error, $error_styles
  -            );
  -
  -    $r->pnotes('xml_string', $error);
  +    );
   
       eval {
  -        process_request($r, $provider, $error_styles);
  -        if (ref($r) eq 'AxKit::Apache') {
  -            bless $r, 'Apache';
  -            tie *STDOUT, 'Apache', $r;
  -        }
  -        deliver_to_browser($r);
  +		my ($transformer, $doit) = AxKit::get_output_transformer();
  +		my $last_in_chain = !( $doit || lc($r->dir_config('Filter')) eq 'on' );
  +		
  +		my $pipeline = Apache::AxKit::Pipeline->create_pipeline(
  +			apache 		=> $r, 
  +			provider	=> $provider, 
  +			styles		=> $error_styles,
  +			lastinchain	=> $last_in_chain
  +		);
  +	 
  +		$pipeline->send($r);
  +
  +		my $ret_val = $r->status();
  +	
  +		AxKit::Debug(5, "pipeline finished with apache status $ret_val");
  +    
       };
  +
       if ($@) {
           $r->log->error("[AxKit] [FATAL] Error occured while processing Error XML: $@");
           return SERVER_ERROR;
  @@ -643,183 +630,9 @@
       return OK;
   }
   
  -sub insert_next_stylesheet {
  -    my ($type, $href) = @_;
  -    my $mapping = $AxKit::Cfg->StyleMap;
  -    my $module = $mapping->{$type};
  -    if (!$module) {
  -        throw Apache::AxKit::Exception::Declined(
  -            reason => "No implementation mapping available for type '$type'"
  -            );
  -    }
  -    unshift @$AxKit::_CurrentStylesheets, 
  -            {
  -                type => $type,
  -                href => $href,
  -                module => $module,
  -            };
  -}
  -
  -sub insert_last_stylesheet {
  -    my ($type, $href) = @_;
  -    my $mapping = $AxKit::Cfg->StyleMap;
  -    my $module = $mapping->{$type};
  -    if (!$module) {
  -        throw Apache::AxKit::Exception::Declined(
  -            reason => "No implementation mapping available for type '$type'"
  -            );
  -    }
  -    push @$AxKit::_CurrentStylesheets, 
  -            {
  -                type => $type,
  -                href => $href,
  -                module => $module,
  -            };
  -}
  -
  -sub reset_stylesheets {
  -    @$AxKit::_CurrentStylesheets = ();
  -}
  -
  -sub process_request {
  -    my ($r, $provider, $styles, $no_output) = @_;
  -    my $result_code = OK;
  -
  -    my $num_styles = 0;
  -    for my $style (@$styles) {
  -        AxKit::Debug(4, "styles: ", $style->{module}, "(", $style->{href}, ")");
  -        $num_styles++;
  -    }
  -
  -    my $interm_prefix;
  -    my $interm_count = 0;
  -    if (my $ti = $AxKit::Cfg->TraceIntermediate) {
  -        my $id = $r->notes('AxRequestID');
  -        $interm_prefix = ($id?$id:$r->uri);
  -        $interm_prefix =~ s{%}{%25}g;
  -        $interm_prefix =~ s{/}{%2f}g;
  -        if (defined $id) {
  -                $interm_prefix = substr($interm_prefix,-1).'/'.substr($interm_prefix,-3,2).'/'.substr($interm_prefix,0,-3).'/';
  -                mkdir($ti.'/'.substr($interm_prefix,0,1),0777);
  -                mkdir($ti.'/'.substr($interm_prefix,0,4),0777);
  -                mkdir($ti.'/'.$interm_prefix,0777);
  -        } else {
  -                $interm_prefix =~ s/[^0-9a-zA-Z.,_|-]/_/g;
  -                $interm_prefix .= '.';
  -        }
  -        $interm_prefix = $ti.'/'.$interm_prefix;
  -    
  -        if ($interm_prefix) {
  -            if (!-d $ti) {
  -                if (!mkdir($ti, 0777)) {
  -                    AxKit::Debug(1, "Can't create AxTraceIntermediate directory '$ti': $!");
  -                }
  -            }
  -            my $fh = Apache->gensym();
  -            if (AxKit::open($fh, ">".$interm_prefix.$interm_count)) {
  -                print $fh ${$provider->get_strref};
  -                close($fh);
  -                $interm_count++;
  -            } else {
  -                AxKit::Debug(1,"could not open $interm_prefix$interm_count for writing: $!");
  -            }
  -        }
  -    }
  -
  -    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,
  -                uri => $style->{href},
  -                );
  -
  -        $r->notes('resetstring', 1);
  -
  -        no strict 'refs';
  -
  -        my $mapto = $style->{module};
  -
  -        # if no module is give AxKit should use the default modules
  -        # from the server config.
  -        unless ( $mapto ) {
  -            my $mapping = $AxKit::Cfg->StyleMap;
  -            $mapto = $mapping->{$style->{type}};
  -        }
  -
  -        AxKit::Debug(3, "about to execute: $mapto\::handler");
  -        AxKit::load_module($mapto);
  -
  -        my $method = "handler";
  -        if (defined &{"$mapto\::$method"}) {
  -            if ($mapto->stylesheet_exists() && !$styleprovider->exists()) {
  -                throw Apache::AxKit::Exception::Error(
  -                        -text => "stylesheet '$style->{href}' could not be found or is not readable"
  -                        );
  -            }
  -            my $retval = $mapto->$method(
  -                    $r,
  -                    $provider,
  -                    $styleprovider,
  -                    $output_to_browser,
  -                    );
  -	    AxKit::Debug(5, "$mapto\::handler finished with code $retval");
  -            $result_code = $retval if $retval != OK;
  -        }
  -        else {
  -            throw Apache::AxKit::Exception::Error(
  -                -text => "$mapto Function not found"
  -                );
  -        }
  -
  -        if ($interm_prefix) {
  -            my $fh = Apache->gensym();
  -            if (AxKit::open($fh, '>'.$interm_prefix.$interm_count)) {
  -                my $xmlstr;
  -                if ($AxKit::Cfg->DebugTidy) {
  -                    eval {
  -                        require XML::LibXML;
  -                        my $parser = new XML::LibXML();
  -                        $parser->keep_blanks(0);
  -                        if (my $dom_tree = $r->pnotes('dom_tree')) {
  -                            $xmlstr = $dom_tree->toString;
  -                        } elsif ($r->pnotes('xml_string')) {
  -                            $xmlstr = $r->pnotes('xml_string');
  -                        } else {
  -                            die;
  -                        }
  -                        local $XML::LibXML::setTagCompression = 1;
  -                        $xmlstr = $parser->parse_string($xmlstr,$r->uri)->toString(1);
  -                    };
  -                    AxKit::Debug(1,"AxDebugTidy unavailable for XML: $@") if $@;
  -                }
  -                if (!defined $xmlstr) {
  -                    if (my $dom_tree = $r->pnotes('dom_tree')) {
  -                        $xmlstr = $dom_tree->toString;
  -                    } elsif ($r->pnotes('xml_string')) {
  -                        $xmlstr = $r->pnotes('xml_string');
  -                    } else {
  -                        $xmlstr = "<?xml version='1.0'?>\n<empty reason='no data found'/>\n";
  -                    }
  -                }
  -                print($fh $xmlstr);
  -                close($fh);
  -                $interm_count++;
  -            } else {
  -                AxKit::Debug(1,"could not open $interm_prefix$interm_count for writing: $!");
  -            }
  -        }
  -
  -        AxKit::Debug(3, "execution of: $mapto\::$method finished");
  -
  -        last if $r->notes('axkit_passthru');
  -    }
  -
  -    return $result_code;
  -}
  +sub insert_next_stylesheet { die("Not supported anymore") }
  +sub insert_last_stylesheet { die("Not supported anymore") }
  +sub reset_stylesheets { die("Not supported anymore") }
   
   sub get_style_and_media {
       my $style = $AxKit::Cfg->PreferredStyle;
  @@ -835,16 +648,20 @@
   }
   
   sub get_styles {
  -    my ($media, $style, $cache, $provider) = @_;
  +    my ($media, $style, $provider, $r) = @_;
  +
  +	# This cache is only generating a key for the style cache.
   
  -    my $key = $cache->key();
  +    my $key = Apache::AxKit::Cache->new($r, $provider->key() . 
  +    	($r->path_info() || ''), $style, $media )->key();
   
       AxKit::Debug(2, "getting styles and external entities from the XML");
       # get styles/ext_ents from cache or re-parse
   
       my $styles;
   
  -    if (exists($AxKit::Stash{$key})
  +    if (!$r->dir_config('AxDisableGetStylesCache') 
  +	    && exists($AxKit::Stash{$key})
               && !$provider->has_changed($AxKit::Stash{$key}{mtime}))
       {
           AxKit::Debug(3, "styles cached");
  @@ -863,153 +680,73 @@
       }
   }
   
  -sub check_dependencies {
  -    my ($r, $provider, $cache) = @_;
  -    AxKit::Debug(2, "Checking dependencies");
  -    if ( $provider->has_changed( $cache->mtime() ) ) {
  -        AxKit::Debug(3, "xml newer than cache");
  -        return 1;
  -    }
  -    else {
  -        my $depend_cache = Apache::AxKit::Cache->new($r, $cache->key(), '.depends');
  -        my $depends_contents = $depend_cache->read();
  -        if ($depends_contents) {
  -            DEPENDENCY:
  -            for my $dependency (split(/:/, $depends_contents)) {
  -                $dependency =~ s|^\{(\w+)\}||;
  -                my $dep_type = $1;
  -                AxKit::Debug(3, "Checking dependency: $dependency of type $dep_type for resource ", $provider->key());
  -                my $dep = ($dep_type eq "style") ?
  -                    Apache::AxKit::Provider->new_style_provider($r, key => $dependency) :
  -                    Apache::AxKit::Provider->new($r, key => $dependency);
  -                if ( $dep->has_changed( $cache->mtime() ) ) {
  -                    AxKit::Debug(4, "dependency: $dependency newer");
  -                    return 1;
  -                }
  -            }
  -        }
  -        else {
  -            AxKit::Debug(2, "No dependencies list yet");
  -            return 1;
  -#            return check_resource_mtimes($provider, $styles, $cache->mtime());
  -        }
  -    }
  -}
  -
  -sub save_dependencies {
  -    my ($r, $cache) = @_;
  -
  -    return if $cache->no_cache();
  -
  -    eval {
  -        my @depends = get_depends();
  -        my $depend_cache = Apache::AxKit::Cache->new($r, $cache->key(), '.depends');
  -        $depend_cache->write(join(':', @depends));
  -    };
  -    if ($@) {
  -        AxKit::Debug(2, "Cannot write dependencies cache: $@");
  -    }
  -}
  -
  -sub deliver_to_browser {
  -    my ($r, $result_code) = @_;
  -    $result_code ||= OK;
  +#sub deliver_to_browser {
  +#    my ($r, $str_ref) = @_;
       
  -    AxKit::Debug(4, "delivering to browser");
  -
  -    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 (ref($r) eq 'AxKit::Apache') {
  +#		bless $r, 'Apache';
  +#		tie *STDOUT, 'Apache', $r;
  +#	}
  +        
  +#    my $result_code = $r->status();
  +        
  +#    AxKit::Debug(4, "delivering to browser");
   
  -    if ($r->content_type eq 'changeme' && !$r->notes('axkit_passthru_type')) {
  -        $AxKit::Cfg->AllowOutputCharset(1);
  -        $r->content_type('text/html; charset=' . ($AxKit::Cfg->OutputCharset || "UTF-8"));
  -    }
  -    elsif ($r->notes('axkit_passthru_type')) {
  -        $r->content_type($AxKit::OrigType);
  -    }
  +#
  +#    if ($r->content_type eq 'changeme' && !$r->notes('axkit_passthru_type')) {
  +#        $AxKit::Cfg->AllowOutputCharset(1);
  +#        $r->content_type('text/html; charset=' . ($AxKit::Cfg->OutputCharset || "UTF-8"));
  +#    }
  +#    elsif ($r->notes('axkit_passthru_type')) {
  +#        $r->content_type($AxKit::OrigType);
  +#    }
   
  -    if (my $charset = $AxKit::Cfg->OutputCharset()) {
  -        my $ct = $r->content_type;
  -        $ct =~ s/charset=.*?(;|$)/charset=$charset/i;
  -        $r->content_type($ct);
  -    }
  +#    if (my $charset = $AxKit::Cfg->OutputCharset()) {
  +#        my $ct = $r->content_type;
  +#        $ct =~ s/charset=.*?(;|$)/charset=$charset/i;
  +#        $r->content_type($ct);
  +#    }
  +#	
  +# I've removed all this cause it breaks error documents
  +# 
  +#    if ($result_code != OK && $result_code != 200) {
  +#    	# no caching - probably makes no sense, and will be turned off
  +#        # anyways, as currently only XSP pages allow to send custom responses
  +#    	AxKit::Debug(4,"sending custom response: $result_code");
  +#        my ($transformer, $doit) = get_output_transformer();
  +#        if ($doit) {
  +#            $r->custom_response($result_code,$transformer->( ${$str_ref} ));
  +#        }
  +#        else {
  +#            $r->custom_response($result_code,${$str_ref});
  +#        }
  +#        return $result_code;
  +#    }
  +#
  +#	$r->status(200);
   
  -    if ($result_code != OK && $result_code != 200) {
  -    	# no caching - probably makes no sense, and will be turned off
  -        # anyways, as currently only XSP pages allow to send custom responses
  -    	AxKit::Debug(4,"sending custom response: $result_code");
  -        my ($transformer, $doit) = get_output_transformer();
  -        if ($doit) {
  -            $r->custom_response($result_code,$transformer->($r->pnotes('xml_string') || ''));
  -        }
  -        else {
  -            $r->custom_response($result_code,$r->pnotes('xml_string') || '');
  -        }
  -        return $result_code;
  -    }
  -
  -    if ($AxKit::Cache->no_cache() ||
  -        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) {
  -            AxKit::Debug(4, 'Sending gzipped xml string to browser');
  -            my $data = Compress::Zlib::memGzip($doit ?
  -                        $transformer->($r->pnotes('xml_string')) :
  -                        $r->pnotes('xml_string')
  -                    );
  -            $r->header_out('Content-Length' => length($data));
  -            AxKit::Apache::send_http_header($r);
  -            return DONE if $r->method eq 'HEAD';
  -            $r->print($data);
  -        }
  -        else {
  -            AxKit::Apache::send_http_header($r);
  -            return DONE if $r->method eq 'HEAD';
  -            if ($doit) {
  -                $r->print(
  -                        $transformer->( $r->pnotes('xml_string') )
  -                        );
  -            }
  -            else {
  -                $r->print( $r->pnotes('xml_string') );
  -            }
  -        }
  -        return OK;
  -    }
  -    else {
  -        AxKit::Debug(4, "writing xml string to cache and delivering to browser");
  -        my $retval = eval {
  -            $AxKit::Cache->write($r->pnotes('xml_string'));
  -            $AxKit::Cache->deliver();
  -        };
  -        if (my $E = $@) {
  -            if ($E->isa('Apache::AxKit::Exception::IO')) {
  -                AxKit::Debug(1, "WARNING: Unable to write to AxCacheDir or .xmlstyle_cache");
  -                AxKit::Apache::send_http_header($r);
  -                return DONE if $r->method eq 'HEAD';
  -                $r->print( $r->pnotes('xml_string') );
  -            }
  -            else {
  -                throw $E;
  -            }
  -        }
  -        else {
  -            return $retval;
  -        }
  -    }
  -}
  +#	AxKit::Debug(4, "writing xml string to browser");
  +#	my ($transformer, $doit) = get_output_transformer();
  +#	if ($AxKit::Cfg->DoGzip) {
  +#		AxKit::Debug(4, 'Sending gzipped xml string to browser');
  +#		my $data = Compress::Zlib::memGzip($doit ?
  +#					$transformer->($r->pnotes('xml_string')) :
  +#					$r->pnotes('xml_string')
  +#				);
  +#		$r->header_out('Content-Length' => length($data));
  +#		AxKit::Apache::send_http_header($r);
  +#		return DONE if $r->method eq 'HEAD';
  +#		$r->print($data);
  +#	}
  +#	else {
  +#		my $data = $doit ? $transformer->( ${$str_ref} ) : ${$str_ref};
  +#		$r->header_out('Content-Length' => length($data));
  +#		AxKit::Apache::send_http_header($r);
  + #       return DONE if $r->method eq 'HEAD';
  +#		$r->print($data);
  +#	}
  + #  	return OK;
  +#}
   
   sub prep_exception {
       my $err = shift;
  @@ -1097,23 +834,10 @@
       $r ||= Apache->request;
   }
   
  -sub content_type {
  -    my $self = shift;
  -
  -    my ($type) = @_;
  -
  -    if ($type) {
  -#        warn "Writing content type '$type'\n";
  -        $AxKit::Cache->set_type($type);
  -    }
  -
  -    $self->SUPER::content_type(@_);
  -}
  -
   sub print {
       my $self = shift;
  +	delete $self->pnotes()->{'dom_tree'};	
       use bytes;
  -    
       if ($self->notes('resetstring')) {
           $self->pnotes('xml_string', '');
           $self->notes('resetstring', 0);
  @@ -1124,18 +848,6 @@
   }
   
   *PRINT = \&print;
  -
  -sub no_cache {
  -    my $self = shift;
  -    my ($set) = @_;
  -
  -    $self->SUPER::no_cache(@_);
  -
  -    if ($set) {
  -#        warn "caching being turned off!\n";
  -        $AxKit::Cache->no_cache(1);
  -    }
  -}
   
   sub send_http_header {
       my $self = shift;