Package javax.script

Examples of javax.script.CompiledScript


              page = Integer.parseInt((String) req
                  .getParameter("page"));
            } catch (Exception e) {
              page = 1;
            }
            CompiledScript compiledscript = CompileScriptEngine
                .getCompileScript(config.getApplicationId(),
                    "tag", template.getTag());

            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            CategoryModel cateModel = new CategoryModel();
            cateModel.prepareAll();
            TagModel tagModel = new TagModel();
            tagModel.prepareList();

            bind.put("current_tag", obj);
            bind.put("recent_view",
                RecentViewHelper.getRecentView());
            bind.put("list_tag", tagModel.getListResult());
            bind.put("list_category", cateModel.getListResult());

            List<News> listResult = new ArrayList<News>();
            listResult = obj.recoverListNews();
            int start = (page - 1) * limit;
            double dLimit = limit;
            bind.put("total_page",
                (int) Math.ceil(listResult.size() / dLimit));
            try {
              listResult = listResult
                  .subList(start, page * limit);
            } catch (Exception e) {
              try {
                listResult = listResult.subList(start,
                    listResult.size());
              } catch (Exception e2) {

              }
            }
            bind.put("articles", listResult);
            bind.put("current_page", page);

            try {
              resp.getWriter().print(
                  (String) compiledscript.eval());
            } catch (Exception e) {
              e.printStackTrace();
              log.warning(e.toString());
            }
          } else {
View Full Code Here


          CategoryModel cateModel = new CategoryModel();
          cateModel.prepareAll();
          TagModel tagModel = new TagModel();
          tagModel.prepareList();

          CompiledScript compiledscript = CompileScriptEngine
              .getCompileScript(config.getApplicationId(),
                  "home", template.getHome());
          if (compiledscript != null) {
            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            bind.put("recent_view",
                RecentViewHelper.getRecentView());
            bind.put("list_tag", tagModel.getListResult());
            bind.put("list_category", cateModel.getListResult());

            bind.put("current_page", model.getPage());
            bind.put("total_page", model.getTotalPage());
            bind.put("articles", model.getListResult());
            try {
              resp.getWriter().print(
                  (String) compiledscript.eval());
            } catch (Exception e) {
              e.printStackTrace();
              log.warning(e.toString());
            }
          } else {
View Full Code Here

          if (obj != null) {
            CategoryModel cateModel = new CategoryModel();
            cateModel.prepareAll();
            TagModel tagModel = new TagModel();
            tagModel.prepareList();
            CompiledScript compiledscript = CompileScriptEngine
                .getCompileScript(config.getApplicationId(),
                    "detail", template.getDetail());

            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            RecentViewHelper.addRecentView(obj);
            bind.put("recent_view",
                RecentViewHelper.getRecentView());
            bind.put("list_tag", tagModel.getListResult());
            bind.put("list_category", cateModel.getListResult());
            bind.put("article", obj);
            try {
              String result = (String) compiledscript.eval();
              treeCache.put(alias, result);
              resp.getWriter().print(result);
            } catch (Exception e) {
              e.printStackTrace();
              log.warning(e.toString());
View Full Code Here

          String categoryAlias = splitted[2];
          categoryAlias = URLDecoder.decode(categoryAlias, "UTF-8");
          Category obj = CategoryModel.getById(categoryAlias);
          if (obj != null || check == false) {

            CompiledScript compiledscript = CompileScriptEngine
                .getCompileScript(config.getApplicationId(),
                    "category", template.getCategory());
            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            int page = 1;
            try {
              page = Integer.parseInt((String) req
                  .getParameter("page"));
            } catch (Exception e) {
              page = 1;
            }
            List<News> listNews = new ArrayList<News>();
            NewsModel model = new NewsModel();
            model.setPage(page);
            model.prepareListByCategory(categoryAlias);
            listNews = model.getListResult();
            CategoryModel cateModel = new CategoryModel();
            cateModel.prepareAll();
            TagModel tagModel = new TagModel();
            tagModel.prepareList();
            bind.put("recent_view",
                RecentViewHelper.getRecentView());
            bind.put("list_tag", tagModel.getListResult());
            bind.put("list_category", cateModel.getListResult());

            bind.put("category", obj);
            bind.put("current_page", model.getPage());
            bind.put("total_page", model.getTotalPage());
            bind.put("articles", listNews);
            try {
              resp.getWriter().print(
                  (String) compiledscript.eval());
            } catch (Exception e) {
              e.printStackTrace();
              log.warning(e.toString());
            }
          } else {
View Full Code Here

                    if (supportsCompilable) {
                        String cacheKey =
                                getScriptLanguage()+"#"+
                                scriptFile.getAbsolutePath()+"#"+
                                        scriptFile.lastModified();
                        CompiledScript compiledScript =
                                compiledScriptsCache.get(cacheKey);
                        if (compiledScript==null) {
                            synchronized (compiledScriptsCache) {
                                compiledScript =
                                        compiledScriptsCache.get(cacheKey);
                                if (compiledScript==null) {
                                    // TODO Charset ?
                                    fileReader = new BufferedReader(new FileReader(scriptFile),
                                            (int)scriptFile.length());
                                    compiledScript =
                                            ((Compilable) scriptEngine).compile(fileReader);
                                    compiledScriptsCache.put(cacheKey, compiledScript);
                                }
                            }
                        }
                        return compiledScript.eval(bindings);
                    } else {
                        // TODO Charset ?
                        fileReader = new BufferedReader(new FileReader(scriptFile),
                                (int)scriptFile.length());
                        return scriptEngine.eval(fileReader, bindings);                   
                    }
                } finally {
                    IOUtils.closeQuietly(fileReader);
                }
            }  else {
                throw new ScriptException("Script file '"+scriptFile.getAbsolutePath()+"' does not exist or is unreadable for element:"+getName());
            }
        } else if (!StringUtils.isEmpty(getScript())){
            if (supportsCompilable && !StringUtils.isEmpty(cacheKey)) {
                CompiledScript compiledScript =
                        compiledScriptsCache.get(cacheKey);
                if (compiledScript==null) {
                    synchronized (compiledScriptsCache) {
                        compiledScript =
                                compiledScriptsCache.get(cacheKey);
                        if (compiledScript==null) {
                            compiledScript =
                                    ((Compilable) scriptEngine).compile(getScript());
                            compiledScriptsCache.put(cacheKey, compiledScript);
                        }
                    }
                }
                return compiledScript.eval(bindings);
            } else {
                return scriptEngine.eval(getScript(), bindings);
            }
        } else {
            throw new ScriptException("Both script file and script text are empty for element:"+getName());           
View Full Code Here

                if(supportsCompilable) {
                    String cacheKey =
                            getScriptLanguage()+"#"+
                            scriptFile.getAbsolutePath()+"#"+
                                    scriptFile.lastModified();
                    CompiledScript compiledScript =
                            compiledScriptsCache.get(cacheKey);
                    if(compiledScript==null) {
                        synchronized (compiledScriptsCache) {
                            compiledScript =
                                    compiledScriptsCache.get(cacheKey);
                            if(compiledScript==null) {
                                // TODO Charset ?
                                fileReader = new BufferedReader(new FileReader(scriptFile),
                                        (int)scriptFile.length());
                                compiledScript =
                                        ((Compilable) scriptEngine).compile(fileReader);
                                compiledScriptsCache.put(cacheKey, compiledScript);
                            }
                        }
                    }
                    return compiledScript.eval(bindings);
                } else {
                    // TODO Charset ?
                    fileReader = new BufferedReader(new FileReader(scriptFile),
                            (int)scriptFile.length());
                    return scriptEngine.eval(fileReader, bindings);                   
View Full Code Here

            "end\n" +
            "def get_perimeter(x, y)\n" +
              "x + 2.0 * y + Math::PI / 2.0 * x\n" +
            "end\n" +
            "norman_window(2, 1)";
        CompiledScript cs = ((Compilable)instance).compile(script);
        List<Double> result = (List<Double>) cs.eval();
        assertEquals(3.570796327, result.get(0), 0.000001);
        assertEquals(7.141592654, result.get(1), 0.000001);

        instance.getBindings(ScriptContext.ENGINE_SCOPE).clear();
        instance = null;
View Full Code Here

        }
        String filename = basedir + "/test/org/jruby/embed/ruby/proverbs_of_the_day.rb";
        Reader reader = new FileReader(filename);
       
        instance.put("$day", -1);
        CompiledScript cs = ((Compilable)instance).compile(reader);
        String result = (String) cs.eval();
        String expResult = "A rolling stone gathers no moss.";
        assertEquals(expResult, result);
        result = (String) cs.eval();
        expResult = "A friend in need is a friend indeed.";
        assertEquals(expResult, result);
        result = (String) cs.eval();
        expResult = "Every garden may have some weeds.";
        assertEquals(expResult, result);
       
        instance.getBindings(ScriptContext.ENGINE_SCOPE).clear();
        instance = null;
View Full Code Here

     */
    private void compileAndCache(String scriptId, String script) throws ScriptException
    {
        if ( compiler_ != null )
        {
            CompiledScript compiledScript = compiler_.compile(script);
            calloutCache_.put(scriptId, compiledScript);
        }
    }
View Full Code Here

     * @param args arguments to be passed to the callouts.
     */
    public Object executeCallout(String callout, Object ... args)
    {
        Object result = null;
        CompiledScript script = calloutCache_.get(callout);
        if ( script != null )
        {
            try
            {
                Bindings binding = new SimpleBindings();
                binding.put("args", args);
                result = script.eval(binding);
            }
            catch(ScriptException ex)
            {
                logger_.warn(LogUtil.throwableToString(ex));
            }
View Full Code Here

TOP

Related Classes of javax.script.CompiledScript

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.