KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > ResourceStack


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.policyframework;
21
22 import java.util.Stack JavaDoc;
23
24 import javax.servlet.http.HttpSession JavaDoc;
25
26 import com.sslexplorer.security.Constants;
27
28
29 /**
30  * Holds a stack of edited resources
31  *
32  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
33  */

34 public class ResourceStack extends Stack JavaDoc<Resource> {
35
36     /**
37      * Push a resource to the edit stack
38      *
39      * @param session session
40      * @param resource resource
41      */

42     public static void pushToEditingStack(HttpSession JavaDoc session, Resource resource) {
43         ResourceStack stack = (ResourceStack)session.getAttribute(Constants.EDITING_RESOURCE_STACK);
44         if(stack == null) {
45             stack = new ResourceStack();
46             session.setAttribute(Constants.EDITING_RESOURCE_STACK, stack);
47         }
48         
49         // A refresh on an edit page could cause a resource to be pushed more than once, this check prevents that
50
if(!stack.contains(resource)) {
51             stack.push(resource);
52         }
53     }
54
55     /**
56      * Pop a resource from the edit stack
57      *
58      * @param session session
59      * @return resource
60      */

61     public static Resource popFromEditingStack(HttpSession JavaDoc session) {
62         ResourceStack stack = (ResourceStack)session.getAttribute(Constants.EDITING_RESOURCE_STACK);
63         if(stack != null) {
64             Resource r = stack.pop();
65             if(stack.isEmpty()) {
66                 session.removeAttribute(Constants.EDITING_RESOURCE_STACK);
67             }
68             return r;
69         }
70         return null;
71     }
72
73     /**
74      * Peek at the item at the top of the stack
75      *
76      * @param session session
77      * @return resource
78      */

79     public static Resource peekEditingStack(HttpSession JavaDoc session) {
80         ResourceStack stack = (ResourceStack)session.getAttribute(Constants.EDITING_RESOURCE_STACK);
81         if(stack == null) {
82             return null;
83         }
84         return stack.peek();
85     }
86
87     /**
88      * Get if the stack is empty
89      *
90      * @param session session
91      * @return empty
92      */

93     public static boolean isEmpty(HttpSession JavaDoc session) {
94         return session.getAttribute(Constants.EDITING_RESOURCE_STACK) == null;
95     }
96 }
97
Popular Tags