1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.core;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.TagSupport;
20 import org.apache.commons.jelly.XMLOutput;
21
22
23 /***
24 * A tag which conditionally evaluates its body if
25 * none of its preceeding sibling {@link CaseTag <case>}
26 * tags have been evaluated.
27 *
28 * This tag must be contained within the body of some
29 * {@link SwitchTag <switch>} tag.
30 *
31 * @see SwitchTag
32 *
33 * @author Rodney Waldhoff
34 * @version $Revision: 155420 $ $Date: 2005-02-26 14:06:03 +0100 (Sat, 26 Feb 2005) $
35 */
36 public class DefaultTag extends TagSupport {
37
38 public DefaultTag() {
39 }
40
41
42
43
44 public void setFallThru(boolean fallThru) {
45 this.fallThru = fallThru;
46 }
47
48 public void doTag(XMLOutput output) throws JellyTagException {
49 SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class);
50 if(null == tag) {
51 throw new JellyTagException("This tag must be enclosed inside a <switch> tag" );
52 }
53 if(tag.hasDefaultBeenEncountered()) {
54 throw new JellyTagException("Only one <default> tag is allowed per <switch>.");
55 }
56 tag.defaultEncountered();
57 if(tag.isFallingThru() || (!tag.hasSomeCaseMatched())) {
58 tag.caseMatched();
59 tag.setFallingThru(fallThru);
60 invokeBody(output);
61 }
62 }
63
64
65
66 private boolean fallThru = false;
67
68 }