jwalt 2003/01/28 17:35:50
Modified: demo/xsp .htaccess index.xml lib AxKit.pm lib/Apache/AxKit ConfigReader.pm Exception.pm lib/Apache/AxKit/Language LibXSLT.pm XPathScript.pm XSP.pm lib/Apache/AxKit/Language/XSP SimpleTaglib.pm Added: demo/xsp simple-input-attributes.xsp Log: - added demo files from Ken Neighbors - fixed Session demo (needs 0.93) - modified AxTraceIntermediate for the upcoming request tracker - fixed AxTraceIntermediate for perl 5.8.0 - ConfigReader now interprets relative cache and trace dirs relative to document_root - ConfigReader better supports configuration through PerlSetVar now, for the upcoming Apache::Fake based Axkit-via-plain-CGI support - added xmldb: URIs similar to axkit: URIs - updated PerlTidy usage for latest PerlTidy release - completely removed old namespace prefix hack: the new, correct solution works fine, updated docs accordingly - fix "Unknown node type 19/20" by ignoring them - fix for SimpleTaglib: :expr tags inside other taglib tags didn't work Revision Changes Path 1.8 +10 -2 xml-axkit/demo/xsp/.htaccess Index: .htaccess =================================================================== RCS file: /home/cvs/xml-axkit/demo/xsp/.htaccess,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- .htaccess 26 Jan 2003 17:25:21 -0000 1.7 +++ .htaccess 29 Jan 2003 01:35:49 -0000 1.8 @@ -19,6 +19,14 @@ AxAddXSPTaglib AxKit::XSP::Param </Files> +<Files simple-input-attributes.xsp> +AxAddXSPTaglib AxKit::XSP::Demo::SimpleInputAttributes +</Files> + +<Files simpletaglib-object.xsp> +AxAddXSPTaglib AxKit::XSP::Demo::Object +</Files> + <Files simpletaglib-simple.xsp> AxAddXSPTaglib AxKit::XSP::Demo::Simple </Files> @@ -26,8 +34,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.7 +1 -0 xml-axkit/demo/xsp/index.xml Index: index.xml =================================================================== RCS file: /home/cvs/xml-axkit/demo/xsp/index.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- index.xml 26 Jan 2003 17:26:39 -0000 1.6 +++ index.xml 29 Jan 2003 01:35:49 -0000 1.7 @@ -187,6 +187,7 @@ if (!$@) { <li><a href="simpletaglib-simple.xsp">SimpleTaglib Simple Taglib Example</a></li> <li><a href="simpletaglib-object.xsp">SimpleTaglib OO Taglib Example</a></li> + <li><a href="simple-input-attributes.xsp">SimpleTaglib Input Attributes Example</a></li> } else { AxKit::Debug(1, "SimpleTaglib failed to load: $@"); 1.1 xml-axkit/demo/xsp/simple-input-attributes.xsp Index: simple-input-attributes.xsp =================================================================== <?xml version="1.0"?> <?xml-stylesheet href="NULL" type="application/x-xsp"?> <xsp:page xmlns:xsp="http://www.apache.org/1999/XSP/Core" xmlns:demo="http://www.nsds.com/NS/xsp/demo/simple-input-attributes" indent-result="yes" > <html> <head><title>SimpleTaglib Input Attributes Demonstration</title></head> <body> <h1>SimpleTaglib Input Attributes Demonstration</h1> <h2>attrib</h2> <ol> <li><demo:attrib/></li> <li><demo:attrib parameter="value"/></li> </ol> <h2>child</h2> <ol> <li><demo:child/></li> <li> <demo:child> <demo:parameter>value</demo:parameter> </demo:child> </li> </ol> <h2>attribOrChild</h2> <ol> <li><demo:attribOrChild/></li> <li><demo:attribOrChild parameter="value"/></li> <li> <demo:attribOrChild> <demo:parameter>value</demo:parameter> </demo:attribOrChild> </li> <li> <demo:attribOrChild parameter="value1"> <demo:parameter>value2</demo:parameter> </demo:attribOrChild> </li> </ol> <h2>childStruct</h2> <ol> <li><demo:childStruct/></li> <li> <demo:childStruct> <demo:parameter>value</demo:parameter> </demo:childStruct> </li> <li> <demo:childStruct> <demo:parameter>value1</demo:parameter> <demo:parameter>value2</demo:parameter> </demo:childStruct> </li> </ol> <h2>attrib-or-childStruct</h2> <ol> <li><demo:attrib-or-childStruct/></li> <li><demo:attrib-or-childStruct parameter="value"/></li> <li> <demo:attrib-or-childStruct> <demo:parameter>value</demo:parameter> </demo:attrib-or-childStruct> </li> <li> <demo:attrib-or-childStruct parameter="value1"> <demo:parameter>value2</demo:parameter> </demo:attrib-or-childStruct> </li> <li> <demo:attrib-or-childStruct> <demo:parameter>value1</demo:parameter> <demo:parameter>value2</demo:parameter> </demo:attrib-or-childStruct> </li> </ol> <h2>captureContent</h2> <ol> <li><demo:captureContent/></li> <li><demo:captureContent>text content</demo:captureContent></li> <li> <demo:captureContent> text content </demo:captureContent> </li> </ol> <h2>captureContent-and-keepWhitespace</h2> <ol> <li><demo:captureContent-and-keepWhitespace/></li> <li><demo:captureContent-and-keepWhitespace>text content</demo:captureContent-and-keepWhitespace></li> <li> <demo:captureContent-and-keepWhitespace> text content </demo:captureContent-and-keepWhitespace> </li> </ol> <h2>complex-childStruct</h2> <pre> <complex-childStruct xmlns="http://www.nsds.com/NS/xsp/demo/simple-input-attributes"> <add> <permission type="user"> foo </permission> <permission> <type>group</type> bar </permission> <target>/test.html</target> <comment lang="en" day="Sun">Test entry</comment> <comment lang="en" day="Wed">Test entry 2</comment> <comment lang="de">Testeintrag</comment> </add> <remove target="/test2.html"> <permission type="user"> baz </permission> </remove> </complex-childStruct> </pre> </body> </html> </xsp:page> 1.37 +30 -8 xml-axkit/lib/AxKit.pm Index: AxKit.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/AxKit.pm,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- AxKit.pm 26 Jan 2003 17:37:42 -0000 1.36 +++ AxKit.pm 29 Jan 2003 01:35:49 -0000 1.37 @@ -674,10 +674,32 @@ my $interm_prefix; my $interm_count = 0; if ($AxKit::Cfg->TraceIntermediate) { - $interm_prefix = $r->uri; - $interm_prefix =~ s{/}{|}g; - $interm_prefix =~ s/[^0-9a-zA-Z.,_|-]/_/g; - $interm_prefix = $AxKit::Cfg->TraceIntermediate.'/'.$interm_prefix; + my $id = $r->notes('AxRequestID'); + $interm_prefix = ($id?$id:$r->uri); + $interm_prefix =~ s{%}{%25}g; + $interm_prefix =~ s{/}{%2f}g; + my $ti = $AxKit::Cfg->TraceIntermediate; + 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)); + mkdir($ti.'/'.substr($interm_prefix,0,4)); + mkdir($ti.'/'.$interm_prefix); + } else { + $interm_prefix =~ s/[^0-9a-zA-Z.,_|-]/_/g; + $interm_prefix .= '.'; + } + $interm_prefix = $ti.'/'.$interm_prefix; + + if ($interm_prefix) { + my $fh = Apache->gensym(); + if (sysopen($fh, $interm_prefix.$interm_count, O_WRONLY|O_CREAT|O_TRUNC)) { + syswrite($fh,${$provider->get_strref}); + close($fh); + $interm_count++; + } else { + AxKit::Debug(1,"could not open $interm_prefix$interm_count for writing: $!"); + } + } } while (@$styles) { @@ -731,7 +753,7 @@ if ($interm_prefix) { my $fh = Apache->gensym(); - if (sysopen($fh, $interm_prefix.'.'.$interm_count, O_WRONLY|O_CREAT|O_TRUNC)) { + if (open($fh, '>'.$interm_prefix.$interm_count)) { my $xmlstr; if ($AxKit::Cfg->DebugTidy) { eval { @@ -759,11 +781,11 @@ $xmlstr = "<?xml version='1.0'?>\n<empty reason='no data found'/>\n"; } } - syswrite($fh,$xmlstr); + print($fh $xmlstr); close($fh); $interm_count++; } else { - AxKit::Debug(1,"could not open $interm_prefix.$interm_count for writing: $!"); + AxKit::Debug(1,"could not open $interm_prefix$interm_count for writing: $!"); } } 1.11 +24 -11 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ConfigReader.pm 28 Jun 2002 01:26:01 -0000 1.10 +++ ConfigReader.pm 29 Jan 2003 01:35:49 -0000 1.11 @@ -40,7 +40,7 @@ # you may want to override this in your subclass if you write your own ConfigReader sub get_config { my $self = shift; - $self->{cfg} = _get_config($self->{apache}); + $self->{cfg} = _get_config($self->{apache}); } # sub DESTROY { @@ -65,6 +65,9 @@ $self->{cfg}->{CacheDir} || $self->{apache}->dir_config('AxCacheDir')) { + if (substr($cachedir,0,1) ne '/') { + $self->{cfg}->{CacheDir} = $cachedir = Apache->request()->document_root.'/'.$cachedir; + } return $cachedir; } @@ -160,6 +163,9 @@ if (my $dir = $self->{cfg}{TraceIntermediate} || $self->{apache}->dir_config('AxTraceIntermediate')) { return undef if $dir =~ m/^\s*(?:off|none|disabled?)\s*$/i; + if (substr($dir,0,1) ne '/') { + $self->{cfg}{TraceIntermediate} = $dir = Apache->request()->document_root.'/'.$dir; + } return $dir; } @@ -346,12 +352,19 @@ my $processors = $self->{apache}->dir_config('AxProcessors'); if( $processors ) { foreach my $processor (split(/\s*,\s*/, $processors) ) { - my ($pmedia, $pstyle, @processor) = split(/\s+/, $processor); - next unless ($pmedia eq $media and $pstyle eq $style); - push (@$list, [ 'NORMAL', @processor ] ); + my ($pmedia, $pstyle, @processor) = split(/\s+/, $processor); + next unless ($pmedia eq $media and $pstyle eq $style); + push (@$list, [ 'NORMAL', @processor ] ); } } + my @processors = $self->{apache}->dir_config->get('AxProcessor'); + foreach my $processor (@processors) { + my ($pmedia, $pstyle, @processor) = split(/\s+/, $processor); + next unless ($pmedia eq $media and $pstyle eq $style); + push (@$list, [ @processor ] ); + } + my @results; for my $directive (@$list) { @@ -361,25 +374,25 @@ href => $directive->[2], title => $style, }; - if ($type eq 'NORMAL') { + if (lc($type) eq 'normal') { push @results, $style_hash; } - elsif ($type eq 'DocType') { + elsif (lc($type) eq 'doctype') { if ($doctype eq $directive->[3]) { push @results, $style_hash; } } - elsif ($type eq 'DTD') { + elsif (lc($type) eq 'dtd') { if ($dtd eq $directive->[3]) { push @results, $style_hash; } } - elsif ($type eq 'Root') { + elsif (lc($type) eq 'root') { if ($root eq $directive->[3]) { push @results, $style_hash; } } - elsif ($type eq 'URI') { + elsif (lc($type) eq 'uri') { my $uri = $provider->apache_request->uri; if ($uri =~ /$directive->[3]/) { push @results, $style_hash; @@ -391,7 +404,7 @@ } # list any dynamically chosen stylesheets here - $list = $self->{cfg}{DynamicProcessors}; + $list = $self->{cfg}{DynamicProcessors} || [ $self->{apache}->dir_config->get('AxDynamicProcessors') ]; foreach my $package (@$list) { AxKit::load_module($package); no strict 'refs'; 1.4 +2 -2 xml-axkit/lib/Apache/AxKit/Exception.pm Index: Exception.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Exception.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Exception.pm 29 Jun 2002 22:10:05 -0000 1.3 +++ Exception.pm 29 Jan 2003 01:35:49 -0000 1.4 @@ -8,7 +8,7 @@ my $class = shift; my $self = $class->SUPER::new(@_); - if ($AxKit::Cfg->StackTrace) { + if ($AxKit::Cfg && $AxKit::Cfg->StackTrace) { my $i = $Error::Depth + 1; my ($pkg, $file, $line) = caller($i++); my @stacktrace; 1.16 +6 -2 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- LibXSLT.pm 8 Jan 2003 17:11:04 -0000 1.15 +++ LibXSLT.pm 29 Jan 2003 01:35:50 -0000 1.16 @@ -153,7 +153,7 @@ sub match_uri { my $uri = shift; AxKit::Debug(8, "LibXSLT match_uri: $uri"); - return 1 if $uri =~ /^axkit:/; + return 1 if $uri =~ /^(axkit|xmldb):/; return $uri !~ /^\w+:/; # only handle URI's without a scheme } @@ -163,6 +163,8 @@ if ($uri =~ /^axkit:/) { return AxKit::get_axkit_uri($uri); + } elsif ($uri =~ /^xmldb:/) { + return Apache::AxKit::Provider::XMLDB::get_xmldb_uri($uri); } # create a subrequest, so we get the right AxKit::Cfg for the URI @@ -188,6 +190,8 @@ if ($uri =~ /^axkit:/) { return AxKit::get_axkit_uri($uri); + } elsif ($uri =~ /^xmldb:/) { + return Apache::AxKit::Provider::XMLDB::get_xmldb_uri($uri); } # create a subrequest, so we get the right AxKit::Cfg for the URI 1.10 +3 -1 xml-axkit/lib/Apache/AxKit/Language/XPathScript.pm Index: XPathScript.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XPathScript.pm,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XPathScript.pm 26 Jan 2003 17:15:55 -0000 1.9 +++ XPathScript.pm 29 Jan 2003 01:35:50 -0000 1.10 @@ -326,6 +326,8 @@ my $newdoc; if ($uri =~ /^axkit:/) { $newdoc = $parser->parse( AxKit::get_axkit_uri($uri) ); + } elsif ($uri =~ /^xmldb:/) { + $newdoc = $parser->parse( Apache::AxKit::Provider::XMLDB::get_xmldb_uri($uri) ); } elsif ($uri =~ /^\w\w+:/) { # assume it's scheme://foo uri eval { 1.32 +14 -44 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.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- XSP.pm 28 Jan 2003 09:41:22 -0000 1.31 +++ XSP.pm 29 Jan 2003 01:35:50 -0000 1.32 @@ -106,16 +106,13 @@ if ($to_eval) { eval { require Perl::Tidy; - require IO::Scalar; AxKit::Debug(5,'Running PerlTidy...'); - my $temp_cache = Apache::AxKit::Cache->new($r, __PACKAGE__, 'PerlTidy'); - $temp_cache->{no_cache} = 0; - $temp_cache->write( $to_eval ); my $errors; + my $res; Perl::Tidy::perltidy( - source => $temp_cache->{file}, - destination => new Apache::AxKit::Language::XSP::StringWriter($to_eval), + source => \$to_eval, + destination => \$res, stderr => \$errors, argv => '-se -npro -f -nsyn -pt=2 -sbt=2 -csc -csce=2 -vt=1 -lp -cab=3 -iob'); if ($errors) { @@ -123,6 +120,7 @@ } else { AxKit::Debug(5,"PerlTidy successful"); } + $to_eval = $res; } if $AxKit::Cfg->DebugTidy; AxKit::Debug(1,"AxDebugTidy unavailable for Perl code: $@") if $@; @@ -132,8 +130,8 @@ $interm_prefix =~ s/[^0-9a-zA-Z.,_|-]/_/g; $interm_prefix = $AxKit::Cfg->TraceIntermediate.'/'.$interm_prefix; my $fh = Apache->gensym(); - if (sysopen($fh, $interm_prefix.'.XSP', O_WRONLY|O_CREAT|O_TRUNC)) { - syswrite($fh,$to_eval); + if (open($fh, '>'.$interm_prefix.'.XSP')) { + print($fh $to_eval); } else { AxKit::Debug(1,"could not open $interm_prefix.XSP for writing: $!"); } @@ -557,28 +555,6 @@ } } -# FIXME: can be removed when nsprefix stuff works okay -#sub generate_nsprefix { -# my ($e, $nsuri) = @_; -# -# unless ($e->{XSP_Random_Prefix}){ -# $e->{XSP_Random_Prefix} = join("",map { ('a'..'z','A'..'Z','0'..'9','-','_')[rand(64)] } 1..5 ); -# $e->{XSP_Random_Sequence} = "aaaa"; -# $e->{XSP_Random_Map} = {}; -# } -# -# my $nsprefix; -# if (exists $e->{XSP_Random_Map}{$nsuri}) { -# $nsprefix = $e->{XSP_Random_Map}{$nsuri}.$e->{XSP_Random_Prefix}; -# } -# else { -# $nsprefix = $e->{XSP_Random_Sequence}.$e->{XSP_Random_Prefix}; -# $e->{XSP_Random_Map}{$nsuri} = $e->{XSP_Random_Sequence}; -# $e->{XSP_Random_Sequence}++; -# } -# $nsprefix; -#} - ############################################################ # Functions implementing xsp:* processing ############################################################ @@ -835,14 +811,8 @@ "\n", ); $e->{XSP_User_Root} = 1; -# $code = '{ my $elem = $document->createElement(q(' . $node->{Name} . '));' . -# $code = '{ my $elem = $document->createElementNS(q(' . ($node->{NamespaceURI} || "") . '), q(' . $node->{Name} . '));' . if ($node->{NamespaceURI}) { -# FIXME: This seems to be okay now, needs more testing. -# if ($node->{Name} !~ m/:/) { -# $node->{Name} = $e->generate_nsprefix($node->{NamespaceURI}).':'.$node->{Name}; -# } $code = '$parent = __mk_ns_element_node($document, $parent, '. makeSingleQuoted($node->{NamespaceURI}).','. makeSingleQuoted($node->{Name}).");\n"; @@ -943,6 +913,7 @@ package AxKit::XSP::SAXParser; use XML::LibXML 1.30; +use XML::LibXML::Common qw(:libxml :encoding); sub new { my ($type, %self) = @_; @@ -985,7 +956,7 @@ sub match_uri { my $uri = shift; AxKit::Debug(8, "XSP match_uri: $uri"); - return 1 if $uri =~ /^axkit:/; + return 1 if $uri =~ /^(axkit|xmldb):/; return $uri !~ /^\w+:/; # only handle URI's without a scheme } @@ -995,6 +966,8 @@ if ($uri =~ /^axkit:/) { return AxKit::get_axkit_uri($uri); + } elsif ($uri =~ /^xmldb:/) { + return Apache::AxKit::Provider::XMLDB::get_xmldb_uri($uri); } # create a subrequest, so we get the right AxKit::Cfg for the URI @@ -1053,6 +1026,9 @@ } } } + elsif ($node_type == XML_XINCLUDE_START || $node_type == XML_XINCLUDE_END) { + # ignore + } else { warn("unknown node type: $node_type"); } @@ -1212,12 +1188,6 @@ way of providing an environment for dynamic pages. XSP is originally part of the Apache Cocoon project, and so you will see some Apache namespaces used in XSP. - -A warning to namespace users: Do not expect your namespace _prefixes_ to -come out of an XSP transformation as they were fed in. But since you are using -namespaces, this doesn't really matter. You just have to make sure that -each and every step in your transformation process is namespaces aware -and uses the correct namespace declarations. Also, use only one XSP processor in a pipeline. XSP is powerful enough that you should only need one stage, and this implementation allows only 1.7 +12 -4 xml-axkit/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm Index: SimpleTaglib.pm =================================================================== RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XSP/SimpleTaglib.pm,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SimpleTaglib.pm 13 Sep 2002 13:01:05 -0000 1.6 +++ SimpleTaglib.pm 29 Jan 2003 01:35:50 -0000 1.7 @@ -228,6 +228,14 @@ # companions to start_expr +sub start_expr { + my $e = shift; + my $cur = $e->{Current_Element}; + my $rc = $e->start_expr(@_); + $e->{Current_Element} = $cur; + return $rc; +} + sub start_elem { my ($e, $nodename, $attribs, $default_prefix, $default_ns) = @_; my($ns, $prefix, $name) = parse_namespace($nodename); @@ -629,10 +637,10 @@ $e->append_to_script('.') if ($globalframe[0]{'capture'}); $e->append_to_script('do { '); start_elem($e,$$handlerAttributes{'nodename'},$$handlerAttributes{'resultattr'},$element->{'Prefix'},$ns); - $e->start_expr($tag); + start_expr($e,$tag); } else { $e->append_to_script('.') if ($globalframe[0]{'capture'} && $element->{Parent}->{Name} =~ /^(.*:)?(logic|expr)$/); - $e->start_expr($tag); + start_expr($e,$tag); } foreach my $attrib (keys %{$$handlerAttributes{'attribs'}}) { @@ -715,7 +723,7 @@ $e->append_to_script('}; foreach my $_res (@_res) {'); start_elem($e,$$handlerAttributes{'nodename'},$$handlerAttributes{'resultattr'},$element->{'Prefix'},$ns); - $e->start_expr($$handlerAttributes{'nodename'}); + start_expr($e,$$handlerAttributes{'nodename'}); $e->append_to_script('$_res'); $e->end_expr(); end_elem($e);