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:
19: /* $Id: ReservedCheckoutTestAction.java 564507 2007-08-10 08:33:31Z andreas $ */
20:
21: package org.apache.lenya.cms.cocoon.acting;
22:
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: import org.apache.avalon.framework.parameters.Parameters;
27: import org.apache.cocoon.environment.Redirector;
28: import org.apache.cocoon.environment.SourceResolver;
29: import org.apache.lenya.cms.repository.Node;
30: import org.apache.lenya.cms.repository.RepositoryException;
31:
32: /**
33: * An action that tests if a document is already checked out by a given user.
34: * If it isn't, a check out will be tried.
35: */
36:
37: public class ReservedCheckoutTestAction extends
38: RevisionControllerAction {
39:
40: /**
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 act(Redirector redirector, SourceResolver resolver,
44: Map objectModel, String src, Parameters parameters)
45: throws Exception {
46: super .act(redirector, resolver, objectModel, src, parameters);
47:
48: HashMap actionMap = new HashMap();
49:
50: try {
51: Node node = getNode();
52:
53: if (!node.isCheckedOut()
54: || !node.getCheckoutUserId().equals(getUsername())) {
55: //check out
56: getNode().checkout();
57: }
58: } catch (RepositoryException e) {
59: actionMap.put("exception", "RepositoryException");
60: actionMap.put("filename", getNode().getSourceURI());
61:
62: return actionMap;
63: } catch (Exception e) {
64: actionMap.put("exception", "genericException");
65: actionMap.put("filename", getNode().getSourceURI());
66: actionMap.put("message", e.getMessage());
67: getLogger().error(
68: ".act(): The node " + getNode().getSourceURI()
69: + " couldn't be checked out: ", e);
70:
71: return actionMap;
72: }
73: return null;
74: }
75: }
|