Hi Andreas

I noticed (apart from some formatting changes) that you extended the
document info module with the possibility to get the document's
visibility in navigation. I wonder if that's the right place as document
visibility is dependent on the chosen navigation. Wouldn't it be
preferable to have this property in the navigation module (like
sitetree) itself?

- Felix

[EMAIL PROTECTED] wrote:
Author: andreas
Date: Wed Jan 25 02:59:30 2006
New Revision: 372193

URL: http://svn.apache.org/viewcvs?rev=372193&view=rev
Log:
Added menu item to switch navigation visibility

Added:
    
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java
Modified:
    
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java
    lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
    lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp

Modified: 
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java?rev=372193&r1=372192&r2=372193&view=diff
==============================================================================
--- 
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java
 (original)
+++ 
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java
 Wed Jan 25 02:59:30 2006
@@ -39,21 +39,23 @@
 import org.apache.lenya.cms.publication.PublicationUtil;
 import org.apache.lenya.cms.repository.RepositoryUtil;
 import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteUtil;
/**
  * Input module to get document information.
- * 
{doc-info:{publication-id}:{area}:{document-id}:{document-language}:{property}}
- * where {property} may be:
+ * 
{doc-info:{publication-id}:{area}:{document-id}:{document-language}:{property}} 
where {property}
+ * may be:
  * <ul>
- *   <li>resourceType</li>
- *   <li>lastModified</li>
- *   <li>mimeType</li>
+ * <li>resourceType</li>
+ * <li>lastModified</li>
+ * <li>mimeType</li>
  * </ul>
  */
 public class DocumentInfoModule extends AbstractInputModule implements 
Serviceable {
protected ServiceManager manager; - +
     // Input module parameters:
     protected final static String PARAM_PUBLICATION_ID = "publication-id";
     protected final static String PARAM_AREA = "area";
@@ -61,31 +63,34 @@
     protected final static String PARAM_DOCUMENT_LANGUAGE = 
"document-language";
     protected final static String PARAM_PROPERTY = "property";
     protected final static int MIN_MANDATORY_PARAMS = 5;
- +
     protected final static String RESOURCE_TYPE = "resourceType";
     protected final static String LAST_MODIFIED = "lastModified";
     protected final static String MIME_TYPE = "mimeType";
- - protected final static String[] PARAMS = {PARAM_PUBLICATION_ID, PARAM_AREA,
-        PARAM_DOCUMENT_ID, PARAM_DOCUMENT_LANGUAGE, PARAM_PROPERTY};
- + protected final static String VISIBLE_IN_NAVIGATION = "visibleInNav";
+
+    protected final static String[] PARAMS = { PARAM_PUBLICATION_ID, 
PARAM_AREA, PARAM_DOCUMENT_ID,
+            PARAM_DOCUMENT_LANGUAGE, PARAM_PROPERTY, VISIBLE_IN_NAVIGATION };
+
     protected final static String META_RESOURCE_TYPE = "resourceType";
- +
     /**
      * Parse the parameters and return a document.
+     * @param publicationId The publication ID.
+     * @param area The area.
+     * @param docId The document ID.
+     * @param docLang The document language.
+     * @param objectModel The object model.
      * @return The document object created.
      * @throws ConfigurationException
      */
-    protected Document getDocument(String publicationId, String area, String 
docId, String docLang, Map objectModel)
-    throws ConfigurationException
-    {
+    protected Document getDocument(String publicationId, String area, String 
docId, String docLang,
+            Map objectModel) throws ConfigurationException {
         Document document = null;
- +
         Request request = ObjectModelHelper.getRequest(objectModel);
         Session session = RepositoryUtil.getSession(request, getLogger());
-        DocumentIdentityMap docFactory = new DocumentIdentityMap(session,
-                this.manager,
-                getLogger());
+        DocumentIdentityMap docFactory = new DocumentIdentityMap(session, 
this.manager, getLogger());
try {
             Publication publication = 
PublicationUtil.getPublication(this.manager, publicationId);
@@ -96,26 +101,25 @@
         }
         return document;
     }
- +
     /**
      * @see 
org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
      *      org.apache.avalon.framework.configuration.Configuration, 
java.util.Map)
      */
     public Object getAttribute(String name, Configuration modeConf, Map 
objectModel)
-    throws ConfigurationException
-    {
+            throws ConfigurationException {
         Object value = null;
- - InputModuleParameters params =
-            new InputModuleParameters(name, PARAMS, MIN_MANDATORY_PARAMS);
+
+        InputModuleParameters params = new InputModuleParameters(name, PARAMS, 
MIN_MANDATORY_PARAMS);
try { - Document document = getDocument(params.getParameter(PARAM_PUBLICATION_ID), + Document document = getDocument(params.getParameter(PARAM_PUBLICATION_ID),
                     params.getParameter(PARAM_AREA),
                     params.getParameter(PARAM_DOCUMENT_ID),
-                    params.getParameter(PARAM_DOCUMENT_LANGUAGE), objectModel);
+                    params.getParameter(PARAM_DOCUMENT_LANGUAGE),
+                    objectModel);
             String attribute = params.getParameter(PARAM_PROPERTY);
- +
             if (attribute.equals(RESOURCE_TYPE)) {
                 value = getResourceType(document);
             } else if (attribute.equals(LAST_MODIFIED)) {
@@ -123,22 +127,32 @@
             } else if (attribute.equals(MIME_TYPE)) {
                 value = getMimeType(document);
                 if (value == null)
-                    throw new ConfigurationException("Attribute '" + attribute + "' 
not defined [" +
-                            name + "]");
+                    throw new ConfigurationException("Attribute '" + attribute + "' 
not defined ["
+                            + name + "]");
+            } else if (attribute.equals(VISIBLE_IN_NAVIGATION)) {
+                value = Boolean.toString(isVisibleInNavigation(document));
             } else {
-                throw new ConfigurationException("Attribute '" + attribute + "' not 
supported [" +
-                        name + "]");
+                throw new ConfigurationException("Attribute '" + attribute + "' not 
supported ["
+                        + name + "]");
             }
         } catch (ParameterException e) {
             throw new ConfigurationException("Error getting input module 
parameters.", e);
         }
- +
         return value;
     }
- - protected String getResourceType(Document document)
-    throws ConfigurationException
-    {
+
+    protected boolean isVisibleInNavigation(Document document) throws 
ConfigurationException {
+        try {
+            return SiteUtil.isVisibleInNavigation(this.manager, document);
+        } catch (SiteException e) {
+            throw new ConfigurationException("Obtaining navigation visibility 
failed ["
+                    + document.getId() + "]: " + e.getMessage(), e);
+        }
+
+    }
+
+    protected String getResourceType(Document document) throws 
ConfigurationException {
         String resourceType = null;
         MetaData metaData = null;
         try {
@@ -147,7 +161,7 @@
             throw new ConfigurationException("Obtaining custom meta data value for 
["
                     + document.getSourceURI() + "] failed: " + e.getMessage(), 
e);
         }
- +
         try {
             resourceType = metaData.getFirstValue(META_RESOURCE_TYPE);
         } catch (DocumentException e) {
@@ -163,9 +177,7 @@
      * @return Formatted HTTP date string.
      * @throws ConfigurationException
      */
-    protected String getLastModified(Document document)
-    throws ConfigurationException
-    {
+    protected String getLastModified(Document document) throws 
ConfigurationException {
         SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy 
HH:mm:ss z");
         return httpDateFormat.format(document.getLastModified());
     }
@@ -176,9 +188,7 @@
      * @return Mime-type of document.
      * @throws ConfigurationException
      */
-    protected String getMimeType(Document document)
-    throws ConfigurationException
-    {
+    protected String getMimeType(Document document) throws 
ConfigurationException {
         String mimeType = null;
         MetaData metaData = null;
         try {
@@ -187,7 +197,7 @@
             throw new ConfigurationException("Obtaining custom meta data value 
failed ["
                     + document.getSourceURI() + "]: " + e.getMessage(), e);
         }
- +
         try {
             mimeType = metaData.getFirstValue(DublinCore.ELEMENT_FORMAT);
         } catch (DocumentException e) {

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java?rev=372193&r1=372192&r2=372193&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java Wed Jan 25 
02:59:30 2006
@@ -81,8 +81,10 @@
      */
     public static SiteStructure getSiteStructure(ServiceManager manager, 
Document document)
             throws SiteException {
-        return SiteUtil.getSiteStructure(manager, document.getIdentityMap(), 
document
-                .getPublication(), document.getArea());
+        return SiteUtil.getSiteStructure(manager,
+                document.getIdentityMap(),
+                document.getPublication(),
+                document.getArea());
     }
/**
@@ -227,8 +229,11 @@
             DocumentSet subSite = SiteUtil.getSubSite(manager, source);
             Document[] docs = subSite.getDocuments();
             for (int i = 0; i < docs.length; i++) {
-                Document targetDoc = 
SiteUtil.getTransferedDocument(siteManager, docs[i], source,
-                        target, mode);
+                Document targetDoc = 
SiteUtil.getTransferedDocument(siteManager,
+                        docs[i],
+                        source,
+                        target,
+                        mode);
                 if (targetDoc != null) {
                     map.put(docs[i], targetDoc);
                 }
@@ -257,8 +262,10 @@
         String suffix = source.getId().substring(sourceId.length());
         String targetId = baseTarget.getId() + suffix;
- Document target = source.getIdentityMap().get(baseTarget.getPublication(), targetArea,
-                targetId, source.getLanguage());
+        Document target = 
source.getIdentityMap().get(baseTarget.getPublication(),
+                targetArea,
+                targetId,
+                source.getLanguage());
         switch (mode) {
         case MODE_REPLACE:
             break;
@@ -298,7 +305,9 @@
             DocumentSet subSite = SiteUtil.getSubSite(manager, source);
             Document[] docs = subSite.getDocuments();
             for (int i = 0; i < docs.length; i++) {
-                Document target = SiteUtil.getTransferedDocument(siteManager, 
docs[i], targetArea,
+                Document target = SiteUtil.getTransferedDocument(siteManager,
+                        docs[i],
+                        targetArea,
                         mode);
                 if (target != null) {
                     map.put(docs[i], target);
@@ -354,6 +363,34 @@
                     .getSiteManagerHint());
return siteManager.getAvailableDocument(document);
+        } catch (Exception e) {
+            throw new SiteException(e);
+        } finally {
+            if (selector != null) {
+                if (siteManager != null) {
+                    selector.release(siteManager);
+                }
+                manager.release(selector);
+            }
+        }
+    }
+
+    /**
+     * @param manager The site manager.
+     * @param document The document.
+     * @return If the document is visible in the navigation.
+     * @throws SiteException if an error occurs.
+     */
+    public static boolean isVisibleInNavigation(ServiceManager manager, 
Document document)
+            throws SiteException {
+        ServiceSelector selector = null;
+        SiteManager siteManager = null;
+        try {
+            selector = (ServiceSelector) manager.lookup(SiteManager.ROLE + 
"Selector");
+            siteManager = (SiteManager) 
selector.select(document.getPublication()
+                    .getSiteManagerHint());
+
+            return siteManager.isVisibleInNav(document);
         } catch (Exception e) {
             throw new SiteException(e);
         } finally {

Modified: 
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java?rev=372193&r1=372192&r2=372193&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java 
(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeLabel.java 
Wed Jan 25 02:59:30 2006
@@ -22,6 +22,7 @@
 import org.apache.lenya.cms.repository.Node;
 import org.apache.lenya.cms.site.SiteManager;
 import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.site.SiteUtil;
 import org.apache.lenya.cms.usecase.DocumentUsecase;
 import org.apache.lenya.cms.usecase.UsecaseException;
@@ -55,25 +56,12 @@
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
      */
     protected Node[] getNodesToLock() throws UsecaseException {
-        SiteManager siteManager = null;
-        ServiceSelector selector = null;
         try {
-            Document doc = getSourceDocument();
-            selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + 
"Selector");
-            siteManager = (SiteManager) 
selector.select(doc.getPublication().getSiteManagerHint());
-            SiteStructure structure = 
siteManager.getSiteStructure(doc.getIdentityMap(), doc
-                    .getPublication(), doc.getArea());
+            SiteStructure structure = SiteUtil.getSiteStructure(this.manager, 
getSourceDocument());
             Node[] objects = { structure.getRepositoryNode() };
             return objects;
         } catch (Exception e) {
             throw new UsecaseException(e);
-        } finally {
-            if (selector != null) {
-                if (siteManager != null) {
-                    selector.release(siteManager);
-                }
-                this.manager.release(selector);
-            }
         }
     }
Added: 
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java?rev=372193&view=auto
==============================================================================
--- 
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java 
(added)
+++ 
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/ChangeVisibility.java 
Wed Jan 25 02:59:30 2006
@@ -0,0 +1,72 @@
+/*
+ * 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.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.site.SiteUtil;
+import org.apache.lenya.cms.usecase.DocumentUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Switch the navigation visibility of a document.
+ */
+public class ChangeVisibility extends DocumentUsecase {
+
+    protected void doExecute() throws Exception {
+ + super.doExecute(); + + ServiceSelector selector = null;
+        SiteManager siteManager = null;
+        try {
+            Document document = getSourceDocument();
+            selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + 
"Selector");
+            siteManager = (SiteManager) 
selector.select(document.getPublication()
+                    .getSiteManagerHint());
+
+            boolean visible = siteManager.isVisibleInNav(document);
+            siteManager.setVisibleInNav(document, !visible);
+        } catch (final Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (selector != null) {
+                if (siteManager != null) {
+                    selector.release(siteManager);
+                }
+                this.manager.release(selector);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
+     */
+    protected Node[] getNodesToLock() throws UsecaseException {
+        try {
+            SiteStructure structure = SiteUtil.getSiteStructure(this.manager, 
getSourceDocument());
+            Node[] objects = { structure.getRepositoryNode() };
+            return objects;
+        } catch (Exception e) {
+            throw new UsecaseException(e);
+        }
+    }
+
+}

Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?rev=372193&r1=372192&r2=372193&view=diff
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Wed Jan 25 02:59:30 2006
@@ -447,6 +447,7 @@
     <component-instance name="site.changeNodeID" logger="lenya.site" 
class="org.apache.lenya.cms.site.usecases.ChangeNodeID">
       <view template="usecases/site/changeNodeID.jx"/>
     </component-instance>
+    <component-instance name="site.changeVisibility" logger="lenya.site" 
class="org.apache.lenya.cms.site.usecases.ChangeVisibility"/>
     <component-instance name="site.cut" logger="lenya.site" 
class="org.apache.lenya.cms.site.usecases.Cut">
       <view template="usecases/site/cut.jx"/>
       <exit usecase="lucene.index">

Modified: lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp
URL: 
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp?rev=372193&r1=372192&r2=372193&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp 
(original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/config/menus/generic.xsp Wed Jan 
25 02:59:30 2006
@@ -54,6 +54,18 @@
       catch (Exception e) {
           throw new ProcessingException(e);
       }
+ + String visibilityChar;
+      String visible = <input:get-attribute module="doc-info" as="string">
+        <input:param name="name"><xsp:expr>document.getPublication().getId() + ":" + document.getArea() + ":" 
+ document.getId() + ":" + document.getLanguage() + ":visibleInNav"</xsp:expr></input:param>
+      </input:get-attribute>;
+      if (Boolean.valueOf(visible).booleanValue()) {
+          visibilityChar = "&#x2713;&#160;";
+      }
+      else {
+          visibilityChar = "&#x2717;&#160;";
+      }
+ </xsp:logic> <menus>
@@ -84,6 +96,7 @@
       <block authoring="false">
         <item uc:usecase="site.changeNodeID" href="?"><i18n:text>Rename 
URL</i18n:text></item>
         <item uc:usecase="site.changeLabel" href="?"><i18n:text>Edit Navigation 
Title</i18n:text></item>
+        <item uc:usecase="site.changeVisibility" 
href="?"><xsp:expr>visibilityChar</xsp:expr><i18n:text>Visible in 
Navigation</i18n:text></item>
       </block>
       <block authoring="false">
         <item uc:usecase="site.nudge" href="?direction=up"><i18n:text>Move 
Up</i18n:text></item>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
Felix Röthenbacher                  [EMAIL PROTECTED]
Wyona Inc.  -   Open Source Content Management   -   Apache Lenya
http://www.wyona.com                      http://lenya.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to