1 16 package org.apache.cocoon.environment; 17 18 import java.util.Map ; 19 20 import org.apache.cocoon.util.Deprecation; 21 22 38 39 public final class ObjectModelHelper { 40 41 42 public final static String REQUEST_OBJECT = "request"; 43 44 45 public final static String RESPONSE_OBJECT = "response"; 46 47 48 public final static String CONTEXT_OBJECT = "context"; 49 50 51 public final static String EXPIRES_OBJECT = "expires"; 52 53 54 public final static String THROWABLE_OBJECT = "throwable"; 55 56 60 public final static String PARENT_CONTEXT = "parent-context"; 61 62 63 private ObjectModelHelper() { 64 } 66 67 public static final Request getRequest(Map objectModel) { 68 return (Request)objectModel.get(REQUEST_OBJECT); 69 } 70 71 public static final Response getResponse(Map objectModel) { 72 return (Response)objectModel.get(RESPONSE_OBJECT); 73 } 74 75 public static final Context getContext(Map objectModel) { 76 return (Context)objectModel.get(CONTEXT_OBJECT); 77 } 78 79 public static final Long getExpires(Map objectModel) { 80 return (Long )objectModel.get(EXPIRES_OBJECT); 81 } 82 83 public static final Throwable getThrowable(Map objectModel) { 84 return (Throwable )objectModel.get(THROWABLE_OBJECT); 85 } 86 87 91 public static Cookie getCookie(Map objectModel, 92 String cookieName, 93 int cookieIndex) { 94 Deprecation.logger.error("ObjectModelHelper.getCookie() should not be used, and will be removed in the next release"); 95 boolean retrieveByName = false; 96 boolean retrieveByIndex = false; 97 boolean matchFound = false; 98 99 int count = 0; 100 101 Request request = ObjectModelHelper.getRequest(objectModel); 102 Cookie currentCookie = null; 103 104 if (cookieName != null) { 105 retrieveByName = true; 106 } else if (cookieIndex >=0) { 107 retrieveByIndex = true; 108 } 109 110 Cookie[] cookies = request.getCookies(); 111 if (cookies != null && retrieveByName) { 112 for(count = 0; count < cookies.length; count++) { 113 currentCookie = cookies[count]; 114 if (currentCookie.getName().equals(cookieName)) { 115 matchFound = true; 116 break; 117 } 118 } 119 } else if(cookies != null && retrieveByIndex) { 120 if(cookies.length > cookieIndex) { 121 currentCookie = cookies[cookieIndex]; 122 matchFound = true; 123 } 124 } 125 126 if (matchFound) { 127 return currentCookie; 128 } 129 return null; 130 } 131 132 } 133 | Popular Tags |