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);
}
}
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("]");
}
}
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);
}
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);
}
}
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);
}
}
Aggregations