View Javadoc

1   /*
2    * WebFlow Navigation Manager: webflow definiton, server side navigation history and automatic session cleaning.
3    * Distributed under LGPL license at web site http://wfnm.sourceforge.net .
4    */
5   package net.sf.wfnm.web;
6   
7   import net.sf.wfnm.NavigationManager;
8   import net.sf.wfnm.NavigationManagerFactory;
9   
10  import javax.servlet.http.HttpSession;
11  
12  
13  /***
14   * The factory for dynamic navigation and info.<br>It allows to get the following information:
15   * 
16   * <ul>
17   * <li>
18   * the current page
19   * </li>
20   * <li>
21   * the current webflow name
22   * </li>
23   * <li>
24   * whether a page has been visited or not
25   * </li>
26   * <li>
27   * whether a webflow has been visited or not
28   * </li>
29   * <li>
30   * the previous page
31   * </li>
32   * <li>
33   * the previous webflow (top page)
34   * </li>
35   * <li>
36   * a previous webflow (top page) given its name
37   * </li>
38   * </ul>
39   * 
40   *
41   * @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
42   * @version 1.0.6
43   */
44  public class DynamicFactory {
45      /***
46       * Gets the current page.
47       *
48       * @param session the http session
49       *
50       * @return the url of the current page
51       */
52      public static String getCurrentPage(HttpSession session) {
53          NavigationManager navigationManager = getNavigationManager(session);
54  
55          return navigationManager.getCurrentPage();
56      }
57  
58      /***
59       * Get the current webflow name
60       *
61       * @param session the http session
62       *
63       * @return the current webflow name (null=no webflow opened)
64       */
65      public static String getCurrentWebflowName(HttpSession session) {
66          NavigationManager navigationManager = getNavigationManager(session);
67  
68          return navigationManager.getCurrentWebflow();
69      }
70  
71      /***
72       * Gets the navigation manager.
73       *
74       * @param session the http session
75       *
76       * @return the navigation manager
77       */
78      public static NavigationManager getNavigationManager(HttpSession session) {
79          HttpSessionWrapper sessionWrapper = (HttpSessionWrapper) HttpSessionWrapper.wrapItIfNecessary(session);
80  
81          return NavigationManagerFactory.getInstance(sessionWrapper);
82      }
83  
84      /***
85       * Returns true if the page has been visited.
86       *
87       * @param session the http session
88       * @param url the url of the page
89       *
90       * @return true if the page has been visited
91       */
92      public static boolean isPageVisited(HttpSession session, String url) {
93          NavigationManager navigationManager = getNavigationManager(session);
94  
95          return navigationManager.isPageVisited(url);
96      }
97  
98      /***
99       * Gets the previous page.
100      *
101      * @param session the http session
102      * @param currentIfNotExists indicates to reload the current page if it does not exists
103      *
104      * @return the url of the previous page
105      */
106     public static String getPreviousPage(HttpSession session, boolean currentIfNotExists) {
107         NavigationManager navigationManager = getNavigationManager(session);
108 
109         String page = navigationManager.getPreviousPage();
110 
111         if ((page == null) && currentIfNotExists) {
112             page = getCurrentPage(session);
113         }
114 
115         return page;
116     }
117 
118     /***
119      * Gets the previous page.
120      *
121      * @param session the http session
122      *
123      * @return the url of the previous page
124      */
125     public static String getPreviousPage(HttpSession session) {
126         return getPreviousPage(session, true);
127     }
128 
129     /***
130      * Gets the previous webflow (top page).
131      *
132      * @param session the http session
133      * @param currentIfNotExists indicates to reload the current page if it does not exists
134      *
135      * @return the url of the previous webflow (top page)
136      */
137     public static String getPreviousWebflow(HttpSession session, boolean currentIfNotExists) {
138         NavigationManager navigationManager = getNavigationManager(session);
139 
140         String page = navigationManager.getPreviousWebflow();
141 
142         if ((page == null) && currentIfNotExists) {
143             page = getCurrentPage(session);
144         }
145 
146         return page;
147     }
148 
149     /***
150      * Gets the previous webflow (top page).
151      *
152      * @param session the http session
153      *
154      * @return the url of the previous webflow (top page)
155      */
156     public static String getPreviousWebflow(HttpSession session) {
157         return getPreviousWebflow(session, true);
158     }
159 
160     /***
161      * Gets a previous webflow (top page) given its name.
162      *
163      * @param session the http session
164      * @param webflowName the webflow name
165      * @param currentIfNotExists indicates to reload the current page if it does not exists
166      *
167      * @return the url of the previous webflow (top page) with name 'webflowName'
168      */
169     public static String getPreviousWebflow(HttpSession session, String webflowName, final boolean currentIfNotExists) {
170         NavigationManager navigationManager = getNavigationManager(session);
171 
172         String page = navigationManager.getPreviousWebflow(webflowName);
173 
174         if ((page == null) && currentIfNotExists) {
175             page = getCurrentPage(session);
176         }
177 
178         return page;
179     }
180 
181     /***
182      * Gets a previous webflow (top page) given its name.
183      *
184      * @param session the http session
185      * @param webflowName the webflow name
186      *
187      * @return the url of the previous webflow (top page) with name 'webflowName'
188      */
189     public static String getPreviousWebflow(HttpSession session, String webflowName) {
190         return getPreviousWebflow(session, webflowName, true);
191     }
192 
193     /***
194      * Returns true if the webflow has been visited.
195      *
196      * @param session the http session
197      * @param webflowName the webflow name
198      *
199      * @return true if the webflow has been visited
200      */
201     public static boolean isWebflowVisited(HttpSession session, String webflowName) {
202         NavigationManager navigationManager = getNavigationManager(session);
203 
204         return navigationManager.isWebflowVisited(webflowName);
205     }
206 }