Пример #1
0
 public static void execute(HttpServletRequest request, HttpServletResponse response)
     throws IOException, ServletException {
   String scriptPath = getScriptPath(request);
   InputStream sourceIn = request.getServletContext().getResourceAsStream(scriptPath);
   if (sourceIn == null) {
     response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI());
     return;
   }
   RhinoEngine engine = null;
   try {
     engine = CommonManager.getInstance().getEngine();
     Context cx = engine.enterContext();
     // Creating an OutputStreamWritter to write content to the servletResponse
     OutputStream out = response.getOutputStream();
     JaggeryContext webAppContext = createJaggeryContext(out, scriptPath, request, response);
     initContext(cx, webAppContext);
     RhinoEngine.putContextProperty(
         FileHostObject.JAVASCRIPT_FILE_MANAGER,
         new WebAppFileManager(request.getServletContext()));
     CommonManager.getInstance()
         .getEngine()
         .exec(
             new ScriptReader(sourceIn),
             webAppContext.getScope(),
             getScriptCachingContext(request, scriptPath));
     // out.flush();
   } catch (ScriptException e) {
     String msg = e.getMessage();
     log.error(msg, e);
     response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
   } finally {
     // Exiting from the context
     if (engine != null) {
       RhinoEngine.exitContext();
     }
   }
 }
Пример #2
0
  static {
    try {

      String jaggeryDir = System.getProperty("jaggery.home");
      if (jaggeryDir == null) {
        jaggeryDir = System.getProperty("carbon.home");
      }

      if (jaggeryDir == null) {
        log.error("Unable to find jaggery.home or carbon.home system properties");
      }

      String modulesDir = jaggeryDir + File.separator + JAGGERY_MODULES_DIR;

      CommonManager.getInstance()
          .initialize(
              modulesDir,
              new RhinoSecurityController() {
                @Override
                protected void updatePermissions(
                    PermissionCollection permissions, RhinoSecurityDomain securityDomain) {
                  JaggerySecurityDomain domain = (JaggerySecurityDomain) securityDomain;
                  ServletContext context = domain.getServletContext();
                  String docBase = context.getRealPath("/");
                  // Create a file read permission for web app context directory
                  if (!docBase.endsWith(File.separator)) {
                    permissions.add(new FilePermission(docBase, "read"));
                    docBase = docBase + File.separator;
                  } else {
                    permissions.add(
                        new FilePermission(docBase.substring(0, docBase.length() - 1), "read"));
                  }
                  docBase = docBase + "-";
                  permissions.add(new FilePermission(docBase, "read"));
                }
              });
    } catch (ScriptException e) {
      log.error(e.getMessage(), e);
    }
  }
Пример #3
0
 public static RhinoEngine getEngine() throws ScriptException {
   return CommonManager.getInstance().getEngine();
 }