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 org.apache.lenya.cms.publication.Document;
021: import org.apache.lenya.cms.repository.History;
022: import org.apache.lenya.cms.repository.Revision;
023: import org.apache.lenya.cms.workflow.WorkflowUtil;
024: import org.apache.lenya.workflow.Version;
025: import org.apache.lenya.workflow.Workflow;
026: import org.apache.lenya.workflow.Workflowable;
027:
028: /**
029: * Usecase to display revisions of a resource.
030: *
031: * @version $Id: Revisions.java 565858 2007-08-14 18:58:48Z rfrovarp $
032: */
033: public class Revisions extends SiteUsecase {
034:
035: /**
036: * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters() TODO
037: * filter out checkin entries
038: */
039: protected void initParameters() {
040: super .initParameters();
041: Document sourceDoc = getSourceDocument();
042: if (sourceDoc != null) {
043: try {
044: History history = sourceDoc.getRepositoryNode()
045: .getHistory();
046:
047: int[] numbers = history.getRevisionNumbers();
048: Revision[] revisions = new Revision[numbers.length];
049: for (int i = 0; i < numbers.length; i++) {
050: revisions[i] = history.getRevision(numbers[i]);
051: }
052: setParameter("revisions", revisions);
053:
054: Boolean canRollback = Boolean.valueOf(WorkflowUtil
055: .canInvoke(this .manager, getDocumentFactory()
056: .getSession(), getLogger(), sourceDoc,
057: getEvent()));
058: setParameter("canRollback", canRollback);
059:
060: if (WorkflowUtil.hasWorkflow(this .manager,
061: getSession(), getLogger(), sourceDoc)) {
062: Workflowable workflowable = WorkflowUtil
063: .getWorkflowable(this .manager,
064: getSession(), getLogger(),
065: sourceDoc);
066: Version latestVersion = workflowable
067: .getLatestVersion();
068: String state;
069: if (latestVersion != null) {
070: state = latestVersion.getState();
071: } else {
072: Workflow workflow = WorkflowUtil
073: .getWorkflowSchema(this .manager,
074: getSession(), getLogger(),
075: sourceDoc);
076: state = workflow.getInitialState();
077: }
078: setParameter("workflowState", state);
079: }
080: } catch (final Exception e) {
081: throw new RuntimeException(e);
082: }
083:
084: /*
085: * // since we need both state and canInvoke, we could deal with the
086: * avalon // component ourselves rather than using WorkflowUtil -
087: * saves one // service manager lookup. // problem is that
088: * DocumentWorkflowable is not public and Workflowable is abstract :(
089: *
090: * WorkflowManager wfManager = null; String workflowState; Boolean
091: * canRollback; try { wfManager = (WorkflowManager)
092: * this.manager.lookup(WorkflowManager.ROLE); Workflowable
093: * workflowable = new DocumentWorkflowable( this.manager,
094: * getDocumentFactory().getSession(), sourceDoc, getLogger() );
095: * workflowState = workflowable.getLatestVersion().getState();
096: * canRollback = new Boolean(wfManager.canInvoke(workflowable,
097: * WORKFLOW_EVENT_EDIT)); } catch (ServiceException e) { throw new
098: * RuntimeException(e); } finally { if (wfManager != null) {
099: * manager.release(wfManager); } } setParameter("workflowState",
100: * workflowState); setParameter("canRollback", canRollback);
101: */
102:
103: }
104: }
105:
106: protected String getEvent() {
107: return getParameterAsString("workflowEvent");
108: }
109: }
|