01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.acting;
18:
19: import org.apache.avalon.framework.configuration.Configuration;
20: import org.apache.avalon.framework.thread.ThreadSafe;
21:
22: import org.apache.cocoon.environment.ObjectModelHelper;
23: import org.apache.cocoon.environment.Session;
24:
25: import java.util.Collection;
26: import java.util.HashMap;
27: import java.util.Iterator;
28: import java.util.Map;
29:
30: /**
31: * This is the action used to validate Session parameters (attributes).
32: * The parameters are described via the external xml
33: * file.
34: *
35: * @see org.apache.cocoon.acting.AbstractValidatorAction
36: *
37: * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
38: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
39: * @version CVS $Id: SessionValidatorAction.java 433543 2006-08-22 06:22:54Z crossley $
40: */
41: public class SessionValidatorAction extends AbstractValidatorAction
42: implements ThreadSafe {
43:
44: /* (non-Javadoc)
45: * @see org.apache.cocoon.acting.AbstractValidatorAction#createMapOfParameters(java.util.Map, java.util.Collection)
46: */
47: protected HashMap createMapOfParameters(Map objectModel,
48: Collection set) {
49: String name;
50: HashMap params = new HashMap(set.size());
51: // put required params into hash
52: Session session = ObjectModelHelper.getRequest(objectModel)
53: .getSession();
54: for (Iterator i = set.iterator(); i.hasNext();) {
55: name = ((Configuration) i.next()).getAttribute("name", "")
56: .trim();
57: Object value = session.getAttribute(name);
58: params.put(name, value);
59: }
60: return params;
61: }
62:
63: /* (non-Javadoc)
64: * @see org.apache.cocoon.acting.AbstractValidatorAction#setResult(java.util.Map, java.util.Map, java.util.Map, boolean)
65: */
66: protected Map setResult(Map objectModel, Map actionMap,
67: Map resultMap, boolean allOK) {
68: if (allOK) {
69: Session session = ObjectModelHelper.getRequest(objectModel)
70: .getSession();
71: for (Iterator i = actionMap.entrySet().iterator(); i
72: .hasNext();) {
73: Map.Entry me = (Map.Entry) i.next();
74: session.setAttribute((String) me.getKey(), me
75: .getValue());
76: }
77: }
78: return super
79: .setResult(objectModel, actionMap, resultMap, allOK);
80: }
81:
82: /* (non-Javadoc)
83: * @see org.apache.cocoon.acting.AbstractValidatorAction#isStringEncoded()
84: */
85: boolean isStringEncoded() {
86: return false;
87: }
88:
89: }
|