01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.formmodel;
18:
19: import java.util.Locale;
20: import java.util.Iterator;
21: import org.apache.cocoon.woody.Constants;
22: import org.apache.cocoon.woody.FormContext;
23: import org.apache.cocoon.xml.AttributesImpl;
24: import org.xml.sax.ContentHandler;
25: import org.xml.sax.SAXException;
26:
27: /**
28: * A general-purpose abstract Widget which can hold zero or more widgets.
29: *
30: * @author Timothy Larson
31: * @version $Id: AbstractContainerWidget.java 433543 2006-08-22 06:22:54Z crossley $
32: */
33: public abstract class AbstractContainerWidget extends AbstractWidget
34: implements ContainerWidget {
35: protected ContainerDelegate widgets;
36:
37: public AbstractContainerWidget(AbstractWidgetDefinition definition) {
38: setDefinition(definition);
39: setLocation(definition.getLocation());
40: widgets = new ContainerDelegate(definition);
41: }
42:
43: public void addWidget(Widget widget) {
44: widget.setParent(this );
45: widgets.addWidget(widget);
46: }
47:
48: public boolean hasWidget(String id) {
49: return widgets.hasWidget(id);
50: }
51:
52: public Widget getWidget(String id) {
53: return widgets.getWidget(id);
54: }
55:
56: public Iterator getChildren() {
57: return widgets.iterator();
58: }
59:
60: public void readFromRequest(FormContext formContext) {
61: widgets.readFromRequest(formContext);
62: }
63:
64: public boolean validate(FormContext formContext) {
65: // Validate self only if child widgets are valid
66: if (widgets.validate(formContext)) {
67: return super .validate(formContext);
68: } else {
69: return false;
70: }
71: }
72:
73: public void generateSaxFragment(ContentHandler contentHandler,
74: Locale locale, String element) throws SAXException {
75: if (getId() == null || getId().length() == 0) {
76: contentHandler.startElement(Constants.WI_NS, element,
77: Constants.WI_PREFIX_COLON + element,
78: Constants.EMPTY_ATTRS);
79: } else {
80: AttributesImpl attrs = new AttributesImpl();
81: attrs.addCDATAAttribute("id", getFullyQualifiedId());
82: contentHandler.startElement(Constants.WI_NS, element,
83: Constants.WI_PREFIX_COLON + element, attrs);
84: }
85: if (definition != null)
86: definition.generateDisplayData(contentHandler);
87: // The child widgets
88: widgets.generateSaxFragment(contentHandler, locale);
89: contentHandler.endElement(Constants.WI_NS, element,
90: Constants.WI_PREFIX_COLON + element);
91: }
92: }
|