KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
20
21 import org.apache.avalon.framework.parameters.ParameterException;
22 import org.apache.avalon.framework.parameters.Parameters;
23 import org.apache.cocoon.portal.PortalService;
24 import org.apache.cocoon.portal.layout.Item;
25 import org.apache.cocoon.portal.layout.Layout;
26 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
27 import org.apache.cocoon.xml.AttributesImpl;
28 import org.apache.cocoon.xml.XMLUtils;
29 import org.xml.sax.ContentHandler JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * Add several contents.
34  *
35  * <h2>Example XML:</h2>
36  * <pre>
37  * &lt;composite&gt;
38  * &lt;item param1="value1" param2="value2"&gt;
39  * &lt;!-- included content from following renderers for this item's layout--&gt;
40  * &lt;/item&gt;
41  * &lt;item&gt;
42  * &lt;!-- included content from following renderers for this item's layout--&gt;
43  * &lt;/item&gt;
44  * &lt;item param1="value1"&gt;
45  * &lt;!-- included content from following renderers for this item's layout--&gt;
46  * &lt;/item&gt;
47  * &lt;/composite&gt;
48  * </pre>
49  *
50  * <h2>Applicable to:</h2>
51  * <ul>
52  * <li>{@link org.apache.cocoon.portal.layout.CompositeLayout}</li>
53  * </ul>
54  *
55  * <h2>Parameters</h2>
56  * <table><tbody>
57  * <tr><th>root-tag</th><td><Enclose result in root tag?/td><td></td><td>boolean</td><td><code>true</code></td></tr>
58  * <tr><th>tag-name</th><td>Name of root tag to use.</td><td></td><td>String</td><td><code>"composite"</code></td></tr>
59  * </tbody></table>
60  *
61  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
62  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
63  *
64  * @version CVS $Id:CompositeContentAspect.java 30932 2004-07-29 17:35:38Z vgritsenko $
65  */

66 public class CompositeContentAspect extends AbstractCompositeAspect {
67
68     protected static final String JavaDoc ITEM_STRING = "item";
69
70     /* (non-Javadoc)
71      * @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)
72      */

73     public void toSAX(RendererAspectContext context,
74                         Layout layout,
75                         PortalService service,
76                         ContentHandler JavaDoc handler)
77     throws SAXException JavaDoc {
78         PreparedConfiguration config = (PreparedConfiguration)context.getAspectConfiguration();
79         if ( config.rootTag) {
80             XMLUtils.startElement(handler, config.tagName);
81         }
82         super.toSAX(context, layout, service, handler);
83         if ( config.rootTag) {
84             XMLUtils.endElement(handler, config.tagName);
85         }
86
87     }
88
89     /* (non-Javadoc)
90      * @see org.apache.cocoon.portal.layout.renderer.impl.AbstractContentAspect#processItem(org.apache.cocoon.portal.layout.Item, org.xml.sax.ContentHandler, org.apache.cocoon.portal.PortalService)
91      */

92     protected void processItem(Item item,
93                                  ContentHandler JavaDoc handler,
94                                  PortalService service)
95     throws SAXException JavaDoc {
96         Layout layout = item.getLayout();
97
98         Map JavaDoc parameters = item.getParameters();
99         if (parameters.size() == 0) {
100             XMLUtils.startElement(handler, ITEM_STRING);
101         } else {
102             AttributesImpl attributes = new AttributesImpl();
103
104             Map.Entry JavaDoc entry;
105             for (Iterator JavaDoc iter = parameters.entrySet().iterator(); iter.hasNext();) {
106                 entry = (Map.Entry JavaDoc) iter.next();
107                 attributes.addCDATAAttribute((String JavaDoc)entry.getKey(), (String JavaDoc)entry.getValue());
108             }
109             XMLUtils.startElement(handler, ITEM_STRING, attributes);
110         }
111         processLayout(layout, service, handler);
112         XMLUtils.endElement(handler, ITEM_STRING);
113
114     }
115
116     protected class PreparedConfiguration {
117         public String JavaDoc tagName;
118         public boolean rootTag;
119         
120         public void takeValues(PreparedConfiguration from) {
121             this.tagName = from.tagName;
122             this.rootTag = from.rootTag;
123         }
124     }
125     
126     /* (non-Javadoc)
127      * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
128      */

129     public Object JavaDoc prepareConfiguration(Parameters configuration)
130     throws ParameterException {
131         PreparedConfiguration pc = new PreparedConfiguration();
132         pc.tagName = configuration.getParameter("tag-name", "composite");
133         pc.rootTag = configuration.getParameterAsBoolean("root-tag", true);
134         return pc;
135     }
136
137 }
138
Popular Tags