001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.site.usecases;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import org.apache.lenya.cms.publication.Document;
024: import org.apache.lenya.cms.publication.DocumentException;
025: import org.apache.lenya.cms.publication.Publication;
026: import org.apache.lenya.cms.repository.Node;
027: import org.apache.lenya.cms.site.SiteStructure;
028: import org.apache.lenya.cms.usecase.DocumentUsecase;
029: import org.apache.lenya.cms.usecase.UsecaseException;
030: import org.apache.lenya.cms.workflow.WorkflowUtil;
031: import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
032:
033: /**
034: * Change the label of a document.
035: *
036: * @version $Id: ChangeLabel.java 559056 2007-07-24 14:14:33Z rfrovarp $
037: */
038: public class ChangeLabel extends DocumentUsecase {
039:
040: protected static final String LABEL = "label";
041: protected static final String DOCUMENT_ID = "documentId";
042:
043: protected String getEvent() {
044: return "edit";
045: }
046:
047: /**
048: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
049: */
050: protected void doCheckPreconditions() throws Exception {
051: super .doCheckPreconditions();
052: if (hasErrors()) {
053: return;
054: }
055:
056: Document doc = getSourceDocument();
057: if (!getSourceDocument().getArea().equals(
058: Publication.AUTHORING_AREA)) {
059: addErrorMessage("This usecase can only be invoked in the authoring area!");
060: }
061:
062: UsecaseWorkflowHelper.checkWorkflow(this .manager, this ,
063: getEvent(), doc, getLogger());
064: }
065:
066: /**
067: * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
068: */
069: protected Node[] getNodesToLock() throws UsecaseException {
070: List nodes = new ArrayList();
071: if (getSourceDocument() != null) {
072: SiteStructure structure = getSourceDocument().area()
073: .getSite();
074: nodes.add(structure.getRepositoryNode());
075: }
076:
077: return (Node[]) nodes.toArray(new Node[nodes.size()]);
078: }
079:
080: /**
081: * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
082: */
083: protected void initParameters() {
084: super .initParameters();
085: Document document = getSourceDocument();
086: try {
087: if (document != null && document.exists()) {
088: setParameter(DOCUMENT_ID, document.getUUID());
089: setParameter(LABEL, document.getLink().getLabel());
090: }
091: } catch (final DocumentException e) {
092: throw new RuntimeException(e);
093: }
094: }
095:
096: /**
097: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
098: */
099: protected void doCheckExecutionConditions() throws Exception {
100: String label = getParameterAsString(LABEL);
101: if (label.trim().equals("")) {
102: addErrorMessage("missing-navigation-title");
103: }
104: }
105:
106: /**
107: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
108: */
109: protected void doExecute() throws Exception {
110: super .doExecute();
111:
112: Document document = getSourceDocument();
113: String label = getParameterAsString(LABEL).trim();
114: document.getLink().setLabel(label);
115:
116: WorkflowUtil.invoke(this.manager, getSession(), getLogger(),
117: document, getEvent());
118:
119: }
120: }
|