示例#1
0
  public String getContext(IParameterProvider requestParams) {
    try {
      String solution = requestParams.getStringParameter("solution", ""),
          path = requestParams.getStringParameter("path", ""),
          // Fix #29. Because there is no file parameter in CDF, but action parameter
          // file parameter is used in CDE
          file =
              requestParams.getStringParameter(
                  "file", requestParams.getStringParameter("action", "")),
          fullPath = ("/" + solution + "/" + path + "/" + file).replaceAll("/+", "/");
      final JSONObject context = new JSONObject();
      Calendar cal = Calendar.getInstance();

      Document config = getConfigFile();

      context.put("queryData", processAutoIncludes(fullPath, config));
      context.put("sessionAttributes", processSessionAttributes(config));

      context.put("serverLocalDate", cal.getTimeInMillis());
      context.put("serverUTCDate", cal.getTimeInMillis() + cal.getTimeZone().getRawOffset());
      context.put("user", userSession.getName());
      context.put("locale", userSession.getLocale());
      context.put("solution", solution);
      context.put("path", path);
      context.put("file", file);
      context.put("fullPath", fullPath);

      SecurityParameterProvider securityParams = new SecurityParameterProvider(userSession);
      context.put("roles", securityParams.getParameter("principalRoles"));

      JSONObject params = new JSONObject();

      Iterator it = requestParams.getParameterNames();
      while (it.hasNext()) {
        String p = (String) it.next();
        if (p.indexOf("param") == 0) {
          params.put(p.substring(5), requestParams.getParameter(p));
        }
      }
      context.put("params", params);

      final StringBuilder s = new StringBuilder();
      s.append("\n<script language=\"javascript\" type=\"text/javascript\">\n");
      s.append("  Dashboards.context = ");
      s.append(context.toString(2) + "\n");
      s.append("</script>\n");
      // setResponseHeaders(MIME_PLAIN,0,null);
      logger.info(
          "[Timing] Finished building context: "
              + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));

      return s.toString();
    } catch (JSONException e) {
      return "";
    }
  }