Package org.apache.jetspeed.om.page.impl

Examples of org.apache.jetspeed.om.page.impl.FragmentPropertyList


        String fragmentKey = getFragmentPropertyListFragmentKey(baseFragmentElementImpl);
        Subject subject = JSSubject.getSubject(AccessController.getContext());
        Principal userPrincipal = ((subject != null) ? SubjectHelper.getBestPrincipal(subject, User.class) : null);
        String fragmentListKey = getFragmentPropertyListKey(fragmentKey, userPrincipal);
        Map threadLocalCache = (Map)fragmentPropertyListsCache.get();
        FragmentPropertyList list = ((threadLocalCache != null) ? (FragmentPropertyList)threadLocalCache.get(fragmentListKey) : null);

        // get and cache persistent list
        if (list == null)
        {
            // get cached fragment property list components or
            // query from database if not cached and cache
            DatabasePageManagerCachedFragmentPropertyList globalFragmentPropertyList = DatabasePageManagerCache.fragmentPropertyListCacheLookup(fragmentKey);
            if (globalFragmentPropertyList == null)
            {
                globalFragmentPropertyList = new DatabasePageManagerCachedFragmentPropertyList(baseFragmentElementImpl.getBaseFragmentsElement().getPath());
                Criteria filter = new Criteria();
                filter.addEqualTo("fragment", new Integer(baseFragmentElementImpl.getIdentity()));
                filter.addIsNull("scope");
                QueryByCriteria query = QueryFactory.newQuery(FragmentPropertyImpl.class, filter);
                Collection fragmentProperties = getPersistenceBrokerTemplate().getCollectionByQuery(query);
                globalFragmentPropertyList.addAll(fragmentProperties);
                DatabasePageManagerCache.fragmentPropertyListCacheAdd(fragmentKey, globalFragmentPropertyList, false);
            }
            Map principalFragmentPropertyLists = null;
            DatabasePageManagerCachedFragmentPropertyList userFragmentPropertyList = null;
            if (subject != null)
            {
                if (GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                {
                    Set principals = subject.getPrincipals();
                    Iterator principalsIter = principals.iterator();
                    while (principalsIter.hasNext())
                    {
                        Principal principal = (Principal)principalsIter.next();
                        String principalScope = null;
                        if (principal instanceof User)
                        {
                            principalScope = USER_PROPERTY_SCOPE;
                        }
                        else if (principal instanceof Group)
                        {
                            principalScope = GROUP_PROPERTY_SCOPE;
                        }
                        else if (principal instanceof Role)
                        {
                            principalScope = ROLE_PROPERTY_SCOPE;
                        }
                        if (principalScope != null)
                        {
                            String principalKey = getFragmentPropertyListPrincipalKey(principalScope, principal.getName());
                            DatabasePageManagerCachedFragmentPropertyList principalFragmentPropertyList = DatabasePageManagerCache.principalFragmentPropertyListCacheLookup(principalKey);
                            if (principalFragmentPropertyList == null)
                            {
                                principalFragmentPropertyList = new DatabasePageManagerCachedFragmentPropertyList(principalScope, principalKey);
                                Criteria filter = new Criteria();
                                filter.addEqualTo("scope", principalScope);
                                filter.addEqualTo("scopeValue", principal.getName());
                                QueryByCriteria query = QueryFactory.newQuery(FragmentPropertyImpl.class, filter);
                                Collection fragmentProperties = getPersistenceBrokerTemplate().getCollectionByQuery(query);
                                principalFragmentPropertyList.addAll(fragmentProperties);
                                DatabasePageManagerCache.principalFragmentPropertyListCacheAdd(principalKey, principalFragmentPropertyList, false);
                            }
                            if (principalFragmentPropertyList != null)
                            {
                                if (principalFragmentPropertyLists == null)
                                {
                                    principalFragmentPropertyLists = new HashMap();
                                }
                                principalFragmentPropertyLists.put(principalKey, principalFragmentPropertyList);
                            }
                        }
                    }
                }
                else if (userPrincipal != null)
                {
                    String principalKey = getFragmentPropertyListPrincipalKey(USER_PROPERTY_SCOPE, userPrincipal.getName());
                    userFragmentPropertyList = DatabasePageManagerCache.principalFragmentPropertyListCacheLookup(principalKey);
                    if (userFragmentPropertyList == null)
                    {
                        userFragmentPropertyList = new DatabasePageManagerCachedFragmentPropertyList(USER_PROPERTY_SCOPE, principalKey);
                        Criteria filter = new Criteria();
                        filter.addEqualTo("scope", USER_PROPERTY_SCOPE);
                        filter.addEqualTo("scopeValue", userPrincipal.getName());
                        QueryByCriteria query = QueryFactory.newQuery(FragmentPropertyImpl.class, filter);
                        Collection fragmentProperties = getPersistenceBrokerTemplate().getCollectionByQuery(query);
                        userFragmentPropertyList.addAll(fragmentProperties);
                        DatabasePageManagerCache.principalFragmentPropertyListCacheAdd(principalKey, userFragmentPropertyList, false);
                    }
                }
            }
           
            // assemble fragment property list instance, (use transient
            // list or create new fragment property list)
            list = new FragmentPropertyList(baseFragmentElementImpl);
            list.getProperties().addAll(globalFragmentPropertyList);
            if (subject != null)
            {
                if (GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                {
                    if (principalFragmentPropertyLists != null)
                    {                       
                        Set principals = subject.getPrincipals();
                        Iterator principalsIter = principals.iterator();
                        while (principalsIter.hasNext())
                        {
                            Principal principal = (Principal)principalsIter.next();
                            String principalScope = null;
                            if (principal instanceof User)
                            {
                                principalScope = USER_PROPERTY_SCOPE;
                            }
                            else if (principal instanceof Group)
                            {
                                principalScope = GROUP_PROPERTY_SCOPE;
                            }
                            else if (principal instanceof Role)
                            {
                                principalScope = ROLE_PROPERTY_SCOPE;
                            }
                            if (principalScope != null)
                            {
                                String principalKey = getFragmentPropertyListPrincipalKey(principalScope, principal.getName());
                                DatabasePageManagerCachedFragmentPropertyList principalFragmentPropertyList = (DatabasePageManagerCachedFragmentPropertyList)principalFragmentPropertyLists.get(principalKey);
                                List principalFragmentProperties = filterPrincipalFragmentPropertyList(principalFragmentPropertyList, baseFragmentElementImpl);
                                if (principalFragmentProperties != null)
                                {
                                    list.getProperties().addAll(principalFragmentProperties);
                                }
                            }
                        }
                    }
                }
                else if (userFragmentPropertyList != null)
                {
                    List userFragmentProperties = filterPrincipalFragmentPropertyList(userFragmentPropertyList, baseFragmentElementImpl);
                    if (userFragmentProperties != null)
                    {
                        list.getProperties().addAll(userFragmentProperties);
                    }
                }
            }

            // merge results into transient list if specified
            if ((list != null) && (transientList != null))
            {
                synchronized (transientList)
                {
                    // merge into persistent list; this is unsafe due to the
                    // lack of transactional isolation in shared objects, but
                    // this should only happen before new objects are committed
                    // and here we are assuming that only the current user has
                    // access to the new objects
                    Iterator sourceIter = transientList.iterator();
                    while (sourceIter.hasNext())
                    {
                        FragmentProperty sourceProperty = (FragmentProperty)sourceIter.next();
                        FragmentProperty targetProperty = list.getMatchingProperty(sourceProperty);
                        if (targetProperty != null)
                        {
                            targetProperty.setValue(sourceProperty.getValue());
                        }
                        else
                        {
                            list.add(sourceProperty);
                        }
                    }
                   
                    // clear transient list
                    transientList.clearProperties();
View Full Code Here


     * @param transientList transient fragment property list
     */
    public void updateFragmentPropertyList(BaseFragmentElementImpl baseFragmentElementImpl, String scope, FragmentPropertyList transientList)
    {
        // update persistent list
        FragmentPropertyList list = getFragmentPropertyList(baseFragmentElementImpl, transientList);
        if (list != null)
        {
            // get subject
            Subject subject = JSSubject.getSubject(AccessController.getContext());
            Principal userPrincipal = ((subject != null) ? SubjectHelper.getBestPrincipal(subject, User.class) : null);
            String userPrincipalKey = ((userPrincipal != null) ? getFragmentPropertyListPrincipalKey(USER_PROPERTY_SCOPE, userPrincipal.getName()) : null);
           
            // update fragment properties in list in database
            boolean updateAllScopes = ((scope != null) && scope.equals(ALL_PROPERTY_SCOPE));
            synchronized (list)
            {
                // store property objects for add/update and decompose
                // update into cache updates, (assumes scoped property
                // extents are fully represented in list).
                boolean updateTransaction = false;
                DatabasePageManagerCachedFragmentPropertyList globalFragmentPropertyList = null;
                Map principalPartialFragmentPropertyLists = null;
                String fragmentKey = getFragmentPropertyListFragmentKey(baseFragmentElementImpl);
                List properties = list.getProperties();
                List removedProperties = list.getRemovedProperties();
               
                // construct scoped properties lists for cache updates from
                // all properties, (add, update, and remove)
                List allProperties = new ArrayList(properties);
                if (removedProperties != null)
View Full Code Here

        String fragmentKey = getFragmentPropertyListFragmentKey(baseFragmentElementImpl);
        Subject subject = JSSubject.getSubject(AccessController.getContext());
        Principal userPrincipal = ((subject != null) ? SubjectHelper.getBestPrincipal(subject, User.class) : null);
        String fragmentListKey = getFragmentPropertyListKey(fragmentKey, userPrincipal);
        Map threadLocalCache = (Map)fragmentPropertyListsCache.get();
        FragmentPropertyList list = ((threadLocalCache != null) ? (FragmentPropertyList)threadLocalCache.get(fragmentListKey) : null);

        // remove cached persistent list
        if (list != null)
        {
            // remove list from cache
            threadLocalCache.remove(fragmentKey);
            // cleanup list
            list.clearProperties();
        }
        // cleanup transient list
        if (transientList != null)
        {
            transientList.clearProperties();
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.page.impl.FragmentPropertyList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.