Package com.stimulsoft.base.parser
Class StiCSharpScriptParser
java.lang.Object
com.stimulsoft.base.parser.StiCSharpScriptParser
Parses and executes C# scripts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic interfacestatic classstatic classstatic classstatic classRepresents the position of a token in the script text. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanA value indicating whether the 'using' directive is allowed in the script.static booleanA value indicating whether type creation should be restricted to whitelist.static intThe maximum allowed size for array creation.static intThe maximum allowed number of iterations for loops (for, while, do-while, foreach).static intThe maximum allowed depth for recursion in method calls and expressions. -
Constructor Summary
ConstructorsConstructorDescriptionStiCSharpScriptParser(String scriptText) StiCSharpScriptParser(String scriptText, StiCSharpScriptParserOptions options) Initializes a new instance of the StiParser class.StiCSharpScriptParser(String script, ArrayList<StiToken> cachedTokens, ArrayList<StiCSharpScriptParser.TokenPosition> cachedPositions) StiCSharpScriptParser(String script, ArrayList<StiToken> cachedTokens, ArrayList<StiCSharpScriptParser.TokenPosition> cachedPositions, StiCSharpScriptParserOptions options) -
Method Summary
Modifier and TypeMethodDescriptionfinal Objectexecute()Starts the parsing and execution of the script.final Objectexecute(int timeoutMilliseconds) static ObjectInitializes a new instance of the StiParser class with the specified script text.final Objectfinal ClassGets the type of a variable by its name.final ObjectgetVariable(String name) Gets a variable value from the script or external variable provider.final BooleangetVariableAsBool(String name) Gets a variable value as a string from the script or external variable provider.final BigDecimalgetVariableAsDecimal(String name) Gets a variable value as a string from the script or external variable provider.final DoublegetVariableAsDouble(String name) Gets a variable value as a string from the script or external variable provider.final FloatgetVariableAsFloat(String name) Gets a variable value as a string from the script or external variable provider.final IntegergetVariableAsInt(String name) Gets a variable value as a string from the script or external variable provider.final LonggetVariableAsLong(String name) Gets a variable value as a string from the script or external variable provider.final voidregisterFunction(String name, Function<Object[], Object> function) Registers a custom function that can be called from the script.final voidregisterNamespace(String name) Registers a namespace that can be used from the script.final voidSets an external objects provider that can be used in the script.final voidsetExternalTypesCache(HashMap nameToType) final voidsetThisObject(Object thisObject) final voidsetVariable(String name, Object value) Sets a variable value that can be used in the script.
-
Field Details
-
allowUsingDirective
public static boolean allowUsingDirectiveA value indicating whether the 'using' directive is allowed in the script. -
allowUsingSecurityMode
public static boolean allowUsingSecurityModeA value indicating whether type creation should be restricted to whitelist. When true, only types from the whitelist can be instantiated. Default value is true for maximum security. -
maxArraySize
public static int maxArraySizeThe maximum allowed size for array creation. This limit prevents potential denial-of-service attacks through excessive memory allocation. Default value is 1,000,000 elements. Set to 0 to disable the limit (not recommended for security). -
maxLoopIterations
public static int maxLoopIterationsThe maximum allowed number of iterations for loops (for, while, do-while, foreach). This limit prevents potential denial-of-service attacks through infinite or very long loops. Default value is 1,000,000 iterations. Set to 0 to disable the limit (not recommended for security). -
maxRecursionDepth
public static int maxRecursionDepthThe maximum allowed depth for recursion in method calls and expressions. This limit prevents potential stack overflow attacks through deep recursion. Default value is 100 levels. Set to 0 to disable the limit (not recommended for security).
-
-
Constructor Details
-
StiCSharpScriptParser
-
StiCSharpScriptParser
Initializes a new instance of the StiParser class.- Parameters:
scriptText- The script text to parse and execute.
-
StiCSharpScriptParser
public StiCSharpScriptParser(String script, ArrayList<StiToken> cachedTokens, ArrayList<StiCSharpScriptParser.TokenPosition> cachedPositions) -
StiCSharpScriptParser
public StiCSharpScriptParser(String script, ArrayList<StiToken> cachedTokens, ArrayList<StiCSharpScriptParser.TokenPosition> cachedPositions, StiCSharpScriptParserOptions options)
-
-
Method Details
-
getResult
-
execute
Initializes a new instance of the StiParser class with the specified script text.- Parameters:
script-- Returns:
-
execute
Starts the parsing and execution of the script.- Returns:
- The result of the script execution.
-
execute
-
setThisObject
-
setExternalObjectsProvider
public final void setExternalObjectsProvider(StiCSharpScriptParser.IExternalObjectsProvider provider) Sets an external objects provider that can be used in the script. -
registerFunction
Registers a custom function that can be called from the script.- Parameters:
name- The function name.function- The function implementation.
-
registerNamespace
Registers a namespace that can be used from the script.- Parameters:
name- The namespace name.
-
getTokens
-
getTokenPositions
-
GetType
Gets the type of a variable by its name. -
setExternalTypesCache
-
setVariable
Sets a variable value that can be used in the script.- Parameters:
name- The variable name.
-
getVariable
Gets a variable value from the script or external variable provider. -
getVariableAsBool
Gets a variable value as a string from the script or external variable provider. -
getVariableAsInt
Gets a variable value as a string from the script or external variable provider. -
getVariableAsLong
Gets a variable value as a string from the script or external variable provider. -
getVariableAsFloat
Gets a variable value as a string from the script or external variable provider. -
getVariableAsDouble
Gets a variable value as a string from the script or external variable provider. -
getVariableAsDecimal
Gets a variable value as a string from the script or external variable provider.
-