You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/05/20 19:54:01 UTC

svn commit: r171141 - in /incubator/beehive/trunk/samples/petstoreWeb/web: WEB-INF/tags/beehive/petstore/copyright.tag webappRoot/SharedFlow.java

Author: ekoneil
Date: Fri May 20 10:54:00 2005
New Revision: 171141

URL: http://svn.apache.org/viewcvs?rev=171141&view=rev
Log:
Fixes for JIRA 734.  This puts the category list in the ServletContext.

Also includes a font fix for the copyright JSP tag file to make the copyright and Beehive fonts the same size.

BB: self
DRT: petstoreWeb pass


Modified:
    incubator/beehive/trunk/samples/petstoreWeb/web/WEB-INF/tags/beehive/petstore/copyright.tag
    incubator/beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java

Modified: incubator/beehive/trunk/samples/petstoreWeb/web/WEB-INF/tags/beehive/petstore/copyright.tag
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/web/WEB-INF/tags/beehive/petstore/copyright.tag?rev=171141&r1=171140&r2=171141&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/web/WEB-INF/tags/beehive/petstore/copyright.tag (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/web/WEB-INF/tags/beehive/petstore/copyright.tag Fri May 20 10:54:00 2005
@@ -25,9 +25,7 @@
     </tr>
     <tr>
         <td align="left">
-        Licensed under the
-        <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License,
-        Version 2.0</a>.
+            Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
         </td>
         <td align="right">
         <table>
@@ -38,7 +36,10 @@
                 </netui:anchor>
                 </td>
                 <td valign="center">
-                <netui:span style="font-size:12;font-color:#00cccc;" value="Powered by Apache Beehive"/>
+                    <netui:span value="Powered by"/>
+                    <netui:anchor style="font-color:#00cccc;"
+                                  href="http://incubator.apache.org/beehive"
+                                  value="Apache Beehive"/>
                 </td>
             </tr>
         </table>

Modified: incubator/beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java?rev=171141&r1=171140&r2=171141&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java (original)
+++ incubator/beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java Fri May 20 10:54:00 2005
@@ -17,6 +17,8 @@
  */
 package webappRoot;
 
+import javax.servlet.ServletContext;
+
 import org.apache.beehive.controls.api.bean.Control;
 import org.apache.beehive.netui.pageflow.annotations.Jpf;
 import org.apache.beehive.netui.pageflow.PageFlowException;
@@ -59,7 +61,7 @@
 public class SharedFlow
     extends SharedFlowController {
 
-    private static String[] CATEGORY_NAMES = null;
+    private static final String ATTR_CATEGORY_NAMES = SharedFlow.class + "CATEGORY_NAMES";
 
     @Control()
     private CatalogControl _catalogControl;
@@ -71,17 +73,6 @@
     private Cart _cart = null;
     private Product[] _myList;
 
-    protected void onCreate() {
-
-		// todo: move to ServletContext so it's cached for all users
-        Category[] categories = _catalogControl.getCategoryList();
-        CATEGORY_NAMES = new String[categories.length];
-        for(int i = 0; i < CATEGORY_NAMES.length; i++)
-        {
-            CATEGORY_NAMES[i] = categories[i].getCatId();
-        }
-    }
-
     /**
      * Utility used to ensure that the user is logged into the site; an exception is
      * thrown when the the user is not logged in.
@@ -92,7 +83,9 @@
             throw new NotLoggedInException("User not logged in", this);
     }
 
-    public void handleLogin(String username) throws NoSuchAccountException, InvalidIdentifierException {
+    public void handleLogin(String username)
+        throws NoSuchAccountException, InvalidIdentifierException {
+
         Account account = _accountControl.getAccount(username);
 
         // Throw an exception if the user is not found
@@ -122,20 +115,22 @@
 
     public void updateAccount(Account account)
         throws InvalidIdentifierException, NoSuchAccountException {
-        // update account info in globalApp
+
+        assert account != null : "Received a null account!";
+        // update the user's account info
         _account = account;
 
-        // set the user's favorites list if they are logged in
+        // set the user's favorites once they're logged in
         if (account.isMyListOpt())
             setMyList(_catalogControl.getProductListByCategory(account.getFavCategory()));
     }
     
     public String[] getCategoryNames() {
-        return CATEGORY_NAMES;
+        return lookupCategoryNames();
     }
 
     /**
-     * Determine if the user is logged into the website.
+     * Determine if the current user has logged in.
      */
     public boolean isUserLoggedIn() {
         return _account == null ? false : true;
@@ -156,25 +151,6 @@
         return _account;
     }
 
-    private void setAccount(Account account) {
-        _account = account;
-    }
-
-    private void setCart(Cart cart) {
-        _cart = cart;
-    }
-
-    private void setMyList(Product[] myList) {
-        _myList = myList;
-    }
-
-    @Jpf.Action(
-        forwards={@Jpf.Forward(name="help", path="/help.jsp")}
-    )
-    public Forward showHelp() {
-        return new Forward("help");
-    }
-
     /**
      * This action is used to drop into the nested login controller
      * from a user click on a page
@@ -207,13 +183,7 @@
     }
 
     @Jpf.Action(
-        forwards={
-            @Jpf.Forward(
-                redirect=true,
-                name="shop",
-                path="/shop/Controller.jpf"
-            )
-        }
+        forwards={@Jpf.Forward(redirect=true, name="shop", path="/shop/Controller.jpf")}
     )
     public Forward globalShop() {
         return new Forward("shop");
@@ -272,5 +242,40 @@
         throws java.io.IOException {
         ex.sendError(getRequest(), getResponse());
         return null;
+    }
+
+    private void setAccount(Account account) {
+        _account = account;
+    }
+
+    private void setCart(Cart cart) {
+        _cart = cart;
+    }
+
+    private void setMyList(Product[] myList) {
+        _myList = myList;
+    }
+
+    private String[] lookupCategoryNames() {
+        ServletContext servletContext = getServletContext();
+        Object obj = servletContext.getAttribute(ATTR_CATEGORY_NAMES);
+        String[] categoryNames = null;
+        if(obj == null) {
+            assert _catalogControl != null : "Found a null CategoryControl";
+            Category[] categories = _catalogControl.getCategoryList();
+            categoryNames = new String[categories.length];
+            for(int i = 0; i < categories.length; i++)
+                categoryNames[i] = categories[i].getCatId();
+
+            servletContext.setAttribute(ATTR_CATEGORY_NAMES, categoryNames);
+        }
+        else {
+            assert categoryNames instanceof String[] :
+                "Found ServletContext \"" + ATTR_CATEGORY_NAMES + "\" that is not a String[]";
+            categoryNames = (String[])obj;
+        }
+
+        assert categoryNames != null : "Found null category names";
+        return categoryNames;
     }
 }