KickJava   Java API By Example, From Geeks To Geeks.

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


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.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  * Create a title tag for a coplet as well as an optional enclosing tag.
31  *
32  * <h2>Example XML:</h2>
33  * <pre>
34  * &lt;window&gt;
35  * &lt;title&gt;title&lt;/title&gt;
36  * &lt;/window&gt;
37  * </pre>
38  *
39  *
40  * <h2>Applicable to:</h2>
41  * <ul>
42  * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
43  * </ul>
44  *
45  * <h2>Parameters</h2>
46  * <table><tbody>
47  * <tr><th>root-tag</th><td>Should a tag enclosing the following output be generated?</td>
48  * <td></td><td>boolean</td><td><code>true</code></td></tr>
49  * <tr><th>tag-name</th><td>Name of tag enclosing follwoing output if requested.</td>
50  * <td></td><td>String</td><td><code>"window"</code></td></tr>
51  * </tbody></table>
52  *
53  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
54  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
55  *
56  * @version CVS $Id: WindowAspect.java 331660 2005-11-08 01:22:30Z rgoers $
57  */

58 public final class WindowAspect extends AbstractAspect {
59
60     /* (non-Javadoc)
61      * @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)
62      */

63     public void toSAX(RendererAspectContext context,
64                         Layout layout,
65                         PortalService service,
66                         ContentHandler JavaDoc contenthandler)
67     throws SAXException JavaDoc {
68         final PreparedConfiguration config = (PreparedConfiguration)context.getAspectConfiguration();
69         final CopletInstanceData copletInstanceData = ((CopletLayout)layout).getCopletInstanceData();
70
71         if ( config.rootTag ) {
72             XMLUtils.startElement(contenthandler, config.tagName);
73         }
74         XMLUtils.createElement(contenthandler, "title", copletInstanceData.getTitle());
75         XMLUtils.createElement(contenthandler , "instance-id", copletInstanceData.getId());
76
77         context.invokeNext( layout, service, contenthandler );
78
79         if ( config.rootTag ) {
80             XMLUtils.endElement(contenthandler, config.tagName);
81         }
82     }
83
84     protected static class PreparedConfiguration {
85         public String JavaDoc tagName;
86         public boolean rootTag;
87         
88         public void takeValues(PreparedConfiguration from) {
89             this.tagName = from.tagName;
90             this.rootTag = from.rootTag;
91         }
92     }
93     
94     /* (non-Javadoc)
95      * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
96      */

97     public Object JavaDoc prepareConfiguration(Parameters configuration)
98     throws ParameterException {
99         PreparedConfiguration pc = new PreparedConfiguration();
100         pc.tagName = configuration.getParameter("tag-name", "window");
101         pc.rootTag = configuration.getParameterAsBoolean("root-tag", true);
102         return pc;
103     }
104
105 }
106
Popular Tags