1 package com.opensymphony.module.sitemesh.html; 2 3 public class StateTransitionRule extends BasicRule { 4 5 private final State newState; 6 private final boolean includeEnclosingTags; 7 8 private State lastState; 9 10 public StateTransitionRule(String tagName, State newState, boolean includeEnclosingTags) { 11 super(tagName); 12 this.newState = newState; 13 this.includeEnclosingTags = includeEnclosingTags; 14 } 15 16 public void process(Tag tag) { 17 if (tag.getType() == Tag.OPEN) { 18 lastState = context.currentState(); 19 context.changeState(newState); 20 newState.addRule(this); 21 } else if (tag.getType() == Tag.CLOSE && lastState != null) { 22 context.changeState(lastState); 23 lastState = null; 24 } 25 if (includeEnclosingTags) { 26 tag.writeTo(context.currentBuffer()); 27 } 28 } 29 } 30 | Popular Tags |