1 16 package org.apache.cocoon.portal.layout.renderer.aspect.impl; 17 18 import java.util.Iterator ; 19 import java.util.Map ; 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 ; 30 import org.xml.sax.SAXException ; 31 32 66 public class CompositeContentAspect extends AbstractCompositeAspect { 67 68 protected static final String ITEM_STRING = "item"; 69 70 73 public void toSAX(RendererAspectContext context, 74 Layout layout, 75 PortalService service, 76 ContentHandler handler) 77 throws SAXException { 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 92 protected void processItem(Item item, 93 ContentHandler handler, 94 PortalService service) 95 throws SAXException { 96 Layout layout = item.getLayout(); 97 98 Map 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 entry; 105 for (Iterator iter = parameters.entrySet().iterator(); iter.hasNext();) { 106 entry = (Map.Entry ) iter.next(); 107 attributes.addCDATAAttribute((String )entry.getKey(), (String )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 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 129 public Object 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 |