Beispiel #1
0
  @Override
  public String getDecoratedMenu() {
    String menuItem = null;
    boolean showRowCount = Boolean.valueOf(getPropertyString("rowCount")).booleanValue();
    if (showRowCount) {
      // get datalist and row count
      DataList dataList = getDataList();
      if (dataList != null) {
        int rowCount = dataList.getTotal();

        // sanitize label
        String label = getPropertyString("label");
        if (label != null) {
          label = StringUtil.stripHtmlRelaxed(label);
        }

        // generate menu link
        menuItem =
            "<a href=\""
                + getUrl()
                + "\" class=\"menu-link default\"><span>"
                + label
                + "</span> <span class='rowCount'>("
                + rowCount
                + ")</span></a>";
      }
    }
    return menuItem;
  }
Beispiel #2
0
  public Object execute(Map properties) {
    WorkflowAssignment wfAssignment = (WorkflowAssignment) properties.get("workflowAssignment");

    String jsonUrl = (String) properties.get("jsonUrl");
    GetMethod get = null;
    try {
      HttpClient client = new HttpClient();

      jsonUrl = WorkflowUtil.processVariable(jsonUrl, "", wfAssignment);

      jsonUrl = StringUtil.encodeUrlParam(jsonUrl);

      get = new GetMethod(jsonUrl);
      client.executeMethod(get);
      InputStream in = get.getResponseBodyAsStream();
      String jsonResponse = streamToString(in);

      Map object = PropertyUtil.getPropertiesValueFromJson(jsonResponse);

      storeToForm(wfAssignment, properties, object);
      storeToWorkflowVariable(wfAssignment, properties, object);

    } catch (Exception ex) {
      LogUtil.error(getClass().getName(), ex, "");
    } finally {
      if (get != null) {
        get.releaseConnection();
      }
    }

    return null;
  }
  protected String getTitle() {
    String title = userview.getPropertyString("name");
    if (userview.getCurrent() != null) {
      title += "&nbsp;&gt;&nbsp;" + userview.getCurrent().getPropertyString("label");
    }

    return StringUtil.stripAllHtmlTag(title);
  }
 protected String homePageRedirection() {
   if (userview.getParamString("menuId").isEmpty()
       && !userview.getPropertyString("homeMenuId").isEmpty()) {
     return "redirect:"
         + getHomePageLink()
         + (request.getQueryString() == null
             ? ""
             : ("?" + StringUtil.decodeURL(request.getQueryString())));
   }
   return null;
 }
 protected String loginPageRedirection() {
   boolean isAnonymous = WorkflowUtil.isCurrentUserAnonymous();
   boolean hasCurrentPage = userview.getCurrent() != null;
   if ((!isAuthorized || !hasCurrentPage) && isAnonymous) {
     return "redirect:"
         + getLoginLink()
         + (request.getQueryString() == null
             ? ""
             : ("?" + StringUtil.decodeURL(request.getQueryString())));
   }
   return null;
 }
Beispiel #6
0
  public static String processHashVariable(
      String content,
      WorkflowAssignment wfAssignment,
      String escapeFormat,
      Map<String, String> replaceMap,
      AppDefinition appDef) {
    // check for hash # to avoid unnecessary processing
    if (!containsHashVariable(content)) {
      return content;
    }

    // parse content
    if (content != null) {
      Pattern pattern = Pattern.compile("\\#([^#^\"^ ])*\\.([^#^\"])*\\#");
      Matcher matcher = pattern.matcher(content);
      List<String> varList = new ArrayList<String>();
      while (matcher.find()) {
        varList.add(matcher.group());
      }

      try {
        if (!varList.isEmpty()) {
          PluginManager pluginManager = (PluginManager) appContext.getBean("pluginManager");
          PluginDefaultPropertiesDao pluginDefaultPropertiesDao =
              (PluginDefaultPropertiesDao) appContext.getBean("pluginDefaultPropertiesDao");
          Collection<Plugin> pluginList = pluginManager.list(HashVariablePlugin.class);
          Map<String, HashVariablePlugin> hashVariablePluginCache =
              new HashMap<String, HashVariablePlugin>();

          for (String var : varList) {
            String tempVar = var.replaceAll("#", "");

            for (Plugin p : pluginList) {
              HashVariablePlugin hashVariablePlugin = (HashVariablePlugin) p;
              if (tempVar.startsWith(hashVariablePlugin.getPrefix() + ".")) {
                tempVar = tempVar.replaceFirst(hashVariablePlugin.getPrefix() + ".", "");

                HashVariablePlugin cachedPlugin =
                    hashVariablePluginCache.get(hashVariablePlugin.getClassName());
                if (cachedPlugin == null) {
                  cachedPlugin =
                      (HashVariablePlugin)
                          pluginManager.getPlugin(hashVariablePlugin.getClassName());
                  // get default plugin properties

                  if (appDef == null) {
                    appDef = AppUtil.getCurrentAppDefinition();
                  }
                  PluginDefaultProperties pluginDefaultProperties =
                      pluginDefaultPropertiesDao.loadById(cachedPlugin.getClassName(), appDef);
                  if (pluginDefaultProperties != null
                      && pluginDefaultProperties.getPluginProperties() != null
                      && pluginDefaultProperties.getPluginProperties().trim().length() > 0) {
                    cachedPlugin.setProperties(
                        PropertyUtil.getPropertiesValueFromJson(
                            pluginDefaultProperties.getPluginProperties()));
                  }

                  // put appDef & wfAssignment to properties
                  cachedPlugin.setProperty("appDefinition", appDef);
                  cachedPlugin.setProperty("workflowAssignment", wfAssignment);
                  hashVariablePluginCache.put(hashVariablePlugin.getClassName(), cachedPlugin);
                }

                // process nested hash
                while (tempVar.contains("{") && tempVar.contains("}")) {
                  Pattern nestedPattern = Pattern.compile("\\{([^\\{^\\}])*\\}");
                  Matcher nestedMatcher = nestedPattern.matcher(tempVar);
                  while (nestedMatcher.find()) {
                    String nestedHash = nestedMatcher.group();
                    String nestedHashString = nestedHash.replace("{", "#");
                    nestedHashString = nestedHashString.replace("}", "#");

                    String processedNestedHashValue =
                        processHashVariable(
                            nestedHashString, wfAssignment, escapeFormat, replaceMap, appDef);
                    tempVar =
                        tempVar.replaceAll(
                            StringUtil.escapeString(nestedHash, StringUtil.TYPE_REGEX, null),
                            StringUtil.escapeString(
                                processedNestedHashValue, escapeFormat, replaceMap));
                  }
                }

                // get result from plugin
                String value = cachedPlugin.processHashVariable(tempVar);

                if (value != null && !StringUtil.TYPE_REGEX.equals(escapeFormat)) {
                  value = StringUtil.escapeRegex(value);
                }

                // escape special char in HashVariable
                var = cachedPlugin.escapeHashVariable(var);

                // replace
                if (value != null) {
                  content =
                      content.replaceAll(
                          var, StringUtil.escapeString(value, escapeFormat, replaceMap));
                }
              }
            }
          }
        }
      } catch (Exception ex) {
        LogUtil.error(AppUtil.class.getName(), ex, "");
      }
    }
    return content;
  }