1 19 20 package com.sslexplorer.policyframework; 21 22 import java.util.Stack ; 23 24 import javax.servlet.http.HttpSession ; 25 26 import com.sslexplorer.security.Constants; 27 28 29 34 public class ResourceStack extends Stack <Resource> { 35 36 42 public static void pushToEditingStack(HttpSession 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 if(!stack.contains(resource)) { 51 stack.push(resource); 52 } 53 } 54 55 61 public static Resource popFromEditingStack(HttpSession 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 79 public static Resource peekEditingStack(HttpSession 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 93 public static boolean isEmpty(HttpSession session) { 94 return session.getAttribute(Constants.EDITING_RESOURCE_STACK) == null; 95 } 96 } 97 | Popular Tags |