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 da...@apache.org on 2002/02/18 19:36:21 UTC
cvs commit: xml-axkit/lib/Apache/AxKit/Language LibXSLT.pm XSP.pm
darobin 02/02/18 10:36:21
Modified: lib/Apache/AxKit Cache.pm
lib/Apache/AxKit/Language LibXSLT.pm XSP.pm
Log:
fixes from Joerg that make XSP.pm actually work, plus a few other things
Revision Changes Path
1.3 +2 -2 xml-axkit/lib/Apache/AxKit/Cache.pm
Index: Cache.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Cache.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Cache.pm 11 Feb 2002 14:49:17 -0000 1.2
+++ Cache.pm 18 Feb 2002 18:36:20 -0000 1.3
@@ -1,4 +1,4 @@
-# $Id: Cache.pm,v 1.2 2002/02/11 14:49:17 darobin Exp $
+# $Id: Cache.pm,v 1.3 2002/02/18 18:36:20 darobin Exp $
package Apache::AxKit::Cache;
use strict;
@@ -17,7 +17,7 @@
my ($r, $xmlfile, @extras) = @_;
my $gzip = 0;
- if ($xmlfile =~ /.gzip/) {
+ if ($xmlfile =~ /\.gzip/) {
$gzip++;
# @extras = grep(!/gzip/, @extras);
}
1.3 +3 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LibXSLT.pm 30 Jan 2002 18:17:21 -0000 1.2
+++ LibXSLT.pm 18 Feb 2002 18:36:20 -0000 1.3
@@ -1,4 +1,4 @@
-# $Id: LibXSLT.pm,v 1.2 2002/01/30 18:17:21 darobin Exp $
+# $Id: LibXSLT.pm,v 1.3 2002/02/18 18:36:20 darobin Exp $
package Apache::AxKit::Language::LibXSLT;
@@ -142,14 +142,13 @@
sub match_uri {
my $uri = shift;
-# warn("match: $uri\n");
AxKit::Debug(8, "LibXSLT match_uri: $uri");
return $uri !~ /^\w+:/; # only handle URI's without a scheme
}
sub open_uri {
- my $uri = shift;
-# warn("open: $uri\n");
+ my $uri = shift || './';
+ AxKit::Debug(8, "LibXSLT open_uri: $uri");
my $provider = Apache::AxKit::Provider->new(
AxKit::Apache->request(),
uri => $uri,
1.2 +110 -20 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XSP.pm 13 Jan 2002 20:45:11 -0000 1.1
+++ XSP.pm 18 Feb 2002 18:36:20 -0000 1.2
@@ -1,4 +1,4 @@
-# $Id: XSP.pm,v 1.1 2002/01/13 20:45:11 matts Exp $
+# $Id: XSP.pm,v 1.2 2002/02/18 18:36:20 darobin Exp $
package Apache::AxKit::Language::XSP;
@@ -195,6 +195,8 @@
return "Apache::AxKit::Language::XSP::ROOT$filename";
}
+sub makeSingleQuoted($) { $_ = shift; s/([\\|])/\\\1/g; 'q|'.$_.'|'; }
+
############################################################
# SAX Handler code
############################################################
@@ -718,6 +720,8 @@
package AxKit::XSP::DefaultHandler;
+*makeSingleQuoted = \&Apache::AxKit::Language::XSP::makeSingleQuoted;
+
sub start_element {
my ($e, $node) = @_;
@@ -731,24 +735,73 @@
"\n",
);
$e->{XSP_User_Root} = 1;
- $code = '{ my $elem = $document->createElement(q(' . $node->{Name} . '));' .
+# $code = '{ my $elem = $document->createElement(q(' . $node->{Name} . '));' .
# $code = '{ my $elem = $document->createElementNS(q(' . ($node->{NamespaceURI} || "") . '), q(' . $node->{Name} . '));' .
+
+ $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} = {};
+ if ($node->{NamespaceURI}) {
+ if ($node->{Name} !~ m/:/) {
+ if (exists $e->{XSP_Random_Map}{$node->{NamespaceURI}}) {
+ $node->{Name} = $e->{XSP_Random_Map}{$node->{NamespaceURI}}.$e->{XSP_Random_Prefix}.':'.$node->{Name};
+ }
+ else {
+ $node->{Name} = $e->{XSP_Random_Sequence}.$e->{XSP_Random_Prefix}.':'.$node->{Name};
+ $e->{XSP_Random_Map}{$node->{NamespaceURI}} = $e->{XSP_Random_Sequence};
+ $e->{XSP_Random_Sequence}++;
+ }
+ }
+ $code = '{ my $elem = $document->createElementNS('.makeSingleQuoted($node->{NamespaceURI}).','.makeSingleQuoted($node->{Name}).');' .
'$document->setDocumentElement($elem); $parent = $elem; }' . "\n";
+ }
+ else {
+ $code = '{ my $elem = $document->createElement('.makeSingleQuoted($node->{Name}).');' .
+ '$document->setDocumentElement($elem); $parent = $elem; }' . "\n";
+ }
}
else {
- $code = '{ my $elem = $document->createElement(q(' . $node->{Name} . '));' .
+# $code = '{ my $elem = $document->createElement(q(' . $node->{Name} . '));' .
+ if ($node->{NamespaceURI}) {
+ if ($node->{Name} !~ m/:/) {
+ if (exists $e->{XSP_Random_Map}{$node->{NamespaceURI}}) {
+ $node->{Name} = $e->{XSP_Random_Map}{$node->{NamespaceURI}}.$e->{XSP_Random_Prefix}.':'.$node->{Name};
+ }
+ else {
+ $node->{Name} = $e->{XSP_Random_Sequence}.$e->{XSP_Random_Prefix}.':'.$node->{Name};
+ $e->{XSP_Random_Map}{$node->{NamespaceURI}} = $e->{XSP_Random_Sequence};
+ $e->{XSP_Random_Sequence}++;
+ }
+ }
+ $code = '{ my $elem = $document->createElementNS('.makeSingleQuoted($node->{NamespaceURI}).','.makeSingleQuoted($node->{Name}).');' .
+ '$parent->appendChild($elem); $parent = $elem; }' . "\n";
+ }
+ else {
+ $code = '{ my $elem = $document->createElement('.makeSingleQuoted($node->{Name}).');' .
'$parent->appendChild($elem); $parent = $elem; }' . "\n";
+ }
}
for my $attr (@{$node->{Attributes}}) {
- $code .= '$parent->setAttribute(q(' . $attr->{Name} .
- '), q(' . $attr->{Value} .
- '));' . "\n";
+# $code .= '$parent->setAttribute(q(' . $attr->{Name} .
+# '), q(' . $attr->{Value} .
+# '));' . "\n";
+ $code .= '$parent->setAttribute('.makeSingleQuoted($attr->{Name}).
+ ','.makeSingleQuoted($attr->{Value}).');' . "\n";
}
for my $ns (keys %{$e->{Current_NS}}) {
- $code .= '$parent->setAttribute("xmlns:" . q(' . $ns .'), q(' .
- $e->{Current_NS}{$ns} . '));';
+# $code .= '$parent->setAttribute("xmlns:" . q(' . $ns .'), q(' .
+# $e->{Current_NS}{$ns} . '));';
+ if ($ns eq '#default') {
+ $code .= '$parent->setAttribute("xmlns",' .
+ makeSingleQuoted($e->{Current_NS}{$ns}) . ');';
+ }
+ else {
+ $code .= '$parent->setAttribute("xmlns:" . '.makeSingleQuoted($ns).',' .
+ makeSingleQuoted($e->{Current_NS}{$ns}) . ');';
+ }
+
}
push @{ $e->{NS_Stack} },
@@ -966,6 +1019,29 @@
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.
+
+=head2 Result Code
+
+You can specify the result code of the request in two ways. Both actions
+go inside a <xsp:logic> tag.
+
+If you want to completely abort the current request, throw an exception:
+
+ throw Apache::AxKit::Exception::Retval(return_code => FORBIDDEN);
+
+If you want to send your page but have a custom result code, return it:
+
+ return FORBIDDEN;
+
+In that case, only the part of the document that was processed so far gets
+sent/processed further.
+
+
=head1 Tag Reference
=head2 C<<xsp:page>>
@@ -1113,18 +1189,31 @@
thing". If it doesn't, then something (either a taglib or XSP.pm itself)
is broken and you should report a bug.
-=head1 DESIGN PATTERNS
+=head1 Writing Taglibs
Writing your own taglibs can be tricky, because you're using an event
based API to write out Perl code. You may want to take a look at the
Apache::AxKit::Language::XSP::TaglibHelper module, which comes with
AxKit and allows you to easily publish a taglib without writing
-XML event code.
+XML event code. Recently, another taglib helper has been developed,
+Apache::AxKit::Language::XSP::SimpleTaglib. The latter manages all the
+details described under 'Design Patterns' for you, so you don't really
+need to bother with them anymore.
+
+A warning about character sets: All string values are passed in and
+expected back as UTF-8 encoded strings. So you cannot use national characters
+in a different encoding, like the widespread ISO-8859-1. This applies to
+Taglib source code only. The XSP XML-source is of course interpreted according
+to the XML rules. Your taglib module may want to 'use utf8;' as well, see
+L<perlunicode> and L<utf8> for more information.
+
+=head1 Design Patterns
+
These patterns represent the things you may want to achieve when
authoring a tag library "from scratch".
-B<1. Your tag is a wrapper around other things.>
+=head2 1. Your tag is a wrapper around other things.
Example:
@@ -1156,7 +1245,7 @@
Note there the closing of that original opening block.
-B<2. Your tag indicates a parameter for a surrounding taglib.>
+=head2 2. Your tag indicates a parameter for a surrounding taglib.
Example:
@@ -1197,9 +1286,11 @@
All of this black magic allows other taglibs to set the thing in that
variable using expressions.
-B<3. You want your tag to return a scalar (string) that does the right thing
-depending on context. For example, generates a Text node in one place or
-generates a scalar in another context.>
+=head2 3. You want your tag to return a scalar (string) that does the right thing
+depending on context.
+
+For example, generates a Text node in one place or generates a scalar in another
+context.
Solution:
@@ -1284,7 +1375,7 @@
use Apache::AxKit::Language::XSP
qw(start_expr end_expr append_to_script);
-B<4. Your tag can take as an option either an attribute, or a child tag.>
+=head2 4. Your tag can take as an option either an attribute, or a child tag.
Example:
@@ -1339,8 +1430,7 @@
';
}
-B<5. You want to return a scalar that does the right thing in context, but
-also can take a parameter as an attribute I<or> a child tag.>
+=head2 5. You want to return a scalar that does the right thing in context, but also can take a parameter as an attribute I<or> a child tag.
Example:
@@ -1382,7 +1472,7 @@
return '';
}
-B<6. You have a conditional tag>
+=head2 6. You have a conditional tag
Example:
@@ -1407,7 +1497,7 @@
instead get handled by XSP core, thus creating text nodes (and doing
the right thing, generally).
-=head1 <xsp:expr> (and start_expr, end_expr) Notes
+=head2 <xsp:expr> (and start_expr, end_expr) Notes
B<Do not> consider adding in the 'do {' ... '}' bits yourself. Always
leave this to the start_expr, and end_expr functions. This is because the