KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > formmodel > AbstractContainerWidget


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.woody.formmodel;
17
18 import java.util.Locale JavaDoc;
19 import java.util.Iterator JavaDoc;
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 JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
25
26 /**
27  * A general-purpose abstract Widget which can hold zero or more widgets.
28  *
29  * @author Timothy Larson
30  * @version $Id: AbstractContainerWidget.java 30932 2004-07-29 17:35:38Z vgritsenko $
31  */

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 JavaDoc id) {
47         return widgets.hasWidget(id);
48     }
49
50     public Widget getWidget(String JavaDoc id) {
51         return widgets.getWidget(id);
52     }
53
54     public Iterator JavaDoc 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         // Validate self only if child widgets are valid
64
if (widgets.validate(formContext)) {
65             return super.validate(formContext);
66         } else {
67             return false;
68         }
69     }
70
71     public void generateSaxFragment(ContentHandler JavaDoc contentHandler, Locale JavaDoc locale, String JavaDoc element) throws SAXException JavaDoc {
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         // The child widgets
82
widgets.generateSaxFragment(contentHandler, locale);
83         contentHandler.endElement(Constants.WI_NS, element, Constants.WI_PREFIX_COLON + element);
84     }
85 }
86
Popular Tags