/** This generates the HTML for the tag. * @param out The JspWriter object. * @param bodyContent The BodyContent object. * @throws IOException if any I/O error occurs. */ public void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException { // clear the body content for the next time through. bodyContent.clearBody(); // get the model TableModel model = null; try { model = (TableModel) TagHelper.getModel(pageContext, getField(), TAG_NAME); } catch (ClassCastException e) { String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField(); log.error(str, e); throw new JspWriteRuntimeException(str, e); } if (model != null) { // write out the html String idPrefix = getHtmlIdPrefix(); out.println( getHtml(idPrefix, model)); } }
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]; }
/** * Write the specified text as the response to the writer associated with * the body content for the tag within which we are currently nested. * * @param pageContext The PageContext object for this page * @param text The text to be written * * @exception JspException if an input/output error occurs (already saved) */ public void writePrevious(PageContext pageContext, String text) throws JspException { JspWriter writer = pageContext.getOut(); if (writer instanceof BodyContent) { writer = ((BodyContent) writer).getEnclosingWriter(); } try { writer.print(text); } catch (IOException e) { TagUtils.getInstance().saveException(pageContext, e); throw new JspException (messages.getMessage("write.io", e.toString())); } }
/** * Process the start of this tag. * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String serverName = (this.server == null) ? request.getServerName() : this.server; String baseTag = renderBaseElement( request.getScheme(), serverName, request.getServerPort(), request.getRequestURI()); JspWriter out = pageContext.getOut(); try { out.write(baseTag); } catch (IOException e) { pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw new JspException(messages.getMessage("common.io", e.toString())); } return EVAL_BODY_INCLUDE; }
/** This concludes the html of the Form tag. * @throws JspException if any error occurs. * @return EVAL_PAGE if the JSP engine should continue evaluating the JSP page, otherwise return SKIP_PAGE. */ public int doEndTag() throws JspException { // Note: popping the nested component stack here causes runtime problems. try { JspWriter writer = pageContext.getOut(); doEndTagExt1(writer); int i = super.doEndTag(); doEndTagExt2(writer); return i; } catch (IOException e) { throw new JspException("error in FormTag: " + e); } finally { // Remove from stack CustomTag.popParent(this,pageContext); } }
/** Looks up the request stream for input parameters and then generates appropriate metaData. */ public static void perform(HttpServletRequest request, JspWriter out, ServletContext servletContext) throws Exception { // Create a parameter Map from the input request Map<String, String> parameters = getParameters(request); if (log.isDebugEnabled()) log.debug("Input: " + parameters); // Error out if parameters are not passed if (parameters == null) { String m = "MetaData cannot be generated since parameters have not been passed"; log.error(m); throw new IllegalArgumentException(m); } // Obtain metaData String metaData = c_enableCaching ? obtainMetaData(parameters, servletContext) : generateMetaData(parameters, servletContext); out.print(metaData); }
/** * Does two things: * <ul> * <li>Stops the page if the corresponding attribute has been set</li> * <li>Prints a message another tag encloses this one.</li> * </ul> */ public int doEndTag() throws JspTagException { //get the parent if any Tag parent = this.getParent(); if (parent != null) { try { JspWriter out = this.pageContext.getOut(); out.println("This tag has a parent. <BR>"); } catch (IOException e) { throw new JspTagException(e.getMessage()); } } if (this.stopPage) { return Tag.SKIP_PAGE; } return Tag.EVAL_PAGE; }
/** * Perform a RequestDispatcher.include() operation, with optional flushing * of the response beforehand. * * @param request The servlet request we are processing * @param response The servlet response we are processing * @param relativePath The relative path of the resource to be included * @param out The Writer to whom we are currently writing * @param flush Should we flush before the include is processed? * * @exception IOException if thrown by the included servlet * @exception ServletException if thrown by the included servlet */ public static void include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush) throws IOException, ServletException { if (flush && !(out instanceof BodyContent)) out.flush(); // FIXME - It is tempting to use request.getRequestDispatcher() to // resolve a relative path directly, but Catalina currently does not // take into account whether the caller is inside a RequestDispatcher // include or not. Whether Catalina *should* take that into account // is a spec issue currently under review. In the mean time, // replicate Jasper's previous behavior String resourcePath = getContextRelativePath(request, relativePath); RequestDispatcher rd = request.getRequestDispatcher(resourcePath); rd.include(request, new ServletResponseWrapperInclude(response, out)); }
/** This generates the HTML for the tag. * @param out The JspWriter object. * @param bodyContent The BodyContent object. * @throws IOException if any I/O error occurs. */ public void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException { if (isFirstPass()) // Write the main table tag, the table column headings, and start the table body out.println( getInitialHtml() ); // Write out the start and end of the rows. out.println( getRowStartHtml() ); if (m_hasRows) out.println( processRow()); out.println( getRowEndingHtml() ); // clear the body content for the next time through. bodyContent.clearBody(); // Increment the RowNo ++m_rowNo; //Reset the column counters m_currColumnNo = 0; m_currColName = null; }
@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(); }
@Override protected int doStartTagInternal() throws Exception { try { String avatarUrl; String id = userId; String avatar = this.avatar; if (current || id == null) { DiscordUserDetails details = SecurityUtils.getCurrentUser(); if (details != null) { id = details.getId(); avatar = details.getAvatar(); } } avatarUrl = AvatarType.USER.getUrl(id, avatar); JspWriter out = pageContext.getOut(); out.write(avatarUrl); } catch (Exception ex) { throw new JspException(ex); } return SKIP_BODY; }
@Override protected int doStartTagInternal() throws Exception { try { String result = code; Long serverId = (Long) pageContext.getRequest().getAttribute("serverId"); if (serverId != null) { Locale locale = (Locale) pageContext.getAttribute(LOCALE_ATTR); ApplicationContext context = getRequestContext().getWebApplicationContext(); if (locale == null) { ContextService contextService = context.getBean(ContextService.class); locale = contextService.getLocale(serverId); pageContext.setAttribute(LOCALE_ATTR, locale); } result = context.getMessage(code, null, locale); } if (StringUtils.isNotEmpty(var)) { pageContext.setAttribute(var, result); } else { JspWriter out = pageContext.getOut(); out.write(result); } } catch (Exception ex) { throw new JspException(ex); } return SKIP_BODY; }
/** .//GEN-BEGIN:doAfterbody * * * 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. * @throws JspException * @throws JspException */ public int doAfterBody() throws JspException, JspException { try { // // This code is generated for tags whose bodyContent is "JSP" // JspWriter out = getPreviousOut(); BodyContent bodyContent = getBodyContent(); writeTagBodyContent(out, bodyContent); } catch (Exception ex) { throw new JspException("error in FunctionGuardTag: " + ex); } if (theBodyShouldBeEvaluatedAgain()) { return EVAL_BODY_AGAIN; } else { return SKIP_BODY; } }
/** .//GEN-BEGIN:doAfterbody * * * 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. * @throws JspException */ public int doAfterBody() throws JspException { try { // // This code is generated for tags whose bodyContent is "JSP" // JspWriter out = getPreviousOut(); BodyContent bodyContent = getBodyContent(); writeTagBodyContent(out, bodyContent); } catch (Exception ex) { throw new JspException("error in ComponentGuardTag: " + ex); } if (theBodyShouldBeEvaluatedAgain()) { return EVAL_BODY_AGAIN; } else { return SKIP_BODY; } }
/** The HTML is generated in this end tag, assuming the underlying field * is not read-only or hidden */ public void otherDoEndTagOperations() throws JspException { super.otherDoEndTagOperations(); if (getPropertyRuleIntrospector() == null || (getPropertyRuleIntrospector() != null && !getPropertyRuleIntrospector().isHidden() && !getPropertyRuleIntrospector().isReadOnly() ) ) { try { JspWriter out = pageContext.getOut(); out.println( getHtml() ); } catch (IOException e) { String str = "Exception in writing the " + TAG_NAME; log.error(str, e); throw new JspWriteRuntimeException(str, e); } } else { log.debug(TAG_NAME + " Not displayed as field " + getField() + " is hidden or read-only"); } }
private void wrapSpan(JspWriter out, String title, int status) throws IOException { if (status == 1) { out.append("<li class='active'>"); } else if (status == -1) { out.append("<li class='disabled'>"); } else { out.append("<li>"); } out.append("<a href='javascript:void(0);'>"); out.append(title); out.append("</a></li>"); }
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; } } }
/** * Constructor. */ public BodyContentImpl(JspWriter enclosingWriter) { super(enclosingWriter); cb = new char[Constants.DEFAULT_TAG_BUFFER_SIZE]; bufferSize = cb.length; nextChar = 0; closed = false; }
/** This method will write out the hidden-fields */ private void doEndTagExt1(JspWriter writer) throws IOException { Object formObj = pageContext.findAttribute(getBeanName()); if(formObj != null && formObj instanceof FormBase) { FormBase f = (FormBase) formObj; StringBuffer buf = new StringBuffer(); buf.append("<input type='hidden' name='" + PARAMETER_COMPONENT_ID + "' value='" + (f.getComponent()==null ? "" : f.getComponent().getComponentId() ) + "'>\n"); buf.append("<input type='hidden' name='" + PARAMETER_EVENT_ID + "' value=''>\n"); buf.append("<input type='hidden' id='" + PARAMETER_DATESTAMP_ID + "' value='" + m_dateTime.timeInMillis() + "'>\n"); // buf.append("<input type=\"hidden\" name=\"" + PARAMETER_TOKEN_ID + "\" value=\"" + // (UserSession.getUserSession((HttpServletRequest) pageContext.getRequest()).getCurrentToken()) + "\">\n"); buf.append("</span>"); writer.println(buf.toString()); } }
/** . * 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 { if (log.isDebugEnabled()) log.debug(this.NAME+".doAfterBody: START. pageContext="+pageContext+ ", BodyContent="+getBodyContent() ); if(IBodyTag.class.isInstance(this)) { // We should output the body content BodyContent bodyContent = getBodyContent(); if (log.isDebugEnabled()) log.debug(this.NAME+".doAfterBody: Got Body Size = " + (bodyContent.getString() == null ? "null" : ""+bodyContent.getString().length())); try { JspWriter out = getPreviousOut(); writeTagBodyContent(out, bodyContent); } catch (IOException ex) { log.error(this.NAME + ".doAfterBody(): Error on "+this, ex); throw new JspException("Error in " + this.NAME + ".doAfterBody() on "+this); } } if (theBodyShouldBeEvaluatedAgain()) { return EVAL_BODY_AGAIN; } else { return SKIP_BODY; } }
public void doTag() throws JspException, IOException { JspWriter out = getJspContext().getOut(); for( int i = 0; i < keys.size(); i++ ) { String key = (String)keys.get( i ); Object value = values.get( i ); out.println( "<li>" + key + " = " + value + "</li>" ); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PageContext pageContext = JspFactory.getDefaultFactory().getPageContext( this, req, resp, null, false, JspWriter.DEFAULT_BUFFER, true); JspWriter out = pageContext.getOut(); if (Constants.DEFAULT_BUFFER_SIZE == out.getBufferSize()) { resp.getWriter().println("OK"); } else { resp.getWriter().println("FAIL"); } }
public JspWriter popBody() { depth--; if (depth >= 0) { out = outs[depth]; } else { out = baseOut; } // Update the value of the "out" attribute in the page scope // attribute namespace of this PageContext setAttribute(OUT, out); return out; }
/** * Render the JavaScript for to perform validations based on the form name. * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { JspWriter writer = pageContext.getOut(); try { writer.print(this.renderJavascript()); } catch (IOException e) { throw new JspException(e.getMessage()); } return EVAL_BODY_TAG; }
/** * Render the end of this form. * * @exception JspException if a JSP exception has occurred */ public int doEndTag() throws JspException { // Remove the page scope attributes we created pageContext.removeAttribute(Constants.BEAN_KEY, PageContext.REQUEST_SCOPE); pageContext.removeAttribute(Constants.FORM_KEY, PageContext.REQUEST_SCOPE); // Render a tag representing the end of our current form StringBuffer results = new StringBuffer("</form>"); // Render JavaScript to set the input focus if required if (this.focus != null) { results.append(this.renderFocusJavascript()); } // Print this value to our output writer JspWriter writer = pageContext.getOut(); try { writer.print(results.toString()); } catch (IOException e) { throw new JspException(messages.getMessage("common.io", e.toString())); } // Continue processing this page return (EVAL_PAGE); }
@Override public int doEndTag() throws JspException { String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL); serverURL = serverURL == null ? null : serverURL.trim(); try { if (userId != null && userId.length() > 0) { String code = null; HashMap<String, String> cache = getPortraitCache(); code = cache.get(userId); if (code == null) { Integer userIdInt = Integer.decode(userId); User user = (User) getUserManagementService().findById(User.class, userIdInt); boolean isHover = (hover != null ? Boolean.valueOf(hover) : false); if ( isHover ) { code = buildHoverUrl(user); } else { code = buildDivUrl(user); } cache.put(userId, code); } JspWriter writer = pageContext.getOut(); writer.print(code); } } catch (NumberFormatException nfe) { PortraitTag.log.error("PortraitId unable to write out portrait details as userId is invalid. " + userId, nfe); } catch (IOException ioe) { PortraitTag.log.error( "PortraitId unable to write out portrait details due to IOException. UserId is " + userId, ioe); } catch (Exception e) { PortraitTag.log.error( "PortraitId unable to write out portrait details due to an exception. UserId is " + userId, e); } return Tag.SKIP_BODY; }
private void writeString(String output) { try { JspWriter writer = pageContext.getOut(); writer.println(output); } catch (IOException e) { log.error("HTML tag unable to write out HTML details due to IOException.", e); // don't throw a JSPException as we want the system to still function, well, best // the page can without the html tag! } }
@Override public int doStartTag() throws JspException { JspWriter writer = pageContext.getOut(); try { writer.print(Configuration.get(getKey())); } catch (IOException e) { log.error("Error in configuration tag", e); throw new JspException(e); } return SKIP_BODY; }
/** This method will write out all the header-info for the widgets in the form */ private void doEndTagExt2(JspWriter writer) throws IOException { // Display guarded page section writer.println(determineGuardedHtml()); // Write out and footer code needed by the widgets for (Iterator iter=m_footerCache.keySet().iterator(); iter.hasNext(); ) { Object key = iter.next(); Object javaScript = m_footerCache.get(key); if(javaScript!=null) { writer.println(javaScript); if(log.isDebugEnabled()) log.debug("Write Footer Code For Widget " + key + "\n" + javaScript); } } }
/** This generates the HTML for the tag, unless there is a layout, in which case it is sent there. * @param out The JspWriter object. * @param bodyContent The BodyContent object. * @throws IOException if any I/O error occurs. */ public void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException { //log.debug("writeTagBodyContent: " + this.toString()); if (m_layoutTag != null) { m_layoutTag.addSectionContent(m_id,bodyContent.getString()); } else { // Generate a folding section if (m_containsContent || (!m_hideIfNoWidgets)) { out.print( LayoutTag.createFoldingSection( getId(), getLabel(), getLabelEditorLink(), isClosed(), bodyContent.getString())); } } // clear the body content for the next time through. bodyContent.clearBody(); }
public void htmlTableForInstructionalOffering( SessionContext context, ClassAssignmentProxy classAssignment, ExamAssignmentProxy examAssignment, Long instructionalOfferingId, JspWriter outputStream, Comparator classComparator){ if (instructionalOfferingId != null) { InstructionalOfferingDAO idao = new InstructionalOfferingDAO(); InstructionalOffering io = idao.get(instructionalOfferingId); Long subjectAreaId = io.getControllingCourseOffering().getSubjectArea().getUniqueId(); // Get Configuration TreeSet ts = new TreeSet(); ts.add(io); WebInstructionalOfferingTableBuilder iotbl = new WebInstructionalOfferingTableBuilder(); iotbl.setDisplayDistributionPrefs(false); setVisibleColumns(COLUMNS); htmlTableForInstructionalOfferings( context, classAssignment, examAssignment, ts, subjectAreaId, false, false, outputStream, classComparator, null); } }
public void htmlTableForInstructionalOfferings( SessionContext context, ClassAssignmentProxy classAssignment, ExamAssignmentProxy examAssignment, InstructionalOfferingListForm form, String[] subjectAreaIds, boolean displayHeader, boolean allCoursesAreGiven, JspWriter outputStream, String backType, String backId){ setBackType(backType); setBackId(backId); this.setVisibleColumns(form); List<Long> navigationOfferingIds = new ArrayList<Long>(); for (String subjectAreaId: subjectAreaIds) { htmlTableForInstructionalOfferings(context, classAssignment, examAssignment, form.getInstructionalOfferings(Long.valueOf(subjectAreaId)), Long.valueOf(subjectAreaId), displayHeader, allCoursesAreGiven, outputStream, new ClassCourseComparator(form.getSortBy(), classAssignment, false), navigationOfferingIds ); } }
public void htmlTableForInstructionalOfferingConfig( Vector subpartIds, ClassAssignmentProxy classAssignment, ExamAssignmentProxy examAssignment, Long instrOfferingConfigId, SessionContext context, JspWriter outputStream){ if (instrOfferingConfigId != null){ InstrOfferingConfigDAO iocDao = new InstrOfferingConfigDAO(); InstrOfferingConfig ioc = iocDao.get(instrOfferingConfigId); this.htmlTableForInstructionalOfferingConfig(subpartIds, classAssignment, examAssignment, ioc, context, outputStream); } }
/** Called from the doEndTag() */ public void otherDoEndTagOperations() throws JspException { super.otherDoEndTagOperations(); // Generate the HTML if (!m_propertyRuleIntrospector.isHidden() && m_model != null) { String html = null; if (m_displayOnly) { // Just display the text for a readOnly field html = getDisplayOnlyHtml(); } else { String classPrefix = m_propertyRuleIntrospector.isMandatory() ? "<span class=\"dropdownMandatoryPrefix\"> </span>" : "<span class=\"dropdownOptionalPrefix\"> </span>"; String classSuffix = m_propertyRuleIntrospector.isMandatory() ? "<span class=\"dropdownMandatorySuffix\"> </span>" : "<span class=\"dropdownOptionalSuffix\"> </span>"; html = classPrefix + getHtml() + classSuffix; html += getJavascript(); } if (html != null) { // Write the HTML JspWriter out = pageContext.getOut(); try { out.print(html); } catch (IOException e) { String str = "Exception in writing the " + TAG_NAME; log.error(str, e); throw new JspWriteRuntimeException(str, e); } } } }
public final void initialize(ServletContext servletcontext, HttpSession httpsession, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, JspWriter jspwriter) throws ServletException { m_application = servletcontext; m_request = httpservletrequest; m_response = httpservletresponse; }
/** * Prints the names and values of everything in page scope to the response, * along with the body (if showBody is set to <code>true</code>). */ public int doStartTag() throws JspTagException { Enumeration names = pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE); JspWriter out = pageContext.getOut(); try { out.println("The following attributes exist in page scope: <BR>"); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Object attribute = pageContext.getAttribute(name); out.println(name + " = " + attribute + " <BR>"); } if (this.showBody) { out.println("Body Content Follows: <BR>"); return EVAL_BODY_INCLUDE; } } catch (IOException e) { throw new JspTagException(e.getMessage()); } return SKIP_BODY; }
@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("<"); 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(); }
/** This generates the HTML for the tag. * @param out The JspWriter object. * @param bodyContent The BodyContent object. * @throws IOException if any I/O error occurs. */ public void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException { // // The bodycontent will NOT be written.. since its just expected to invoke the addOption() method //bodyContent.writeOut(out); // clear the body content for the next time through. bodyContent.clearBody(); }