コード例 #1
0
 protected void importGlobalUserSettings(List<ExportManifestUserSetting> globalSettings) {
   IUserSettingService settingService = PentahoSystem.get(IUserSettingService.class);
   if (settingService != null) {
     for (ExportManifestUserSetting globalSetting : globalSettings) {
       if (isOverwriteFile()) {
         settingService.setGlobalUserSetting(globalSetting.getName(), globalSetting.getValue());
       } else {
         IUserSetting userSetting =
             settingService.getGlobalUserSetting(globalSetting.getName(), null);
         if (userSetting == null) {
           settingService.setGlobalUserSetting(globalSetting.getName(), globalSetting.getValue());
         }
       }
     }
   }
 }
コード例 #2
0
  public void handleRequest(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    try {
      // look for a passed in theme context (content generator, other named area)
      String moduleName = req.getParameter("context");
      OutputStream out = resp.getOutputStream();
      resp.setContentType("text/javascript"); // $NON-NLS-1$
      resp.setHeader("Cache-Control", "no-cache"); // $NON-NLS-1$

      IUserSettingService settingsService =
          PentahoSystem.get(IUserSettingService.class, getPentahoSession(req));

      String activeTheme = (String) getPentahoSession(req).getAttribute("pentaho-user-theme");

      String ua = req.getHeader("User-Agent");
      // check if we're coming from a mobile device, if so, lock to system default (crystal)
      if (!StringUtils.isEmpty(ua) && ua.matches(".*(?i)(iPad|iPod|iPhone|Android).*")) {
        activeTheme = PentahoSystem.getSystemSetting("default-theme", "crystal");
      }
      if (activeTheme == null) {
        try {
          activeTheme =
              settingsService.getUserSetting("pentaho-user-theme", null).getSettingValue();
        } catch (
            Exception
                ignored) { // the user settings service is not valid in the agile-bi deployment of
          // the server
        }
        if (activeTheme == null) {
          activeTheme = PentahoSystem.getSystemSetting("default-theme", "crystal");
        }
      }

      out.write(
          ("\n\n// Theming scripts. This file is generated by ("
                  + getClass().getName()
                  + ") and cannot be found on disk\n")
              .getBytes());

      out.write(("var active_theme = \"" + activeTheme + "\";\n\n").getBytes());

      // Build-up JSON graph for system theme.
      JSONObject root = new JSONObject();
      JSONObject themeObject;

      for (String systemThemeName : themeManager.getSystemThemeIds()) {
        Theme theme = themeManager.getSystemTheme(systemThemeName);

        themeObject = new JSONObject();
        root.put(theme.getId(), themeObject);
        themeObject.put("rootDir", theme.getThemeRootDir());
        for (ThemeResource res : theme.getResources()) {
          themeObject.append("resources", res.getLocation());
        }
      }

      out.write(("var core_theme_tree = " + root.toString() + ";\n\n").getBytes());
      out.write(
          "// Inject the theme script to handle the insertion of requested theme resources\n\n"
              .getBytes());

      ModuleThemeInfo moduleThemeinfo = themeManager.getModuleThemeInfo(moduleName);
      if (moduleThemeinfo != null) {
        // Build-up JSON graph for module theme.
        root = new JSONObject();
        for (Theme theme : moduleThemeinfo.getModuleThemes()) {
          themeObject = new JSONObject();
          root.put(theme.getName(), themeObject);
          themeObject.put("rootDir", theme.getThemeRootDir());
          for (ThemeResource res : theme.getResources()) {
            themeObject.append("resources", res.getLocation());
          }
        }

        out.write(("var module_theme_tree = " + root.toString() + ";\n\n").getBytes());
      }

      // createElement & insertBefore
      out.write(
          ("(function() {\n"
                  + "var script = document.createElement('script');\n"
                  + "script.type = 'text/javascript';\n"
                  +
                  // "script.async = false;\n" +
                  "script.src = CONTEXT_PATH + 'js/themeResources.js';\n"
                  + "var existing = document.getElementsByTagName('script')[0];\n"
                  + "existing.parentNode.insertBefore(script, existing);\n"
                  + "}());")
              .getBytes());

    } catch (IOException e) {
      logger.debug("IO exception creating Theme info", e);
      throw new ServletException(e);
    } catch (JSONException e) {
      logger.debug("JSON exception creating Theme info", e);
      throw new ServletException(e);
    }
  }