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 java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.lenya.cms.publication.Document;
24: import org.apache.lenya.cms.publication.Publication;
25: import org.apache.lenya.cms.publication.util.DocumentHelper;
26: import org.apache.lenya.cms.repository.Node;
27: import org.apache.lenya.cms.usecase.DocumentUsecase;
28: import org.apache.lenya.cms.usecase.UsecaseException;
29:
30: /**
31: * Delete a language version.
32: *
33: * @version $Id: DeleteLanguage.java 559054 2007-07-24 14:04:40Z rfrovarp $
34: */
35: public class DeleteLanguage extends DocumentUsecase {
36:
37: /**
38: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
39: */
40: protected void doCheckPreconditions() throws Exception {
41: super .doCheckPreconditions();
42: if (hasErrors()) {
43: return;
44: }
45:
46: Document doc = getSourceDocument();
47:
48: if (!doc.getArea().equals(Publication.AUTHORING_AREA)) {
49: addErrorMessage("This usecase can only be invoked in the authoring area!");
50: } else if (doc.getLanguages().length == 1) {
51: addErrorMessage("The last language version cannot be removed.");
52: }
53:
54: if (doc.existsVersion(Publication.LIVE_AREA, doc.getLanguage())) {
55: addErrorMessage("The document can't be deleted if a live version exists.");
56: }
57: }
58:
59: /**
60: * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
61: */
62: protected Node[] getNodesToLock() throws UsecaseException {
63: List nodes = new ArrayList();
64: if (getSourceDocument() != null) {
65: Node docNode = getSourceDocument().getRepositoryNode();
66: Node siteNode = getSourceDocument().area().getSite()
67: .getRepositoryNode();
68: nodes.add(docNode);
69: nodes.add(siteNode);
70: }
71: return (Node[]) nodes.toArray(new Node[nodes.size()]);
72: }
73:
74: /**
75: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
76: */
77: protected void doExecute() throws Exception {
78: super .doExecute();
79:
80: Document document = getSourceDocument();
81: document.getLink().delete();
82: document.delete();
83:
84: setTargetDocument(DocumentHelper
85: .getExistingLanguageVersion(document));
86: }
87:
88: }
|