portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r893702 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/impl/ components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/ components/jetspeed-page-manage...
Date Thu, 24 Dec 2009 07:04:45 GMT
Author: rwatler
Date: Thu Dec 24 07:04:33 2009
New Revision: 893702

URL: http://svn.apache.org/viewvc?rev=893702&view=rev
Log:
Fine Grain Scoped Fragment Property Update Page Manager API
---------------------------------------------------------------------
- added PageManager.updateFragmentProperties() API and implementations
- the PageManager.updateFragmentProperties() API can update fragment properties for user,
group, role, global, and all scopes

Notes:

- this method does not check for edit access for user scoped properties updates:
  it is assumed that properties can be set in the user scope for any fragment that
  is viewable by the user
- with the PSML/XML file page manager implementation, this API must write the
  entire page, page template, dynamic page, or fragment definition
- with the DBPSML page manager implementation, this method updates only fragment
  properties and avoides the overhead of updating the entire document
- given these various implementations and lack of transaction isolation in
  Jetspeed's persistence implementations, it is important that other changes not
  be made on the page, page template, dynamic page or fragment definition document
  and its child fragments before this API is invoked: only modifications of the
  fragment properties and the specified scope(s) should be made before invoking this
  API.


Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/impl/BaseFragmentElementImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/DelegatingPageManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/psml/CastorXmlPageManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/page/PageManager.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/impl/BaseFragmentElementImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/impl/BaseFragmentElementImpl.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/impl/BaseFragmentElementImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/impl/BaseFragmentElementImpl.java
Thu Dec 24 07:04:33 2009
@@ -25,6 +25,7 @@
 import org.apache.jetspeed.om.page.BaseFragmentValidationListener;
 import org.apache.jetspeed.om.page.FragmentProperty;
 import org.apache.jetspeed.om.page.PageSecurity;
+import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.impl.DatabasePageManager;
 import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
 import org.apache.ojb.broker.PersistenceBroker;
@@ -1082,7 +1083,7 @@
         DatabasePageManager pageManager = getPageManager();
         if (pageManager != null)
         {
-            pageManager.updateFragmentPropertiesList(this, fragmentProperties);
+            pageManager.updateFragmentPropertiesList(this, PageManager.ALL_PROPERTY_SCOPE,
fragmentProperties);
             fragmentProperties = null;
         }
     }
@@ -1104,7 +1105,7 @@
         DatabasePageManager pageManager = getPageManager();
         if (pageManager != null)
         {
-            pageManager.updateFragmentPropertiesList(this, fragmentProperties);
+            pageManager.updateFragmentPropertiesList(this, PageManager.ALL_PROPERTY_SCOPE,
fragmentProperties);
             fragmentProperties = null;
         }
     }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
Thu Dec 24 07:04:33 2009
@@ -655,11 +655,21 @@
         this.preferences = preferences;  
     } 
     
-    AbstractBaseFragmentsElement getBaseFragmentsElement()
+    /**
+     * Get owning base fragments element.
+     * 
+     * @return base fragments element
+     */
+    public AbstractBaseFragmentsElement getBaseFragmentsElement()
     {
         return baseFragmentsElement;
     }
 
+    /**
+     * Set owning base fragments element.
+     * 
+     * @param base fragments element
+     */
     void setBaseFragmentsElement(AbstractBaseFragmentsElement baseFragmentsElement)
     {
         // set base fragments implementation

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/DelegatingPageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/DelegatingPageManager.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/DelegatingPageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/DelegatingPageManager.java
Thu Dec 24 07:04:33 2009
@@ -22,6 +22,7 @@
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.FolderNotFoundException;
 import org.apache.jetspeed.om.folder.InvalidFolderException;
+import org.apache.jetspeed.om.page.BaseFragmentElement;
 import org.apache.jetspeed.om.page.FragmentDefinition;
 import org.apache.jetspeed.om.page.DynamicPage;
 import org.apache.jetspeed.om.page.Link;
@@ -325,6 +326,15 @@
     }
 
     /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#updateFragmentProperties(org.apache.jetspeed.om.page.BaseFragmentElement,
java.lang.String)
+     */
+    public void updateFragmentProperties(BaseFragmentElement fragment, String scope) throws
NodeException,
+            PageNotUpdatedException
+    {
+        // TODO Auto-generated method stub
+    }
+
+    /* (non-Javadoc)
      * @see org.apache.jetspeed.page.PageManager#updateFolder(org.apache.jetspeed.om.folder.Folder)
      */
     public void updateFolder(Folder folder) throws NodeException,

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/impl/DatabasePageManager.java
Thu Dec 24 07:04:33 2009
@@ -2609,16 +2609,52 @@
         fragmentPropertyListsCache.remove();
     }
     
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#updateFragmentProperties(org.apache.jetspeed.om.page.BaseFragmentElement,
java.lang.String)
+     */
+    public void updateFragmentProperties(BaseFragmentElement fragment, String scope) throws
NodeException, PageNotUpdatedException
+    {
+        try
+        {
+            // validate fragment element
+            BaseFragmentElementImpl baseFragmentElementImpl = (BaseFragmentElementImpl)fragment;
+            if (baseFragmentElementImpl.getIdentity() == 0)
+            {
+                throw new PageNotUpdatedException("Properties for transient fragment cannot
be updated");
+            }
+            
+            // check access
+            boolean checkEditAccess = ((scope == null) || !scope.equals(USER_PROPERTY_SCOPE));
+            baseFragmentElementImpl.checkAccess(checkEditAccess ? JetspeedActions.EDIT :
JetspeedActions.VIEW);
+
+            // update fragment properties
+            updateFragmentPropertiesList(baseFragmentElementImpl, scope, null);
+        }
+        catch (PageNotUpdatedException pnue)
+        {
+            throw pnue;
+        }
+        catch (SecurityException se)
+        {
+            throw se;
+        }
+        catch (Exception e)
+        {
+            throw new PageNotUpdatedException("Fragment properties for fragment " + fragment.getId()
+ " not updated.", e);
+        }        
+    }
+
     /**
      * Get and cache fragment property list for specified fragment.
      * 
-     * @param baseFragmentElement owning fragment of fragment property list
+     * @param baseFragmentElementImpl owning fragment of fragment property list
+     * @param transientList transient fragment property list
      * @return new or cached fragment property list
      */
-    public FragmentPropertyList getFragmentPropertiesList(BaseFragmentElementImpl baseFragmentElement,
FragmentPropertyList transientList)
+    public FragmentPropertyList getFragmentPropertiesList(BaseFragmentElementImpl baseFragmentElementImpl,
FragmentPropertyList transientList)
     {
         // access thread local fragment property lists cache
-        String threadLocalCacheKey = getFragmentPropertiesListThreadLocalCacheKey(baseFragmentElement);
+        String threadLocalCacheKey = getFragmentPropertiesListThreadLocalCacheKey(baseFragmentElementImpl);
         Map threadLocalCache = (Map)fragmentPropertyListsCache.get();
 
         // get cached persistent list
@@ -2626,11 +2662,11 @@
         if (list == null)
         {
             // use transient list or create new fragment property list
-            list = ((transientList != null) ? transientList : new FragmentPropertyList(baseFragmentElement));
+            list = ((transientList != null) ? transientList : new FragmentPropertyList(baseFragmentElementImpl));
             
             // build fragment properties database query
             Criteria filter = new Criteria();
-            filter.addEqualTo("fragment", new Integer(baseFragmentElement.getIdentity()));
+            filter.addEqualTo("fragment", new Integer(baseFragmentElementImpl.getIdentity()));
             Criteria scopesFilter = new Criteria();
             Criteria globalScopeFilter = new Criteria();
             globalScopeFilter.addIsNull("scope");
@@ -2639,7 +2675,7 @@
             Subject subject = JSSubject.getSubject(AccessController.getContext());
             if (subject != null)
             {
-                if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
+                if (GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                 {
                     Set principals = subject.getPrincipals();
                     Iterator principalsIter = principals.iterator();
@@ -2649,21 +2685,21 @@
                         if (principal instanceof User)
                         {
                             Criteria userScopeFilter = new Criteria();
-                            userScopeFilter.addEqualTo("scope", FragmentProperty.USER_PROPERTY_SCOPE);
+                            userScopeFilter.addEqualTo("scope", USER_PROPERTY_SCOPE);
                             userScopeFilter.addEqualTo("scopeValue", principal.getName());
                             scopesFilter.addOrCriteria(userScopeFilter);
                         }
                         else if (principal instanceof Group)
                         {
                             Criteria groupScopeFilter = new Criteria();
-                            groupScopeFilter.addEqualTo("scope", FragmentProperty.GROUP_PROPERTY_SCOPE);
+                            groupScopeFilter.addEqualTo("scope", GROUP_PROPERTY_SCOPE);
                             groupScopeFilter.addEqualTo("scopeValue", principal.getName());
                             scopesFilter.addOrCriteria(groupScopeFilter);
                         }
                         else if (principal instanceof Role)
                         {
                             Criteria roleScopeFilter = new Criteria();
-                            roleScopeFilter.addEqualTo("scope", FragmentProperty.ROLE_PROPERTY_SCOPE);
+                            roleScopeFilter.addEqualTo("scope", ROLE_PROPERTY_SCOPE);
                             roleScopeFilter.addEqualTo("scopeValue", principal.getName());
                             scopesFilter.addOrCriteria(roleScopeFilter);
                         }
@@ -2675,7 +2711,7 @@
                     if (userPrincipal != null)
                     {
                         Criteria userScopeFilter = new Criteria();
-                        userScopeFilter.addEqualTo("scope", FragmentProperty.USER_PROPERTY_SCOPE);
+                        userScopeFilter.addEqualTo("scope", USER_PROPERTY_SCOPE);
                         userScopeFilter.addEqualTo("scopeValue", userPrincipal.getName());
                         scopesFilter.addOrCriteria(userScopeFilter);
                     }
@@ -2737,23 +2773,29 @@
     /**
      * Update fragment property list.
      * 
-     * @param list fragment property list
+     * @param baseFragmentElementImpl fragment element
+     * @param scope fragment property scope to update
+     * @param transientList transient fragment property list
      */
-    public void updateFragmentPropertiesList(BaseFragmentElementImpl baseFragmentElement,
FragmentPropertyList transientList)
+    public void updateFragmentPropertiesList(BaseFragmentElementImpl baseFragmentElementImpl,
String scope, FragmentPropertyList transientList)
     {
         // update persistent list
-        FragmentPropertyList list = getFragmentPropertiesList(baseFragmentElement, transientList);
+        FragmentPropertyList list = getFragmentPropertiesList(baseFragmentElementImpl, transientList);
         if (list != null)
         {
             // update fragment properties in list in database
+            boolean updateAllScopes = ((scope != null) && scope.equals(ALL_PROPERTY_SCOPE));
             synchronized (list)
             {
                 Iterator propertiesIter = list.getProperties().iterator();
                 while (propertiesIter.hasNext())
                 {
                     FragmentPropertyImpl storeProperty = (FragmentPropertyImpl)propertiesIter.next();
-                    storeProperty.setFragment(baseFragmentElement);
-                    getPersistenceBrokerTemplate().store(storeProperty);
+                    storeProperty.setFragment(baseFragmentElementImpl);
+                    if (updateAllScopes || ((scope == null) && (storeProperty.getScope()
== null)) || ((scope != null) && scope.equals(storeProperty.getScope())))
+                    {
+                        getPersistenceBrokerTemplate().store(storeProperty);
+                    }
                 }
                 List removedProperties = list.getRemovedProperties();
                 if (removedProperties != null)
@@ -2762,8 +2804,11 @@
                     while (removedPropertiesIter.hasNext())
                     {
                         FragmentPropertyImpl deleteProperty = (FragmentPropertyImpl)removedPropertiesIter.next();
-                        deleteProperty.setFragment(baseFragmentElement);
-                        getPersistenceBrokerTemplate().delete(deleteProperty);
+                        deleteProperty.setFragment(baseFragmentElementImpl);
+                        if (updateAllScopes || ((scope == null) && (deleteProperty.getScope()
== null)) || ((scope != null) && scope.equals(deleteProperty.getScope())))
+                        {
+                            getPersistenceBrokerTemplate().delete(deleteProperty);
+                        }
                     }
                 }
             }
@@ -2773,12 +2818,13 @@
     /**
      * Remove fragment property list.
      * 
-     * @param list fragment property list
+     * @param baseFragmentElementImpl fragment element
+     * @param transientList transient fragment property list
      */
-    public void removeFragmentPropertiesList(BaseFragmentElementImpl baseFragmentElement,
FragmentPropertyList transientList)
+    public void removeFragmentPropertiesList(BaseFragmentElementImpl baseFragmentElementImpl,
FragmentPropertyList transientList)
     {
         // access thread local fragment property lists cache
-        String threadLocalCacheKey = getFragmentPropertiesListThreadLocalCacheKey(baseFragmentElement);
+        String threadLocalCacheKey = getFragmentPropertiesListThreadLocalCacheKey(baseFragmentElementImpl);
         Map threadLocalCache = (Map)fragmentPropertyListsCache.get();
 
         // remove cached persistent list
@@ -2815,7 +2861,7 @@
 
         // remove all fragment properties in list from database
         Criteria filter = new Criteria();
-        filter.addEqualTo("fragment", new Integer(baseFragmentElement.getIdentity()));
+        filter.addEqualTo("fragment", new Integer(baseFragmentElementImpl.getIdentity()));
         QueryByCriteria query = QueryFactory.newQuery(FragmentPropertyImpl.class, filter);
         getPersistenceBrokerTemplate().deleteByQuery(query);
     }
@@ -2823,13 +2869,13 @@
     /**
      * Compute thread local cache key for fragment properties.
      * 
-     * @param baseFragmentElement owner of fragment properties
+     * @param baseFragmentElementImpl owner of fragment properties
      * @return key string
      */
-    private static String getFragmentPropertiesListThreadLocalCacheKey(BaseFragmentElementImpl
baseFragmentElement)
+    private static String getFragmentPropertiesListThreadLocalCacheKey(BaseFragmentElementImpl
baseFragmentElementImpl)
     {
         // base key
-        String key = baseFragmentElement.getBaseFragmentsElement().getPath()+"/"+baseFragmentElement.getId();
+        String key = baseFragmentElementImpl.getBaseFragmentsElement().getPath()+"/"+baseFragmentElementImpl.getId();
         // append current user if available
         Subject subject = JSSubject.getSubject(AccessController.getContext());
         if (subject != null)

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/psml/CastorXmlPageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/psml/CastorXmlPageManager.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/psml/CastorXmlPageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/psml/CastorXmlPageManager.java
Thu Dec 24 07:04:33 2009
@@ -36,14 +36,18 @@
 import org.apache.jetspeed.om.folder.psml.MenuIncludeDefinitionImpl;
 import org.apache.jetspeed.om.folder.psml.MenuOptionsDefinitionImpl;
 import org.apache.jetspeed.om.folder.psml.MenuSeparatorDefinitionImpl;
+import org.apache.jetspeed.om.page.BaseFragmentElement;
 import org.apache.jetspeed.om.page.DynamicPage;
+import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.FragmentDefinition;
+import org.apache.jetspeed.om.page.FragmentProperty;
 import org.apache.jetspeed.om.page.Link;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.om.page.PageSecurity;
 import org.apache.jetspeed.om.page.PageTemplate;
 import org.apache.jetspeed.om.page.SecurityConstraintImpl;
 import org.apache.jetspeed.om.page.SecurityConstraintsDef;
+import org.apache.jetspeed.om.page.psml.AbstractBaseFragmentElement;
 import org.apache.jetspeed.om.page.psml.AbstractBaseFragmentsElement;
 import org.apache.jetspeed.om.page.psml.DynamicPageImpl;
 import org.apache.jetspeed.om.page.psml.FragmentDefinitionImpl;
@@ -63,6 +67,7 @@
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.PageManagerSecurityUtils;
 import org.apache.jetspeed.page.PageNotFoundException;
+import org.apache.jetspeed.page.PageNotUpdatedException;
 import org.apache.jetspeed.page.document.DocumentException;
 import org.apache.jetspeed.page.document.DocumentHandlerFactory;
 import org.apache.jetspeed.page.document.DocumentNotFoundException;
@@ -255,7 +260,7 @@
     public void updatePage(Page page) throws NodeException
     {
         PageImpl pageImpl = (PageImpl)page;
-        updateFragmentsElement(pageImpl, Page.DOCUMENT_TYPE);
+        updateFragmentsElement(pageImpl, Page.DOCUMENT_TYPE, true);
     }
 
     /**
@@ -268,7 +273,7 @@
     public void updatePageTemplate(PageTemplate pageTemplate) throws NodeException
     {
         PageTemplateImpl pageTemplateImpl = (PageTemplateImpl)pageTemplate;
-        updateFragmentsElement(pageTemplateImpl, PageTemplate.DOCUMENT_TYPE);
+        updateFragmentsElement(pageTemplateImpl, PageTemplate.DOCUMENT_TYPE, true);
     }
 
     /**
@@ -281,7 +286,7 @@
     public void updateDynamicPage(DynamicPage dynamicPage) throws NodeException
     {
         DynamicPageImpl dynamicPageImpl = (DynamicPageImpl)dynamicPage;
-        updateFragmentsElement(dynamicPageImpl, DynamicPage.DOCUMENT_TYPE);
+        updateFragmentsElement(dynamicPageImpl, DynamicPage.DOCUMENT_TYPE, true);
     }
 
     /**
@@ -294,7 +299,45 @@
     public void updateFragmentDefinition(FragmentDefinition fragmentDefinition) throws NodeException
     {
         FragmentDefinitionImpl fragmentDefinitionImpl = (FragmentDefinitionImpl)fragmentDefinition;
-        updateFragmentsElement(fragmentDefinitionImpl, FragmentDefinition.DOCUMENT_TYPE);
+        updateFragmentsElement(fragmentDefinitionImpl, FragmentDefinition.DOCUMENT_TYPE,
true);
+    }
+
+    /**
+     * <p>
+     * updateFragmentProperty
+     * </p>
+     * 
+     * @see org.apache.jetspeed.page.PageManager#updateFragmentProperties(org.apache.jetspeed.om.page.BaseFragmentElement,
java.lang.String)
+     */
+    public void updateFragmentProperties(BaseFragmentElement fragment, String scope) throws
NodeException, PageNotUpdatedException
+    {
+        // fragment property writes not supported: lookup and
+        // update entire page, dynamic page, page template, or
+        // fragment definition; security is checked unless user
+        // scope is specified
+        AbstractBaseFragmentElement fragmentElement = (AbstractBaseFragmentElement)fragment;
+        AbstractBaseFragmentsElement fragmentsElement = ((fragmentElement != null) ? fragmentElement.getBaseFragmentsElement()
: null);
+        boolean checkEditAccess = ((scope == null) || !scope.equals(USER_PROPERTY_SCOPE));
+        if (fragmentsElement instanceof Page)
+        {
+            updateFragmentsElement(fragmentsElement, Page.DOCUMENT_TYPE, checkEditAccess);
+        }
+        else if (fragmentsElement instanceof DynamicPage)
+        {
+            updateFragmentsElement(fragmentsElement, DynamicPage.DOCUMENT_TYPE, checkEditAccess);
+        }
+        else if (fragmentsElement instanceof PageTemplate)
+        {
+            updateFragmentsElement(fragmentsElement, PageTemplate.DOCUMENT_TYPE, checkEditAccess);
+        }
+        else if (fragmentsElement instanceof FragmentDefinition)
+        {
+            updateFragmentsElement(fragmentsElement, FragmentDefinition.DOCUMENT_TYPE, checkEditAccess);
+        }
+        else
+        {
+            throw new PageNotUpdatedException("Unable to update fragment properties: no owning
page");
+        }
     }
 
     /**
@@ -306,7 +349,7 @@
      * @param documentType document type
      * @throws NodeException thrown on update error
      */
-    public void updateFragmentsElement(AbstractBaseFragmentsElement fragmentsElement, String
documentType) throws NodeException
+    private void updateFragmentsElement(AbstractBaseFragmentsElement fragmentsElement, String
documentType, boolean checkEditAccess) throws NodeException
     {
         // make sure path and related members are set
         if (fragmentsElement.getPath() != null)
@@ -342,8 +385,8 @@
             fragmentsElement.setPermissionsEnabled(handlerFactory.getPermissionsEnabled());
             fragmentsElement.setConstraintsEnabled(handlerFactory.getConstraintsEnabled());
             
-            // check for edit access
-            fragmentsElement.checkAccess(JetspeedActions.EDIT);
+            // check for edit/view access
+            fragmentsElement.checkAccess(checkEditAccess ? JetspeedActions.EDIT : JetspeedActions.VIEW);
             
             // update fragments/page
             handlerFactory.getDocumentHandler(documentType).updateDocument(fragmentsElement);
@@ -443,7 +486,7 @@
      * @param documentType document type
      * @throws NodeException thrown on remove error
      */
-    public void removeFragmentsElement(AbstractBaseFragmentsElement fragmentsElement, String
documentType) throws NodeException
+    private void removeFragmentsElement(AbstractBaseFragmentsElement fragmentsElement, String
documentType) throws NodeException
     {
         // check for edit access
         fragmentsElement.checkAccess(JetspeedActions.EDIT);

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
Thu Dec 24 07:04:33 2009
@@ -469,32 +469,7 @@
         f.setLayoutY(100.0F);
         f.setProperty("custom-0", null, null, "custom-value-0");
         f.setProperty("custom-1", null, null, "custom-value-1");
-        f.setProperty("custom-1", Fragment.USER_PROPERTY_SCOPE, "user", "custom-value-user-1");
         f.setProperty("custom-2", null, null, "custom-value-2");
-        final Fragment userFragment = f;
-        Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(),
new PrivilegedAction()
-        {
-            public Object run()
-            {
-                try
-                {
-                    userFragment.setProperty("custom-2", Fragment.USER_PROPERTY_SCOPE, null,
"custom-value-user-2");
-                    return null;
-                }
-                catch (Exception e)
-                {
-                    return e;
-                }
-                finally
-                {
-                    JSSubject.clearSubject();
-                }
-            }
-        }, null);
-        if (userException != null)
-        {
-            throw userException;
-        }
         root.getFragments().add(f);
         FragmentReference fr = pageManager.newFragmentReference();
         fr.setRefId("test002");
@@ -525,6 +500,44 @@
             System.err.println(errmsg);
             assertNotNull(errmsg, null);
         }
+        
+        final Fragment userFragment = (Fragment)((Fragment)page.getRootFragment()).getFragments().get(0);
+        Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(),
new PrivilegedAction()
+        {
+            public Object run()
+            {
+                try
+                {
+                    userFragment.setProperty("custom-1", Fragment.USER_PROPERTY_SCOPE, "user",
"custom-value-user-1");
+                    userFragment.setProperty("custom-2", Fragment.USER_PROPERTY_SCOPE, null,
"custom-value-user-2");
+
+                    try
+                    {
+                        pageManager.updateFragmentProperties(userFragment, PageManager.USER_PROPERTY_SCOPE);
+                    }
+                    catch (Exception e)
+                    {
+                        String errmsg = "Exception in page fragment properties update: "
+ e.toString();
+                        e.printStackTrace();
+                        System.err.println(errmsg);
+                        assertNotNull(errmsg, null);
+                    }
+                    return null;
+                }
+                catch (Exception e)
+                {
+                    return e;
+                }
+                finally
+                {
+                    JSSubject.clearSubject();
+                }
+            }
+        }, null);
+        if (userException != null)
+        {
+            throw userException;
+        }
 
         page = pageManager.getPage("/test002.psml");
         assertNotNull(page);

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestDatabasePageManager.java
Thu Dec 24 07:04:33 2009
@@ -142,7 +142,7 @@
     
     public void testCreates() throws Exception
     {
-        PageManager pageManager = (PageManager)scm.getComponent("pageManager");
+        final PageManager pageManager = (PageManager)scm.getComponent("pageManager");
         PageManagerEventListenerImpl pmel = new PageManagerEventListenerImpl();
         pageManager.addListener(pmel);
 
@@ -306,38 +306,6 @@
         root.setProperty("custom-1", null, null, "custom-value-1");
         root.setProperty("custom-2", null, null, "custom-value-2");
         root.setProperty("custom-3", null, null, "custom-value-3");
-        final Fragment userRootFragment = root;
-        Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(),
new PrivilegedAction()
-        {
-            public Object run()
-            {
-                try
-                {
-                    if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
-                    {
-                        userRootFragment.setProperty("custom-1", FragmentProperty.ROLE_PROPERTY_SCOPE,
"role", "custom-value-role-1");
-                        userRootFragment.setProperty("custom-2", FragmentProperty.ROLE_PROPERTY_SCOPE,
"role", "custom-value-role-2");
-                        userRootFragment.setProperty("custom-2", FragmentProperty.GROUP_PROPERTY_SCOPE,
"group", "custom-value-group-2");
-                        userRootFragment.setProperty("custom-3", FragmentProperty.ROLE_PROPERTY_SCOPE,
"role", "custom-value-role-3");
-                        userRootFragment.setProperty("custom-3", FragmentProperty.GROUP_PROPERTY_SCOPE,
"group", "custom-value-group-3");
-                    }
-                    userRootFragment.setProperty("custom-3", FragmentProperty.USER_PROPERTY_SCOPE,
"user", "custom-value-user-3");
-                    return null;
-                }
-                catch (Exception e)
-                {
-                    return e;
-                }
-                finally
-                {
-                    JSSubject.clearSubject();
-                }
-            }
-        }, null);
-        if (userException != null)
-        {
-            throw userException;
-        }
         
         Fragment portlet = pageManager.newPortletFragment();
         portlet.setName("security::LoginPortlet");
@@ -396,6 +364,46 @@
         assertEquals(1, folder.getPages().size());
         assertNotNull(pageManager.getPages(folder));
         assertEquals(1, pageManager.getPages(folder).size());
+        
+        final Fragment userRootFragment = (Fragment)page.getRootFragment();
+        Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(),
new PrivilegedAction()
+        {
+            public Object run()
+            {
+                try
+                {
+                    if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
+                    {
+                        userRootFragment.setProperty("custom-1", FragmentProperty.ROLE_PROPERTY_SCOPE,
"role", "custom-value-role-1");
+                        userRootFragment.setProperty("custom-2", FragmentProperty.ROLE_PROPERTY_SCOPE,
"role", "custom-value-role-2");
+                        userRootFragment.setProperty("custom-2", FragmentProperty.GROUP_PROPERTY_SCOPE,
"group", "custom-value-group-2");
+                        userRootFragment.setProperty("custom-3", FragmentProperty.ROLE_PROPERTY_SCOPE,
"role", "custom-value-role-3");
+                        userRootFragment.setProperty("custom-3", FragmentProperty.GROUP_PROPERTY_SCOPE,
"group", "custom-value-group-3");
+                    }
+                    userRootFragment.setProperty("custom-3", FragmentProperty.USER_PROPERTY_SCOPE,
"user", "custom-value-user-3");
+
+                    if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
+                    {
+                        pageManager.updateFragmentProperties(userRootFragment, PageManager.ROLE_PROPERTY_SCOPE);
+                        pageManager.updateFragmentProperties(userRootFragment, PageManager.GROUP_PROPERTY_SCOPE);
+                    }
+                    pageManager.updateFragmentProperties(userRootFragment, PageManager.USER_PROPERTY_SCOPE);
+                    return null;
+                }
+                catch (Exception e)
+                {
+                    return e;
+                }
+                finally
+                {
+                    JSSubject.clearSubject();
+                }
+            }
+        }, null);
+        if (userException != null)
+        {
+            throw userException;
+        }
 
         page = pageManager.newPage("/another-page.psml");
         assertEquals("Another Page", page.getTitle());

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/page/PageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/page/PageManager.java?rev=893702&r1=893701&r2=893702&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/page/PageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/page/PageManager.java
Thu Dec 24 07:04:33 2009
@@ -64,6 +64,36 @@
     public String SERVICE_NAME = "PageManager";
     
     /**
+     * user standard property scope
+     */
+    String USER_PROPERTY_SCOPE = FragmentProperty.USER_PROPERTY_SCOPE;
+
+    /**
+     * group standard property scope
+     */
+    String GROUP_PROPERTY_SCOPE = FragmentProperty.GROUP_PROPERTY_SCOPE;
+
+    /**
+     * role standard property scope
+     */
+    String ROLE_PROPERTY_SCOPE = FragmentProperty.ROLE_PROPERTY_SCOPE;
+
+    /**
+     * global standard property scope
+     */
+    String GLOBAL_PROPERTY_SCOPE = FragmentProperty.GLOBAL_PROPERTY_SCOPE;
+
+    /**
+     * all standard property scopes
+     */
+    String ALL_PROPERTY_SCOPE = "all";
+
+    /**
+     * group and role standard property scopes enabled flag
+     */
+    boolean GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED = FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED;
+
+    /**
      * <p>
      * getConstraintsEnabled
      * </p>
@@ -693,18 +723,32 @@
     /**
      * Update a fragment definition in persistent storage
      *
-     * @param dynamicPage The fragment definition to be updated.
+     * @param fragmentDefinition The fragment definition to be updated.
      */
     public void updateFragmentDefinition(FragmentDefinition fragmentDefinition) throws NodeException,
PageNotUpdatedException;
 
     /**
      * Remove a fragment definition.
      *
-     * @param dynamicPage The fragment definition to be removed.
+     * @param fragmentDefinition The fragment definition to be removed.
      */
     public void removeFragmentDefinition(FragmentDefinition fragmentDefinition) throws NodeException,
PageNotRemovedException;
     
     /**
+     * Update fragment properties for specified scope. Implementation
+     * may not be able to update fragment properties without updating
+     * entire page. Edit page security constraints will not be checked
+     * in these cases if the specified scope is user; this effectively
+     * circumvents security checks, so this method should only be used
+     * in places where the edits will be restricted to user fragment
+     * properties.
+     *
+     * @param fragment owner of fragment properties to update.
+     * @param scope fragment property scope to update, (user, group, role, global, or all).
+     */
+    public void updateFragmentProperties(BaseFragmentElement fragment, String scope) throws
NodeException, PageNotUpdatedException;
+    
+    /**
      * Update a folder and all child folders
      * and documents in persistent storage
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message