import dk.brics.jwig.runtime.*;
public class PowerFreebie extends Service {
public class HowMany extends Session {
static final int MAX = 5;
XML templateAsk = [[
<html><head><title>PowerFreebie</title></head><body><form>
How many free T-shirts do you want?
<input name="amount" type="text"/>
<input name="continue" type="submit"/>
</form></body></html>
]];
XML templateReply = [[
<html><head><title>PowerFreebie</title></head><body>
You will receive <[amount]> k00l T-shirts any day now...
</body></html>
]];
XML format = [[
<powerforms xmlns="http://www.brics.dk/powerforms/2.0">
<constraint field="amount">
<match>
<interval low="1" high=[high]/>
</match>
</constraint>
</powerforms>
]];
public void main() {
show templateAsk powerforms format<[high=MAX];
int amount = Integer.parseInt(receive amount);
exit templateReply<[amount=amount];
}
}
}
|