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: ReservedCheckinAction.java 568030 2007-08-21 09:06:57Z 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.ObjectModelHelper;
28: import org.apache.cocoon.environment.Redirector;
29: import org.apache.cocoon.environment.Request;
30: import org.apache.cocoon.environment.SourceResolver;
31: import org.apache.lenya.ac.Identity;
32: import org.apache.lenya.cms.publication.DocumentFactory;
33: import org.apache.lenya.cms.publication.DocumentUtil;
34: import org.apache.lenya.cms.repository.Node;
35: import org.apache.lenya.cms.repository.RepositoryException;
36: import org.apache.lenya.cms.repository.RepositoryUtil;
37: import org.apache.lenya.cms.repository.Session;
38: import org.apache.lenya.util.ServletHelper;
39:
40: /**
41: * Checkin document
42: */
43: public class ReservedCheckinAction extends RevisionControllerAction {
44: /**
45: * Checkin document
46: * @return HashMap with checkin parameters
47: * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector,
48: * org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String,
49: * org.apache.avalon.framework.parameters.Parameters)
50: */
51: public Map act(Redirector redirector, SourceResolver resolver,
52: Map objectModel, String src, Parameters parameters)
53: throws Exception {
54: super .act(redirector, resolver, objectModel, src, parameters);
55:
56: try {
57: Request request = ObjectModelHelper.getRequest(objectModel);
58: Identity identity = (Identity) request.getSession()
59: .getAttribute(Identity.class.getName());
60: Session session = RepositoryUtil.createSession(
61: this .manager, identity, true);
62:
63: DocumentFactory factory = DocumentUtil
64: .createDocumentFactory(this .manager, session);
65: String url = ServletHelper.getWebappURI(request);
66: if (factory.isDocument(url)) {
67: Node node = factory.getFromURL(url).getRepositoryNode();
68: if (node.isCheckedOutBySession(session)) {
69: node.checkin();
70: }
71: } else {
72: throw new RuntimeException("The URL [" + url
73: + "] doesn't represent a document.");
74: }
75:
76: } catch (RepositoryException e) {
77: getLogger().error("Could not check in node: ", e);
78: Map actionMap = new HashMap();
79: actionMap.put("exception", "genericException");
80: actionMap.put("filename", getNode().getSourceURI());
81: actionMap.put("message", e.getMessage());
82: return actionMap;
83: }
84:
85: return null;
86: }
87: }
|