类javax.servlet.jsp.tagext.JspFragment源码实例Demo

下面列出了怎么用javax.servlet.jsp.tagext.JspFragment的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: java-tutorial   文件: ToUpperCaseTag.java
@Override
public void doTag() throws JspException, IOException {

	// 将 标签体内容读入该 writer
	StringWriter writer = new StringWriter();

	// 标签体 为 JspFragment 的形式
	JspFragment jspFragment = this.getJspBody();

	// 通过 invoke 输出到指定的 writer 中。
	// 如果参数为 null,将输出到默认的 writer 中,即 getJspContext().getOut() 输出到HTML中
	jspFragment.invoke(writer);

	String content = writer.getBuffer().toString();
	this.getJspContext().getOut().print(content.toUpperCase());
}
 
源代码2 项目: HongsCORE   文件: NuidTag.java
@Override
public void doTag() throws JspException {
  JspWriter out = getJspContext().getOut();

  String uid;
  if (this.sid != null) {
    uid = Core.newIdentity(this.sid);
  } else {
    uid = Core.newIdentity();
  }

  try {
    out.print(uid);

    JspFragment f = getJspBody();
    if (f != null) f.invoke(out);
  } catch (java.io.IOException ex) {
    throw new JspException("Error in NuidTag", ex);
  }
}
 
源代码3 项目: sinavi-jfw   文件: PankuzuTag.java
/**
 * パンクズリストを表示します。
 * このメソッドはJSP-BODYを評価せずに、
 * 既存のHTMLテンプレート、あるいはクラスコンフィグオーバライドされたHTMLテンプレートを利用します。
 * @throws JspException JSP処理中にエラーが発生した場合
 * @throws IOException 入出力エラーの場合
 */
protected void render() throws JspException, IOException {
    render(new JspFragment() {
        @Override public JspContext getJspContext() {
            return PankuzuTag.this.getJspContext();
        }
        @Override public void invoke(Writer out) throws JspException, IOException {
            JspContext context = getJspContext();
            ViewId vid = (ViewId) context.getAttribute(var);
            String encodedUrl = encodeURL(vid.getUrl());
            String item = Strings.substitute(DEFAULT_TEMPLATE, Maps
                        .hash("url", encodedUrl)
                        .map("label", Strings.escapeHTML(vid.getLabel()))
                        .map("query", trimQueryMarkerIfGetRequestParameterExists(encodedUrl, vid.getQuery())));
            context.getOut().print(item);
        }
    });
}
 
源代码4 项目: sinavi-jfw   文件: PageNavigationTag.java
private String invokeFragmentIfNeeded(
        JspFragment fragment,
        String defaultValue,
        int currentIndex) throws JspException {
    PageContext p = pageContext;
    StringWriter w = new StringWriter();
    if (fragment != null) {
        if (currentIndex > 0) p.setAttribute(var, currentIndex);
        try {
            fragment.invoke(w);
        } catch (IOException e) {throw new JspException(e);}
        if (currentIndex > 0) p.removeAttribute(var);
    } else {
        w.append(Strings.substitute(
                defaultValue,
                Maps.hash(var, String.valueOf(currentIndex))));
    }
    return w.toString();
}
 
源代码5 项目: sinavi-jfw   文件: PankuzuTag.java
/**
 * {@inheritDoc}
 */
@Override
public void doTag() throws JspException, IOException {
    super.doTag();
    JspFragment template = getJspBody();
    if (template != null) {
        render(template);
    } else {
        render();
    }
}
 
源代码6 项目: jsp-template-inheritance   文件: BlockTagUtils.java
public static String getBodyResult(JspFragment jspBody) throws IOException, JspException {
    if (jspBody == null) {
        return "";
    }

    StringWriter writer = new StringWriter();
    jspBody.invoke(writer);
    return writer.toString();
}
 
源代码7 项目: Tomcat8-Source-Read   文件: ShuffleSimpleTag.java
public void setFragment1( JspFragment fragment1 ) {
    this.fragment1 = fragment1;
}
 
源代码8 项目: Tomcat8-Source-Read   文件: ShuffleSimpleTag.java
public void setFragment2( JspFragment fragment2 ) {
    this.fragment2 = fragment2;
}
 
源代码9 项目: Tomcat8-Source-Read   文件: ShuffleSimpleTag.java
public void setFragment3( JspFragment fragment3 ) {
    this.fragment3 = fragment3;
}
 
源代码10 项目: Tomcat8-Source-Read   文件: ShuffleSimpleTag.java
public void setFragment1( JspFragment fragment1 ) {
    this.fragment1 = fragment1;
}
 
源代码11 项目: Tomcat8-Source-Read   文件: ShuffleSimpleTag.java
public void setFragment2( JspFragment fragment2 ) {
    this.fragment2 = fragment2;
}
 
源代码12 项目: Tomcat8-Source-Read   文件: ShuffleSimpleTag.java
public void setFragment3( JspFragment fragment3 ) {
    this.fragment3 = fragment3;
}
 
源代码13 项目: java-tutorial   文件: MultiAttributeTag.java
public void setBody1(JspFragment body1) {
	this.body1 = body1;
}
 
源代码14 项目: java-tutorial   文件: MultiAttributeTag.java
public void setBody2(JspFragment body2) {
	this.body2 = body2;
}
 
源代码15 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment1( JspFragment fragment1 ) {
    this.fragment1 = fragment1;
}
 
源代码16 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment2( JspFragment fragment2 ) {
    this.fragment2 = fragment2;
}
 
源代码17 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment3( JspFragment fragment3 ) {
    this.fragment3 = fragment3;
}
 
源代码18 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment1( JspFragment fragment1 ) {
    this.fragment1 = fragment1;
}
 
源代码19 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment2( JspFragment fragment2 ) {
    this.fragment2 = fragment2;
}
 
源代码20 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment3( JspFragment fragment3 ) {
    this.fragment3 = fragment3;
}
 
源代码21 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment1( JspFragment fragment1 ) {
    this.fragment1 = fragment1;
}
 
源代码22 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment2( JspFragment fragment2 ) {
    this.fragment2 = fragment2;
}
 
源代码23 项目: tomcatsrc   文件: ShuffleSimpleTag.java
public void setFragment3( JspFragment fragment3 ) {
    this.fragment3 = fragment3;
}
 
源代码24 项目: packagedrone   文件: CallTag.java
@Override
public void doTag () throws JspException, IOException
{
    final JspFragment body = (JspFragment)getJspContext ().getAttribute ( DefineTag.ATTR_PREFIX + this.name );

    if ( body == null )
    {
        throw new JspException ( String.format ( "Unable to find macro '%s'", this.name ) );
    }

    final JspContext ctx = body.getJspContext ();

    // set attributes to body context

    final Map<String, Object> oldEntries = new HashMap<> ( this.data.size () );

    for ( final Map.Entry<String, Object> entry : this.data.entrySet () )
    {
        oldEntries.put ( entry.getKey (), ctx.getAttribute ( entry.getKey (), PageContext.PAGE_SCOPE ) );
        ctx.setAttribute ( entry.getKey (), entry.getValue (), PageContext.PAGE_SCOPE );
    }

    // invoke

    body.invoke ( getJspContext ().getOut () );

    // set old values, so we don't clutter up the context for the next caller

    for ( final String key : this.data.keySet () )
    {
        final Object val = oldEntries.get ( key );
        if ( val == null )
        {
            ctx.removeAttribute ( key, PageContext.PAGE_SCOPE );
        }
        else
        {
            ctx.setAttribute ( key, val, PageContext.PAGE_SCOPE );
        }
    }
}
 
源代码25 项目: packagedrone   文件: DefineTag.java
@Override
public void setJspBody ( final JspFragment jspBody )
{
    super.setJspBody ( jspBody );
    getJspContext ().setAttribute ( ATTR_PREFIX + this.name, jspBody, PageContext.PAGE_SCOPE );
}
 
源代码26 项目: sinavi-jfw   文件: PageNavigationTag.java
private String invokeFragmentIfNeeded(
        JspFragment fragment,
        String defaultValue) throws JspException {
    return invokeFragmentIfNeeded(fragment, defaultValue, Integer.MIN_VALUE);
}
 
源代码27 项目: sinavi-jfw   文件: PageNavigationTagTest.java
@Test
public void jspFragmentが設定される() throws Exception {

    PartialList<String> display = new PartialList<String>();
    for (int i = 0; i < 110; i++) {
        display.add(Integer.toString(i));
    }
    display.setElementCount(110);
    display.setPartCount(11);
    display.setElementCountPerPart(10);
    display.setPartIndex(7);
    PageNavigationTag tag = new PageNavigationTag();
    tag.setPageContext(context);
    tag.setPartial(display);
    tag.setAction("/list");
    JspFragment fragment = new JspFragment() {

        @Override
        public JspContext getJspContext() {
            return context;
        }

        @Override
        public void invoke(Writer out) throws JspException, IOException {
            out.write("----");
        }
    };
    tag.setOmission(fragment);
    tag.doStartTag();
    tag.doEndTag();
    String actual = resp.getContentAsString();
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_head\">", "");
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_previous\">", "");
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_page\">", "");
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_page_selected\">", "");
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_next\">", "");
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_tail\">", "");
    actual = actual.replaceAll("<span class=\"jfw_paginate_navi_omission\">", "");
    actual = actual.replaceAll("</span>", "\n");
    String[] split = actual.split("\n");
    assertThat(split.length, is(15));
    assertThat(Arrays.asList(split), hasItem("<a href=\"/list?pageNumber=1\">&lt;&lt;</a>"));
    assertThat(Arrays.asList(split), hasItem("<a href=\"/list?pageNumber=6\">&lt;</a>"));
    assertThat(Arrays.asList(split), hasItem("<a href=\"/list?pageNumber=2\">2</a>"));
    assertThat(Arrays.asList(split), hasItem("<a href=\"/list?pageNumber=11\">11</a>"));
    assertThat(Arrays.asList(split), hasItem("7"));
    assertThat(Arrays.asList(split), hasItem("----"));
    assertThat(Arrays.asList(split), hasItem("<a href=\"/list?pageNumber=8\">&gt;</a>"));
    assertThat(Arrays.asList(split), hasItem("<a href=\"/list?pageNumber=11\">&gt;&gt;</a>"));
}
 
源代码28 项目: Online-Library-System   文件: SearchByTag.java
public void setJspBody(JspFragment arg0) {

	}
 
源代码29 项目: Online-Library-System   文件: BookLocationTag.java
public void setJspBody(JspFragment arg0) {

	}
 
源代码30 项目: kfs   文件: AccountingLineGroupTag.java
/**
 * Gets the importLineOverride attribute. 
 * @return Returns the importLineOverride.
 */
public JspFragment getImportLineOverride() {
    return importLineOverride;
}
 
 类所在包
 类方法
 同包方法