This class is a helper class used by Cookie logicsheet
This class contains following methods:
| Method from org.apache.cocoon.components.language.markup.xsp.XSPCookieHelper Detail: |
public static void addCookie(Map objectModel,
String name,
String value,
String comment,
String domain,
int maxage,
String path,
String secure,
int version) {
Response response = ObjectModelHelper.getResponse(objectModel);
Cookie cookieToSet = response.createCookie(name,value);
if ((comment.trim()).length() > 0)
cookieToSet.setComment(comment);
if ((domain.trim()).length() > 0)
cookieToSet.setDomain(domain);
if (maxage > 0)
cookieToSet.setMaxAge(maxage);
if ((path.trim()).length() > 0)
cookieToSet.setPath("/");
cookieToSet.setSecure(BooleanUtils.toBoolean(secure));
cookieToSet.setVersion(version);
response.addCookie(cookieToSet);
}
This method will set a new cookie with values that are passed through parameters |
public static String getComment(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "C");
}
Method to return the value of comment for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static Cookie getCookie(Map objectModel,
String cookieName,
int cookieIndex) {
boolean retrieveByName = false;
boolean retrieveByIndex = false;
boolean matchFound = false;
int count = 0;
Request request = ObjectModelHelper.getRequest(objectModel);
Cookie currentCookie = null;
if (cookieName != null) {
retrieveByName = true;
} else if (cookieIndex >=0) {
retrieveByIndex = true;
}
Cookie[] cookies = request.getCookies();
if (cookies != null && retrieveByName) {
for(count = 0; count < cookies.length; count++) {
currentCookie = cookies[count];
if (currentCookie.getName().equals(cookieName)) {
matchFound = true;
break;
}
}
} else if(cookies != null && retrieveByIndex) {
if(cookies.length > cookieIndex) {
currentCookie = cookies[cookieIndex];
matchFound = true;
}
}
if (matchFound)
return currentCookie;
else
return null;
}
Method used to return a cookie object based on the name or the index that was passed
If both name and index of cookie to be extracted is passed in, name will take
precedence. Basic thing followed is that, when name is passed, index should be -1 and
when index is passed name should null |
public static void getCookie(Map objectModel,
String cookieName,
int cookieIndex,
ContentHandler contentHandler) throws SAXException {
boolean retrieveByName = false;
boolean retrieveByIndex = false;
String tempStr = null;
Hashtable nodeTable = new Hashtable();
if (cookieName != null) {
retrieveByName = true;
} else if (cookieIndex >=0) {
retrieveByIndex = true;
}
if (retrieveByName || retrieveByIndex)
tempStr = getName(objectModel , cookieName , cookieIndex);
if (tempStr !=null) {
XSPObjectHelper.start(URI, PREFIX, contentHandler, "cookie");
// name
nodeTable.put("name", tempStr);
// value
if ((tempStr = getValue(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("value", tempStr);
//comment
if ((tempStr = getComment(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("comment", tempStr);
//value
if ((tempStr = getDomain(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("domain", tempStr);
// maxage
if((tempStr = getMaxAge(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("maxage", tempStr);
// path
if((tempStr = getPath(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("path", tempStr);
// secure
if((tempStr = getSecure(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("secure", tempStr);
// version
if((tempStr = getVersion(objectModel , cookieName , cookieIndex)) != null)
nodeTable.put("version", tempStr);
Enumeration keys = nodeTable.keys();
while (keys.hasMoreElements())
{
String nodeName = (String)keys.nextElement();
String nodeValue = (String)nodeTable.get(nodeName);
XSPObjectHelper.elementData(URI, PREFIX, contentHandler, nodeName, nodeValue);
}
XSPObjectHelper.end(URI, PREFIX, contentHandler, "cookie");
}
}
This method is used to find a cookie by it's name or index and place it in
the XML resulting tree
The xml structure that will be inserted will be,
<cookie>
<name>......</name>
<value>.....</value>
<comment>...</comment>
<domain>....</domain>
<maxage>....</maxage>
<path>......</path>
<secure>....</secure>
<version>...</version>
</cookie>
|
public static Cookie[] getCookies(Map objectModel) {
Request request = ObjectModelHelper.getRequest(objectModel);
return request.getCookies();
}
This method is used to return all the cookies that present in the passed request object |
public static void getCookies(Map objectModel,
ContentHandler contentHandler) throws SAXException {
Request request = ObjectModelHelper.getRequest(objectModel);
Cookie[] cookies = request.getCookies();
if(cookies != null && cookies.length > 0)
{
int count = 0;
String tempStr = null;
Hashtable nodeTable = new Hashtable();
XSPObjectHelper.start(URI, PREFIX, contentHandler, "cookies");
for(count=0; count< cookies.length; count++)
{
XSPObjectHelper.start(URI, PREFIX, contentHandler, "cookie");
if ((tempStr = getName(objectModel , null , count)) != null)
nodeTable.put("name", tempStr);
if((tempStr = getValue(objectModel , null , count))!=null)
nodeTable.put("value", tempStr);
if((tempStr = getComment(objectModel , null , count))!=null)
nodeTable.put("comment", tempStr);
if((tempStr = getDomain(objectModel , null , count))!= null)
nodeTable.put("domain", tempStr);
if((tempStr = getMaxAge(objectModel , null , count))!=null)
nodeTable.put("maxage", tempStr);
if((tempStr = getPath(objectModel , null , count)) != null)
nodeTable.put("path", tempStr);
if((tempStr = getSecure(objectModel , null , count)) !=null)
nodeTable.put("secure", tempStr);
if((tempStr = getVersion(objectModel , null , count)) != null)
nodeTable.put("version", tempStr);
Enumeration keys = nodeTable.keys();
while (keys.hasMoreElements())
{
String nodeName = (String)keys.nextElement();
String nodeValue = (String)nodeTable.get(nodeName);
XSPObjectHelper.elementData(URI, PREFIX, contentHandler, nodeName, nodeValue);
}
XSPObjectHelper.end(URI, PREFIX, contentHandler, "cookie");
}
XSPObjectHelper.end(URI, PREFIX, contentHandler, "cookies");
}
}
This method is used to write the values of all the cookies in the resulting XML tree
The structure that will be added to the XML tree will be
<cookies>
<cookie>
<name>......</name>
<value>.....</value>
<comment>...</comment>
<domain>....</domain>
<maxage>....</maxage>
<path>......</path>
<secure>....</secure>
<version>...</version>
</cookie>
<cookie>
...
</cookie>
...
</cookies>
If the values of any of these is not present those tags will not be present. |
public static String getDomain(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "D");
}
Method to return the value of domain for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static String getMaxAge(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "M");
}
Method to return the value of maxage for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static String getName(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "N");
}
Method to return the value of name for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static String getPath(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "P");
}
Method to return the value of path for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static String getSecure(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "S");
}
Method to return the value of secure property for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static String getValue(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "V");
}
Method to return the value for a particular cookie based on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |
public static String getVersion(Map objectModel,
String cookieName,
int cookieIndex) {
return returnCookieProperty(objectModel , cookieName , cookieIndex , "Ve");
}
Method to return the version of comment for a particular cookie based
on it's name or index
Rule for passing name and index of the cookie remains same as specified in
previous method(s) |