1 16 package org.apache.cocoon.woody.formmodel; 17 18 import java.util.Locale ; 19 import java.util.Iterator ; 20 import org.apache.cocoon.woody.Constants; 21 import org.apache.cocoon.woody.FormContext; 22 import org.apache.cocoon.xml.AttributesImpl; 23 import org.xml.sax.ContentHandler ; 24 import org.xml.sax.SAXException ; 25 26 32 public abstract class AbstractContainerWidget extends AbstractWidget implements ContainerWidget { 33 protected ContainerDelegate widgets; 34 35 public AbstractContainerWidget(AbstractWidgetDefinition definition) { 36 setDefinition(definition); 37 setLocation(definition.getLocation()); 38 widgets = new ContainerDelegate(definition); 39 } 40 41 public void addWidget(Widget widget) { 42 widget.setParent(this); 43 widgets.addWidget(widget); 44 } 45 46 public boolean hasWidget(String id) { 47 return widgets.hasWidget(id); 48 } 49 50 public Widget getWidget(String id) { 51 return widgets.getWidget(id); 52 } 53 54 public Iterator getChildren() { 55 return widgets.iterator(); 56 } 57 58 public void readFromRequest(FormContext formContext) { 59 widgets.readFromRequest(formContext); 60 } 61 62 public boolean validate(FormContext formContext) { 63 if (widgets.validate(formContext)) { 65 return super.validate(formContext); 66 } else { 67 return false; 68 } 69 } 70 71 public void generateSaxFragment(ContentHandler contentHandler, Locale locale, String element) throws SAXException { 72 if (getId() == null || getId().equals("")) { 73 contentHandler.startElement(Constants.WI_NS, element, Constants.WI_PREFIX_COLON + element, Constants.EMPTY_ATTRS); 74 } else { 75 AttributesImpl attrs = new AttributesImpl(); 76 attrs.addCDATAAttribute("id", getFullyQualifiedId()); 77 contentHandler.startElement(Constants.WI_NS, element, Constants.WI_PREFIX_COLON + element, attrs); 78 } 79 if (definition != null) 80 definition.generateDisplayData(contentHandler); 81 widgets.generateSaxFragment(contentHandler, locale); 83 contentHandler.endElement(Constants.WI_NS, element, Constants.WI_PREFIX_COLON + element); 84 } 85 } 86 | Popular Tags |