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 2006/11/28 14:42:23 UTC

svn commit: r480037 - in /lenya/trunk/src: java/org/apache/lenya/cms/publication/util/ modules-core/linking/java/src/org/apache/lenya/cms/linking/ pubs/default/lenya/resources/i18n/ pubs/default/lenya/usecases/workflow/ pubs/default/modules/defaultusec...

Author: andreas
Date: Tue Nov 28 05:42:22 2006
New Revision: 480037

URL: http://svn.apache.org/viewvc?view=rev&rev=480037
Log:
Added link check to publish and deactivate usecases, removed obsolete DocumentReferencesHelper

Added:
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkException.java
Removed:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/util/DocumentReferencesHelper.java
Modified:
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkManagerImpl.java
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolver.java
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolverImpl.java
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkTarget.java
    lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml
    lenya/trunk/src/pubs/default/lenya/usecases/workflow/deactivate.jx
    lenya/trunk/src/pubs/default/lenya/usecases/workflow/publish.jx
    lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
    lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
    lenya/trunk/src/pubs/default/modules/defaultusecases/module.xml

Added: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkException.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkException.java?view=auto&rev=480037
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkException.java (added)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkException.java Tue Nov 28 05:42:22 2006
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.linking;
+
+/**
+ * Link exception.
+ */
+public class LinkException extends Exception {
+
+    private static final long serialVersionUID = -3304874622495079970L;
+
+    public LinkException() {
+        super();
+    }
+
+    public LinkException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+    }
+
+    public LinkException(String arg0) {
+        super(arg0);
+    }
+
+    public LinkException(Throwable arg0) {
+        super(arg0);
+    }
+
+
+}

Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkManagerImpl.java?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkManagerImpl.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkManagerImpl.java Tue Nov 28 05:42:22 2006
@@ -80,7 +80,7 @@
                 Link[] links = getLinksFrom(allDocs[d]);
                 for (int l = 0; l < links.length; l++) {
                     LinkTarget linkTarget = resolver.resolve(allDocs[d], links[l].getUri());
-                    if (linkTarget.getDocument().equals(target)) {
+                    if (linkTarget.exists() && linkTarget.getDocument().equals(target)) {
                         docs.add(allDocs[d]);
                     }
                 }

Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolver.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolver.java?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolver.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolver.java Tue Nov 28 05:42:22 2006
@@ -83,8 +83,7 @@
      * 
      * @param currentDocument The document which contains the link.
      * @param linkUri The link URI.
-     * @return A link target or <code>null</code> if the target document does not
-     *         exist.
+     * @return A link target.
      * @throws MalformedURLException if the URI is invalid.
      */
     LinkTarget resolve(Document currentDocument, String linkUri) throws MalformedURLException;

Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolverImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolverImpl.java?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolverImpl.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkResolverImpl.java Tue Nov 28 05:42:22 2006
@@ -29,7 +29,9 @@
 import org.apache.lenya.cms.publication.PublicationException;
 
 /**
- * Link resolver implemenation.
+ * Basic link resolver implementation which searches for links by parsing the
+ * document source. For better performance use an implementation which is based
+ * on meta data or a centralized link registry.
  */
 public class LinkResolverImpl extends AbstractLogEnabled implements LinkResolver, Configurable {
 
@@ -37,12 +39,11 @@
      * The Avalon role.
      */
     public static final String ROLE = LinkResolverImpl.class.getName();
-    
 
     public LinkTarget resolve(Document currentDoc, String linkUri) throws MalformedURLException {
 
         Link link = new Link(linkUri);
-        
+
         String uuid = getValue(link.getUuid(), currentDoc.getUUID());
         String language = getValue(link.getLanguage(), currentDoc.getLanguage());
         String revisionString = getValue(link.getRevision(), null);
@@ -52,8 +53,7 @@
         int revision;
         if (revisionString == null) {
             revision = -1;
-        }
-        else {
+        } else {
             revision = Integer.valueOf(revisionString).intValue();
         }
 
@@ -73,8 +73,7 @@
                 } else if (this.fallbackMode == MODE_DEFAULT_LANGUAGE) {
                     if (areaObj.contains(uuid, pub.getDefaultLanguage())) {
                         doc = areaObj.getDocument(uuid, pub.getDefaultLanguage());
-                    }
-                    else {
+                    } else {
                         doc = null;
                     }
                 } else {
@@ -82,22 +81,24 @@
                             + "] is not supported!");
                 }
             }
-            if (revision > -1) {
-                return new LinkTarget(doc, revision);
-            }
-            else {
-                return new LinkTarget(doc);
+            if (doc == null) {
+                return new LinkTarget();
+            } else {
+                if (revision > -1) {
+                    return new LinkTarget(doc, revision);
+                } else {
+                    return new LinkTarget(doc);
+                }
             }
         } catch (PublicationException e) {
             throw new RuntimeException(e);
         }
     }
-    
+
     protected String getValue(String value, String defaultValue) {
         if (value == null) {
             return defaultValue;
-        }
-        else {
+        } else {
             return value;
         }
     }
@@ -111,7 +112,7 @@
     public void setFallbackMode(int mode) {
         this.fallbackMode = mode;
     }
-    
+
     protected static final String ELEMENT_FALLBACK = "fallback";
 
     public void configure(Configuration config) throws ConfigurationException {
@@ -120,8 +121,7 @@
             boolean fallback = config.getValueAsBoolean();
             if (fallback) {
                 setFallbackMode(MODE_DEFAULT_LANGUAGE);
-            }
-            else {
+            } else {
                 setFallbackMode(MODE_FAIL);
             }
         }

Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkTarget.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkTarget.java?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkTarget.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkTarget.java Tue Nov 28 05:42:22 2006
@@ -18,7 +18,7 @@
 package org.apache.lenya.cms.linking;
 
 import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.util.Assert;
 
 /**
  * The target of a link.
@@ -27,7 +27,7 @@
 
     private Document doc;
     private int revisionNumber = -1;
-    
+
     /**
      * Ctor.
      * @param doc The document.
@@ -37,38 +37,60 @@
         this(doc);
         this.revisionNumber = revisionNumber;
     }
-    
+
     /**
      * Ctor.
      * @param doc The document.
      */
     protected LinkTarget(Document doc) {
+        Assert.notNull("document", doc);
         this.doc = doc;
     }
 
     /**
+     * Ctor for non-existing targets.
+     */
+    protected LinkTarget() {
+    }
+
+    /**
      * @return The linked document.
+     * @throws LinkException if the target doesn't exist.
      */
-    public Document getDocument() {
+    public Document getDocument() throws LinkException {
+        if (!exists()) {
+            throw new LinkException("The target doesn't exist!");
+        }
         return this.doc;
     }
-    
+
     /**
      * @return The revision number.
-     * @throws PublicationException if no revision number is specified in the link.
+     * @throws LinkException if the target doesn't exist or no revision number
+     *         is specified in the link.
      */
-    public int getRevisionNumber() throws PublicationException {
+    public int getRevisionNumber() throws LinkException {
+        if (!exists()) {
+            throw new LinkException("The target doesn't exist!");
+        }
         if (this.revisionNumber == -1) {
-            throw new PublicationException("No revision specified!");
+            throw new LinkException("No revision specified!");
         }
         return this.revisionNumber;
     }
-    
+
     /**
      * @return if the revision is specified in the link.
      */
     public boolean isRevisionSpecified() {
         return this.revisionNumber != -1;
     }
-    
+
+    /**
+     * @return if the target exists.
+     */
+    public boolean exists() {
+        return this.doc != null;
+    }
+
 }

Modified: lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml (original)
+++ lenya/trunk/src/pubs/default/lenya/resources/i18n/cmsui.xml Tue Nov 28 05:42:22 2006
@@ -32,4 +32,7 @@
 
   <message key="last-published">This page was last published at {0} by {1}.</message>
   <message key="never-published">This page has not been published yet.</message>
+  
+  <message key="unpublished-links">Links to unpublished documents:</message>
+  <message key="links-to-document">Links from other documents:</message>
 </catalogue>

Modified: lenya/trunk/src/pubs/default/lenya/usecases/workflow/deactivate.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/usecases/workflow/deactivate.jx?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/usecases/workflow/deactivate.jx (original)
+++ lenya/trunk/src/pubs/default/lenya/usecases/workflow/deactivate.jx Tue Nov 28 05:42:22 2006
@@ -6,9 +6,9 @@
   The ASF licenses this file to You 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
-
+  
+  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.
@@ -19,21 +19,21 @@
 <!-- $Id$ -->
 
 <page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
-           xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
-           xmlns="http://www.w3.org/1999/xhtml" 
-           xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
-
+  xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
+  xmlns="http://www.w3.org/1999/xhtml" 
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+  
   <page:title><i18n:text>Deactivate</i18n:text></page:title>
   <page:body>
     <div class="lenya-box">
       <div class="lenya-box-title">
         <i18n:text>Deactivate</i18n:text>
       </div>
-
+      
       <jx:import uri="fallback://lenya/usecases/templates/messages.jx"/>
-
+      
       <div class="lenya-box-body">
-
+        
         <jx:set var="title" value="${usecase.getParameter('document')
           .getMetaData('http://purl.org/dc/elements/1.1/')
           .getFirstValue('title')}"/>
@@ -48,8 +48,33 @@
                 "<jx:out value="${title}"/>"
               </td>
             </tr>
+            <jx:if test="${!usecase.hasErrors() &amp;&amp; usecase.getParameter('linksToDocument').size() &gt; 0}">
+              <tr>
+                <td class="lenya-entry-caption" valign="top">
+                  <p>
+                    <i18n:text>links-to-document</i18n:text>
+                  </p>
+                </td>
+                <td>
+                  <ul>
+                    <jx:forEach var="link" items="${usecase.getParameter('linksToDocument')}">
+                      <li>
+                        <a href="${request.contextPath}${link.getCanonicalWebappURL()}">
+                          <jx:out value="${link.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}"/></a>
+                        <span>
+                          (<jx:out value="${link.getPath()}"/>,
+                          <jx:out value="${link.getLanguage()}"/>)
+                        </span>
+                      </li>
+                    </jx:forEach>
+                  </ul>
+                </td>
+              </tr>
+            </jx:if>
             <tr>
-              <td/>
+              <td class="lenya-entry-caption">
+                <i18n:text>deactivate complete subtree</i18n:text>:
+              </td>
               <td>
                 <jx:choose>
                   <jx:when test="${usecase.getParameter('allowSingleDocument').equals('false')}">
@@ -63,7 +88,6 @@
                     <input name="subtree" type="checkbox" checked="checked"/>
                   </jx:otherwise>
                 </jx:choose>
-                <i18n:text>deactivate complete subtree</i18n:text>
               </td>
             </tr>
             <tr>

Modified: lenya/trunk/src/pubs/default/lenya/usecases/workflow/publish.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/lenya/usecases/workflow/publish.jx?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/pubs/default/lenya/usecases/workflow/publish.jx (original)
+++ lenya/trunk/src/pubs/default/lenya/usecases/workflow/publish.jx Tue Nov 28 05:42:22 2006
@@ -6,9 +6,9 @@
   The ASF licenses this file to You 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
-
+  
+  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.
@@ -19,10 +19,10 @@
 <!-- $Id$ -->
 
 <page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
-           xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
-           xmlns="http://www.w3.org/1999/xhtml" 
-           xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
-
+  xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
+  xmlns="http://www.w3.org/1999/xhtml" 
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+  
   <page:title><i18n:text>Publish</i18n:text></page:title>
   <page:body>
     <div class="lenya-box">
@@ -46,7 +46,10 @@
               </td>
             </tr>
             <tr>
-              <td colspan="2">
+              <td class="lenya-entry-caption">
+                <i18n:text>Messages</i18n:text>:
+              </td>
+              <td>
                 <ul>
                   <jx:forEach var="message" items="${usecase.getErrorMessages()}">
                     <li>
@@ -70,8 +73,33 @@
                 </ul>
               </td>
             </tr>
+            <jx:if test="${usecase.getParameter('unpublishedLinks').size() &gt; 0}">
+              <tr>
+                <td class="lenya-entry-caption" valign="top">
+                  <p>
+                    <i18n:text>unpublished-links</i18n:text>
+                  </p>
+                </td>
+                <td>
+                  <ul>
+                    <jx:forEach var="link" items="${usecase.getParameter('unpublishedLinks')}">
+                      <li>
+                        <a href="${request.contextPath}${link.getCanonicalWebappURL()}">
+                          <jx:out value="${link.getMetaData('http://purl.org/dc/elements/1.1/').getFirstValue('title')}"/></a>
+                        <span>
+                          (<jx:out value="${link.getPath()}"/>,
+                          <jx:out value="${link.getLanguage()}"/>)
+                        </span>
+                      </li>
+                    </jx:forEach>
+                  </ul>
+                </td>
+              </tr>
+            </jx:if>
             <tr>
-              <td/>
+              <td class="lenya-entry-caption">
+                <i18n:text>publish complete subtree</i18n:text>:
+              </td>
               <td>
                 <jx:choose>
                   <jx:when test="${usecase.getParameter('allowSingleDocument').equals('false')}">
@@ -85,11 +113,13 @@
                     <input name="subtree" type="checkbox" checked="checked"/>
                   </jx:otherwise>
                 </jx:choose>
-                <i18n:text>publish complete subtree</i18n:text>
+                
               </td>
             </tr>
             <tr>
-              <td/>
+              <td class="lenya-entry-caption">
+                <i18n:text>notify-submitter</i18n:text>:
+              </td>
               <td>
                 <jx:choose>
                   <jx:when test="${usecase.getParameter('sendNotification').equals('true')}">
@@ -99,11 +129,10 @@
                     <input name="sendNotification" type="checkbox" checked="checked"/>
                   </jx:otherwise>
                 </jx:choose>
-                <i18n:text>notify-submitter</i18n:text>
               </td>
             </tr>
             <tr>
-              <td><i18n:text>Schedule</i18n:text>:</td>
+              <td class="lenya-entry-caption"><i18n:text>Schedule</i18n:text>:</td>
               <td>
                 <input type="checkbox" name="schedule"/>
                 <input type="text" name="schedule.time" value="${usecase.getParameter('schedule.time')}"/>

Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java (original)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java Tue Nov 28 05:42:22 2006
@@ -18,10 +18,13 @@
 package org.apache.lenya.defaultpub.cms.usecases;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.linking.LinkManager;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentManager;
 import org.apache.lenya.cms.publication.Publication;
@@ -42,6 +45,8 @@
  */
 public class Deactivate extends DocumentUsecase {
 
+    protected static final String LINKS_TO_DOCUMENT = "linksToDocument";
+
     /**
      * Checks if the workflow event is supported and the parent of the document exists in the live
      * area.
@@ -84,7 +89,33 @@
                 }
                 setParameter(Publish.ALLOW_SINGLE_DOCUMENT, Boolean.toString(allowSingle));
             }
+
+            setParameter(LINKS_TO_DOCUMENT, getLinksToDocument());
+        }
+    }
+
+    protected Document[] getLinksToDocument() {
+        Set docs = new HashSet();
+        LinkManager linkMgr = null;
+        try {
+            linkMgr = (LinkManager) this.manager.lookup(LinkManager.ROLE);
+            Document liveVersion = getSourceDocument().getAreaVersion(Publication.LIVE_AREA);
+            Document[] referencingDocs = linkMgr.getReferencingDocuments(liveVersion);
+            for (int d = 0; d < referencingDocs.length; d++) {
+                Document doc = referencingDocs[d];
+                if (doc.getArea().equals(Publication.LIVE_AREA)) {
+                    docs.add(doc);
+                }
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        finally {
+            if (linkMgr != null) {
+                this.manager.release(linkMgr);
+            }
         }
+        return (Document[]) docs.toArray(new Document[docs.size()]);
     }
 
     /**

Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java (original)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java Tue Nov 28 05:42:22 2006
@@ -23,13 +23,18 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.lenya.ac.Identifiable;
 import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.linking.LinkManager;
+import org.apache.lenya.cms.linking.LinkResolver;
+import org.apache.lenya.cms.linking.LinkTarget;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.DocumentFactory;
@@ -70,6 +75,7 @@
     protected static final String SCHEDULE = "schedule";
     protected static final String SCHEDULE_TIME = "schedule.time";
     protected static final String SEND_NOTIFICATION = "sendNotification";
+    protected static final String UNPUBLISHED_LINKS = "unpublishedLinks";
 
     /**
      * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
@@ -77,11 +83,46 @@
     protected void initParameters() {
         super.initParameters();
 
+        if (hasErrors()) {
+            return;
+        }
+
         Date now = new GregorianCalendar().getTime();
         DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         setParameter(SCHEDULE_TIME, format.format(now));
 
         setParameter(SEND_NOTIFICATION, Boolean.TRUE);
+        
+        setParameter(UNPUBLISHED_LINKS, getUnpublishedLinks());
+    }
+
+    protected Document[] getUnpublishedLinks() {
+        Set docs = new HashSet();
+        LinkManager linkMgr = null;
+        LinkResolver resolver = null;
+        try {
+            linkMgr = (LinkManager) this.manager.lookup(LinkManager.ROLE);
+            resolver = (LinkResolver) this.manager.lookup(LinkResolver.ROLE);
+            org.apache.lenya.cms.linking.Link[] links = linkMgr.getLinksFrom(getSourceDocument());
+            for (int i = 0; i < links.length; i++) {
+                LinkTarget target = resolver.resolve(getSourceDocument(), links[i].getUri());
+                Document doc = target.getDocument();
+                if (!doc.existsAreaVersion(Publication.LIVE_AREA)) {
+                    docs.add(doc);
+                }
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        finally {
+            if (linkMgr != null) {
+                this.manager.release(linkMgr);
+            }
+            if (resolver != null) {
+                this.manager.release(resolver);
+            }
+        }
+        return (Document[]) docs.toArray(new Document[docs.size()]);
     }
 
     /**

Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/module.xml?view=diff&rev=480037&r1=480036&r2=480037
==============================================================================
--- lenya/trunk/src/pubs/default/modules/defaultusecases/module.xml (original)
+++ lenya/trunk/src/pubs/default/modules/defaultusecases/module.xml Tue Nov 28 05:42:22 2006
@@ -23,6 +23,7 @@
   <depends module="org.apache.lenya.modules.usecase"/>
   <depends module="org.apache.lenya.modules.sitemanagement"/>
   <depends module="org.apache.lenya.modules.notification"/>
+  <depends module="org.apache.lenya.modules.linking"/>
   <package>org.apache.lenya.modules</package>
   <version>0.1-dev</version>
   <name>Default publication usecases</name>



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