W3C home > Mailing lists > Public > www-jigsaw@w3.org > September to October 1996

Re: SSIResource and PostableResource

From: Antoine Bertier <bertier@world-net.sct.fr>
Date: Wed, 23 Oct 1996 21:58:20 +0200
Message-Id: <199610231958.VAA24015@storm.certix.fr>
To: Antonio Ramirez <anto@MIT.EDU>
Cc: www-jigsaw@w3.org
At 23:58 18/10/1996 EDT, you wrote:
>
>Since SSIResource is not currently a subclass of PostableResource (and
>I'm not sure how that could be accomplished in a very straightforward
>way), you can only get data from a form by the following somewhat
>hackish procedure.
>
>The DefaultCommandRegistry initializes an SSI variable called formData
>whenever that it detects that a query or it detects a POST method
>with an appropriate content type. formData is an URLDecoder.
>
>So one of the commands you define could do this:
>
>Reply execute(....., Dictionary variables, ...) {
>
>    URLDecoder formData = (URLDecoder) variables.get("formData") ;
>
>    if(formData != null) {
>        // This means there is form data to use
>    } else {
>        // This means there isn't
>    }
>
>}
>
>Does this make sense?
>
>I have to admit that this "feature" was a sort of midnight hack and is
>not thoroughly tested (initially it didn't cross my mind that poeple
>would want to use the POST method on SSIResources...). If you have any
>problems with it, let me know and I'll fix it.
>
>Also, maybe this mechanism doesn't suit your needs at all.  In that
>case, please tell me what you need to do and I'll try to incorporate
>that into the SSIResource.
>
>Antonio.
>

Well I tried this and it seems to work ! And it certainly looks very useful.

My test is so simple that it may not look that useful, but I think it
demonstrates the feature. I added an UpperCommand which takes the name of an URL
parameter (i.e. a form field) and returns its value in upper case. 
MyCommandDirectory justs declares this new command (after stat from the
tutorial). The page upper.shtml contains a form with an 'input' field
and an 'output' field. The value of the output field is the result of the
upper command with input as parameter. The result of the upper command is
also displayed at the end of the page. (the code and page are appended to 
this message).

I must say I was quite impressed to get it to work so easily !!! 

Thanks a lot for your help,

Antoine.

------------------- UpperCommand.java --------------------
package w3c.jigsaw.tutorials ;

import java.util.* ;

import w3c.jigsaw.http.* ;
import w3c.www.http.HTTP ;
import w3c.jigsaw.ssi.* ;
import w3c.util.* ;
import w3c.jigsaw.forms.*;

public class UpperCommand implements Command {
    private static final String NAME = "upper" ;

    public final String getName()
    {
	return NAME ;
    }
    
    public Reply execute(SSIResource resource,
			  Request request,
			  ArrayDictionary parameters,
			  Dictionary variables)
    {
	// Get the parameter specifying the kind of statistic to emit.
	String data = (String) parameters.get("data") ;

        // if the parameter is not supplied, return "UPPER: NO PARAMETER"
        if (data == null) {
            Reply reply = resource.createCommandReply(request, HTTP.OK) ;
            reply.setContent("UPPER: NO PARAMETER");
            return reply ;
        }

        // now the parameter data contains the name of a field in the HTML form
        // first get the corresponding URL decoder
        URLDecoder formData = (URLDecoder) variables.get("formData");

        Reply reply = resource.createCommandReply(request, HTTP.OK) ;
        if ((formData == null) || (formData.getValue(data) == null)) {
            reply.setContent("UPPER: NO FIELD " + data);
        } else {
            reply.setContent(formData.getValue(data).toUpperCase());
        }
        return reply;
        
    }
}
-------------------------MyCommandRegistry.java -----------------------------
package w3c.jigsaw.tutorials ;

import w3c.jigsaw.ssi.* ;

public class MyCommandRegistry extends DefaultCommandRegistry {       
    public MyCommandRegistry()
    {
	registerCommand(new StatCommand()) ;
	registerCommand(new UpperCommand()) ;
    }
}
---------------------------upper.shtml---------------------------------------
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>Test for UpperCommand with SSI</title>
  </head>
  <body>
  <H1>Test for UpperCommand</H1>
  <FORM METHOD="POST" ACTION="upper.shtml">
  Input:<INPUT NAME="input"><P>
  <INPUT NAME="action" TYPE="submit" VALUE="Convert to UPPER case">
  <P>
  Output:<INPUT NAME="output" VALUE="<!--#upper data=input -->">
  </FORM>
  <HR>
  Output: <!--#upper data=input -->
  </body>
</html>
Antoine BERTIER
bertier@world-net.sct.fr
Received on Wednesday, 23 October 1996 16:04:54 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:25 GMT