KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-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.Collections JavaDoc;
19 import java.util.Iterator 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.aspect.impl.DefaultAspectDescription;
25 import org.apache.cocoon.portal.layout.Layout;
26 import org.apache.cocoon.portal.layout.impl.FrameLayout;
27 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31 /**
32  * Adds a cinclude tag for a FrameLayout's source to the resulting stream.
33  *
34  * <h2>Example XML:</h2>
35  * <pre>
36  * &lt;xy:z SRC="coplet://copletID"/&gt;
37  * </pre>
38  *
39  * <h2>Applicable to:</h2>
40  * <ul>
41  * <li>{@link org.apache.cocoon.portal.layout.impl.FrameLayout}</li>
42  * </ul>
43  *
44  * <h2>Parameters</h2>
45  * <table><tbody>
46  * <tr><th>aspect-name</th><td></td><td></td><td>String</td><td><code>"frame"</code></td></tr>
47  * <tr><th>store</th><td></td><td>req</td><td>String</td><td><code>null</code></td></tr>
48  * </tbody></table>
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: FrameAspect.java 124685 2005-01-08 22:20:56Z antonio $
54  */

55 public class FrameAspect extends AbstractCIncludeAspect {
56
57     public void toSAX(RendererAspectContext context, Layout layout, PortalService service, ContentHandler JavaDoc handler)
58     throws SAXException JavaDoc {
59         PreparedConfiguration config = (PreparedConfiguration)context.getAspectConfiguration();
60
61         if (!(layout instanceof FrameLayout)) {
62             throw new SAXException JavaDoc("Wrong layout type, FrameLayout expected: " + layout.getClass().getName());
63         }
64
65         String JavaDoc source = (String JavaDoc)layout.getAspectData(config.aspectName);
66         if (source == null) {
67             source = ((FrameLayout) layout).getSource();
68         }
69         
70         this.createCInclude(source, handler);
71     }
72
73     protected static class PreparedConfiguration {
74         public String JavaDoc aspectName;
75         public String JavaDoc store;
76         
77         public void takeValues(PreparedConfiguration from) {
78             this.aspectName = from.aspectName;
79             this.store = from.store;
80         }
81     }
82     
83     /* (non-Javadoc)
84      * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
85      */

86     public Object JavaDoc prepareConfiguration(Parameters configuration)
87     throws ParameterException {
88         PreparedConfiguration pc = new PreparedConfiguration();
89         pc.aspectName = configuration.getParameter("aspect-name", "frame");
90         pc.store = configuration.getParameter("store");
91         return pc;
92     }
93
94     /**
95      * Return the aspects required for this renderer
96      * @return An iterator for the aspect descriptions or null.
97      */

98     public Iterator JavaDoc getAspectDescriptions(Object JavaDoc configuration) {
99         PreparedConfiguration pc = (PreparedConfiguration)configuration;
100         
101         DefaultAspectDescription desc = new DefaultAspectDescription();
102         desc.setName(pc.aspectName);
103         desc.setClassName("java.lang.String");
104         desc.setPersistence(pc.store);
105         desc.setAutoCreate(false);
106         
107         return Collections.singletonList(desc).iterator();
108     }
109 }
110
Popular Tags