01: package com.opensymphony.module.sitemesh.html;
02:
03: public class StateTransitionRule extends BasicRule {
04:
05: private final State newState;
06: private final boolean writeEnclosingTag;
07:
08: private State lastState;
09:
10: public StateTransitionRule(String tagName, State newState) {
11: this (tagName, newState, true);
12: }
13:
14: public StateTransitionRule(String tagName, State newState,
15: boolean writeEnclosingTag) {
16: super (tagName);
17: this .newState = newState;
18: this .writeEnclosingTag = writeEnclosingTag;
19: }
20:
21: public void process(Tag tag) {
22: if (tag.getType() == Tag.OPEN) {
23: lastState = context.currentState();
24: context.changeState(newState);
25: newState.addRule(this);
26: } else if (tag.getType() == Tag.CLOSE && lastState != null) {
27: context.changeState(lastState);
28: lastState = null;
29: }
30: if (writeEnclosingTag) {
31: tag.writeTo(context.currentBuffer());
32: }
33: }
34: }
|