cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anathan...@apache.org
Subject svn commit: r220047 - in /cocoon/trunk: ./ src/documentation/src/content/xdocs/c21-modules-ref/ src/java/org/apache/cocoon/components/modules/input/ src/webapp/WEB-INF/xconf/ src/webapp/samples/modules/
Date Thu, 21 Jul 2005 12:30:18 GMT
Author: anathaniel
Date: Thu Jul 21 05:30:17 2005
New Revision: 220047

URL: http://svn.apache.org/viewcvs?rev=220047&view=rev
Log:
Added CookieModule as a more convinient way to access cookie values as {cookie:query}
in alternative to {request:cookies[name='query']/value}.

Code contributed by Jon Evans (jon.evans@misgl.com).  Bugzilla #28045

Added:
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/CookieModule.java   (with
props)
Modified:
    cocoon/trunk/src/documentation/src/content/xdocs/c21-modules-ref/content_en.html
    cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf
    cocoon/trunk/src/webapp/samples/modules/menu.xml
    cocoon/trunk/src/webapp/samples/modules/sitemap.xmap
    cocoon/trunk/status.xml

Modified: cocoon/trunk/src/documentation/src/content/xdocs/c21-modules-ref/content_en.html
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/documentation/src/content/xdocs/c21-modules-ref/content_en.html?rev=220047&r1=220046&r2=220047&view=diff
==============================================================================
--- cocoon/trunk/src/documentation/src/content/xdocs/c21-modules-ref/content_en.html (original)
+++ cocoon/trunk/src/documentation/src/content/xdocs/c21-modules-ref/content_en.html Thu Jul
21 05:30:17 2005
@@ -76,6 +76,20 @@
       Finish the reference for this Module.</div>
 
         
+<h2>CookieModule</h2>
+<p>This module returns the value of the named HTTP cookie.</p>
+<p>
+<strong>Example Pipeline Fragment:</strong>
+</p>
+<pre class="code">
+&lt;map:match pattern="foo.html"&gt;
+  &lt;map:generate type="file" src="documents/{cookie:user-language}/foo.xml"/&gt;
+  &lt;map:transform src="stylesheets/foo2html.xsl"/&gt;
+  &lt;map:serialize/&gt;
+&lt;/map:match&gt;
+</pre>
+
+        
 <h2>DateInputModule</h2>
 <p>This module returns the current date, optionally formated 
             as string. Format given through attribute "format" of 

Added: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/CookieModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/CookieModule.java?rev=220047&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/CookieModule.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/CookieModule.java Thu
Jul 21 05:30:17 2005
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.http.HttpCookie;
+
+/**
+ * Input module for cookies. Retrieves the value of the requested cookie.
+ * 
+ * @author Jon Evans <jon.evans@misgl.com>
+ * @version CVS $Id:$
+ */
+public class CookieModule extends AbstractInputModule implements ThreadSafe {
+    
+    /**
+     * @return the value of the cookie whose name matches the one requested,
+     * or <code>null</code> if there is no match.
+     */
+    public Object getAttribute(String name, Configuration modeConf,
+            Map objectModel) throws ConfigurationException {
+        
+        HttpCookie cookie = (HttpCookie) getCookieMap(objectModel).get(name);
+        String value = (cookie == null ? null : cookie.getValue());
+        
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Cookie[" + name + "]=" + value);
+        }
+        return value;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
+     *      java.util.Map)
+     */
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+            throws ConfigurationException {
+        
+        return getCookieMap(objectModel).keySet().iterator();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
+     *      org.apache.avalon.framework.configuration.Configuration,
+     *      java.util.Map)
+     */
+    public Object[] getAttributeValues(String name, Configuration modeConf,
+            Map objectModel) throws ConfigurationException {
+        
+        Map allCookies = getCookieMap(objectModel);
+        
+        Iterator it = allCookies.values().iterator();
+        List matched = new LinkedList();
+        while (it.hasNext()) {
+            HttpCookie cookie = (HttpCookie) it.next();
+            if (cookie.getName().matches(name)) {
+                matched.add(cookie.getValue());
+            }
+        }
+        return matched.toArray();
+    }
+
+    /**
+     * @param objectModel
+     *            Object Model for the current request
+     * @return a Map of {see: HttpCookie}s for the current request, keyed on
+     *         cookie name.
+     */
+    protected Map getCookieMap(Map objectModel) {
+        return ObjectModelHelper.getRequest(objectModel).getCookieMap();
+    }
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/CookieModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf?rev=220047&r1=220046&r2=220047&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf (original)
+++ cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf Thu Jul 21 05:30:17 2005
@@ -171,6 +171,7 @@
     <component-instance logger="core.modules.input" name="request-scoped-attr"     class="org.apache.cocoon.components.modules.input.RequestScopedAttributeModule"/>
     <component-instance logger="core.modules.input" name="request-header"   class="org.apache.cocoon.components.modules.input.HeaderAttributeModule"/>
     <component-instance logger="core.modules.input" name="session-attr"     class="org.apache.cocoon.components.modules.input.SessionAttributeModule"/>
+    <component-instance logger="core.modules.input" name="cookie"           class="org.apache.cocoon.components.modules.input.CookieModule"/>
     <component-instance logger="core.modules.input" name="system-property"  class="org.apache.cocoon.components.modules.input.SystemPropertyModule"/>
     <component-instance logger="core.modules.input" name="constant"         class="org.apache.cocoon.components.modules.input.StringConstantModule"/>
     <component-instance logger="core.modules.input" name="random"           class="org.apache.cocoon.components.modules.input.RandomNumberModule"/>

Modified: cocoon/trunk/src/webapp/samples/modules/menu.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/samples/modules/menu.xml?rev=220047&r1=220046&r2=220047&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/samples/modules/menu.xml (original)
+++ cocoon/trunk/src/webapp/samples/modules/menu.xml Thu Jul 21 05:30:17 2005
@@ -31,6 +31,7 @@
   <menu label="Modules">
     <menu-item label="BaseLinkModule" href="baselink.html" desc="BaseLink properties"/>
     <menu-item label="ChainMetaModule" href="chain.html" desc="Chained values"/>
+    <menu-item label="CookieModule" href="cookie.html" desc="Cookie values"/>
     <menu-item label="DateInputModule" href="date.html" desc="Date"/>
     <menu-item label="DefaultsModule" href="defaults.html" desc="Default (static) values"/>
     <menu-item label="GlobalInputModule" href="global.html" desc="Access to the global
variables defined in the sitemap."/>

Modified: cocoon/trunk/src/webapp/samples/modules/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/samples/modules/sitemap.xmap?rev=220047&r1=220046&r2=220047&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/samples/modules/sitemap.xmap (original)
+++ cocoon/trunk/src/webapp/samples/modules/sitemap.xmap Thu Jul 21 05:30:17 2005
@@ -23,6 +23,16 @@
     +-->
 <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
 
+  <!-- =========================== Components ============================== -->
+  <map:components>
+    <map:actions>
+      <!-- Action to store locale name as cookie. -->
+      <map:action name="cookie-locale" src="org.apache.cocoon.acting.LocaleAction">
+        <store-in-cookie>true</store-in-cookie>
+      </map:action>
+    </map:actions>
+  </map:components>
+
   <!-- =========================== Resources =============================== -->
   <map:resources>
     <!-- This resource is used to create a composite page from menu and content -->
@@ -256,6 +266,23 @@
             first that returns a non-null value, usually 'defaults'.
             Try adding '?skin=myskin' to the URL, and it should
             change."/>
+        </map:transform>
+        <map:serialize/>
+      </map:match>
+
+      <map:match pattern="content/cookie.xml">
+        <map:act type="cookie-locale"/>
+        <map:generate type="jx" src="properties.xml">
+          <map:parameter name="locale" value="{cookie:locale}"/>
+        </map:generate>
+        <map:transform src="properties2html.xsl">
+          <map:parameter name="title" value="Cookie module (CookieModule)"/>
+          <map:parameter name="description" value="Returns the value
+            of the named HTTP cookie.
+            The example used LocaleAction to store the current locale name as cookie.
+            If the value is empty, use the browser's reload button.
+            (Cookies just created cannot be read out. Only when the browser presents it
+            on the next request, it will be available.)"/>
         </map:transform>
         <map:serialize/>
       </map:match>

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=220047&r1=220046&r2=220047&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Thu Jul 21 05:30:17 2005
@@ -197,6 +197,10 @@
 
   <changes>
   <release version="@version@" date="@date@">
+    <action dev="AN" type="add" fixes-bug="28045" due-to="Jon Evans" due-to-email="jon.evans@misgl.com">
+      Added CookieModule as a more convinient way to access cookie values as {cookie:query}
+      in alternative to {request:cookies[name='query']/value}.
+    </action>
     <action dev="AN" type="add" fixes-bug="33388" due-to="Andrew Stevens" due-to-email="ats37@hotmail.com">
       Added parameter "show-cocoon-version" to web.xml for configuring whether X-Cocoon-Version
       response header should be sent.  Default is true.



Mime
View raw message