MODULEa form value is a link to another formHTTPControlValue EXPORTSHTTPControlValue ,Main ; IMPORT App, FloatMode, Fmt, HTTP, HTTPControl, Lex, Rd, Text, TextRd, TextExtras, Thread, Wr; <* PRAGMA LL *> REVEAL BooleanValue = BooleanValuePublic BRANDED "HTTPControlValue.BooleanValue" OBJECT OVERRIDES getText := BooleanGetText; get := BooleanGetNull; setText := BooleanSetText; set := BooleanSetNull; setDefault := BooleanSetDefault; writeFormItem := BooleanWriteFormItem; END; PROCEDUREBooleanGetText (self: BooleanValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN IF self.get(req) THEN RETURN "TRUE" ELSE RETURN "FALSE" END; END BooleanGetText; PROCEDUREBooleanSetText (self: BooleanValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN IF TextExtras.CIEqual("FALSE", v) THEN self.set(req, FALSE); ELSIF TextExtras.CIEqual("TRUE", v) THEN self.set(req, TRUE); ELSE log.log(Fmt.F("Bad value (%s) for boolean item: %s", v, self.label), App.LogStatus.Error); END; END BooleanSetText; PROCEDUREBooleanGetNull (<* UNUSED *> self: BooleanValue; <* UNUSED *> req : HTTP.Request ): BOOLEAN = BEGIN <* ASSERT FALSE *> END BooleanGetNull; PROCEDUREBooleanSetNull (<* UNUSED *> self: BooleanValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : BOOLEAN ) = BEGIN <* ASSERT FALSE *> END BooleanSetNull; PROCEDUREBooleanSetDefault (self: BooleanValue; req : HTTP.Request; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN self.set(req, FALSE); IF App.Verbose() THEN log.log(Fmt.F("setting default \"FALSE\" value: %s", self.label), App.LogStatus.Verbose); END; END BooleanSetDefault; PROCEDUREBooleanWriteFormItem (self: BooleanValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = VAR checked: TEXT; BEGIN TRY IF self.editable THEN IF self.get(req) THEN checked := "checked" ELSE checked := "" END; Wr.PutText( wr, Fmt.F( "%s <input type=checkbox name=%s value=true %s> %s %s<BR>\n", self.leader, self.id, checked, self.label, self.trailer)); ELSE Wr.PutText(wr, Fmt.F("%s %s: %s %s<BR>\n", self.leader, self.label, self.getText(req), self.trailer)); END; EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing boolean item to browser", App.LogStatus.Error); END; END BooleanWriteFormItem; REVEAL ChoiceValue = ChoiceValuePublic BRANDED "HTTPControlValue.ChoiceValue" OBJECT OVERRIDES init := ChoiceInit; getText := ChoiceGetText; get := ChoiceGetNull; setText := ChoiceSetText; set := ChoiceSetNull; setDefault := ChoiceSetDefault; writeFormItem := ChoiceWriteFormItem; END; PROCEDUREChoiceInit (self: ChoiceValue; READONLY names: ARRAY OF TEXT): ChoiceValue = BEGIN self.names := NEW(REF ARRAY OF TEXT, NUMBER(names)); self.names^ := names; RETURN self; END ChoiceInit; PROCEDUREChoiceGetText (self: ChoiceValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN RETURN self.names[self.get(req)]; END ChoiceGetText; PROCEDUREChoiceSetText (self: ChoiceValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN FOR i := 0 TO LAST(self.names^) DO IF Text.Equal(v, self.names[i]) THEN self.set(req, i, log); RETURN; END; END; log.log(Fmt.F("Bad value (%s) for choice item: %s", v, self.label), App.LogStatus.Error); END ChoiceSetText; PROCEDUREChoiceGetNull (<* UNUSED *> self: ChoiceValue; <* UNUSED *> req : HTTP.Request ): INTEGER = BEGIN <* ASSERT FALSE *> END ChoiceGetNull; PROCEDUREChoiceSetNull (<* UNUSED *> self: ChoiceValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : INTEGER; <* UNUSED *> log : App.Log ) = BEGIN <* ASSERT FALSE *> END ChoiceSetNull; PROCEDUREChoiceSetDefault (self: ChoiceValue; req : HTTP.Request; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN self.set(req, 0, log); IF App.Verbose() THEN log.log(Fmt.F("setting default %s choice value: %s", self.names[0], self.label), App.LogStatus.Verbose); END; END ChoiceSetDefault; PROCEDUREChoiceWriteFormItem (self: ChoiceValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = VAR selected := self.get(req); checked : TEXT; BEGIN TRY IF self.editable THEN Wr.PutText(wr, Fmt.F("%s %s: ", self.leader, self.label)); FOR i := 0 TO LAST(self.names^) DO IF i = selected THEN checked := "checked" ELSE checked := "" END; Wr.PutText( wr, Fmt.F("<input type=radio name=%s value=%s %s> %s \n", self.id, self.names[i], checked, self.names[i])); END; Wr.PutText(wr, Fmt.F(" %s<BR>", self.trailer)); ELSE Wr.PutText(wr, Fmt.F("%s %s: %s %s<BR>\n", self.leader, self.label, self.getText(req), self.trailer)); END; EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing choice item to browser", App.LogStatus.Error); END; END ChoiceWriteFormItem;
REVEAL FormValue = FormValuePublic BRANDED "HTTPControlValue.FormValue" OBJECT OVERRIDES init := FormValueInit; getText := FormGetText; get := FormGet; setText := FormSetText; set := FormSet; writeFormItem := FormWriteFormItem; END; PROCEDUREFormValueInit (self: FormValue; name, url: TEXT): FormValue = BEGIN self.name := name; self.url := url; RETURN self; END FormValueInit; PROCEDUREFormGetText (self: FormValue; <* UNUSED *> req: HTTP.Request): TEXT = BEGIN RETURN self.form.name() END FormGetText; PROCEDUREFormSetText (self: FormValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = VAR form := HTTPControl.FormLookup(v); BEGIN IF form # NIL THEN self.set(req, form); ELSE log.log(Fmt.F("no form with name: %s", v), App.LogStatus.Error); END; END FormSetText; PROCEDUREFormGet (self: FormValue; <* UNUSED *> req: HTTP.Request): HTTPControl.Form = BEGIN RETURN self.form; END FormGet; PROCEDUREFormSet ( self: FormValue; <* UNUSED *> req : HTTP.Request; v : HTTPControl.Form) = BEGIN self.form := v; END FormSet; PROCEDUREFormWriteFormItem ( self: FormValue; <* UNUSED *> req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error} = BEGIN TRY Wr.PutText( wr, Fmt.F("<A HREF=\"%s\">%s</A><BR>\n", self.url, self.name)); EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing form item to browser", App.LogStatus.Error); END; END FormWriteFormItem; REVEAL IntegerValue = IntegerValuePublic BRANDED "HTTPControlValue.IntegerValue" OBJECT OVERRIDES getText := IntegerGetText; get := IntegerGetNull; setText := IntegerSetText; set := IntegerSetNull; writeFormItem := IntegerWriteFormItem; END; PROCEDUREIntegerGetText (self: IntegerValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN RETURN Fmt.Int(self.get(req)); END IntegerGetText; PROCEDUREIntegerSetText (self: IntegerValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY self.set(req, Lex.Int(TextRd.New(v)), log) EXCEPT | Rd.Failure, Lex.Error, FloatMode.Trap, Thread.Alerted => log.log( Fmt.F("Bad integer value (%s) for field: %s", v, self.label), App.LogStatus.Error); END; END IntegerSetText; PROCEDUREIntegerGetNull (<* UNUSED *> self: IntegerValue; <* UNUSED *> req : HTTP.Request ): INTEGER = BEGIN <* ASSERT FALSE *> END IntegerGetNull; PROCEDUREIntegerSetNull (<* UNUSED *> self: IntegerValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : INTEGER; <* UNUSED *> log : App.Log ) = BEGIN <* ASSERT FALSE *> END IntegerSetNull; PROCEDUREIntegerWriteFormItem (self: IntegerValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY IF self.editable THEN Wr.PutText( wr, Fmt.F( "%s %s: <input type=text name=%s maxlength=1000 size=10 value=%s> %s<BR>\n", self.leader, self.label, self.id, self.getText(req), self.trailer)); ELSE Wr.PutText(wr, Fmt.F("%s %s: %s %s<BR>", self.leader, self.label, self.getText(req), self.trailer)); END; EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing iteger item to browser", App.LogStatus.Error); END; END IntegerWriteFormItem; REVEAL RealValue = RealValuePublic BRANDED "HTTPControlValue.RealValue" OBJECT OVERRIDES getText := RealGetText; get := RealGetNull; setText := RealSetText; set := RealSetNull; writeFormItem := RealWriteFormItem; END; PROCEDURERealGetText (self: RealValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN RETURN Fmt.Real(self.get(req)); END RealGetText; PROCEDURERealSetText (self: RealValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY self.set(req, Lex.Real(TextRd.New(v)), log) EXCEPT | Rd.Failure, Lex.Error, FloatMode.Trap, Thread.Alerted => log.log( Fmt.F("Bad integer value (%s) for field: %s", v, self.label), App.LogStatus.Error); END; END RealSetText; PROCEDURERealGetNull (<* UNUSED *> self: RealValue; <* UNUSED *> req : HTTP.Request): REAL = BEGIN <* ASSERT FALSE *> END RealGetNull; PROCEDURERealSetNull (<* UNUSED *> self: RealValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : REAL; <* UNUSED *> log : App.Log ) = BEGIN <* ASSERT FALSE *> END RealSetNull; PROCEDURERealWriteFormItem (self: RealValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY IF self.editable THEN Wr.PutText( wr, Fmt.F( "%s %s <input type=text name=%s maxlength=1000 size=10 value=%s> %s<BR>\n", self.leader, self.label, self.id, self.getText(req), self.trailer)); ELSE Wr.PutText(wr, Fmt.F("%s %s: %s %s<BR>", self.leader, self.label, self.getText(req), self.trailer)); END; EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing real item to browser", App.LogStatus.Error); END; END RealWriteFormItem; REVEAL TextValue = TextValuePublic BRANDED "HTTPControlValue.TextValue" OBJECT OVERRIDES getText := TextGetText; get := TextGetNull; setText := TextSetText; set := TextSetNull; writeFormItem := TextWriteFormItem; END; PROCEDURETextGetText (self: TextValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN RETURN self.get(req); END TextGetText; PROCEDURETextSetText (self: TextValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN self.set(req, HTTP.DecodeTextForHTML(v, log), log); END TextSetText; PROCEDURETextGetNull (<* UNUSED *> self: TextValue; <* UNUSED *> req : HTTP.Request): TEXT = BEGIN <* ASSERT FALSE *> END TextGetNull; PROCEDURETextSetNull (<* UNUSED *> self: TextValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : TEXT; <* UNUSED *> log : App.Log ) = BEGIN <* ASSERT FALSE *> END TextSetNull; PROCEDURETextWriteFormItem (self: TextValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY IF self.editable THEN IF self.scrollable THEN Wr.PutText(wr, Fmt.FN( "%s %s <TEXTAREA name=%s rows=%s cols=%s>%s</TEXTAREA>%s<BR>\n", ARRAY OF TEXT{ self.leader, self.label, self.id, Fmt.Int(self.rows), Fmt.Int(self.columns), HTTP.EncodeTextForHTML(self.getText(req)), self.trailer})); ELSE Wr.PutText(wr, Fmt.FN( "%s %s <input type=text name=\"%s\" maxlength=%s size=%s value=\"%s\"> %s<BR>\n", ARRAY OF TEXT{ self.leader, self.label, self.id, Fmt.Int(self.maxLength), Fmt.Int(self.size), HTTP.EncodeTextForHTML(self.getText(req)), self.trailer})); END; ELSE Wr.PutText(wr, Fmt.F("%s %s: %s %s", self.leader, self.label, HTTP.EncodeTextForHTML(self.getText(req)), self.trailer)); END; EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing text item to browser", App.LogStatus.Error); END; END TextWriteFormItem; REVEAL URLValue = URLValuePublic BRANDED "HTTPControlValue.URLValue" OBJECT url: TEXT; OVERRIDES init := URLInit; getText := URLGetText; get := URLGetNull; setText := URLSetText; set := URLSetNull; writeFormItem := URLWriteFormItem; END; PROCEDUREURLInit (self: URLValue; url: TEXT): URLValue = BEGIN self.url := url; RETURN self; END URLInit; PROCEDUREURLGetText (self: URLValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN RETURN self.get(req); END URLGetText; PROCEDUREURLSetText (self: URLValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN self.set(req, v, log); END URLSetText; PROCEDUREURLGetNull (self: URLValue; <* UNUSED *> req: HTTP.Request): TEXT = BEGIN RETURN self.url; END URLGetNull; PROCEDUREURLSetNull ( self: URLValue; <* UNUSED *> req : HTTP.Request; v : TEXT; <* UNUSED *> log : App.Log ) = BEGIN self.url := v; END URLSetNull; PROCEDUREURLWriteFormItem (self: URLValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY Wr.PutText( wr, Fmt.F("%s <A HREF=\"%s\">%s</A> %s<BR>\n", self.leader, self.getText(req), self.label, self.trailer)); EXCEPT | Wr.Failure, Thread.Alerted => log.log("Problem writing URL item to browser", App.LogStatus.Error); END; END URLWriteFormItem; REVEAL ImageValue = ImageValuePublic BRANDED "HTTPControlValue.ImageValue" OBJECT OVERRIDES getText := ImageGetText; get := ImageGetNull; setText := ImageSetText; set := ImageSetNull; writeFormItem := ImageWriteFormItem; END; PROCEDUREImageGetText (self: ImageValue; req: HTTP.Request): TEXT RAISES {HTTPControl.NotAuthorized} = BEGIN RETURN self.get(req).toText(); END ImageGetText; PROCEDUREImageSetText (self: ImageValue; req : HTTP.Request; v : TEXT; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN self.set(req, NEW(HTTP.URL).init(v, log), log); END ImageSetText; PROCEDUREImageGetNull (<* UNUSED *> self: ImageValue; <* UNUSED *> req : HTTP.Request): HTTP.URL = BEGIN <* ASSERT FALSE *> END ImageGetNull; PROCEDUREImageSetNull (<* UNUSED *> self: ImageValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : HTTP.URL; <* UNUSED *> log : App.Log ) = BEGIN <* ASSERT FALSE *> END ImageSetNull; PROCEDUREImageWriteFormItem (self: ImageValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY Wr.PutText( wr, Fmt.F("%s <IMG ALT=\"%s\" SRC=\"%s\"> %s<BR>\n", self.leader, self.label, self.getText(req), self.trailer)); EXCEPT | Wr.Failure, Thread.Alerted => log.log("Problem writing URL item to browser", App.LogStatus.Error); END; END ImageWriteFormItem; REVEAL TableValue = TableValuePublic BRANDED "HTTPControlValue.TableValue" OBJECT OVERRIDES getText := TableGetText; get := TableGet; setText := TableSetText; set := TableSet; setValues := TableSetValues; writeFormItem := TableWriteFormItem; END; PROCEDURETableGetText (<* UNUSED *> self: TableValue; <* UNUSED *> req : HTTP.Request): TEXT = BEGIN RETURN "<table>"; END TableGetText; PROCEDURETableSetText (<* UNUSED *> self: TableValue; <* UNUSED *> req : HTTP.Request; <* UNUSED *> v : TEXT; log : App.Log ) RAISES {App.Error} = BEGIN log.log("Cant set table text", App.LogStatus.Error); END TableSetText; PROCEDURETableGet (self: TableValue; <* UNUSED *> req: HTTP.Request): Table = BEGIN RETURN self.table; END TableGet; PROCEDURETableSet ( self : TableValue; <* UNUSED *> req : HTTP.Request; table: Table ) = BEGIN self.table := table; END TableSet; PROCEDURETableWriteFormItem (self: TableValue; req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = BEGIN TRY Wr.PutText( wr, Fmt.F("<TABLE BORDER><CAPTION>%s</CAPTION>\n", self.caption)); FOR i := 0 TO LAST(self.table^) DO Wr.PutText(wr, "<TR>"); FOR j := 0 TO LAST(self.table[i]^) DO Wr.PutText(wr, "<TH>"); self.table[i, j].writeFormItem(req, wr, log); END; Wr.PutText(wr, "\n"); END; Wr.PutText(wr, "</TABLE>"); EXCEPT | Wr.Failure, Thread.Alerted => log.log("Problem writing URL item to browser", App.LogStatus.Error); END; END TableWriteFormItem; PROCEDURETableSetValues (self : TableValue; req : HTTP.Request; query: HTTP.FormQuery; log : App.Log ) RAISES {App.Error, HTTPControl.NotAuthorized} = VAR field: HTTP.Field; value: HTTPControl.Value; BEGIN FOR i := 0 TO LAST(self.table^) DO FOR j := 0 TO LAST(self.table[i]^) DO value := self.table[i, j]; IF value.editable THEN field := query.lookupField(value.id); IF field = NIL THEN value.setDefault(req, log); ELSE value.setText(req, field.value, log); END; END; END; END; END TableSetValues; REVEAL MessageValue = MessageValuePublic BRANDED "HTTPControlValue.MessageValue" OBJECT msg: TEXT; OVERRIDES init := MessageInit; getText := MessageGetText; writeFormItem := MessageWriteFormItem; END; PROCEDUREMessageInit (self: MessageValue; msg: TEXT): MessageValue = BEGIN self.msg := msg; self.editable := FALSE; self.label := ""; self.id := ""; RETURN self; END MessageInit; PROCEDUREMessageGetText ( self: MessageValue; <* UNUSED *> req : HTTP.Request ): TEXT = BEGIN RETURN self.msg; END MessageGetText; PROCEDUREMessageWriteFormItem ( self: MessageValue; <* UNUSED *> req : HTTP.Request; wr : Wr.T; log : App.Log ) RAISES {App.Error} = BEGIN TRY Wr.PutText(wr, self.msg); EXCEPT | Wr.Failure, Thread.Alerted => log.log( "Problem writing boolean item to browser", App.LogStatus.Error); END; END MessageWriteFormItem; BEGIN END HTTPControlValue.