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.demo.customerInfo;
018:
019: import java.io.IOException;
020: import java.util.ArrayList;
021: import java.util.GregorianCalendar;
022: import java.util.List;
023:
024: import javax.portlet.ActionRequest;
025: import javax.portlet.ActionResponse;
026: import javax.portlet.PortletException;
027: import javax.portlet.PortletSession;
028: import javax.portlet.RenderRequest;
029: import javax.portlet.RenderResponse;
030:
031: /**
032: * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
033: * @version $Id: CustomerPortlet.java 516448 2007-03-09 16:25:47Z ate $
034: */
035: public class CustomerPortlet extends
036: org.apache.portals.bridges.common.GenericServletPortlet {
037:
038: private List defaultCustomers = new ArrayList();
039:
040: /** Creates a new instance of CustomerPortlet */
041: public CustomerPortlet() {
042: }
043:
044: public void init() throws javax.portlet.PortletException {
045: CustomerInfo newCustomer = null;
046: Address newAddress = null;
047:
048: // Initialize the defaultCustomer
049: newCustomer = new CustomerInfo();
050: newCustomer.setName("Jane Doe");
051:
052: newCustomer.setLastOrdered(new GregorianCalendar(2002, 05, 15));
053: newAddress = new Address();
054: newAddress.setName(newCustomer.getName());
055: newAddress.setStreet("124 Main Street");
056: newAddress.setCity("AnyTown");
057: newAddress.setState("ME");
058: newAddress.setCountry("U.S.A.");
059: newCustomer.setBillingAddress(newAddress);
060: newAddress.setName(newCustomer.getName());
061: newAddress.setStreet("1862 Elm Drive");
062: newAddress.setCity("AnyTown");
063: newAddress.setState("ME");
064: newAddress.setCountry("U.S.A.");
065: newCustomer.setShippingAddress(newAddress);
066: this .defaultCustomers.add(newCustomer);
067:
068: newCustomer = new CustomerInfo();
069: newCustomer.setName("Fred Smith");
070: newCustomer.setLastOrdered(new GregorianCalendar(2002, 9, 15));
071: newAddress = new Address();
072: newAddress.setName(newCustomer.getName());
073: newAddress.setStreet("1 Bearch Way");
074: newAddress.setCity("AnyTown");
075: newAddress.setState("ME");
076: newAddress.setCountry("U.S.A.");
077: newCustomer.setBillingAddress(newAddress);
078: newAddress.setName(newCustomer.getName());
079: newAddress.setStreet("1862 Elm Drive");
080: newAddress.setCity("AnyTown");
081: newAddress.setState("ME");
082: newAddress.setCountry("U.S.A.");
083: newCustomer.setShippingAddress(newAddress);
084: this .defaultCustomers.add(newCustomer);
085:
086: newCustomer = new CustomerInfo();
087: newCustomer.setName("Wallace George");
088: newCustomer.setLastOrdered(new GregorianCalendar(2003, 1, 1));
089: newAddress = new Address();
090: newAddress.setName(newCustomer.getName());
091: newAddress.setStreet("73 Wamack Drive");
092: newAddress.setCity("AnyTown");
093: newAddress.setState("ME");
094: newAddress.setCountry("U.S.A.");
095: newCustomer.setBillingAddress(newAddress);
096: newAddress.setName(newCustomer.getName());
097: newAddress.setStreet("73 Wamack Drive");
098: newAddress.setCity("AnyTown");
099: newAddress.setState("ME");
100: newAddress.setCountry("U.S.A.");
101: newCustomer.setShippingAddress(newAddress);
102: this .defaultCustomers.add(newCustomer);
103: }
104:
105: /**
106: * Execute the servlet as define by the init parameter or preference PARAM_ACTION_PAGE. The value
107: * if the parameter is a relative URL, i.e. /actionPage.jsp will execute the
108: * JSP editPage.jsp in the portlet application's web app. The action should
109: * not generate any content. The content will be generate by doCustom(),
110: * doHelp() , doEdit(), or doView().
111: *
112: * See section PLT.16.2 of the JSR 168 Portlet Spec for more information
113: * around executing a servlet or JSP in processAction()
114: *
115: * @see javax.portlet.GenericPortlet#processAction
116: *
117: * @task Need to be able to execute a servlet for the action
118: * @task Need to set current customer and customer detail item
119: * in the session.
120: *
121: */
122: public void processAction(ActionRequest request,
123: ActionResponse actionResponse) throws PortletException,
124: IOException {
125:
126: }
127:
128: /**
129: * Execute the servlet as define by the init parameter or preference PARAM_VIEW_PAGE.
130: * The value if the parameter is a relative URL, i.e. /viewPage.jsp will execute the
131: * JSP viewPage.jsp in the portlet application's web app.
132: *
133: * @see javax.portlet.GenericPortlet#doView
134: *
135: */
136: public void doView(RenderRequest request, RenderResponse response)
137: throws PortletException, IOException {
138: List customerList = null;
139: // Get the current customer list from the session
140: PortletSession portletSession = request.getPortletSession();
141: if (portletSession != null) {
142: customerList = (List) portletSession.getAttribute(
143: "CustomerList", PortletSession.APPLICATION_SCOPE);
144: if (customerList == null) {
145: customerList = this .defaultCustomers;
146: portletSession.setAttribute("CustomerList",
147: this .defaultCustomers,
148: PortletSession.APPLICATION_SCOPE);
149: }
150: }
151:
152: else {
153: // TODO: the portletSession == null?
154: System.out
155: .println("In org.apache.demo.customerInfo.CustomerPortlet.doView() - The portletSession == null !!!!");
156: }
157:
158: // If no customer list exists, use the default.
159: if (customerList == null) {
160: customerList = this .defaultCustomers;
161: }
162:
163: // Place the customer list in the request context.
164: request.setAttribute("CustomerList", customerList);
165: super.doView(request, response);
166: }
167:
168: }
|