1 package com.opensymphony.module.sitemesh.html; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 public class State { 8 9 private final List rules = new ArrayList (); 10 private final ArrayList listeners = new ArrayList (); 11 12 public void addRule(TagRule rule) { 13 rules.add(rule); 14 } 15 16 public boolean shouldProcessTag(String tagName) { 17 for (Iterator iterator = rules.iterator(); iterator.hasNext();) { 18 TagRule tagRule = (TagRule) iterator.next(); 19 if (tagRule.shouldProcess(tagName)) { 20 return true; 21 } 22 } 23 return false; 24 } 25 26 public TagRule getRule(String tagName) { 27 for (Iterator iterator = rules.iterator(); iterator.hasNext();) { 28 TagRule tagRule = (TagRule) iterator.next(); 29 if (tagRule.shouldProcess(tagName)) { 30 return tagRule; 31 } 32 } 33 return null; 34 } 35 36 public void addListener(StateChangeListener listener) { 37 listeners.add(listener); 38 } 39 40 public void endOfState() { 41 for (Iterator iter = listeners.iterator(); iter.hasNext();) { 42 StateChangeListener listener = (StateChangeListener) iter.next(); 43 listener.stateFinished(); 44 } 45 } 46 47 } 48 | Popular Tags |