KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > cocoon > acting > ReservedCheckoutTestAction


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: ReservedCheckoutTestAction.java 43220 2004-08-16 12:12:43Z andreas $ */
19
20 package org.apache.lenya.cms.cocoon.acting;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.avalon.framework.parameters.Parameters;
26 import org.apache.cocoon.environment.Redirector;
27 import org.apache.cocoon.environment.SourceResolver;
28 import org.apache.lenya.cms.rc.FileReservedCheckOutException;
29 import org.apache.lenya.cms.rc.RCML;
30 import org.apache.lenya.cms.rc.RCMLEntry;
31
32
33 /**
34  * An action that tests if a document is already checked out by a given user.
35  * If it isn't, a check out will be tried.
36  */

37
38 public class ReservedCheckoutTestAction extends RevisionControllerAction {
39
40     /** (non-Javadoc)
41      * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
42      */

43     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src,
44         Parameters parameters) throws Exception JavaDoc {
45         super.act(redirector, resolver, objectModel, src, parameters);
46
47         HashMap JavaDoc actionMap = new HashMap JavaDoc();
48
49         try {
50             RCMLEntry entry =getRc().getRCML(getFilename()).getLatestEntry();
51
52             if ((entry == null) || (entry.getType() != RCML.co) || !entry.getIdentity().equals(getUsername())) {
53                 //check out
54
getRc().reservedCheckOut(getFilename(),getUsername());
55             }
56         } catch (FileReservedCheckOutException e) {
57             actionMap.put("exception", "fileReservedCheckOutException");
58             actionMap.put("filename", getFilename());
59             actionMap.put("user", e.getCheckOutUsername());
60             actionMap.put("date", e.getCheckOutDate());
61             getLogger().warn("Document " + getFilename() + " already checked-out by " + e.getCheckOutUsername() + " since " + e.getCheckOutDate());
62
63             return actionMap;
64         } catch (Exception JavaDoc e) {
65             actionMap.put("exception", "genericException");
66             actionMap.put("filename", getFilename());
67             actionMap.put("message", e.getMessage());
68             getLogger().error(".act(): The document " + getFilename() + " couldn't be checked out: ", e);
69
70             return actionMap;
71         }
72         return null;
73     }
74 }
75
Popular Tags