01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.workflow.usecases;
19:
20: import org.apache.avalon.framework.configuration.Configurable;
21: import org.apache.avalon.framework.configuration.Configuration;
22: import org.apache.avalon.framework.configuration.ConfigurationException;
23: import org.apache.lenya.cms.publication.Document;
24: import org.apache.lenya.cms.usecase.DocumentUsecase;
25: import org.apache.lenya.cms.workflow.WorkflowUtil;
26:
27: /**
28: * Check if a workflow event can be invoked on the current document without actually invoking it.
29: * The event is obtained from the configuration in <code>cocoon.xconf</code>:<code>
30: * <pre>
31: * <component-instance name="default/workflow.submit"
32: * logger="lenya.usecases.workflow"
33: * class="org.apache.lenya.cms.workflow.usecases.CheckWorkflow">
34: * <event id="submit"/>
35: * </component-instance>
36: * </pre>
37: * </code>
38: *
39: * @version $Id: InvokeWorkflow.java 426254 2006-07-27 21:27:04Z andreas $
40: */
41: public class CheckWorkflow extends DocumentUsecase implements
42: Configurable {
43:
44: private String event;
45:
46: /**
47: * @return The workflow event to use.
48: */
49: protected String getEvent() {
50: return event;
51: }
52:
53: /**
54: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
55: */
56: protected void doCheckPreconditions() throws Exception {
57: super .doCheckPreconditions();
58:
59: if (hasErrors()) {
60: return;
61: }
62:
63: Document doc = getSourceDocument();
64: if (!WorkflowUtil.canInvoke(this .manager, getSession(),
65: getLogger(), doc, getEvent())) {
66: UsecaseWorkflowHelper.addWorkflowError(this , getEvent(),
67: doc);
68: }
69: }
70:
71: protected static final String ELEMENT_EVENT = "event";
72: protected static final String ATTRIBUTE_ID = "id";
73:
74: /**
75: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
76: */
77: public void configure(Configuration config)
78: throws ConfigurationException {
79: super.configure(config);
80: this.event = config.getChild(ELEMENT_EVENT).getAttribute(
81: ATTRIBUTE_ID);
82: }
83:
84: }
|