1 17 18 19 20 package org.apache.lenya.cms.cocoon.acting; 21 22 import java.util.Collections ; 23 import java.util.Map ; 24 25 import org.apache.avalon.framework.parameters.Parameters; 26 import org.apache.cocoon.acting.AbstractAction; 27 import org.apache.cocoon.environment.Redirector; 28 import org.apache.cocoon.environment.SourceResolver; 29 import org.apache.lenya.cms.cocoon.workflow.WorkflowHelper; 30 import org.apache.lenya.cms.publication.Document; 31 import org.apache.lenya.cms.publication.DocumentBuilder; 32 import org.apache.lenya.cms.publication.PageEnvelope; 33 import org.apache.lenya.cms.publication.PageEnvelopeFactory; 34 import org.apache.lenya.cms.publication.Publication; 35 import org.apache.lenya.cms.workflow.WorkflowFactory; 36 import org.apache.lenya.workflow.Event; 37 import org.apache.lenya.workflow.Situation; 38 import org.apache.lenya.workflow.SynchronizedWorkflowInstances; 39 40 50 public class WorkflowInvokerAction extends AbstractAction { 51 52 public static final String AREA = "area"; 53 public static final String DOCUMENT_ID = "document-id"; 54 public static final String LANGUAGE = "language"; 55 public static final String EVENT = "event"; 56 57 60 public Map act( 61 Redirector redirector, 62 SourceResolver resolver, 63 Map objectModel, 64 String source, 65 Parameters parameters) 66 throws Exception { 67 68 String area = parameters.getParameter(AREA); 69 String documentId = parameters.getParameter(DOCUMENT_ID); 70 String language = parameters.getParameter(LANGUAGE); 71 String eventName = parameters.getParameter(EVENT); 72 73 if (getLogger().isDebugEnabled()) { 74 getLogger().debug(getClass().getName() + " invoked."); 75 getLogger().debug(" Area: [" + area + "]"); 76 getLogger().debug(" Document ID: [" + documentId + "]"); 77 getLogger().debug(" Language: [" + language + "]"); 78 getLogger().debug(" Event: [" + eventName + "]"); 79 } 80 81 PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel); 82 Publication publication = envelope.getPublication(); 83 DocumentBuilder builder = publication.getDocumentBuilder(); 84 String url = builder.buildCanonicalUrl(publication, area, documentId, language); 85 Document document = builder.buildDocument(publication, url); 86 87 WorkflowFactory factory = WorkflowFactory.newInstance(); 88 89 if (factory.hasWorkflow(document)) { 90 91 if (getLogger().isDebugEnabled()) { 92 getLogger().debug(" Invoking workflow event"); 93 } 94 95 SynchronizedWorkflowInstances instance = factory.buildSynchronizedInstance(document); 96 Situation situation = WorkflowHelper.buildSituation(objectModel); 97 Event[] events = instance.getExecutableEvents(situation); 98 Event event = null; 99 100 for (int i = 0; i < events.length; i++) { 101 if (events[i].getName().equals(eventName)) { 102 event = events[i]; 103 } 104 } 105 106 assert event != null; 107 instance.invoke(situation, event); 108 } else { 109 if (getLogger().isDebugEnabled()) { 110 getLogger().debug(" Document has no workflow."); 111 } 112 } 113 114 return Collections.EMPTY_MAP; 115 } 116 117 } 118 | Popular Tags |