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.repository.Node;
26: import org.apache.lenya.cms.site.SiteNode;
27: import org.apache.lenya.cms.site.SiteStructure;
28: import org.apache.lenya.cms.usecase.DocumentUsecase;
29: import org.apache.lenya.cms.usecase.UsecaseException;
30: import org.apache.lenya.cms.workflow.WorkflowUtil;
31: import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
32:
33: /**
34: * Switch the navigation visibility of a document.
35: */
36: public class ChangeVisibility extends DocumentUsecase {
37:
38: protected String getEvent() {
39: return "edit";
40: }
41:
42: /**
43: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
44: */
45: protected void doCheckPreconditions() throws Exception {
46: super .doCheckPreconditions();
47: if (hasErrors()) {
48: return;
49: }
50:
51: Document doc = getSourceDocument();
52: if (!getSourceDocument().getArea().equals(
53: Publication.AUTHORING_AREA)) {
54: addErrorMessage("This usecase can only be invoked in the authoring area!");
55: }
56:
57: String[] languages = doc.getLanguages();
58: for (int i = 0; i < languages.length; i++) {
59: Document version = doc.getTranslation(languages[i]);
60: UsecaseWorkflowHelper.checkWorkflow(this .manager, this ,
61: getEvent(), version, getLogger());
62: }
63: }
64:
65: protected void doExecute() throws Exception {
66: super .doExecute();
67: Document doc = getSourceDocument();
68: SiteNode node = doc.getLink().getNode();
69: node.setVisible(!node.isVisible());
70:
71: String[] languages = doc.getLanguages();
72: for (int i = 0; i < languages.length; i++) {
73: Document version = doc.getTranslation(languages[i]);
74: WorkflowUtil.invoke(this .manager, getSession(),
75: getLogger(), version, getEvent());
76: }
77: }
78:
79: /**
80: * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
81: */
82: protected Node[] getNodesToLock() throws UsecaseException {
83: List nodes = new ArrayList();
84: if (getSourceDocument() != null) {
85: SiteStructure structure = getSourceDocument().area()
86: .getSite();
87: nodes.add(structure.getRepositoryNode());
88: }
89:
90: return (Node[]) nodes.toArray(new Node[nodes.size()]);
91: }
92:
93: }
|