コード例 #1
0
ファイル: Token.java プロジェクト: Hayakiji/struts
  /**
   * First looks for the token in the PageContext using the supplied name (or {@link
   * org.apache.struts2.util.TokenHelper#DEFAULT_TOKEN_NAME} if no name is provided) so that the
   * same token can be re-used for the scope of a request for the same name. If the token is not in
   * the PageContext, a new Token is created and set into the Session and the PageContext with the
   * name.
   */
  protected void evaluateExtraParams() {
    super.evaluateExtraParams();

    String tokenName;
    Map parameters = getParameters();

    if (parameters.containsKey("name")) {
      tokenName = (String) parameters.get("name");
    } else {
      if (name == null) {
        tokenName = TokenHelper.DEFAULT_TOKEN_NAME;
      } else {
        tokenName = findString(name);

        if (tokenName == null) {
          tokenName = name;
        }
      }

      addParameter("name", tokenName);
    }

    String token = buildToken(tokenName);
    addParameter("token", token);
    addParameter("tokenNameField", TokenHelper.TOKEN_NAME_FIELD);
  }
コード例 #2
0
ファイル: UIBean.java プロジェクト: angelowolf/SEW
  public void evaluateParams() {
    String templateDir = getTemplateDir();
    String theme = getTheme();

    addParameter("templateDir", templateDir);
    addParameter("theme", theme);
    addParameter("template", template != null ? findString(template) : getDefaultTemplate());
    addParameter("dynamicAttributes", dynamicAttributes);
    addParameter("themeExpansionToken", uiThemeExpansionToken);
    addParameter("expandTheme", uiThemeExpansionToken + theme);

    String name = null;
    String providedLabel = null;

    if (this.key != null) {

      if (this.name == null) {
        this.name = key;
      }

      if (this.label == null) {
        // lookup the label from a TextProvider (default value is the key)
        providedLabel = TextProviderHelper.getText(key, key, stack);
      }
    }

    if (this.name != null) {
      name = findString(this.name);
      addParameter("name", name);
    }

    if (label != null) {
      addParameter("label", findString(label));
    } else {
      if (providedLabel != null) {
        // label found via a TextProvider
        addParameter("label", providedLabel);
      }
    }

    if (labelSeparator != null) {
      addParameter("labelseparator", findString(labelSeparator));
    }

    if (labelPosition != null) {
      addParameter("labelposition", findString(labelPosition));
    }

    if (requiredPosition != null) {
      addParameter("requiredPosition", findString(requiredPosition));
    }

    if (errorPosition != null) {
      addParameter("errorposition", findString(errorPosition));
    }

    if (requiredLabel != null) {
      addParameter("required", findValue(requiredLabel, Boolean.class));
    }

    if (disabled != null) {
      addParameter("disabled", findValue(disabled, Boolean.class));
    }

    if (tabindex != null) {
      addParameter("tabindex", findString(tabindex));
    }

    if (onclick != null) {
      addParameter("onclick", findString(onclick));
    }

    if (ondblclick != null) {
      addParameter("ondblclick", findString(ondblclick));
    }

    if (onmousedown != null) {
      addParameter("onmousedown", findString(onmousedown));
    }

    if (onmouseup != null) {
      addParameter("onmouseup", findString(onmouseup));
    }

    if (onmouseover != null) {
      addParameter("onmouseover", findString(onmouseover));
    }

    if (onmousemove != null) {
      addParameter("onmousemove", findString(onmousemove));
    }

    if (onmouseout != null) {
      addParameter("onmouseout", findString(onmouseout));
    }

    if (onfocus != null) {
      addParameter("onfocus", findString(onfocus));
    }

    if (onblur != null) {
      addParameter("onblur", findString(onblur));
    }

    if (onkeypress != null) {
      addParameter("onkeypress", findString(onkeypress));
    }

    if (onkeydown != null) {
      addParameter("onkeydown", findString(onkeydown));
    }

    if (onkeyup != null) {
      addParameter("onkeyup", findString(onkeyup));
    }

    if (onselect != null) {
      addParameter("onselect", findString(onselect));
    }

    if (onchange != null) {
      addParameter("onchange", findString(onchange));
    }

    if (accesskey != null) {
      addParameter("accesskey", findString(accesskey));
    }

    if (cssClass != null) {
      addParameter("cssClass", findString(cssClass));
    }

    if (cssStyle != null) {
      addParameter("cssStyle", findString(cssStyle));
    }

    if (cssErrorClass != null) {
      addParameter("cssErrorClass", findString(cssErrorClass));
    }

    if (cssErrorStyle != null) {
      addParameter("cssErrorStyle", findString(cssErrorStyle));
    }

    if (title != null) {
      addParameter("title", findString(title));
    }

    // see if the value was specified as a parameter already
    if (parameters.containsKey("value")) {
      parameters.put("nameValue", parameters.get("value"));
    } else {
      if (evaluateNameValue()) {
        final Class valueClazz = getValueClassType();

        if (valueClazz != null) {
          if (value != null) {
            addParameter("nameValue", findValue(value, valueClazz));
          } else if (name != null) {
            String expr = completeExpressionIfAltSyntax(name);

            addParameter("nameValue", findValue(expr, valueClazz));
          }
        } else {
          if (value != null) {
            addParameter("nameValue", findValue(value));
          } else if (name != null) {
            addParameter("nameValue", findValue(name));
          }
        }
      }
    }

    final Form form = (Form) findAncestor(Form.class);

    // create HTML id element
    populateComponentHtmlId(form);

    if (form != null) {
      addParameter("form", form.getParameters());

      if (name != null) {
        // list should have been created by the form component
        List<String> tags = (List<String>) form.getParameters().get("tagNames");
        tags.add(name);
      }
    }

    // tooltip & tooltipConfig
    if (tooltipConfig != null) {
      addParameter("tooltipConfig", findValue(tooltipConfig));
    }
    if (tooltip != null) {
      addParameter("tooltip", findString(tooltip));

      Map tooltipConfigMap = getTooltipConfig(this);

      if (form != null) { // inform the containing form that we need tooltip javascript included
        form.addParameter("hasTooltip", Boolean.TRUE);

        // tooltipConfig defined in component itseilf will take precedence
        // over those defined in the containing form
        Map overallTooltipConfigMap = getTooltipConfig(form);
        overallTooltipConfigMap.putAll(tooltipConfigMap); // override parent form's tooltip config

        for (Object o : overallTooltipConfigMap.entrySet()) {
          Map.Entry entry = (Map.Entry) o;
          addParameter((String) entry.getKey(), entry.getValue());
        }
      } else {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              "No ancestor Form found, javascript based tooltip will not work, however standard HTML tooltip using alt and title attribute will still work ");
        }
      }

      // TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped
      String jsTooltipEnabled = (String) getParameters().get("jsTooltipEnabled");
      if (jsTooltipEnabled != null) this.javascriptTooltip = jsTooltipEnabled;

      // TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped
      String tooltipIcon = (String) getParameters().get("tooltipIcon");
      if (tooltipIcon != null) this.addParameter("tooltipIconPath", tooltipIcon);
      if (this.tooltipIconPath != null)
        this.addParameter("tooltipIconPath", findString(this.tooltipIconPath));

      // TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped
      String tooltipDelayParam = (String) getParameters().get("tooltipDelay");
      if (tooltipDelayParam != null) this.addParameter("tooltipDelay", tooltipDelayParam);
      if (this.tooltipDelay != null)
        this.addParameter("tooltipDelay", findString(this.tooltipDelay));

      if (this.javascriptTooltip != null) {
        Boolean jsTooltips = (Boolean) findValue(this.javascriptTooltip, Boolean.class);
        // TODO use a Boolean model when tooltipConfig is dropped
        this.addParameter("jsTooltipEnabled", jsTooltips.toString());

        if (form != null) form.addParameter("hasTooltip", jsTooltips);
        if (this.tooltipCssClass != null)
          this.addParameter("tooltipCssClass", findString(this.tooltipCssClass));
      }
    }

    evaluateExtraParams();
  }