1 16 package org.apache.cocoon.portal.tools.transformation; 17 18 import java.io.IOException ; 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 import org.apache.avalon.framework.activity.Disposable; 24 import org.apache.avalon.framework.parameters.ParameterException; 25 import org.apache.avalon.framework.parameters.Parameters; 26 import org.apache.avalon.framework.service.ServiceException; 27 import org.apache.avalon.framework.service.ServiceManager; 28 import org.apache.cocoon.ProcessingException; 29 import org.apache.cocoon.environment.SourceResolver; 30 import org.apache.cocoon.portal.tools.PortalTool; 31 import org.apache.cocoon.portal.tools.PortalToolFunction; 32 import org.apache.cocoon.portal.tools.PortalToolManager; 33 import org.apache.cocoon.transformation.AbstractSAXTransformer; 34 import org.apache.cocoon.xml.AttributesImpl; 35 import org.xml.sax.SAXException ; 36 37 42 public class PortalToolsLayoutTransformer extends AbstractSAXTransformer 43 implements Disposable { 44 45 public static final String ROLE = PortalToolsLayoutTransformer.class.getName(); 46 47 private PortalToolManager pm; 48 private String selected; 49 50 53 public void service(ServiceManager manager) throws ServiceException { 54 super.service(manager); 55 pm = (PortalToolManager) manager.lookup(PortalToolManager.ROLE); 56 } 57 58 61 public void setup(SourceResolver resolver, Map objectModel, String src, 62 Parameters par) throws ProcessingException, SAXException , 63 IOException { 64 super.setup(resolver, objectModel, src, par); 65 try { 66 selected = par.getParameter("selected"); 67 } catch (ParameterException e) { 68 } 70 } 71 72 75 public void dispose() { 76 if (this.manager != null) { 77 this.manager.release(pm); 78 this.pm = null; 79 } 80 super.dispose(); 81 } 82 83 84 87 public void startDocument() throws SAXException { 88 super.startDocument(); 89 AttributesImpl a = new AttributesImpl(); 90 91 super.startPrefixMapping("i18n", "http://apache.org/cocoon/i18n/2.1"); 93 super.startElement("", "div","div", a); 94 super.startElement("", "tab-layout", "tab-layout", a); 95 Collection tools = pm.getToolsWithFunctions(); 96 for(Iterator it = tools.iterator(); it.hasNext();) { 97 AttributesImpl attr = new AttributesImpl(); 98 PortalTool pt = (PortalTool) it.next(); 99 attr.addCDATAAttribute("parameter", "tools/functions/" + pt.getId()); 100 attr.addCDATAAttribute("name", pt.getName()); 101 attr.addCDATAAttribute("http://apache.org/cocoon/i18n/2.1", "attr", "i18n:attr", "name"); 102 if(selected != null) { 103 if(selected.equals(pt.getId())) { 104 attr.addCDATAAttribute("selected", "true"); 105 } 106 } 107 super.startElement("","named-item", "named-item", attr); 108 super.endElement("", "named-item", "named-item"); 109 } 110 super.endElement("", "tab-layout", "tab-layout"); 111 if(selected != null) { 112 PortalTool ct = pm.getTool(selected); 113 if(ct != null) { 114 super.startElement("", "tool-functions", "tool-functions", a); 115 Collection funs = ct.getFunctions(); 116 for(Iterator it = funs.iterator();it.hasNext();) { 117 PortalToolFunction ptf = (PortalToolFunction) it.next(); 118 AttributesImpl attr = new AttributesImpl(); 119 attr.addCDATAAttribute("parameter", "tools/plugins/" + ct.getId() + "/" + ptf.getFunction()); 120 attr.addCDATAAttribute("name", ptf.getName()); 121 attr.addCDATAAttribute("http://apache.org/cocoon/i18n/2.1", "attr", "i18n:attr", "name"); super.startElement("", "function", "function", attr); 122 super.endElement("", "function", "function"); 123 } 124 super.endElement("", "tool-functions", "tool-functions"); 125 } 126 } 127 } 128 129 130 133 public void endDocument() throws SAXException { 134 super.endElement("", "div", "div"); 135 super.endPrefixMapping("i18n"); 136 selected= null; 137 super.endDocument(); 138 } 139 140 } 141 | Popular Tags |