# HG changeset patch # User Claus Gittinger # Date 1307011229 -7200 # Node ID e8885f059bea90fe89aa7e804940417539739f12 # Parent f7fda774209a141a63c61ddd99a05650e413280a changed: #createWebServiceCodeFor: better intitial examples diff -r f7fda774209a -r e8885f059bea SmalltalkCodeGeneratorTool.st --- a/SmalltalkCodeGeneratorTool.st Fri May 13 12:33:41 2011 +0200 +++ b/SmalltalkCodeGeneratorTool.st Thu Jun 02 12:40:29 2011 +0200 @@ -1063,12 +1063,12 @@ metaClass := aClass theMetaclass. className := nonMetaClass name. - (nonMetaClass includesSelector:#process:) ifFalse:[ + (nonMetaClass includesSelector:#page1:) ifFalse:[ txt := -'process:aRequest - "This is the web services main processing method. - It will be invoked for every incoming webBrowser-request. - The argument, aRequest contains the parameters (url, fields, parameters etc.)." +'page1:aRequest + "This is a sample page-generation method. + This uses the simplest possible way to generate html: generating plain HTML. + See page2 for a more structured example." |response| @@ -1085,6 +1085,82 @@ self compile:txt forClass:nonMetaClass + inCategory:'response generation - pages'. + ]. + + (nonMetaClass includesSelector:#page2:) ifFalse:[ + txt := +'page2:aRequest + "This is a sample page-generation method. + This uses a slightly more convenient way to generate html: using an HTML tree builder. + Event better examples to follow..." + + |page| + + page := HTML::TreeBuilder newDocument. + page + head; + title:''Hello''; + headEnd; + body; + h1:''Hello World''; + div; + nlsText:''here is some text and ''; + a; href:''page3''; + text:''an anchor''; + aEnd; + text:'' and an image: ''; + img:(httpServer graphicLinkIdFor:(ToolbarIconLibrary smiley_cool) expirationTimeDelta:30 seconds); + divEnd; + bodyEnd. + + aRequest reply:(page htmlString). +'. + self + compile:txt + forClass:nonMetaClass + inCategory:'response generation - pages'. + ]. + + (nonMetaClass includesSelector:#page3:) ifFalse:[ + txt := +'page3:aRequest + "This is a sample page which generates plain text (i.e. nit html)." + + aRequest response + contentType:''text/plain''; + data:''This is some plain text, +without any html formatting.'' +'. + self + compile:txt + forClass:nonMetaClass + inCategory:'response generation - pages'. + ]. + + (nonMetaClass includesSelector:#process:) ifFalse:[ + txt := +'process:aRequest + "This is the web services main processing method. + It will be invoked for every incoming webBrowser-request. + The argument, aRequest contains the parameters (url, fields, parameters etc.); browse HTTPRequest for details. + Its response object collects any returned html or other contents. Browse HTTPResponse for more info. + + Here, the simplest possible dipatch method is used: a hardcoded switch on the URL..." + + |whichPage| + + whichPage := aRequest pathRelativeToService. + "/ two example pages... + ( #( ''page1'' ''page2'' ''page3'' ) includes:whichPage ) ifTrue:[ + self perform:(whichPage,'':'') asSymbol with:aRequest. + ^ self. + ]. + aRequest reportNotFound:''No such page in this service''. +'. + self + compile:txt + forClass:nonMetaClass inCategory:'response generation'. ]. @@ -1117,7 +1193,7 @@ self executeCollectedChangesNamed:('Add WebService Code for ' , className). - "Modified: / 1.2.1998 / 16:10:03 / cg" + "Modified: / 02-06-2011 / 12:39:27 / cg" ! createWidgetCodeFor:aClass @@ -2254,5 +2330,5 @@ !SmalltalkCodeGeneratorTool class methodsFor:'documentation'! version_CVS - ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.3 2011-02-10 15:58:13 cg Exp $' + ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.4 2011-06-02 10:40:29 cg Exp $' ! !