It seems this mail hasn't made it to the list.

Cheers
Christian.

Date: Tue, 7 Oct 2003 14:45:09 +0200
To: [EMAIL PROTECTED]
From: Christian Jaeger <[EMAIL PROTECTED]>
Subject: Provider problems

Hello

I'm having many troubles and unclarities about providers.

The attached provider solves this problem:

- url's should be mapped to source files with a fallback strategy:
  if file.html is not found, look for file.xml, if not found, look for .xsp
- translations depend on both url suffix and source suffix: .xsp
files should always be executed as xsp, .xsp and .xml files should
be translated with xsl if requested as .html, and so on.

Now there is one problem and one question.

- Problem: somehow new requests depend on previous requests. Some
state information is preserved between requests. When I request an
.xml file as .html, then even subsequent .xml requests yield the
.html. In spite of "AxNocache On" in the apache condig, so it
doesn't seem like a cache problem (though that's prolly an unsolved
problem still).

- Question: I'm coding my own typemap in this code. That's since I
didn't know how the whole typemap stuff works. Suggestions for a
clean mechanims welcome.

Thanks,
Christian.


package Thea::Provider; use strict; use base 'Apache::AxKit::Provider::File'; sub init { my $self=shift; warn "CJ init"; my $rv=$self->SUPER::init(@_); delete $$self{file_exists}; ### ggrrrr return $rv; } sub process { my $self = shift; my $xmlfile = $self->{file}; unless ($self->exists()) { AxKit::Debug(5, "file '$xmlfile' does not exist or is not readable"); return 0; } if ($$self{cjfile_sourcetype} eq 'html') { return; # geht!!! } if (!$AxKit::FastHandler) { local $^W; if (($xmlfile =~ /\.xml$/i) || ($xmlfile =~ /\.html$/i)|| ##<-- cj; nötig? ($self->{apache}->content_type() =~ /^(text|application)\/xml/) || $self->{apache}->pnotes('xml_string') ) { return 1; } } else { return 1; } AxKit::Debug(5, "'$xmlfile' not recognised as XML"); return 0; } sub exists { my $self = shift; my $file= $self->{file}; my $uri= $ENV{REQUEST_URI}; $uri=~ s/\?.*//s; my $is_dirindex= substr($uri,-1) eq '/'; if (!$is_dirindex and exists $$self{file_exists}){ return $self->{file_exists} } warn "CJ determine media for '$file'.."; if ($is_dirindex) { $$self{cjfile_media}='html'; warn "CJ: es ist dirindex"; } else { if ( $file=~ /\.html$/) { $$self{cjfile_media}='html'; } else { $$self{cjfile_media}= 'xml'; } } warn "CJ determined media '$$self{cjfile_media}'"; warn "CJ: determine source for '$file'.."; if ($file=~ /\.html$/) { if (-e AxKit::FromUTF8($file)) { $$self{cjfile_sourcetype}='html'; } else { $file=~ s/\.html$/.xml/; goto checkxml; } } elsif ($file=~ /\.xml$/) { checkxml: if (-e AxKit::FromUTF8($file)) { $$self{cjfile_sourcetype}='xml'; } else { $file=~ s/\.xml$/.xsp/; goto checkxsp; } } elsif ($file=~ /\.xsp$/) { checkxsp: if (-e AxKit::FromUTF8($file)) { $$self{cjfile_sourcetype}='xsp'; } else { warn "CJ determine: nothing found"; return; } } else { warn "CJ determine: unknown extension"; return; } warn "CJ: determined source '$$self{cjfile_sourcetype}'"; if (-r _ ) { $self->{file_exists} = 1; $$self{file}=$file; return 1; } else { AxKit::Debug(2, "'$file' not readable"); return; } } my %myowntypemap; $myowntypemap{xsp}{xml}= [{type=> "application/x-xsp", href=>"."}, {type=> "application/x-addparams", href=>"NULL"}, ]; $myowntypemap{xsp}{html}= [{type=> "application/x-xsp", href=>"."}, {type=> "application/x-addparams", href=>"NULL"}, {type=> "text/xsl", href=> "/xsl/htmlview.xsl"}]; $myowntypemap{xml}{xml}= [{type=> "application/x-addparams", href=>"NULL"}, {type=> "text/xsl", href=> "/xsl/flashview.xsl"}, {type=> "application/x-stripwhitespace", href=>"NULL"}, ]; $myowntypemap{xml}{html}= [{type=> "application/x-addparams", href=>"NULL"}, {type=> "text/xsl", href=> "/xsl/htmlview.xsl"}]; sub get_styles { my $self=shift; if ($$self{cjfile_media} eq 'html') { $$self{apache}->content_type("text/html"); } my $res= $myowntypemap{ $$self{cjfile_sourcetype} }{$$self{cjfile_media}}; if (!$res) { warn "CJ get_styles: fallback to super, since type/media $$self{cjfile_sourcetype}/$$self{cjfile_media} not found"; $res= $self->SUPER::get_styles; } $res; } 1;


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to