KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.avalon.framework.service.ServiceException;
19 import org.apache.avalon.framework.service.ServiceSelector;
20 import org.apache.cocoon.portal.PortalService;
21 import org.apache.cocoon.portal.coplet.CopletInstanceData;
22 import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
23 import org.apache.cocoon.portal.layout.Layout;
24 import org.apache.cocoon.portal.layout.impl.CopletLayout;
25 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
26 import org.apache.cocoon.xml.IncludeXMLConsumer;
27 import org.apache.cocoon.xml.XMLUtils;
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31 /**
32  * This aspect directly invokes the coplet adapter to stream out the coplet content.
33  * An alternative solution is to generate only cinclude tags by using the
34  * {@link org.apache.cocoon.portal.layout.renderer.aspect.impl.CIncludeCopletAspect}
35  * and include the coplet contents later. That would allow caching up to the point
36  * of the cinclude transformer.
37  *
38  * <h2>Example XML:</h2>
39  * <pre>
40  * &lt;content&gt;
41  * &lt;!-- content streamed from coplet --&gt;
42  * &lt;/content&gt;
43  * </pre>
44  *
45  * <h2>Applicable to:</h2>
46  * <ul>
47  * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
48  * </ul>
49  *
50  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
51  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
52  *
53  * @version CVS $Id: DefaultCopletAspect.java 330865 2005-11-04 18:54:05Z rgoers $
54  */

55 public class DefaultCopletAspect extends AbstractAspect {
56
57     /* (non-Javadoc)
58      * @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)
59      */

60     public void toSAX(RendererAspectContext context,
61                         Layout layout,
62                         PortalService service,
63                         ContentHandler JavaDoc handler)
64     throws SAXException JavaDoc {
65
66         if (!(context.isRendering())) {
67             context.invokeNext(layout, service, handler);
68             return;
69         }
70
71         XMLUtils.startElement(handler, "content");
72         CopletInstanceData cid = ((CopletLayout)layout).getCopletInstanceData();
73
74         final String JavaDoc adapterName = cid.getCopletData().getCopletBaseData().getCopletAdapterName();
75         CopletAdapter copletAdapter = null;
76         ServiceSelector adapterSelector = null;
77         try {
78             adapterSelector = (ServiceSelector) this.manager.lookup(CopletAdapter.ROLE + "Selector");
79             copletAdapter = (CopletAdapter) adapterSelector.select(adapterName);
80             copletAdapter.toSAX(cid, new IncludeXMLConsumer(handler));
81         } catch (ServiceException ce) {
82             throw new SAXException JavaDoc("Unable to lookup component.", ce);
83         } finally {
84             if (null != copletAdapter) {
85                 adapterSelector.release(copletAdapter);
86             }
87             this.manager.release(adapterSelector);
88         }
89
90         XMLUtils.endElement(handler, "content");
91         context.invokeNext(layout, service, handler);
92     }
93
94 }
95
Popular Tags