Java tutorial
/** * PureInfo TGirls * @(#)SNSDataHelper.java 1.0 2009-3-17 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.tgirls.sns; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import com.pureinfo.ark.content.ArkContentHelper; import com.pureinfo.tgirls.domain.IUserMgr; import com.pureinfo.tgirls.model.User; import com.pureinfo.tgirls.sns.constants.SessionConstants; import com.pureinfo.tgirls.utils.servlet.CookieUtils; import com.taobao.api.sns.response.ListResponse; public class SNSDataHelper { public static List<User> getFriends(String _taobaoId, HttpServletRequest _request) { if (StringUtils.isEmpty(_taobaoId)) { return null; } String sessionId = (String) CookieUtils.getRequestCookieValue(_request, SessionConstants.TAOBAO_SESSION_ID); try { ListResponse<com.taobao.api.sns.pojo.user.User> lr = TOPAPI.getInstance() .getFriends(Long.parseLong(_taobaoId), 1, 100, sessionId); IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); List<User> result = new ArrayList<User>(); if (lr.isSuccess() && lr.getObjs() != null) { for (Iterator iterator = lr.getObjs().iterator(); iterator.hasNext();) { com.taobao.api.sns.pojo.user.User user = (com.taobao.api.sns.pojo.user.User) iterator.next(); User tgirlUser = mgr.getUserByTaobaoId(user.getUserid() + ""); if (tgirlUser != null) { result.add(tgirlUser); } } } return result; } catch (Exception e) { e.printStackTrace(System.err); } return null; } }