Java Code Examples for org.mozilla.javascript.ScriptableObject#get()
The following examples show how to use
org.mozilla.javascript.ScriptableObject#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JscriptWorkflowDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Helper to extract a map of properties from a scriptable object (generally an associative array) * * @param scriptable The scriptable object to extract name/value pairs from. * @param map The map to add the converted name/value pairs to. */ private void extractScriptablePropertiesToMap(ScriptableObject scriptable, Map<QName, Serializable> map) { // get all the keys to the provided properties // and convert them to a Map of QName to Serializable objects Object[] propIds = scriptable.getIds(); for (int i = 0; i < propIds.length; i++) { // work on each key in turn Object propId = propIds[i]; // we are only interested in keys that are formed of Strings i.e. QName.toString() if (propId instanceof String) { // get the value out for the specified key - it must be Serializable String key = (String)propId; Object value = scriptable.get(key, scriptable); if (value instanceof Serializable) { value = getValueConverter().convertValueForRepo((Serializable)value); map.put(createQName(key), (Serializable)value); } } } }
Example 2
Source File: ScriptNode.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Extract a map of properties from a scriptable object (generally an associative array) * * @param scriptable The scriptable object to extract name/value pairs from. * @param map The map to add the converted name/value pairs to. */ private void extractScriptableProperties(ScriptableObject scriptable, Map<QName, Serializable> map) { // we need to get all the keys to the properties provided // and convert them to a Map of QName to Serializable objects Object[] propIds = scriptable.getIds(); for (int i = 0; i < propIds.length; i++) { // work on each key in turn Object propId = propIds[i]; // we are only interested in keys that are formed of Strings i.e. QName.toString() if (propId instanceof String) { // get the value out for the specified key - it must be Serializable String key = (String)propId; Object value = scriptable.get(key, scriptable); if (value instanceof Serializable) { value = getValueConverter().convertValueForRepo((Serializable)value); map.put(createQName(key), (Serializable)value); } } } }
Example 3
Source File: JavascriptTemplate.java From manifold with Apache License 2.0 | 6 votes |
@SuppressWarnings("unused") public static String renderToStringImpl( ScriptableObject scope, JSTNode templateNode, Object... args ) { try { //make argument list including the raw string list Object[] argsWithStrings = Arrays.copyOf( args, args.length + 1 ); List rawStrings = templateNode.getChildren( RawStringNode.class ) .stream() .map( node -> node.genCode() ) .collect( Collectors.toList() ); argsWithStrings[argsWithStrings.length - 1] = rawStrings; Function renderToString = (Function)scope.get( "renderToString", scope ); return (String)renderToString.call( Context.getCurrentContext(), scope, scope, argsWithStrings ); } catch( Exception e ) { throw new RuntimeException( e ); } }
Example 4
Source File: JsRuntime.java From manifold with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") public static <T> T invokeProg( ScriptableObject scope, String func, Object... args ) { try { Function renderToString = (Function)scope.get( func, scope ); //noinspection unchecked return (T)renderToString.call( Context.getCurrentContext(), scope, scope, args ); } catch( Exception e ) { throw new RuntimeException( e ); } }
Example 5
Source File: ScriptNode.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private String processTemplate(String template, NodeRef templateRef, ScriptableObject args) { Object person = (Object)scope.get("person", scope); Object companyhome = (Object)scope.get("companyhome", scope); Object userhome = (Object)scope.get("userhome", scope); // build default model for the template processing Map<String, Object> model = this.services.getTemplateService().buildDefaultModel( (person.equals(UniqueTag.NOT_FOUND)) ? null : ((ScriptNode)((Wrapper)person).unwrap()).getNodeRef(), (companyhome.equals(UniqueTag.NOT_FOUND)) ? null : ((ScriptNode)((Wrapper)companyhome).unwrap()).getNodeRef(), (userhome.equals(UniqueTag.NOT_FOUND)) ? null : ((ScriptNode)((Wrapper)userhome).unwrap()).getNodeRef(), templateRef, null); // add the current node as either the document/space as appropriate if (this.getIsDocument()) { model.put("document", this.nodeRef); model.put("space", getPrimaryParentAssoc().getParentRef()); } else { model.put("space", this.nodeRef); } // add the supplied args to the 'args' root object if (args != null) { // we need to get all the keys to the properties provided // and convert them to a Map of QName to Serializable objects Object[] propIds = args.getIds(); Map<String, String> templateArgs = new HashMap<String, String>(propIds.length); for (int i = 0; i < propIds.length; i++) { // work on each key in turn Object propId = propIds[i]; // we are only interested in keys that are formed of Strings i.e. QName.toString() if (propId instanceof String) { // get the value out for the specified key - make sure it is Serializable Object value = args.get((String) propId, args); value = getValueConverter().convertValueForRepo((Serializable)value); if (value != null) { templateArgs.put((String) propId, value.toString()); } } } // add the args to the model as the 'args' root object model.put("args", templateArgs); } // execute template! // TODO: check that script modified nodes are reflected... return this.services.getTemplateService().processTemplateString(null, template, model); }