### php.java.script

# Class PhpSimpleHttpScriptContext

- `java.lang.Object`

- `javax.script.SimpleScriptContext`

- `php.java.script.PhpSimpleHttpScriptContext`

Implemented Interfaces:
  Invocable, IPhpScriptContext, ScriptContext

Known Direct Subclasses:
  PhpFacesScriptContext

`public abstract class PhpSimpleHttpScriptContext`
`extends SimpleScriptContext`
`implements IPhpScriptContext`

A simple ScriptContext which can be used in servlet environments.

Author:
  jostb

## Field Summary

`static int`

`APPLICATION_SCOPE`
  Integer value for the level of APPLICATION_SCOPE

`static int`

`REQUEST_SCOPE`
  Integer value for the level of SCRIPT_SCOPE

`static int`

`SESSION_SCOPE`
  Integer value for the level of SESSION_SCOPE

### Fields inherited from interface javax.script.ScriptContext

`ENGINE_SCOPE`, `GLOBAL_SCOPE`

## Method Summary

`java.lang.Object`

`getAttribute(java.lang.String name)`
  Retrieves the value of the getAttribute(String, int) for the lowest scope in which it returns a non-null value.

`java.lang.Object`

`getAttribute(java.lang.String key, int scope)`
  Retrieves the value of an attribute in the specified scope.

`javax.servlet.ServletContext`

`getContext()`
  Get the ServletContext

`javax.servlet.http.HttpServletRequest`

`getRequest()`
  Get the HttpServletRequest

`javax.servlet.http.HttpServletResponse`

`getResponse()`
  Get the servlet response

`java.io.Writer`

`getWriter()`
  Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

`void`

`initialize(javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, PhpScriptWriter writer)`
  Initilaize the context.

`void`

`setAttribute(java.lang.String key, java.lang.Object value, int scope)`
  Associates a specified value with the specifed name in the specified scope.

### Methods inherited from class javax.script.SimpleScriptContext

`getAttribute`, `getAttribute`, `getAttributesScope`, `getBindings`, `getWriter`, `removeAttribute`, `setAttribute`, `setBindings`

### Methods inherited from class java.lang.Object

`equals`, `getClass`, `hashCode`, `notify`, `notifyAll`, `toString`, `wait`, `wait`, `wait`

## Field Details

### APPLICATION_SCOPE

    public static final int APPLICATION_SCOPE

> Integer value for the level of APPLICATION_SCOPE

> Field Value:
>   200

### REQUEST_SCOPE

    public static final int REQUEST_SCOPE

> Integer value for the level of SCRIPT_SCOPE

> Field Value:
>   0

### SESSION_SCOPE

    public static final int SESSION_SCOPE

> Integer value for the level of SESSION_SCOPE

> Field Value:
>   100

## Method Details

### getAttribute

    public java.lang.Object getAttribute(java.lang.String name)
                throws java.lang.IllegalArgumentException

> Retrieves the value of the getAttribute(String, int) for the lowest scope in which it returns a non-null value. Returns null if there is no such value exists in any scope.
> Specified by:
>   getAttribute in interface ScriptContext
> Overrides:
>   getAttribute in interface SimpleScriptContext

> Parameters:
>   `name` - the name of the attribute

> Returns:
>   the associated value with the specified name

> Throws:
>   `java.lang.IllegalArgumentException` - if the name is null

### getAttribute

    public java.lang.Object getAttribute(java.lang.String key,
                                         int scope)

> Retrieves the value of an attribute in the specified scope. Returns null if the no such value exists in the specified scope.
> Specified by:
>   getAttribute in interface ScriptContext
> Overrides:
>   getAttribute in interface SimpleScriptContext

> Parameters:
>   `scope` - the value of the scope

> Returns:
>   the associated value for the specified name

> Throws:
>   `java.lang.IllegalArgumentException` - if the name is null or the scope is invalid

### getContext

    public javax.servlet.ServletContext getContext()

> Get the ServletContext

> Returns:
>   The current ServletContext

### getRequest

    public javax.servlet.http.HttpServletRequest getRequest()

> Get the HttpServletRequest

> Returns:
>   The HttpServletRequest

### getResponse

    public javax.servlet.http.HttpServletResponse getResponse()

> Get the servlet response

> Returns:
>   The HttpServletResponse

### getWriter

    public java.io.Writer getWriter()

> Retrieves an instance of java.io.Writer which can be used by scripts to display their output.
> Specified by:
>   getWriter in interface IPhpScriptContext
>   getWriter in interface ScriptContext
> Overrides:
>   getWriter in interface SimpleScriptContext

> Returns:
>   an instance of java.io.Writer

### initialize

    public void initialize(javax.servlet.ServletContext ctx,
                           javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res,
                           PhpScriptWriter writer)
                throws javax.servlet.ServletException

> Initilaize the context.

> Parameters:
>   `ctx` - The ServletContext
>   `req` - The HttpServletRequest
>   `res` - The HttpServletResponse
>   `writer` - The PhpScriptWriter

> Throws:
>   `javax.servlet.ServletException` -

### setAttribute

    public void setAttribute(java.lang.String key,
                             java.lang.Object value,
                             int scope)
                throws java.lang.IllegalArgumentException

> Associates a specified value with the specifed name in the specified scope.
> Specified by:
>   setAttribute in interface ScriptContext
> Overrides:
>   setAttribute in interface SimpleScriptContext

> Parameters:
>   `key` - the name of the attribute
>   `value` - the value of the attribute
>   `scope` - the level of the scope

> Throws:
>   `java.lang.IllegalArgumentException` - if the name is null or the scope is invalid