Beispiel #1
0
  @Handler(
      id = "calculateHelpUrl",
      input = {
        @HandlerInput(name = "pluginId", type = String.class, required = true),
        @HandlerInput(name = "helpKey", type = String.class, required = true)
      },
      output = {@HandlerOutput(name = "url", type = String.class)})
  public static void calculateHelpUrl(HandlerContext handlerCtx) {
    String pluginId = (String) handlerCtx.getInputValue("pluginId");
    String helpKey = (String) handlerCtx.getInputValue("helpKey");
    ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext());

    ClassLoader cl = cps.getModuleClassLoader(pluginId);

    // Try the viewRoot locale first
    String path =
        getHelpPathForResource(helpKey, handlerCtx.getFacesContext().getViewRoot().getLocale(), cl);
    if (path == null) {
      // Try the default locale
      path = getHelpPathForResource(helpKey, Locale.getDefault(), cl);

      // Default to en
      if (path == null) {
        path = "/en/help/" + helpKey;
      }
    }

    handlerCtx.setOutputValue("url", path);
  }
Beispiel #2
0
  @Handler(
      id = "getPluginIdFromViewId",
      input = {@HandlerInput(name = "viewId", type = String.class, required = true)},
      output = {@HandlerOutput(name = "pluginId", type = String.class)})
  public static void getPluginIdFromViewId(HandlerContext handlerCtx) {
    String viewId = (String) handlerCtx.getInputValue("viewId");
    if (viewId == null) {
      return;
    }
    ConsolePluginService cps = getPluginService(handlerCtx.getFacesContext());
    String pluginId = "common";
    int next = viewId.indexOf("/", 1);
    if (next > -1) {
      pluginId = viewId.substring(0, next);
      String resource = viewId.substring(next);

      if (pluginId.startsWith("/")) {
        pluginId = pluginId.substring(1);
      }

      ClassLoader cl = cps.getModuleClassLoader(pluginId);
      URL url = null;
      if (cl != null) {
        url = cl.getResource(resource);
      }
      if (url == null) {
        pluginId = "common";
      }
    }
    handlerCtx.setOutputValue("pluginId", pluginId);
  }