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.components.profiler;
18:
19: import org.apache.cocoon.environment.Environment;
20: import org.apache.cocoon.environment.Request;
21: import org.apache.cocoon.environment.ObjectModelHelper;
22: import org.apache.cocoon.environment.Session;
23:
24: import java.util.HashMap;
25: import java.util.Map;
26: import java.util.Enumeration;
27:
28: /**
29: * Holds information about the environment (such as request
30: * parameters and session attributes) to be stored in the ProfilerData.
31: *
32: * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>,
33: * @version CVS $Id: EnvironmentInfo.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class EnvironmentInfo {
36:
37: HashMap requestParameters = new HashMap();
38: HashMap sessionAttributes = new HashMap();
39: String uri;
40: String uriPrefix;
41:
42: public EnvironmentInfo(Environment environment) {
43:
44: Map objectModel = environment.getObjectModel();
45: Request request = ObjectModelHelper.getRequest(objectModel);
46:
47: // make a copy of the request parameters
48: Enumeration requestParameterNames = request.getParameterNames();
49: while (requestParameterNames.hasMoreElements()) {
50: String paramName = (String) requestParameterNames
51: .nextElement();
52: String rawValue = request.getParameter(paramName);
53: String value = rawValue != null ? rawValue : "null";
54: requestParameters.put(paramName, value);
55: }
56:
57: // make a copy of the session contents
58: Session session = request.getSession(false);
59: if (session != null) {
60: Enumeration sessionAttributeNames = session
61: .getAttributeNames();
62: while (sessionAttributeNames.hasMoreElements()) {
63: String attrName = (String) sessionAttributeNames
64: .nextElement();
65: Object rawValue = session.getAttribute(attrName);
66: String value = rawValue != null ? rawValue.toString()
67: : "null";
68: sessionAttributes.put(attrName, value);
69: }
70: }
71:
72: uri = environment.getURI();
73: uriPrefix = environment.getURIPrefix();
74: }
75:
76: public String getURI() {
77: return uri;
78: }
79:
80: public Map getRequestParameters() {
81: return requestParameters;
82: }
83:
84: public Map getSessionAttributes() {
85: return sessionAttributes;
86: }
87: }
|