001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /* $Id: WorkflowInvokerAction.java 586495 2007-10-19 15:13:36Z rfrovarp $ */
020:
021: package org.apache.lenya.cms.cocoon.acting;
022:
023: import java.util.Collections;
024: import java.util.Map;
025:
026: import org.apache.avalon.framework.parameters.Parameters;
027: import org.apache.cocoon.acting.ServiceableAction;
028: import org.apache.cocoon.environment.ObjectModelHelper;
029: import org.apache.cocoon.environment.Redirector;
030: import org.apache.cocoon.environment.Request;
031: import org.apache.cocoon.environment.SourceResolver;
032: import org.apache.lenya.ac.AccessControlException;
033: import org.apache.lenya.cms.publication.Document;
034: import org.apache.lenya.cms.publication.DocumentFactory;
035: import org.apache.lenya.cms.publication.DocumentUtil;
036: import org.apache.lenya.cms.publication.Publication;
037: import org.apache.lenya.cms.publication.PublicationUtil;
038: import org.apache.lenya.cms.repository.RepositoryUtil;
039: import org.apache.lenya.cms.repository.Session;
040: import org.apache.lenya.cms.workflow.WorkflowUtil;
041:
042: /**
043: * Action to invoke a workflow transition independently from the request document URL. Parameters:
044: * <ul>
045: * <li><strong>area: </strong> The area.</li>
046: * <li><strong>document-uuid: </strong> The document uuid.</li>
047: * <li><strong>language: </strong> The language.</li>
048: * <li><strong>event: </strong> The event to invoke.</li>
049: * </ul>
050: */
051: public class WorkflowInvokerAction extends ServiceableAction {
052:
053: /**
054: * <code>AREA</code> The area
055: */
056: public static final String AREA = "area";
057: /**
058: * <code>DOCUMENT_UUID</code> The document id
059: */
060: public static final String DOCUMENT_UUID = "document-uuid";
061: /**
062: * <code>LANGUAGE</code> The language
063: */
064: public static final String LANGUAGE = "language";
065: /**
066: * <code>EVENT</code> The event
067: */
068: public static final String EVENT = "event";
069:
070: /**
071: * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector,
072: * org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String,
073: * org.apache.avalon.framework.parameters.Parameters)
074: */
075: public Map act(Redirector redirector, SourceResolver resolver,
076: Map objectModel, String source, Parameters parameters)
077: throws Exception {
078:
079: String area = parameters.getParameter(AREA);
080: String documentId = parameters.getParameter(DOCUMENT_UUID);
081: String language = parameters.getParameter(LANGUAGE);
082: String eventName = parameters.getParameter(EVENT);
083:
084: if (getLogger().isDebugEnabled()) {
085: getLogger().debug(getClass().getName() + " invoked.");
086: getLogger().debug(" Area: [" + area + "]");
087: getLogger().debug(" Document ID: [" + documentId + "]");
088: getLogger().debug(" Language: [" + language + "]");
089: getLogger().debug(" Event: [" + eventName + "]");
090: }
091:
092: Publication pub;
093: Request request = ObjectModelHelper.getRequest(objectModel);
094:
095: try {
096: pub = PublicationUtil.getPublication(this .manager, request);
097: } catch (Exception e) {
098: throw new AccessControlException(e);
099: }
100: Session session = RepositoryUtil.getSession(this .manager,
101: request);
102: DocumentFactory map = DocumentUtil.createDocumentFactory(
103: this .manager, session);
104: Document document = map.get(pub, area, documentId, language);
105:
106: if (getLogger().isDebugEnabled()) {
107: getLogger().debug(" Invoking workflow event");
108: }
109: WorkflowUtil.invoke(this.manager, session, getLogger(),
110: document, eventName);
111:
112: return Collections.EMPTY_MAP;
113: }
114:
115: }
|