javax.servlet.jsp.JspWriter Java Examples

The following examples show how to use javax.servlet.jsp.JspWriter. 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 File: PageContextImpl.java    From packagedrone with 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 File: ValuesTag.java    From tomcatsrc with 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 #3
Source File: JseErrorsTag.java    From sinavi-jfw with 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 File: ColumnTag.java    From spacewalk with 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 #5
Source File: CkeditorTag.java    From jeecg with 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 #6
Source File: PageContextImpl.java    From Tomcat8-Source-Read with 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 #7
Source File: LAMSURLTag.java    From lams with 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 #8
Source File: ListTag.java    From uyuni with 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 File: SumBodyTagHandler.java    From netbeans with 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 File: NamespaceTag.java    From portals-pluto with 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 #11
Source File: SubString.java    From anyline with 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 File: FormValidationTag.java    From jeewx with 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 File: WebAppURLTag.java    From lams with 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 #14
Source File: ValuesTag.java    From Tomcat8-Source-Read with 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 #15
Source File: SumBodyTagHandler.java    From netbeans with 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 #16
Source File: SubMetricTag.java    From jstorm with 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 #17
Source File: UploadTag.java    From jeecg with 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 #18
Source File: ConfigChannelTag.java    From uyuni with 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 #19
Source File: ToolTipTag.java    From uyuni with 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 #20
Source File: JobTrackerJspHelper.java    From RDFS with 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 #21
Source File: Modal.java    From Bootstrap.jsp with 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 #22
Source File: ScriptTagTest.java    From attic-rave with 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 #23
Source File: DictSelectTag.java    From jeecg with 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 #24
Source File: RawContentTag.java    From lognavigator with 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 #25
Source File: ShowSource.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
    if ((jspFile.indexOf( ".." ) >= 0) ||
        (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/WEB-INF/") != 0) ||
        (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/META-INF/") != 0))
        throw new JspTagException("Invalid JSP file " + jspFile);

    InputStream in = pageContext.getServletContext().getResourceAsStream(
            jspFile);
    if (in == null)
        throw new JspTagException("Unable to find JSP file: " + jspFile);

    try {
        JspWriter out = pageContext.getOut();
        out.println("<body>");
        out.println("<pre>");
        for (int ch = in.read(); ch != -1; ch = in.read())
            if (ch == '<')
                out.print("&lt;");
            else
                out.print((char) ch);
        out.println("</pre>");
        out.println("</body>");
    } catch (IOException ex) {
        throw new JspTagException("IOException: " + ex.toString());
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            throw new JspTagException("Can't close inputstream: ", e);
        }
    }
    return super.doEndTag();
}
 
Example #26
Source File: JspRuntimeLibrary.java    From Tomcat8-Source-Read with 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 #27
Source File: AccountingLineTableFooterRenderer.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Renders the table footer
 * @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(buildTableEnd());
        out.write(buildKualiElementsNotifier());
        out.write(buildDivEnd());
    }
    catch (IOException ioe) {
        throw new JspException("Difficulty rendering accounting line table footer", ioe);
    }
}
 
Example #28
Source File: ReadOnlyRenderer.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
 */
@Override
public void render(PageContext pageContext, Tag parentTag) throws JspException {
    JspWriter out = pageContext.getOut();

    try {
        String value = discoverRenderValue();
        out.write(buildBeginSpan());

        if (!StringUtils.isEmpty(value)) {
            if (shouldRenderInquiryLink()) {
                out.write(buildBeginInquiryLink());
            }
            out.write(value);
            if (shouldRenderInquiryLink()) {
                out.write(buildEndInquiryLink());
            }
        } else {
            out.write(buildNonBreakingSpace());
        }

        out.write(buildEndSpan());
    }
    catch (IOException ioe) {
        throw new JspException("Difficulty rendering read only field", ioe);
    }
}
 
Example #29
Source File: DESHttpRequestParam.java    From anyline with Apache License 2.0 5 votes vote down vote up
public int doEndTag() throws JspException { 
	try{ 
		value = BasicUtil.nvl(value,body,"").toString().trim(); 
		if(null != value && !"".equals(value)){ 
			String result = ""; 
			String url = ""; 
			String split = ""; 
			if(value.contains("?")){ 
				url = value.substring(0, value.indexOf("?")); 
				value = value.substring(value.indexOf("?")+1); 
				split = "?"; 
			} 
			if(value.startsWith("&")){ 
				split = "&"; 
			} 
			String[] params = value.split("&"); 
			int size = params.length; 
			for(int i=0; i<size; i++){ 
				String param = params[i]; 
				String[] keys = param.split("="); 
				if(keys.length == 2){ 
					result += DESUtil.encryptParamKey(keys[0]) + "=" + DESUtil.encryptParamValue(keys[1]); 
					if(i<size-1){ 
						result += "&"; 
					} 
				} 
			} 
			result = url + split + result; 
			JspWriter out = pageContext.getOut(); 
			out.print(result); 
		} 
	}catch(Exception e){ 
		e.printStackTrace(); 
	}finally{ 
		release(); 
	} 
	return EVAL_PAGE;    
}
 
Example #30
Source File: PropertyTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Process the start tag for this instance.
 */
@Override
public int doStartTag() throws JspTagException {
  // get logic context tag we are nested in
  ContextTag contextTag = FrameworkUtils.getContextTag(pageContext);
  NavigatorConfigurationIF navConf = contextTag.getNavigatorConfiguration();
  // retrieve property value from navigator configuration by name
  if (propertyName != null) {
    String propertyValue = navConf.getProperty(propertyName);
    if (propertyValue != null) {
      try {
        JspWriter out = pageContext.getOut();
        out.print(propertyValue);
      } catch (IOException ioe) {
        String msg = "Error in PropertyTag: " +
          "JspWriter not there: " + ioe.getMessage();
        log.error(msg);
        throw new NavigatorRuntimeException(msg, ioe);
      }
    } else {
      log.info("Property with name '" + propertyName + "' has no value.");
    }
  } else {
    log.warn("No property name specified to ouput.");
  }
  // empty tag
  return SKIP_BODY;
}