Author: michiel
Date: 2010-02-09 19:04:00 +0100 (Tue, 09 Feb 2010)
New Revision: 40949
Added:
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/processors/Cookies.java
Modified:
mmbase/branches/MMBase-1_9/applications/taglib/src/main/java/org/mmbase/bridge/jsp/taglib/CloudTag.java
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/bridge/Cloud.java
Log:
: MMB-1931
Modified:
mmbase/branches/MMBase-1_9/applications/taglib/src/main/java/org/mmbase/bridge/jsp/taglib/CloudTag.java
===================================================================
---
mmbase/branches/MMBase-1_9/applications/taglib/src/main/java/org/mmbase/bridge/jsp/taglib/CloudTag.java
2010-02-09 18:01:14 UTC (rev 40948)
+++
mmbase/branches/MMBase-1_9/applications/taglib/src/main/java/org/mmbase/bridge/jsp/taglib/CloudTag.java
2010-02-09 18:04:00 UTC (rev 40949)
@@ -518,6 +518,7 @@
if (cloud.getCloudContext() instanceof LocalContext) {
cloud.setProperty(Cloud.PROP_REQUEST, request);
+ cloud.setProperty(Cloud.PROP_RESPONSE, response);
}
cloud.setProperty(LocaleTag.TZ_KEY, getTimeZone());
Modified:
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/bridge/Cloud.java
===================================================================
--- mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/bridge/Cloud.java
2010-02-09 18:01:14 UTC (rev 40948)
+++ mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/bridge/Cloud.java
2010-02-09 18:04:00 UTC (rev 40949)
@@ -48,13 +48,20 @@
/**
- * With the Cloud a ServletRequest can be associated and stored in the
'property.
+ * With the Cloud a ServletRequest can be associated and stored in a
property with this name
*
* @since MMBase-1.9
*/
public static final String PROP_REQUEST = "request";
+ /**
+ * With the Cloud a ServletResponse can be associated and stored in a
property with this name.
+ *
+ * @since MMBase-1.9.3
+ */
+ public static final String PROP_RESPONSE = "response";
+
/**
* If you set this property on the cloud to true, validation errors will
not be fatal, and nodes
* can be saved anyways.
Added:
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/processors/Cookies.java
===================================================================
---
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/processors/Cookies.java
(rev 0)
+++
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/processors/Cookies.java
2010-02-09 18:04:00 UTC (rev 40949)
@@ -0,0 +1,100 @@
+/*
+
+This software is OSI Certified Open Source Software.
+OSI Certified is a certification mark of the Open Source Initiative.
+
+The license (Mozilla version 1.0) can be read at the MMBase site.
+See http://www.MMBase.org/license
+
+*/
+package org.mmbase.datatypes.processors;
+
+import org.mmbase.bridge.*;
+import org.mmbase.bridge.util.*;
+import org.mmbase.util.Casting;
+import org.mmbase.util.logging.*;
+import javax.servlet.http.*;
+
+
+/**
+ * This processor can be used on a field to return a certain function value of
the node, if the
+ * field is empty. Noticeably, this can be used on 'virtual' field, to map
their value to a function
+ * value, which can come in handy sometimes.
+ *
+ * @author Michiel Meeuwissen
+ * @version $Id: FunctionValueIfEmptyGetter.java 34900 2009-05-01 16:29:42Z
michiel $
+ * @since MMBase-1.9.3
+ */
+
+public class Cookies {
+
+ private static final Logger LOG = Logging.getLoggerInstance(Cookies.class);
+
+
+ protected static abstract class CookieBase {
+ private static final long serialVersionUID = 1L;
+
+ protected String cookie;
+ public void setCookie(String s) {
+ cookie = s;
+ }
+ }
+
+ public static class Getter extends CookieBase implements Processor {
+ private static final long serialVersionUID = 1L;
+
+ public Object process(Node node, Field field, Object value) {
+ LOG.info("Getting defaul gvalue for " + field);
+ Cloud cloud = CloudThreadLocal.currentCloud();
+ if (cloud == null) {
+ LOG.info("No cloud using " + value);
+ return value;
+ } else {
+ HttpServletRequest req = (HttpServletRequest)
cloud.getProperty(Cloud.PROP_REQUEST);
+ if (req == null) {
+ LOG.info("No request using " + value);
+ return value;
+ }
+ Cookie[] cookies = req.getCookies();
+ if (cookies != null) {
+ for (Cookie c : cookies) {
+ LOG.info("Considering " + c.getName());
+ if (c.getName().equals(cookie)) {
+ LOG.info("Found! " + c.getValue());
+ return c.getValue();
+ }
+ }
+ }
+ LOG.info("Cookie not found using " + value);
+ return value;
+ }
+ }
+ }
+
+ public static class Setter extends CookieBase implements Processor {
+ private static final long serialVersionUID = 1L;
+ public Object process(Node node, Field field, Object value) {
+ Cloud cloud = CloudThreadLocal.currentCloud();
+ if (cloud == null) {
+ return value;
+ } else {
+ HttpServletResponse res = (HttpServletResponse)
cloud.getProperty(Cloud.PROP_RESPONSE);
+ if (res == null) {
+ return value;
+ }
+ Cookie c = new Cookie(cookie, Casting.toString(value));
+ c.setMaxAge(60 * 60 * 24 * 365);
+ if (res.isCommitted()) {
+ LOG.warn("Cannot set cookie " + c);
+ } else {
+ LOG.service("Setting cookie " + c);
+ res.addCookie(c);
+ }
+ return value;
+ }
+ }
+ }
+
+}
+
+
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs