001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.cms.workflow; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022 023import org.ametys.cms.content.ContentHelper; 024import org.ametys.cms.repository.Content; 025import org.ametys.cms.repository.WorkflowAwareContent; 026import org.ametys.plugins.workflow.AbstractWorkflowComponent; 027 028import com.opensymphony.workflow.WorkflowException; 029 030/** 031 * Abstract class for easily retrieving environment components 032 * in a condition or a function and especially a content. 033 */ 034public abstract class AbstractContentWorkflowComponent extends AbstractWorkflowComponent 035{ 036 /** Constant for storing the content into the transient variables map. */ 037 public static final String CONTENT_KEY = Content.class.getName(); 038 039 /** The content helper */ 040 protected ContentHelper _contentHelper; 041 042 @Override 043 public void service(ServiceManager smanager) throws ServiceException 044 { 045 super.service(smanager); 046 _contentHelper = (ContentHelper) smanager.lookup(ContentHelper.ROLE); 047 } 048 /** 049 * Retrieve the content associated with the workflow. 050 * @param transientVars the parameters from the call. 051 * @return the content. 052 * @throws WorkflowException if the content is not found. 053 */ 054 protected WorkflowAwareContent getContent(Map transientVars) throws WorkflowException 055 { 056 WorkflowAwareContent content = (WorkflowAwareContent) transientVars.get(CONTENT_KEY); 057 058 if (content == null) 059 { 060 throw new WorkflowException("Unable to retrieve content"); 061 } 062 063 // Found in transient variables map 064 return content; 065 } 066}