lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froethenbac...@apache.org
Subject svn commit: r1052317 - in /lenya/branches/BRANCH_2_1_X: lib/ src/impl/java/org/apache/lenya/cms/repository/ src/impl/test/org/apache/lenya/transaction/ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/cms/ac/ src/java/org/apache/lenya/cms/cocoon...
Date Thu, 23 Dec 2010 17:02:21 GMT
Author: froethenbacher
Date: Thu Dec 23 17:02:20 2010
New Revision: 1052317

URL: http://svn.apache.org/viewvc?rev=1052317&view=rev
Log:
Added site tree monitor for monitoring external changes to a site tree in a cluster environment.

Added:
    lenya/branches/BRANCH_2_1_X/lib/guava-r07.jar   (with props)
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeMonitor.xconf
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitor.java
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorImpl.java
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorListener.java
Removed:
    lenya/branches/BRANCH_2_1_X/src/impl/java/org/apache/lenya/cms/repository/SharedItemStoreImpl.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/SharedItemStore.java
    lenya/branches/BRANCH_2_1_X/src/webapp/lenya/config/cocoon-xconf/misc/shared-item-store.xconf
Modified:
    lenya/branches/BRANCH_2_1_X/src/impl/test/org/apache/lenya/transaction/TransactionTest.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/ac/Identity.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/ac/PolicyUtil.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryManagerImpl.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/Session.java
    lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/SessionImpl.java
    lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java
    lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/DelegatingSiteTree.java
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java
    lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeSiteManager.java
    lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
    lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
    lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRcmlFactory.java

Added: lenya/branches/BRANCH_2_1_X/lib/guava-r07.jar
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/lib/guava-r07.jar?rev=1052317&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/branches/BRANCH_2_1_X/lib/guava-r07.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: lenya/branches/BRANCH_2_1_X/src/impl/test/org/apache/lenya/transaction/TransactionTest.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/impl/test/org/apache/lenya/transaction/TransactionTest.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/impl/test/org/apache/lenya/transaction/TransactionTest.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/impl/test/org/apache/lenya/transaction/TransactionTest.java Thu Dec 23 17:02:20 2010
@@ -24,10 +24,10 @@ public class TransactionTest extends Con
 
     public void testTransaction() throws TransactionException {
 
-        Identity lenya = new Identity(getLogger());
+        Identity lenya = new Identity();
         lenya.addIdentifiable(new MockUser("lenya"));
 
-        Identity alice = new Identity(getLogger());
+        Identity alice = new Identity();
         alice.addIdentifiable(new MockUser("alice"));
 
         IdentityMap lenyaMap = new IdentityMapImpl(getLogger());

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/ac/Identity.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/ac/Identity.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/ac/Identity.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/ac/Identity.java Thu Dec 23 17:02:20 2010
@@ -36,27 +36,22 @@ import org.apache.cocoon.environment.Ses
 /**
  * Identity object. Used to store the authenticated accreditables in the session.
  */
-public class Identity extends AbstractLogEnabled implements Identifiable, Serializable {
+public class Identity implements Identifiable, Serializable {
     /**
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
 	private Set identifiables = new HashSet();
 
-    /**
-     * Ctor.
-     * @param logger The logger.
-     */
-    public Identity(Logger logger) {
-        ContainerUtil.enableLogging(this, logger);
-    }
-    
-    /**
-     * Initializes this identity.
-     */
-    public void initialize() {
+	public static Identity ANONYMOUS = new Identity();
+
+	/**
+	 * C'tor.
+	 * Adds World identifiable by default.
+	 */
+	public Identity() {
         addIdentifiable(World.getInstance());
-    }
+	}
 
     /**
      * In the case of Tomcat the object will be serialized to TOMCAT/work/Standalone/localhost/lenya/SESSIONS.ser
@@ -96,10 +91,6 @@ public class Identity extends AbstractLo
         assert identifiable != this;
         assert !this.identifiables.contains(identifiable);
 
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Adding identifiable: [" + identifiable + "]");
-        }
-
         this.identifiables.add(identifiable);
     }
 

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/ac/PolicyUtil.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/ac/PolicyUtil.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/ac/PolicyUtil.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/ac/PolicyUtil.java Thu Dec 23 17:02:20 2010
@@ -136,7 +136,7 @@ public final class PolicyUtil {
             Role roleObject = accreditableManager.getRoleManager().getRole(role);
 
             for (int i = 0; i < users.length; i++) {
-                Identity identity = new Identity(logger);
+                Identity identity = new Identity();
                 identity.addIdentifiable(users[i]);
                 Role[] roles = policyManager.getGrantedRoles(accreditableManager, identity,
                         webappUrl);

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/cocoon/source/RepositorySource.java Thu Dec 23 17:02:20 2010
@@ -96,12 +96,12 @@ public class RepositorySource extends Ab
         int start = 0;
         int end = uri.indexOf(':');
         if (end == -1)
-            throw new MalformedURLException("Malformed uri for xmodule source (cannot find scheme) : "
+            throw new MalformedURLException("Malformed uri for lenya source (cannot find scheme) : "
                     + uri);
 
         String scheme = uri.substring(start, end);
         if (!SCHEME.equals(scheme))
-            throw new MalformedURLException("Malformed uri for a xmodule source : " + uri);
+            throw new MalformedURLException("Malformed uri for a lenya source : " + uri);
 
         setScheme(scheme);
 

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryManagerImpl.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryManagerImpl.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryManagerImpl.java Thu Dec 23 17:02:20 2010
@@ -17,12 +17,18 @@
  */
 package org.apache.lenya.cms.repository;
 
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.lang.Validate;
 import org.apache.lenya.ac.Identity;
 
+import com.google.common.collect.MapMaker;
+
 /**
  * Repository manager implementation.
  * @version $Id:$
@@ -31,6 +37,9 @@ public class RepositoryManagerImpl exten
         Serviceable {
 
     protected ServiceManager manager;
+    // Cache unmodifiable sessions per identity.
+    protected ConcurrentMap<Identity, Session> sharedSessions =
+        new MapMaker().softKeys().softValues().expiration(30, TimeUnit.MINUTES).makeMap();
 
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
@@ -39,8 +48,35 @@ public class RepositoryManagerImpl exten
         this.manager = manager;
     }
 
+    @Override
     public Session createSession(Identity identity, boolean modifiable) throws RepositoryException {
-        return new SessionImpl(identity, modifiable, this.manager, getLogger());
+        Validate.notNull(identity, "identity must not be null");
+        if (modifiable) {
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("Created modifiable session.");
+            return new SessionImpl(identity, modifiable, this.manager, getLogger());
+        } else {
+            // If session is not modifiable then get a shared session.
+            return getSharedSession(identity);
+        }
     }
 
+    /**
+     * Get a shared session for identity.
+     * @param identity Identity
+     * @return Shared session for identity.
+     */
+    protected Session getSharedSession(Identity identity) {
+        Session session = sharedSessions.get(identity);
+        if (session == null) {
+            session = new SessionImpl(identity, false, manager, getLogger());
+            sharedSessions.put(identity, session);
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("Created new shared session.");
+        } else {
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("Using cached shared session.");
+        }
+        return session;
+    }
 }

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java Thu Dec 23 17:02:20 2010
@@ -38,6 +38,8 @@ public class RepositoryUtil {
         Session session = (Session) request.getAttribute(Session.class.getName());
         if (session == null) {
             Identity identity = getIdentity(request);
+            if (identity == null)
+                identity = Identity.ANONYMOUS;
             // attach a read-only repository session to the HTTP request
             session = createSession(manager, identity, false);
             request.setAttribute(Session.class.getName(), session);
@@ -52,8 +54,7 @@ public class RepositoryUtil {
 
     protected static Identity getIdentity(Request request) {
         org.apache.cocoon.environment.Session cocoonSession = request.getSession();
-        Identity identity = (Identity) cocoonSession.getAttribute(Identity.class.getName());
-        return identity;
+        return Identity.getIdentity(cocoonSession);
     }
 
     /**

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/Session.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/Session.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/Session.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/Session.java Thu Dec 23 17:02:20 2010
@@ -57,6 +57,17 @@ public interface Session extends UnitOfW
             throws RepositoryException;
 
     /**
+     * Invalidate repository item if cached for a non-modifiable session.
+     * @param key Repository item key.
+     */
+    void invalidateRepositoryItem(String key);
+
+    /**
+     * Invalidate all repository items a non-modifiable session.
+     */
+    void invalidateAllRepositoryItems();
+
+    /**
      * @param listener The listener to add.
      * @throws RepositoryException if the listener is already registered.
      */

Modified: lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/SessionImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/SessionImpl.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/SessionImpl.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/java/org/apache/lenya/cms/repository/SessionImpl.java Thu Dec 23 17:02:20 2010
@@ -22,11 +22,11 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.lenya.ac.Identity;
 import org.apache.lenya.cms.observation.ObservationRegistry;
@@ -44,6 +44,8 @@ import org.apache.lenya.transaction.Unit
 import org.apache.lenya.transaction.UnitOfWorkImpl;
 import org.apache.lenya.util.Assert;
 
+import com.google.common.collect.MapMaker;
+
 /**
  * Repository session.
  */
@@ -52,6 +54,10 @@ public class SessionImpl extends Abstrac
     protected static final String UNMODIFIABLE_SESSION_ID = "unmodifiable";
     private ServiceManager manager;
     private Identity identity;
+    private boolean modifiable;
+    // Cache repository items if session is not modifiable.
+    private ConcurrentMap<String, RepositoryItem> itemCache =
+        new MapMaker().softValues().makeMap();
 
     /**
      * Ctor.
@@ -67,7 +73,6 @@ public class SessionImpl extends Abstrac
         Assert.notNull("service manager", manager);
         this.manager = manager;
 
-        this.identityMap = new IdentityMapImpl(logger);
         this.identity = identity;
         this.id = modifiable ? createUuid() : UNMODIFIABLE_SESSION_ID;
 
@@ -82,9 +87,10 @@ public class SessionImpl extends Abstrac
                 this.manager.release(registry);
             }
         }
-
+        this.modifiable = modifiable;
         if (modifiable) {
-            this.unitOfWork = new UnitOfWorkImpl(this.identityMap, this.identity, getLogger());
+            this.unitOfWork = new UnitOfWorkImpl(new IdentityMapImpl(logger),
+                    this.identity, getLogger());
         }
     }
 
@@ -109,14 +115,13 @@ public class SessionImpl extends Abstrac
         return this.identity;
     }
 
-    private UnitOfWork unitOfWork;
-    private SharedItemStore sharedItemStore;
+    private UnitOfWorkImpl unitOfWork;
 
     /**
      * @return The unit of work.
      */
     protected UnitOfWork getUnitOfWork() {
-        if (this.unitOfWork == null) {
+        if (!isModifiable()) {
             throw new RuntimeException("This session [" + getId() + "] is not modifiable!");
         }
         return this.unitOfWork;
@@ -140,7 +145,6 @@ public class SessionImpl extends Abstrac
             synchronized (TransactionLock.LOCK) {
                 
                 getUnitOfWork().commit();
-                getSharedItemStore().clear();
             }
         } catch (ConcurrentModificationException e) {
             throw e;
@@ -164,7 +168,9 @@ public class SessionImpl extends Abstrac
      * @throws RepositoryException if an error occurs.
      */
     protected void savePersistables() throws RepositoryException {
-        Object[] objects = getIdentityMap().getObjects();
+        if (!isModifiable())
+            throw new RepositoryException("Session not modifiable.");
+        Object[] objects = unitOfWork.getIdentityMap().getObjects();
         for (int i = 0; i < objects.length; i++) {
             if (objects[i] instanceof Node) {
                 Node node = (Node) objects[i];
@@ -191,25 +197,35 @@ public class SessionImpl extends Abstrac
         this.events.clear();
     }
 
-    protected SharedItemStore getSharedItemStore() {
-        if (this.sharedItemStore == null) {
-            try {
-                this.sharedItemStore = (SharedItemStore) this.manager.lookup(SharedItemStore.ROLE);
-            } catch (ServiceException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return this.sharedItemStore;
-    }
-
     /**
      * @see org.apache.lenya.cms.repository.Session#getRepositoryItem(org.apache.lenya.cms.repository.RepositoryItemFactory,
      *      java.lang.String)
      */
     public RepositoryItem getRepositoryItem(RepositoryItemFactory factory, String key)
             throws RepositoryException {
-        RepositoryItemFactoryWrapper wrapper = new RepositoryItemFactoryWrapper(factory, this);
-        return (RepositoryItem) getIdentityMap().get(wrapper, key);
+        RepositoryItem repositoryItem;
+        if (isModifiable()) {
+            IdentityMap identityMap = unitOfWork.getIdentityMap();
+            RepositoryItemFactoryWrapper wrapper = new RepositoryItemFactoryWrapper(factory, this);
+            repositoryItem = (RepositoryItem) identityMap.get(wrapper, key);
+        } else {
+            repositoryItem = itemCache.get(key);
+            if (repositoryItem == null) {
+                repositoryItem = factory.buildItem(this, key);
+                itemCache.put(key, repositoryItem);
+            }
+        }
+        return repositoryItem;
+    }
+
+    @Override
+    public void invalidateRepositoryItem(String key) {
+        itemCache.remove(key);
+    }
+
+    @Override
+    public void invalidateAllRepositoryItems() {
+        itemCache.clear();
     }
 
     public void registerNew(Transactionable object) throws TransactionException {
@@ -258,7 +274,6 @@ public class SessionImpl extends Abstrac
     }
 
     private List events = new ArrayList();
-    private IdentityMap identityMap;
 
     public synchronized void enqueueEvent(RepositoryEvent event) {
         if (!isModifiable()) {
@@ -273,12 +288,8 @@ public class SessionImpl extends Abstrac
         this.events.add(event);
     }
 
-    protected IdentityMap getIdentityMap() {
-        return this.identityMap;
-    }
-
     public boolean isModifiable() {
-        return this.unitOfWork != null;
+        return modifiable;
     }
 
     private String id;

Modified: lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/src/org/apache/lenya/ac/impl/DefaultAccessController.java Thu Dec 23 17:02:20 2010
@@ -406,8 +406,7 @@ public class DefaultAccessController ext
     public void setupIdentity(Request request) throws AccessControlException {
         Session session = request.getSession(true);
         if (!hasValidIdentity(session)) {
-            Identity identity = new Identity(getLogger());
-            identity.initialize();
+            Identity identity = new Identity();
             String remoteAddress = request.getRemoteAddr();
             String clientAddress = request.getHeader("x-forwarded-for");
 

Modified: lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules-core/ac/java/test/org/apache/lenya/ac/impl/IdentityTest.java Thu Dec 23 17:02:20 2010
@@ -37,7 +37,7 @@ public class IdentityTest extends Abstra
      * @throws AccessControlException if an error occurs
      */
     public void testIdentity() throws AccessControlException {
-        Identity identity = new Identity(getLogger());
+        Identity identity = new Identity();
         User user = getAccessController().getAccreditableManager().getUserManager().getUser(USER_ID);
         getLogger().info("Adding user to identity: [" + user + "]");
         identity.addIdentifiable(user);
@@ -57,10 +57,10 @@ public class IdentityTest extends Abstra
         User testUser = testMgr.getUserManager().getUser(userId);
         User defaultUser = defaultMgr.getUserManager().getUser(userId);
         
-        Identity testIdentity = new Identity(getLogger());
+        Identity testIdentity = new Identity();
         testIdentity.addIdentifiable(testUser);
         
-        Identity defaultIdentity = new Identity(getLogger());
+        Identity defaultIdentity = new Identity();
         defaultIdentity.addIdentifiable(defaultUser);
         
         assertTrue(testIdentity.belongsTo(testMgr));

Added: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeMonitor.xconf
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeMonitor.xconf?rev=1052317&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeMonitor.xconf (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeMonitor.xconf Thu Dec 23 17:02:20 2010
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.cms.site.tree2.SiteTreeMonitor']">
+
+  <component role="org.apache.lenya.cms.site.tree2.SiteTreeMonitor" logger="lenya.site"
+    class="org.apache.lenya.cms.site.tree2.SiteTreeMonitorImpl"/>
+  
+</xconf>

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/DelegatingSiteTree.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/DelegatingSiteTree.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/DelegatingSiteTree.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/DelegatingSiteTree.java Thu Dec 23 17:02:20 2010
@@ -22,8 +22,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.commons.lang.Validate;
 import org.apache.lenya.cms.publication.Area;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.Publication;
@@ -41,7 +43,9 @@ import org.apache.lenya.cms.site.tree.Si
  * Site tree implementation which delegates all operations to a shared site
  * tree.
  */
-public class DelegatingSiteTree implements SiteStructure, SiteTree {
+public class DelegatingSiteTree extends AbstractLogEnabled
+implements SiteStructure, SiteTree
+{
 
     private Area area;
     private ServiceManager manager;
@@ -51,9 +55,7 @@ public class DelegatingSiteTree implemen
     private List topLevelNodes;
     private List preOrder;
     private String sourceUri;
-    private Session sharedItemStoreSession;
-    private String key;
-    private SiteTreeFactory factory;
+    private SiteTree delegate;
 
     /**
      * @param manager The service manager.
@@ -62,13 +64,14 @@ public class DelegatingSiteTree implemen
      * @param store The shared item store.
      * @param key The key to build the sitetree.
      */
-    public DelegatingSiteTree(ServiceManager manager, Area area, SiteTreeFactory factory, Session session,
-            String key) {
+    public DelegatingSiteTree(ServiceManager manager, Area area, SiteTree delegate, String key) {
+        Validate.notNull(manager, "manager must not be null");
+        Validate.notNull(area, "area must not be null");
+        Validate.notNull(delegate, "delegate must not be null");
+        Validate.notNull(key, "key must not be null");
         this.area = area;
         this.manager = manager;
-        this.key = key;
-        this.factory = factory;
-        this.sharedItemStoreSession = session;
+        this.delegate = delegate;
     }
 
     public Link add(String path, Document doc) throws SiteException {
@@ -209,15 +212,26 @@ public class DelegatingSiteTree implemen
     }
 
     protected SiteTree getTree() {
-        try {
-            return (SiteTree) this.sharedItemStoreSession.getRepositoryItem(this.factory, this.key);
-        } catch (RepositoryException e) {
-            throw new RuntimeException(e);
-        }
+        return delegate;
     }
 
     public void save() throws RepositoryException {
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * Reload site tree delegate.
+     */
+    public void notifySiteTreeModified() {
+        SiteTree siteTree = getTree();
+        if (siteTree instanceof SiteTreeImpl) {
+            SiteTreeImpl siteTreeImpl = (SiteTreeImpl) getTree();
+            siteTreeImpl.reload();
+        } else {
+            if (getLogger().isWarnEnabled())
+                getLogger().warn("Unknown site tree implementation [" +
+                        siteTree.getClass().getName() +
+                        "]. Reloading skipped.");
+        }
+    }
 }

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeFactory.java Thu Dec 23 17:02:20 2010
@@ -29,7 +29,6 @@ import org.apache.lenya.cms.repository.R
 import org.apache.lenya.cms.repository.RepositoryItem;
 import org.apache.lenya.cms.repository.RepositoryItemFactory;
 import org.apache.lenya.cms.repository.Session;
-import org.apache.lenya.cms.repository.SharedItemStore;
 import org.apache.lenya.cms.site.tree.SiteTree;
 
 /**
@@ -56,25 +55,19 @@ public class SiteTreeFactory extends Abs
         String publicationId = snippets[0];
         String areaName = snippets[1];
         SiteTree tree;
-        SharedItemStore store = null;
         try {
             DocumentFactory factory = DocumentUtil.createDocumentFactory(this.manager, session);
             Publication publication = factory.getPublication(publicationId);
             Area area = publication.getArea(areaName);
-            store = (SharedItemStore) this.manager.lookup(SharedItemStore.ROLE);
 
-            Session storeSession = store.getSession();
-            if (session.isModifiable() || session == storeSession) {
+            if (session.isModifiable()) {
                 tree = new SiteTreeImpl(this.manager, area, getLogger());
             } else {
-                tree = new DelegatingSiteTree(this.manager, area, this, storeSession, key);
+                SiteTree delegate = new SiteTreeImpl(this.manager, area, getLogger());
+                tree = new DelegatingSiteTree(this.manager, area, delegate, key);
             }
         } catch (Exception e) {
             throw new RepositoryException(e);
-        } finally {
-            if (store != null) {
-                this.manager.release(store);
-            }
         }
         return tree;
     }

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java Thu Dec 23 17:02:20 2010
@@ -17,6 +17,7 @@
  */
 package org.apache.lenya.cms.site.tree2;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -51,6 +52,15 @@ public class SiteTreeImpl extends Abstra
     protected ServiceManager manager;
     private RootNode root;
     private int revision;
+    /**
+     * Last modification date of site tree file.
+     */
+    private Date lastModified;
+    /**
+     * Site tree file has been modified on file system and site
+     * tree should be reloaded.
+     */
+    private boolean reload; 
 
     /**
      * @param manager The service manager.
@@ -117,6 +127,8 @@ public class SiteTreeImpl extends Abstra
             if (!repoNode.exists()) {
                 reset();
             }
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("Site tree loaded [" + getSourceUri() + "]");
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -429,4 +441,10 @@ public class SiteTreeImpl extends Abstra
         this.revision = revision;
     }
 
+    public void reload() {
+        reset();
+        loaded = false;
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("Site tree marked for reloading");
+    }
 }

Added: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitor.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitor.java?rev=1052317&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitor.java (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitor.java Thu Dec 23 17:02:20 2010
@@ -0,0 +1,10 @@
+package org.apache.lenya.cms.site.tree2;
+
+import org.apache.lenya.cms.site.tree.SiteTree;
+
+public interface SiteTreeMonitor {
+
+    String ROLE = SiteTreeMonitor.class.getName();
+
+    void addListener(SiteTree siteTree, SiteTreeMonitorListener listener);
+}

Added: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorImpl.java?rev=1052317&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorImpl.java (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorImpl.java Thu Dec 23 17:02:20 2010
@@ -0,0 +1,109 @@
+package org.apache.lenya.cms.site.tree2;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.HashMap;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
+import org.apache.commons.io.monitor.FileAlterationMonitor;
+import org.apache.commons.io.monitor.FileAlterationObserver;
+import org.apache.commons.lang.Validate;
+import org.apache.lenya.cms.site.tree.SiteTree;
+
+/**
+ * SiteTreeMonitor implementation.
+ * Monitor site tree file for modifications and notify
+ * site tree for reloading.
+ */
+public class SiteTreeMonitorImpl extends AbstractLogEnabled
+implements SiteTreeMonitor, Serviceable, Startable, Initializable, ThreadSafe
+{
+    private ServiceManager serviceManager;
+    private FileAlterationMonitor fileAlterationMonitor;
+    private HashMap<String, SiteTree> siteTreeMap =
+        new HashMap<String, SiteTree>();
+    private HashMap<String, SiteTreeMonitorListener> listenerMap =
+        new HashMap<String, SiteTreeMonitorListener>();
+
+    @Override
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        this.serviceManager = serviceManager;
+    }
+
+    @Override
+    public void start() throws Exception {
+        Validate.notNull(fileAlterationMonitor, "Not initialized.");
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("Site tree monitor started.");
+        fileAlterationMonitor.start();
+    }
+
+    @Override
+    public void stop() throws Exception {
+        Validate.notNull(fileAlterationMonitor, "Not initialized.");
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("Site tree monitor stopped.");
+        fileAlterationMonitor.stop();
+    }
+
+    @Override
+    public void initialize() throws Exception {
+        if (getLogger().isDebugEnabled())
+            getLogger().debug("Site tree monitor initialized.");
+        fileAlterationMonitor = new FileAlterationMonitor();
+    }
+
+    @Override
+    public void addListener(SiteTree siteTree,
+            SiteTreeMonitorListener listener)
+    {
+        // Publication/area content directory.
+        File contentDir = siteTree.getPublication().getContentDirectory(
+                siteTree.getArea());
+        String siteTreeKey = contentDir.getAbsolutePath() + "/" +
+                SiteTreeImpl.SITETREE_FILE_NAME;
+        if (!siteTreeMap.containsKey(siteTreeKey)) {
+            // Watch sitetree.xml file only.
+            FileFilter fileFilter = new FileFilter() {
+                @Override
+                public boolean accept(File pathname) {
+                    return pathname.getName().equals(
+                            SiteTreeImpl.SITETREE_FILE_NAME);
+                }
+            };
+            FileAlterationObserver observer =
+                new FileAlterationObserver(contentDir, fileFilter);
+            observer.addListener(new FileAlterationListenerAdaptor() {
+                @Override
+                public void onFileChange(File file) {
+                    if (getLogger().isDebugEnabled())
+                        getLogger().debug("Site tree modified [" +
+                                file.getAbsolutePath() + "]");
+                    String siteTreeKey = file.getAbsolutePath();
+                    SiteTree siteTree = siteTreeMap.get(siteTreeKey);
+                    SiteTreeMonitorListener listener = listenerMap.get(siteTreeKey);
+                    // Notify listener.
+                    listener.siteTreeModified(siteTree);
+                }
+            });
+            fileAlterationMonitor.addObserver(observer);
+            siteTreeMap.put(siteTreeKey, siteTree);
+            listenerMap.put(siteTreeKey, listener);
+            if (getLogger().isDebugEnabled())
+                getLogger().debug("Site tree monitor listener added for " +
+                        siteTreeKey);
+        } else {
+            if (getLogger().isWarnEnabled())
+                getLogger().warn("Site tree monitor listener already " +
+                        "added for " + siteTreeKey);
+        }
+    }
+
+}

Added: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorListener.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorListener.java?rev=1052317&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorListener.java (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeMonitorListener.java Thu Dec 23 17:02:20 2010
@@ -0,0 +1,9 @@
+package org.apache.lenya.cms.site.tree2;
+
+import org.apache.lenya.cms.site.tree.SiteTree;
+
+public interface SiteTreeMonitorListener {
+
+    void siteTreeModified(SiteTree siteTree);
+
+}

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeSiteManager.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeSiteManager.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeSiteManager.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/TreeSiteManager.java Thu Dec 23 17:02:20 2010
@@ -18,8 +18,11 @@
 package org.apache.lenya.cms.site.tree2;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.lenya.cms.publication.Area;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentException;
@@ -40,7 +43,13 @@ import org.apache.lenya.cms.site.tree.Si
 /**
  * Tree-based site manager.
  */
-public class TreeSiteManager extends AbstractSiteManager {
+public class TreeSiteManager extends AbstractSiteManager
+implements SiteTreeMonitorListener
+{
+    
+    private SiteTreeMonitor siteTreeMonitor;
+    private static HashMap<String, SiteTree> siteTreeMap =
+        new HashMap<String, SiteTree>();
 
     /**
      * Returns the sitetree for a specific area of this publication. Sitetrees are created on demand
@@ -51,7 +60,6 @@ public class TreeSiteManager extends Abs
      * @throws SiteException if an error occurs.
      */
     protected SiteTree getTree(Area area) throws SiteException {
-
         String key = getKey(area);
         SiteTree sitetree;
         RepositoryItemFactory factory = new SiteTreeFactory(this.manager, getLogger());
@@ -61,7 +69,13 @@ public class TreeSiteManager extends Abs
         } catch (Exception e) {
             throw new SiteException(e);
         }
-
+        // Only support site tree reloading for live area.
+        if (area.getName().equals(Publication.LIVE_AREA)) {
+            if (!siteTreeMap.containsKey(key)) {
+                siteTreeMonitor.addListener(sitetree, this);
+                siteTreeMap.put(key, sitetree);
+            }
+        }
         return sitetree;
     }
 
@@ -287,4 +301,32 @@ public class TreeSiteManager extends Abs
         }
     }
 
+    @Override
+    public void service(ServiceManager manager) throws ServiceException {
+        super.service(manager);
+        siteTreeMonitor = (SiteTreeMonitor) manager.lookup(SiteTreeMonitor.ROLE);
+    }
+
+    @Override
+    public void siteTreeModified(SiteTree siteTree) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Site tree modified [" +
+                    siteTree.getPublication().getId() + ":" +
+                    siteTree.getArea() + "]");
+        }
+        if (siteTree instanceof DelegatingSiteTree) {
+            // Invalidate cached repository items when site was modified.
+            siteTree.getSession().invalidateAllRepositoryItems();
+            // Notify site tree to reload next time when accessed.
+            DelegatingSiteTree delegatingSiteTree =
+                (DelegatingSiteTree) siteTree;
+            delegatingSiteTree.notifySiteTreeModified();
+        } else {
+            if (getLogger().isWarnEnabled())
+                getLogger().warn("Unknown site tree implementation [" +
+                        siteTree.getClass().getName() + "]. " +
+                        "Reloading skipped.");
+        }
+    }
+
 }

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Thu Dec 23 17:02:20 2010
@@ -35,7 +35,6 @@ import org.apache.lenya.cms.observation.
 import org.apache.lenya.cms.observation.RepositoryEvent;
 import org.apache.lenya.cms.observation.RepositoryEventFactory;
 import org.apache.lenya.cms.rc.CheckInEntry;
-import org.apache.lenya.cms.rc.CheckOutEntry;
 import org.apache.lenya.cms.rc.RCML;
 import org.apache.lenya.cms.rc.RCMLEntry;
 import org.apache.lenya.cms.rc.RevisionControlException;
@@ -375,15 +374,12 @@ public class SourceNode extends Abstract
         }
     }
 
-    private RCML rcml;
     private Persistable persistable;
 
     protected synchronized RCML getRcml() {
-        if (this.rcml == null) {
-            SourceNodeRcmlFactory factory = SourceNodeRcmlFactory.getInstance();
-            this.rcml = factory.getRcml(this, this.manager);
-        }
-        return this.rcml;
+        // RCML is cached by factory. So don't cache it here.
+        SourceNodeRcmlFactory factory = SourceNodeRcmlFactory.getInstance();
+        return factory.getRcml(this, this.manager);
     }
 
     public History getHistory() {

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java Thu Dec 23 17:02:20 2010
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Vector;
 
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
@@ -43,6 +44,8 @@ import org.apache.lenya.xml.NamespaceHel
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import sun.security.action.GetLongAction;
+
 /**
  * Handle with the RCML file
  */
@@ -58,6 +61,7 @@ public class SourceNodeRCML implements R
 
     private String contentSourceUri;
     private String metaSourceUri;
+    private long lastModified;
 
     private static Map ELEMENTS = new HashMap();
     protected static final String ELEMENT_CHECKIN = "CheckIn";
@@ -122,6 +126,7 @@ public class SourceNodeRCML implements R
         Assert.notNull("XML document", helper);
         try {
             SourceUtil.writeDOM(helper.getDocument(), getRcmlSourceUri(), this.manager);
+            lastModified = SourceUtil.getLastModified(getRcmlSourceUri(), manager);
         } catch (Exception e) {
             throw new RevisionControlException(e);
         }
@@ -636,5 +641,15 @@ public class SourceNodeRCML implements R
         }
         return false;
     }
-    
+
+    public boolean isModifiedExternally() {
+        boolean isModified = false;
+        try {
+            long sourceLastModified = SourceUtil.getLastModified(getRcmlSourceUri(), manager);
+            isModified = (sourceLastModified != lastModified);
+        } catch (Exception e) {
+        }
+        return isModified;
+    }
+
 }

Modified: lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRcmlFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRcmlFactory.java?rev=1052317&r1=1052316&r2=1052317&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRcmlFactory.java (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRcmlFactory.java Thu Dec 23 17:02:20 2010
@@ -18,7 +18,6 @@
 package org.apache.lenya.cms.repository;
 
 import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.lenya.cms.rc.RCML;
@@ -37,7 +36,8 @@ public class SourceNodeRcmlFactory {
         return instance;
     }
 
-    private Map uri2rcml = new HashMap();
+    private HashMap<String, SourceNodeRCML> uri2rcml =
+        new HashMap<String, SourceNodeRCML>();
 
     private SourceNodeRcmlFactory() {
     }
@@ -49,8 +49,8 @@ public class SourceNodeRcmlFactory {
      */
     public synchronized RCML getRcml(SourceNode node, ServiceManager manager) {
         String uri = node.getSourceURI();
-        RCML rcml = (RCML) this.uri2rcml.get(uri);
-        if (rcml == null) {
+        SourceNodeRCML rcml = uri2rcml.get(uri);
+        if (rcml == null || (rcml != null && rcml.isModifiedExternally())) {
             rcml = new SourceNodeRCML(node.getContentSource().getRealSourceUri(), node
                     .getMetaSource().getRealSourceUri(), manager);
             this.uri2rcml.put(uri, rcml);



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


Mime
View raw message