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 2002/05/26 18:24:41 UTC
cvs commit: xml-axkit/lib/Apache/AxKit/Language LibXSLT.pm XSP.pm
matts 02/05/26 09:24:40
Modified: demo axkit.conf
demo/xsp .htaccess session.xsp
lib AxKit.pm
lib/Apache/AxKit ConfigReader.pm
lib/Apache/AxKit/Language LibXSLT.pm XSP.pm
Log:
Fixed demo slightly for Session taglib demo
Implemented axkit: scheme for URIs (required re-arrangement of AxKit.pm)
Revision Changes Path
1.5 +5 -0 xml-axkit/demo/axkit.conf
Index: axkit.conf
===================================================================
RCS file: /home/cvs/xml-axkit/demo/axkit.conf,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- axkit.conf 19 Mar 2002 20:30:59 -0000 1.4
+++ axkit.conf 26 May 2002 16:24:40 -0000 1.5
@@ -17,6 +17,11 @@
<Perl>
## CHANGE THIS as well
use lib qw(/opt/axkit/demo/);
+
+eval {
+ require Apache::AxKit::Plugin::Session;
+ import Apache::AxKit::Plugin::Session '/redirect';
+};
</Perl>
## and another one, CHANGE THIS
1.6 +2 -2 xml-axkit/demo/xsp/.htaccess
Index: .htaccess
===================================================================
RCS file: /home/cvs/xml-axkit/demo/xsp/.htaccess,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- .htaccess 15 Mar 2002 00:24:49 -0000 1.5
+++ .htaccess 26 May 2002 16:24:40 -0000 1.6
@@ -19,8 +19,8 @@
# Note: these require additional setup. Not sure how/if that
# can be handled automagically
<Files session.xsp>
- AxAddPlugin Apache::AxKit::Plugin::Session
- AxAddXSPTaglib AxKit::XSP::Session
+# AxAddPlugin Apache::AxKit::Plugin::Session
+ AxAddXSPTaglib +AxKit::XSP::Session
</Files>
<Files globals.xsp>
1.4 +1 -1 xml-axkit/demo/xsp/session.xsp
Index: session.xsp
===================================================================
RCS file: /home/cvs/xml-axkit/demo/xsp/session.xsp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- session.xsp 15 Mar 2002 00:24:49 -0000 1.3
+++ session.xsp 26 May 2002 16:24:40 -0000 1.4
@@ -3,7 +3,7 @@
<xsp:page language="Perl"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
xmlns:session="http://www.apache.org/1999/XSP/Session"
- xmlns="http://www.w3.org/1999/xhtml">
+ xmlns:ignore="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>Session Taglib demo</title>
1.15 +140 -86 xml-axkit/lib/AxKit.pm
Index: AxKit.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/AxKit.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AxKit.pm 22 May 2002 19:45:39 -0000 1.14
+++ AxKit.pm 26 May 2002 16:24:40 -0000 1.15
@@ -1,4 +1,4 @@
-# $Id: AxKit.pm,v 1.14 2002/05/22 19:45:39 matts Exp $
+# $Id: AxKit.pm,v 1.15 2002/05/26 16:24:40 matts Exp $
package AxKit;
use strict;
@@ -144,6 +144,9 @@
# Carp::confess("caught SIGUSR2!");
# };
+ # local $AxKit::Cfg;
+ # local $Error::Debug;
+
$AxKit::Cfg = Apache::AxKit::ConfigReader->new($r);
# if ($AxKit::Cfg->DebugTime) {
@@ -207,8 +210,7 @@
$AxKit::T0 = [Time::HiRes::gettimeofday()] if $AxKit::Cfg->DebugTime;
}
- $AxKit::DebugLevel = $AxKit::Cfg->DebugLevel();
- $Error::Debug = 1 if (($AxKit::DebugLevel > 3) || $AxKit::Cfg->StackTrace);
+ $Error::Debug = 1 if (($AxKit::Cfg->DebugLevel() > 3) || $AxKit::Cfg->StackTrace);
AxKit::Debug(1, "handler called for " . $r->uri);
@@ -251,6 +253,8 @@
}
return OK;
}
+
+ local $AxKit::Cache;
my $retcode = eval {
# $r->header_out('X-AxKit-Version', $VERSION);
@@ -258,87 +262,11 @@
chdir(File::Basename::dirname($r->filename));
$AxKit::OrigType = $r->content_type('changeme');
-
- # 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, $r->filename() . '.gzip' . ($r->path_info() || ''), $preferred, $media, $r->notes('axkit_cache_extra'));
-
- my $recreate; # 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, $r->filename() . '.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();
-
- if (!$recreate) {
- AxKit::Debug(1, "delivering cached copy - all conditions met");
- return $cache->deliver();
- AxKit::Debug(1, "UNREACHABLE CODE!!!");
- }
-
- AxKit::Debug(1, "some condition failed. recreating output");
-
- # 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')) {
- $r->content_type("text/html; charset=$charset");
- }
- }
- # Someone help me remember why I added this???
- # my $uri = $r->uri();
- # my $path_info = $r->path_info();
- # $uri =~ s/\Q$path_info\E$//;
- # $r->uri($uri);
- # $ENV{PATH_INFO} = $path_info
-
reset_depends();
- {
- # copy styles because we blat the copy
- my @copy = @$styles;
- $AxKit::_CurrentStylesheets = \@copy;
- }
- # Main grunt of the work done here...
- my $result_code = process_request($r, $provider, $AxKit::_CurrentStylesheets);
+ my $result_code = run_axkit_engine($r, $provider);
- save_dependencies($r, $cache);
-
# if (my $dom = $r->pnotes('dom_tree')) {
# AxKit::Debug(4, "got a dom_tree back - outputting that to the cache");
# $r->notes('resetstring', 1);
@@ -439,6 +367,132 @@
return DECLINED;
}
+sub run_axkit_engine {
+ my ($r, $provider) = @_;
+
+ # 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, $r->filename() . '.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, $r->filename() . '.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();
+
+ if (!$recreate) {
+ AxKit::Debug(1, "delivering cached copy - all conditions met");
+ return $cache->deliver();
+ }
+
+ AxKit::Debug(1, "some condition failed. recreating output");
+
+ warn("Storing AxKit::Cache");
+ # 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')) {
+ $r->content_type("text/html; charset=$charset");
+ }
+ }
+
+ # Someone help me remember why I added this???
+ # my $uri = $r->uri();
+ # my $path_info = $r->path_info();
+ # $uri =~ s/\Q$path_info\E$//;
+ # $r->uri($uri);
+ # $ENV{PATH_INFO} = $path_info
+
+ {
+ # copy styles because we blat the copy
+ my @copy = @$styles;
+ $AxKit::_CurrentStylesheets = \@copy;
+ }
+
+ # Main grunt of the work done here...
+ my $return_code = process_request($r, $provider, $AxKit::_CurrentStylesheets);
+
+ save_dependencies($r, $cache);
+
+ return $return_code;
+
+}
+
+sub get_axkit_uri {
+ my ($uri) = @_;
+
+ my $apache = AxKit::Apache->request;
+ my $r;
+ if ($uri =~ /^axkit:\/(\/.*)$/) {
+ my $abs_uri = $1;
+ $r = $apache->lookup_uri($abs_uri);
+ }
+ elsif ($uri =~ /^axkit:(.*)$/) {
+ my $rel_uri = $1;
+ $r = $apache->lookup_uri($rel_uri);
+ }
+
+ local $AxKit::Cfg = Apache::AxKit::ConfigReader->new($r);
+ local $AxKit::Cache;
+
+ my $provider = Apache::AxKit::Provider->new_content_provider($r);
+
+ my $result_code = run_axkit_engine($r, $provider);
+
+ 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;
+ }
+ else {
+ return $r->pnotes('xml_string');
+ }
+ }
+ elsif ($result_code == DECLINED) {
+ # probably came from the cache system. Try and read it.
+ return $AxKit::Cache->read();
+ }
+ else {
+ throw Apache::AxKit::Exception ( -text => "$uri internal request returned unknown result code: ".$result_code);
+ }
+}
+
sub process_error {
my ($r, $E, $error_styles) = @_;
@@ -695,16 +749,16 @@
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
+ # 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')));
+ $r->custom_response($result_code,$transformer->($r->pnotes('xml_string')));
+ }
+ else {
+ $r->custom_response($result_code,$r->pnotes('xml_string'));
}
- else {
- $r->custom_response($result_code,$r->pnotes('xml_string'));
- }
- return $result_code;
+ return $result_code;
}
if ($AxKit::Cache->no_cache() ||
1.5 +2 -1 xml-axkit/lib/Apache/AxKit/ConfigReader.pm
Index: ConfigReader.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/ConfigReader.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigReader.pm 21 May 2002 22:42:29 -0000 1.4
+++ ConfigReader.pm 26 May 2002 16:24:40 -0000 1.5
@@ -1,4 +1,4 @@
-# $Id: ConfigReader.pm,v 1.4 2002/05/21 22:42:29 matts Exp $
+# $Id: ConfigReader.pm,v 1.5 2002/05/26 16:24:40 matts Exp $
package Apache::AxKit::ConfigReader;
@@ -345,6 +345,7 @@
}
}
elsif ($type eq 'URI') {
+warn("XXX URI");
my $uri = $provider->apache_request->uri;
if ($uri =~ /$directive->[3]/) {
push @results, $style_hash;
1.11 +9 -1 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- LibXSLT.pm 22 May 2002 19:41:39 -0000 1.10
+++ LibXSLT.pm 26 May 2002 16:24:40 -0000 1.11
@@ -1,4 +1,4 @@
-# $Id: LibXSLT.pm,v 1.10 2002/05/22 19:41:39 matts Exp $
+# $Id: LibXSLT.pm,v 1.11 2002/05/26 16:24:40 matts Exp $
package Apache::AxKit::Language::LibXSLT;
@@ -154,6 +154,10 @@
my $uri = shift || './';
AxKit::Debug(8, "LibXSLT open_content_uri: $uri");
+ if ($uri =~ /^axkit:/) {
+ return AxKit::get_axkit_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($uri);
@@ -174,6 +178,10 @@
sub open_stylesheet_uri {
my $uri = shift || './';
AxKit::Debug(8, "LibXSLT open_stylesheet_uri: $uri");
+
+ if ($uri =~ /^axkit:/) {
+ return AxKit::get_axkit_uri($uri);
+ }
# create a subrequest, so we get the right AxKit::Cfg for the URI
my $apache = AxKit::Apache->request;
1.11 +43 -1 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XSP.pm 26 May 2002 15:34:21 -0000 1.10
+++ XSP.pm 26 May 2002 16:24:40 -0000 1.11
@@ -1,4 +1,4 @@
-# $Id: XSP.pm,v 1.10 2002/05/26 15:34:21 matts Exp $
+# $Id: XSP.pm,v 1.11 2002/05/26 16:24:40 matts Exp $
package Apache::AxKit::Language::XSP;
@@ -902,6 +902,10 @@
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;
$parser->expand_entities(1);
if (ref($thing)) {
@@ -922,6 +926,44 @@
}
$self->{Handler}->end_document($document);
+}
+
+sub match_uri {
+ my $uri = shift;
+ AxKit::Debug(8, "LibXSLT match_uri: $uri");
+ 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);
+ }
+
+ # create a subrequest, so we get the right AxKit::Cfg for the URI
+ my $apache = AxKit::Apache->request;
+ my $sub = $apache->lookup_uri($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 close_uri {
+}
+
+sub read_uri {
+ return substr($_[0], 0, $_[1], "");
}
sub process_node {