Class JavaxPacScriptParser
- java.lang.Object
-
- com.github.markusbernhardt.proxy.selector.pac.JavaxPacScriptParser
-
- All Implemented Interfaces:
PacScriptParser
public class JavaxPacScriptParser extends java.lang.Object implements PacScriptParser
PAC parser using the Rhino JavaScript engine bundled with Java 1.6
More information about PAC can be found there:
Proxy_auto-config
web-browser-auto-proxy-configuration
-
-
Field Summary
Fields Modifier and Type Field Description private delight.rhinosandox.RhinoSandboxengine(package private) static java.lang.StringSCRIPT_METHODS_OBJECTprivate PacScriptSourcesource(package private) static java.lang.StringSOURCE_NAME
-
Constructor Summary
Constructors Constructor Description JavaxPacScriptParser(PacScriptSource source)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringbuildFunctionCallCode(java.lang.String functionName, int args)Builds a JavaScript code snippet to call a function that we bind.java.lang.Stringevaluate(java.lang.String url, java.lang.String host)Evaluates the given URL and host against the PAC script.PacScriptSourcegetScriptSource()Gets the source of the PAC script used by this parser.private delight.rhinosandox.RhinoSandboxsetupEngine()Initializes the JavaScript engine and adds aliases for the functions defined in ScriptMethods.
-
-
-
Field Detail
-
SCRIPT_METHODS_OBJECT
static final java.lang.String SCRIPT_METHODS_OBJECT
- See Also:
- Constant Field Values
-
SOURCE_NAME
static final java.lang.String SOURCE_NAME
-
source
private final PacScriptSource source
-
engine
private final delight.rhinosandox.RhinoSandbox engine
-
-
Constructor Detail
-
JavaxPacScriptParser
public JavaxPacScriptParser(PacScriptSource source) throws ProxyEvaluationException
Constructor- Parameters:
source- the source for the PAC script.- Throws:
ProxyEvaluationException- on error.
-
-
Method Detail
-
setupEngine
private delight.rhinosandox.RhinoSandbox setupEngine() throws ProxyEvaluationExceptionInitializes the JavaScript engine and adds aliases for the functions defined in ScriptMethods.- Throws:
ProxyEvaluationException- on error.
-
buildFunctionCallCode
private java.lang.String buildFunctionCallCode(java.lang.String functionName, int args)Builds a JavaScript code snippet to call a function that we bind.- Parameters:
functionName- of the bound functionargs- of the bound function- Returns:
- the JS code to invoke the method.
-
getScriptSource
public PacScriptSource getScriptSource()
Gets the source of the PAC script used by this parser.- Specified by:
getScriptSourcein interfacePacScriptParser- Returns:
- a PacScriptSource.
-
evaluate
public java.lang.String evaluate(java.lang.String url, java.lang.String host) throws ProxyEvaluationExceptionEvaluates the given URL and host against the PAC script.- Specified by:
evaluatein interfacePacScriptParser- Parameters:
url- the URL to evaluate.host- the host name part of the URL.- Returns:
- the script result.
- Throws:
ProxyEvaluationException- on execution error.
-
-