if (!UserSecurity.hasPermission(SystemPermission.javaScriptCoding))
throw new SecurityException("User is not permitted to execute code on the server");
return cx.evaluateString(GlobalData.getGlobalScope(), (String) args[0], "console", 0, null);
}
});
BaseFunction putHandler = new PersevereNativeFunction() {
@Override
public Object call(final Context cx, final Scriptable scope,
final Scriptable thisObj, Object[] args) {
// check to make sure all the objects are valid after a schema change
// TODO: The performance of this could be greatly improved with more information from the put
PersistableClass schema = (PersistableClass) thisObj;
if (schema != null) {
Object propertiesDefinitions = schema.get("properties");
if (propertiesDefinitions instanceof Persistable && schema.getPrototypeProperty() instanceof Persistable) {
Persistable prototype = (Persistable) schema.getPrototypeProperty();
for (Object key : prototype.getIds())
if (key instanceof String)
enforceSchemaForProperty(schema, prototype, (String) key, prototype.get((String) key), true, true, false);
List<Persistable> instances = (List) schema.get("instances");
Object[] propertyIds = ((Persistable)propertiesDefinitions).getIds();
List<String> stringList = new ArrayList();
for (Object property : propertyIds){
if (property instanceof String)
stringList.add((String) property);
}
String[] stringKeys = new String[stringList.size()];
stringList.toArray(stringKeys);
for (String key : stringKeys) {
Object propertyDef = ((Persistable)propertiesDefinitions).get(key);
//TODO: Allow it to point to another a schema's properties object
if (propertyDef instanceof Persistable && !(propertyDef instanceof PersistableClass)) {
if (((Persistable)propertyDef).get("properties") instanceof Persistable)
throw new RuntimeException("Can not create an object validator that does not reference an existing schema");
}
}
if(Boolean.TRUE.equals(schema.get("checkAllInstancesOnSchemaChange", schema))) {
for (Persistable instance : instances){
for (String key : stringKeys) {
enforceSchemaForProperty(schema, instance, key, ScriptableObject.getProperty(instance, key), true, true, false);
}
}
}
}
}
return true;
}
public String toString() {
return "function(resource){/*native code*/}";
}
};
putHandler.put("source", putHandler, "function(){[Native code]}");
pjsLibrary.put("putHandler", pjsLibrary, putHandler);
putHandler.setPrototype(ScriptableObject.getFunctionPrototype(GlobalData.getGlobalScope()));
}