KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > acting > SessionValidatorAction


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.acting;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.thread.ThreadSafe;
20
21 import org.apache.cocoon.environment.ObjectModelHelper;
22 import org.apache.cocoon.environment.Session;
23
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * This is the action used to validate Session parameters (attributes).
31  * The parameters are described via the external xml
32  * file.
33  *
34  * @see org.apache.cocoon.acting.AbstractValidatorAction
35  *
36  * @author <a HREF="mailto:Martin.Man@seznam.cz">Martin Man</a>
37  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
38  * @version CVS $Id: SessionValidatorAction.java 123825 2004-12-31 21:18:01Z antonio $
39  */

40 public class SessionValidatorAction extends AbstractValidatorAction implements ThreadSafe {
41
42     /* (non-Javadoc)
43      * @see org.apache.cocoon.acting.AbstractValidatorAction#createMapOfParameters(java.util.Map, java.util.Collection)
44      */

45     protected HashMap JavaDoc createMapOfParameters(Map JavaDoc objectModel, Collection JavaDoc set) {
46         String JavaDoc name;
47         HashMap JavaDoc params = new HashMap JavaDoc(set.size());
48         // put required params into hash
49
Session session = ObjectModelHelper.getRequest(objectModel).getSession();
50         for (Iterator JavaDoc i = set.iterator(); i.hasNext();) {
51             name = ((Configuration) i.next()).getAttribute("name", "").trim();
52             Object JavaDoc value = session.getAttribute(name);
53             params.put(name, value);
54         }
55         return params;
56     }
57     
58     
59     /* (non-Javadoc)
60      * @see org.apache.cocoon.acting.AbstractValidatorAction#setResult(java.util.Map, java.util.Map, java.util.Map, boolean)
61      */

62     protected Map JavaDoc setResult(Map JavaDoc objectModel, Map JavaDoc actionMap, Map JavaDoc resultMap, boolean allOK) {
63         if (allOK){
64             Session session = ObjectModelHelper.getRequest(objectModel).getSession();
65             for (Iterator JavaDoc i = actionMap.entrySet().iterator(); i.hasNext(); ) {
66                 Map.Entry JavaDoc me = (Map.Entry JavaDoc)i.next();
67                 session.setAttribute((String JavaDoc)me.getKey(), me.getValue());
68             }
69         }
70         return super.setResult(objectModel, actionMap, resultMap, allOK);
71     }
72
73
74     /* (non-Javadoc)
75      * @see org.apache.cocoon.acting.AbstractValidatorAction#isStringEncoded()
76      */

77     boolean isStringEncoded() {
78         return false;
79     }
80
81 }
82
Popular Tags