Skip to content

Package: JspContext

JspContext

nameinstructionbranchcomplexitylinemethod
JspContext()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
popBody()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
pushBody(Writer)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2022 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.servlet.jsp;
20:
21: import java.util.Enumeration;
22:
23: import jakarta.el.ELContext;
24:
25: /**
26: * <p>
27: * <code>JspContext</code> serves as the base class for the PageContext class and abstracts all information that is not
28: * specific to servlets. This allows for Simple Tag Extensions to be used outside of the context of a request/response
29: * Servlet.
30: * <p>
31: * The JspContext provides a number of facilities to the page/component author and page implementor, including:
32: * <ul>
33: * <li>a single API to manage the various scoped namespaces
34: * <li>a mechanism to obtain the JspWriter for output
35: * <li>a mechanism to expose page directive attributes to the scripting environment
36: * </ul>
37: *
38: * <p>
39: * <B>Methods Intended for Container Generated Code</B>
40: * <p>
41: * The following methods enable the <B>management of nested</B> JspWriter streams to implement Tag Extensions:
42: * <code>pushBody()</code> and <code>popBody()</code>
43: *
44: * <p>
45: * <B>Methods Intended for JSP authors</B>
46: * <p>
47: * Some methods provide <B>uniform access</B> to the diverse objects representing scopes. The implementation must use
48: * the underlying machinery corresponding to that scope, so information can be passed back and forth between the
49: * underlying environment (e.g. Servlets) and JSP pages. The methods are: <code>setAttribute()</code>,
50: * <code>getAttribute()</code>, <code>findAttribute()</code>, <code>removeAttribute()</code>,
51: * <code>getAttributesScope()</code> and <code>getAttributeNamesInScope()</code>.
52: *
53: * <p>
54: * The following methods provide <B>convenient access</B> to implicit objects: <code>getOut()</code>
55: *
56: * <p>
57: * The following methods provide <B>programmatic access</b> to the Expression Language evaluator:
58: * <code>getExpressionEvaluator()</code>, <code>getVariableResolver()</code>
59: *
60: * @since JSP 2.0
61: */
62: public abstract class JspContext {
63:
64: /**
65: * Sole constructor. (For invocation by subclass constructors, typically implicit.)
66: */
67: public JspContext() {
68: }
69:
70: /**
71: * Register the name and value specified with page scope semantics. If the value passed in is <code>null</code>,
72: * this has the same effect as calling <code>removeAttribute( name, PageContext.PAGE_SCOPE )</code>.
73: *
74: * @param name the name of the attribute to set
75: * @param value the value to associate with the name, or null if the attribute is to be removed from the page scope.
76: * @throws NullPointerException if the name is null
77: */
78: abstract public void setAttribute(String name, Object value);
79:
80: /**
81: * Register the name and value specified with appropriate scope semantics. If the value passed in is
82: * <code>null</code>, this has the same effect as calling <code>removeAttribute( name, scope )</code>.
83: *
84: * @param name the name of the attribute to set
85: * @param value the object to associate with the name, or null if the attribute is to be removed from the specified
86: * scope.
87: * @param scope the scope with which to associate the name/object
88: *
89: * @throws NullPointerException if the name is null
90: * @throws IllegalArgumentException if the scope is invalid
91: * @throws IllegalStateException if the scope is PageContext.SESSION_SCOPE but the page that was requested does
92: * not participate in a session or the session has been invalidated.
93: */
94: abstract public void setAttribute(String name, Object value, int scope);
95:
96: /**
97: * Returns the object associated with the name in the page scope or null if not found.
98: *
99: * @param name the name of the attribute to get
100: * @return the object associated with the name in the page scope or null if not found.
101: *
102: * @throws NullPointerException if the name is null
103: */
104: abstract public Object getAttribute(String name);
105:
106: /**
107: * Return the object associated with the name in the specified scope or null if not found.
108: *
109: * @param name the name of the attribute to set
110: * @param scope the scope with which to associate the name/object
111: * @return the object associated with the name in the specified scope or null if not found.
112: *
113: * @throws NullPointerException if the name is null
114: * @throws IllegalArgumentException if the scope is invalid
115: * @throws IllegalStateException if the scope is PageContext.SESSION_SCOPE but the page that was requested does
116: * not participate in a session or the session has been invalidated.
117: */
118: abstract public Object getAttribute(String name, int scope);
119:
120: /**
121: * Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and
122: * returns the value associated or null.
123: *
124: * @param name the name of the attribute to search for
125: * @return the value associated or null
126: * @throws NullPointerException if the name is null
127: */
128: abstract public Object findAttribute(String name);
129:
130: /**
131: * Remove the object reference associated with the given name from all scopes. Does nothing if there is no such
132: * object.
133: *
134: * @param name The name of the object to remove.
135: * @throws NullPointerException if the name is null
136: */
137: abstract public void removeAttribute(String name);
138:
139: /**
140: * Remove the object reference associated with the specified name in the given scope. Does nothing if there is no
141: * such object.
142: *
143: * @param name The name of the object to remove.
144: * @param scope The scope where to look.
145: * @throws IllegalArgumentException if the scope is invalid
146: * @throws IllegalStateException if the scope is PageContext.SESSION_SCOPE but the page that was requested does
147: * not participate in a session or the session has been invalidated.
148: * @throws NullPointerException if the name is null
149: */
150: abstract public void removeAttribute(String name, int scope);
151:
152: /**
153: * Get the scope where a given attribute is defined.
154: *
155: * @param name the name of the attribute to return the scope for
156: * @return the scope of the object associated with the name specified or 0
157: * @throws NullPointerException if the name is null
158: */
159: abstract public int getAttributesScope(String name);
160:
161: /**
162: * Enumerate all the attributes in a given scope.
163: *
164: * @param scope the scope to enumerate all the attributes for
165: * @return an enumeration of names (java.lang.String) of all the attributes the specified scope
166: * @throws IllegalArgumentException if the scope is invalid
167: * @throws IllegalStateException if the scope is PageContext.SESSION_SCOPE but the page that was requested does
168: * not participate in a session or the session has been invalidated.
169: */
170: abstract public Enumeration<String> getAttributeNamesInScope(int scope);
171:
172: /**
173: * The current value of the out object (a JspWriter).
174: *
175: * @return the current JspWriter stream being used for client response
176: */
177: abstract public JspWriter getOut();
178:
179: /**
180: * Returns the <code>ELContext</code> associated with this <code>JspContext</code>.
181: *
182: * <p>
183: * The <code>ELContext</code> is created lazily and is reused if it already exists. There is a new
184: * <code>ELContext</code> for each <code>JspContext</code>.
185: * </p>
186: *
187: * <p>
188: * The <code>ELContext</code> must contain the <code>ELResolver</code> described in the JSP specification (and in
189: * the javadocs for {@link JspApplicationContext#addELResolver}).
190: * </p>
191: *
192: * @return The <code>ELContext</code> associated with this <code>JspContext</code>.
193: * @since JSP 2.1
194: */
195: public abstract ELContext getELContext();
196:
197: /**
198: * Return a new JspWriter object that sends output to the provided Writer. Saves the current "out" JspWriter, and
199: * updates the value of the "out" attribute in the page scope attribute namespace of the JspContext.
200: * <p>
201: * The returned JspWriter must implement all methods and behave as though it were unbuffered. More specifically:
202: * </p>
203: * <ul>
204: * <li>clear() must throw an IOException</li>
205: * <li>clearBuffer() does nothing</li>
206: * <li>getBufferSize() always returns 0</li>
207: * <li>getRemaining() always returns 0</li>
208: * </ul>
209: *
210: * @param writer The Writer for the returned JspWriter to send output to.
211: * @return a new JspWriter that writes to the given Writer.
212: * @since JSP 2.0
213: */
214: public JspWriter pushBody(java.io.Writer writer) {
215: return null; // XXX to implement
216: }
217:
218: /**
219: * Return the previous JspWriter "out" saved by the matching pushBody(), and update the value of the "out" attribute
220: * in the page scope attribute namespace of the JspContext.
221: *
222: * @return the saved JspWriter.
223: */
224: public JspWriter popBody() {
225: return null; // XXX to implement
226: }
227: }