Java 类javax.servlet.jsp.tagext.BodyTag 实例源码

项目:lazycat    文件:Node.java   
public CustomTag(String qName, String prefix, String localName, String uri, Attributes attrs,
        Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent, TagInfo tagInfo,
        Class<?> tagHandlerClass) {
    super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent);

    this.uri = uri;
    this.prefix = prefix;
    this.tagInfo = tagInfo;
    this.tagHandlerClass = tagHandlerClass;
    this.customNestingLevel = makeCustomNestingLevel();
    this.childInfo = new ChildInfo();

    this.implementsIterationTag = IterationTag.class.isAssignableFrom(tagHandlerClass);
    this.implementsBodyTag = BodyTag.class.isAssignableFrom(tagHandlerClass);
    this.implementsTryCatchFinally = TryCatchFinally.class.isAssignableFrom(tagHandlerClass);
    this.implementsSimpleTag = SimpleTag.class.isAssignableFrom(tagHandlerClass);
    this.implementsDynamicAttributes = DynamicAttributes.class.isAssignableFrom(tagHandlerClass);
    this.implementsJspIdConsumer = JspIdConsumer.class.isAssignableFrom(tagHandlerClass);
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void withExplicitNonWhitespaceBodyContent() throws Exception {
    String mockContent = "This is some explicit body content";
    this.tag.setBodyContent(new MockBodyContent(mockContent, getWriter()));

    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
    assertEquals(mockContent, getOutput());
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void withExplicitWhitespaceBodyContent() throws Exception {
    this.tag.setBodyContent(new MockBodyContent("\t\n   ", getWriter()));

    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "Default Message");
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void withExplicitEmptyWhitespaceBodyContent() throws Exception {
    this.tag.setBodyContent(new MockBodyContent("", getWriter()));

    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "Default Message");
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void withErrors() throws Exception {
    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "<br/>");
    assertBlockTagContains(output, "Default Message");
    assertBlockTagContains(output, "Too Short");
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void withEscapedErrors() throws Exception {
    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default <> Message");
    errors.rejectValue("name", "too.short", "Too & Short");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "<br/>");
    assertBlockTagContains(output, "Default &lt;&gt; Message");
    assertBlockTagContains(output, "Too &amp; Short");
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void asBodyTag() throws Exception {
    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");
    exposeBindingResult(errors);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
    String bodyContent = "Foo";
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    this.tag.doEndTag();
    this.tag.doFinally();
    assertEquals(bodyContent, getOutput());
    assertNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
@Test
public void asBodyTagWithExistingMessagesAttribute() throws Exception {
    String existingAttribute = "something";
    getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute);
    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");
    exposeBindingResult(errors);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
    assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
    String bodyContent = "Foo";
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    this.tag.doEndTag();
    this.tag.doFinally();
    assertEquals(bodyContent, getOutput());
    assertEquals(existingAttribute, getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
}
项目:spring4-understanding    文件:ErrorsTagTests.java   
/**
 * https://jira.spring.io/browse/SPR-2788
 */
@Test
public void asBodyTagWithErrorsAndExistingMessagesAttributeInNonPageScopeAreNotClobbered() throws Exception {
    String existingAttribute = "something";
    getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute, PageContext.APPLICATION_SCOPE);
    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");
    exposeBindingResult(errors);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
    assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
    String bodyContent = "Foo";
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    this.tag.doEndTag();
    this.tag.doFinally();
    assertEquals(bodyContent, getOutput());
    assertEquals(existingAttribute,
            getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, PageContext.APPLICATION_SCOPE));
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void canBeDisabledEvenWhenSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDisabled(true);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "disabled", "disabled");
    assertBlockTagContains(output, "Bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void renderNotSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertBlockTagContains(output, "Bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void renderWithDynamicAttributes() throws Exception {
    String dynamicAttribute1 = "attr1";
    String dynamicAttribute2 = "attr2";

    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
    this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, dynamicAttribute1, dynamicAttribute1);
    assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2);
    assertBlockTagContains(output, "Bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void renderSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setId("myOption");
    this.tag.setValue("foo");
    this.tag.setLabel("Foo");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "id", "myOption");
    assertContainsAttribute(output, "value", "foo");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "Foo");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withNoLabel() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setCssClass("myClass");
    this.tag.setOnclick("CLICK");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "class", "myClass");
    assertContainsAttribute(output, "onclick", "CLICK");
    assertBlockTagContains(output, "bar");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withCustomObjectSelected() throws Exception {
    String selectName = "testBean.someNumber";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue(new Float(12.34));
    this.tag.setLabel("GBP 12.34");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "12.34");
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "GBP 12.34");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withCustomObjectNotSelected() throws Exception {
    String selectName = "testBean.someNumber";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue(new Float(12.35));
    this.tag.setLabel("GBP 12.35");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "12.35");
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "GBP 12.35");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void withCustomObjectAndEditorNotSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    String selectName = "testBean.someNumber";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return floatEditor;
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue(new Float(12.35));
    this.tag.setLabel("12.35f");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertAttributeNotPresent(output, "selected");
    assertBlockTagContains(output, "12.35f");
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTag() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue("foo");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, bodyContent);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTagSelected() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue("Rob Harrop");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertBlockTagContains(output, bodyContent);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTagCollapsed() throws Exception {
    String selectName = "testBean.name";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    String bodyContent = "some content";

    this.tag.setValue(bodyContent);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", bodyContent);
    assertBlockTagContains(output, bodyContent);
}
项目:spring4-understanding    文件:OptionTagTests.java   
@Test
public void asBodyTagWithEditor() throws Exception {
    String selectName = "testBean.stringArray";
    BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
        @Override
        public PropertyEditor getEditor() {
            return new RulesVariantEditor();
        }
    };
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
    this.tag.setValue(rulesVariant);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    assertEquals(rulesVariant, getPageContext().getAttribute("value"));
    assertEquals(rulesVariant.toId(), getPageContext().getAttribute("displayValue"));

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
}
项目:spring4-understanding    文件:OptionTagEnumTests.java   
@Test
@SuppressWarnings("rawtypes")
public void withJavaEnum() throws Exception {
    GenericBean testBean = new GenericBean();
    testBean.setCustomEnum(CustomEnum.VALUE_1);
    getPageContext().getRequest().setAttribute("testBean", testBean);
    String selectName = "testBean.customEnum";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));

    this.tag.setValue("VALUE_1");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getWriter().toString();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "VALUE_1");
    assertContainsAttribute(output, "selected", "selected");
}
项目:spring4-understanding    文件:HtmlEscapeTagTests.java   
@Test
public void escapeBody() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer result = new StringBuffer();
    EscapeBodyTag tag = new EscapeBodyTag() {
        @Override
        protected String readBodyContent() {
            return "test text";
        }
        @Override
        protected void writeBodyContent(String content) {
            result.append(content);
        }
    };
    tag.setPageContext(pc);
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
    assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
    assertEquals("test text", result.toString());
}
项目:spring4-understanding    文件:HtmlEscapeTagTests.java   
@Test
public void escapeBodyWithHtmlEscape() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer result = new StringBuffer();
    EscapeBodyTag tag = new EscapeBodyTag() {
        @Override
        protected String readBodyContent() {
            return "test & text";
        }
        @Override
        protected void writeBodyContent(String content) {
            result.append(content);
        }
    };
    tag.setPageContext(pc);
    tag.setHtmlEscape(true);
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
    assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
    assertEquals("test &amp; text", result.toString());
}
项目:spring4-understanding    文件:HtmlEscapeTagTests.java   
@Test
public void escapeBodyWithJavaScriptEscape() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer result = new StringBuffer();
    EscapeBodyTag tag = new EscapeBodyTag() {
        @Override
        protected String readBodyContent() {
            return "' test & text \\";
        }
        @Override
        protected void writeBodyContent(String content) {
            result.append(content);
        }
    };
    tag.setPageContext(pc);
    tag.setJavaScriptEscape(true);
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
    assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
    assertEquals("Correct content", "\\' test & text \\\\", result.toString());
}
项目:spring4-understanding    文件:HtmlEscapeTagTests.java   
@Test
public void escapeBodyWithHtmlEscapeAndJavaScriptEscape() throws JspException {
    PageContext pc = createPageContext();
    final StringBuffer result = new StringBuffer();
    EscapeBodyTag tag = new EscapeBodyTag() {
        @Override
        protected String readBodyContent() {
            return "' test & text \\";
        }
        @Override
        protected void writeBodyContent(String content) {
            result.append(content);
        }
    };
    tag.setPageContext(pc);
    tag.setHtmlEscape(true);
    tag.setJavaScriptEscape(true);
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
    assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
    assertEquals("Correct content", "&#39; test &amp; text \\\\", result.toString());
}
项目:openmrs-module-legacyui    文件:ForEachEncounterTagTest.java   
/**
 * @see ForEachEncounterTag#doStartTag()
 * @regression TRUNK-2465
 */
@Test
@Verifies(value = "should sort encounters by encounterDatetime in descending order", method = "doStartTag()")
public void doStartTag_shouldSortEncountersByEncounterDatetimeInDescendingOrder() throws Exception {
    int num = 3;
    executeDataSet("org/openmrs/web/taglib/include/ForEachEncounterTagTest.xml");
    Patient patient = Context.getPatientService().getPatient(7);
    List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(patient);
    ForEachEncounterTag tag = new ForEachEncounterTag();
    tag.setPageContext(new MockPageContext());
    tag.setDescending(true);
    tag.setEncounters(encounters);
    tag.setVar("enc");
    tag.setNum(num);
    // the tag passes
    Assert.assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
    //the match count should not exceed the limit
    Assert.assertTrue(num >= tag.matchingEncs.size());
    //check the sorting
    Assert.assertEquals(11, tag.matchingEncs.get(0).getId().intValue());
    Assert.assertEquals(16, tag.matchingEncs.get(1).getId().intValue());
    Assert.assertEquals(7, tag.matchingEncs.get(2).getId().intValue());
}
项目:Telepathology    文件:AbstractResolvedArtifactSourceCollectionTag.java   
/**
 * Create and expose the current RequestContext. Delegates to
 * {@link #doStartTagInternal()} for actual work.
 * 
 * @see #REQUEST_CONTEXT_PAGE_ATTRIBUTE
 * @see org.springframework.web.servlet.support.JspAwareRequestContext
 */
public final int doStartTag() 
throws JspException
{
    resolvedArtifactSourceIterator = getResolvedArtifactSourcesIterator();
    if(resolvedArtifactSourceIterator == null || !resolvedArtifactSourceIterator.hasNext())
    {
        currentResolvedArtifactSource = null;
        if(getEmptyResultMessage() != null)
            try{pageContext.getOut().write(getEmptyResultMessage());}
            catch(IOException ioX){logger.error("Unable to write empty result set message.");}

        return BodyTag.SKIP_BODY;
    }
    else
    {
        currentResolvedArtifactSource = resolvedArtifactSourceIterator.next();
        return BodyTag.EVAL_BODY_INCLUDE;
    }
}
项目:Telepathology    文件:AbstractUrlCollectionTag.java   
/**
 * Create and expose the current RequestContext. Delegates to
 * {@link #doStartTagInternal()} for actual work.
 * 
 * @see #REQUEST_CONTEXT_PAGE_ATTRIBUTE
 * @see org.springframework.web.servlet.support.JspAwareRequestContext
 */
public final int doStartTag() 
throws JspException
{
    urlIterator = getUrlIterator();
    if(urlIterator.hasNext())
    {
        currentUrl = urlIterator.next();
        return BodyTag.EVAL_BODY_INCLUDE;
    }
    else
    {
        if(getEmptyResultMessage() != null)
            try{pageContext.getOut().write(getEmptyResultMessage());}
            catch(IOException ioX){logger.error("Unable to write empty result set message.");}

        currentUrl = null;
        return BodyTag.SKIP_BODY;
    }
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testWithExplicitNonWhitespaceBodyContent() throws Exception {
    String mockContent = "This is some explicit body content";
    this.tag.setBodyContent(new MockBodyContent(mockContent, getWriter()));

    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
    assertEquals(mockContent, getOutput());
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testWithExplicitWhitespaceBodyContent() throws Exception {
    this.tag.setBodyContent(new MockBodyContent("\t\n   ", getWriter()));

    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "Default Message");
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testWithExplicitEmptyWhitespaceBodyContent() throws Exception {
    this.tag.setBodyContent(new MockBodyContent("", getWriter()));

    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "Default Message");
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testWithErrors() throws Exception {
    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "<br/>");
    assertBlockTagContains(output, "Default Message");
    assertBlockTagContains(output, "Too Short");
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testWithEscapedErrors() throws Exception {
    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default <> Message");
    errors.rejectValue("name", "too.short", "Too & Short");

    exposeBindingResult(errors);

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "<br/>");
    assertBlockTagContains(output, "Default &lt;&gt; Message");
    assertBlockTagContains(output, "Too &amp; Short");
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testWithErrorsAndCustomElement() throws Exception {
    // construct an errors instance of the tag
    TestBean target = new TestBean();
    target.setName("Rob Harrop");
    Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");

    exposeBindingResult(errors);

    this.tag.setElement("div");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertElementTagOpened(output);
    assertElementTagClosed(output);

    assertContainsAttribute(output, "id", "name.errors");
    assertBlockTagContains(output, "<br/>");
    assertBlockTagContains(output, "Default Message");
    assertBlockTagContains(output, "Too Short");
}
项目:class-guard    文件:ErrorsTagTests.java   
public void testAsBodyTagWithExistingMessagesAttribute() throws Exception {
    String existingAttribute = "something";
    getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute);
    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");
    exposeBindingResult(errors);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
    assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
    String bodyContent = "Foo";
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    this.tag.doEndTag();
    this.tag.doFinally();
    assertEquals(bodyContent, getOutput());
    assertEquals(existingAttribute, getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
}
项目:class-guard    文件:ErrorsTagTests.java   
/**
 * http://opensource.atlassian.com/projects/spring/browse/SPR-2788
 */
public void testAsBodyTagWithErrorsAndExistingMessagesAttributeInNonPageScopeAreNotClobbered() throws Exception {
    String existingAttribute = "something";
    getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute, PageContext.APPLICATION_SCOPE);
    Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
    errors.rejectValue("name", "some.code", "Default Message");
    errors.rejectValue("name", "too.short", "Too Short");
    exposeBindingResult(errors);
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
    assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
    String bodyContent = "Foo";
    this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
    this.tag.doEndTag();
    this.tag.doFinally();
    assertEquals(bodyContent, getOutput());
    assertEquals(existingAttribute,
            getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, PageContext.APPLICATION_SCOPE));
}
项目:class-guard    文件:OptionTagTests.java   
public void testCanBeDisabledEvenWhenSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    this.tag.setDisabled("true");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertContainsAttribute(output, "disabled", "disabled");
    assertBlockTagContains(output, "Bar");
}
项目:class-guard    文件:OptionTagTests.java   
public void testRenderNotSelected() throws Exception {
    String selectName = "testBean.name";
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
    this.tag.setValue("bar");
    this.tag.setLabel("Bar");
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();

    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "value", "bar");
    assertBlockTagContains(output, "Bar");
}