Class AbstractJessopScriptBuilder
- All Implemented Interfaces:
JessopScriptBuilder
- Direct Known Subclasses:
JavaJessopScriptBuilder
,JavascriptJessopScriptBuilder
,LispJessopScriptBuilder
,LuaJessopScriptBuilder
,Python2JessopScriptBuilder
,RubyJessopScriptBuilder
This class is responsible for processing jessop declarations (e.g. <%@ jessop language="javascript" engine="rhino" %>
),
and switching to the correct language JessopScriptBuilder implementation.
Note that having multiple languages in the same script file is not yet supported by jessop. The declaration (if it exists) should therefore only appear once, and be the first thing that appears in a jessop source file.
If the declaration is missing, then the default JavascriptJessopScriptBuilder is used, using the 'rhino' engine.
- Author:
- knoxg
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JessopDeclarations
protected org.apache.log4j.Logger
protected PrintWriter
protected Tokeniser
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
emitDeclaration
(int line, String s) Called by the tokeniser and requests that this JessopScriptBuilder process a<%@ ...
abstract void
emitExpression
(int line, String s) Called by the tokeniser and requests that this JessopScriptBuilder generate code to generate some evaluated output.abstract void
emitScriptlet
(int line, String s) Called by the tokeniser and requests that this JessopScriptBuilder copy the included code into the generated script.abstract void
Called by the tokeniser and requests that this JessopScriptBuilder generate code to generate some text output.Returns the value of any jessop declarations that are in effect.Returns the name of the default bindingsConverter class that should be used for the default script engine, or null if no converter is required.Returns the name of the default exceptionConverter class that should be used for the default script engine, or null if no converter is required.void
Sets the printWriter that this class will write to during emit() methodsvoid
setTokeniserAndDeclarations
(Tokeniser t, JessopDeclarations declarations) Sets the tokeniser and declaration that are in effect at the start of parsing.protected String
suppressEol
(String s, boolean suppressEol) Conditionally remove the first newline from the supplied string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.randomnoun.common.jessop.JessopScriptBuilder
getDefaultScriptEngineName, getLanguage
-
Field Details
-
logger
-
declarations
-
tokeniser
-
pw
-
-
Constructor Details
-
AbstractJessopScriptBuilder
public AbstractJessopScriptBuilder()
-
-
Method Details
-
setPrintWriter
Description copied from interface:JessopScriptBuilder
Sets the printWriter that this class will write to during emit() methods- Specified by:
setPrintWriter
in interfaceJessopScriptBuilder
- Parameters:
pw
- the printWriter that this class will write to during emit() methods
-
setTokeniserAndDeclarations
Description copied from interface:JessopScriptBuilder
Sets the tokeniser and declaration that are in effect at the start of parsing. This allows this ScriptBuilder to switch ScriptBuilders.- Specified by:
setTokeniserAndDeclarations
in interfaceJessopScriptBuilder
- Parameters:
t
- tokeniser that is processing the jessop sourcedeclarations
- jessop declarations that are in effect
-
getDeclarations
Description copied from interface:JessopScriptBuilder
Returns the value of any jessop declarations that are in effect.Used to maintain declarations when switching JessopScriptBuilders, and to retrieve declarations after the script is built.
- Specified by:
getDeclarations
in interfaceJessopScriptBuilder
-
emitDeclaration
Description copied from interface:JessopScriptBuilder
Called by the tokeniser and requests that this JessopScriptBuilder process a<%@ ... %>
directive.The exact semantics of these declarations can be defined per-language, but 'jessop' declarations should be processed by the AbstractJessopScriptBuilder, i.e. declarations that are in the form
<%@ jessop language="xxx" %>
Ideally, there's only one declaration, at the top of the source script.
- Specified by:
emitDeclaration
in interfaceJessopScriptBuilder
- Parameters:
line
- jessop source line number that begins this directives
- the contents of the<%@ ... %>
directive- Throws:
ScriptException
-
emitText
Description copied from interface:JessopScriptBuilder
Called by the tokeniser and requests that this JessopScriptBuilder generate code to generate some text output.This method should escape the output and generate code that outputs this text in the implementation language.
- Specified by:
emitText
in interfaceJessopScriptBuilder
- Parameters:
line
- jessop source line number that begins this text outputs
- the text to output; may include newlines.
-
emitExpression
Description copied from interface:JessopScriptBuilder
Called by the tokeniser and requests that this JessopScriptBuilder generate code to generate some evaluated output. i.e. process a<%= ... %>
expression.This method should generate the code to evaluate and output the contents of the
<%= ... %>
expression.This method should attempt to preserve line numbers between the jessop source file and the generated code file.
- Specified by:
emitExpression
in interfaceJessopScriptBuilder
- Parameters:
line
- jessop source line number that begins this text output.s
- the contents of the<%= ... %>
expression.
-
emitScriptlet
Description copied from interface:JessopScriptBuilder
Called by the tokeniser and requests that this JessopScriptBuilder copy the included code into the generated script. i.e. process a<% ... %>
scriptlet. (The 'scriptlet' term is the term used in the JSP specification)This method should generate the same code that is contained within the
<% ... %>
scriptlet.This method should attempt to preserve line numbers between the jessop source file and the generated code file.
This scriptlet may not be syntactically correct by itself and may require further scriptlets to function, e.g.
<% if (a > b) { %> something <% } %>
- Specified by:
emitScriptlet
in interfaceJessopScriptBuilder
- Parameters:
line
- jessop source line number that begins this scriptlet.s
- the contents of the<%= ... %>
expression.
-
getDefaultExceptionConverterClassName
Description copied from interface:JessopScriptBuilder
Returns the name of the default exceptionConverter class that should be used for the default script engine, or null if no converter is required.Changing the engine in the jessop declaration will reset the the converter to null.
- Specified by:
getDefaultExceptionConverterClassName
in interfaceJessopScriptBuilder
- Returns:
- the name of the default exceptionConverter class that should be used for the default script engine
-
getDefaultBindingsConverterClassName
Description copied from interface:JessopScriptBuilder
Returns the name of the default bindingsConverter class that should be used for the default script engine, or null if no converter is required.Changing the engine in the jessop declaration will reset the the converter to null.
- Specified by:
getDefaultBindingsConverterClassName
in interfaceJessopScriptBuilder
- Returns:
- the name of the default bindingsConverter class that should be used for the default script engine
-
suppressEol
Conditionally remove the first newline from the supplied string.This method is used to perform
suppressEol
declaration processing.When the
suppressEol
declaration istrue
, and the text to be emitted by the output script immediately follows a scriptlet and begins with a newline (or whitespace followed by a newline), then we want to remove that (whitespace and) newline.If there are non-whitespace characters before the first newline, then it is not suppressed.
- Parameters:
s
- text which is to be emitted by the output scriptsuppressEol
- if true, remove the beginning whitespace and newline, if it exists.- Returns:
- the supplied string, with the first newline conditionally removed
-