Package jodd.servlet

Examples of jodd.servlet.HtmlTag


   */
  protected String populateForm(String html, FieldResolver resolver) {
    int s = 0;
    StringBuilder result = new StringBuilder((int) (html.length() * 1.2));
    String currentSelectName = null;
    HtmlTag tag = null;
    while (true) {
      if (tag != null) {
        result.append(tag);
      }
      tag = HtmlTag.locateNextTag(html, s);
      if (tag == null) {
        result.append(html.substring(s));
        break;
      }
      result.append(html.substring(s, tag.getStartIndex()));
      s = tag.getNextIndex();

      String tagName = tag.getTagName();
      // process end tags
      if (tag.isEndTag()) {
        if (tagName.equals(SELECT)) {
          currentSelectName = null;
        }
        continue;
      }

      if (tagName.equals(INPUT) == true) {
        // INPUT
        String tagType = tag.getAttribute(TYPE);
        if (tagType == null) {
          continue;
        }
        String name = tag.getAttribute(NAME);
        if (name == null) {
          continue;
        }
        Object valueObject = resolver.value(name);
        if (valueObject == null) {
          continue;
        }
        String value = valueObject.toString();
        tagType = tagType.toLowerCase();

        if (tagType.equals(TEXT)) {
          tag.setAttribute(VALUE, value);
        } else if (tagType.equals(HIDDEN)) {
          tag.setAttribute(VALUE, value);
        } else if (tagType.equals(IMAGE)) {
          tag.setAttribute(VALUE, value);
        } else if (tagType.equals(PASSWORD)) {
          tag.setAttribute(VALUE, value);
        } else if (tagType.equals(CHECKBOX)) {
          String tagValue = tag.getAttribute(VALUE);
          if (tagValue == null) {
            tagValue = TRUE;
          }
          if (valueObject.getClass().isArray()) {
            // checkbox group
            String vs[] = StringUtil.toStringArray(valueObject);
            for (String vsk : vs) {
              if ((vsk != null) && (vsk.equals(tagValue))) {
                tag.setAttribute(CHECKED);
              }
            }
          } else if (tagValue.equals(value)) {
            tag.setAttribute(CHECKED);
          }
        } else if (tagType.equals(RADIO)) {
          String tagValue = tag.getAttribute(VALUE);
          if (tagValue != null) {
            if (tagValue.equals(value)) {
              tag.setAttribute(CHECKED);
            }
          }
        }
      } else if (tagName.equals(TEXTAREA)) {
        String name = tag.getAttribute(NAME);
        Object valueObject = resolver.value(name);
        if (valueObject != null) {
          tag.setSuffixText(HtmlEncoder.text(valueObject.toString()));
        }
      } else if (tagName.equals(SELECT)) {
        currentSelectName = tag.getAttribute(NAME);
      } else if (tagName.equals(OPTION)) {
        if (currentSelectName == null) {
          continue;
        }
        String tagValue = tag.getAttribute(VALUE);
        if (tagValue != null) {
          Object vals = resolver.value(currentSelectName);
          if (vals == null) {
            continue;
          }
          if (vals.getClass().isArray()) {
            String vs[] = StringUtil.toStringArray(vals);
            for (String vsk : vs) {
              if ((vsk != null) && (vsk.equals(tagValue))) {
                tag.setAttribute(SELECTED);
              }
            }
          } else {
            String value = StringUtil.toString(vals);
            if (value.equals(tagValue)) {
              tag.setAttribute(SELECTED);
            }
          }
        }
      }
    }
View Full Code Here


  public String process(String input) {
    StringTemplateParser tagParser = createStringTemplateParser();

    return tagParser.parse(input, new StringTemplateParser.MacroResolver() {
      public String resolve(String macro) {
        HtmlTag htmlTag = new HtmlTag("<" + macro + "/>");
        String tagName = htmlTag.getTagName();

        String macroBody = loadMacro(tagName);

        Map<String, String> attributes = htmlTag.getAttributes();

        // replace attributes with values
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
          String key = macroPrefix + entry.getKey() + macroSuffix;
          macroBody = StringUtil.replace(macroBody, key, entry.getValue());
View Full Code Here

TOP

Related Classes of jodd.servlet.HtmlTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.