View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8   *
9   *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17  package org.apache.jetspeed.userinfo.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.jetspeed.om.common.UserAttribute;
26  import org.apache.jetspeed.om.common.UserAttributeRef;
27  import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
28  
29  /***
30   * <p> Common user info management support
31   * </p>
32   * 
33   * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
34   * @version $Id: AbstractUserInfoManagerImpl.java 516448 2007-03-09 16:25:47Z ate $
35   */
36  public abstract class AbstractUserInfoManagerImpl
37  {
38      /*** Logger */
39      private static final Log log = LogFactory.getLog(UserInfoManagerImpl.class);
40      
41      /***
42       * <p>
43       * Return the linked attributes mapping portlet user attributes to portal
44       * user attributes.
45       * </p>
46       * 
47       * @param userAttributes
48       *            The declarative portlet user attributes.
49       * @param userAttributeRefs
50       *            The declarative jetspeed portlet extension user attributes
51       *            reference.
52       * @return The collection of linked attributes.
53       */
54      protected Collection mapLinkedUserAttributes(Collection userAttributes, Collection userAttributeRefs)
55      {
56          Collection linkedUserAttributes = new ArrayList();
57          if ((null != userAttributeRefs) && (userAttributeRefs.size() > 0))
58          {
59              Iterator attrIter = userAttributes.iterator();
60              while (attrIter.hasNext())
61              {
62                  UserAttribute currentAttribute = (UserAttribute) attrIter.next();
63                  boolean linkedAttribute = false;
64                  if (null != currentAttribute)
65                  {
66                      Iterator attrRefsIter = userAttributeRefs.iterator();
67                      while (attrRefsIter.hasNext())
68                      {
69                          UserAttributeRef currentAttributeRef = (UserAttributeRef) attrRefsIter.next();
70                          if (null != currentAttributeRef)
71                          {
72                              if ((currentAttribute.getName()).equals(currentAttributeRef.getNameLink()))
73                              {
74                                  if (log.isDebugEnabled())
75                                      log.debug("Linking user attribute ref: [[name, " + currentAttribute.getName()
76                                              + "], [linked name, " + currentAttributeRef.getName() + "]]");
77                                  linkedUserAttributes.add(currentAttributeRef);
78                                  linkedAttribute = true;
79                              }
80                          }
81                      }
82                  }
83                  if (!linkedAttribute)
84                  {
85                      linkedUserAttributes.add(new UserAttributeRefImpl(currentAttribute));
86                  }
87              }
88          }
89          else
90          {
91              Iterator attrIter = userAttributes.iterator();
92              while (attrIter.hasNext())
93              {
94                  UserAttribute currentAttribute = (UserAttribute) attrIter.next();
95                  linkedUserAttributes.add(new UserAttributeRefImpl(currentAttribute));
96              }
97          }
98          return linkedUserAttributes;
99      }
100 
101 }