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.lenya.cms.cocoon.components.context;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.component.Component;
22: import org.apache.avalon.framework.context.Context;
23: import org.apache.avalon.framework.context.ContextException;
24: import org.apache.avalon.framework.context.Contextualizable;
25: import org.apache.avalon.framework.logger.AbstractLogEnabled;
26: import org.apache.cocoon.components.ContextHelper;
27: import org.apache.cocoon.environment.Request;
28: import org.apache.cocoon.environment.Response;
29:
30: /**
31: * Utility class for getting the context, request, response and
32: * object model of the current request.
33: */
34: public class ContextUtility extends AbstractLogEnabled implements
35: Component, Contextualizable {
36: /**
37: * The component's role.
38: */
39: public static final String ROLE = ContextUtility.class.getName();
40:
41: protected Context context;
42:
43: /**
44: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
45: */
46: public void contextualize(Context context) throws ContextException {
47: this .context = context;
48: }
49:
50: /**
51: * Get the context object of the current request.
52: * @return The context object of the current request.
53: */
54: public Context getContext() {
55: return context;
56: }
57:
58: /**
59: * Get the request object of the current request.
60: * @return The request object of the current request.
61: */
62: public Request getRequest() {
63: return ContextHelper.getRequest(context);
64: }
65:
66: /**
67: * Get the response object of the current request.
68: * @return The response object of the current request.
69: */
70: public Response getResponse() {
71: return ContextHelper.getResponse(context);
72: }
73:
74: /**
75: * Get the object model of the current request.
76: * @return The object model of the current request.
77: */
78: public Map getObjectModel() {
79: return ContextHelper.getObjectModel(context);
80: }
81: }
|