KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.cocoon.portal.PortalService;
23 import org.apache.cocoon.portal.layout.Layout;
24 import org.apache.cocoon.portal.layout.CompositeLayout;
25 import org.apache.cocoon.portal.layout.Item;
26 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect;
27 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
28 import org.apache.cocoon.portal.layout.renderer.Renderer;
29 import org.xml.sax.ContentHandler JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * The renderer aspect context is passed to every renderer aspect.
34  * Using this context, a renderer aspect can get it's configuration
35  * and it can invoke (if wanted) the next aspect in the aspect chain.
36  *
37  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
38  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
39  *
40  * @version CVS $Id: DefaultRendererContext.java 331660 2005-11-08 01:22:30Z rgoers $
41  */

42 public final class DefaultRendererContext implements RendererAspectContext {
43
44     private Iterator JavaDoc iterator;
45     private Iterator JavaDoc configIterator;
46     private Object JavaDoc config;
47     private Map JavaDoc attributes;
48     private Map JavaDoc objectModel;
49     private boolean isRendering;
50     private boolean isRequired;
51     
52     public DefaultRendererContext(RendererAspectChain chain, Layout layout, PortalService service) {
53         this.iterator = chain.getIterator();
54         this.configIterator = chain.getConfigIterator();
55         this.isRequired = chain.isRequired();
56         Layout entryLayout = service.getEntryLayout(null);
57         if (service.isRenderable().booleanValue()) {
58             this.isRendering = true;
59             return;
60         }
61         if (entryLayout == layout) {
62             this.isRendering = true;
63             service.setRenderable(Boolean.TRUE);
64         }
65     }
66     
67     /* (non-Javadoc)
68      * @see org.apache.cocoon.portal.layout.renderer.RendererAspectContext#invokeNext(org.apache.cocoon.portal.layout.Layout, org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler)
69      */

70     public void invokeNext(Layout layout,
71                             PortalService service,
72                             ContentHandler JavaDoc handler)
73     throws SAXException JavaDoc {
74         if (!this.isRendering && !this.isRequired) {
75             if (layout instanceof CompositeLayout) {
76                 CompositeLayout compositeLayout = (CompositeLayout)layout;
77                 for (Iterator JavaDoc iter = compositeLayout.getItems().iterator(); iter.hasNext();) {
78                     Layout itemLayout = ((Item) iter.next()).getLayout();
79                     if ( itemLayout != null ) {
80                         final String JavaDoc rendererName = itemLayout.getRendererName();
81                         final Renderer renderer = service.getComponentManager().getRenderer(rendererName);
82                         renderer.toSAX(itemLayout, service, handler);
83                     }
84                 }
85             }
86             return;
87         }
88         if (iterator.hasNext()) {
89             this.config = this.configIterator.next();
90             final RendererAspect aspect = (RendererAspect) iterator.next();
91             aspect.toSAX(this, layout, service, handler);
92         }
93     }
94
95     public boolean isRendering() {
96         return this.isRendering;
97     }
98
99     /* (non-Javadoc)
100     * @see org.apache.cocoon.portal.layout.renderer.RendererAspectContext#getConfiguration()
101     */

102     public Object JavaDoc getAspectConfiguration() {
103         return this.config;
104     }
105
106     /**
107      * Set an attribute
108      */

109     public void setAttribute(String JavaDoc key, Object JavaDoc attribute) {
110         if ( key != null ) {
111             if ( this.attributes == null ) {
112                 this.attributes = new HashMap JavaDoc(10);
113             }
114             this.attributes.put( key, attribute );
115         }
116     }
117
118     /**
119      * Get an attribute
120      */

121     public Object JavaDoc getAttribute(String JavaDoc key) {
122         if ( key != null && this.attributes != null) {
123             return this.attributes.get( key );
124         }
125         return null;
126     }
127
128     /**
129      * Remove an attribute
130      */

131     public void removeAttribute(String JavaDoc key) {
132         if ( this.attributes != null && key != null) {
133             this.attributes.remove( key );
134         }
135     }
136
137     /* (non-Javadoc)
138      * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext#getObjectModel()
139      */

140     public Map JavaDoc getObjectModel() {
141         return this.objectModel;
142     }
143
144     /**
145      * Set the object model
146      * @param map The object model
147      */

148     public void setObjectModel(Map JavaDoc map) {
149         this.objectModel = map;
150     }
151
152 }
153
Popular Tags