KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2002,2004-2005 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.parameters.ParameterException;
19 import org.apache.avalon.framework.parameters.Parameters;
20 import org.apache.cocoon.portal.PortalService;
21 import org.apache.cocoon.portal.coplet.CopletInstanceData;
22 import org.apache.cocoon.portal.layout.Layout;
23 import org.apache.cocoon.portal.layout.impl.CopletLayout;
24 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
25 import org.apache.cocoon.xml.XMLUtils;
26 import org.xml.sax.ContentHandler JavaDoc;
27 import org.xml.sax.SAXException JavaDoc;
28
29 /**
30  * This aspect streams a cinclude statement into the stream that
31  * will include the coplet using the coplet protocol.
32  *
33  * <h2>Resulting XML:</h2>
34  * <pre>
35  * &lt;content&gt;
36  * &lt;xy:z SRC="coplet://copletID"/&gt;
37  * &lt;/content&gt;
38  * </pre>
39  * where <code>xy</code> is the CInclude namespace and <code>z</code> is
40  * the CInclude tagname.
41  * By default, the cinclude statetement is surrounded by a "content" element;
42  * this can be further controlled by parameters (see below).
43  *
44  * <h2>Applicable to:</h2>
45  * <ul>
46  * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
47  * </ul>
48  *
49  * <h2>Parameters</h2>
50  * <table><tbody>
51  * <tr><th>root-tag</th><td>Should a tag enclosing the cinclude be generated? (Default is true)</td>
52  * <td></td><td>boolean</td><td><code>true</code></td></tr>
53  * <tr><th>tag-name</th><td>Name of enclosing tag.</td>
54  * <td></td><td>String</td><td><code>"content"</code></td></tr>
55  * </tbody></table>
56  *
57  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
58  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
59  *
60  * @version CVS $Id: CIncludeCopletAspect.java 330865 2005-11-04 18:54:05Z rgoers $
61  */

62 public class CIncludeCopletAspect
63     extends AbstractCIncludeAspect {
64
65     /* (non-Javadoc)
66      * @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)
67      */

68     public void toSAX(RendererAspectContext context,
69                         Layout layout,
70                         PortalService service,
71                         ContentHandler JavaDoc handler)
72     throws SAXException JavaDoc {
73         final PreparedConfiguration config = (PreparedConfiguration)context.getAspectConfiguration();
74         final CopletInstanceData cid = ((CopletLayout)layout).getCopletInstanceData();
75         if (!(context.isRendering())) {
76             context.invokeNext(layout, service, handler);
77         }
78         if ( config.rootTag) {
79             XMLUtils.startElement(handler, config.tagName);
80         }
81
82         this.createCInclude("coplet://" + cid.getId(), handler);
83
84         if ( config.rootTag) {
85             XMLUtils.endElement(handler, config.tagName);
86         }
87
88         context.invokeNext(layout, service, handler);
89     }
90
91     protected static class PreparedConfiguration {
92
93         public String JavaDoc tagName;
94         public boolean rootTag;
95         
96         public void takeValues(PreparedConfiguration from) {
97             this.tagName = from.tagName;
98             this.rootTag = from.rootTag;
99         }
100     }
101     
102     /* (non-Javadoc)
103      * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
104      */

105     public Object JavaDoc prepareConfiguration(Parameters configuration)
106     throws ParameterException {
107         PreparedConfiguration pc = new PreparedConfiguration();
108         pc.tagName = configuration.getParameter("tag-name", "content");
109         pc.rootTag = configuration.getParameterAsBoolean("root-tag", true);
110         return pc;
111     }
112     
113 }
114
Popular Tags