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.portal.layout.renderer.aspect.impl;
18:
19: import java.util.Iterator;
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.renderer.Renderer;
26: import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
27: import org.xml.sax.ContentHandler;
28: import org.xml.sax.SAXException;
29:
30: /**
31: * Insert a composite layout's elements into the resulting XML. Elements (items)
32: * are processed in order. Concrete descendents of this class need to implement the
33: * actual handling of layout elements.
34: *
35: * <h2>Applicable to:</h2>
36: * <ul>
37: * <li>{@link org.apache.cocoon.portal.layout.CompositeLayout}</li>
38: * </ul>
39: *
40: *
41: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
42: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
43: *
44: * @version CVS $Id: AbstractCompositeAspect.java 433543 2006-08-22 06:22:54Z crossley $
45: */
46: public abstract class AbstractCompositeAspect extends AbstractAspect {
47:
48: /**
49: * @see org.apache.cocoon.portal.layout.renderer.aspect.impl.AbstractAspect#toSAX(org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext, org.apache.cocoon.portal.layout.Layout, org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler)
50: */
51: public void toSAX(RendererAspectContext context, Layout layout,
52: PortalService service, ContentHandler handler)
53: throws SAXException {
54: if (layout instanceof CompositeLayout) {
55: CompositeLayout compositeLayout = (CompositeLayout) layout;
56: // loop over all rows
57: for (Iterator iter = compositeLayout.getItems().iterator(); iter
58: .hasNext();) {
59: Item item = (Item) iter.next();
60: this .processItem(context, item, handler, service);
61: }
62: } else {
63: throw new SAXException("CompositeLayout expected.");
64: }
65: }
66:
67: /**
68: * Process a single layout element.
69: *
70: * @param item layout item to be processed
71: * @param handler SAX handler taking events
72: * @param service portal service providing component access
73: * @throws SAXException
74: */
75: protected abstract void processItem(RendererAspectContext context,
76: Item item, ContentHandler handler, PortalService service)
77: throws SAXException;
78:
79: /**
80: * Default implementation for processing a Layout. Calls the associated
81: * renderer for a layout to render it.
82: */
83: protected void processLayout(Layout layout, PortalService service,
84: ContentHandler handler) throws SAXException {
85: if (layout != null) {
86: final String rendererName = layout.getRendererName();
87: final Renderer renderer = service.getComponentManager()
88: .getRenderer(rendererName);
89: renderer.toSAX(layout, service, handler);
90: }
91: }
92: }
|