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 2008/02/06 22:59:21 UTC

svn commit: r619170 - in /lenya/trunk/src/modules-core: sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ usecase/java/src/org/apache/lenya/cms/cocoon/transformation/ usecase/java/src/org/apache/lenya/cms/usecase/

Author: andreas
Date: Wed Feb  6 13:59:18 2008
New Revision: 619170

URL: http://svn.apache.org/viewvc?rev=619170&view=rev
Log:
Add 'checked' attribute to menu item depending on the 'itemChecked' parameter of the corresponding usecase. This allows to make the publication menu static because the XSP logic is not needed anymore.

Modified:
    lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeVisibility.java
    lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java
    lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java

Modified: lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeVisibility.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeVisibility.java?rev=619170&r1=619169&r2=619170&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeVisibility.java (original)
+++ lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeVisibility.java Wed Feb  6 13:59:18 2008
@@ -21,11 +21,13 @@
 import java.util.List;
 
 import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.repository.Node;
 import org.apache.lenya.cms.site.SiteNode;
 import org.apache.lenya.cms.site.SiteStructure;
 import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.Usecase;
 import org.apache.lenya.cms.usecase.UsecaseException;
 import org.apache.lenya.cms.workflow.WorkflowUtil;
 import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
@@ -37,6 +39,20 @@
 
     protected String getEvent() {
         return "edit";
+    }
+
+    public Object getParameter(String name) {
+        if (name.equals(Usecase.PARAMETER_ITEM_STATE)) {
+            Document doc = getSourceDocument();
+            try {
+                return doc != null ? Boolean.valueOf(doc.getLink().getNode().isVisible()) : null;
+            } catch (DocumentException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        else {
+            return super.getParameter(name);
+        }
     }
 
     /**

Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java?rev=619170&r1=619169&r2=619170&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java Wed Feb  6 13:59:18 2008
@@ -70,6 +70,12 @@
      * <code>USECASE_ATTRIBUTE</code> The usecase attribute
      */
     public static final String USECASE_ATTRIBUTE = "usecase";
+    
+    /**
+     * The value of the <em>checked</em> attribute can either be <em>true</em> or <em>false</em>.
+     */
+    public static final String CHECKED_ATTRIBUTE = "checked";
+    
     /**
      * Comment for <code>HREF_ATTRIBUTE</code> The href attribute
      */
@@ -88,7 +94,7 @@
     public void startElement(String uri, String localName, String raw, Attributes attr)
             throws SAXException {
 
-        Attributes attributes = attr;
+        AttributesImpl attributes = new AttributesImpl(attr);
         List messages = null;
 
         UsecaseResolver usecaseResolver = null;
@@ -109,7 +115,7 @@
                         if (getLogger().isDebugEnabled()) {
                             getLogger().debug("Usecase not authorized");
                         }
-                        attributes = removeHrefAttribute(attr);
+                        removeHrefAttribute(attributes);
                         UsecaseMessage message = new UsecaseMessage("Access denied");
                         messages = Collections.singletonList(message);
                     }
@@ -129,10 +135,14 @@
                             if (getLogger().isDebugEnabled()) {
                                 getLogger().debug("Usecase preconditions not complied");
                             }
-
-                            attributes = removeHrefAttribute(attr);
+                            removeHrefAttribute(attributes);
                             messages = usecase.getErrorMessages();
                         }
+                        Object itemState = usecase.getParameter(Usecase.PARAMETER_ITEM_STATE);
+                        if (itemState != null && itemState instanceof Boolean) {
+                            Boolean state = (Boolean) itemState;
+                            attributes.addAttribute("", CHECKED_ATTRIBUTE, CHECKED_ATTRIBUTE, "CDATA", state.toString());
+                        }
                     } finally {
                         if (usecase != null) {
                             usecaseResolver.release(usecase);
@@ -159,17 +169,13 @@
     /**
      * Removes the <code>href</code> attribute.
      * 
-     * @param attr The original attributes.
-     * @return An attributes object.
+     * @param attributes The attributes.
      */
-    protected Attributes removeHrefAttribute(Attributes attr) {
-        Attributes attributes = attr;
+    protected void removeHrefAttribute(AttributesImpl attributes) {
         int hrefIndex = attributes.getIndex(HREF_ATTRIBUTE);
         if (hrefIndex > -1) {
-            attributes = new AttributesImpl(attr);
-            ((AttributesImpl) attributes).removeAttribute(hrefIndex);
+            attributes.removeAttribute(hrefIndex);
         }
-        return attributes;
     }
 
     protected void addMessages(List messages) throws SAXException {

Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java?rev=619170&r1=619169&r2=619170&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java Wed Feb  6 13:59:18 2008
@@ -35,6 +35,13 @@
     String ROLE = Usecase.class.getName();
     
     /**
+     * The <em>itemState</em> parameter is used to ask the usecase if the corresponding menu item
+     * is checked. The parameter value is supposed to be a {@link java.lang.Boolean} object. If the
+     * value is null, the <em>checked</em> attribute is not added.
+     */
+    public static final String PARAMETER_ITEM_STATE = "itemState";
+    
+    /**
      * @param url The URL the usecase is invoked on.
      */
     void setSourceURL(String url);



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