1 package nl.hippo.cms.workflow; 2 3 import java.io.IOException ; 4 import java.util.Iterator ; 5 import nl.hippo.componentcontainers.AvalonSpringBridge; 6 import nl.hippo.servermanager.Project; 7 import nl.hippo.servermanager.Server; 8 import nl.hippo.servermanager.ServerManager; 9 import org.apache.avalon.framework.activity.Disposable; 10 import org.apache.avalon.framework.service.ServiceException; 11 import org.apache.avalon.framework.service.ServiceManager; 12 import org.apache.avalon.framework.service.Serviceable; 13 import org.apache.cocoon.ProcessingException; 14 import org.apache.cocoon.environment.Request; 15 import org.apache.cocoon.generation.AbstractGenerator; 16 import org.xml.sax.SAXException ; 17 import org.xml.sax.helpers.AttributesImpl ; 18 19 public class DashboardWorkflowQueriesGenerator extends AbstractGenerator implements Serviceable, Disposable 20 { 21 22 private ServiceManager m_manager; 23 24 private AvalonSpringBridge m_avalonSpringBridge; 25 26 public DashboardWorkflowQueriesGenerator() 27 { 28 super(); 29 } 30 31 public void service(ServiceManager manager) throws ServiceException 32 { 33 m_manager = manager; 34 m_avalonSpringBridge = (AvalonSpringBridge) manager.lookup(AvalonSpringBridge.ROLE); 35 } 36 37 public void generate() throws IOException , SAXException , ProcessingException 38 { 39 try 40 { 41 Request request = (Request) objectModel.get("request"); 42 43 ServerManager serverManager = (ServerManager) m_avalonSpringBridge.getBean("serverManager"); 44 Server server = serverManager.getServer(); 45 Project project = server.getProjectByDomain(request.getServerName()); 46 47 contentHandler.startDocument(); 48 contentHandler.startElement("", "queries", "queries", new AttributesImpl ()); 49 50 Iterator iterator = project.dashboardWorkflowQueriesIterator(); 51 while (iterator.hasNext()) 52 { 53 String workflowQueryId = (String )iterator.next(); 54 AttributesImpl attributes = new AttributesImpl (); 55 attributes.addAttribute("http://apache.org/cocoon/include/1.0", "src", "src", "CDATA", "cocoon://workflow/query/" + workflowQueryId); 56 contentHandler.startElement("http://apache.org/cocoon/include/1.0", "include", "incl:include", attributes); 57 contentHandler.endElement("http://apache.org/cocoon/include/1.0", "include", "incl:include"); 58 } 59 60 contentHandler.endElement("", "queries", "queries"); 61 contentHandler.endDocument(); 62 } 63 catch (Exception e) 64 { 65 throw new ProcessingException("Unknown error", e); 66 } 67 } 68 69 public void dispose() 70 { 71 m_manager.release(m_avalonSpringBridge); 72 m_manager = null; 73 } 74 75 } | Popular Tags |