01: /* Choose.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Sep 6 15:33:24 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.web.servlet.dsp.action;
20:
21: import java.io.StringWriter;
22: import java.io.Writer;
23: import java.io.IOException;
24:
25: import org.zkoss.web.mesg.MWeb;
26: import org.zkoss.web.servlet.ServletException;
27:
28: /**
29: * Provides the context for mutually exclusive conditional execution.
30: *
31: * @author tomyeh
32: */
33: public class Choose extends AbstractAction {
34: private boolean _matched, _trim = true;
35:
36: /** Returns whether any child {@link When} is evaluated to true. */
37: /*package*/boolean isMatched() {
38: return _matched;
39: }
40:
41: /** Sets whether any child {@link When} is evaluated to true. */
42: /*package*/void setMatched(boolean matched) {
43: _matched = matched;
44: }
45:
46: //-- Action --//
47: public void render(ActionContext ac, boolean nested)
48: throws javax.servlet.ServletException, IOException {
49: if (nested && isEffective()) {
50: if (_trim) {
51: final StringWriter sw = new StringWriter();
52: ac.renderFragment(sw);
53: ac.getOut().write(sw.toString().trim());
54: } else {
55: ac.renderFragment(null);
56: }
57: }
58: }
59:
60: //-- Object --//
61: public String toString() {
62: return "choose";
63: }
64: }
|