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 org.apache.avalon.framework.service.ServiceException;
20: import org.apache.avalon.framework.service.ServiceSelector;
21: import org.apache.cocoon.portal.PortalService;
22: import org.apache.cocoon.portal.coplet.CopletInstanceData;
23: import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
24: import org.apache.cocoon.portal.layout.Layout;
25: import org.apache.cocoon.portal.layout.impl.CopletLayout;
26: import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
27: import org.apache.cocoon.xml.IncludeXMLConsumer;
28: import org.apache.cocoon.xml.XMLUtils;
29: import org.xml.sax.ContentHandler;
30: import org.xml.sax.SAXException;
31:
32: /**
33: * This aspect directly invokes the coplet adapter to stream out the coplet content.
34: * An alternative solution is to generate only cinclude tags by using the
35: * {@link org.apache.cocoon.portal.layout.renderer.aspect.impl.CIncludeCopletAspect}
36: * and include the coplet contents later. That would allow caching up to the point
37: * of the cinclude transformer.
38: *
39: * <h2>Example XML:</h2>
40: * <pre>
41: * <content>
42: * <!-- content streamed from coplet -->
43: * </content>
44: * </pre>
45: *
46: * <h2>Applicable to:</h2>
47: * <ul>
48: * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
49: * </ul>
50: *
51: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
52: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
53: *
54: * @version CVS $Id: DefaultCopletAspect.java 433543 2006-08-22 06:22:54Z crossley $
55: */
56: public class DefaultCopletAspect extends AbstractAspect {
57:
58: /* (non-Javadoc)
59: * @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)
60: */
61: public void toSAX(RendererAspectContext context, Layout layout,
62: PortalService service, ContentHandler handler)
63: throws SAXException {
64:
65: if (!(context.isRendering())) {
66: context.invokeNext(layout, service, handler);
67: return;
68: }
69:
70: XMLUtils.startElement(handler, "content");
71: CopletInstanceData cid = ((CopletLayout) layout)
72: .getCopletInstanceData();
73:
74: final String adapterName = cid.getCopletData()
75: .getCopletBaseData().getCopletAdapterName();
76: CopletAdapter copletAdapter = null;
77: ServiceSelector adapterSelector = null;
78: try {
79: adapterSelector = (ServiceSelector) this .manager
80: .lookup(CopletAdapter.ROLE + "Selector");
81: copletAdapter = (CopletAdapter) adapterSelector
82: .select(adapterName);
83: copletAdapter.toSAX(cid, new IncludeXMLConsumer(handler));
84: } catch (ServiceException ce) {
85: throw new SAXException("Unable to lookup component.", ce);
86: } finally {
87: if (null != copletAdapter) {
88: adapterSelector.release(copletAdapter);
89: }
90: this .manager.release(adapterSelector);
91: }
92:
93: XMLUtils.endElement(handler, "content");
94: context.invokeNext(layout, service, handler);
95: }
96:
97: }
|