KickJava   Java API By Example, From Geeks To Geeks.

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


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: RollbackAction.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.cocoon.acting;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
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
32
33 public class RollbackAction extends RevisionControllerAction {
34     /**
35      * DOCUMENT ME!
36      *
37      * @param redirector DOCUMENT ME!
38      * @param resolver DOCUMENT ME!
39      * @param objectModel DOCUMENT ME!
40      * @param src DOCUMENT ME!
41      * @param parameters DOCUMENT ME!
42      *
43      * @return DOCUMENT ME!
44      *
45      * @throws Exception DOCUMENT ME!
46      */

47     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src,
48         Parameters parameters) throws Exception JavaDoc {
49         super.act(redirector, resolver, objectModel, src, parameters);
50
51         HashMap JavaDoc actionMap = new HashMap JavaDoc();
52
53         // Get request object
54
Request request = ObjectModelHelper.getRequest(objectModel);
55
56         if (request == null) {
57             getLogger().error("No request object");
58
59             return null;
60         }
61
62         // Get parameters
63
String JavaDoc rollbackTime = request.getParameter("rollbackTime");
64
65         // Do the rollback to an earlier version
66
long newtime = 0;
67
68         try {
69             newtime = getRc().rollback(getFilename(), getUsername(), true, new Long JavaDoc(rollbackTime).longValue());
70         } catch (FileNotFoundException JavaDoc e) {
71             getLogger().error("Unable to roll back!" + e);
72
73             return null;
74         } catch (Exception JavaDoc e) {
75             getLogger().error("Unable to roll back!" + e);
76
77             return null;
78         }
79
80         getLogger().debug("rollback complete, old (and now current) time was " + rollbackTime +
81             " backup time is " + newtime);
82
83         String JavaDoc location = request.getHeader("Referer");
84
85         getLogger().debug("redirect to " + location);
86         actionMap.put("location", location);
87
88         return actionMap;
89     }
90 }
91
Popular Tags