php.java.script.servlet
Class EngineFactory

java.lang.Object
  extended by php.java.script.servlet.EngineFactory

public class EngineFactory
extends java.lang.Object

Create JSR 223 script engines from a servlet context.

See Also:
ContextLoaderListener, InvocablePhpServletScriptEngine, PhpServletScriptEngine

Field Summary
static java.lang.String ROOT_ENGINE_FACTORY_ATTRIBUTE
          The key used to store the factory in the servlet context
 
Constructor Summary
EngineFactory()
          Only for internal use
 
Method Summary
static void addManaged(javax.servlet.http.HttpServletRequest req, InvocablePhpServletLocalHttpServerScriptEngine engine)
          Manage a script engine
static java.io.FileReader createPhpScriptFileReader(java.io.File phpScriptFile)
          Deprecated. Use createPhpScriptFileReader(ScriptFile) instead
static java.io.FileReader createPhpScriptFileReader(php.java.script.servlet.ScriptFile phpScriptFile)
          Create a Reader from a given PHP script file.
static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Get a PHP JSR 223 ScriptEngine which implements the Invocable interface from the servlet context.
static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String protocol, int port)
          Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local host.
static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String protocol, int port, java.lang.String proxy)
          Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local host.
static php.java.script.servlet.ScriptFile getPhpScript(java.lang.String path)
          Get a PHP script from the given Path.
static php.java.script.servlet.ScriptFile getPhpScript(java.lang.String path, java.io.Reader reader)
          Get a PHP script from the given Path.
static ScriptEngine getPhpScriptEngine(javax.servlet.Servlet servlet, javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Get a PHP JSR 223 ScriptEngine from the servlet context.
 void releaseScriptEngines(java.util.List list)
          Release all managed script engines.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_ENGINE_FACTORY_ATTRIBUTE

public static final java.lang.String ROOT_ENGINE_FACTORY_ATTRIBUTE
The key used to store the factory in the servlet context

Constructor Detail

EngineFactory

public EngineFactory()
Only for internal use

Method Detail

getPhpScriptEngine

public static ScriptEngine getPhpScriptEngine(javax.servlet.Servlet servlet,
                                              javax.servlet.ServletContext ctx,
                                              javax.servlet.http.HttpServletRequest req,
                                              javax.servlet.http.HttpServletResponse res)
                                       throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine from the servlet context. Example:
ScriptEngine scriptEngine = EngineFactory.getPhpScriptEngine(this, application, request, response);
scriptEngine.eval(reader);
reader.close();

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
Returns:
the PHP JSR 223 ScriptEngine, an instance of the PhpServletScriptEngine
Throws:
java.lang.Exception
java.net.MalformedURLException
java.lang.IllegalStateException

getInvocablePhpScriptEngine

public static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet,
                                                       javax.servlet.ServletContext ctx,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse res)
                                                throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine which implements the Invocable interface from the servlet context. Example:
ScriptEngine scriptEngine = EngineFactory.getInvocablePhpScriptEngine(this, application, request, response);
...
scriptEngine.eval(reader);
reader.close ();
Invocable invocableEngine = (Invocable)scriptEngine;
invocableEngine.invoceFunction("phpinfo", new Object[]{});
...
scriptEngine.eval ((Reader)null);

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
Returns:
the invocable PHP JSR 223 ScriptEngine, an instance of the InvocablePhpServletScriptEngine
Throws:
java.lang.Exception
java.net.MalformedURLException
java.lang.IllegalStateException

getInvocablePhpScriptEngine

public static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet,
                                                       javax.servlet.ServletContext ctx,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse res,
                                                       java.lang.String protocol,
                                                       int port)
                                                throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local host. Example:
ScriptEngine scriptEngine = EngineFactory.getInvocablePhpScriptEngine(this, application, request, response, "HTTP", 80);
...
scriptEngine.eval(reader);
reader.close ();
Invocable invocableEngine = (Invocable)scriptEngine;
invocableEngine.invoceFunction("phpinfo", new Object[]{});
...
scriptEngine.eval ((Reader)null);

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
protocol - either "HTTP" or "HTTPS"
port - the port number
Returns:
the invocable PHP JSR 223 ScriptEngine, an instance of the InvocablePhpServletScriptEngine
Throws:
java.lang.Exception
java.net.MalformedURLException
java.lang.IllegalStateException

getInvocablePhpScriptEngine

public static ScriptEngine getInvocablePhpScriptEngine(javax.servlet.Servlet servlet,
                                                       javax.servlet.ServletContext ctx,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse res,
                                                       java.lang.String protocol,
                                                       int port,
                                                       java.lang.String proxy)
                                                throws java.lang.Exception
Get a PHP JSR 223 ScriptEngine, which implements the Invocable interface, from a HTTP server running on the local host. Example:
ScriptEngine scriptEngine = EngineFactory.getInvocablePhpScriptEngine(this, application, request, response, "HTTP", 80);
...
scriptEngine.eval(reader);
reader.close ();
Invocable invocableEngine = (Invocable)scriptEngine;
invocableEngine.invoceFunction("phpinfo", new Object[]{});
...
scriptEngine.eval ((Reader)null);

Parameters:
servlet - the servlet
ctx - the servlet context
req - the request
res - the response
protocol - either "HTTP" or "HTTPS"
port - the port number
proxy - the name of the PHP proxy, for example "/JavaProxy.php"
Returns:
the invocable PHP JSR 223 ScriptEngine, an instance of the InvocablePhpServletScriptEngine
Throws:
java.lang.Exception
java.net.MalformedURLException
java.lang.IllegalStateException

getPhpScript

public static php.java.script.servlet.ScriptFile getPhpScript(java.lang.String path,
                                                              java.io.Reader reader)
Get a PHP script from the given Path. This procedure can be used to cache dynamically-generated scripts

Parameters:
path - the file path which should contain the cached script, must be within the web app directory
reader - the JSR 223 script reader
Returns:
A pointer to the cached PHP script, named: path+"._cache_.php"
See Also:
createPhpScriptFileReader(File)

getPhpScript

public static php.java.script.servlet.ScriptFile getPhpScript(java.lang.String path)
Get a PHP script from the given Path. This procedure can be used to cache dynamically-generated scripts

Parameters:
path - the file path which should contain the cached script, must be within the web app directory
Returns:
A pointer to the cached PHP script, usually named: path+"._cache_.php"
See Also:
createPhpScriptFileReader(File)

createPhpScriptFileReader

public static java.io.FileReader createPhpScriptFileReader(php.java.script.servlet.ScriptFile phpScriptFile)
Create a Reader from a given PHP script file. This procedure can be used to create a reader from a cached script Example:
private static File script;
private static final File getScript() {
   if (script!=null) return script;
   return EngineFactory.getPhpScript(ctx.getRealPath(req.getServletPath(),new StringReader("<?php phpinfo();?>"));
}
...
FileReader reader = EngineFactory.createPhpScriptFileReader(getScript());
scriptEngine.eval (reader);
reader.close();
...

Parameters:
phpScriptFile - the file containing the cached script, obtained from getPhpScript(String, Reader) or getPhpScript(String)
Returns:
A pointer to the cached PHP script, usually named: path+"._cache_.php"

createPhpScriptFileReader

public static java.io.FileReader createPhpScriptFileReader(java.io.File phpScriptFile)
Deprecated. Use createPhpScriptFileReader(ScriptFile) instead

Parameters:
phpScriptFile -
Returns:
A new FileReader

releaseScriptEngines

public void releaseScriptEngines(java.util.List list)
Release all managed script engines. Will be called automatically at the end of each request, if a RequestListener has been declared.

Parameters:
list - the list from the request attribute RequestListener.ROOT_ENGINES_COLLECTION_ATTRIBUTE

addManaged

public static void addManaged(javax.servlet.http.HttpServletRequest req,
                              InvocablePhpServletLocalHttpServerScriptEngine engine)
                       throws ScriptException
Manage a script engine

Parameters:
req - the servlet request
engine - the engine to manage
Throws:
ScriptException
See Also:
releaseScriptEngines(List)