Search in sources :

Example 51 with JspWriter

use of javax.servlet.jsp.JspWriter in project freemarker by apache.

the class TagTransformModel method getWriter.

public Writer getWriter(Writer out, Map args) throws TemplateModelException {
    try {
        Tag tag = (Tag) getTagInstance();
        FreeMarkerPageContext pageContext = PageContextFactory.getCurrentPageContext();
        Tag parentTag = (Tag) pageContext.peekTopTag(Tag.class);
        tag.setParent(parentTag);
        tag.setPageContext(pageContext);
        setupTag(tag, args, pageContext.getObjectWrapper());
        // If the parent of this writer is not a JspWriter itself, use
        // a little Writer-to-JspWriter adapter...
        boolean usesAdapter;
        if (out instanceof JspWriter) {
            // we'd use an assert.
            if (out != pageContext.getOut()) {
                throw new TemplateModelException("out != pageContext.getOut(). Out is " + out + " pageContext.getOut() is " + pageContext.getOut());
            }
            usesAdapter = false;
        } else {
            out = new JspWriterAdapter(out);
            pageContext.pushWriter((JspWriter) out);
            usesAdapter = true;
        }
        JspWriter w = new TagWriter(out, tag, pageContext, usesAdapter);
        pageContext.pushTopTag(tag);
        pageContext.pushWriter(w);
        return w;
    } catch (Exception e) {
        throw toTemplateModelExceptionOrRethrow(e);
    }
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) BodyTag(javax.servlet.jsp.tagext.BodyTag) Tag(javax.servlet.jsp.tagext.Tag) IterationTag(javax.servlet.jsp.tagext.IterationTag) SimpleTag(javax.servlet.jsp.tagext.SimpleTag) JspWriter(javax.servlet.jsp.JspWriter) TemplateModelException(freemarker.template.TemplateModelException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException)

Example 52 with JspWriter

use of javax.servlet.jsp.JspWriter in project freemarker by apache.

the class AttributeInfoTag method doTag.

@SuppressWarnings("boxing")
@Override
public void doTag() throws JspException, IOException {
    JspContext ctx = getJspContext();
    JspWriter out = ctx.getOut();
    final Integer scope = getScopeAsInteger();
    Object attrVal = scope == null ? ctx.getAttribute(name) : ctx.getAttribute(name, scope);
    final String formattedVal;
    if (attrVal instanceof Date) {
        formattedVal = DateUtil.dateToISO8601String((Date) attrVal, true, true, true, DateUtil.ACCURACY_SECONDS, DateUtil.UTC, new TrivialDateToISO8601CalendarFactory());
    } else {
        formattedVal = String.valueOf(attrVal);
    }
    out.write(formattedVal);
    if (attrVal != null) {
        out.write(" [");
        out.write(attrVal.getClass().getName());
        out.write("]");
    }
}
Also used : JspContext(javax.servlet.jsp.JspContext) TrivialDateToISO8601CalendarFactory(freemarker.template.utility.DateUtil.TrivialDateToISO8601CalendarFactory) JspWriter(javax.servlet.jsp.JspWriter) Date(java.util.Date)

Example 53 with JspWriter

use of javax.servlet.jsp.JspWriter 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 54 with JspWriter

use of javax.servlet.jsp.JspWriter in project com.revolsys.open by revolsys.

the class OnLoadTag method doStartTag.

/**
 * Process the start tag.
 *
 * @return SKIP_BODY
 */
@Override
public int doStartTag() throws JspException {
    try {
        final WebUiContext context = WebUiContext.get();
        if (context != null) {
            final Page page = context.getPage();
            if (page != null) {
                final JspWriter out = this.pageContext.getOut();
                final Iterator onLoads = page.getOnLoads().iterator();
                out.print("onload=\"");
                while (onLoads.hasNext()) {
                    final String onLoad = (String) onLoads.next();
                    out.print(onLoad);
                    out.print("; ");
                }
                out.print("\"");
            }
        }
        return SKIP_BODY;
    } catch (final Throwable t) {
        throw new JspTagException(t);
    }
}
Also used : Iterator(java.util.Iterator) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 55 with JspWriter

use of javax.servlet.jsp.JspWriter in project com.revolsys.open by revolsys.

the class StylesTag method doStartTag.

/**
 * Process the start tag.
 *
 * @return SKIP_BODY
 * @throws JspException If there was an exception processing the tag.
 */
@Override
public int doStartTag() throws JspException {
    try {
        final WebUiContext context = WebUiContext.get();
        if (context != null) {
            final Page page = context.getPage();
            if (page != null) {
                final Collection styles = page.getStyles();
                String contextPath = context.getContextPath();
                if (contextPath.equals("/")) {
                    contextPath = "";
                }
                final JspWriter out = this.pageContext.getOut();
                final Iterator styleIter = styles.iterator();
                while (styleIter.hasNext()) {
                    final String style = (String) styleIter.next();
                    out.print("<link rel=\"stylesheet\" href=\"");
                    out.print(style);
                    out.println("\" type=\"text/css\" />");
                }
            }
        }
        final SiteNodeController controller = (SiteNodeController) this.pageContext.findAttribute("rsWebController");
        if (controller instanceof PageController) {
            final PageController page = (PageController) controller;
            serializeElements(page.getStyles());
        }
        return SKIP_BODY;
    } catch (final Throwable t) {
        log.error(t.getMessage(), t);
        throw new JspTagException(t.getMessage(), t);
    }
}
Also used : SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) PageController(com.revolsys.ui.web.config.PageController) Iterator(java.util.Iterator) Collection(java.util.Collection) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

JspWriter (javax.servlet.jsp.JspWriter)145 IOException (java.io.IOException)72 JspException (javax.servlet.jsp.JspException)68 HttpServletRequest (javax.servlet.http.HttpServletRequest)17 JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)14 PageContext (javax.servlet.jsp.PageContext)13 Iterator (java.util.Iterator)9 Engine (org.apache.wiki.api.core.Engine)9 JspContext (javax.servlet.jsp.JspContext)8 JspTagException (javax.servlet.jsp.JspTagException)8 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)7 ArrayList (java.util.ArrayList)6 Properties (java.util.Properties)6 HttpSession (javax.servlet.http.HttpSession)5 BodyContent (javax.servlet.jsp.tagext.BodyContent)5 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)5 Page (org.apache.wiki.api.core.Page)5 HtmlCode (org.compiere.util.HtmlCode)5 MissingParametersRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)5 IPropertyRuleIntrospector (org.jaffa.rules.IPropertyRuleIntrospector)5