You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/01/03 17:54:43 UTC

svn commit: r124009 - lenya/trunk/src/java/org/apache/lenya/cms/site/usecases

Author: andreas
Date: Mon Jan  3 08:54:42 2005
New Revision: 124009

URL: http://svn.apache.org/viewcvs?view=rev&rev=124009
Log:
refactor usecase packages
Added:
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Move.java
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java
   lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java?view=auto&rev=124009
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java	Mon Jan  3 08:54:42 2005
@@ -0,0 +1,101 @@
+/*
+ * Copyright  1999-2004 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.Map;
+import org.apache.cocoon.servlet.multipart.Part;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.ResourcesManager;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.site.usecases.SiteUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to Assets a resource.
+ * 
+ * @version $Id: Assets.java 123984 2005-01-03 15:02:18Z andreas $
+ */
+public class Assets extends SiteUsecase {
+	
+	private ResourcesManager resourcesManager = null;
+
+	/**
+     * Ctor.
+     */
+    public Assets() {
+        super();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doInitialize()
+     */
+    protected void doInitialize() {
+        super.doInitialize();
+        resourcesManager = getSourceDocument().getResourcesManager();
+    }
+            
+     /**
+     * Validates the request parameters.
+     * @throws UsecaseException if an error occurs.
+     */
+    void validate() throws UsecaseException {
+        String title = getParameterAsString("title");
+        String creator = getParameterAsString("creator");
+        String rights = getParameterAsString("rights");
+
+        if (title.length() == 0) {
+            addErrorMessage("Please enter a title.");
+        }
+
+   }
+
+    /**
+     * @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();
+        String title = getParameterAsString("title");
+        String creator = getParameterAsString("creator");
+        String rights = getParameterAsString("rights");
+        Part file = (Part)getParameter("file");
+
+        Map metadata = null;
+        metadata.put("title",title);
+        metadata.put("cretor",creator);
+        metadata.put("rights",rights);
+        try {
+        	resourcesManager.addResource(file, metadata);
+        } catch (Exception e) {
+            addErrorMessage("The resource could not be added.");
+        }
+    }
+
+    /**
+     * @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);
+    }
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java?view=auto&rev=124009
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java	Mon Jan  3 08:54:42 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright  1999-2004 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.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to create a resource.
+ * 
+ * @version $Id: Create.java 123982 2005-01-03 15:01:19Z andreas $
+ */
+public class Create extends DocumentUsecase {
+
+	/**
+     * Ctor.
+     */
+    public Create() {
+        super();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doInitialize()
+     */
+    protected void doInitialize() {
+        super.doInitialize();
+    }
+            
+     /**
+     * Validates the request parameters.
+     * @throws UsecaseException if an error occurs.
+     */
+    void validate() throws UsecaseException {
+    }
+
+    /**
+     * @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);
+
+    }
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Move.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Move.java?view=auto&rev=124009
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Move.java	Mon Jan  3 08:54:42 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright  1999-2004 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.publication.Document;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.site.usecases.SiteUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to move a resource.
+ * 
+ * @version $Id: Move.java 123984 2005-01-03 15:02:18Z andreas $
+ */
+public class Move extends SiteUsecase {
+
+	/**
+     * Ctor.
+     */
+    public Move() {
+        super();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doInitialize()
+     */
+    protected void doInitialize() {
+        super.doInitialize();
+    }
+            
+     /**
+     * Validates the request parameters.
+     * @throws UsecaseException if an error occurs.
+     */
+    void validate() throws UsecaseException {
+    }
+
+    /**
+     * @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);
+    }
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java?view=auto&rev=124009
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java	Mon Jan  3 08:54:42 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright  1999-2004 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.dublincore.DublinCore;
+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 {
+	private DublinCore dc;
+
+	/**
+     * Ctor.
+     */
+    public Overview() {
+        super();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doInitialize()
+     */
+    protected void doInitialize() {
+        super.doInitialize();
+        dc = getSourceDocument().getDublinCore();
+        try {
+	        setParameter("languages", getSourceDocument().getLanguages());
+	        setParameter("title", dc.getFirstValue(DublinCore.ELEMENT_TITLE));
+	        setParameter("description", dc.getFirstValue(DublinCore.ELEMENT_DESCRIPTION));
+	        setParameter("lastmodified", "");
+	        setParameter("resourcetype", "");
+	        setParameter("live", "");
+        } catch (Exception e) {
+        	addErrorMessage("Could not read a value.");
+        	getLogger().error("Could not read value for Overview usecase. " + e.toString());
+        }
+    }
+            
+     /**
+     * Validates the request parameters.
+     * @throws UsecaseException if an error occurs.
+     */
+    void validate() throws UsecaseException {
+   }
+
+    /**
+     * @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);
+    }
+}
\ No newline at end of file

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java?view=auto&rev=124009
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/SiteUsecase.java	Mon Jan  3 08:54:42 2005
@@ -0,0 +1,84 @@
+/*
+ * Copyright  1999-2004 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.publication.Document;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.workflow.WorkflowFactory;
+import org.apache.lenya.workflow.WorkflowInstance;
+
+/**
+ * Super class for site related usecases.
+ * 
+ * @version $Id$
+ */
+public class SiteUsecase extends DocumentUsecase {
+
+    protected Document doc = null;
+    protected WorkflowInstance instance = null;
+    protected static final String AREA = "area";
+    protected static final String DOCUMENTID = "documentid";
+    protected static final String LANGUAGEEXISTS = "languageexists";
+    protected static final String STATE = "state";
+    protected static final String ISLIVE = "is_live";
+
+    /**
+     * Ctor.
+     */
+    public SiteUsecase() {
+        super();
+    }
+    
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doInitialize()
+    /*TODO make common parameters available to site usecases: area, documentid, languageexists etc
+     * may need to take special areas into acccount, such as info-authoring */
+    protected void doInitialize() {
+        super.doInitialize();
+        doc = getSourceDocument();
+        try {
+            WorkflowFactory factory = WorkflowFactory.newInstance();
+            if (factory.hasWorkflow(getSourceDocument())) {
+                instance = factory.buildInstance(getSourceDocument());
+                setParameter(STATE, instance.getCurrentState().toString());
+                String[] variableNames = instance.getWorkflow().getVariableNames();
+                if (Arrays.asList(variableNames).contains(ISLIVE)) {
+                    setParameter("islive", Boolean.valueOf(instance.getValue(ISLIVE)));
+                }
+            } else {
+                setParameter("state", "");
+            }
+        } catch (Exception e) {
+        	getLogger().error("Could not get workflow state.");
+        	addErrorMessage("Could not get workflow state.");
+        }
+        setParameter(AREA, this.doc.getArea());
+        setParameter(DOCUMENTID, this.doc.getId());
+        setParameter(LANGUAGEEXISTS, "true");
+    }
+
+    /**
+     * @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);
+    }
+
+    
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org