svn commit: r567462 - in /lenya/trunk/src: java/org/apache/lenya/cms/cocoon/acting/ java/org/apache/lenya/cms/rc/ java/org/apache/lenya/cms/repository/ java/org/apache/lenya/transaction/ modules-core/usecase/java/src/org/apache/lenya/cms/usecase/ modul...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Sun Aug 19 13:31:38 2007
New Revision: 567462

URL: http://svn.apache.org/viewvc?rev=567462&view=rev
Log:
Added workaround for usecases which can't use the same session for check-in and check-out (BXE, FCKeditor): Allow to check-out a node without the restriction to the same session. See bug 43157.

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java
    lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java
    lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
    lenya/trunk/src/java/org/apache/lenya/transaction/Versionable.java
    lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java
    lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf
    lenya/trunk/src/modules/fckeditor/config/cocoon-xconf/usecases-edit-fckeditor.xconf
    lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
    lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckinAction.java Sun Aug 19 13:31:38 2007
@@ -53,7 +53,7 @@
 
         try {
             Node node = getNode();
-            if (node.isCheckedOutBySession()) {
+            if (node.isCheckedOutBySession(node.getSession())) {
                 node.checkin();
             }
         } catch (RepositoryException e) {

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/ReservedCheckoutAction.java Sun Aug 19 13:31:38 2007
@@ -53,7 +53,7 @@
             Assert.notNull("node", node);
             Assert.notNull("username", username);
 
-            if (!node.isCheckedOutBySession()) {
+            if (!node.isCheckedOutBySession(node.getSession())) {
                 node.checkout();
             }
         } catch (RepositoryException e) {

Modified: lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/rc/RCML.java Sun Aug 19 13:31:38 2007
@@ -26,9 +26,8 @@
 import org.apache.lenya.cms.repository.Session;
 
 /**
- * An object of this class handles the revisions of a node. The node is passed
- * as a parameter so an RCML object can be shared between sessions for synchronization
- * purposes.
+ * An object of this class handles the revisions of a node. The node is passed as a parameter so an
+ * RCML object can be shared between sessions for synchronization purposes.
  */
 public interface RCML {
 
@@ -49,15 +48,24 @@
      * @throws RevisionControlException if an error occurs.
      */
     void checkIn(Node node, boolean backup, boolean newVersion) throws RevisionControlException;
-    
+
     /**
-     * Check the RCML out.
+     * Check the RCML out with restriction to the current session.
      * @param node The node.
      * @throws RevisionControlException if an error occurs.
      */
     void checkOut(Node node) throws RevisionControlException;
 
     /**
+     * Check the RCML out.
+     * @param node The node.
+     * @param restrictedToSession If only the current session may check the node in, or all sessions
+     *        belonging to this user.
+     * @throws RevisionControlException if an error occurs.
+     */
+    void checkOut(Node node, boolean restrictedToSession) throws RevisionControlException;
+
+    /**
      * get the latest check out
      * @return CheckOutEntry The entry of the check out
      * @throws RevisionControlException if an error occurs
@@ -91,7 +99,7 @@
      * @throws Exception if an error occurs
      */
     Vector getBackupEntries() throws Exception;
-    
+
     /**
      * Creates a backup.
      * @param time The time.
@@ -132,20 +140,20 @@
      * @return boolean true, if the file was deleted
      */
     boolean delete();
-    
+
     /**
      * Delete all revisions.
      * @throws RevisionControlException if an error occurs.
      */
     void deleteRevisions() throws RevisionControlException;
-    
+
     /**
      * @param node The target node.
      * @param otherNode The source node.
      * @throws RevisionControlException if an error occurs.
      */
     void copyFrom(Node node, Node otherNode) throws RevisionControlException;
-    
+
     /**
      * @return if the RCML is checked out.
      * @throws RevisionControlException if an error occurs.
@@ -159,4 +167,4 @@
      */
     boolean isCheckedOutBySession(Session session) throws RevisionControlException;
 
-}
\ No newline at end of file
+}

Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/Node.java Sun Aug 19 13:31:38 2007
@@ -79,12 +79,21 @@
     void unlock() throws RepositoryException;
 
     /**
-     * Checks out the node.
+     * Checks out the node with restriction to the current session..
      * @throws RepositoryException if an error occurs.
      */
     void checkout() throws RepositoryException;
 
     /**
+     * Checks out the node with the possibility to allow other sessions to check it in.
+     * This is a workaround for the current WYSIWYG editor infrastructure, which can't
+     * use the same session for opening and saving a node.
+     * @param restrictedToSession if the check-out is restricted to the current session.
+     * @throws RepositoryException if an error occurs.
+     */
+    void checkout(boolean restrictedToSession) throws RepositoryException;
+
+    /**
      * Checks in the node.
      * @throws RepositoryException if the node is not checked out or is checked
      *         out by a different session.
@@ -116,10 +125,13 @@
     String getCheckoutUserId() throws RepositoryException;
 
     /**
-     * @return if the node is checked out by the current session.
+     * Checks if the node is checked out by a certain session. We pass the session
+     * as a parameter to allow the check for nodes from the shared item store.
+     * @param session The session.
+     * @return if the node is checked out by a specific session.
      * @throws RepositoryException if an error occurs.
      */
-    boolean isCheckedOutBySession() throws RepositoryException;
+    boolean isCheckedOutBySession(Session session) throws RepositoryException;
 
     /**
      * @param source The node to copy the revisions from.

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/Versionable.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/transaction/Versionable.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/Versionable.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/Versionable.java Sun Aug 19 13:31:38 2007
@@ -43,7 +43,7 @@
     boolean isCheckedOut() throws TransactionException;
     
     /**
-     * @return if the object is checked out by the current session.
+     * @return if the object is checked out by its session.
      * @throws TransactionException if an error occurs.
      */
     boolean isCheckedOutBySession() throws TransactionException;

Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/AbstractUsecase.java Sun Aug 19 13:31:38 2007
@@ -82,6 +82,7 @@
     protected static final String PARAMETER_STATE_MACHINE = "private.stateMachine";
     protected static final String PARAMETER_SESSION = "private.session";
     protected static final String PARAMETER_FACTORY = "private.factory";
+    protected static final String PARAMETER_CHECKOUT_RESTRICTED_TO_SESSION = "checkoutRestrictedToSession";
 
     protected static final String PARAMETERS_INITIALIZED = "private.parametersInitialized";
 
@@ -797,8 +798,8 @@
                 if (!objects[i].isLocked()) {
                     objects[i].lock();
                 }
-                if (!isOptimistic() && !objects[i].isCheckedOutBySession()) {
-                    objects[i].checkout();
+                if (!isOptimistic() && !objects[i].isCheckedOutBySession(getSession())) {
+                    objects[i].checkout(checkoutRestrictedToSession());
                 }
             }
         } catch (RepositoryException e) {
@@ -810,7 +811,7 @@
         boolean canExecute = true;
 
         for (int i = 0; i < objects.length; i++) {
-            if (objects[i].isCheckedOut() && !objects[i].isCheckedOutBySession()) {
+            if (objects[i].isCheckedOut() && !objects[i].isCheckedOutBySession(getSession())) {
                 if (getLogger().isDebugEnabled()) {
                     getLogger().debug(
                             "AbstractUsecase::lockInvolvedObjects() can not execute, object ["
@@ -898,6 +899,10 @@
     public void setTestSession(Session session) {
         this.commitEnabled = false;
         setSession(session);
+    }
+    
+    protected boolean checkoutRestrictedToSession() {
+        return getParameterAsBoolean(PARAMETER_CHECKOUT_RESTRICTED_TO_SESSION, true);
     }
 
 }

Modified: lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf (original)
+++ lenya/trunk/src/modules/bxe/config/cocoon-xconf/usecase-bxe.xconf Sun Aug 19 13:31:38 2007
@@ -25,7 +25,8 @@
       class="org.apache.lenya.cms.workflow.usecases.InvokeWorkflow">
       <view template="modules/bxe/usecases/bxe.jx" menu="false" createContinuation="false"/>
       <transaction policy="pessimistic"/>
-      <event id="edit"/>
+      <event id="edit"/>
+      <parameter name="checkoutRestrictedToSession" value="false"/>
     </component-instance>
     
   </xconf>

Modified: lenya/trunk/src/modules/fckeditor/config/cocoon-xconf/usecases-edit-fckeditor.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/fckeditor/config/cocoon-xconf/usecases-edit-fckeditor.xconf?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/modules/fckeditor/config/cocoon-xconf/usecases-edit-fckeditor.xconf (original)
+++ lenya/trunk/src/modules/fckeditor/config/cocoon-xconf/usecases-edit-fckeditor.xconf Sun Aug 19 13:31:38 2007
@@ -24,6 +24,7 @@
     <parameter name="tidyConfig" value="fallback://lenya/modules/fckeditor/config/jtidy.properties"/> 
     <view uri="cocoon://modules/fckeditor/fckeditor.open" menu="false"/>
     <event id="edit" />
+    <parameter name="checkoutRestrictedToSession" value="false"/>
   </component-instance>
     
 </xconf>

Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Sun Aug 19 13:31:38 2007
@@ -143,21 +143,15 @@
         }
     }
 
-    /**
-     * @see org.apache.lenya.transaction.Transactionable#isCheckedOutBySession()
-     */
-    public boolean isCheckedOutBySession() throws RepositoryException {
+    public boolean isCheckedOutBySession(Session session) throws RepositoryException {
         try {
-            return getRcml().isCheckedOutBySession(getSession());
+            return getRcml().isCheckedOutBySession(session);
         } catch (RevisionControlException e) {
             throw new RepositoryException(e);
         }
     }
 
-    /**
-     * @see org.apache.lenya.transaction.Transactionable#checkout()
-     */
-    public void checkout() throws RepositoryException {
+    public void checkout(boolean restrictedToSession) throws RepositoryException {
 
         if (getLogger().isDebugEnabled())
             getLogger().debug("SourceNode::checkout() called, sourceURI [" + getSourceURI() + "]");
@@ -170,13 +164,17 @@
                             + "] is already checked out by another session!");
                 }
                 if (!rcml.isCheckedOut()) {
-                    rcml.checkOut(this);
+                    rcml.checkOut(this, restrictedToSession);
                 }
             } catch (RevisionControlException e) {
                 throw new RepositoryException(e);
             }
         }
     }
+    
+    public void checkout() throws RepositoryException {
+        checkout(true);
+    }
 
     private Lock lock;
 
@@ -471,6 +469,10 @@
         } catch (RevisionControlException e) {
             throw new RepositoryException(e);
         }
+    }
+
+    public boolean isCheckedOutBySession() throws TransactionException {
+        return isCheckedOutBySession(getSession());
     }
     
 }

Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java?rev=567462&r1=567461&r2=567462&view=diff
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java Sun Aug 19 13:31:38 2007
@@ -95,6 +95,8 @@
 
     protected static final String RCML_EXTENSION = ".rcml";
 
+    private static final String ALL_SESSIONS = "unrestricted";
+
     protected String getRcmlSourceUri() {
         return this.contentSourceUri + RCML_EXTENSION;
     }
@@ -127,17 +129,20 @@
     }
 
     /**
-     * Write a new entry for a check out or a check in the RCML-File made by the
-     * user with identity at time
+     * Write a new entry for a check out or a check in the RCML-File made by the user with identity
+     * at time
      * @param node The node.
      * @param type co for a check out, ci for a check in
      * @param time
-     * @param backup Create backup element
-     * @param newVersion If the revision number shall be increased.
+     * @param backup Create backup element (only considered for check-in entries).
+     * @param newVersion If the revision number shall be increased (only considered for check-in
+     *        entries).
+     * @param restrictedToSession If the check-out is restricted to the session (only considered for
+     *        check-out entries).
      * @throws RevisionControlException if an error occurs
      */
-    public synchronized void checkOutIn(Node node, short type, long time, boolean backup, boolean newVersion)
-            throws RevisionControlException {
+    public synchronized void checkOutIn(Node node, short type, long time, boolean backup,
+            boolean newVersion, boolean restrictedToSession) throws RevisionControlException {
 
         String identity = node.getSession().getIdentity().getUser().getId();
 
@@ -156,7 +161,13 @@
             }
         }
 
-        String sessionId = node.getSession().getId();
+        String sessionId;
+        if (type == RCML.co && !restrictedToSession) {
+            sessionId = ALL_SESSIONS;
+        }
+        else {
+            sessionId = node.getSession().getId();
+        }
 
         RCMLEntry entry;
         switch (type) {
@@ -423,9 +434,8 @@
     }
 
     /**
-     * Prune the list of entries and delete the corresponding backups. Limit the
-     * number of entries to the value maximalNumberOfEntries
-     * (2maxNumberOfRollbacks(configured)+1)
+     * Prune the list of entries and delete the corresponding backups. Limit the number of entries
+     * to the value maximalNumberOfEntries (2maxNumberOfRollbacks(configured)+1)
      * @throws RevisionControlException if an error occurs
      */
     public synchronized void pruneEntries() throws RevisionControlException {
@@ -498,8 +508,7 @@
     }
 
     /**
-     * Delete the revisions, the RCML source and the collection if the latter is
-     * empty.
+     * Delete the revisions, the RCML source and the collection if the latter is empty.
      * @return boolean true, if the file was deleted
      */
     public synchronized boolean delete() {
@@ -584,20 +593,26 @@
         return entry != null && entry.getType() == RCML.co;
     }
 
-    public synchronized void checkIn(Node node, boolean backup, boolean newVersion) throws RevisionControlException {
+    public synchronized void checkIn(Node node, boolean backup, boolean newVersion)
+            throws RevisionControlException {
         long time = new Date().getTime();
 
         if (backup) {
             makeBackup(time);
         }
 
-        checkOutIn(node, RCML.ci, time, backup, newVersion);
+        checkOutIn(node, RCML.ci, time, backup, newVersion, false);
         pruneEntries();
         write();
     }
 
     public synchronized void checkOut(Node node) throws RevisionControlException {
-        checkOutIn(node, RCML.co, new Date().getTime(), false, false);
+        checkOut(node, true);
+    }
+
+    public synchronized void checkOut(Node node, boolean restrictedToSession)
+            throws RevisionControlException {
+        checkOutIn(node, RCML.co, new Date().getTime(), false, false, restrictedToSession);
     }
 
     public boolean isCheckedOutBySession(Session session) throws RevisionControlException {
@@ -605,9 +620,20 @@
         if (entries.size() > 0) {
             RCMLEntry entry = (RCMLEntry) entries.get(0);
             String otherSessionId = entry.getSessionId();
-            return entry.getType() == co && otherSessionId.equals(session.getId());
+            if (entry.getType() == co) {
+                // not restricted to session
+                if (otherSessionId.equals(ALL_SESSIONS)) {
+                    String otherUserId = entry.getIdentity();
+                    String userId = session.getIdentity().getUser().getId();
+                    return userId.equals(otherUserId);
+                }
+                // restricted to session
+                if (otherSessionId.equals(session.getId())) {
+                    return true;
+                }
+            }
         }
         return false;
     }
-
-}
\ No newline at end of file
+    
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.