Example usage for javax.script ScriptException printStackTrace

List of usage examples for javax.script ScriptException printStackTrace

Introduction

In this page you can find the example usage for javax.script ScriptException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:controllers.skilltag.SkillTagApp.java

@Transactional(readOnly = true)
public static Result list() {
    DynamicForm requestData = Form.form().bindFromRequest();
    String p = requestData.get("p") == null ? "1" : requestData.get("p");
    Long i = StringUtils.isBlank(requestData.get("i")) ? 2L : Long.parseLong(requestData.get("i"));
    String s = StringUtils.isBlank(requestData.get("s")) ? null : requestData.get("s");

    String cf = requestData.get("cf");
    String ssf = requestData.get("ssf");
    String ef = requestData.get("ef");
    String gf = requestData.get("gf");
    String o = requestData.get("o");
    String ot = requestData.get("ot");

    List<SkillTag> skillTags = SkillTag.getAll(i, 1, "all");

    List<TagListVo> ivs = new ArrayList<TagListVo>();
    List<TagListVo> svs = new ArrayList<TagListVo>();
    ScriptEngine engine = SemUtils.getEngine();
    try {/*from  www .  j  a  v  a2s .  com*/
        for (SkillTag st : skillTags) {
            TagListVo tv = new TagListVo();
            tv.setTagName(st.tagName);
            tv.setTagId(st.id);
            if (st.tagType != null && st.tagType.ordinal() == SkillTag.TagType.CATEGORY.ordinal()) {
                if (st.id.equals(i))
                    tv.setIsCurr(true);
                tv.setHref(controllers.skilltag.routes.SkillTagApp.list().url() + "?p=1&i=" + tv.getTagId());
                ivs.add(tv);
            } else {
                tv.setHref(controllers.skilltag.routes.SkillTagApp.list().url() + "?p=1&i=" + i + "&s="
                        + engine.eval("encodeURIComponent('" + tv.getTagName() + "')").toString());
                svs.add(tv);
            }
        }
        if (StringUtils.isNotBlank(s)) {
            TagListVo tv = new TagListVo();
            tv.setTagName(s);
            tv.setIsCurr(true);
            tv.setHref(controllers.skilltag.routes.SkillTagApp.list().url() + "?p=1&i=" + i + "&s="
                    + engine.eval("encodeURIComponent('" + tv.getTagName() + "')").toString());
            svs.add(0, tv);
        }
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    List<ExpertListVO> elv = getTagExperts(p, i, s, cf, ssf, ef, gf, o, ot);
    SPage spage = new SPage(Integer.parseInt(p), i, s, cf, ssf, ef, gf, o, ot, ivs, svs, elv);
    List<String> countryList = SkillTag.getCountryNameWithCache();
    spage.setCountryList(countryList);

    return ok(views.html.skilltag.skilltagall.render(spage));
}

From source file:controllers.ExpertApp.java

public static Result searchTag() {
    String st = request().getQueryString("st");
    String p = StringUtils.defaultIfBlank(request().getQueryString("p"), "1|1");
    String type = StringUtils.defaultIfBlank(request().getQueryString("type"), "html");
    ScriptEngine engine = SemUtils.getEngine();
    try {//  ww  w  .j av a 2  s  .  c om
        if (StringUtils.isNotBlank(st))
            st = engine.eval("decodeURIComponent('" + st + "')").toString();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    Transformer trf = new Transformer(st, p, null, null, null, null, null, null);
    String resultJson = SearchHttpClient.advancedQuery(trf.tranMustTagNVP());
    EPage<ExpertListVO> pageObj = trf.pageFromJson(resultJson, null, Constants.HOME_EXPERT_PAGE_SIZE);
    pageObj.setFt(st);
    if (!type.equals("json")) {
        return ok(views.html.expert.customerservice.render(pageObj));
    } else {
        return ok(play.libs.Json.toJson(pageObj));
    }
}

From source file:controllers.ExpertApp.java

@Transactional(readOnly = true)
public static Result search() {
    User user = User.getFromSession(session());
    DynamicForm requestData = Form.form().bindFromRequest();
    String p = requestData.get("p") == null ? "1|1" : requestData.get("p");
    String type = requestData.get("type") == null ? "html" : requestData.get("type");
    String ft = requestData.get("ft") == null ? "" : requestData.get("ft").trim();
    String cf = requestData.get("cf");
    String ssf = requestData.get("ssf");
    String ef = requestData.get("ef");
    String gf = requestData.get("gf");
    String o = requestData.get("o");
    String ot = requestData.get("ot");
    ScriptEngine engine = SemUtils.getEngine();
    try {//from w  w w .j av  a2  s  .c  o m
        if (StringUtils.isNotBlank(ft))
            ft = engine.eval("decodeURIComponent('" + ft + "')").toString();
        if (StringUtils.isNotBlank(cf))
            cf = engine.eval("decodeURIComponent('" + cf + "')").toString();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    Transformer trf = new Transformer(ft, p, cf, ssf, ef, gf, o, ot);
    String resultJson = SearchHttpClient.advancedQuery(trf.tranAdSearchNVP(Constants.HOME_EXPERT_PAGE_SIZE));
    EPage<ExpertListVO> pageObj = null;
    if (StringUtils.isNotBlank(resultJson))
        pageObj = trf.pageFromJson(resultJson, user, Constants.HOME_EXPERT_PAGE_SIZE);
    else
        pageObj = new EPage(null, 0L, 1, 1);

    pageObj.setCf(cf);
    pageObj.setEf(ef);
    pageObj.setFt(ft);
    pageObj.setGf(gf);
    pageObj.setO(o);
    pageObj.setOt(ot);
    pageObj.setSsf(ssf);

    List<String> countryList = SkillTag.getCountryNameWithCache();
    pageObj.setCountryList(countryList);

    if (!type.equals("json")) {
        return ok(views.html.expert.search.render(pageObj));
    } else {
        return ok(play.libs.Json.toJson(pageObj));
    }
}

From source file:org.siphon.common.js.JsEngineUtil.java

/**
 * /*  w w w  .j  a  v a 2  s. c o m*/
 * @param jsEngine
 * @param libs [path, path, ...]
 */
public static void initEngine(ScriptEngine jsEngine, Object[] libs) {
    try {
        jsEngine.put("engine", jsEngine);
        NashornScriptEngine nashornScriptEngine = (NashornScriptEngine) jsEngine;
        JsTypeUtil jsTypeUtil = new JsTypeUtil(jsEngine);
        ScriptObjectMirror importedFiles = jsTypeUtil.newObject();
        jsEngine.put("IMPORTED_FILES", importedFiles);

        ScriptObjectMirror stk = jsTypeUtil.newArray();
        jsEngine.put("IMPORTS_PATH_STACK", stk);

        ScriptObjectMirror defaults = (libs.length > 0 && libs[0] != null && libs[0] instanceof String
                && ((String) libs[0]).length() > 0) ? jsTypeUtil.newArray(libs) : jsTypeUtil.newArray();
        jsEngine.put("DEFAULT_IMPORTS_PATHS", defaults);

        jsEngine.put(ScriptEngine.FILENAME, "common/engine.js");
        jsEngine.eval(importsFn);
    } catch (ScriptException e) {
        e.printStackTrace();
    }
}

From source file:at.alladin.rmbt.qos.testscript.TestScriptInterpreter.java

/**
 * //from w  w  w  . j  a v a2 s. com
 * @param command
 * @return
 */
public static <T> Object interprete(String command, Hstore hstore, AbstractResult<T> object,
        boolean useRecursion, ResultOptions resultOptions) {

    if (jsEngine == null) {
        ScriptEngineManager sem = new ScriptEngineManager();
        jsEngine = sem.getEngineByName("JavaScript");
        System.out.println("JS Engine: " + jsEngine.getClass().getCanonicalName());
        Bindings b = jsEngine.createBindings();
        b.put("nn", new SystemApi());
        jsEngine.setBindings(b, ScriptContext.GLOBAL_SCOPE);
    }

    command = command.replace("\\%", "{PERCENT}");

    Pattern p;
    if (!useRecursion) {
        p = PATTERN_COMMAND;
    } else {
        p = PATTERN_RECURSIVE_COMMAND;

        Matcher m = p.matcher(command);
        while (m.find()) {
            String replace = m.group(0);
            //System.out.println("found: " + replace);
            String toReplace = String.valueOf(interprete(replace, hstore, object, false, resultOptions));
            //System.out.println("replacing: " + m.group(0) + " -> " + toReplace);
            command = command.replace(m.group(0), toReplace);
        }

        command = command.replace("{PERCENT}", "%");
        return command;
    }

    Matcher m = p.matcher(command);
    command = command.replace("{PERCENT}", "%");

    String scriptCommand;
    String[] args;

    if (m.find()) {
        if (m.groupCount() != 2) {
            return command;
        }
        scriptCommand = m.group(1);

        if (!COMMAND_EVAL.equals(scriptCommand)) {
            args = m.group(2).trim().split("\\s");
        } else {
            args = new String[] { m.group(2).trim() };
        }
    } else {
        return command;
    }

    try {
        if (COMMAND_RANDOM.equals(scriptCommand)) {
            return random(args);
        } else if (COMMAND_PARAM.equals(scriptCommand)) {
            return parse(args, hstore, object, resultOptions);
        } else if (COMMAND_EVAL.equals(scriptCommand)) {
            return eval(args, hstore, object);
        } else if (COMMAND_RANDOM_URL.equals(scriptCommand)) {
            return randomUrl(args);
        } else {
            return command;
        }
    } catch (ScriptException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.eclairjs.nashorn.Utils.java

public static Object toJsArray(Object javaArray) {
    Object jsArray = javaArray;//from  w w w  .j  a v a 2 s. com
    ScriptEngine engine = NashornEngineSingleton.getEngine();
    try {
        String func = "function(javaArray){return Java.from(javaArray)}";
        Object fn = engine.eval(func);
        Object params[] = { jsArray };
        jsArray = ((ScriptObjectMirror) fn).call(null, params);

    } catch (ScriptException e) {
        e.printStackTrace();
    }
    return jsArray;
}

From source file:org.suren.autotest.web.framework.data.JavaScriptDynamicData.java

@Override
public String getValue(String orginData) {
    String value = null;/*w  ww . j ava  2 s. c o  m*/
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
    try {
        Object resObj = engine.eval(orginData);
        if (resObj != null) {
            value = resObj.toString();
        } else {
            value = "js not return!";
        }
    } catch (ScriptException e) {
        value = e.getMessage();
        e.printStackTrace();
    }

    return value;
}

From source file:com.pamarin.game24.Equations.java

private Integer execute(String equation) {
    try {// ww  w  .j av  a2 s  .co m
        Object result = getEngine().eval(equation);
        if (result instanceof Integer) {
            return (Integer) result;
        }
    } catch (ScriptException ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:org.gatherdata.alert.detect.bsf.internal.BsfEventDetector.java

public Iterable<DetectedEvent> detect(Iterable<RuleSet> usingRules, Map<String, Object> attributes) {
    Set<DetectedEvent> detectedEvents = new HashSet<DetectedEvent>();

    DateTime detectionTime = new DateTime();

    for (RuleSet rule : usingRules) {
        if (rule.isActive()) {
            log.info("applying rule: " + rule);
            boolean anyMatch = false;
            boolean allMatch = true;

            for (LanguageScript predicate : rule.getPredicates()) {
                ScriptEngine engine = scriptEngineManager.getEngineByName(predicate.getLanguage());
                if (engine != null) {
                    try {
                        Boolean doesMatch = (Boolean) engine.eval(predicate.getScript(),
                                adaptToScriptContext(attributes));

                        log.info("\tpredicate [" + predicate + "] "
                                + (doesMatch ? "matches" : "does not match"));
                        anyMatch |= doesMatch;
                        allMatch &= doesMatch;

                    } catch (ScriptException e) {
                        e.printStackTrace();
                    }/*w  ww .  j  a  v a  2  s  .  c om*/
                } else {
                    log.warn("Cant't evaluate predicate for missing language: " + predicate.getLanguage());
                }
            }

            if ((!rule.isSatisfyAll() && anyMatch) || allMatch) {
                detectedEvents.add(MutableDetectedEvent.createFor(detectionTime,
                        CbidFactory.createCbid(attributes.get("body").toString()), rule));
            }
        } else {
            log.warn("Skipping inactive rule:" + rule);
        }

    }
    return detectedEvents;
}

From source file:mrf.Graficar.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    ArrayList<Integer> Datosx = new ArrayList<Integer>();
    ArrayList<Double> Datosy = new ArrayList<Double>();
    int in = Integer.parseInt(jTextField2.getText());
    int sup = Integer.parseInt(jTextField3.getText());
    try {//w w  w.jav a  2s .c  o  m
        XYSeries series = new XYSeries("");
        int inferior = in, superior = sup;
        while (inferior <= superior) {
            Datosx.add(inferior);
            engine.put("X", inferior);
            String a = jTextField1.getText();
            Object operation = engine.eval(a);
            Datosy.add(Double.parseDouble("" + operation));
            jTextArea1.append("Parejas ordenadas " + inferior + ":" + operation + "\n");
            series.add(inferior, Double.parseDouble("" + operation));
            inferior++;
        }

        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createXYLineChart("Grafica del polinomio ingresado", // Ttulo
                "Eje x", // Etiqueta Coordenada X
                "Eje y", // Etiqueta Coordenada Y
                dataset, // Datos
                PlotOrientation.VERTICAL, true, // Muestra la leyenda de los productos (Producto A)              
                false, false);

        // Mostramos la grafica en pantalla
        ChartFrame frame = new ChartFrame("GRAFICA POLINOMIO", chart);
        frame.pack();
        frame.setVisible(true);

    } catch (ScriptException e) {
        e.printStackTrace();
    }

}