<commit_before>/*
 * Copyright  1999-2005 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.lenya.cms.site.usecases;

import java.util.Arrays;

import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.workflow.DocumentWorkflowable;
import org.apache.lenya.workflow.Version;
import org.apache.lenya.workflow.Workflow;
import org.apache.lenya.workflow.WorkflowManager;

/**
 * Usecase to display the overview tab in the site area for a document.
 * 
 * @version $Id$
 */
public class Overview extends SiteUsecase {

    protected static final String RESOURCE_TYPE = "resourcetype";
    protected static final String LASTMODIFIED = "lastmodified";
    protected static final String LANGUAGES = "languages";
    protected static final String STATE = "state";
    protected static final String ISLIVE = "isLive";
    protected static final String VISIBLE_IN_NAVIGATION = "visibleInNav";

    /**
     * Ctor.
     */
    public Overview() {
        super();
    }

    /**
     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
     */
    protected void initParameters() {
        super.initParameters();

        WorkflowManager resolver = null;
        try {
            Document doc = getSourceDocument();

            // read parameters from Dublin Core meta-data
            MetaData dc = doc.getMetaDataManager().getDublinCoreMetaData();
            setParameter(DublinCore.ELEMENT_TITLE, dc.getFirstValue(DublinCore.ELEMENT_TITLE));
            setParameter(DublinCore.ELEMENT_DESCRIPTION,
                    dc.getFirstValue(DublinCore.ELEMENT_DESCRIPTION));

            // read parameters from document attributes
            setParameter(LANGUAGES, doc.getLanguages());
            setParameter(LASTMODIFIED, doc.getLastModified());
            setParameter(RESOURCE_TYPE, doc.getResourceType());
            boolean visible = SiteUtil.isVisibleInNavigation(this.manager, doc);
            setParameter(VISIBLE_IN_NAVIGATION, Boolean.toString(visible));

            DocumentWorkflowable workflowable = new DocumentWorkflowable(this.manager,
                    getSession(),
                    doc,
                    getLogger());
            resolver = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
            if (resolver.hasWorkflow(workflowable)) {
                Workflow workflow = resolver.getWorkflowSchema(workflowable);
                String[] variableNames = workflow.getVariableNames();
                Version latestVersion = workflowable.getLatestVersion();
                Boolean isLive = null;
                if (latestVersion != null) {
                    setParameter(STATE, latestVersion.getState());
                    if (Arrays.asList(variableNames).contains(ISLIVE)) {
                        isLive = Boolean.valueOf(latestVersion.getValue(ISLIVE));<commit_msg>display the last modified date in iso-8601 format<commit_after>/*
 * Copyright  1999-2005 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.lenya.cms.site.usecases;

import java.text.SimpleDateFormat;
import java.util.Arrays;

import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.workflow.DocumentWorkflowable;
import org.apache.lenya.workflow.Version;
import org.apache.lenya.workflow.Workflow;
import org.apache.lenya.workflow.WorkflowManager;

/**
 * Usecase to display the overview tab in the site area for a document.
 * 
 * @version $Id$
 */
public class Overview extends SiteUsecase {

    protected static final String RESOURCE_TYPE = "resourcetype";
    protected static final String LASTMODIFIED = "lastmodified";
    protected static final String LANGUAGES = "languages";
    protected static final String STATE = "state";
    protected static final String ISLIVE = "isLive";
    protected static final String VISIBLE_IN_NAVIGATION = "visibleInNav";

    /**
     * Ctor.
     */
    public Overview() {
        super();
    }

    /**
     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
     */
    protected void initParameters() {
        super.initParameters();

        WorkflowManager resolver = null;
        try {
            Document doc = getSourceDocument();

            // read parameters from Dublin Core meta-data
            MetaData dc = doc.getMetaDataManager().getDublinCoreMetaData();
            setParameter(DublinCore.ELEMENT_TITLE, dc.getFirstValue(DublinCore.ELEMENT_TITLE));
            setParameter(DublinCore.ELEMENT_DESCRIPTION,
                    dc.getFirstValue(DublinCore.ELEMENT_DESCRIPTION));

            // read parameters from document attributes
            setParameter(LANGUAGES, doc.getLanguages());
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
            String lastModified = format.format(getSourceDocument().getLastModified());
            setParameter(LASTMODIFIED, lastModified);
            setParameter(RESOURCE_TYPE, doc.getResourceType());
            boolean visible = SiteUtil.isVisibleInNavigation(this.manager, doc);
            setParameter(VISIBLE_IN_NAVIGATION, Boolean.toString(visible));

            DocumentWorkflowable workflowable = new DocumentWorkflowable(this.manager,
                    getSession(),
                    doc,
                    getLogger());
            resolver = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
            if (resolver.hasWorkflow(workflowable)) {
                Workflow workflow = resolver.getWorkflowSchema(workflowable);
                String[] variableNames = workflow.getVariableNames();
                Version latestVersion = workflowable.getLatestVersion();
                Boolean isLive = null;
                if (latestVersion != null) {
                    setParameter(STATE, latestVersion.getState());
                    if (Arrays.asList(variableNames).contains(ISLIVE)) {
                        isLive = Boolean.valueOf(latestVersion.getValue(ISLIVE));
{'fraction_non_alphanumeric': 0.09069431683948025, 'fraction_numerical': 0.0036750229688935557, 'mean_word_length': 2.917737789203085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7147808', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2015, 'n_words': 507}