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:
  • Field Details

  • Constructor Details

    • ScriptableResource

      public ScriptableResource()
    • ScriptableResource

      public ScriptableResource(Resource resource)
  • Method Details

    • 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 or null
    • 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 context
      thisObj - 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 returns null.
      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 interface org.mozilla.javascript.Scriptable
      Specified by:
      getClassName in interface SlingWrapper
      Specified by:
      getClassName in class org.mozilla.javascript.ScriptableObject
      Returns:
      the class name
    • getDefaultValue

      public Object getDefaultValue(Class typeHint)
      Specified by:
      getDefaultValue in interface org.mozilla.javascript.Scriptable
      Overrides:
      getDefaultValue in class org.mozilla.javascript.ScriptableObject
    • setResource

      public void setResource(Resource entry)
    • getWrappedClasses

      public Class<?>[] getWrappedClasses()
      Description copied from interface: SlingWrapper
      The list of Java classes wrapped by this wrapper.
      Specified by:
      getWrappedClasses in interface SlingWrapper
      Returns:
      the wrapped classes
    • unwrap

      public Object unwrap()
      Specified by:
      unwrap in interface org.mozilla.javascript.Wrapper