KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > profiler > EnvironmentInfo


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.components.profiler;
17
18 import org.apache.cocoon.environment.Environment;
19 import org.apache.cocoon.environment.Request;
20 import org.apache.cocoon.environment.ObjectModelHelper;
21 import org.apache.cocoon.environment.Session;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Enumeration JavaDoc;
26
27 /**
28  * Holds information about the environment (such as request
29  * parameters and session attributes) to be stored in the ProfilerData.
30  *
31  * @author <a HREF="mailto:bruno@outerthought.org">Bruno Dumon</a>,
32  * @version CVS $Id: EnvironmentInfo.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

34 public class EnvironmentInfo {
35
36     HashMap JavaDoc requestParameters = new HashMap JavaDoc();
37       HashMap JavaDoc sessionAttributes = new HashMap JavaDoc();
38     String JavaDoc uri;
39       String JavaDoc uriPrefix;
40
41     public EnvironmentInfo(Environment environment) {
42
43             Map JavaDoc objectModel = environment.getObjectModel();
44             Request request = ObjectModelHelper.getRequest(objectModel);
45
46             // make a copy of the request parameters
47
Enumeration JavaDoc requestParameterNames = request.getParameterNames();
48             while (requestParameterNames.hasMoreElements()) {
49                 String JavaDoc paramName = (String JavaDoc)requestParameterNames.nextElement();
50                 String JavaDoc rawValue = request.getParameter(paramName);
51                   String JavaDoc value = rawValue != null ? rawValue : "null";
52                 requestParameters.put(paramName, value);
53             }
54
55             // make a copy of the session contents
56
Session session = request.getSession(false);
57             if (session != null) {
58                 Enumeration JavaDoc sessionAttributeNames = session.getAttributeNames();
59                 while (sessionAttributeNames.hasMoreElements()) {
60                         String JavaDoc attrName = (String JavaDoc)sessionAttributeNames.nextElement();
61                         Object JavaDoc rawValue = session.getAttribute(attrName);
62                         String JavaDoc value = rawValue != null ? rawValue.toString() : "null";
63                         sessionAttributes.put(attrName, value);
64                   }
65             }
66
67             uri = environment.getURI();
68             uriPrefix = environment.getURIPrefix();
69     }
70
71     public String JavaDoc getURI() {
72         return uri;
73     }
74
75     public Map JavaDoc getRequestParameters() {
76         return requestParameters;
77     }
78
79     public Map JavaDoc getSessionAttributes() {
80         return sessionAttributes;
81     }
82 }
83
84
Popular Tags