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.text.SimpleDateFormat;
021: import java.util.Arrays;
022: import java.util.Date;
023:
024: import org.apache.lenya.cms.metadata.MetaData;
025: import org.apache.lenya.cms.metadata.dublincore.DublinCore;
026: import org.apache.lenya.cms.publication.Document;
027: import org.apache.lenya.cms.site.usecases.SiteUsecase;
028: import org.apache.lenya.cms.workflow.WorkflowUtil;
029: import org.apache.lenya.workflow.Version;
030: import org.apache.lenya.workflow.Workflow;
031: import org.apache.lenya.workflow.WorkflowManager;
032: import org.apache.lenya.workflow.Workflowable;
033:
034: /**
035: * Usecase to display the overview tab in the site area for a document.
036: *
037: * @version $Id: Overview.java 557322 2007-07-18 16:40:35Z andreas $
038: */
039: public class Overview extends SiteUsecase {
040:
041: protected static final String LASTMODIFIED = "lastmodified";
042: protected static final String LANGUAGES = "languages";
043: protected static final String STATE = "state";
044: protected static final String ISLIVE = "isLive";
045: protected static final String VISIBLE_IN_NAVIGATION = "visibleInNav";
046: protected static final String WORKFLOW_VARIABLE_ISLIVE = "is_live";
047:
048: /**
049: * Ctor.
050: */
051: public Overview() {
052: super ();
053: }
054:
055: /**
056: * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
057: */
058: protected void initParameters() {
059: super .initParameters();
060:
061: WorkflowManager resolver = null;
062: try {
063: Document doc = getSourceDocument();
064: if (doc != null) {
065: // read parameters from Dublin Core meta-data
066: MetaData dc = doc.getMetaData(DublinCore.DC_NAMESPACE);
067: setParameter(DublinCore.ELEMENT_TITLE, dc
068: .getFirstValue(DublinCore.ELEMENT_TITLE));
069: setParameter(DublinCore.ELEMENT_DESCRIPTION, dc
070: .getFirstValue(DublinCore.ELEMENT_DESCRIPTION));
071:
072: // read parameters from document attributes
073: setParameter(LANGUAGES, doc.getLanguages());
074: SimpleDateFormat format = new SimpleDateFormat(
075: "yyyy-MM-dd HH:mm:ss Z");
076: String lastModified = format.format(new Date(
077: getSourceDocument().getLastModified()));
078: setParameter(LASTMODIFIED, lastModified);
079: boolean visible = doc.getLink().getNode().isVisible();
080: setParameter(VISIBLE_IN_NAVIGATION, Boolean
081: .valueOf(visible));
082:
083: Workflowable workflowable = WorkflowUtil
084: .getWorkflowable(this .manager, getSession(),
085: getLogger(), doc);
086: resolver = (WorkflowManager) this .manager
087: .lookup(WorkflowManager.ROLE);
088: if (resolver.hasWorkflow(workflowable)) {
089: Workflow workflow = resolver
090: .getWorkflowSchema(workflowable);
091: String[] variableNames = workflow
092: .getVariableNames();
093: Version latestVersion = workflowable
094: .getLatestVersion();
095: Boolean isLive = null;
096: if (latestVersion != null) {
097: setParameter(STATE, latestVersion.getState());
098: if (Arrays.asList(variableNames).contains(
099: WORKFLOW_VARIABLE_ISLIVE)) {
100: isLive = Boolean
101: .valueOf(latestVersion
102: .getValue(WORKFLOW_VARIABLE_ISLIVE));
103: }
104: } else {
105: setParameter(STATE, workflow.getInitialState());
106: if (Arrays.asList(variableNames).contains(
107: WORKFLOW_VARIABLE_ISLIVE)) {
108: isLive = Boolean
109: .valueOf(workflow
110: .getInitialValue(WORKFLOW_VARIABLE_ISLIVE));
111: }
112: }
113: setParameter(ISLIVE, isLive);
114: } else {
115: setParameter(STATE, "");
116: }
117: }
118:
119: } catch (final Exception e) {
120: addErrorMessage("Could not read a value. See log files for details.");
121: getLogger().error(
122: "Could not read value for Overview usecase. ", e);
123: } finally {
124: if (resolver != null) {
125: this .manager.release(resolver);
126: }
127: }
128: }
129:
130: /**
131: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
132: */
133: protected void doCheckPreconditions() throws Exception {
134: // don't complain if document is null
135: }
136:
137: }
|