private static String toPatternString(ScriptObjectMirror mirror) { return mirror.to(String.class); } }
@Override public void injectInto(NashornEngine nashornEngine) { final Set<List<String>> includedScripts = new HashSet<>(); nashornEngine.put("include", (Consumer<ScriptObjectMirror>) args -> { final String[] arguments = args.to(String[].class); final String script = scriptFetcher.getScript(arguments); if (script == null) { throwException(new ScriptException(Arrays.asList(arguments).toString() + " is not found")); } if (includedScripts.add(Arrays.asList(arguments))) { nashornEngine.eval("//# sourceURL=" + Arrays.asList(arguments).toString() + "\n" + script, this::throwException); } }, this::throwException); } }
@SuppressWarnings("unchecked") private Collection<String> deps(ProcessKey processKey, Map<String, Object> req) { Object o = req.get(InternalConstants.Request.DEPENDENCIES_KEY); if (o == null) { return null; } if (o instanceof Collection) { return (Collection<String>) o; } if (o instanceof ScriptObjectMirror) { ScriptObjectMirror m = (ScriptObjectMirror) o; if (!m.isArray()) { logManager.error(processKey, "Invalid dependencies object type. Expected a JavaScript array, got: " + m); throw new ProcessException(processKey, "Invalid dependencies object type. Expected a JavaScript array, got: " + m); } String[] as = m.to(String[].class); return Arrays.asList(as); } logManager.error(processKey, "Invalid dependencies object type. Expected an array or a collection, got: " + o.getClass()); throw new ProcessException(processKey, "Invalid dependencies object type. Expected an array or a collection, got: " + o.getClass()); } }
private String[] extractPossibleOutcomes(JsAuthenticationContext context, Object possibleOutcomesObj) { String[] possibleOutcomes; if (possibleOutcomesObj instanceof String[]) { possibleOutcomes = (String[]) possibleOutcomesObj; } else if (possibleOutcomesObj instanceof ScriptObjectMirror) { if (((ScriptObjectMirror) possibleOutcomesObj).isArray()) { possibleOutcomes = ((ScriptObjectMirror) possibleOutcomesObj).to(String[].class); } else { log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() .getServiceProviderName() + ". Expected array of strings."); possibleOutcomes = new String[0]; } } else { log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() .getServiceProviderName() + ". Expected array of strings."); possibleOutcomes = new String[0]; } return possibleOutcomes; }
private String[] extractPossibleOutcomes(JsAuthenticationContext context, Object possibleOutcomesObj) { String[] possibleOutcomes; if (possibleOutcomesObj instanceof String[]) { possibleOutcomes = (String[]) possibleOutcomesObj; } else if (possibleOutcomesObj instanceof ScriptObjectMirror) { if (((ScriptObjectMirror) possibleOutcomesObj).isArray()) { possibleOutcomes = ((ScriptObjectMirror) possibleOutcomesObj).to(String[].class); } else { log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() .getServiceProviderName() + ". Expected array of strings."); possibleOutcomes = new String[0]; } } else { log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() .getServiceProviderName() + ". Expected array of strings."); possibleOutcomes = new String[0]; } return possibleOutcomes; }
/** * Compile the given HTML template to JS functions using vue-template-compiler. * * @param htmlTemplate The HTML Component template to compile * @return An object containing the render functions * @throws VueTemplateCompilerException If the compilation fails */ public VueTemplateCompilerResult compile(String htmlTemplate) throws VueTemplateCompilerException { ScriptObjectMirror templateCompilerResult; try { templateCompilerResult = (ScriptObjectMirror) engine.invokeFunction("compile", htmlTemplate); } catch (ScriptException | NoSuchMethodException e) { e.printStackTrace(); throw new VueTemplateCompilerException( "An error occurred while compiling the template: " + htmlTemplate + " -> " + e.getMessage()); } String renderFunction = (String) templateCompilerResult.get("render"); String[] staticRenderFunctions = ((ScriptObjectMirror) templateCompilerResult.get("staticRenderFns")).to(String[].class); return new VueTemplateCompilerResult(renderFunction, staticRenderFunctions); } }
protected Object getIndexedListValue(Map<String, Object> map, String name, boolean throwIfNoList) { Object value = null; String prop = getListKeyName(name); Object val = getValue(map, prop); if (!(val instanceof List) && val instanceof ScriptObjectMirror) { ScriptObjectMirror mirror = (ScriptObjectMirror) val; if (mirror.isArray()) { val = mirror.to(List.class); } } if (val instanceof List) { List list = (List) val; int index = getListIndex(name); if (index < list.size()) { value = list.get(index); } else { value = null; } } else { if (val != null || throwIfNoList) { throw new SlimFixtureException(false, prop + " is not a list, but " + val); } } return value; }
ScriptObjectMirror jsArray = jsScriptEngine.newJSArray(); @SuppressWarnings("unchecked") List<Object> mrefValues = jsArray.to(List.class); entity .getEntities(attrName)