portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r731466 [8/12] - in /portals/jetspeed-2/portal/branches/JPA_BRANCH: ./ components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ components/jetspeed-cm/src/main/java/org/apache/jetspeed/test/ components/jetspeed-page-manager/ com...
Date Mon, 05 Jan 2009 06:04:18 GMT
Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsContextImpl.java?rev=731466&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsContextImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsContextImpl.java Sun Jan  4 22:04:13 2009
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.om.page.jpa;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jetspeed.om.common.SecurityConstraintsContext;
+import org.apache.jetspeed.om.page.PageSecurity;
+import org.apache.jetspeed.om.page.AbstractSecurityConstraintImpl;
+import org.apache.jetspeed.om.page.SecurityConstraintsDef;
+
+/**
+ * SecurityConstraintsContextImpl
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public abstract class SecurityConstraintsContextImpl implements SecurityConstraintsContext
+{
+    private BaseElementImpl owningObject;
+    private SecurityConstraintList securityConstraints;
+    private SecurityConstraintsRefList securityConstraintsRefs;
+
+    private List allConstraints;
+
+    /**
+     * Set owning object to manage relationship inverses.
+     *
+     * @param owningObject object that this context is related to.
+     */
+    protected void setOwningObject(BaseElementImpl owningObject)
+    {
+        this.owningObject = owningObject;
+    }
+    
+    /**
+     * Get owning object to manage relationship inverses.
+     * 
+     * @return owning object this context is related to.
+     */
+    public BaseElementImpl getOwningObject()
+    {
+        return owningObject;
+    }
+    
+    /**
+     * Access mutable persistent collection member for List wrappers.
+     *
+     * @return persistent collection
+     */
+    protected abstract List accessConstraintsRefs();
+
+    /**
+     * Access mutable persistent collection member for List wrappers.
+     *
+     * @return persistent collection
+     */
+    protected abstract List accessConstraints();
+
+    /**
+     * getSecurityConstraintClass
+     *
+     * Return class of persistent constraint instance.
+     *
+     * @return constraint class
+     */
+    protected abstract Class getSecurityConstraintClass();
+
+    /**
+     * getSecurityConstraintsRefClass
+     *
+     * Return class of persistent constraints reference instance.
+     *
+     * @return constraints reference class
+     */
+    protected abstract Class getSecurityConstraintsRefClass();
+
+    /**
+     * checkConstraints
+     *
+     * @param actions actions to check
+     * @param userPrincipals principal users list
+     * @param rolePrincipals principal roles list
+     * @param groupPrincipals principal group list
+     * @param pageSecurity page security definitions
+     * @throws SecurityException
+     */
+    public void checkConstraints(List actions, List userPrincipals, List rolePrincipals, List groupPrincipals, PageSecurity pageSecurity) throws SecurityException
+    {
+        // if owner defined, override all constraints and allow all access
+        String owner = getOwner();
+        if ((owner != null) && (userPrincipals != null) && userPrincipals.contains(owner))
+        {
+            return;
+        }
+
+        // skip missing or empty constraints: permit all access
+        List checkConstraints = getAllSecurityConstraints(pageSecurity);
+        if ((checkConstraints != null) && !checkConstraints.isEmpty())
+        {
+            // test each action, constraints check passes only
+            // if all actions are permitted for principals
+            Iterator actionsIter = actions.iterator();
+            while (actionsIter.hasNext())
+            {
+                // check each action:
+                // - if any actions explicitly permitted, (including owner),
+                //   assume no permissions are permitted by default
+                // - if all constraints do not specify a permission, assume
+                //   access is permitted by default
+                String action = (String)actionsIter.next();
+                boolean actionPermitted = false;
+                boolean actionNotPermitted = false;
+                boolean anyActionsPermitted = (getOwner() != null);
+                
+                // check against constraints
+                Iterator checkConstraintsIter = checkConstraints.iterator();
+                while (checkConstraintsIter.hasNext())
+                {
+                    AbstractSecurityConstraintImpl constraint = (AbstractSecurityConstraintImpl)checkConstraintsIter.next();
+                    
+                    // if permissions specified, attempt to match constraint
+                    if (constraint.getPermissions() != null)
+                    {
+                        // explicit actions permitted
+                        anyActionsPermitted = true;
+
+                        // test action permission match and user/role/group principal match
+                        if (constraint.actionMatch(action) &&
+                            constraint.principalsMatch(userPrincipals, rolePrincipals, groupPrincipals, true))
+                        {
+                            actionPermitted = true;
+                            break;
+                        }
+                    }
+                    else
+                    {
+                        // permissions not specified: not permitted if any principal matched
+                        if (constraint.principalsMatch(userPrincipals, rolePrincipals, groupPrincipals, false))
+                        {
+                            actionNotPermitted = true;
+                            break;
+                        }
+                    }
+                }
+                
+                // fail if any action not permitted
+                if ((!actionPermitted && anyActionsPermitted) || actionNotPermitted)
+                {
+                    throw new SecurityException("SecurityConstraintsContextImpl.checkConstraints(): Access for " + action + " not permitted.");
+                }
+            }
+        }
+        else
+        {
+            // fail for any action if owner specified
+            // since no other constraints were found
+            if ((getOwner() != null) && !actions.isEmpty())
+            {
+                String action = (String)actions.get(0);
+                throw new SecurityException("SecurityConstraintsContextImpl.checkConstraints(): Access for " + action + " not permitted, (not owner).");
+            }
+        }
+    }
+
+    /**
+     * resetCachedSecurityConstraints
+     */
+    public void resetCachedSecurityConstraints()
+    {
+        // clear previously cached security constraints
+        clearAllSecurityConstraints();
+    }
+
+    /**
+     * getAllSecurityConstraints
+     *
+     * @param pageSecurity page security definitions
+     * @return all security constraints
+     */
+    private synchronized List getAllSecurityConstraints(PageSecurity pageSecurity)
+    {
+        // return previously cached security constraints
+        if (allConstraints != null)
+        {
+            return allConstraints;
+        }
+
+        // construct new ordered security constraints list
+        allConstraints = new ArrayList();
+
+        // add any defined security constraints
+        if ((getSecurityConstraints() != null) && !getSecurityConstraints().isEmpty())
+        {
+            allConstraints.addAll(securityConstraints);
+        }
+
+        // add any security constraints references
+        if ((getSecurityConstraintsRefs() != null) && !getSecurityConstraintsRefs().isEmpty())
+        {
+            List referencedConstraints = dereferenceSecurityConstraintsRefs(getSecurityConstraintsRefs(), pageSecurity);
+            if (referencedConstraints != null)
+            {
+                allConstraints.addAll(referencedConstraints);
+            }
+        }
+        
+        // add any global decurity constraints references
+        if (pageSecurity != null)
+        {
+            List globalConstraintsRefs = pageSecurity.getGlobalSecurityConstraintsRefs();
+            if ((globalConstraintsRefs != null) && !globalConstraintsRefs.isEmpty())
+            {
+                List referencedConstraints = dereferenceSecurityConstraintsRefs(globalConstraintsRefs, pageSecurity);
+                if (referencedConstraints != null)
+                {
+                    allConstraints.addAll(referencedConstraints);
+                }
+            }
+        }
+        
+        return allConstraints;
+    }
+
+    /**
+     * clearAllSecurityConstraints
+     */
+    protected synchronized void clearAllSecurityConstraints()
+    {
+        // clear previously cached security constraints
+        allConstraints = null;
+    }
+
+    /**
+     * dereferenceSecurityConstraintsRefs
+     *
+     * @param constraintsRefs constraints references to be dereferenced
+     * @param pageSecurity page security definitions
+     * @return security constraints
+     */
+    private List dereferenceSecurityConstraintsRefs(List constraintsRefs, PageSecurity pageSecurity)
+    {
+        List constraints = null;
+        if (pageSecurity != null)
+        {   
+            // dereference each security constraints definition
+            Iterator constraintsRefsIter = constraintsRefs.iterator();
+            while (constraintsRefsIter.hasNext())
+            {
+                String constraintsRef = (String)constraintsRefsIter.next();
+                SecurityConstraintsDef securityConstraintsDef = pageSecurity.getSecurityConstraintsDef(constraintsRef);
+                if ((securityConstraintsDef != null) && (securityConstraintsDef.getSecurityConstraints() != null))
+                {
+                    if (constraints == null)
+                    {
+                        constraints = new ArrayList();
+                    }
+                    constraints.addAll(securityConstraintsDef.getSecurityConstraints());
+                }
+            }
+        }
+        return constraints;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.common.SecurityConstraints#getSecurityConstraints()
+     */
+    public List getSecurityConstraints()
+    {
+        // return mutable inline constraint list
+        // by using list wrapper to manage apply order
+        if (securityConstraints == null)
+        {
+            securityConstraints = new SecurityConstraintList(this);
+        }
+        return securityConstraints;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.common.SecurityConstraints#setSecurityConstraints(java.util.List)
+     */
+    public void setSecurityConstraints(List constraints)
+    {
+        // set inline constraints by replacing existing
+        // entries with new elements if new collection
+        // is specified
+        List securityConstraints = getSecurityConstraints();
+        if (constraints != securityConstraints)
+        {
+            // replace all constraints
+            securityConstraints.clear();
+            if (constraints != null)
+            {
+                securityConstraints.addAll(constraints);
+            }
+        }
+        // reset cached security constraints
+        clearAllSecurityConstraints();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.common.SecurityConstraints#getSecurityConstraintsRefs()
+     */
+    public List getSecurityConstraintsRefs()
+    {
+        // return mutable constraints refs list
+        // by using list wrapper to manage apply
+        // order and element uniqueness
+        if (securityConstraintsRefs == null)
+        {
+            securityConstraintsRefs = new SecurityConstraintsRefList(this);
+        }
+        return securityConstraintsRefs;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.common.SecurityConstraints#setSecurityConstraintsRefs(java.util.List)
+     */
+    public void setSecurityConstraintsRefs(List constraintsRefs)
+    {
+        // set constraints refs using ordered ref
+        // names by replacing existing entries with
+        // new elements if new collection is specified
+        List securityConstraintsRefs = getSecurityConstraintsRefs();
+        if (constraintsRefs != securityConstraintsRefs)
+        {
+            // replace all constraints ref names
+            securityConstraintsRefs.clear();
+            if (constraintsRefs != null)
+            {
+                securityConstraintsRefs.addAll(constraintsRefs);
+            }
+        }
+        // reset cached security constraints
+        clearAllSecurityConstraints();
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsDefImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsDefImpl.java?rev=731466&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsDefImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsDefImpl.java Sun Jan  4 22:04:13 2009
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.om.page.jpa;
+
+import java.util.List;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
+import javax.persistence.PostLoad;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.persistence.Version;
+
+import org.apache.jetspeed.om.page.SecurityConstraintsDef;
+import org.apache.jetspeed.page.jpa.DatabasePageManagerUtils;
+
+/**
+ * SecurityConstraintsDefImpl
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+@Entity (name="PageSecurityConstraintsDef")
+@Table (name="PAGE_SEC_CONSTRAINTS_DEF")
+public class SecurityConstraintsDefImpl implements SecurityConstraintsDef
+{
+    @Id
+    @GeneratedValue (strategy=GenerationType.AUTO)
+    @Column (name="CONSTRAINTS_DEF_ID")
+    private int id;
+    @Version
+    @Column (name="JPA_VERSION")
+    private int jpaVersion;
+    @ManyToOne (targetEntity=PageSecurityImpl.class, fetch=FetchType.LAZY, optional=false)
+    @JoinColumn (name="PAGE_SECURITY_ID", referencedColumnName="PAGE_SECURITY_ID")
+    private PageSecurityImpl pageSecurity;
+    @Basic
+    @Column (name="NAME")
+    private String name;
+    @OneToMany (targetEntity=PageSecuritySecurityConstraintImpl.class, mappedBy="constraintsDef", fetch=FetchType.LAZY, cascade=CascadeType.ALL)    
+    @OrderBy (value="applyOrder ASC")
+    private List constraintDefs;
+
+    @PostLoad
+    private void eagerFetchCollections()
+    {
+        if (constraintDefs != null)
+        {
+            constraintDefs.size();
+        }
+    }
+
+    @Transient
+    private SecurityConstraintDefList securityConstraintDefs;
+
+    /**
+     * Explicitly set inverse relationship when this object
+     * is added to a one-to-many collection. JPA does not
+     * manage bidirectional relationships.
+     * 
+     * @param inverse inverse relationship owning object.
+     */
+    public void setInverseRelationship(Object inverse)
+    {
+        pageSecurity = (PageSecurityImpl)inverse;
+    }
+    
+    /**
+     * accessConstraintDefs
+     *
+     * Access mutable persistent collection member for List wrappers.
+     *
+     * @return persistent collection
+     */
+    List accessConstraintDefs()
+    {
+        // create initial collection if necessary
+        if (constraintDefs == null)
+        {
+            constraintDefs = DatabasePageManagerUtils.createList();
+        }
+        return constraintDefs;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#getName()
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#setName(java.lang.String)
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#getSecurityConstraints()
+     */
+    public List getSecurityConstraints()
+    {
+        // return mutable constraint def list
+        // by using list wrapper to manage apply order
+        if (securityConstraintDefs == null)
+        {
+            securityConstraintDefs = new SecurityConstraintDefList(this);
+        }
+        return securityConstraintDefs;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#setSecurityConstraints(java.util.List)
+     */
+    public void setSecurityConstraints(List constraints)
+    {
+        // set constraint defs by replacing existing
+        // entries with new elements if new collection
+        // is specified
+        List securityConstraintDefs = getSecurityConstraints();
+        if (constraints != securityConstraintDefs)
+        {
+            // replace all constraints
+            securityConstraintDefs.clear();
+            if (constraints != null)
+            {
+                securityConstraintDefs.addAll(constraints);
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object o)
+    {
+        if (o instanceof SecurityConstraintsDefImpl)
+        {
+            if (name != null)
+            {
+                return name.equals(((SecurityConstraintsDefImpl)o).getName());
+            }
+            return (((SecurityConstraintsDefImpl)o).getName() == null);
+        }
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        if (name != null)
+        {
+            return name.hashCode();
+        }
+        return 0;
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsRefList.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsRefList.java?rev=731466&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsRefList.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/SecurityConstraintsRefList.java Sun Jan  4 22:04:13 2009
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.om.page.jpa;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SecurityConstraintsRefList
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+class SecurityConstraintsRefList extends AbstractList
+{
+    private SecurityConstraintsContextImpl constraints;
+    private Object constraintsOwningObject;
+
+    private List removedConstraintsRefs;
+
+    SecurityConstraintsRefList(SecurityConstraintsContextImpl constraints)
+    {
+        super();
+        this.constraints = constraints;
+        this.constraintsOwningObject = constraints.getOwningObject();
+    }
+
+    /**
+     * wrapNameStringForAdd
+     *
+     * Wraps and validates constraints ref name string
+     * to be added to this list.
+     *
+     * @param name constraints ref name string to add
+     * @return list element to add
+     */
+    private BaseSecurityConstraintsRef wrapNameStringForAdd(String name)
+    {
+        // only non-null names supported
+        if (name == null)
+        {
+            throw new NullPointerException("Unable to add null to list.");
+        }
+        // wrap constraints ref name string; use
+        // specific constraints ref name string wrapper
+        BaseSecurityConstraintsRef constraintsRef = null;
+        if (constraints.getSecurityConstraintsRefClass() != null)
+        {
+            try
+            {
+                constraintsRef = (BaseSecurityConstraintsRef)constraints.getSecurityConstraintsRefClass().newInstance();
+            }
+            catch (InstantiationException ie)
+            {
+                throw new ClassCastException("Unable to create constratins reference list element instance: " + constraints.getSecurityConstraintsRefClass().getName() + ", (" + ie + ").");
+            }
+            catch (IllegalAccessException iae)
+            {
+                throw new ClassCastException("Unable to create constraints reference list element instance: " + constraints.getSecurityConstraintsRefClass().getName() + ", (" + iae + ").");
+            }
+        }
+        else
+        {
+            constraintsRef = new BaseSecurityConstraintsRef();
+        }
+        constraintsRef.setName(name);
+        // make sure element is unique
+        if (constraints.accessConstraintsRefs().contains(constraintsRef))
+        {
+            throw new IllegalArgumentException("Unable to add duplicate entry to list: " + constraintsRef.getName());
+        }
+        // retrieve from removed list to reuse
+        // previously removed element
+        if (removedConstraintsRefs != null)
+        {
+            int removedIndex = removedConstraintsRefs.indexOf(constraintsRef);
+            if (removedIndex >= 0)
+            {
+                constraintsRef = (BaseSecurityConstraintsRef)removedConstraintsRefs.remove(removedIndex);
+            }
+        }
+        return constraintsRef;
+    }
+
+    /**
+     * getRemovedConstraintsRefs
+     *
+     * @return removed constraints refs tracking collection
+     */
+    private List getRemovedConstraintsRefs()
+    {
+        if (removedConstraintsRefs == null)
+        {
+            removedConstraintsRefs = new ArrayList();
+        }
+        return removedConstraintsRefs;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#add(int,java.lang.Object)
+     */
+    public synchronized void add(int index, Object element)
+    {
+        // implement for modifiable AbstractList:
+        // validate index
+        if ((index < 0) || (index > constraints.accessConstraintsRefs().size()))
+        {
+            throw new IndexOutOfBoundsException("Unable to add to list at index: " + index);
+        }
+        // wrap and verify constraints ref name string
+        BaseSecurityConstraintsRef constraintsRef = wrapNameStringForAdd((String)element);
+        // add to underlying ordered list
+        constraintsRef.setInverseRelationship(constraintsOwningObject);
+        constraints.accessConstraintsRefs().add(index, constraintsRef);
+        // set apply order in added element
+        if (index > 0)
+        {
+            constraintsRef.setApplyOrder(((BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().get(index-1)).getApplyOrder() + 1);
+        }
+        else
+        {
+            constraintsRef.setApplyOrder(0);
+        }
+        // maintain apply order in subsequent elements
+        for (int i = index, limit = constraints.accessConstraintsRefs().size() - 1; (i < limit); i++)
+        {
+            BaseSecurityConstraintsRef nextConstraintsRef = (BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().get(i + 1);
+            if (nextConstraintsRef.getApplyOrder() <= constraintsRef.getApplyOrder())
+            {
+                // adjust apply order for next element
+                nextConstraintsRef.setApplyOrder(constraintsRef.getApplyOrder() + 1);
+                constraintsRef = nextConstraintsRef;
+            }
+            else
+            {
+                // apply order maintained for remaining list elements
+                break;
+            }
+        }
+        // clear all cached security constraints
+        constraints.clearAllSecurityConstraints();
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#get(int)
+     */
+    public synchronized Object get(int index)
+    {
+        // implement for modifiable AbstractList:
+        // unwrap constraints ref name string
+        return ((BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().get(index)).getName();
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#remove(int)
+     */
+    public synchronized Object remove(int index)
+    {
+        // implement for modifiable AbstractList
+        BaseSecurityConstraintsRef removed = (BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().remove(index);
+        if (removed != null)
+        {
+            removed.setInverseRelationship(null);
+            // save removed element 
+            getRemovedConstraintsRefs().add(removed);
+            // clear all cached security constraints
+            constraints.clearAllSecurityConstraints();
+        }
+        return removed;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#set(int,java.lang.Object)
+     */
+    public synchronized Object set(int index, Object element)
+    {
+        // implement for modifiable AbstractList:
+        // wrap and verify constraints ref name string
+        BaseSecurityConstraintsRef newConstraintsRef = wrapNameStringForAdd((String)element);
+        // set in underlying ordered list
+        newConstraintsRef.setInverseRelationship(constraintsOwningObject);
+        BaseSecurityConstraintsRef constraintsRef = (BaseSecurityConstraintsRef)constraints.accessConstraintsRefs().set(index, newConstraintsRef);
+        constraintsRef.setInverseRelationship(null);
+        // set apply order in new element
+        newConstraintsRef.setApplyOrder(constraintsRef.getApplyOrder());
+        // save replaced element
+        getRemovedConstraintsRefs().add(constraintsRef);
+        // clear all cached security constraints
+        constraints.clearAllSecurityConstraints();
+        // return unwrapped constraints ref name string
+        return constraintsRef.getName();
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#size()
+     */
+    public synchronized int size()
+    {
+        // implement for modifiable AbstractList
+        return constraints.accessConstraintsRefs().size();
+    }
+}

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseElement.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseElement.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseElement.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseElement.java Sun Jan  4 22:04:13 2009
@@ -32,7 +32,7 @@
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.om.common.SecuredResource;
 import org.apache.jetspeed.om.common.SecurityConstraint;
-import org.apache.jetspeed.om.common.SecurityConstraints;
+import org.apache.jetspeed.om.common.SecurityConstraintsContext;
 import org.apache.jetspeed.om.page.BaseElement;
 import org.apache.jetspeed.om.page.PageSecurity;
 import org.apache.jetspeed.om.page.SecurityConstraintImpl;
@@ -63,7 +63,7 @@
 
     private boolean constraintsEnabled;
 
-    private SecurityConstraints constraints = null;
+    private SecurityConstraintsContext constraintsContext = null;
 
     private boolean permissionsEnabled;
     
@@ -169,28 +169,28 @@
 
     /**
      * <p>
-     * getSecurityConstraints
+     * getSecurityConstraintsContext
      * </p>
      *
-     * @see org.apache.jetspeed.om.common.SecureResource#getSecurityConstraints()
+     * @see org.apache.jetspeed.om.common.SecureResource#getSecurityConstraintsContext()
      * @return the PSML security constraints
      */
-    public SecurityConstraints getSecurityConstraints()
+    public SecurityConstraintsContext getSecurityConstraintsContext()
     {
-        return constraints;
+        return constraintsContext;
     }
     
     /**
      * <p>
-     * newSecurityConstraints
+     * newSecurityConstraintsContext
      * </p>
      *
      * @see org.apache.jetspeed.om.common.SecureResource#newSecurityConstraints()
      * @return  a new security constraints object
      */
-    public SecurityConstraints newSecurityConstraints()
+    public SecurityConstraintsContext newSecurityConstraintsContext()
     {
-        return new SecurityConstraintsImpl();
+        return new SecurityConstraintsContextImpl();
     }
 
     /**
@@ -208,15 +208,15 @@
 
     /**
      * <p>
-     * setSecurityConstraints
+     * setSecurityConstraintsContext
      * </p>
      *
-     * @see org.apache.jetspeed.om.common.SecureResource#setSecurityConstraints(org.apache.jetspeed.om.common.SecurityConstraints)
-     * @param constraints
+     * @see org.apache.jetspeed.om.common.SecureResource#setSecurityConstraintsContext(org.apache.jetspeed.om.common.SecurityConstraintsContext)
+     * @param constraintsContext
      */
-    public void setSecurityConstraints(SecurityConstraints constraints)
+    public void setSecurityConstraintsContext(SecurityConstraintsContext constraintsContext)
     {
-        this.constraints = constraints;
+        this.constraintsContext = constraintsContext;
     }
 
     /**
@@ -333,9 +333,9 @@
     public void checkConstraints(List actions, List userPrincipals, List rolePrincipals, List groupPrincipals, boolean checkNodeOnly, boolean checkParentsOnly) throws SecurityException
     {
         // check node constraints if available
-        if ((constraints != null) && !constraints.isEmpty())
+        if ((constraintsContext != null) && !constraintsContext.isEmpty())
         {
-            ((SecurityConstraintsImpl)constraints).checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
+            ((SecurityConstraintsContextImpl)constraintsContext).checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
         }
     }
 

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PageImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PageImpl.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PageImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PageImpl.java Sun Jan  4 22:04:13 2009
@@ -17,6 +17,7 @@
 
 package org.apache.jetspeed.om.page.psml;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -36,7 +37,6 @@
 import org.apache.jetspeed.om.folder.psml.MenuSeparatorDefinitionImpl;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
 
 /**
  * @version $Id$
@@ -255,7 +255,7 @@
 
     public List getFragmentsByName( String name )
     {
-        List fragments = DatabasePageManagerUtils.createList();
+        List fragments = new ArrayList();
 
         Stack stack = new Stack();
         if (getRootFragment() != null)

Copied: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsContextImpl.java (from r728362, portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsImpl.java)
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsContextImpl.java?p2=portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsContextImpl.java&p1=portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsImpl.java&r1=728362&r2=731466&rev=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsContextImpl.java Sun Jan  4 22:04:13 2009
@@ -23,14 +23,14 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.om.common.SecurityConstraints;
+import org.apache.jetspeed.om.common.SecurityConstraintsContext;
 import org.apache.jetspeed.om.page.PageSecurity;
 import org.apache.jetspeed.om.page.SecurityConstraintImpl;
 import org.apache.jetspeed.om.page.SecurityConstraintsDef;
 
 /**
  * <p>
- * SecurityConstraintsImpl
+ * SecurityConstraintsContextImpl
  * </p>
  * <p>
  *
@@ -39,9 +39,9 @@
  * @version $Id$
  *
  */
-public class SecurityConstraintsImpl implements SecurityConstraints
+public class SecurityConstraintsContextImpl implements SecurityConstraintsContext
 {
-    private final static Log log = LogFactory.getLog(SecurityConstraintsImpl.class);
+    private final static Log log = LogFactory.getLog(SecurityConstraintsContextImpl.class);
 
     private String owner;
 
@@ -224,7 +224,7 @@
                 // fail if any action not permitted
                 if ((!actionPermitted && anyActionsPermitted) || actionNotPermitted)
                 {
-                    throw new SecurityException("SecurityConstraintsImpl.checkConstraints(): Access for " + action + " not permitted.");
+                    throw new SecurityException("SecurityConstraintsContextImpl.checkConstraints(): Access for " + action + " not permitted.");
                 }
             }
         }

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsDefImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsDefImpl.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsDefImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/SecurityConstraintsDefImpl.java Sun Jan  4 22:04:13 2009
@@ -23,7 +23,7 @@
 
 /**
  * <p>
- * SecurityConstraintsImpl
+ * SecurityConstraintsContextImpl
  * </p>
  * <p>
  *

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/AbstractPageManager.java Sun Jan  4 22:04:13 2009
@@ -27,7 +27,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.om.common.SecurityConstraint;
-import org.apache.jetspeed.om.common.SecurityConstraints;
+import org.apache.jetspeed.om.common.SecurityConstraintsContext;
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.FolderNotFoundException;
 import org.apache.jetspeed.om.folder.InvalidFolderException;
@@ -44,7 +44,6 @@
 import org.apache.jetspeed.om.preference.FragmentPreference;
 import org.apache.jetspeed.page.document.Node;
 import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
 
 /**
  * AbstractPageManagerService
@@ -77,7 +76,7 @@
     protected Class pageMenuIncludeDefinitionClass;
     protected Class pageMenuOptionsDefinitionClass;
     protected Class pageMenuSeparatorDefinitionClass;
-    protected Class securityConstraintsClass;
+    protected Class securityConstraintsContextClass;
     protected Class folderSecurityConstraintClass;
     protected Class pageSecurityConstraintClass;
     protected Class fragmentSecurityConstraintClass;
@@ -117,7 +116,7 @@
         this.pageMenuIncludeDefinitionClass = (Class)modelClasses.get("PageMenuIncludeDefinitionImpl");
         this.pageMenuOptionsDefinitionClass = (Class)modelClasses.get("PageMenuOptionsDefinitionImpl");
         this.pageMenuSeparatorDefinitionClass = (Class)modelClasses.get("PageMenuSeparatorDefinitionImpl");
-        this.securityConstraintsClass = (Class)modelClasses.get("SecurityConstraintsImpl");
+        this.securityConstraintsContextClass = (Class)modelClasses.get("SecurityConstraintsContextImpl");
         this.folderSecurityConstraintClass = (Class)modelClasses.get("FolderSecurityConstraintImpl");
         this.pageSecurityConstraintClass = (Class)modelClasses.get("PageSecurityConstraintImpl");
         this.fragmentSecurityConstraintClass = (Class)modelClasses.get("FragmentSecurityConstraintImpl");
@@ -154,6 +153,31 @@
     }
 
     /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#registerContext(java.lang.Object)
+     */
+    public void registerContext(Object context)
+    {
+        // no context supported by default
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#getContext()
+     */
+    public Object getContext()
+    {
+        // no context supported by default
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.PageManager#unregisterContext(java.lang.Object)
+     */
+    public void unregisterContext(Object context)
+    {
+        // no context supported by default
+    }
+
+    /* (non-Javadoc)
      * @see org.apache.jetspeed.page.PageManager#newPage(java.lang.String)
      */
     public Page newPage(String path)
@@ -487,19 +511,19 @@
     }
 
     /**
-     * newSecurityConstraints - creates a new empty security constraints definition
+     * newSecurityConstraints - creates a new empty security constraints context definition
      *
-     * @return a newly created SecurityConstraints object
+     * @return a newly created SecurityConstraintsContext object
      */
-    public SecurityConstraints newSecurityConstraints()
+    public SecurityConstraintsContext newSecurityConstraintsContext()
     {
         try
         {
-            return (SecurityConstraints)createObject(this.securityConstraintsClass);
+            return (SecurityConstraintsContext)createObject(this.securityConstraintsContextClass);
         }
         catch (ClassCastException e)
         {
-            String message = "Failed to create security constraints definition object for " + this.securityConstraintsClass;
+            String message = "Failed to create security constraints context definition object for " + this.securityConstraintsContextClass;
             log.error(message, e);
         }
         return null;
@@ -817,15 +841,15 @@
         folder.getMetadata().copyFields(source.getMetadata().getFields());
         
         // copy security constraints
-        SecurityConstraints srcSecurity = source.getSecurityConstraints();        
-        if ((srcSecurity != null) && !srcSecurity.isEmpty())
+        SecurityConstraintsContext srcSecurityContext = source.getSecurityConstraintsContext();
+        if ((srcSecurityContext != null) && !srcSecurityContext.isEmpty())
         {
-            SecurityConstraints copiedSecurity = copySecurityConstraints(FOLDER_NODE_TYPE, srcSecurity);
-            folder.setSecurityConstraints(copiedSecurity);
+            SecurityConstraintsContext copiedSecurityContext = copySecurityConstraintsContext(FOLDER_NODE_TYPE, srcSecurityContext);
+            folder.setSecurityConstraintsContext(copiedSecurityContext);
         }    
         
         // copy document orders
-        folder.setDocumentOrder(DatabasePageManagerUtils.createList());
+        folder.setDocumentOrder(null);
         Iterator documentOrders = source.getDocumentOrder().iterator();
         while (documentOrders.hasNext())
         {
@@ -861,11 +885,11 @@
         page.getMetadata().copyFields(source.getMetadata().getFields());
         
         // copy security constraints
-        SecurityConstraints srcSecurity = source.getSecurityConstraints();        
-        if ((srcSecurity != null) && !srcSecurity.isEmpty())
+        SecurityConstraintsContext srcSecurityContext = source.getSecurityConstraintsContext();        
+        if ((srcSecurityContext != null) && !srcSecurityContext.isEmpty())
         {
-            SecurityConstraints copiedSecurity = copySecurityConstraints(PAGE_NODE_TYPE, srcSecurity);
-            page.setSecurityConstraints(copiedSecurity);
+            SecurityConstraintsContext copiedSecurityContext = copySecurityConstraintsContext(PAGE_NODE_TYPE, srcSecurityContext);
+            page.setSecurityConstraintsContext(copiedSecurityContext);
         }    
 
         // copy menu definitions
@@ -897,11 +921,11 @@
         copy.setState(source.getState());
 
         // copy security constraints
-        SecurityConstraints srcSecurity = source.getSecurityConstraints();        
-        if ((srcSecurity != null) && !srcSecurity.isEmpty())
+        SecurityConstraintsContext srcSecurityContext = source.getSecurityConstraintsContext();        
+        if ((srcSecurityContext != null) && !srcSecurityContext.isEmpty())
         {
-            SecurityConstraints copiedSecurity = copySecurityConstraints(FRAGMENT_NODE_TYPE, srcSecurity);
-            copy.setSecurityConstraints(copiedSecurity);
+            SecurityConstraintsContext copiedSecurityContext = copySecurityConstraintsContext(FRAGMENT_NODE_TYPE, srcSecurityContext);
+            copy.setSecurityConstraintsContext(copiedSecurityContext);
         }    
         
         // copy properties
@@ -913,7 +937,7 @@
         }
                   
         // copy preferences
-        copy.setPreferences(DatabasePageManagerUtils.createList());
+        copy.setPreferences(new ArrayList());
         Iterator prefs = source.getPreferences().iterator();
         while (prefs.hasNext())
         {
@@ -921,7 +945,7 @@
             FragmentPreference newPref = this.newFragmentPreference();
             newPref.setName(pref.getName());
             newPref.setReadOnly(pref.isReadOnly());
-            newPref.setValueList(DatabasePageManagerUtils.createList());
+            newPref.setValueList(new ArrayList());
             Iterator values = pref.getValueList().iterator();            
             while (values.hasNext())
             {
@@ -959,11 +983,11 @@
         link.getMetadata().copyFields(source.getMetadata().getFields());
         
         // copy security constraints
-        SecurityConstraints srcSecurity = source.getSecurityConstraints();        
-        if ((srcSecurity != null) && !srcSecurity.isEmpty())
+        SecurityConstraintsContext srcSecurityContext = source.getSecurityConstraintsContext();        
+        if ((srcSecurityContext != null) && !srcSecurityContext.isEmpty())
         {
-            SecurityConstraints copiedSecurity = copySecurityConstraints(LINK_NODE_TYPE, srcSecurity);
-            link.setSecurityConstraints(copiedSecurity);
+            SecurityConstraintsContext copiedSecurityContext = copySecurityConstraintsContext(LINK_NODE_TYPE, srcSecurityContext);
+            link.setSecurityConstraintsContext(copiedSecurityContext);
         }    
 
         return link;
@@ -978,14 +1002,14 @@
         copy.setVersion(source.getVersion());        
 
         // copy security constraint defintions
-        copy.setSecurityConstraintsDefs(DatabasePageManagerUtils.createList());                
+        copy.setSecurityConstraintsDefs(new ArrayList());                
         Iterator defs = source.getSecurityConstraintsDefs().iterator();
         while (defs.hasNext())
         {
             SecurityConstraintsDef def = (SecurityConstraintsDef)defs.next();
             SecurityConstraintsDef defCopy = this.newSecurityConstraintsDef();            
             defCopy.setName(def.getName());
-            List copiedConstraints = DatabasePageManagerUtils.createList();
+            List copiedConstraints = new ArrayList();
             Iterator constraints = def.getSecurityConstraints().iterator();
             while (constraints.hasNext())
             {
@@ -999,7 +1023,7 @@
         }
         
         // copy global security constraint references
-        copy.setGlobalSecurityConstraintsRefs(DatabasePageManagerUtils.createList());
+        copy.setGlobalSecurityConstraintsRefs(new ArrayList());
         Iterator globals = source.getGlobalSecurityConstraintsRefs().iterator();
         while (globals.hasNext())
         {
@@ -1012,7 +1036,7 @@
 
     protected List copyMenuDefinitions(String type, List srcMenus)
     {
-        List copiedMenus = DatabasePageManagerUtils.createList(); 
+        List copiedMenus = new ArrayList(); 
         Iterator menus = srcMenus.iterator();
         while (menus.hasNext())
         {
@@ -1059,7 +1083,7 @@
             List elements = source.getMenuElements();
             if (elements != null)
             {
-                List copiedElements = DatabasePageManagerUtils.createList(); 
+                List copiedElements = new ArrayList(); 
                 Iterator elementsIter = elements.iterator();
                 while (elementsIter.hasNext())
                 {
@@ -1163,16 +1187,16 @@
         dstConstraint.setPermissions(srcConstraint.getPermissions());        
     }
     
-    protected SecurityConstraints copySecurityConstraints(String type, SecurityConstraints source)
+    protected SecurityConstraintsContext copySecurityConstraintsContext(String type, SecurityConstraintsContext source)
     {
-        SecurityConstraints security = newSecurityConstraints();
+        SecurityConstraintsContext security = newSecurityConstraintsContext();
         if (source.getOwner() != null)        
         {
             security.setOwner(source.getOwner());
         }
         if (source.getSecurityConstraints() != null)
         {
-            List copiedConstraints = DatabasePageManagerUtils.createList();
+            List copiedConstraints = new ArrayList();
             Iterator constraints = source.getSecurityConstraints().iterator();
             while (constraints.hasNext())
             {
@@ -1201,7 +1225,7 @@
         }
         if (source.getSecurityConstraintsRefs() != null)
         {
-            List copiedRefs = DatabasePageManagerUtils.createList();
+            List copiedRefs = new ArrayList();
             Iterator refs = source.getSecurityConstraintsRefs().iterator();
             while (refs.hasNext())
             {                

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerSecurityUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerSecurityUtils.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerSecurityUtils.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerSecurityUtils.java Sun Jan  4 22:04:13 2009
@@ -190,7 +190,7 @@
                 // fail if any action not permitted
                 if ((!actionPermitted && anyActionsPermitted) || actionNotPermitted)
                 {
-                    //throw new SecurityException("SecurityConstraintsImpl.checkConstraints(): Access for " + action + " not permitted.");
+                    //throw new SecurityException("SecurityConstraintsContextImpl.checkConstraints(): Access for " + action + " not permitted.");
                     return false;
                 }
             }
@@ -202,7 +202,7 @@
             if (/*(getOwner() != null) && */ !actions.isEmpty())
             {
                 //String action = (String)actions.get(0);
-                //throw new SecurityException("SecurityConstraintsImpl.checkConstraints(): Access for " + action + " not permitted, (not owner).");
+                //throw new SecurityException("SecurityConstraintsContextImpl.checkConstraints(): Access for " + action + " not permitted, (not owner).");
                 return false;
             }
         }

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerUtils.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerUtils.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/PageManagerUtils.java Sun Jan  4 22:04:13 2009
@@ -23,7 +23,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.om.common.SecurityConstraints;
+import org.apache.jetspeed.om.common.SecurityConstraintsContext;
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.FolderNotFoundException;
 import org.apache.jetspeed.om.page.Link;
@@ -74,9 +74,9 @@
             else
             {
                 newUserFolder = pageManager.newFolder(Folder.USER_FOLDER + userName);
-                SecurityConstraints constraints = pageManager.newSecurityConstraints();
-                newUserFolder.setSecurityConstraints(constraints);
-                newUserFolder.getSecurityConstraints().setOwner(userName);
+                SecurityConstraintsContext constraintsContext = pageManager.newSecurityConstraintsContext();
+                newUserFolder.setSecurityConstraintsContext(constraintsContext);
+                newUserFolder.getSecurityConstraintsContext().setOwner(userName);
                 pageManager.updateFolder(newUserFolder);                
             }            
             // for each role for a user, deep copy the folder contents for that role 
@@ -236,13 +236,13 @@
         Folder dstFolder = pageManager.copyFolder(srcFolder, destinationPath);
         if (owner != null)
         {
-            SecurityConstraints constraints = dstFolder.getSecurityConstraints();
-            if (constraints == null)
+            SecurityConstraintsContext constraintsContext = dstFolder.getSecurityConstraintsContext();
+            if (constraintsContext == null)
             {
-                constraints = pageManager.newSecurityConstraints();
-                dstFolder.setSecurityConstraints(constraints);
+                constraintsContext = pageManager.newSecurityConstraintsContext();
+                dstFolder.setSecurityConstraintsContext(constraintsContext);
             }
-            dstFolder.getSecurityConstraints().setOwner(owner);
+            dstFolder.getSecurityConstraintsContext().setOwner(owner);
         }
         pageManager.updateFolder(dstFolder);
         
@@ -297,13 +297,13 @@
             dstFolder = pageManager.copyFolder(srcFolder, destinationPath);
             if (owner != null)
             {
-                SecurityConstraints constraints = dstFolder.getSecurityConstraints();
+                SecurityConstraintsContext constraints = dstFolder.getSecurityConstraintsContext();
                 if (constraints == null)
                 {
-                    constraints = pageManager.newSecurityConstraints();
-                    dstFolder.setSecurityConstraints(constraints);
+                    constraints = pageManager.newSecurityConstraintsContext();
+                    dstFolder.setSecurityConstraintsContext(constraints);
                 }
-                dstFolder.getSecurityConstraints().setOwner(owner);
+                dstFolder.getSecurityConstraintsContext().setOwner(owner);
             }
             pageManager.updateFolder(dstFolder);
         }

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/DocumentImpl.java Sun Jan  4 22:04:13 2009
@@ -17,7 +17,7 @@
 package org.apache.jetspeed.page.document.impl;
 
 import org.apache.jetspeed.om.page.Document;
-import org.apache.jetspeed.om.page.impl.SecurityConstraintsImpl;
+import org.apache.jetspeed.om.page.impl.SecurityConstraintsContextImpl;
 
 /**
  * DocumentImpl
@@ -31,7 +31,7 @@
     
     private boolean dirty = false;
     
-    public DocumentImpl(SecurityConstraintsImpl constraints)
+    public DocumentImpl(SecurityConstraintsContextImpl constraints)
     {
         super(constraints);
     }

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeImpl.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeImpl.java Sun Jan  4 22:04:13 2009
@@ -25,7 +25,7 @@
 import org.apache.jetspeed.om.page.PageMetadataImpl;
 import org.apache.jetspeed.om.page.PageSecurity;
 import org.apache.jetspeed.om.page.impl.BaseElementImpl;
-import org.apache.jetspeed.om.page.impl.SecurityConstraintsImpl;
+import org.apache.jetspeed.om.page.impl.SecurityConstraintsContextImpl;
 import org.apache.jetspeed.om.portlet.GenericMetadata;
 import org.apache.jetspeed.page.document.Node;
 import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
@@ -55,7 +55,7 @@
     private PageMetadataImpl pageMetadata;
     private String logicalPath;
 
-    public NodeImpl(SecurityConstraintsImpl constraints)
+    public NodeImpl(SecurityConstraintsContextImpl constraints)
     {
         super(constraints);
     }
@@ -241,10 +241,10 @@
             // check node constraints if available; otherwise,
             // recursively check parent constraints until
             // default constraints for node are checked
-            SecurityConstraintsImpl constraintsImpl = (SecurityConstraintsImpl)getSecurityConstraints();
-            if ((constraintsImpl != null) && !constraintsImpl.isEmpty())
+            SecurityConstraintsContextImpl constraintsContextImpl = (SecurityConstraintsContextImpl)getSecurityConstraintsContext();
+            if ((constraintsContextImpl != null) && !constraintsContextImpl.isEmpty())
             {
-                constraintsImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
+                constraintsContextImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
             }
             else
             {
@@ -261,10 +261,10 @@
             // to be skipped due to explicity granted access
             if (!checkParentsOnly)
             {
-                SecurityConstraintsImpl constraintsImpl = (SecurityConstraintsImpl)getSecurityConstraints();
-                if ((constraintsImpl != null) && !constraintsImpl.isEmpty())
+                SecurityConstraintsContextImpl constraintsContextImpl = (SecurityConstraintsContextImpl)getSecurityConstraintsContext();
+                if ((constraintsContextImpl != null) && !constraintsContextImpl.isEmpty())
                 {
-                    constraintsImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
+                    constraintsContextImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
                 }
             }
 

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeSetImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeSetImpl.java?rev=731466&r1=731465&r2=731466&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeSetImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/impl/NodeSetImpl.java Sun Jan  4 22:04:13 2009
@@ -44,12 +44,12 @@
 
     public NodeSetImpl(List nodes, Comparator comparator)
     {
-        this.nodes = new TreeMap(comparator);        
-        Object[] nodeToCopy = nodes.toArray();
-        for (int ix = 0; ix < nodeToCopy.length; ix++)
+        this.nodes = new TreeMap(comparator);
+        Iterator nodesIter = nodes.iterator();
+        while (nodesIter.hasNext())
         {
-            Node node = (Node)nodeToCopy[ix];
-            if (!this.nodes.containsKey( node.getName()))
+            Node node = (Node)nodesIter.next();
+            if (!this.nodes.containsKey(node.getName()))
             {
                 this.nodes.put(node.getName(), node);
             }

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/DocumentImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/DocumentImpl.java?rev=731466&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/DocumentImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/DocumentImpl.java Sun Jan  4 22:04:13 2009
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.page.document.jpa;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Transient;
+
+import org.apache.jetspeed.om.page.Document;
+
+/**
+ * DocumentImpl
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+@MappedSuperclass
+public abstract class DocumentImpl extends NodeImpl implements Document
+{
+    @Basic
+    @Column (name="VERSION")
+    private String version;
+
+    @Transient
+    private boolean dirty = false;
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.Document#setVersion()
+     */
+    public String getVersion()
+    {
+        return version;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.Document#setVersion(java.lang.String)
+     */
+    public void setVersion(String version)
+    {
+        this.version = version;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.Document#isDirty()
+     */
+    public boolean isDirty()
+    {
+		return dirty;
+	}
+    
+	/* (non-Javadoc)
+	 * @see org.apache.jetspeed.om.page.Document#setDirty(boolean)
+	 */
+	public void setDirty(boolean dirty)
+	{
+		this.dirty = dirty;
+	}
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/NodeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/NodeImpl.java?rev=731466&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/NodeImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/page/document/jpa/NodeImpl.java Sun Jan  4 22:04:13 2009
@@ -0,0 +1,626 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.page.document.jpa;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Transient;
+
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.PageMetadataImpl;
+import org.apache.jetspeed.om.page.PageSecurity;
+import org.apache.jetspeed.om.page.jpa.BaseElementImpl;
+import org.apache.jetspeed.om.page.jpa.SecurityConstraintsContextImpl;
+import org.apache.jetspeed.om.portlet.GenericMetadata;
+import org.apache.jetspeed.page.document.Node;
+
+/**
+ * NodeImpl
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+@MappedSuperclass
+public abstract class NodeImpl extends BaseElementImpl implements Node
+{
+    @Basic
+    @Column (name="PATH")
+    private String path;
+    @Basic
+    @Column (name="SUBSITE")
+    private String subsite;
+    @Basic
+    @Column (name="USER_PRINCIPAL")
+    private String user;
+    @Basic
+    @Column (name="ROLE_PRINCIPAL")
+    private String role;
+    @Basic
+    @Column (name="GROUP_PRINCIPAL")
+    private String group;
+    @Basic
+    @Column (name="MEDIATYPE")
+    private String mediatype;
+    @Basic
+    @Column (name="LOCALE")
+    private String locale;
+    @Basic
+    @Column (name="EXT_ATTR_NAME")
+    private String extendedAttributeName;
+    @Basic
+    @Column (name="EXT_ATTR_VALUE")
+    private String extendedAttributeValue;
+
+    @Transient
+    private PageMetadataImpl pageMetadata;
+    @Transient
+    private String logicalPath;
+    
+    /**
+     * Default constructor.
+     */
+    public NodeImpl()
+    {
+        path = Folder.PATH_SEPARATOR;
+    }
+
+    /**
+     * getCanonicalNodePath
+     *
+     * Format paths used to set and query NodeImpl instances.
+     *
+     * @param path specified path
+     * @return canonical path
+     */
+    public static String getCanonicalNodePath(String path)
+    {
+        // validate and format path
+        if ((path == null) || (path.length() == 0))
+        {
+            path = Folder.PATH_SEPARATOR;
+        }
+        if (!path.startsWith(Folder.PATH_SEPARATOR))
+        {
+            path = Folder.PATH_SEPARATOR + path;
+        }
+        if (path.endsWith(Folder.PATH_SEPARATOR) && !path.equals(Folder.PATH_SEPARATOR))
+        {
+            path = path.substring(0, path.length() - 1);
+        }
+        return path;
+    }
+
+    /**
+     * newPageMetadata
+     *
+     * Construct page manager specific metadata implementation.
+     *
+     * @param fields mutable fields collection
+     * @return page metadata
+     */
+    public PageMetadataImpl newPageMetadata(Collection fields)
+    {
+        // no metadata available by default
+        return null;
+    }
+
+    /**
+     * getPageMetadata
+     *
+     * Get page manager specific metadata implementation.
+     *
+     * @return page metadata
+     */
+    public PageMetadataImpl getPageMetadata()
+    {
+        if (pageMetadata == null)
+        {
+            Collection metadataFields = getMetadataFields();
+            if (metadataFields != null)
+            {
+                pageMetadata = newPageMetadata(getMetadataFields());
+            }
+        }
+        return pageMetadata;
+    }
+    
+    /**
+     * Access mutable persistent collection member for base class implementation.
+     * 
+     * @return node specific metadata fields collection.
+     */
+    protected abstract Collection getMetadataFields();
+
+    /**
+     * defaultTitleFromName
+     *
+     * Compute default title from name.
+     *
+     * @return default title
+     */
+    protected String defaultTitleFromName()
+    {
+        // transform name to title
+        String title = getName();
+        if (title != null)
+        {
+            // strip extensions and default root folder name
+            if ((getType() != null) && title.endsWith(getType()))
+            {
+                title = title.substring(0, title.length()-getType().length());
+            }
+            else if (title.equals(Folder.PATH_SEPARATOR))
+            {
+                title = "top";
+            }
+            // use space as word separator
+            title = title.replace('_', ' ');
+            title = title.replace('-', ' ');
+            // use title case for title words
+            int wordIndex = -1;
+            do
+            {
+                if (!Character.isTitleCase(title.charAt(wordIndex+1)))
+                {
+                    StringBuffer makeTitle = new StringBuffer();
+                    makeTitle.append(title.substring(0, wordIndex+1));
+                    makeTitle.append(Character.toTitleCase(title.charAt(wordIndex+1)));
+                    makeTitle.append(title.substring(wordIndex+2));
+                    title = makeTitle.toString();
+                }
+                wordIndex = title.indexOf(' ', wordIndex+1);
+            }
+            while (wordIndex != -1);
+        }
+        return title;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#getName()
+     */
+    public String getName()
+    {
+        // get name or compute from path
+        String name = super.getName();
+        if (name == null)
+        {
+            if (path != null)
+            {
+                if (!path.equals(Folder.PATH_SEPARATOR))
+                {
+                    name = path.substring(path.lastIndexOf(Folder.PATH_SEPARATOR) + 1);
+                }
+                else
+                {
+                    name = Folder.PATH_SEPARATOR;
+                }
+                super.setName(name);
+            }
+        }
+        return name;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#setName(java.lang.String)
+     */
+    public void setName(String name)
+    {
+        // set path based on name
+        if (name != null)
+        {
+            if (path != null)
+            {
+                // set path
+                if (!name.equals(Folder.PATH_SEPARATOR))
+                {
+                    path = path.substring(0, path.lastIndexOf(Folder.PATH_SEPARATOR) + 1) + name;
+                }
+                else
+                {
+                    path = Folder.PATH_SEPARATOR;
+                }
+
+                // reset logicalPath
+                logicalPath = null;
+            }
+            super.setName(name);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#getEffectivePageSecurity()
+     */
+    public PageSecurity getEffectivePageSecurity()
+    {
+        // by default, delegate to real parent node implementation
+        NodeImpl parentNodeImpl = (NodeImpl)getParent();
+        if (parentNodeImpl != null)
+        {
+            return parentNodeImpl.getEffectivePageSecurity();
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#checkConstraints(java.util.List, java.util.List, java.util.List, java.util.List, boolean, boolean)
+     */
+    public void checkConstraints(List actions, List userPrincipals, List rolePrincipals, List groupPrincipals, boolean checkNodeOnly, boolean checkParentsOnly) throws SecurityException
+    {
+        // check constraints in node hierarchy
+        if (checkNodeOnly)
+        {
+            // check node constraints if available; otherwise,
+            // recursively check parent constraints until
+            // default constraints for node are checked
+            SecurityConstraintsContextImpl constraintsContextImpl = (SecurityConstraintsContextImpl)getSecurityConstraintsContext();
+            if ((constraintsContextImpl != null) && !constraintsContextImpl.isEmpty())
+            {
+                constraintsContextImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
+            }
+            else
+            {
+                NodeImpl parentNodeImpl = (NodeImpl)getParent();
+                if (parentNodeImpl != null)
+                {
+                    parentNodeImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, checkNodeOnly, false);
+                }
+            }
+        }
+        else
+        {
+            // check node constraints if available and not
+            // to be skipped due to explicitly granted access
+            if (!checkParentsOnly)
+            {
+                SecurityConstraintsContextImpl constraintsContextImpl = (SecurityConstraintsContextImpl)getSecurityConstraintsContext();
+                if ((constraintsContextImpl != null) && !constraintsContextImpl.isEmpty())
+                {
+                    constraintsContextImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, getEffectivePageSecurity());
+                }
+            }
+
+            // recursively check all parent constraints in hierarchy
+            NodeImpl parentNodeImpl = (NodeImpl)getParent();
+            if (parentNodeImpl != null)
+            {
+                parentNodeImpl.checkConstraints(actions, userPrincipals, rolePrincipals, groupPrincipals, false, false);
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#checkPermissions(java.lang.String, int, boolean, boolean)
+     */
+    public void checkPermissions(String path, int mask, boolean checkNodeOnly, boolean checkParentsOnly) throws SecurityException
+    {
+        // check granted node permissions unless the check is
+        // to be skipped due to explicity granted access
+        if (!checkParentsOnly)
+        {
+            super.checkPermissions(path, mask, true, false);
+        }
+        
+        // if not checking node only, recursively check
+        // all parent permissions in hierarchy
+        if (!checkNodeOnly)
+        {
+            NodeImpl parentNodeImpl = (NodeImpl)getParent();
+            if (parentNodeImpl != null)
+            {
+                parentNodeImpl.checkPermissions(mask, false, false);
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#getLogicalPermissionPath()
+     */
+    public String getLogicalPermissionPath()
+    {
+        // compute logical path if required
+        if (logicalPath == null)
+        {
+            // check for path attributes
+            if ((subsite != null) || (user != null) || (role != null) || (group != null) || (mediatype != null) ||
+                (locale != null) || (extendedAttributeName != null) || (extendedAttributeValue != null))
+            {
+                // parse path, stripping reserved folders from path
+                boolean skipAttribute = false;
+                StringBuffer logicalPathBuffer = new StringBuffer();
+                StringTokenizer pathElements = new StringTokenizer(path, Folder.PATH_SEPARATOR);
+                while (pathElements.hasMoreTokens())
+                {
+                    // classify path element
+                    String pathElement = pathElements.nextToken();
+                    if (!skipAttribute)
+                    {
+                        if (!pathElement.startsWith(Folder.RESERVED_SUBSITE_FOLDER_PREFIX))
+                        {
+                            if (!pathElement.startsWith(Folder.RESERVED_FOLDER_PREFIX))
+                            {
+                                // append to logical path
+                                logicalPathBuffer.append(Folder.PATH_SEPARATOR);
+                                logicalPathBuffer.append(pathElement);
+                            }
+                            else
+                            {
+                                // skip next attribute path element
+                                skipAttribute = true;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        // attribute path element skipped
+                        skipAttribute = false;
+                    }
+                }
+                
+                // set logical path
+                if (logicalPathBuffer.length() > 0)
+                {
+                    logicalPath = logicalPathBuffer.toString();
+                }
+                else
+                {
+                    logicalPath = Folder.PATH_SEPARATOR;
+                }
+            }
+            else
+            {
+                // no path attributes: logical path and physical path equivalent
+                logicalPath = path;
+            }
+        }
+
+        return logicalPath;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.page.jpa.BaseElementImpl#getPhysicalPermissionPath()
+     */
+    public String getPhysicalPermissionPath()
+    {
+        // return path
+        return path;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getParent()
+     */
+    public Node getParent()
+    {
+        return getParentNode();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#setParent(org.apache.jetspeed.page.document.Node)
+     */
+    public void setParent(Node parent)
+    {
+        // set node parent
+        setParentNode(parent);
+
+        // update path if required
+        if (parent != null)
+        {
+            String parentPath = parent.getPath();
+            if ((parentPath.equals(Folder.PATH_SEPARATOR) &&
+                 (path.lastIndexOf(Folder.PATH_SEPARATOR) > 0)) ||
+                (!parentPath.equals(Folder.PATH_SEPARATOR) &&
+                 !parentPath.equals(path.substring(0, path.lastIndexOf(Folder.PATH_SEPARATOR)))))
+            {
+                // set path
+                path = parentPath + Folder.PATH_SEPARATOR + getName();
+
+                // reset logicalPath
+                logicalPath = null;
+            }
+        }
+    }
+    
+    /**
+     * Access persistent node specific parent node.
+     * 
+     * @return parent node.
+     */
+    protected abstract Node getParentNode();
+    
+    /**
+     * Set persistent node specific parent node.
+     * 
+     * @param parent parent node.
+     */
+    protected abstract void setParentNode(Node parent);
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getPath()
+     */
+    public String getPath()
+    {
+        // return path from attributes and base path
+        return path;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#setPath(java.lang.String)
+     */
+    public void setPath(String path)
+    {
+        // set canonical node path
+        this.path = getCanonicalNodePath(path);
+
+        // reset logical path
+        logicalPath = null;
+
+        // parse and set informational attributes from path
+        String attributeName = null;
+        StringTokenizer pathElements = new StringTokenizer(this.path, Folder.PATH_SEPARATOR);
+        while (pathElements.hasMoreTokens())
+        {
+            String pathElement = pathElements.nextToken();
+            if (attributeName != null)
+            {
+                // set last attribute name with attribute value
+                if (attributeName.startsWith(Folder.RESERVED_USER_FOLDER_NAME))
+                {
+                    user = pathElement.toLowerCase();
+                }
+                else if (attributeName.startsWith(Folder.RESERVED_ROLE_FOLDER_NAME))
+                {
+                    role = pathElement.toLowerCase();
+                }
+                else if (attributeName.startsWith(Folder.RESERVED_GROUP_FOLDER_NAME))
+                {
+                    group = pathElement.toLowerCase();
+                }
+                else if (attributeName.startsWith(Folder.RESERVED_MEDIATYPE_FOLDER_NAME))
+                {
+                    mediatype = pathElement.toLowerCase();
+                }
+                else if (attributeName.startsWith(Folder.RESERVED_LANGUAGE_FOLDER_NAME))
+                {
+                    if (locale != null)
+                    {
+                        // compose locale from language + country
+                        locale = pathElement.toLowerCase() + "_" + locale;
+                    }
+                    else
+                    {
+                        locale = pathElement.toLowerCase();
+                    }
+                }
+                else if (attributeName.startsWith(Folder.RESERVED_COUNTRY_FOLDER_NAME))
+                {
+                    if (locale != null)
+                    {
+                        // compose locale from language + country
+                        locale = locale + "_" + pathElement.toLowerCase() ;
+                    }
+                    else
+                    {
+                        locale = pathElement.toLowerCase();
+                    }
+                }
+                else if (attributeName.startsWith(Folder.RESERVED_FOLDER_PREFIX))
+                {
+                    extendedAttributeName = attributeName.substring(Folder.RESERVED_FOLDER_PREFIX.length());
+                    extendedAttributeValue = pathElement.toLowerCase();
+                }
+
+                // reset attribute name
+                attributeName = null;
+            }
+            else if (pathElement.startsWith(Folder.RESERVED_SUBSITE_FOLDER_PREFIX))
+            {
+                subsite = pathElement.substring(Folder.RESERVED_SUBSITE_FOLDER_PREFIX.length()).toLowerCase();
+            }
+            else if (pathElement.startsWith(Folder.RESERVED_FOLDER_PREFIX))
+            {
+                // save attribute name
+                attributeName = pathElement.toLowerCase();
+            }
+        }
+
+        // set name based on path
+        if (!this.path.equals(Folder.PATH_SEPARATOR))
+        {
+            super.setName(this.path.substring(this.path.lastIndexOf(Folder.PATH_SEPARATOR) + 1));
+        }
+        else
+        {
+            super.setName(Folder.PATH_SEPARATOR);
+        }
+
+        // reset parent if required
+        if (getParent() != null)
+        {
+            String parentPath = getParent().getPath();
+            if ((parentPath.equals(Folder.PATH_SEPARATOR) &&
+                 (this.path.lastIndexOf(Folder.PATH_SEPARATOR) > 0)) ||
+                (!parentPath.equals(Folder.PATH_SEPARATOR) &&
+                 !parentPath.equals(this.path.substring(0, this.path.lastIndexOf(Folder.PATH_SEPARATOR)))))
+            {
+                setParent(null);
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getMetadata()
+     */
+    public GenericMetadata getMetadata()
+    {
+        return getPageMetadata();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getTitle(java.util.Locale)
+     */
+    public String getTitle(Locale locale)
+    {
+        // get title from metadata or use default title
+        String title = getPageMetadata().getText("title", locale);
+        if (title == null)
+        {
+            title = getTitle();
+        }
+        return title;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getShortTitle(java.util.Locale)
+     */
+    public String getShortTitle(Locale locale)
+    {
+        // get short title from metadata or use title from metadata,
+        // default short title, or default title
+        String shortTitle = getPageMetadata().getText("short-title", locale);
+        if (shortTitle == null)
+        {
+            shortTitle = getPageMetadata().getText("title", locale);
+            if (shortTitle == null)
+            {
+                shortTitle = getShortTitle();
+                if (shortTitle == null)
+                {
+                    shortTitle = getTitle();
+                }
+            }
+        }
+        return shortTitle;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getType()
+     */
+    public abstract String getType();
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.page.document.Node#getUrl()
+     */
+    public String getUrl()
+    {
+        return path;
+    }
+}



---------------------------------------------------------------------
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