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`, `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

## Nested Class Summary

## Nested classes/interfaces inherited from class org.mozilla.javascript.TopLevel

`org.mozilla.javascript.TopLevel.Builtins`

## Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject

`org.mozilla.javascript.ScriptableObject.KeyComparator`

## Field Summary

### Fields inherited from class org.mozilla.javascript.ScriptableObject

`CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST`

### Fields inherited from interface org.mozilla.javascript.Scriptable

`NOT_FOUND`

## Constructor Summary

Constructors
Constructor
Description
`GlobalObject(RhinoCore core, Application app, boolean isThreadScope)`
Creates a new GlobalObject object.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`authenticate(String user, String pwd)`
`void`
`clearChangeSet()`
Clear the set of changed properties.
`Object`
`createSkin(String str)`
Create a Skin object from a string
`void`
`defineLibraryScope(String name)`
Deprecated.
should be implemented in JavaScript instead
`Object`
`definePrototype(String name, org.mozilla.javascript.Scriptable desc)`
`static Object`
`deserialize(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)`
Read a previously serialized JavaScript object from a file.
`static Object`
`dontEnum(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)`
Set DONTENUM attrubutes on the given properties in this object.
`String`
`format(Object obj)`
`String`
`formatParagraphs(Object obj)`
`Object`
`get(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".
`Set`
`getChangeSet()`
Returns a set containing the names of properties changed since the last time startRecording() was called.
`String`
`getClassName()`
Get the global object's class name
`Object`
`getDBConnection(String dbsource)`
Get a Helma DB connection specified in db.properties
`Object`
`getHtmlDocument(Object src)`
Try to parse an object to a XML DOM tree.
`String`
`getProperty(String propname, Object defvalue)`
`Object`
`getURL(String location, Object condition, Object timeout)`
Retrieve a Document from the specified URL.
`Object`
`getXmlDocument(Object src)`
Try to parse an object to a XML DOM tree.
`void`
`init()`
Initializes the global object.
`void`
`put(String name, org.mozilla.javascript.Scriptable start, Object value)`
Override ScriptableObject.put() to implement PropertyRecorder interface and to synchronize method.
`boolean`
`renderSkin(Object skinobj, Object paramobj)`
`String`
`renderSkinAsString(Object skinobj, Object paramobj)`
`static void`
`seal(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, 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, Object[] args, org.mozilla.javascript.Function funObj)`
Serialize a JavaScript object to a file.
`void`
`startRecording()`
Tell this PropertyRecorder to start recording changes to properties
`void`
`stopRecording()`
Tell this PropertyRecorder to stop recording changes to properties
`Object`
`toJava(Object obj)`
Convert an object into a wrapper that exposes the java methods of the object to JavaScript.
`String`
`toString()`
`Object`
`unwrapJavaMap(Object obj)`
Unwrap a map previously wrapped using `wrapJavaMap(Object)`.
`Object`
`wrapJavaMap(Object obj)`
Wrap a java.util.Map so that it looks and behaves like a native JS object
`void`
`write(String str)`
`void`
`writeln(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, ensureType, ensureType, exportAsJSClass, fillConstructorProperties, findInstanceIdInfo, findInstanceIdInfo, findPrototypeId, get, getAttributes, getAttributes, getInstanceIdName, getInstanceIdValue, getMaxInstanceId, getOwnPropertyDescriptor, has, hasPrototypeMap, 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, checkPropertyChangeForSlot, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### GlobalObject

public GlobalObject(RhinoCore core, Application app, boolean isThreadScope)
Creates a new GlobalObject object.

Parameters:
  `core` - ...
  `app` - ...

## Method Details

### init

public void init()
Initializes the global object. This is only done for the shared global objects not the per-thread ones.

### getClassName

public String getClassName()
Get the global object's class name

Specified by:
  `getClassName` in interface `org.mozilla.javascript.Scriptable`
Overrides:
  `getClassName` in class `org.mozilla.javascript.ImporterTopLevel`
Returns:
  the class name for the global object

### put

public void put(String name, org.mozilla.javascript.Scriptable start, Object value)
Override ScriptableObject.put() to implement PropertyRecorder interface and to synchronize method.

Specified by:
  `put` in interface `org.mozilla.javascript.Scriptable`
Overrides:
  `put` in class `org.mozilla.javascript.IdScriptableObject`
Parameters:
  `name` -
  `start` -
  `value` -

### get

public Object get(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 interface `org.mozilla.javascript.Scriptable`
Overrides:
  `get` in class `org.mozilla.javascript.ImporterTopLevel`
Parameters:
  `name` -
  `start` -
Returns:
  the property for the given name

### renderSkin

public boolean renderSkin(Object skinobj, Object paramobj) throws UnsupportedEncodingException, IOException

Parameters:
  `skinobj` - ...
  `paramobj` - ...
Returns:
  ...
Throws:
  `UnsupportedEncodingException`
  `IOException`

### renderSkinAsString

public String renderSkinAsString(Object skinobj, Object paramobj) throws UnsupportedEncodingException, IOException

Parameters:
  `skinobj` - ...
  `paramobj` - ...
Returns:
  ...
Throws:
  `UnsupportedEncodingException`
  `IOException`

### getProperty

public String getProperty(String propname, Object defvalue)

Parameters:
  `propname` - ...
  `defvalue` - ...
Returns:
  ...

### authenticate

public boolean authenticate(String user, String pwd)

Parameters:
  `user` - ...
  `pwd` - ...
Returns:
  ...

### createSkin

public Object createSkin(String str)
Create a Skin object from a string

Parameters:
  `str` - the source string to parse
Returns:
  a parsed skin object

### getDBConnection

public Object getDBConnection(String dbsource) throws Exception
Get a Helma DB connection specified in db.properties

Parameters:
  `dbsource` - the db source name
Returns:
  a DatabaseObject for the specified DbConnection
Throws:
  `Exception`

### getURL

public Object getURL(String location, Object condition, Object timeout)
Retrieve a Document from the specified URL.

Parameters:
  `location` - the URL to retrieve
  `condition` - either a LastModified date or an ETag string for conditional GETs
  `timeout` - the optional timeout value in milliseconds used for connecting to and reading from the given URL.
Returns:
  a wrapped MIME object

### getXmlDocument

public Object getXmlDocument(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 Object getHtmlDocument(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(String name)
Deprecated.
should be implemented in JavaScript instead
Creates a libary namespace in the global scope.

Parameters:
  `name` - the name of the libary namespace

### wrapJavaMap

public Object wrapJavaMap(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 Object unwrapJavaMap(Object obj)
Unwrap a map previously wrapped using `wrapJavaMap(Object)`.

Parameters:
  `obj` - the wrapped map
Returns:
  the map exposed as java object

### toJava

public Object toJava(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 String format(Object obj)

Parameters:
  `obj` - ...
Returns:
  ...

### formatParagraphs

public String formatParagraphs(Object obj)

Parameters:
  `obj` - ...
Returns:
  ...

### write

public void write(String str)

Parameters:
  `str` - ...

### writeln

public void writeln(String str)

Parameters:
  `str` - ...

### seal

public static void seal(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, 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, Object[] args, org.mozilla.javascript.Function funObj) throws IOException
Serialize a JavaScript object to a file.

Throws:
  `IOException`

### deserialize

public static Object deserialize(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj) throws IOException, ClassNotFoundException
Read a previously serialized JavaScript object from a file.

Throws:
  `IOException`
  `ClassNotFoundException`

### dontEnum

public static Object dontEnum(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, 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 Object definePrototype(String name, org.mozilla.javascript.Scriptable desc)

### startRecording

public void startRecording()
Tell this PropertyRecorder to start recording changes to properties

Specified by:
  `startRecording` in interface `PropertyRecorder`

### stopRecording

public void stopRecording()
Tell this PropertyRecorder to stop recording changes to properties

Specified by:
  `stopRecording` in interface `PropertyRecorder`

### getChangeSet

public Set getChangeSet()
Returns a set containing the names of properties changed since the last time startRecording() was called.

Specified by:
  `getChangeSet` in interface `PropertyRecorder`
Returns:
  a Set containing the names of changed properties

### clearChangeSet

public void clearChangeSet()
Clear the set of changed properties.

Specified by:
  `clearChangeSet` in interface `PropertyRecorder`

### toString

public String toString()

Overrides:
  `toString` in class `Object`