cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erikjan Rijkers ...@xs4all.nl>
Subject Re: Cocoon & perl
Date Tue, 01 Aug 2000 09:55:14 GMT
Quoting Viktu Pons i Colomer <viktu@salleURL.edu>:

> My question is: How can I do to redirect the output of my perl scripts
> to cocoon, to make it translate to html or wml? Is it possible?


Here is one we made earlier. Don't expect to work because I simplified it 
without retriying it, but you'll get the idea. The script created a file with 
name "<username>.xml", then redirects toward it, and having cocoon kick in.

So, the important point is the CGI package and the statement 
   print $query->redirect( $gs_url );

#!C:\perl\bin\perl.exe	

use CGI qw(:standard) ;

$query 			= new CGI;

@params			= $query->param;
@values			= $query->param(@params[0]);
$gs_arg0		= @params[0]; $gs_val0		= @values[0];
$gs_arg1		= @params[1]; $gs_val1		= @values[1];

$gs_base		= "http://localhost/";

$ls_login 		= getlogin();
$ls_time 		= time();
$ls_basename	        = $ls_login;

$gs_file		= "c:\\website\\"	. $ls_basename . ".xml";
$gs_url			= $gs_base . "web/"	. $ls_basename . ".xml";

@a = split( /\//, $0 )

$ll = @a;

$gs_action		= $gs_base . "cgi-bin/" . @a[$ll-1];

$gs_form 		=
	"<form method=\"post\" action=\"$gs_action\" target=\"_self\">\n"
  .	"<input type=\"text\" name=\"arg0\" value=\"$gs_val0\"></input>\n"
  .	"<input type=\"submit\" value=\"retrieve\"></input>\n"
  .	"</form>\n\n" ;

generate_xml();

print $query->redirect( $gs_url );

print "</html>";

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub generate_xml {

	my($fh,$ls_file,$ls_arg0,$ls_arg1,$ls_sql,$ls_val1,$ls_order);

	$ls_file   = $gs_file	;

	$ls_sql    = "select * from sysobjects " ;
	$ls_sql   .= " where lower( name ) like '%" . $gs_val0 . "%' \n" ;

	open( FH, ">$ls_file" );	
	print FH "<?xml version=\"1.0\"?>\n";	
	print FH "<?cocoon-process type=\"sql\"?>\n";
	print FH "<?cocoon-process type=\"xslt\"?>\n";
	print FH "<?xml-stylesheet href=\"general.xsl\" type=\"text/xsl\"?>\n";
	print FH "<!DOCTYPE page [\n";
	print FH "	<!ENTITY cdefs SYSTEM 
\"http://localhost/cdefs/cdefs.sxml\">\n";
	print FH "]>\n";
	print FH "\n";
	print FH "<page>\n";
	print FH "\n";
	print FH "	&cdefs;\n";
	print FH "	\n";
	print FH "\n";
	print FH "	<title>dev server - $ls_sql</title>\n";
	print FH "\n";
	print FH $gs_form ;
	print FH "\n";
	print FH "	<query connection=\"sybase_connection\">\n";
	print FH "		$ls_sql\n";
	print FH "	</query>\n";
	print FH "\n";
	print FH "</page>\n";
	close (FH);
	
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Mime
View raw message