SmalltalkCodeGeneratorTool.st
changeset 9934 e8885f059bea
parent 9756 5a1787bbf85e
child 9935 5a0685d2ee90
equal deleted inserted replaced
9933:f7fda774209a 9934:e8885f059bea
  1061 
  1061 
  1062     nonMetaClass := aClass theNonMetaclass.
  1062     nonMetaClass := aClass theNonMetaclass.
  1063     metaClass := aClass theMetaclass.
  1063     metaClass := aClass theMetaclass.
  1064     className := nonMetaClass name.
  1064     className := nonMetaClass name.
  1065 
  1065 
  1066     (nonMetaClass includesSelector:#process:) ifFalse:[
  1066     (nonMetaClass includesSelector:#page1:) ifFalse:[
  1067         txt :=
  1067         txt :=
  1068 'process:aRequest
  1068 'page1:aRequest
  1069     "This is the web services main processing method.
  1069     "This is a sample page-generation method. 
  1070      It will be invoked for every incoming webBrowser-request.
  1070      This uses the simplest possible way to generate html: generating plain HTML. 
  1071      The argument, aRequest contains the parameters (url, fields, parameters etc.)."
  1071      See page2 for a more structured example."
  1072 
  1072 
  1073     |response|
  1073     |response|
  1074 
  1074 
  1075     response := aRequest response.
  1075     response := aRequest response.
  1076     response nextPutLine:''<HTML>''.
  1076     response nextPutLine:''<HTML>''.
  1083     response nextPutLine:''</HTML>''.
  1083     response nextPutLine:''</HTML>''.
  1084 '.
  1084 '.
  1085         self
  1085         self
  1086             compile:txt
  1086             compile:txt
  1087             forClass:nonMetaClass 
  1087             forClass:nonMetaClass 
       
  1088             inCategory:'response generation - pages'.
       
  1089     ].
       
  1090 
       
  1091     (nonMetaClass includesSelector:#page2:) ifFalse:[
       
  1092         txt :=
       
  1093 'page2:aRequest
       
  1094     "This is a sample page-generation method. 
       
  1095      This uses a slightly more convenient way to generate html: using an HTML tree builder. 
       
  1096      Event better examples to follow..."
       
  1097 
       
  1098     |page|
       
  1099 
       
  1100     page := HTML::TreeBuilder newDocument.
       
  1101     page
       
  1102         head;
       
  1103             title:''Hello'';
       
  1104         headEnd;
       
  1105         body;
       
  1106             h1:''Hello World'';
       
  1107             div;
       
  1108                 nlsText:''here is some text and '';
       
  1109                 a; href:''page3''; 
       
  1110                     text:''an anchor'';
       
  1111                 aEnd;
       
  1112                 text:'' and an image: '';
       
  1113                 img:(httpServer graphicLinkIdFor:(ToolbarIconLibrary smiley_cool) expirationTimeDelta:30 seconds);
       
  1114             divEnd;
       
  1115         bodyEnd.
       
  1116 
       
  1117     aRequest reply:(page htmlString).
       
  1118 '.
       
  1119         self
       
  1120             compile:txt
       
  1121             forClass:nonMetaClass 
       
  1122             inCategory:'response generation - pages'.
       
  1123     ].
       
  1124 
       
  1125     (nonMetaClass includesSelector:#page3:) ifFalse:[
       
  1126         txt :=
       
  1127 'page3:aRequest
       
  1128     "This is a sample page which generates plain text (i.e. nit html)."
       
  1129 
       
  1130     aRequest response
       
  1131         contentType:''text/plain'';
       
  1132         data:''This is some plain text,
       
  1133 without any html formatting.''
       
  1134 '.
       
  1135         self
       
  1136             compile:txt
       
  1137             forClass:nonMetaClass 
       
  1138             inCategory:'response generation - pages'.
       
  1139     ].
       
  1140 
       
  1141     (nonMetaClass includesSelector:#process:) ifFalse:[
       
  1142         txt :=
       
  1143 'process:aRequest
       
  1144     "This is the web services main processing method.
       
  1145      It will be invoked for every incoming webBrowser-request.
       
  1146      The argument, aRequest contains the parameters (url, fields, parameters etc.); browse HTTPRequest for details.
       
  1147      Its response object collects any returned html or other contents. Browse HTTPResponse for more info.
       
  1148 
       
  1149      Here, the simplest possible dipatch method is used: a hardcoded switch on the URL..."
       
  1150 
       
  1151     |whichPage|
       
  1152 
       
  1153     whichPage := aRequest pathRelativeToService.
       
  1154     "/ two example pages...
       
  1155     ( #( ''page1'' ''page2'' ''page3'' ) includes:whichPage ) ifTrue:[
       
  1156         self perform:(whichPage,'':'') asSymbol with:aRequest.
       
  1157         ^ self.
       
  1158     ].
       
  1159     aRequest reportNotFound:''No such page in this service''.
       
  1160 '.
       
  1161         self
       
  1162             compile:txt
       
  1163             forClass:nonMetaClass 
  1088             inCategory:'response generation'.
  1164             inCategory:'response generation'.
  1089     ].
  1165     ].
  1090 
  1166 
  1091     (metaClass includesSelector:#linkName) ifFalse:[
  1167     (metaClass includesSelector:#linkName) ifFalse:[
  1092         txt :=
  1168         txt :=
  1115     ].
  1191     ].
  1116 
  1192 
  1117 
  1193 
  1118     self executeCollectedChangesNamed:('Add WebService Code for ' , className).
  1194     self executeCollectedChangesNamed:('Add WebService Code for ' , className).
  1119 
  1195 
  1120     "Modified: / 1.2.1998 / 16:10:03 / cg"
  1196     "Modified: / 02-06-2011 / 12:39:27 / cg"
  1121 !
  1197 !
  1122 
  1198 
  1123 createWidgetCodeFor:aClass
  1199 createWidgetCodeFor:aClass
  1124     "create usually required widget code (redraw, model update, event handling)"
  1200     "create usually required widget code (redraw, model update, event handling)"
  1125 
  1201 
  2252 ! !
  2328 ! !
  2253 
  2329 
  2254 !SmalltalkCodeGeneratorTool class methodsFor:'documentation'!
  2330 !SmalltalkCodeGeneratorTool class methodsFor:'documentation'!
  2255 
  2331 
  2256 version_CVS
  2332 version_CVS
  2257     ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.3 2011-02-10 15:58:13 cg Exp $'
  2333     ^ '$Header: /cvs/stx/stx/libtool/SmalltalkCodeGeneratorTool.st,v 1.4 2011-06-02 10:40:29 cg Exp $'
  2258 ! !
  2334 ! !