1 16 package org.apache.cocoon.portal.layout.renderer.aspect.impl; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 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 ; 30 import org.xml.sax.SAXException ; 31 32 42 public final class DefaultRendererContext implements RendererAspectContext { 43 44 private Iterator iterator; 45 private Iterator configIterator; 46 private Object config; 47 private Map attributes; 48 private Map 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 70 public void invokeNext(Layout layout, 71 PortalService service, 72 ContentHandler handler) 73 throws SAXException { 74 if (!this.isRendering && !this.isRequired) { 75 if (layout instanceof CompositeLayout) { 76 CompositeLayout compositeLayout = (CompositeLayout)layout; 77 for (Iterator iter = compositeLayout.getItems().iterator(); iter.hasNext();) { 78 Layout itemLayout = ((Item) iter.next()).getLayout(); 79 if ( itemLayout != null ) { 80 final String 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 102 public Object getAspectConfiguration() { 103 return this.config; 104 } 105 106 109 public void setAttribute(String key, Object attribute) { 110 if ( key != null ) { 111 if ( this.attributes == null ) { 112 this.attributes = new HashMap (10); 113 } 114 this.attributes.put( key, attribute ); 115 } 116 } 117 118 121 public Object getAttribute(String key) { 122 if ( key != null && this.attributes != null) { 123 return this.attributes.get( key ); 124 } 125 return null; 126 } 127 128 131 public void removeAttribute(String key) { 132 if ( this.attributes != null && key != null) { 133 this.attributes.remove( key ); 134 } 135 } 136 137 140 public Map getObjectModel() { 141 return this.objectModel; 142 } 143 144 148 public void setObjectModel(Map map) { 149 this.objectModel = map; 150 } 151 152 } 153 | Popular Tags |