/*
 * 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 org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.DocumentType;
import org.apache.lenya.cms.publication.DocumentTypeResolver;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;

/**
 * Usecase to display the overview tab in the site area for a document.
 * 
 * @version $Id: Overview.java 123984 2005-01-03 15:02:18Z andreas $
 */
public class Overview extends SiteUsecase {

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

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

        DocumentTypeResolver doctypeResolver = null;
        try {
            MetaData dc = (MetaData) getSourceDocument().getMetaDataManager().getDublinCoreMetaData();
            setParameter("languages", getSourceDocument().getLanguages());
            setParameter("title", dc.getFirstValue(DublinCore.ELEMENT_TITLE));

            doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
            DocumentType doctype = doctypeResolver.resolve(getSourceDocument());
            setParameter("languages", getSourceDocument().getLanguages());
            setParameter("lastmodified", getSourceDocument().getLastModified());
            setParameter("resourcetype", doctype.getName());
            setParameter("live", "");
        } catch (final Exception e) {
            addErrorMessage("Could not read a value. See log files for details.");
            getLogger().error("Could not read value for Overview usecase. ", e);
        } finally {
            if (doctypeResolver != null) {
                this.manager.release(doctypeResolver);
            }
        }
    }

    /**
     * Validates the request parameters.
     * @throws UsecaseException if an error occurs.
     */
    void validate() throws UsecaseException {
        // do nothing
    }

    /**
     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
     */
    protected void doCheckExecutionConditions() throws Exception {
        validate();
    }

    /**
     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
     */
    protected void doExecute() throws Exception {
        super.doExecute();
    }

    /**
     * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.Object)
     */
    public void setParameter(String name, Object value) {
        super.setParameter(name, value);
    }
}

@@ -781,124 +781,8 @@
 re;%0A
-import org.apache.lenya.cms.publication.DocumentType;%0Aimport org.apache.lenya.cms.publication.DocumentTypeResolver;%0A
 impo
@@ -1335,66 +1335,71 @@
     
-DocumentTypeResolver doctypeResolver = null;%0A        try %7B
+try %7B%0A            // read parameters from Dublin Core meta-data
 %0A   
@@ -1527,90 +1527,134 @@
 ter(
-%22languages%22, getSourceDocument().getLanguages());%0A            setParameter(%22title%22
+DublinCore.ELEMENT_TITLE, dc.getFirstValue(DublinCore.ELEMENT_TITLE));%0A            setParameter(DublinCore.ELEMENT_DESCRIPTION
 , dc
@@ -1683,29 +1683,35 @@
 ore.ELEMENT_
-TITLE
+DESCRIPTION
 ));%0A%0A       
@@ -1719,156 +1719,90 @@
     
-doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);%0A            DocumentType doctype = doctypeResolver.resolve(
+// read parameters from document attributes%0A            setParameter(%22languages%22, 
 getS
@@ -1816,16 +1816,31 @@
 cument()
+.getLanguages()
 );%0A     
@@ -1985,24 +1985,29 @@
 Modified());
+     
 %0A           
@@ -2040,27 +2040,58 @@
 e%22, 
-doctype.getName());
+getSourceDocument().getResourceType());           
 %0A   
@@ -2121,24 +2121,25 @@
 live%22, %22%22);%0A
+%0A
         %7D ca
@@ -2332,140 +2332,8 @@
 e);%0A
-        %7D finally %7B%0A            if (doctypeResolver != null) %7B%0A                this.manager.release(doctypeResolver);%0A            %7D%0A
     

read meta-data directly instead of using DocumentTypeResolver