1 16 package org.apache.cocoon.woody.formmodel; 17 18 import org.apache.cocoon.woody.FormContext; 19 import org.apache.cocoon.woody.Constants; 20 import org.apache.cocoon.woody.util.StringMessage; 21 import org.apache.excalibur.xml.sax.XMLizable; 22 import org.xml.sax.ContentHandler ; 23 import org.xml.sax.SAXException ; 24 25 import java.util.Locale ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 29 38 public class Messages extends AbstractWidget { 39 private ArrayList messages = new ArrayList (); 40 private MessagesDefinition definition; 41 42 private static final String MESSAGES_EL = "messages"; 43 private static final String MESSAGE_EL = "message"; 44 45 protected Messages(MessagesDefinition definition) { 46 this.definition = definition; 47 setLocation(definition.getLocation()); 48 } 49 50 public String getId() { 51 return definition.getId(); 52 } 53 54 public void readFromRequest(FormContext formContext) { 55 messages.clear(); 56 } 57 58 public boolean validate(FormContext formContext) { 59 return messages.size() == 0; 60 } 61 62 65 public void addMessage(String message) { 66 messages.add(new StringMessage(message)); 67 } 68 69 76 public void addMessage(XMLizable message) { 77 messages.add(message); 78 } 79 80 public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { 81 contentHandler.startElement(Constants.WI_NS, MESSAGES_EL, Constants.WI_PREFIX_COLON + MESSAGES_EL, Constants.EMPTY_ATTRS); 82 83 definition.generateDisplayData(contentHandler); 84 85 Iterator messagesIt = messages.iterator(); 86 while (messagesIt.hasNext()) { 87 XMLizable message = (XMLizable)messagesIt.next(); 88 contentHandler.startElement(Constants.WI_NS, MESSAGE_EL, Constants.WI_PREFIX_COLON + MESSAGE_EL, Constants.EMPTY_ATTRS); 89 message.toSAX(contentHandler); 90 contentHandler.endElement(Constants.WI_NS, MESSAGE_EL, Constants.WI_PREFIX_COLON + MESSAGE_EL); 91 } 92 93 contentHandler.endElement(Constants.WI_NS, MESSAGES_EL, Constants.WI_PREFIX_COLON + MESSAGES_EL); 94 } 95 96 public void generateLabel(ContentHandler contentHandler) throws SAXException { 97 definition.generateLabel(contentHandler); 98 } 99 } 100 | Popular Tags |