svnno****@sourc*****
svnno****@sourc*****
2007年 11月 12日 (月) 17:02:33 JST
Revision: 703 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=703 Author: shinsuke Date: 2007-11-12 17:02:32 +0900 (Mon, 12 Nov 2007) Log Message: ----------- added portlet for displaying top products. Modified Paths: -------------- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/portlet.xml Added Paths: ----------- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListAction.java pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListPage.java pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/topProductList.html -------------- next part -------------- Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java =================================================================== --- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java 2007-11-12 03:36:42 UTC (rev 702) +++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java 2007-11-12 08:02:32 UTC (rev 703) @@ -10,7 +10,6 @@ import jp.sf.pal.common.CommonException; import jp.sf.pal.pompei.PompeiConstants; -import org.apache.commons.lang.StringUtils; import org.apache.jetspeed.administration.PortalAdministration; import org.apache.jetspeed.page.PageManager; import org.apache.jetspeed.security.UserManager; @@ -126,4 +125,24 @@ .getRequestMap().get(PompeiConstants.PAGE_MANAGER_COMPONENT); } + public static String getTypeOfTopProducts() { + String typeOfTopProducts = getPortletConfig().getInitParameter( + PompeiConstants.TYPE_OF_TOP_PRODUCTS); + if (typeOfTopProducts == null) { + return PompeiConstants.DEFAULT_TYPE_OF_TOP_PRODUCTS; + } + return typeOfTopProducts; + } + + public static int getNumOfTopProducts() { + String count = getPortletConfig().getInitParameter( + PompeiConstants.TYPE_OF_TOP_PRODUCTS); + if (count != null) { + try { + return Integer.parseInt(count); + } catch (NumberFormatException e) { + } + } + return PompeiConstants.DEFAULT_NUM_OF_TOP_PRODUCTS; + } } Added: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListAction.java =================================================================== --- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListAction.java 2007-11-12 03:36:42 UTC (rev 702) +++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListAction.java 2007-11-12 08:02:32 UTC (rev 703) @@ -0,0 +1,129 @@ +package jp.sf.pal.pompei.web.user.product; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import jp.sf.pal.common.util.FacesMessageUtil; +import jp.sf.pal.pompei.PompeiConstants; +import jp.sf.pal.pompei.allcommon.cbean.PagingResultBean; +import jp.sf.pal.pompei.dxo.ProductDxo; +import jp.sf.pal.pompei.exentity.Product; +import jp.sf.pal.pompei.exentity.ProductImage; +import jp.sf.pal.pompei.service.ProductService; +import jp.sf.pal.pompei.util.SystemUtil; +import jp.sf.pal.pompei.util.UploadedFileUtil; + +public class TopProductListAction implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3171043762530754438L; + + /** + * + */ + private TopProductListPage topProductListPage; + + /** */ + private ProductService productService; + + /** */ + private ProductDxo productDxo; + + public Class<?> initialize() { + return null; + } + + public Class<?> prerender() { + + // TODO cache + String type = SystemUtil.getTypeOfTopProducts(); + int num = SystemUtil.getNumOfTopProducts(); + + //商品一覧の取得 + PagingResultBean<Product> productList = getProductService() + .getTopProductList(type, num); + List<Map<String, Object>> sList = new ArrayList<Map<String, Object>>(); + getProductDxo().convert(productList, sList); + getTopProductListPage().setProductItems(sList); + + // load thumbnail + loadThumbnail(sList); + + // render faces messages + FacesMessageUtil.renderMessages(); + return null; + } + + private void loadThumbnail(List<Map<String, Object>> productList) { + for (Map<String, Object> map : productList) { + BigDecimal productId = (BigDecimal) map.get("productId"); + if (productId != null) { + // TODO improvement + ProductImage productImage = getProductService() + .getProductImageByProductIdAndType(productId, + PompeiConstants.THUMBNAIL_IMAGE_TYPE); + if (productImage != null) { + map.put(PompeiConstants.THUMBNAIL_IMAGE_URL, + UploadedFileUtil.getProductImageUrl(productImage + .getImageName())); + } else { + // set default image path + map + .put( + PompeiConstants.THUMBNAIL_IMAGE_URL, + UploadedFileUtil + .getProductImageUrl(PompeiConstants.DEFAULT_THUMBNAIL_IMAGE_NAME)); + } + + } + } + } + + /** + * @return the topProductListPage + */ + public TopProductListPage getTopProductListPage() { + return topProductListPage; + } + + /** + * @param topProductListPage the topProductListPage to set + */ + public void setTopProductListPage(TopProductListPage topProductListPage) { + this.topProductListPage = topProductListPage; + } + + /** + * @return the productService + */ + public ProductService getProductService() { + return productService; + } + + /** + * @param productService the productService to set + */ + public void setProductService(ProductService productService) { + this.productService = productService; + } + + /** + * @return the productDxo + */ + public ProductDxo getProductDxo() { + return productDxo; + } + + /** + * @param productDxo the productDxo to set + */ + public void setProductDxo(ProductDxo productDxo) { + this.productDxo = productDxo; + } + +} Property changes on: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListAction.java ___________________________________________________________________ Name: svn:eol-style + native Added: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListPage.java =================================================================== --- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListPage.java 2007-11-12 03:36:42 UTC (rev 702) +++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListPage.java 2007-11-12 08:02:32 UTC (rev 703) @@ -0,0 +1,144 @@ +package jp.sf.pal.pompei.web.user.product; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +import jp.sf.pal.pompei.PompeiConstants; +import jp.sf.pal.pompei.exentity.ProductDescription; +import jp.sf.pal.pompei.service.LanguageService; +import jp.sf.pal.pompei.util.UrlBuilderUtil; + +import org.seasar.teeda.extension.annotation.convert.BigDecimalConverter; + +public class TopProductListPage implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -8096518146757092176L; + + private int productIndex; + + private List<Map<String, Object>> productItems; + + private BigDecimal productId; + + //TODO i18n + @BigDecimalConverter(pattern = "###,###") + private BigDecimal price; + + private LanguageService languageService; + + public int getProductIndex() { + return productIndex; + } + + public void setProductIndex(int productIndex) { + this.productIndex = productIndex; + } + + public List<Map<String, Object>> getProductItems() { + return productItems; + } + + public void setProductItems(List<Map<String, Object>> productItems) { + this.productItems = productItems; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal productsPrice) { + this.price = productsPrice; + } + + public BigDecimal getProductId() { + return productId; + } + + public void setProductId(BigDecimal productsId) { + this.productId = productsId; + } + + public String getCartLinkHref() { + return UrlBuilderUtil.createCartUrl(); + } + + /** + * @return languageService + */ + public LanguageService getLanguageService() { + return languageService; + } + + /** + * @param languageService 設定する languageService + */ + public void setLanguageService(LanguageService languageService) { + this.languageService = languageService; + } + + public String getProductName() { + //TODO + if (getProductItems() != null + && getProductIndex() < getProductItems().size()) { + List<ProductDescription> list = (List<ProductDescription>) productItems + .get(productIndex).get( + PompeiConstants.PRODUCT_DESCRIPTION_LIST); + for (ProductDescription pd : list) { + BigDecimal languagesId = getLanguageService() + .getCurrentLanguage().getLanguageId(); + if (pd.getLanguageId().equals(languagesId)) { + return pd.getName(); + } + } + // TODO need default lang? + } + return "-"; + } + + public String getProductTitle() { + //TODO + if (getProductItems() != null + && getProductIndex() < getProductItems().size()) { + List<ProductDescription> list = (List<ProductDescription>) productItems + .get(productIndex).get( + PompeiConstants.PRODUCT_DESCRIPTION_LIST); + for (ProductDescription pd : list) { + BigDecimal languagesId = getLanguageService() + .getCurrentLanguage().getLanguageId(); + if (pd.getLanguageId().equals(languagesId)) { + // TODO cut a long message? + return pd.getTitle(); + } + } + // TODO need default lang? + } + return "-"; + } + + public String getThumbnailImgSrc() { + if (getProductItems() != null + && getProductIndex() < getProductItems().size()) { + return (String) getProductItems().get(getProductIndex()).get( + PompeiConstants.THUMBNAIL_IMAGE_URL); + } + return ""; + } + + protected String getProductLinkHref() { + return UrlBuilderUtil.createProductListUrl() + "?productId=" + + getProductId(); + } + + public String getProductImageLinkHref() { + return getProductLinkHref(); + } + + public String getProductNameLinkHref() { + return getProductLinkHref(); + } +} Property changes on: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/TopProductListPage.java ___________________________________________________________________ Name: svn:eol-style + native Modified: pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml =================================================================== --- pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml 2007-11-12 03:36:42 UTC (rev 702) +++ pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/jetspeed-portlet.xml 2007-11-12 08:02:32 UTC (rev 703) @@ -40,6 +40,10 @@ <portlet-name>OrderProducts</portlet-name> <js:security-constraint-ref>public-view</js:security-constraint-ref> </portlet> + <portlet> + <portlet-name>TopProductList</portlet-name> + <js:security-constraint-ref>public-view</js:security-constraint-ref> + </portlet> <js:services> <js:service name="SecurityProvider"/> <js:service name="UserManager"/> Modified: pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/portlet.xml =================================================================== --- pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/portlet.xml 2007-11-12 03:36:42 UTC (rev 702) +++ pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/portlet.xml 2007-11-12 08:02:32 UTC (rev 703) @@ -481,4 +481,37 @@ <keywords>Signup</keywords> </portlet-info> </portlet> + <portlet> + <description>Lists top products</description> + <description xml:lang="ja">トップ商品を一覧します</description> + <portlet-name>TopProductList</portlet-name> + <display-name>Pompei: Top Product List</display-name> + <display-name xml:lang="ja">Pompei: トップ商品一覧</display-name> + <portlet-class>org.apache.portals.bridges.portletfilter.FilterPortlet</portlet-class> + <init-param> + <name>portlet-class</name> + <value>org.seasar.teeda.core.portlet.FacesPortlet</value> + </init-param> + <init-param> + <name>portlet-filters</name> + <value>jp.sf.pal.facesresponse.FacesResponseFilter,jp.sf.pal.pooptimizer.OptimizerFilter,org.seasar.portlet.filter.S2PortletFilter,org.seasar.portlet.filter.HotdeployPortletFilter</value> + </init-param> + <init-param> + <name>view-page</name> + <value>/view/user/product/topProductList.html</value> + </init-param> + <expiration-cache>0</expiration-cache> + <supports> + <mime-type>text/html</mime-type> + <portlet-mode>VIEW</portlet-mode> + </supports> + <supported-locale>en</supported-locale> + <supported-locale>ja</supported-locale> + <resource-bundle>jp.sf.pal.pompei.web.user.product.ProductList</resource-bundle> + <portlet-info> + <title>Product List</title> + <short-title>Products</short-title> + <keywords>Product,List</keywords> + </portlet-info> + </portlet> </portlet-app> Added: pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/topProductList.html =================================================================== --- pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/topProductList.html 2007-11-12 03:36:42 UTC (rev 702) +++ pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/topProductList.html 2007-11-12 08:02:32 UTC (rev 703) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:pal="http://pal.sourceforge.jp/jsf4portlet" +xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:te="http://www.seasar.org/teeda/extension"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<title>商品一覧画面</title> +</head> +<body> +<form id="topProductListForm"> +<div style="width:100%;text-align:center;clear: both;"> + <div id="productItems" style="width:100%;"> + <div style="float:left;width:150px"> + <a id="productImageLink" href="productDetails.html?productId=1"><img id="thumbnailImg" src="" alt="画像" border="0"/></a> + <br/> + <a id="productNameLink" href="productDetails.html?productId=1"> + <span id="productName-thumbnail">AAAAAAA</span> + </a><br/> + <b style="color: #990000;"><span id="price-thumbnail">価格</span>円</b> + </div> + </div> +</div> +</form> +</body></html> Property changes on: pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/product/topProductList.html ___________________________________________________________________ Name: svn:eol-style + native