mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Refinements to Javascript/Freemarker Node conversions
- Removed hard-coded conversions from Web Scripts - example category search web script aligned with documentation git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5940 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -72,7 +72,7 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
private static final String SCRIPT_ROOT = "_root";
|
||||
|
||||
/** Base Value Converter */
|
||||
private ValueConverter valueConverter = new ReturnValueConverter();
|
||||
private ValueConverter valueConverter = new ValueConverter();
|
||||
|
||||
/** Store into which to resolve cm:name based script paths */
|
||||
private StoreRef storeRef;
|
||||
@@ -510,19 +510,7 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
Object result = cx.evaluateString(scope, script, "AlfrescoScript", 1, null);
|
||||
|
||||
// extract java object result if wrapped by Rhino
|
||||
if (result instanceof Serializable)
|
||||
{
|
||||
result = valueConverter.convertValueForRepo((Serializable)result);
|
||||
}
|
||||
else if (result instanceof Wrapper)
|
||||
{
|
||||
result = ((Wrapper)result).unwrap();
|
||||
}
|
||||
else if (result instanceof NativeArray)
|
||||
{
|
||||
result = Context.jsToJava(result, Object[].class);
|
||||
}
|
||||
|
||||
result = valueConverter.convertValueForRepo((Serializable)result);
|
||||
return result;
|
||||
}
|
||||
catch (Throwable err)
|
||||
@@ -564,30 +552,5 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
|
||||
}
|
||||
return newModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value conversion for handling Javascript return values.
|
||||
*/
|
||||
public class ReturnValueConverter extends ValueConverter
|
||||
{
|
||||
/**
|
||||
* Convert an object from any script wrapper value to a valid repository serializable value.
|
||||
* This includes converting JavaScript Array objects to Lists of valid objects.
|
||||
*
|
||||
* @param value Value to convert from script wrapper object to repo serializable value
|
||||
*
|
||||
* @return valid repo value
|
||||
*/
|
||||
public Serializable convertValueForRepo(Serializable value)
|
||||
{
|
||||
if (value instanceof Wrapper ||
|
||||
value instanceof ScriptableObject ||
|
||||
value instanceof Serializable[])
|
||||
{
|
||||
value = super.convertValueForRepo(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user