From portal-commits at lists.jboss.org Sun Mar 2 17:24:18 2008 Content-Type: multipart/mixed; boundary="===============7312332122531308027==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r10174 - modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/shoppingcart. Date: Sun, 02 Mar 2008 17:24:18 -0500 Message-ID: --===============7312332122531308027== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien(a)jboss.com Date: 2008-03-02 17:24:18 -0500 (Sun, 02 Mar 2008) New Revision: 10174 Added: modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sam= ples/shoppingcart/CartEvent.java modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sam= ples/shoppingcart/CartPortlet.java modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sam= ples/shoppingcart/Catalog.java modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sam= ples/shoppingcart/CatalogItem.java modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sam= ples/shoppingcart/CatalogPortlet.java Log: adding shopping cart portelts Added: modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet= /samples/shoppingcart/CartEvent.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CartEvent.java (rev 0) +++ modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CartEvent.java 2008-03-02 22:24:18 UTC (rev 10174) @@ -0,0 +1,50 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2008, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software is distributed in the hope that it will be useful, = * + * but WITHOUT ANY WARRANTY; without even the implied warranty of = * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ + +package org.jboss.portal.portlet.samples.shoppingcart; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.namespace.QName; +import java.io.Serializable; + +/** + * @author Chris Laprun + * @version $Revision: 9912 $ + */ +(a)XmlRootElement +public class CartEvent implements Serializable +{ + private String id; + + public static final QName QNAME =3D new QName("urn:jboss:portal:samples= :event", "CartEvent"); + + public CartEvent(String id) + { + this.id =3D id; + } + + public String getId() + { + return id; + } +} Added: modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet= /samples/shoppingcart/CartPortlet.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CartPortlet.java (rev 0) +++ modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CartPortlet.java 2008-03-02 22:24:18 UTC (rev 10174) @@ -0,0 +1,83 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2008, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software is distributed in the hope that it will be useful, = * + * but WITHOUT ANY WARRANTY; without even the implied warranty of = * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ + +package org.jboss.portal.portlet.samples.shoppingcart; + +import javax.portlet.Event; +import javax.portlet.EventRequest; +import javax.portlet.EventResponse; +import javax.portlet.GenericPortlet; +import javax.portlet.PortletException; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Chris Laprun + * @version $Revision: 9932 $ + */ +public class CartPortlet extends GenericPortlet +{ + List items =3D new ArrayList(7); + + @Override + protected void doView(RenderRequest renderRequest, RenderResponse rende= rResponse) throws PortletException, IOException + { + renderResponse.setContentType("text/html"); + Writer writer =3D renderResponse.getWriter(); + + + if (!items.isEmpty()) + { + writer.append(""); + int total =3D 0; + for (CatalogItem item : items) + { + int price =3D item.getPrice(); + total +=3D price; + writer.append(""); + } + writer.append("
DescriptionPric= e
").append(item.getDescription()).append= ("$").append("" + price) + .append("
Total:") + .append("$" + total).append("
"); + } + else + { + writer.append("Cart is empty."); + } + } + + @Override + public void processEvent(EventRequest eventRequest, EventResponse event= Response) throws PortletException, IOException + { + Event event =3D eventRequest.getEvent(); + if (event.getName().equals("CartEvent")) + { + CartEvent cartEvent =3D (CartEvent)event.getValue(); + items.add(Catalog.get(cartEvent.getId())); + } + } +} Added: modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet= /samples/shoppingcart/Catalog.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/Catalog.java (rev 0) +++ modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/Catalog.java 2008-03-02 22:24:18 UTC (rev 10174) @@ -0,0 +1,63 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2008, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software is distributed in the hope that it will be useful, = * + * but WITHOUT ANY WARRANTY; without even the implied warranty of = * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ + +package org.jboss.portal.portlet.samples.shoppingcart; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Chris Laprun + * @version $Revision: 9912 $ + */ +public class Catalog +{ + private static Map items; + + static + { + items =3D new HashMap(7); + items.put("1", new CatalogItem("1", 800, "Bike")); + items.put("2", new CatalogItem("2", 450, "Snowboard")); + items.put("3", new CatalogItem("3", 225, "Tent")); + items.put("4", new CatalogItem("4", 75, "Backpack")); + items.put("5", new CatalogItem("5", 119, "Skateboard")); + items.put("6", new CatalogItem("6", 333, "Surfboard")); + items.put("7", new CatalogItem("7", 90, "Sneakers")); + } + + private Catalog() + { + } + + public static CatalogItem get(String id) + { + return items.get(id); + } + + public static Collection getAll() + { + return items.values(); + } +} Added: modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet= /samples/shoppingcart/CatalogItem.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CatalogItem.java (rev 0) +++ modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CatalogItem.java 2008-03-02 22:24:18 UTC (rev 10174) @@ -0,0 +1,57 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2008, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software is distributed in the hope that it will be useful, = * + * but WITHOUT ANY WARRANTY; without even the implied warranty of = * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ + +package org.jboss.portal.portlet.samples.shoppingcart; + +/** + * @author Chris Laprun + * @version $Revision: 9912 $ + */ +public class CatalogItem +{ + private String id; + private int price; + private String description; + + public CatalogItem(String id, int price, String description) + { + this.id =3D id; + this.price =3D price; + this.description =3D description; + } + + public String getId() + { + return id; + } + + public int getPrice() + { + return price; + } + + public String getDescription() + { + return description; + } +} Added: modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet= /samples/shoppingcart/CatalogPortlet.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CatalogPortlet.java (rev 0) +++ modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/sa= mples/shoppingcart/CatalogPortlet.java 2008-03-02 22:24:18 UTC (rev 10174) @@ -0,0 +1,71 @@ +/*************************************************************************= ***** + * JBoss, a division of Red Hat = * + * Copyright 2008, Red Hat Middleware, LLC, and individual = * + * contributors as indicated by the @authors tag. See the = * + * copyright.txt in the distribution for a full listing of = * + * individual contributors. = * + * = * + * This is free software; you can redistribute it and/or modify it = * + * under the terms of the GNU Lesser General Public License as = * + * published by the Free Software Foundation; either version 2.1 of = * + * the License, or (at your option) any later version. = * + * = * + * This software is distributed in the hope that it will be useful, = * + * but WITHOUT ANY WARRANTY; without even the implied warranty of = * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU = * + * Lesser General Public License for more details. = * + * = * + * You should have received a copy of the GNU Lesser General Public = * + * License along with this software; if not, write to the Free = * + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA = * + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. = * + *************************************************************************= *****/ + +package org.jboss.portal.portlet.samples.shoppingcart; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.GenericPortlet; +import javax.portlet.PortletException; +import javax.portlet.PortletURL; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; + +/** + * @author Chris Laprun + * @version $Revision: 9932 $ + */ +public class CatalogPortlet extends GenericPortlet +{ + @Override + protected void doView(RenderRequest renderRequest, RenderResponse rende= rResponse) throws PortletException, IOException + { + renderResponse.setContentType("text/html"); + Writer writer =3D renderResponse.getWriter(); + + writer.append(""); + + PortletURL addURL =3D renderResponse.createActionURL(); + addURL.setParameter("op", "add"); + + Collection items =3D Catalog.getAll(); + for (CatalogItem item : items) + { + addURL.setParameter("id", item.getId()); + writer.append(""); + } + + writer.append("
DescriptionPriceActions
").append(item.getDescription()).append("<= /td>$").append("" + item.getPrice()) + .append("Add to cart
"); + } + + @Override + public void processAction(ActionRequest actionRequest, ActionResponse a= ctionResponse) throws PortletException, IOException + { + String value =3D actionRequest.getParameter("id"); + actionResponse.setEvent(CartEvent.QNAME, new CartEvent(value)); + } +} --===============7312332122531308027==--