示例#1
0
  public int doEndTag() throws JspTagException {
    try {
      FormTag tag = (FormTag) findAncestorWithClass(this, FormTag.class);
      if (tag != null && validation != null) {
        tag.putValidatedField(name, type);
      }

      StringBuffer html = new StringBuffer();
      html.append("<input");
      html.append(size > 0 ? (" size=\"" + size + "\"") : "");
      html.append(" type=\"" + type + "\"");
      html.append(name != null ? (" name=\"" + name + "\"") : "");
      html.append(value != null ? (" value=\"" + value + "\"") : "");
      html.append(cssClass != null ? (" class=\"" + cssClass + "\"") : "");
      html.append(maxlength > 0 ? (" maxlength=\"" + maxlength + "\"") : "");
      html.append(">");
      pageContext.getOut().print(html.toString());
      return EVAL_PAGE;
    } catch (IOException e) {
      throw new JspTagException("InputTag: " + e.getMessage());
    } finally {
      // reset
      value = null;
      name = null;
      type = null;
      size = 0;
      validation = null;
      maxlength = 0;
      cssClass = null;
    }
  }
 public void testWithNullResolvedCommand() throws Exception {
   try {
     tag.setCommandName(null);
     tag.doStartTag();
     fail("Must not be able to have a command name that resolves to null");
   } catch (IllegalArgumentException ex) {
     // expected
   }
 }
示例#3
0
  public void testWithPartialFormOverriding() throws Exception {

    FormTag formTag = new FormTag();
    formTag.setName("myForm");
    formTag.setPageContext(pageContext);
    formTag.setId("myFormId");
    formTag.setAction("testAction");

    formTag.setTooltipConfig(
        "#{"
            + "'tooltipIcon':'/struts/tooltip/myTooltip.gif', "
            + "'tooltipDelay':'500', "
            + "'jsTooltipEnabled':'true' "
            + "}");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setLabel("MyLabel");
    tag.setId("myId");

    tag.setTooltip("myTooltip");
    tag.setTooltipConfig(
        "#{" + "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " + "'tooltipDelay':'5000' " + "}");

    formTag.doStartTag();
    tag.doStartTag();
    tag.doEndTag();
    formTag.doEndTag();

    verify(TooltipTest.class.getResource("tooltip-3.txt"));
  }
 /**
  * Override method runScript in class BaseJellyFormControlTag
  *
  * @see
  *     com.cyclopsgroup.waterview.jelly.taglib.BaseJellyControlTag#runScript(org.apache.commons.jelly.Script,
  *     org.apache.commons.jelly.XMLOutput)
  */
 protected void runScript(Script script, XMLOutput output) throws Exception {
   FormTag.setHideControls(true, getContext());
   String formContent = getBodyText();
   FormTag.setHideControls(false, getContext());
   if (formTag == null) {
     throw new JellyTagException("Form tag must be defined");
   }
   JellyContext jc = new JellyContext(getContext());
   jc.setVariable("formControl", this);
   jc.setVariable("formTag", formTag);
   jc.setVariable("form", formTag.getForm());
   jc.setVariable("formContent", formContent);
   script.run(jc, output);
 }
 /*
  * See http://opensource.atlassian.com/projects/spring/browse/SPR-2645
  */
 public void testXSSScriptingExploitWhenActionIsResolvedFromQueryString() throws Exception {
   String xssQueryString = QUERY_STRING + "&stuff=\"><script>alert('XSS!')</script>";
   request.setQueryString(xssQueryString);
   tag.doStartTag();
   assertEquals(
       "<form id=\"command\" action=\"/my/form?foo=bar&amp;stuff=&quot;&gt;&lt;script&gt;alert(&#39;XSS!&#39;)&lt;/script&gt;\" method=\"post\">",
       getOutput());
 }
示例#6
0
  public void testWithoutFormOverridingNew() throws Exception {

    // we test it on textfield component, but since the tooltip are common to
    // all components, it will be the same for other components as well.
    FormTag formTag = new FormTag();
    formTag.setPageContext(pageContext);
    formTag.setId("myFormId");
    formTag.setAction("testAction");
    formTag.setName("myForm");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setLabel("MyLabel");
    tag.setId("myId");

    // same parameters as the OGNL map configuration, output must be the same
    tag.setTooltip("myTooltip");
    tag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
    tag.setTooltipDelay("500");
    tag.setJavascriptTooltip("true");

    formTag.doStartTag();
    tag.doStartTag();
    tag.doEndTag();
    formTag.doEndTag();

    verify(TooltipTest.class.getResource("tooltip-1.txt"));
  }
示例#7
0
  public void testWithoutFormOverridingNoJS() throws Exception {

    // we test it on textfield component, but since the tooltip are common to
    // all components, it will be the same for other components as well.
    FormTag formTag = new FormTag();
    formTag.setPageContext(pageContext);
    formTag.setId("myFormId");
    formTag.setAction("testAction");
    formTag.setName("myForm");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setLabel("MyLabel");
    tag.setId("myId");

    tag.setTooltip("myTooltip");
    tag.setTooltipConfig(
        "#{"
            + "'tooltipIcon':'/struts/tooltip/myTooltip.gif', "
            + "'tooltipDelay':'500', "
            + "'jsTooltipEnabled':'false' "
            + "}");

    formTag.doStartTag();
    tag.doStartTag();
    tag.doEndTag();
    formTag.doEndTag();

    verify(TooltipTest.class.getResource("tooltip-4.txt"));
  }
  /**
   * Overwrite or implement method processTag()
   *
   * @see
   *     com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput)
   */
  protected void processTag(XMLOutput output) throws Exception {
    requireAttribute("script");
    invokeBody(XMLOutput.createDummyXMLOutput());

    if (formTag == null) {
      throw new JellyTagException("Form tag must be defined");
    }
    JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE);
    Script script = je.getScript(getScript());

    JellyContext jc = new JellyContext(getContext());
    jc.setVariable("formTag", formTag);
    jc.setVariable("form", formTag.getForm());

    script.run(jc, output);
  }
示例#9
0
  public void testUsingParamBodyValueToSetConfigurations() throws Exception {

    FormTag formTag = new FormTag();
    formTag.setName("myForm");
    formTag.setPageContext(pageContext);
    formTag.setId("myFormId");
    formTag.setAction("testAction");

    ParamTag formParamTag = new ParamTag();
    formParamTag.setPageContext(pageContext);
    formParamTag.setName("tooltipConfig");
    StrutsMockBodyContent bodyContent = new StrutsMockBodyContent(new MockJspWriter());
    bodyContent.setString(
        "tooltipIcon=/struts/tooltip/myTooltip.gif| "
            + "tooltipDelay=500| "
            + "jsTooltipEnabled=true ");
    formParamTag.setBodyContent(bodyContent);

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setLabel("MyLabel");
    tag.setId("myId");
    tag.setTooltip("myTooltip");

    ParamTag textFieldParamTag = new ParamTag();
    textFieldParamTag.setPageContext(pageContext);
    textFieldParamTag.setName("tooltipConfig");
    StrutsMockBodyContent bodyContent2 = new StrutsMockBodyContent(new MockJspWriter());
    bodyContent2.setString("tooltipIcon=/struts/tooltip/myTooltip2.gif| " + "tooltipDelay=5000 ");
    textFieldParamTag.setBodyContent(bodyContent2);

    formTag.doStartTag();
    formParamTag.doStartTag();
    formParamTag.doEndTag();
    tag.doStartTag();
    textFieldParamTag.doStartTag();
    textFieldParamTag.doEndTag();
    tag.doEndTag();
    formTag.doEndTag();

    System.out.println(writer.toString());

    verify(TooltipTest.class.getResource("tooltip-3.txt"));
  }
示例#10
0
  protected void populateParams() {
    // 此段落必须放在super.populateParams()之前
    try {
      if (StringUtils.isNotBlank(autoValidate)) {
        this.setDynamicAttribute(null, "autoValidate", autoValidate);
      }
    } catch (JspException e) {
      e.printStackTrace();
    }

    super.populateParams();
    UIBean uiBean = ((UIBean) component);

    if (id == null) {
      String formid = "form_" + RandomStringUtils.randomAlphabetic(10);
      uiBean.setId(formid);
      // 将id属性设置到pageContext中,便于前端JS代码进行对象分组控制
      pageContext.setAttribute("closestFormId", formid);
    }
    if (this.theme == null) {
      uiBean.setTheme("bootstrap");
    }
  }
示例#11
0
  public void testWithPartialFormOverridingNew() throws Exception {

    FormTag formTag = new FormTag();
    formTag.setName("myForm");
    formTag.setPageContext(pageContext);
    formTag.setId("myFormId");
    formTag.setAction("testAction");

    // same parameters as the OGNL map configuration, output must be the same
    formTag.setTooltip("myTooltip");
    formTag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
    formTag.setTooltipDelay("500");
    formTag.setJavascriptTooltip("true");

    TextFieldTag tag = new TextFieldTag();
    tag.setPageContext(pageContext);
    tag.setLabel("MyLabel");
    tag.setId("myId");

    // same parameters as the OGNL map configuration, output must be the same
    tag.setTooltip("myTooltip");
    tag.setTooltipIconPath("/struts/tooltip/myTooltip2.gif");
    tag.setTooltipDelay("5000");
    tag.setJavascriptTooltip("true");

    formTag.doStartTag();
    tag.doStartTag();
    tag.doEndTag();
    formTag.doEndTag();

    verify(TooltipTest.class.getResource("tooltip-3.txt"));
  }
示例#12
0
  @Override
  protected void setAttributes(HttpServletRequest request) {
    super.setAttributes(request);

    Object bean = getBean();

    if (bean == null) {
      bean = pageContext.getAttribute("aui:model-context:bean");
    }

    Class<?> model = getModel();

    String defaultLanguageId = getDefaultLanguageId();

    if (Validator.isNull(defaultLanguageId)) {
      defaultLanguageId = (String) pageContext.getAttribute("aui:model-context:defaultLanguageId");
    }

    if (Validator.isNull(defaultLanguageId)) {
      if ((model != null) && ModelHintsUtil.hasField(model.getName(), "groupId")) {

        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        defaultLanguageId = LocaleUtil.toLanguageId(themeDisplay.getSiteDefaultLocale());
      }
    }

    if (Validator.isNull(defaultLanguageId)) {
      Locale defaultLocale = LocaleUtil.getDefault();

      defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);
    }

    String name = getName();

    int pos = name.indexOf(StringPool.DOUBLE_DASH);

    if (pos != -1) {
      name = name.substring(pos + 2, name.length() - 2);
    }

    String field = getField();

    if (Validator.isNull(field)) {
      field = getName();
    }

    String formName = getFormName();

    if (formName == null) {
      FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);

      if (formTag != null) {
        formName = formTag.getName();
      }
    }

    String id = getId();
    String type = getType();

    if (Validator.isNull(id)) {
      String fieldParam = getFieldParam();

      if ((model != null) && Validator.isNull(type) && Validator.isNotNull(fieldParam)) {

        id = AUIUtil.normalizeId(fieldParam);
      } else if (!Objects.equals(type, "assetTags") && !Objects.equals(type, "radio")) {

        id = AUIUtil.normalizeId(name);
      } else {
        id = PortalUtil.getUniqueElementId(request, StringPool.BLANK, AUIUtil.normalizeId(name));
      }
    }

    String forLabel = id;

    if (Objects.equals(type, "assetTags")) {
      forLabel = forLabel.concat("assetTagNames");
    }

    String languageId = getLanguageId();

    if (Validator.isNotNull(languageId)) {
      forLabel = LocalizationUtil.getLocalizedName(forLabel, languageId);
    }

    String label = getLabel();

    if (label == null) {
      label = TextFormatter.format(name, TextFormatter.P);
    }

    String title = getTitle();

    if ((title == null) && (Validator.isNull(label) || Objects.equals(type, "image"))) {

      title = TextFormatter.format(name, TextFormatter.P);
    }

    boolean wrappedField = getWrappedField();

    FieldWrapperTag fieldWrapper =
        (FieldWrapperTag) findAncestorWithClass(this, FieldWrapperTag.class);

    if (fieldWrapper != null) {
      wrappedField = true;
    }

    setNamespacedAttribute(request, "baseType", getBaseType());
    setNamespacedAttribute(request, "bean", bean);
    setNamespacedAttribute(request, "defaultLanguageId", defaultLanguageId);
    setNamespacedAttribute(request, "field", field);
    setNamespacedAttribute(request, "forLabel", forLabel);
    setNamespacedAttribute(request, "formName", formName);
    setNamespacedAttribute(request, "id", id);
    setNamespacedAttribute(request, "label", label);
    setNamespacedAttribute(request, "model", model);
    setNamespacedAttribute(request, "title", String.valueOf(title));
    setNamespacedAttribute(request, "wrappedField", wrappedField);

    request.setAttribute(getAttributeNamespace() + "value", getValue());

    Map<String, ValidatorTag> validatorTags = getValidatorTags();

    if ((validatorTags != null) && (validatorTags.get("required") != null)) {

      setNamespacedAttribute(request, "required", Boolean.TRUE.toString());
    }
  }
  @Override
  protected void setAttributes(HttpServletRequest request) {
    super.setAttributes(request);

    Object bean = getBean();

    if (bean == null) {
      bean = pageContext.getAttribute("aui:model-context:bean");
    }

    String name = getName();

    int pos = name.indexOf(StringPool.DOUBLE_DASH);

    if (pos != -1) {
      name = name.substring(pos + 2, name.length() - 2);
    }

    String field = getField();

    if (Validator.isNull(field)) {
      field = getName();
    }

    String formName = getFormName();

    if (formName == null) {
      FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);

      if (formTag != null) {
        formName = formTag.getName();
      }
    }

    String id = getId();
    String type = getType();

    if (Validator.isNull(id)) {
      if (!Validator.equals(type, "assetTags") && !Validator.equals(type, "radio")) {

        id = name;
      } else {
        id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
      }
    }

    String label = getLabel();

    if (label == null) {
      label = TextFormatter.format(name, TextFormatter.K);
    }

    Class<?> model = getModel();

    if (model == null) {
      model = (Class<?>) pageContext.getAttribute("aui:model-context:model");
    }

    _forLabel = id;

    String baseType = null;

    if ((model != null) && Validator.isNull(type)) {
      baseType = ModelHintsUtil.getType(model.getName(), field);

      String fieldParam = getFieldParam();

      if (Validator.isNotNull(fieldParam)) {
        _forLabel = fieldParam;
      }

      if (ModelHintsUtil.isLocalized(model.getName(), field)) {
        Locale defaultLocale = LocaleUtil.getDefault();
        String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

        _forLabel += StringPool.UNDERLINE + defaultLanguageId;
      }
    } else if (Validator.isNotNull(type)) {
      if (Validator.equals(type, "checkbox") || Validator.equals(type, "radio")) {

        baseType = type;
      }
    }

    if (Validator.isNull(baseType)) {
      baseType = "text";
    }

    setNamespacedAttribute(request, "baseType", baseType);
    setNamespacedAttribute(request, "bean", bean);
    setNamespacedAttribute(request, "field", field);
    setNamespacedAttribute(request, "forLabel", _forLabel);
    setNamespacedAttribute(request, "formName", formName);
    setNamespacedAttribute(request, "id", id);
    setNamespacedAttribute(request, "label", label);
    setNamespacedAttribute(request, "model", model);

    request.setAttribute(getAttributeNamespace() + "value", getValue());
  }