Package helma.scripting.rhino
Class GlobalObject
- java.lang.Object
-
- org.mozilla.javascript.ScriptableObject
-
- org.mozilla.javascript.IdScriptableObject
-
- org.mozilla.javascript.TopLevel
-
- org.mozilla.javascript.ImporterTopLevel
-
- helma.scripting.rhino.GlobalObject
-
- All Implemented Interfaces:
PropertyRecorder
,java.io.Serializable
,org.mozilla.javascript.ConstProperties
,org.mozilla.javascript.debug.DebuggableObject
,org.mozilla.javascript.IdFunctionCall
,org.mozilla.javascript.Scriptable
,org.mozilla.javascript.SymbolScriptable
public class GlobalObject extends org.mozilla.javascript.ImporterTopLevel implements PropertyRecorder
Helma global object defines a number of custom global functions.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GlobalObject(RhinoCore core, Application app, boolean isThreadScope)
Creates a new GlobalObject object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
authenticate(java.lang.String user, java.lang.String pwd)
void
clearChangeSet()
Clear the set of changed properties.java.lang.Object
createSkin(java.lang.String str)
Create a Skin object from a stringvoid
defineLibraryScope(java.lang.String name)
Deprecated.should be implemented in JavaScript insteadjava.lang.Object
definePrototype(java.lang.String name, org.mozilla.javascript.Scriptable desc)
static java.lang.Object
deserialize(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj)
Read a previously serialized JavaScript object from a file.static java.lang.Object
dontEnum(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj)
Set DONTENUM attrubutes on the given properties in this object.java.lang.String
format(java.lang.Object obj)
java.lang.String
formatParagraphs(java.lang.Object obj)
java.lang.Object
get(java.lang.String name, org.mozilla.javascript.Scriptable start)
Override ScriptableObject.get() to use the per-thread scope if possible, and return the per-thread scope for "global".java.util.Set
getChangeSet()
Returns a set containing the names of properties changed since the last time startRecording() was called.java.lang.String
getClassName()
Get the global object's class namejava.lang.Object
getDBConnection(java.lang.String dbsource)
Get a Helma DB connection specified in db.propertiesjava.lang.Object
getHtmlDocument(java.lang.Object src)
Try to parse an object to a XML DOM tree.java.lang.String
getProperty(java.lang.String propname, java.lang.Object defvalue)
java.lang.Object
getURL(java.lang.String location, java.lang.Object condition, java.lang.Object timeout)
Retrieve a Document from the specified URL.java.lang.Object
getXmlDocument(java.lang.Object src)
Try to parse an object to a XML DOM tree.void
init()
Initializes the global object.void
put(java.lang.String name, org.mozilla.javascript.Scriptable start, java.lang.Object value)
Override ScriptableObject.put() to implement PropertyRecorder interface and to synchronize method.boolean
renderSkin(java.lang.Object skinobj, java.lang.Object paramobj)
java.lang.String
renderSkinAsString(java.lang.Object skinobj, java.lang.Object paramobj)
static void
seal(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj)
The seal function seals all supplied arguments.static void
serialize(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj)
Serialize a JavaScript object to a file.void
startRecording()
Tell this PropertyRecorder to start recording changes to propertiesvoid
stopRecording()
Tell this PropertyRecorder to stop recording changes to propertiesjava.lang.Object
toJava(java.lang.Object obj)
Convert an object into a wrapper that exposes the java methods of the object to JavaScript.java.lang.String
toString()
java.lang.Object
unwrapJavaMap(java.lang.Object obj)
Unwrap a map previously wrapped usingwrapJavaMap(Object)
.java.lang.Object
wrapJavaMap(java.lang.Object obj)
Wrap a java.util.Map so that it looks and behaves like a native JS objectvoid
write(java.lang.String str)
void
writeln(java.lang.String str)
-
Methods inherited from class org.mozilla.javascript.ImporterTopLevel
execIdCall, findPrototypeId, has, importPackage, init, initPrototypeId, initStandardObjects
-
Methods inherited from class org.mozilla.javascript.TopLevel
cacheBuiltins, getBuiltinCtor, getBuiltinCtor, getBuiltinPrototype, getBuiltinPrototype
-
Methods inherited from class org.mozilla.javascript.IdScriptableObject
activatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, defineOwnProperty, delete, delete, exportAsJSClass, fillConstructorProperties, findInstanceIdInfo, findInstanceIdInfo, findPrototypeId, get, getAttributes, getAttributes, getInstanceIdName, getInstanceIdValue, getMaxInstanceId, getOwnPropertyDescriptor, has, hasPrototypeMap, incompatibleCallError, initPrototypeConstructor, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, put, setAttributes, setInstanceIdAttributes, setInstanceIdValue
-
Methods inherited from class org.mozilla.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
-
-
-
-
Constructor Detail
-
GlobalObject
public GlobalObject(RhinoCore core, Application app, boolean isThreadScope)
Creates a new GlobalObject object.- Parameters:
core
- ...app
- ...
-
-
Method Detail
-
init
public void init()
Initializes the global object. This is only done for the shared global objects not the per-thread ones.
-
getClassName
public java.lang.String getClassName()
Get the global object's class name- Specified by:
getClassName
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
getClassName
in classorg.mozilla.javascript.ImporterTopLevel
- Returns:
- the class name for the global object
-
put
public void put(java.lang.String name, org.mozilla.javascript.Scriptable start, java.lang.Object value)
Override ScriptableObject.put() to implement PropertyRecorder interface and to synchronize method.- Specified by:
put
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
put
in classorg.mozilla.javascript.IdScriptableObject
- Parameters:
name
-start
-value
-
-
get
public java.lang.Object get(java.lang.String name, org.mozilla.javascript.Scriptable start)
Override ScriptableObject.get() to use the per-thread scope if possible, and return the per-thread scope for "global".- Specified by:
get
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
get
in classorg.mozilla.javascript.ImporterTopLevel
- Parameters:
name
-start
-- Returns:
- the property for the given name
-
renderSkin
public boolean renderSkin(java.lang.Object skinobj, java.lang.Object paramobj) throws java.io.UnsupportedEncodingException, java.io.IOException
- Parameters:
skinobj
- ...paramobj
- ...- Returns:
- ...
- Throws:
java.io.UnsupportedEncodingException
java.io.IOException
-
renderSkinAsString
public java.lang.String renderSkinAsString(java.lang.Object skinobj, java.lang.Object paramobj) throws java.io.UnsupportedEncodingException, java.io.IOException
- Parameters:
skinobj
- ...paramobj
- ...- Returns:
- ...
- Throws:
java.io.UnsupportedEncodingException
java.io.IOException
-
getProperty
public java.lang.String getProperty(java.lang.String propname, java.lang.Object defvalue)
- Parameters:
propname
- ...defvalue
- ...- Returns:
- ...
-
authenticate
public boolean authenticate(java.lang.String user, java.lang.String pwd)
- Parameters:
user
- ...pwd
- ...- Returns:
- ...
-
createSkin
public java.lang.Object createSkin(java.lang.String str)
Create a Skin object from a string- Parameters:
str
- the source string to parse- Returns:
- a parsed skin object
-
getDBConnection
public java.lang.Object getDBConnection(java.lang.String dbsource) throws java.lang.Exception
Get a Helma DB connection specified in db.properties- Parameters:
dbsource
- the db source name- Returns:
- a DatabaseObject for the specified DbConnection
- Throws:
java.lang.Exception
-
getURL
public java.lang.Object getURL(java.lang.String location, java.lang.Object condition, java.lang.Object timeout)
Retrieve a Document from the specified URL.- Parameters:
location
- the URL to retrievecondition
- either a LastModified date or an ETag string for conditional GETstimeout
- the optional timeout value in milliseconds used for connecting to and reading from the given URL.- Returns:
- a wrapped MIME object
-
getXmlDocument
public java.lang.Object getXmlDocument(java.lang.Object src)
Try to parse an object to a XML DOM tree. The argument must be either a URL, a piece of XML, an InputStream or a Reader.
-
getHtmlDocument
public java.lang.Object getHtmlDocument(java.lang.Object src)
Try to parse an object to a XML DOM tree. The argument must be either a URL, a piece of XML, an InputStream or a Reader.
-
defineLibraryScope
@Deprecated public void defineLibraryScope(java.lang.String name)
Deprecated.should be implemented in JavaScript insteadCreates a libary namespace in the global scope.- Parameters:
name
- the name of the libary namespace
-
wrapJavaMap
public java.lang.Object wrapJavaMap(java.lang.Object obj)
Wrap a java.util.Map so that it looks and behaves like a native JS object- Parameters:
obj
- a map- Returns:
- a wrapper that makes the map look like a JS object
-
unwrapJavaMap
public java.lang.Object unwrapJavaMap(java.lang.Object obj)
Unwrap a map previously wrapped usingwrapJavaMap(Object)
.- Parameters:
obj
- the wrapped map- Returns:
- the map exposed as java object
-
toJava
public java.lang.Object toJava(java.lang.Object obj)
Convert an object into a wrapper that exposes the java methods of the object to JavaScript. This is useful for treating native numbers, strings, etc as their java counterpart such as java.lang.Double, java.lang.String etc.- Parameters:
obj
- a java object that is wrapped in a special way Rhino- Returns:
- the object wrapped as NativeJavaObject, exposing the public methods of the underlying class.
-
format
public java.lang.String format(java.lang.Object obj)
- Parameters:
obj
- ...- Returns:
- ...
-
formatParagraphs
public java.lang.String formatParagraphs(java.lang.Object obj)
- Parameters:
obj
- ...- Returns:
- ...
-
write
public void write(java.lang.String str)
- Parameters:
str
- ...
-
writeln
public void writeln(java.lang.String str)
- Parameters:
str
- ...
-
seal
public static void seal(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj)
The seal function seals all supplied arguments.
-
serialize
public static void serialize(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj) throws java.io.IOException
Serialize a JavaScript object to a file.- Throws:
java.io.IOException
-
deserialize
public static java.lang.Object deserialize(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj) throws java.io.IOException, java.lang.ClassNotFoundException
Read a previously serialized JavaScript object from a file.- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
dontEnum
public static java.lang.Object dontEnum(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function funObj)
Set DONTENUM attrubutes on the given properties in this object. This is set on the JavaScript Object prototype.
-
definePrototype
public java.lang.Object definePrototype(java.lang.String name, org.mozilla.javascript.Scriptable desc)
-
startRecording
public void startRecording()
Tell this PropertyRecorder to start recording changes to properties- Specified by:
startRecording
in interfacePropertyRecorder
-
stopRecording
public void stopRecording()
Tell this PropertyRecorder to stop recording changes to properties- Specified by:
stopRecording
in interfacePropertyRecorder
-
getChangeSet
public java.util.Set getChangeSet()
Returns a set containing the names of properties changed since the last time startRecording() was called.- Specified by:
getChangeSet
in interfacePropertyRecorder
- Returns:
- a Set containing the names of changed properties
-
clearChangeSet
public void clearChangeSet()
Clear the set of changed properties.- Specified by:
clearChangeSet
in interfacePropertyRecorder
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-