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: package org.apache.lenya.cms.site.usecases;
19:
20: import org.apache.lenya.cms.publication.Area;
21: import org.apache.lenya.cms.publication.Document;
22: import org.apache.lenya.cms.publication.DocumentLocator;
23: import org.apache.lenya.cms.publication.Publication;
24: import org.apache.lenya.cms.site.SiteUtil;
25: import org.apache.lenya.cms.workflow.WorkflowUtil;
26: import org.apache.lenya.workflow.Workflowable;
27:
28: /**
29: * Restore usecase handler.
30: *
31: * @version $Id:$
32: */
33: public class Restore extends MoveSubsite {
34:
35: /**
36: * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getSourceAreas()
37: */
38: protected String[] getSourceAreas() {
39: return new String[] { Publication.TRASH_AREA,
40: Publication.ARCHIVE_AREA };
41: }
42:
43: /**
44: * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getTargetArea()
45: */
46: protected String getTargetArea() {
47: return Publication.AUTHORING_AREA;
48: }
49:
50: /**
51: * @see org.apache.lenya.cms.site.usecases.MoveSubsite#getEvent()
52: */
53: protected String getEvent() {
54: return "restore";
55: }
56:
57: protected void doCheckPreconditions() throws Exception {
58: super .doCheckPreconditions();
59:
60: String targetAreaName = getTargetArea();
61: Document doc = getSourceDocument();
62: if (doc == null) {
63: return;
64: }
65: // Check to see if parent node exists in target to prevent ghost nodes
66: Area targetArea = doc.getPublication().getArea(targetAreaName);
67: DocumentLocator targetLoc = doc.getLocator().getAreaVersion(
68: targetAreaName);
69: targetLoc = SiteUtil.getAvailableLocator(this .manager,
70: getDocumentFactory(), targetLoc);
71: String targetPath = targetLoc.getPath();
72: targetPath = targetPath.substring(0, targetPath
73: .lastIndexOf('/'));
74: if (!targetArea.getSite().contains(targetPath)) {
75: addErrorMessage("The authoring path [" + targetPath
76: + "] does not exist.");
77: }
78: }
79:
80: protected void doCheckPostconditions() throws Exception {
81: super .doCheckPostconditions();
82:
83: Document doc = getTargetDocument(true);
84: Workflowable workflowable = WorkflowUtil.getWorkflowable(
85: this .manager, getSession(), getLogger(), doc);
86: String state = workflowable.getLatestVersion().getState();
87: if (!state.equals("authoring")) {
88: addErrorMessage("The state is [" + state
89: + "] instead of [authoring]!");
90: }
91:
92: }
93:
94: }
|