KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > cocoon > workflow > WorkflowHelper


1
2 /*
3  * Copyright 1999-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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
19 /* $Id: WorkflowHelper.java 42598 2004-03-01 16:18:28Z gregor $ */
20
21 package org.apache.lenya.cms.cocoon.workflow;
22
23 import java.util.Map JavaDoc;
24
25 import org.apache.cocoon.environment.ObjectModelHelper;
26 import org.apache.cocoon.environment.Request;
27 import org.apache.cocoon.environment.Session;
28 import org.apache.lenya.ac.AccessControlException;
29 import org.apache.lenya.ac.Identity;
30 import org.apache.lenya.ac.Role;
31 import org.apache.lenya.ac.impl.PolicyAuthorizer;
32 import org.apache.lenya.cms.workflow.WorkflowFactory;
33 import org.apache.lenya.workflow.Situation;
34 import org.apache.lenya.workflow.WorkflowException;
35
36 /**
37  * Workflow helper.
38  */

39 public class WorkflowHelper {
40
41     /**
42      * Creates a situation for a Cocoon object model.
43      * @param objectModel The object model.
44      * @return A workflow situation.
45      * @throws WorkflowException when something went wrong.
46      */

47     public static Situation buildSituation(Map JavaDoc objectModel) throws WorkflowException {
48         Request request = ObjectModelHelper.getRequest(objectModel);
49         return buildSituation(request);
50     }
51     
52     /**
53      * Creates a situation for a request.
54      * @param request The request.
55      * @return A workflow situation.
56      * @throws WorkflowException when something went wrong.
57      */

58     public static Situation buildSituation(Request request) throws WorkflowException {
59         Role[] roles;
60         try {
61             roles = PolicyAuthorizer.getRoles(request);
62         } catch (AccessControlException e) {
63             throw new WorkflowException(e);
64         }
65         Session session = request.getSession(false);
66         if (session == null) {
67             throw new WorkflowException("Session not initialized!");
68         }
69         Identity identity = Identity.getIdentity(session);
70         
71         return WorkflowFactory.newInstance().buildSituation(roles, identity);
72     }
73
74 }
75
Popular Tags