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.Layout; 25 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext; 26 import org.apache.cocoon.xml.AttributesImpl; 27 import org.apache.cocoon.xml.XMLUtils; 28 import org.xml.sax.ContentHandler ; 29 import org.xml.sax.SAXException ; 30 31 59 public final class ParameterAspect extends AbstractAspect { 60 61 64 public void toSAX(RendererAspectContext context, 65 Layout layout, 66 PortalService service, 67 ContentHandler contenthandler) 68 throws SAXException { 69 70 final PreparedConfiguration config = (PreparedConfiguration)context.getAspectConfiguration(); 71 72 Map parameter = layout.getParameters(); 73 if (parameter.size() > 0) { 74 AttributesImpl attributes = new AttributesImpl(); 75 Map.Entry entry; 76 for (Iterator iter = parameter.entrySet().iterator(); iter.hasNext();) { 77 entry = (Map.Entry ) iter.next(); 78 attributes.addCDATAAttribute((String )entry.getKey(), (String )entry.getValue()); 79 } 80 XMLUtils.startElement(contenthandler, config.tagName, attributes); 81 } else { 82 XMLUtils.startElement(contenthandler, config.tagName); 83 } 84 85 context.invokeNext( layout, service, contenthandler ); 86 87 XMLUtils.endElement(contenthandler, config.tagName); 88 } 89 90 protected static class PreparedConfiguration { 91 public String tagName; 92 93 public void takeValues(PreparedConfiguration from) { 94 this.tagName = from.tagName; 95 } 96 } 97 98 101 public Object prepareConfiguration(Parameters configuration) 102 throws ParameterException { 103 PreparedConfiguration pc = new PreparedConfiguration(); 104 pc.tagName = configuration.getParameter("tag-name", "parameter"); 105 return pc; 106 } 107 } 108 | Popular Tags |