Search in sources :

Example 1 with JspFragment

use of javax.servlet.jsp.tagext.JspFragment in project HongsCORE by ihongs.

the class NuidTag method doTag.

@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);
    }
}
Also used : JspFragment(javax.servlet.jsp.tagext.JspFragment) JspException(javax.servlet.jsp.JspException) JspWriter(javax.servlet.jsp.JspWriter)

Example 2 with JspFragment

use of javax.servlet.jsp.tagext.JspFragment in project freemarker by apache.

the class SimpleTagDirectiveModel method execute.

public void execute(Environment env, Map args, TemplateModel[] outArgs, final TemplateDirectiveBody body) throws TemplateException, IOException {
    try {
        SimpleTag tag = (SimpleTag) getTagInstance();
        final FreeMarkerPageContext pageContext = PageContextFactory.getCurrentPageContext();
        pageContext.pushWriter(new JspWriterAdapter(env.getOut()));
        try {
            tag.setJspContext(pageContext);
            JspTag parentTag = (JspTag) pageContext.peekTopTag(JspTag.class);
            if (parentTag != null) {
                tag.setParent(parentTag);
            }
            setupTag(tag, args, pageContext.getObjectWrapper());
            if (body != null) {
                tag.setJspBody(new JspFragment() {

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

                    @Override
                    public void invoke(Writer out) throws JspException, IOException {
                        try {
                            body.render(out == null ? pageContext.getOut() : out);
                        } catch (TemplateException e) {
                            throw new TemplateExceptionWrapperJspException(e);
                        }
                    }
                });
                pageContext.pushTopTag(tag);
                try {
                    tag.doTag();
                } finally {
                    pageContext.popTopTag();
                }
            } else {
                tag.doTag();
            }
        } finally {
            pageContext.popWriter();
        }
    } catch (TemplateException e) {
        throw e;
    } catch (Exception e) {
        throw toTemplateModelExceptionOrRethrow(e);
    }
}
Also used : JspContext(javax.servlet.jsp.JspContext) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) JspException(javax.servlet.jsp.JspException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException) JspFragment(javax.servlet.jsp.tagext.JspFragment) JspException(javax.servlet.jsp.JspException) SimpleTag(javax.servlet.jsp.tagext.SimpleTag) JspTag(javax.servlet.jsp.tagext.JspTag) Writer(java.io.Writer)

Example 3 with JspFragment

use of javax.servlet.jsp.tagext.JspFragment in project freemarker by apache.

the class TestSimpleTag method doTag.

@Override
public void doTag() throws JspException, IOException {
    JspContext ctx = getJspContext();
    JspWriter w = ctx.getOut();
    w.println("enter TestSimpleTag " + name);
    JspFragment f = getJspBody();
    for (int i = 0; i < bodyLoopCount; ++i) {
        w.println("invoking body i=" + i);
        f.invoke(w);
    }
    w.println("exit TestSimpleTag " + name);
}
Also used : JspFragment(javax.servlet.jsp.tagext.JspFragment) JspContext(javax.servlet.jsp.JspContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 4 with JspFragment

use of javax.servlet.jsp.tagext.JspFragment in project jodd by oblac.

the class IteratorTag method iterateArray.

/**
 * Iterates arrays.
 */
protected void iterateArray(final Object[] array, final int from, final int count, final PageContext pageContext) throws JspException {
    JspFragment body = getJspBody();
    int len = array.length;
    int to = calculateTo(from, count, len);
    int last = to - 1;
    for (int i = from; i < to; i++) {
        Object item = array[i];
        if (status != null) {
            iteratorStatus.next(i == last);
        }
        TagUtil.setScopeAttribute(var, item, scope, pageContext);
        TagUtil.invokeBody(body);
    }
}
Also used : JspFragment(javax.servlet.jsp.tagext.JspFragment)

Example 5 with JspFragment

use of javax.servlet.jsp.tagext.JspFragment in project OpenClinica by OpenClinica.

the class PrintTableTag method doTag.

/**
 * This JSP Tag API method creates a instance of PrintHorizontalFormBuilder,
 * then generates that class's XHTML output into the web page. The tag shows
 * all sections of a CRF.
 *
 * @throws JspException
 * @throws IOException
 */
@Override
public void doTag() throws JspException, IOException {
    JspContext context = getJspContext();
    JspWriter tagWriter = context.getOut();
    // This request attribute is generated by the PrintCRf or PrintDataEntry
    // servlets
    List<DisplaySectionBean> listOfDisplayBeans = (ArrayList) context.findAttribute("listOfDisplaySectionBeans");
    StudyBean studyBean = (StudyBean) context.findAttribute("study");
    // EventCRFBean
    EventCRFBean eventCRFBean = (EventCRFBean) context.findAttribute("EventCRFBean");
    String isInternetExplorer = (String) context.findAttribute("isInternetExplorer");
    if (listOfDisplayBeans != null) {
        PrintHorizontalFormBuilder printFormBuilder = new PrintHorizontalFormBuilder();
        // Provide the form-building code with the list of display section
        // beans
        printFormBuilder.setDisplaySectionBeans(listOfDisplayBeans);
        // The body content of the tag contains 'true' or 'false', depending
        // on whether the
        // printed CRF involves data entry (and possible saved data) or not.
        JspFragment fragment = this.getJspBody();
        Writer stringWriter = new StringWriter();
        fragment.invoke(stringWriter);
        if ("true".equalsIgnoreCase(stringWriter.toString())) {
            printFormBuilder.setInvolvesDataEntry(true);
        }
        printFormBuilder.setEventCRFbean(eventCRFBean);
        if ("true".equalsIgnoreCase(isInternetExplorer)) {
            printFormBuilder.setInternetExplorer(true);
        }
        if (studyBean != null) {
            printFormBuilder.setStudyBean(studyBean);
        }
        if ("true".equalsIgnoreCase(stringWriter.toString())) {
            tagWriter.println(printFormBuilder.createMarkup());
        } else
            tagWriter.println(printFormBuilder.createMarkupNoDE());
    } else {
        tagWriter.println("The application could not generate the markup for the printable form.<br />" + "This error may have been caused by the altering of the web page's URL; the URL needs " + "an 'id' or an 'ecId' value in its query string at the URL end.");
    }
}
Also used : DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) PrintHorizontalFormBuilder(org.akaza.openclinica.view.form.PrintHorizontalFormBuilder) JspFragment(javax.servlet.jsp.tagext.JspFragment) JspContext(javax.servlet.jsp.JspContext) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StringWriter(java.io.StringWriter) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) JspWriter(javax.servlet.jsp.JspWriter) StringWriter(java.io.StringWriter) JspWriter(javax.servlet.jsp.JspWriter) Writer(java.io.Writer)

Aggregations

JspFragment (javax.servlet.jsp.tagext.JspFragment)11 JspException (javax.servlet.jsp.JspException)5 JspContext (javax.servlet.jsp.JspContext)4 JspWriter (javax.servlet.jsp.JspWriter)4 IOException (java.io.IOException)2 Writer (java.io.Writer)2 TemplateException (freemarker.template.TemplateException)1 IntrospectionException (java.beans.IntrospectionException)1 StringWriter (java.io.StringWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 StringTokenizer (java.util.StringTokenizer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PageContext (javax.servlet.jsp.PageContext)1 JspTag (javax.servlet.jsp.tagext.JspTag)1 SimpleTag (javax.servlet.jsp.tagext.SimpleTag)1 LoopIterator (jodd.util.LoopIterator)1