Java tutorial
/** * PureInfo Quake * @(#)ShowReserchCenterSelectorFunctionHandler.java 1.0 2005-9-25 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.view.function; import java.util.Date; import java.util.Iterator; import java.util.List; import org.apache.commons.lang.ArrayUtils; import com.pureinfo.ark.content.ArkContentHelper; import com.pureinfo.dolphinview.context.model.IDVContext; import com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase; import com.pureinfo.force.ForceConstants; import com.pureinfo.force.exception.PureException; import com.pureinfo.srm.auth.model.SRMUser; import com.pureinfo.srm.product.domain.IProductMgr; import com.pureinfo.srm.product.model.Product; /** * <P> * Created on 2005-9-25 14:51:04 <BR> * Last modified on 2005-9-25 * </P> * dispaly <OPTION>part to select reserch centers * * @author elmar.chen * @version 1.0, 2005-9-25 * @since Quake 1.0 */ public class ShowProductsSelectorFunctionHandler extends FunctionHandlerDVImplBase { /** * @see com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase#perform(java.lang.Object[], * com.pureinfo.dolphinview.context.model.IDVContext) */ public Object perform(Object[] _args, IDVContext _context) throws PureException { SRMUser user = (SRMUser) _context.getObject(); if (user == null) return ""; IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); // List products = mgr.getMyProduct(user.getId()); String sWorks = user.getWorks(); int[] arrIds = MyViewFunctionHelper.split(sWorks); //return MyViewFunctionHelper.makeDolphinObjectSelectorOption(products, // "id", "productName", listProIds); StringBuffer sbuff = new StringBuffer(); try { Product product; int nId; Date publishDate; for (Iterator iter = products.iterator(); iter.hasNext();) { product = (Product) iter.next(); nId = product.getId(); sbuff.append("<OPTION value=\"").append(nId).append('"'); if (arrIds != null && ArrayUtils.indexOf(arrIds, nId) >= 0) { sbuff.append(" SELECTED"); } sbuff.append('>').append(product.getProductName()); sbuff.append(" [").append(product.getPublisher()).append(']'); publishDate = product.getPublishDate(); if (publishDate != null) { sbuff.append(' ').append(ForceConstants.DATE_FORMAT.format(publishDate)); } sbuff.append("</OPTION>"); } return sbuff.toString(); } finally { sbuff.setLength(0); } } }