Java Code Examples for javax.servlet.jsp.JspWriter

The following examples show how to use javax.servlet.jsp.JspWriter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: packagedrone   Source File: PageContextImpl.java    License: Eclipse Public License 1.0 7 votes vote down vote up
public JspWriter pushBody(Writer writer) {
       depth++;
       if (depth >= outs.length) {
           BodyContentImpl[] newOuts = new BodyContentImpl[depth + 1];
           for (int i=0; i<outs.length; i++) {
               newOuts[i] = outs[i];
           }
           newOuts[depth] = new BodyContentImpl(out);
           outs = newOuts;
       }

outs[depth].setWriter(writer);
       out = outs[depth];

// Update the value of the "out" attribute in the page scope
// attribute namespace of this PageContext
setAttribute(OUT, out);

       return outs[depth];
   }
 
Example 2
Source Project: Tomcat8-Source-Read   Source File: ValuesTag.java    License: MIT License 6 votes vote down vote up
@Override
public int doEndTag() throws JspException {
    JspWriter out = pageContext.getOut();

    try {
        if (!"-1".equals(objectValue)) {
            out.print(objectValue);
        } else if (!"-1".equals(stringValue)) {
            out.print(stringValue);
        } else if (longValue != -1) {
            out.print(longValue);
        } else if (doubleValue != -1) {
            out.print(doubleValue);
        } else {
            out.print("-1");
        }
    } catch (IOException ex) {
        throw new JspTagException("IOException: " + ex.toString(), ex);
    }
    return super.doEndTag();
}
 
Example 3
Source Project: sinavi-jfw   Source File: JseErrorsTag.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void doTag() throws JspException, IOException {
    JspWriter out = getJspContext().getOut();
    Scope[] scopes = judge();
    if (scopes.length == 0) return;
    
    StringBuilder buffer = new StringBuilder();
    for (Scope s : scopes) {
        printMessages(buffer, s);
    }

    if (!onlyMsg && buffer.length() > 0) {
        out.print(HEADER + buffer.toString() + FOOTER);
    } else {
        out.print(buffer.toString());
    }
}
 
Example 4
Source Project: lams   Source File: LAMSURLTag.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
   public int doStartTag() throws JspException {
String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL);
serverURL = (serverURL != null ? serverURL.trim() : null);
if (serverURL != null && serverURL.length() > 0) {
    JspWriter writer = pageContext.getOut();
    try {
	writer.print(serverURL);
    } catch (IOException e) {
	log.error("ServerURLTag unable to write out server URL due to IOException. ", e);
	throw new JspException(e);
    }
} else {
    log.warn("ServerURLTag unable to write out server URL as it is missing from the configuration file.");
}

return SKIP_BODY;
   }
 
Example 5
Source Project: Tomcat8-Source-Read   Source File: PageContextImpl.java    License: MIT License 6 votes vote down vote up
@Override
public JspWriter pushBody(Writer writer) {
    depth++;
    if (depth >= outs.length) {
        BodyContentImpl[] newOuts = new BodyContentImpl[depth + 1];
        for (int i = 0; i < outs.length; i++) {
            newOuts[i] = outs[i];
        }
        newOuts[depth] = new BodyContentImpl(out);
        outs = newOuts;
    }

    outs[depth].setWriter(writer);
    out = outs[depth];

    // Update the value of the "out" attribute in the page scope
    // attribute namespace of this PageContext
    setAttribute(OUT, out);

    return outs[depth];
}
 
Example 6
Source Project: spacewalk   Source File: ColumnTag.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int doEndTag() throws JspException {
    JspWriter out = null;
    try {
        out = pageContext.getOut();

        if (!showHeader()) {
            if (showUrl()) {
                out.print(href.renderCloseTag());
            }
            out.print(td.renderCloseTag());
        }

        return Tag.EVAL_BODY_INCLUDE;
    }
    catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
}
 
Example 7
Source Project: jeecg   Source File: CkeditorTag.java    License: Apache License 2.0 6 votes vote down vote up
public int doEndTag() throws JspTagException {
	JspWriter out = null;
	try {
		out = this.pageContext.getOut();
		out.print(end().toString());
		out.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}finally{
		try {
			out.clear();
			out.close();
		} catch (Exception e2) {
		}
	}
	return EVAL_PAGE;
}
 
Example 8
Source Project: uyuni   Source File: ListTag.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public int doStartTag() throws JspException {
    JspWriter out = null;

    //if legend was set, process legends
    if (legend != null) {
        setLegends(legend);
    }

    try {
        out = pageContext.getOut();

        if (pageList == null || pageList.isEmpty()) {
            renderEmptyString(out);
            return SKIP_BODY;
        }

        return EVAL_BODY_INCLUDE;
    }
    catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
}
 
Example 9
Source Project: netbeans   Source File: SumBodyTagHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fill in this method to process the body content of the tag.
 * You only need to do this if the tag's BodyContent property
 * is set to "JSP" or "tagdependent."
 * If the tag's bodyContent is set to "empty," then this method
 * will not be called.
 */
private void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException {
    //
    // TODO: insert code to write html before writing the body content.
    // e.g.:
    //
    out.println("<p>");
    out.println("Sum of " + x + " and " + y + " is " + (x+y));
    out.println("<br/>");
    
    //
    // write the body content (after processing by the JSP engine) on the output Writer
    //
    bodyContent.writeOut(out);
    
    out.println("<br/>");
    out.println("END of sum");
    out.println("</p>");
    
    
    // clear the body content for the next time through.
    bodyContent.clearBody();
}
 
Example 10
Source Project: tomcatsrc   Source File: ValuesTag.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int doEndTag() throws JspException {
    JspWriter out = pageContext.getOut();

    try {
        if (!"-1".equals(objectValue)) {
            out.print(objectValue);
        } else if (!"-1".equals(stringValue)) {
            out.print(stringValue);
        } else if (longValue != -1) {
            out.print(longValue);
        } else if (doubleValue != -1) {
            out.print(doubleValue);
        } else {
            out.print("-1");
        }
    } catch (IOException ex) {
        throw new JspTagException("IOException: " + ex.toString(), ex);
    }
    return super.doEndTag();
}
 
Example 11
Source Project: anyline   Source File: SubString.java    License: Apache License 2.0 6 votes vote down vote up
public int doEndTag() throws JspException { 
	//输出 
	JspWriter out = pageContext.getOut(); 
	String text = body; 
	if(null != text){
		int range[] = BasicUtil.range(begin, end, qty, text.length());
		text = text.substring(range[0],range[1]);
		try{ 
			out.print(text); 
		}catch(Exception e){ 
 
		}finally{ 
			release(); 
		} 
	} 
       return EVAL_PAGE;    
}
 
Example 12
Source Project: jeewx   Source File: FormValidationTag.java    License: Apache License 2.0 6 votes vote down vote up
public int doStartTag() throws JspException {
	try {
		JspWriter out = this.pageContext.getOut();
		StringBuffer sb = new StringBuffer();
		if ("div".equals(layout)) {
			sb.append("<div id=\"content\">");
			sb.append("<div id=\"wrapper\">");
			sb.append("<div id=\"steps\">");
		}
		sb.append("<form id=\"" + formid + "\" action=\"" + action + "\" name=\"" + formid + "\" method=\"post\">");
		if ("btn_sub".equals(btnsub) && dialog)
			sb.append("<input type=\"hidden\" id=\"" + btnsub + "\" class=\"" + btnsub + "\"/>");
		out.print(sb.toString());
		out.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return EVAL_PAGE;
}
 
Example 13
Source Project: jeecg   Source File: DictSelectTag.java    License: Apache License 2.0 6 votes vote down vote up
public int doEndTag() throws JspTagException {
	JspWriter out = null;
	try {
		out = this.pageContext.getOut();
		out.print(end().toString());
		out.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}finally{
		try {
			out.clear();
			out.close();
			end().setLength(0);
		} catch (Exception e2) {
		}
	}
	return EVAL_PAGE;
}
 
Example 14
Source Project: lams   Source File: WebAppURLTag.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
   public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

String path = WebUtil.getBaseServerURL() + request.getContextPath();
if (!path.endsWith("/")) {
    path += "/";
}

try {
    JspWriter writer = pageContext.getOut();
    writer.print(path);
} catch (IOException e) {
    WebAppURLTag.log.error("ServerURLTag unable to write out server URL due to IOException. ", e);
    throw new JspException(e);
}
return Tag.SKIP_BODY;
   }
 
Example 15
Source Project: attic-rave   Source File: ScriptTagTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void doStartTag_skip() throws IOException, JspException {

    List<String> strings = new ArrayList<String>();
    strings.add(SCRIPT);
    strings.add(SCRIPT_2);
    expect(service.getScriptBlocks(ScriptLocation.BEFORE_RAVE, context)).andReturn(null);
    replay(service);

    JspWriter writer = createNiceMock(JspWriter.class);
    replay(writer);

    expect(pageContext.getOut()).andReturn(writer).anyTimes();
    replay(pageContext);

    tag.setLocation(ScriptLocation.BEFORE_RAVE);
    int result = tag.doStartTag();
    assertThat(result, is(equalTo(TagSupport.SKIP_BODY)));
    verify(writer);
}
 
Example 16
Source Project: Bootstrap.jsp   Source File: Modal.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {
	super.doTag();
	if (this.show != null) {
		if (!("true".equals(this.show) || "false".equals(this.show))) {
			final JspWriter writer = super.getJspContext().getOut();
            writer.println("<script type=\"text/javascript\">");
            writer.print("$(document).on('");
            writer.print(this.show);
            writer.println("', function() { ");
            writer.print("$('.modal[data-show=\"");
            writer.print(this.show);
            writer.println("\"]:hidden').modal();");
            writer.println("});");
            writer.println("</script>");
		}
	}
}
 
Example 17
Source Project: RDFS   Source File: JobTrackerJspHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generates an XML-formatted block that summarizes the state of the JobTracker.
 */
public void generateSummaryTable(JspWriter out,
                                 JobTracker tracker) throws IOException {
  ClusterStatus status = tracker.getClusterStatus();
  int maxMapTasks = status.getMaxMapTasks();
  int maxReduceTasks = status.getMaxReduceTasks();
  int numTaskTrackers = status.getTaskTrackers();
  String tasksPerNodeStr;
  if (numTaskTrackers > 0) {
    double tasksPerNodePct = (double) (maxMapTasks + maxReduceTasks) / (double) numTaskTrackers;
    tasksPerNodeStr = percentFormat.format(tasksPerNodePct);
  } else {
    tasksPerNodeStr = "-";
  }
  out.print("<maps>" + status.getMapTasks() + "</maps>\n" +
          "<reduces>" + status.getReduceTasks() + "</reduces>\n" +
          "<total_submissions>" + tracker.getTotalSubmissions() + "</total_submissions>\n" +
          "<nodes>" + status.getTaskTrackers() + "</nodes>\n" +
          "<map_task_capacity>" + status.getMaxMapTasks() + "</map_task_capacity>\n" +
          "<reduce_task_capacity>" + status.getMaxReduceTasks() + "</reduce_task_capacity>\n" +
          "<avg_tasks_per_node>" + tasksPerNodeStr + "</avg_tasks_per_node>\n");
}
 
Example 18
Source Project: uyuni   Source File: ToolTipTag.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int doStartTag() throws JspException {
    LocalizationService ls = LocalizationService.getInstance();
    HtmlTag strong = new HtmlTag("strong");
    strong.addBody(ls.getMessage(geTypeKey()) + ": ");

    JspWriter writer = pageContext.getOut();
    try {
        writer.write("<p class=\"small-text\">");
        writer.write(strong.render());
        if (!StringUtils.isBlank(key)) {
            writer.write(ls.getMessage(key));
        }
        return EVAL_BODY_INCLUDE;
    }
    catch (IOException e) {
        throw new JspException(e);
    }

}
 
Example 19
Source Project: uyuni   Source File: ConfigChannelTag.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int doEndTag() throws JspException {
    StringBuilder result = new StringBuilder();
    if (nolink || id == null) {
        result.append(writeIcon());
        result.append(name);
    }
    else {
        result.append("<a href=\"" +
                    ConfigChannelTag.makeConfigChannelUrl(id) + "\">");
        result.append(writeIcon());
        result.append(StringEscapeUtils.escapeXml(name) + "</a>");
    }
    JspWriter writer = pageContext.getOut();
    try {
        writer.write(result.toString());
    }
    catch (IOException e) {
        throw new JspException(e);
    }
    return BodyTagSupport.SKIP_BODY;
}
 
Example 20
Source Project: jeecg   Source File: UploadTag.java    License: Apache License 2.0 6 votes vote down vote up
public int doEndTag() throws JspTagException {
	JspWriter out = null;
	try {
		out = this.pageContext.getOut();
		out.print(end().toString());
		out.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}finally{
		try {
			out.clear();
			out.close();
		} catch (Exception e2) {
		}
	}
	return EVAL_PAGE;
}
 
Example 21
Source Project: jstorm   Source File: SubMetricTag.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void doTag() throws JspException {
    JspWriter out = getJspContext().getOut();
    try {
        StringBuilder sb = new StringBuilder();
        if (metric.size() > 0) {
            if (isHidden) {
                sb.append(String.format("<div class='%s hidden'>", clazz));
            } else {
                sb.append(String.format("<div class='%s'>", clazz));
            }
            for (String parent : parentComp) {
                String key = metricName + "@" + parent;
                String v = metric.get(key);
                if (v != null) {
                    sb.append(v);
                }
                sb.append("<br/>");
            }
            sb.append("</div>");
            out.write(sb.toString());
        }
    } catch (IOException e) {
        throw new JspException("Error: " + e.getMessage());
    }
}
 
Example 22
Source Project: netbeans   Source File: SumBodyTagHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method is called after the JSP engine processes the body content of the tag.
 * @return EVAL_BODY_AGAIN if the JSP engine should evaluate the tag body again, otherwise return SKIP_BODY.
 * This method is automatically generated. Do not modify this method.
 * Instead, modify the methods that this method calls.
 */
public int doAfterBody() throws JspException {
    try {
        //
        // This code is generated for tags whose bodyContent is "JSP"
        //
        BodyContent bodyContent = getBodyContent();
        JspWriter out = bodyContent.getEnclosingWriter();
        
        writeTagBodyContent(out, bodyContent);
    } catch (Exception ex) {
        handleBodyContentException(ex);
    }
    
    if (theBodyShouldBeEvaluatedAgain()) {
        return EVAL_BODY_AGAIN;
    } else {
        return SKIP_BODY;
    }
}
 
Example 23
Source Project: portals-pluto   Source File: NamespaceTag.java    License: Apache License 2.0 6 votes vote down vote up
public int doStartTag() throws JspException {
	
	PortletResponse portletResponse = (PortletResponse) pageContext.getRequest()
        .getAttribute(Constants.PORTLET_RESPONSE);
	
    String namespace = portletResponse.getNamespace();
    
    JspWriter writer = pageContext.getOut();
    
    try {
        writer.print(namespace);
    } catch (IOException ioe) {
        throw new JspException(
            "Unable to write namespace", ioe
        );
    }
    
    return SKIP_BODY;
}
 
Example 24
Source Project: velocity-tools   Source File: VelocityBodyContent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param jspWriter The JSP writer to be used by default.
 * @param block The block to wrap.
 * @param context The directive context.
 */
public VelocityBodyContent(JspWriter jspWriter, ASTBlock block,
        InternalContextAdapter context)
{
    super(jspWriter);
    this.block = block;
    this.context = context;
}
 
Example 25
Source Project: tomcatsrc   Source File: Out.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean output(JspWriter out, Object input, String value,
        String defaultValue, boolean escapeXml) throws IOException {
    if (input instanceof Reader) {
        char[] buffer = new char[8096];
        int read = 0;
        while (read != -1) {
            read = ((Reader) input).read(buffer);
            if (read != -1) {
                if (escapeXml) {
                    String escaped = Util.escapeXml(buffer, read);
                    if (escaped == null) {
                        out.write(buffer, 0, read);
                    } else {
                        out.print(escaped);
                    }
                } else {
                    out.write(buffer, 0, read);
                }
            }
        }
        return true;
    } else {
        String v = value != null ? value : defaultValue;
        if (v != null) {
            if(escapeXml){
                v = Util.escapeXml(v);
            }
            out.write(v);
            return true;
        } else {
            return false;
        }
    }
}
 
Example 26
Source Project: Openfire   Source File: FlashMessageTag.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void doTag() throws IOException {
    final PageContext pageContext = (PageContext) getJspContext();
    final JspWriter jspWriter = pageContext.getOut();
    final HttpSession session = pageContext.getSession();

    for (final String flash : new String[]{SUCCESS_MESSAGE_KEY, WARNING_MESSAGE_KEY, ERROR_MESSAGE_KEY}) {
        final Object flashValue = session.getAttribute(flash);
        if (flashValue != null) {
            jspWriter.append(String.format("<div class='%s'>%s</div>", flash, flashValue));
            session.setAttribute(flash, null);
        }
    }

}
 
Example 27
/**
 * Renders the header for the accounting line table to the screen
 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
 */
public void render(PageContext pageContext, Tag parentTag) throws JspException {
    JspWriter out = pageContext.getOut();
    
    try {
        out.write(buildDivStart());
        out.write(buildTableStart());
        out.write(buildSubheadingWithDetailToggleRowBeginning());
        renderHideDetails(pageContext, parentTag);
        out.write(buildSubheadingWithDetailToggleRowEnding());
    }
    catch (IOException ioe) {
        throw new JspException("Difficulty rendering AccountingLineTableHeader", ioe);
    }
}
 
Example 28
Source Project: Tomcat8-Source-Read   Source File: JspRuntimeLibrary.java    License: MIT License 5 votes vote down vote up
public static JspWriter startBufferedBody(PageContext pageContext, BodyTag tag)
        throws JspException {
    BodyContent out = pageContext.pushBody();
    tag.setBodyContent(out);
    tag.doInitBody();
    return out;
}
 
Example 29
Source Project: lognavigator   Source File: RawContentTag.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	// Get input and ouput variables
	Reader rawContent = (Reader) pageContext.getAttribute(Constants.RAW_CONTENT_KEY, PageContext.REQUEST_SCOPE);
	JspWriter out = pageContext.getOut();
	
	try {
		// Copy input (rawContent) to output (out)
		char[] buffer = new char[StreamUtils.BUFFER_SIZE];
		int bytesRead = -1;
		while ((bytesRead = rawContent.read(buffer)) != -1) {
			String stringToWrite = new String(buffer, 0, bytesRead);
			stringToWrite = HtmlUtils.htmlEscape(stringToWrite);
			out.write(stringToWrite);
		}
		out.flush();

		return EVAL_PAGE;
	}
	catch (IOException e) {
		throw new JspException(e);
	}
	finally {
		IOUtils.closeQuietly(rawContent);
	}
}
 
Example 30
Source Project: jeewx   Source File: ChooseTag.java    License: Apache License 2.0 5 votes vote down vote up
public int doEndTag() throws JspTagException {
	try {
		JspWriter out = this.pageContext.getOut();
		out.print(end().toString());
		out.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return EVAL_PAGE;
}