KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > layout > renderer > aspect > impl > AbstractCompositeAspect


1 /*
2  * Copyright 1999-2002,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.portal.layout.renderer.aspect.impl;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.cocoon.portal.PortalService;
22 import org.apache.cocoon.portal.layout.CompositeLayout;
23 import org.apache.cocoon.portal.layout.Item;
24 import org.apache.cocoon.portal.layout.Layout;
25 import org.apache.cocoon.portal.layout.NamedItem;
26 import org.apache.cocoon.portal.layout.renderer.Renderer;
27 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31 /**
32  * Insert a composite layout's elements into the resulting XML. Elements (items)
33  * are processed in order. Concrete descendents of this class need to implement the
34  * actual handling of layout elements.
35  *
36  * <h2>Applicable to:</h2>
37  * <ul>
38  * <li>{@link org.apache.cocoon.portal.layout.CompositeLayout}</li>
39  * </ul>
40  *
41  *
42  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
43  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
44  *
45  * @version CVS $Id: AbstractCompositeAspect.java 331660 2005-11-08 01:22:30Z rgoers $
46  */

47 public abstract class AbstractCompositeAspect
48     extends AbstractAspect {
49
50     /* (non-Javadoc)
51      * @see org.apache.cocoon.portal.layout.renderer.RendererAspect#toSAX(org.apache.cocoon.portal.layout.renderer.RendererAspectContext, org.apache.cocoon.portal.layout.Layout, org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler)
52      */

53     public void toSAX(RendererAspectContext context,
54                         Layout layout,
55                         PortalService service,
56                         ContentHandler JavaDoc handler)
57     throws SAXException JavaDoc {
58         if ( layout instanceof CompositeLayout) {
59             CompositeLayout compositeLayout = (CompositeLayout)layout;
60             // loop over all rows
61
for (Iterator JavaDoc iter = compositeLayout.getItems().iterator(); iter.hasNext();) {
62                 Item item = (Item) iter.next();
63                 this.processItem(item, handler, service);
64             }
65         } else {
66             throw new SAXException JavaDoc("CompositeLayout expected.");
67         }
68     }
69
70     /**
71      * Process a single layout element.
72      *
73      * @param item layout item to be processed
74      * @param handler SAX handler taking events
75      * @param service portal service providing component access
76      * @throws SAXException
77      */

78     protected abstract void processItem(Item item, ContentHandler JavaDoc handler, PortalService service)
79         throws SAXException JavaDoc;
80
81     /**
82      * Default implementation for processing a Layout. Calls the associated
83      * renderer for a layout to render it.
84      */

85     protected void processLayout(Layout layout, PortalService service, ContentHandler JavaDoc handler) throws SAXException JavaDoc {
86         if ( layout != null ) {
87             final String JavaDoc rendererName = layout.getRendererName();
88             final Renderer renderer = service.getComponentManager().getRenderer(rendererName);
89             renderer.toSAX(layout, service, handler);
90         }
91     }
92 }
93
Popular Tags