Class ScriptableResource
- java.lang.Object
-
- org.mozilla.javascript.ScriptableObject
-
- org.apache.sling.scripting.javascript.wrapper.ScriptableResource
-
- All Implemented Interfaces:
Serializable
,SlingWrapper
,org.mozilla.javascript.ConstProperties
,org.mozilla.javascript.debug.DebuggableObject
,org.mozilla.javascript.Scriptable
,org.mozilla.javascript.Wrapper
public class ScriptableResource extends org.mozilla.javascript.ScriptableObject implements SlingWrapper
Resource in JavaScript has following signature:- [String] getName()
- [String] name
- [Object] getResourceMetadata()
- [Object] resourceMetadata
- [String] getPath()
- [String] path
- [String] getResourceType()
- [String] resourceType
- [String] getResourceSuperType()
- [String] resourceSuperType
- [Resource] getParent()
- [Resource] parent
- [ResourceResolver] getResourceResolver()
- [ResourceResolver] resourceResolver
- [Resource] getChild(String)
- [Resource[]] getChildren()
- [Resource[]] listChildren()
- [Boolean] isResourceType(String)
- [Object] properties
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ScriptableResource()
ScriptableResource(org.apache.sling.api.resource.Resource resource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
getClassName()
The name of the JavaScript host object "class".Object
getDefaultValue(Class typeHint)
Class<?>[]
getWrappedClasses()
The list of Java classes wrapped by this wrapper.void
jsConstructor(Object res)
static Object
jsFunction_adaptTo(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
Implements the adaptTo() method for JavaScript scripts.Object
jsFunction_getChild(String childPath)
Maps getChild(String childPath) to getChild method.org.mozilla.javascript.NativeArray
jsFunction_getChildren()
Object
jsFunction_getMetadata()
Deprecated.since 2.1.0 because the method is named incorrectly.String
jsFunction_getName()
Object
jsFunction_getObject()
Object
jsFunction_getParent()
String
jsFunction_getPath()
Object
jsFunction_getResourceMetadata()
Object
jsFunction_getResourceResolver()
String
jsFunction_getResourceSuperType()
String
jsFunction_getResourceType()
boolean
jsFunction_isResourceType(String type)
org.mozilla.javascript.NativeArray
jsFunction_listChildren()
Object
jsGet_meta()
Deprecated.since 2.1.0 because it maps the method name incorrectly.String
jsGet_name()
Object
jsGet_parent()
String
jsGet_path()
Object
jsGet_properties()
Object
jsGet_resourceMetadata()
Object
jsGet_resourceResolver()
String
jsGet_resourceSuperType()
String
jsGet_resourceType()
String
jsGet_type()
Deprecated.since 2.1.0 because it maps the method name incorrectly.void
setResource(org.apache.sling.api.resource.Resource entry)
Object
unwrap()
-
Methods inherited from class org.mozilla.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, equivalentValues, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasInstance, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
-
-
-
-
Field Detail
-
CLASSNAME
public static final String CLASSNAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
jsConstructor
public void jsConstructor(Object res)
-
jsGet_name
public String jsGet_name()
-
jsFunction_getName
public String jsFunction_getName()
-
jsGet_path
public String jsGet_path()
-
jsFunction_getPath
public String jsFunction_getPath()
-
jsGet_type
@Deprecated public String jsGet_type()
Deprecated.since 2.1.0 because it maps the method name incorrectly.Maps getResourceType() to type property. This property is deprecated since it does not correctly map the getResourceType() method name to a property.- Returns:
- the resource type
-
jsGet_resourceType
public String jsGet_resourceType()
-
jsFunction_getResourceType
public String jsFunction_getResourceType()
-
jsFunction_listChildren
public org.mozilla.javascript.NativeArray jsFunction_listChildren()
-
jsFunction_getChildren
public org.mozilla.javascript.NativeArray jsFunction_getChildren()
-
jsGet_parent
public Object jsGet_parent()
-
jsFunction_getParent
public Object jsFunction_getParent()
-
jsGet_resourceSuperType
public String jsGet_resourceSuperType()
-
jsFunction_getResourceSuperType
public String jsFunction_getResourceSuperType()
-
jsFunction_isResourceType
public boolean jsFunction_isResourceType(String type)
-
jsGet_meta
@Deprecated public Object jsGet_meta()
Deprecated.since 2.1.0 because it maps the method name incorrectly.Maps getResourceMetadata() to meta property. This property is deprecated since it does not correctly map the getResourceType() method name to a property.- Returns:
- the resource metadata
-
jsGet_resourceMetadata
public Object jsGet_resourceMetadata()
-
jsFunction_getMetadata
@Deprecated public Object jsFunction_getMetadata()
Deprecated.since 2.1.0 because the method is named incorrectly.Maps getResourceMetadata() to getMetadata() method. This method is deprecated since it has the wrong name to support the getResourceMetadata() method.- Returns:
- the resource metadata
-
jsFunction_getResourceMetadata
public Object jsFunction_getResourceMetadata()
-
jsFunction_getResourceResolver
public Object jsFunction_getResourceResolver()
-
jsGet_resourceResolver
public Object jsGet_resourceResolver()
-
jsFunction_getChild
public Object jsFunction_getChild(String childPath)
Maps getChild(String childPath) to getChild method.- Parameters:
childPath
- the child path- Returns:
- the child resource if one exists at
childPath
ornull
-
jsFunction_getObject
public Object jsFunction_getObject()
-
jsFunction_adaptTo
public static Object jsFunction_adaptTo(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
Implements the adaptTo() method for JavaScript scripts. This method takes either a java.lang.Class object or a String containing the fully qualified name of the class to adapt to.Supporting String as an argument to this method allows for much easier use in JavaScript since instead of for example writing "javax.jcr.Node" instead of the much clumsier Packages.javax.jcr.Node.
- Parameters:
cx
- The current Rhino contextthisObj
- The ScriptableResource object in which the method is called.args
- The argument vector. Only the first argument is used which is expected to be a Class object or a String. If no argument is supplied or it has the wrong type, this method just returnsnull
.funObj
- The object representing the JavaScript adaptTo function.- Returns:
- The object to which the resource adapts or
null
if the resource does not adapt to the required type or if the argument is of the wrong type or missing.
-
jsGet_properties
public Object jsGet_properties()
-
getClassName
public String getClassName()
Description copied from interface:SlingWrapper
The name of the JavaScript host object "class".- Specified by:
getClassName
in interfaceorg.mozilla.javascript.Scriptable
- Specified by:
getClassName
in interfaceSlingWrapper
- Specified by:
getClassName
in classorg.mozilla.javascript.ScriptableObject
- Returns:
- the class name
-
getDefaultValue
public Object getDefaultValue(Class typeHint)
- Specified by:
getDefaultValue
in interfaceorg.mozilla.javascript.Scriptable
- Overrides:
getDefaultValue
in classorg.mozilla.javascript.ScriptableObject
-
setResource
public void setResource(org.apache.sling.api.resource.Resource entry)
-
getWrappedClasses
public Class<?>[] getWrappedClasses()
Description copied from interface:SlingWrapper
The list of Java classes wrapped by this wrapper.- Specified by:
getWrappedClasses
in interfaceSlingWrapper
- Returns:
- the wrapped classes
-
unwrap
public Object unwrap()
- Specified by:
unwrap
in interfaceorg.mozilla.javascript.Wrapper
-
-