KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > location > LocationModule


1 /*
2  * Created on Aug 4, 2004
3  */

4 package com.openedit.modules.location;
5
6 import com.openedit.WebPageRequest;
7 import com.openedit.page.Page;
8 import com.openedit.util.PathUtilities;
9 import com.openedit.web.Crumb;
10
11 /**
12  * @author cburkey
13  *
14  */

15 public class LocationModule
16 {
17     public void loadPaths( WebPageRequest inContext) throws Exception JavaDoc
18     {
19
20         Page page = inContext.getPage();
21         String JavaDoc path = PathUtilities.extractDirectoryPath(page.getPath());
22         // urlpath is the address the link came in on
23

24         //Now we need two more CSS variables. One for the directory we are in and another for the exact page we are on
25
String JavaDoc csspath = path.replace('/','-');
26         if( csspath.startsWith("-"))
27         {
28             csspath = csspath.substring(1);
29         }
30         if( csspath.endsWith("-"))
31         {
32             csspath = csspath.substring(0,csspath.length() -1);
33         }
34         
35         inContext.putPageValue("cssdirectory",csspath);
36         
37         String JavaDoc name = PathUtilities.extractPageName( page.getPath() );
38         String JavaDoc csspage = csspath + "-" + name;
39         inContext.putPageValue("cssaddress",csspage);
40
41         
42     }
43     
44     
45     /**
46      * Load a crumb object. You can add crumbs by adding a property to a page like this
47      * <property name="crumb">Sales</property>
48      * To append to a crumb you can use the ?addcrumb=New Page on your links or add the "addcrumb" page property
49      * Be aware we only support two levels deep
50      * @param inContext
51      * @throws Exception
52      */

53     public void checkCrumb(WebPageRequest inContext) throws Exception JavaDoc
54     {
55         
56         //First check the crumb status then load the location ID for one item
57
//Look in param to see if we need to reset cart session
58
Page content = (Page)inContext.getPageValue("content");
59
60         String JavaDoc crumb = inContext.getRequestParameter("crumb");
61         if (crumb == null)
62         {
63             crumb = content.get("crumb");
64         }
65         //Did someone set a crumb in on the page?
66
Crumb oldCrumb = (Crumb)inContext.getSessionValue("crumb");
67         //TODO: Support XML or some way to manage longer than 2 item crumbs
68
if (crumb != null)
69         {
70             Crumb newCrumb = new Crumb();
71             newCrumb.setPath(inContext.getPathUrl());
72             newCrumb.setText(crumb);
73
74             Crumb home = new Crumb();
75             home.setPath("/index.html");
76             home.setText("Home");
77             newCrumb.setParent(home);
78             //set the cart again and reload the local page value
79
oldCrumb = newCrumb;
80         }
81         inContext.putSessionValue("crumb",oldCrumb);
82
83         String JavaDoc addcrumb = inContext.getRequestParameter("addcrumb");
84         if ( addcrumb == null )
85         {
86             addcrumb = content.get("addcrumb");
87         }
88         if (addcrumb != null)
89         {
90             //append to existing crumb
91
Crumb newCrumb = new Crumb();
92             newCrumb.setPath(inContext.getPathUrl()); //get the original URI
93
newCrumb.setText(addcrumb);
94             if (oldCrumb != null)
95             {
96                 if (oldCrumb.isFinal())
97                 {
98                     oldCrumb = oldCrumb.getParent();
99                 }
100                 newCrumb.setParent(oldCrumb); //handles duplicates
101
newCrumb.setFinal(true);
102             }
103             inContext.putSessionValue("crumb",newCrumb);
104         }
105     }
106     
107     
108     
109 }
Popular Tags