private Scriptable convertArray(final JSONArray array) throws JSONException { final Scriptable result = context.newArray(scope, array.length()); for (int i = 0, max = array.length(); i < max; i++) { ScriptableObject.putProperty(result, i, convert(array.get(i))); } return result; }
public class RJsDemo { @Test public void simpleRhinoTest() throws FileNotFoundException, IOException { Context cx = Context.enter(); final JsRuntimeSupport browserSupport = new JsRuntimeSupport(); final ScriptableObject sharedScope = cx.initStandardObjects(browserSupport, true); String[] names = { "print", "load" }; sharedScope.defineFunctionProperties(names, sharedScope.getClass(), ScriptableObject.DONTENUM); Scriptable argsObj = cx.newArray(sharedScope, new Object[] {}); sharedScope.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); cx.evaluateReader(sharedScope, new FileReader("./r.js"), "require", 1, null); cx.evaluateReader(sharedScope, new FileReader("./loader.js"), "loader", 1, null); Context.exit(); } }
public static Object toJSON(Context context, Scriptable thisObj, Object[] args, Function fn) { return context.newArray(thisObj, (((MyScriptableList) thisObj).list).toArray()); } }
/** * creates a new javascript array * @param size the size of the array * @return an empty array of the given size */ public Scriptable jsNewArray(long size) { return getContext().newArray(scope, (int)size); }
@Override public Object call(Context cx2, Scriptable scope2, Scriptable thisObj2, Object[] args2) { String[] list = file.list(); if ( list == null ) { return callback.call(cx, scope, thisObj, new Object[] {null, Undefined.instance}); } Object[] objects = new Object[list.length]; System.arraycopy(list, 0, objects, 0, list.length); return callback.call(cx, scope, thisObj, new Object[] {null, cx.newArray(scope, objects)}); } });
/** * @return Array of permissions applied directly to this Node (does not include inherited). * Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION for example * ALLOWED;kevinr;Consumer so can be easily tokenized on the ';' character. */ public Scriptable getDirectPermissions() { return Context.getCurrentContext().newArray(this.scope, retrieveAllSetPermissions(true, false)); }
private static void match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl) { if (mdata.arrayobj == null) { mdata.arrayobj = cx.newArray(scope, 0); } SubString matchsub = reImpl.lastMatch; String matchstr = matchsub.toString(); mdata.arrayobj.put(count, mdata.arrayobj, matchstr); }
private Object toScriptable( ScriptableDelegate[] list ) { Object[] delegates = new Object[ list.length ]; for (int i = 0; i < delegates.length; i++) { delegates[i] = toScriptable( list[i] ); } return Context.getCurrentContext().newArray( this, delegates ); }
private static void match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl) { if (mdata.arrayobj == null) { mdata.arrayobj = cx.newArray(scope, 0); } SubString matchsub = reImpl.lastMatch; String matchstr = matchsub.toString(); mdata.arrayobj.put(count, mdata.arrayobj, matchstr); }
private Object toScriptable( ScriptableDelegate[] list ) { Object[] delegates = new Object[ list.length ]; for (int i = 0; i < delegates.length; i++) { delegates[i] = toScriptable( list[i] ); } return Context.getCurrentContext().newArray( this, delegates ); }
/** * @return Returns a JavaScript array of Nodes at the specified XPath starting at this Node. * So a valid call might be <code>mynode.childrenByXPath("*[@cm:name='Testing']/*");</code> */ public Scriptable childrenByXPath(String xpath) { return Context.getCurrentContext().newArray(this.scope, getChildrenByXPath(xpath, null, false)); }
private static void match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl) { if (mdata.arrayobj == null) { mdata.arrayobj = cx.newArray(scope, 0); } SubString matchsub = reImpl.lastMatch; String matchstr = matchsub.toString(); mdata.arrayobj.put(count, mdata.arrayobj, matchstr); }
private static void match_glob(GlobData mdata, Context cx, Scriptable scope, int count, RegExpImpl reImpl) { if (mdata.arrayobj == null) { mdata.arrayobj = cx.newArray(scope, 0); } SubString matchsub = reImpl.lastMatch; String matchstr = matchsub.toString(); mdata.arrayobj.put(count, mdata.arrayobj, matchstr); }
private Object toScriptable( ScriptableDelegate[] list ) { Object[] delegates = new Object[ list.length ]; for (int i = 0; i < delegates.length; i++) { delegates[i] = toScriptable( list[i] ); } return Context.getCurrentContext().newArray( this, delegates ); }
/** * @return Array of all permissions applied to this Node, including inherited. * Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION;[INHERITED|DIRECT] * for example: ALLOWED;kevinr;Consumer;DIRECT so can be easily tokenized on the ';' character. */ public Scriptable getFullPermissions() { return Context.getCurrentContext().newArray(this.scope, retrieveAllSetPermissions(false, true)); }
public Scriptable getPeoplePaging(String filter, ScriptPagingDetails pagingRequest, String sortBy, Boolean sortAsc) { List<PersonInfo> persons = getPeopleImpl(filter, pagingRequest, sortBy, sortAsc); Object[] peopleRefs = new Object[persons.size()]; for (int i = 0; i < peopleRefs.length; i++) { peopleRefs[i] = persons.get(i).getNodeRef(); } return Context.getCurrentContext().newArray(getScope(), peopleRefs); }
/** * @return Array of settable permissions for this Node */ public Scriptable getSettablePermissions() { Set<String> permissions = this.services.getPermissionService().getSettablePermissions(getNodeRef()); Object[] result = permissions.toArray(new Object[0]); return Context.getCurrentContext().newArray(this.scope, result); }
/** * @return Array of settable permissions for this Node */ public Scriptable getSettablePermissions() { Set<String> permissions = this.services.getPermissionService().getSettablePermissions(getNodeRef()); Object[] result = permissions.toArray(new Object[0]); return Context.getCurrentContext().newArray(this.scope, result); }
/** * Find all the category nodes in a given classification. * * @param aspect String * @return Scriptable */ public Scriptable getAllCategoryNodes(String aspect) { Object[] cats = buildCategoryNodes(services.getCategoryService().getCategories( storeRef, createQName(aspect), CategoryService.Depth.ANY)); return Context.getCurrentContext().newArray(getScope(), cats); }
/** * Get the root categories in a classification. * * @param aspect String * @return Scriptable */ public Scriptable getRootCategories(String aspect) { Object[] cats = buildCategoryNodes(services.getCategoryService().getRootCategories( storeRef, createQName(aspect))); return Context.getCurrentContext().newArray(getScope(), cats); }