Hello everyone, I am working on a taglib to access the Swish-e search functions and am having a hard time figuring out how to pass tags to the subs and get the result back out to the pipeline in a proper xml format. I have a version of the taglib that works but was told by experts that it broke the design patterns for AxKit because I accessed and manipulated the document directly via createElement calls, etc...
Here is the XSP page that calls the taglib: <?xml version="1.0"?> <?xml-stylesheet type="application/x-xsp" href="."?> <xsp:page xmlns:xsp="http://apache.org/xsp/core/v1" xmlns:swish="http://nexus-is.ca/NS/xsp/swish/v1" language="Perl" > <page> <xsp:logic> <swish:send-query> <swish:index>./nexus.swish</swish:index> <swish:title>a search</swish:title> <swish:query>suexec</swish:query> <swish:props></swish:props> <swish:sort></swish:sort> <swish:context>1</swish:context> <swish:limit></swish:limit> </swish:send-query> </xsp:logic> </page> </xsp:page> Here is the current , not working or completed, TagHelper based taglib and after that, the working one that is not properly coded for reference. package AxKit::XSP::Swish; @ISA = ('Apache::AxKit::Language::XSP::TaglibHelper'); # Swish-e Taglib $NS = 'http://nexus-is.ca/NS/xsp/swish/v1'; @EXPORT_TAGLIB = ( 'send_query($index,$query;$title,$props,$sort,$context,$limit)', ); use vars qw/@ISA $NS @EXPORT_TAGLIB/; # libs and prototypes use strict; use SWISHE; use Apache::AxKit::Language::XSP::TaglibHelper; sub parse_char { Apache::AxKit::Language::XSP::TaglibHelper::parse_char(@_); } sub parse_start { Apache::AxKit::Language::XSP::TaglibHelper::parse_start(@_); } sub parse_end { Apache::AxKit::Language::XSP::TaglibHelper::parse_end(@_); } ## Taglib subs sub send_query ($$;$$$$$) { my ($index,$title,$query,$props,$sort,$context,$limit) = @_; die "No index file provided" unless $index; my $handle = SwishOpen( $index ) or die "Failed to open index $index"; # Use an array for a hash slice when reading results. See SwishNext below. my @labels = qw/ rank file_name title content_length /; # Here's the actual query if ( $limit ) { SetLimitParameter( $handle, ,$limit); } my $num_results = SwishSearch( $handle, $query, $context, $props, $sort, ); unless ( $num_results ) { my $error = SwishError( $handle ); SwishClose ($handle); return "Error: $error, No Results\n"; } my %result; my @properties = split /\s+/, $props; my %props; while ( ( @result{ @labels }, @props{@properties} ) = SwishNext( $handle )) { # for ( @labels ) { # $_; # $result{$_}; # for ( @properties ) { # $_; # $props{$_}; #} } # Free the memory. SwishClose( $handle ); return { #search-results => { #search-record => [ %result ], %result # } } } 1; ============================================== Working taglib: package AxKit::XSP::Swish; use strict; use Apache::AxKit::Language::XSP; use SWISHE; use vars qw/@ISA $NS $VERSION/; @ISA = ('Apache::AxKit::Language::XSP'); $NS = 'http://nexus-is.ca/NS/xsp/swish/v1'; $VERSION = "1.0"; ## Taglib subs sub send_query { my ($parent, $document, $query_args) = @_; #print ${$document}; #print %{$query_args}; die "No index file provided" unless $query_args->{'index'}; my $handle = SwishOpen( $query_args->{'index'} ) or die "Failed to open index $query_args->{'index'}"; # Use an array for a hash slice when reading results. See SwishNext below. my @labels = qw/ rank file_name title content_length /; # Here's the actual query if ( $query_args->{'limit'} ) { print "limiting to $query_args->{'limit'}}\n\n"; SetLimitParameter( $handle, ,$query_args->{'limit'}); } my $num_results = SwishSearch( $handle, $query_args->{'query'}, $query_args->{'context'}, $query_args->{'props'}, $query_args->{'sort'} ); unless ( $num_results ) { my $error = SwishError( $handle ); SwishClose ($handle); return "Error: $error, No Results\n"; } my %result; my @properties = split /\s+/, $query_args->{'props'}; my %props; my $return_val; { my $elem = $document->createElement(q|search-results|);$document->setDocumentElement($e lem); $parent = $elem; } while ( ( @result{ @labels }, @props{@properties} ) = SwishNext( $handle )) { for ( @labels ) { { my $elem = $document->createElement(qq|$_|);$parent->appendChild($elem); $parent = $elem; } { my $text = $document->createTextNode(qq|$result{$_}|);$parent->appendChild($text); } $parent = $parent->getParentNode; } for ( @properties ) { { my $elem = $document->createElement(qq|$_|);$parent->appendChild($elem); $parent = $elem; } { my $text = $document->createTextNode(qq|$props{$_}|);$parent->appendChild($text); } $parent = $parent->getParentNode; } } $parent = $parent->getParentNode; # Free the memory. SwishClose( $handle ); } ## Parser subs sub parse_start { my ($e, $tag, %attribs) = @_; #warn "Checking: $tag\n"; if ($tag eq 'send-query') { return qq| {# start swish search code\n | . q| my (%query_args);| . qq|\n|; } elsif ($tag eq 'index') { return q| $query_args{'index'} = ''|; } elsif ($tag eq 'title') { return q| $query_args{'title'} = ''|; } elsif ($tag eq 'query') { return q| $query_args{'query'} = ''|; } elsif ($tag eq 'props') { return q| $query_args{'props'} = ''|; } elsif ($tag eq 'sort') { return q| $query_args{'sort'} = ''|; } elsif ($tag eq 'context') { return q| $query_args{'context'} = ''|; } elsif ($tag eq 'limit') { return q| $query_args{'limit'} = ''|; } else { die "Unknown Swish tag: $tag"; } } sub parse_char { my ($e, $text) = @_; $text =~ s/^\s*//; $text =~ s/\s*$//; return '' unless $text; $text = Apache::AxKit::Language::XSP::makeSingleQuoted($text); return ". $text"; } sub parse_end { my ($e, $tag) = @_; if ($tag eq 'send-query') { return <<'EOF'; AxKit::XSP::Swish::send_query( $parent,$document, { %query_args }, ); } # end swish code EOF } return ";"; } sub parse_comment { } sub parse_final { } 1; Can anyone tell me which of the two helpers that I should use OR is the original taglib salvageable? Also, if I use an helper, what am I doing wrong with it because it dies when it tries to access the params! Thanks and I will post the final result to the group ! ----------------------------------------------------------- Fran�ois Machab�e Nexus Informatique & Marketing Inc. Email: [EMAIL PROTECTED] WWW: http://www.nexus-is.ca --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
