001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.userinfo.impl;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.jetspeed.om.common.UserAttribute;
026: import org.apache.jetspeed.om.common.UserAttributeRef;
027: import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
028:
029: /**
030: * <p> Common user info management support
031: * </p>
032: *
033: * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
034: * @version $Id: AbstractUserInfoManagerImpl.java 516448 2007-03-09 16:25:47Z ate $
035: */
036: public abstract class AbstractUserInfoManagerImpl {
037: /** Logger */
038: private static final Log log = LogFactory
039: .getLog(UserInfoManagerImpl.class);
040:
041: /**
042: * <p>
043: * Return the linked attributes mapping portlet user attributes to portal
044: * user attributes.
045: * </p>
046: *
047: * @param userAttributes
048: * The declarative portlet user attributes.
049: * @param userAttributeRefs
050: * The declarative jetspeed portlet extension user attributes
051: * reference.
052: * @return The collection of linked attributes.
053: */
054: protected Collection mapLinkedUserAttributes(
055: Collection userAttributes, Collection userAttributeRefs) {
056: Collection linkedUserAttributes = new ArrayList();
057: if ((null != userAttributeRefs)
058: && (userAttributeRefs.size() > 0)) {
059: Iterator attrIter = userAttributes.iterator();
060: while (attrIter.hasNext()) {
061: UserAttribute currentAttribute = (UserAttribute) attrIter
062: .next();
063: boolean linkedAttribute = false;
064: if (null != currentAttribute) {
065: Iterator attrRefsIter = userAttributeRefs
066: .iterator();
067: while (attrRefsIter.hasNext()) {
068: UserAttributeRef currentAttributeRef = (UserAttributeRef) attrRefsIter
069: .next();
070: if (null != currentAttributeRef) {
071: if ((currentAttribute.getName())
072: .equals(currentAttributeRef
073: .getNameLink())) {
074: if (log.isDebugEnabled())
075: log
076: .debug("Linking user attribute ref: [[name, "
077: + currentAttribute
078: .getName()
079: + "], [linked name, "
080: + currentAttributeRef
081: .getName()
082: + "]]");
083: linkedUserAttributes
084: .add(currentAttributeRef);
085: linkedAttribute = true;
086: }
087: }
088: }
089: }
090: if (!linkedAttribute) {
091: linkedUserAttributes.add(new UserAttributeRefImpl(
092: currentAttribute));
093: }
094: }
095: } else {
096: Iterator attrIter = userAttributes.iterator();
097: while (attrIter.hasNext()) {
098: UserAttribute currentAttribute = (UserAttribute) attrIter
099: .next();
100: linkedUserAttributes.add(new UserAttributeRefImpl(
101: currentAttribute));
102: }
103: }
104: return linkedUserAttributes;
105: }
106:
107: }
|