List of usage examples for javax.servlet.jsp JspWriter print
abstract public void print(Object obj) throws IOException;
From source file:edu.cornell.mannlib.vedit.tags.ValueTag.java
public int doEndTag() throws JspException { try {//from ww w .ja va2 s . c om JspWriter out = pageContext.getOut(); HashMap values = null; try { // FormObject foo = (FormObject) pageContext.getSession().getAttribute("FormObject"); // FormObject foo = TagUtils.getFormObject(pageContext); FormObject foo = getFormObject(); values = foo.getValues(); } catch (Exception e) { System.out.println("Could not get the form object from which to build an option list"); } if (values != null) { String value = (String) values.get(name); if (value != null) out.print(StringEscapeUtils.escapeHtml(value)); } else { System.out.println("ValueTag unable to get HashMap of form values"); } } catch (Exception ex) { throw new JspException(ex.getMessage()); } return SKIP_BODY; }
From source file:no.kantega.publishing.api.taglibs.util.BylineTag.java
public int doAfterBody() throws JspException { try {//w w w . j a v a2s. c om JspWriter out = bodyContent.getEnclosingWriter(); Content content = content(pageContext); if (content != null) { String userFullName = userFullName(content); Date lastUpdated = content.getLastMajorChange(); String textLabel = textLabel(pageContext, key, bundle, locale, bodyContent.toString()); String text = String.format(textLabel, userFullName, lastUpdated); String html = html(text); out.print(html); } } catch (Exception e) { log.error("Failed while generating byline", e); throw new JspTagException(e); } finally { bodyContent.clearBody(); } cssStyle = null; cssClass = null; key = null; bundle = LocaleLabels.DEFAULT_BUNDLE; locale = null; return SKIP_BODY; }
From source file:nl.strohalm.cyclos.taglibs.MenuTag.java
@Override public int doEndTag() throws JspException { try {/*from ww w . j a va 2s . c o m*/ // Rendering is done by the topmost tag. If this is nested, do nothing // Also, render something only if there is some content if (menu == null || menu.isNested() || !menu.hasContent()) { return EVAL_PAGE; } final JspWriter out = pageContext.getOut(); // Render this parent menu final int index = index(); final String divId = divId(menu, index); renderDiv(menu, index, divId); // Render each submenu final List<Menu> subMenus = menu.getChildren(); if (CollectionUtils.isNotEmpty(subMenus)) { out.print("<ul id='subMenuContainer" + index + "' class='subMenuContainer' style='display:none'>"); final int subMenuCount = subMenus.size(); for (int i = 0; i < subMenuCount; i++) { final Menu subMenu = subMenus.get(i); final String subMenuId = divId(subMenu, i); renderDiv(subMenu, i, subMenuId); if (i == 0) { out.println("<script>$('" + subMenuId + "').addClassName('firstSubMenu');</script>"); } else if (i == subMenuCount - 1) { out.println("<script>$('" + subMenuId + "').addClassName('lastSubMenu');</script>"); } } out.println("</ul></li>"); } out.println(); out.println("<script>allMenus.push($('" + divId + "'));</script>"); return EVAL_PAGE; } catch (final IOException e) { throw new JspException(e); } finally { release(); } }
From source file:info.magnolia.cms.taglibs.util.SimpleNavigationTag.java
/** * Draws page children as an unordered list. * @param page current page/* w ww . j a va 2 s .c om*/ * @param activePage active page * @param out jsp writer * @throws IOException jspwriter exception * @throws RepositoryException any exception thrown during repository reading */ private void drawChildren(Content page, Content activePage, JspWriter out) throws IOException, RepositoryException { Collection children = page.getChildren(ItemType.CONTENT); if (children.size() == 0) { return; } out.print("<ul class=\"level"); //$NON-NLS-1$ out.print(page.getLevel()); if (style != null && page.getLevel() == startLevel) { out.print(" "); out.print(style); } out.print("\">"); //$NON-NLS-1$ Iterator it = children.iterator(); while (it.hasNext()) { Content child = (Content) it.next(); if (expandAll.equalsIgnoreCase(EXPAND_NONE) || expandAll.equalsIgnoreCase(EXPAND_SHOW)) { if (child.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA)) .getBoolean()) { continue; } } List cssClasses = new ArrayList(3); String title = child.getNodeData(NODEDATA_NAVIGATIONTITLE).getString(StringUtils.EMPTY); // if nav title is not set, the main title is taken if (StringUtils.isEmpty(title)) { title = child.getTitle(); } // if main title is not set, the name of the page is taken if (StringUtils.isEmpty(title)) { title = child.getName(); } boolean showChildren = false; boolean self = false; if (!expandAll.equalsIgnoreCase(EXPAND_NONE)) { showChildren = true; } if (activePage.getHandle().equals(child.getHandle())) { // self showChildren = true; self = true; cssClasses.add(CSS_LI_ACTIVE); //$NON-NLS-1$ } else if (!showChildren) { showChildren = (child.getLevel() <= activePage.getAncestors().size() && activePage.getAncestor(child.getLevel()).getHandle().equals(child.getHandle())); } if (!showChildren) { showChildren = child .getNodeData(StringUtils.defaultString(this.openMenu, DEFAULT_OPENMENU_NODEDATA)) .getBoolean(); } if (endLevel > 0) { showChildren &= child.getLevel() < endLevel; } cssClasses.add(hasVisibleChildren(child) ? (showChildren ? CSS_LI_OPEN : CSS_LI_CLOSED) : CSS_LI_LEAF); if (child.getLevel() < activePage.getLevel() && activePage.getAncestor(child.getLevel()).getHandle().equals(child.getHandle())) { cssClasses.add(CSS_LI_TRAIL); } StringBuffer css = new StringBuffer(cssClasses.size() * 10); Iterator iterator = cssClasses.iterator(); while (iterator.hasNext()) { css.append(iterator.next()); if (iterator.hasNext()) { css.append(" "); //$NON-NLS-1$ } } out.print("<li class=\""); //$NON-NLS-1$ out.print(css.toString()); out.print("\">"); //$NON-NLS-1$ if (self) { out.println("<strong>"); //$NON-NLS-1$ } String accesskey = child.getNodeData(NODEDATA_ACCESSKEY).getString(StringUtils.EMPTY); out.print("<a href=\""); //$NON-NLS-1$ out.print(((HttpServletRequest) this.pageContext.getRequest()).getContextPath()); out.print(child.getHandle()); out.print(".html\""); //$NON-NLS-1$ if (StringUtils.isNotEmpty(accesskey)) { out.print(" accesskey=\""); //$NON-NLS-1$ out.print(accesskey); out.print("\""); //$NON-NLS-1$ } out.print(">"); //$NON-NLS-1$ out.print(StringEscapeUtils.escapeHtml(title)); out.print(" </a>"); //$NON-NLS-1$ if (self) { out.println("</strong>"); //$NON-NLS-1$ } if (showChildren) { drawChildren(child, activePage, out); } out.print("</li>"); //$NON-NLS-1$ } out.print("</ul>"); //$NON-NLS-1$ }
From source file:com.glaf.core.tag.TagUtils.java
/** * Write the specified text as the response to the writer associated with * the body content for the tag within which we are currently nested. * /*from w w w . ja v a2 s . co m*/ * @param pageContext * The PageContext object for this page * @param text * The text to be written * @throws 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) { saveException(pageContext, e); throw new JspException(messages.getMessage("write.io", e.toString())); } }
From source file:no.kantega.publishing.admin.content.InputScreenRenderer.java
private void renderSeparatorAttribute(JspWriter out, SeparatorAttribute separatorAttribute) throws IOException { StringBuilder output = new StringBuilder(); output.append("\n<div class=\"separator\">"); output.append("\n<h2 class=\"separator_heading\">").append(separatorAttribute.getName()).append("</h2>\n"); if (separatorAttribute.getHelpText() != null && separatorAttribute.getHelpText().length() > 0) { output.append("<div class=\"separator_description\">").append(separatorAttribute.getHelpText()) .append("</div>"); }/*from w ww .jav a 2 s . co m*/ output.append("</div>"); out.print(output); }
From source file:org.springmodules.validation.commons.taglib.JavascriptValidatorTag.java
/** * Render the JavaScript for to perform validations based on the form name. * * @throws javax.servlet.jsp.JspException if a JSP exception has occurred *//*w ww . j av a2s .co m*/ public int doStartTag() throws JspException { StringBuffer results = new StringBuffer(); Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest()); ValidatorResources resources = getValidatorResources(); Form form = resources.getForm(locale, formName); if (form != null) { if ("true".equalsIgnoreCase(dynamicJavascript)) { MessageSource messages = getMessageSource(); List lActions = new ArrayList(); List lActionMethods = new ArrayList(); // Get List of actions for this Form for (Iterator i = form.getFields().iterator(); i.hasNext();) { Field field = (Field) i.next(); for (Iterator x = field.getDependencyList().iterator(); x.hasNext();) { Object o = x.next(); if (o != null && !lActionMethods.contains(o)) { lActionMethods.add(o); } } } // Create list of ValidatorActions based on lActionMethods for (Iterator i = lActionMethods.iterator(); i.hasNext();) { String depends = (String) i.next(); ValidatorAction va = resources.getValidatorAction(depends); // throw nicer NPE for easier debugging if (va == null) { throw new NullPointerException( "Depends string \"" + depends + "\" was not found in validator-rules.xml."); } String javascript = va.getJavascript(); if (javascript != null && javascript.length() > 0) { lActions.add(va); } else { i.remove(); } } Collections.sort(lActions, new Comparator() { public int compare(Object o1, Object o2) { ValidatorAction va1 = (ValidatorAction) o1; ValidatorAction va2 = (ValidatorAction) o2; if ((va1.getDepends() == null || va1.getDepends().length() == 0) && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 0; } else if ((va1.getDepends() != null && va1.getDepends().length() > 0) && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 1; } else if ((va1.getDepends() == null || va1.getDepends().length() == 0) && (va2.getDepends() != null && va2.getDepends().length() > 0)) { return -1; } else { return va1.getDependencyList().size() - va2.getDependencyList().size(); } } }); String methods = null; for (Iterator i = lActions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); if (methods == null) { methods = va.getMethod() + "(form)"; } else { methods += " && " + va.getMethod() + "(form)"; } } results.append(getJavascriptBegin(methods)); for (Iterator i = lActions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); String jscriptVar = null; String functionName = null; if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) { functionName = va.getJsFunctionName(); } else { functionName = va.getName(); } results.append(" function " + functionName + " () { \n"); for (Iterator x = form.getFields().iterator(); x.hasNext();) { Field field = (Field) x.next(); // Skip indexed fields for now until there is a good way to handle // error messages (and the length of the list (could retrieve from scope?)) if (field.isIndexed() || field.getPage() != page || !field.isDependency(va.getName())) { continue; } String message = MessageUtils.getMessage(messages, locale, va, field); message = (message != null) ? message : ""; jscriptVar = this.getNextVar(jscriptVar); results.append(" this." + jscriptVar + " = new Array(\"" + field.getKey() + "\", \"" + message + "\", "); results.append("new Function (\"varName\", \""); Map vars = field.getVars(); // Loop through the field's variables. Iterator varsIterator = vars.keySet().iterator(); while (varsIterator.hasNext()) { String varName = (String) varsIterator.next(); Var var = (Var) vars.get(varName); String varValue = var.getValue(); String jsType = var.getJsType(); // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue if (varName.startsWith("field")) { continue; } if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=" + ValidatorUtils.replace(varValue, "\\", "\\\\") + "; "); } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=/" + ValidatorUtils.replace(varValue, "\\", "\\\\") + "/; "); } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) { results.append("this." + varName + "='" + ValidatorUtils.replace(varValue, "\\", "\\\\") + "'; "); // So everyone using the latest format doesn't need to change their xml files immediately. } else if ("mask".equalsIgnoreCase(varName)) { results.append("this." + varName + "=/" + ValidatorUtils.replace(varValue, "\\", "\\\\") + "/; "); } else { results.append("this." + varName + "='" + ValidatorUtils.replace(varValue, "\\", "\\\\") + "'; "); } } results.append(" return this[varName];\"));\n"); } results.append(" } \n\n"); } } else if ("true".equalsIgnoreCase(staticJavascript)) { results.append(this.getStartElement()); if ("true".equalsIgnoreCase(htmlComment)) { results.append(htmlBeginComment); } } } if ("true".equalsIgnoreCase(staticJavascript)) { results.append(getJavascriptStaticMethods(resources)); } if (form != null && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) { results.append(getJavascriptEnd()); } JspWriter writer = pageContext.getOut(); try { writer.print(results.toString()); } catch (IOException e) { throw new JspException(e.getMessage()); } return (SKIP_BODY); }
From source file:com.xhsoft.framework.common.page.OrderTag.java
/** * <p>Description:</p>//ww w .j a v a2 s . c o m * @return int * @author wenzhi * @version 1.0 * @exception Exception */ @Override public int doStartTag() throws JspException { /** ?request*/ HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String descMessage = "descMessage"; String ascMessage = "ascMessage"; String realTitle = this.getTitle(); try { } catch (NoSuchMessageException e1) { } String sortType = ""; String image = ""; int cnt = 0; String order = request.getParameter(ORDER); if (StringUtils.isNotEmpty(order)) { /** ???*/ String[] orderItems = order.split(","); for (String orderItem : orderItems) { cnt++; List<String> list = new ArrayList<String>(); String[] items = orderItem.split(" "); for (String item : items) { if (item.length() > 0) { list.add(item); } } /**?*/ if (list.get(0).equalsIgnoreCase(field)) { sortType = list.get(1); /** ????*/ image = "<img border='0' src='" + request.getContextPath() + "/images/table/sort_" + sortType + ".gif' align='absmiddle' title='" + ("asc".equals(sortType) ? ascMessage : descMessage) + "'/>" + "<span class='orderCount'>" + cnt + "</span>"; break; } } } try { JspWriter out = pageContext.getOut(); StringBuffer sb = new StringBuffer(); String reverseSortType = null; /** ??*/ if ("".equals(sortType)) { reverseSortType = "asc"; } else if ("asc".equals(sortType)) { reverseSortType = "desc"; } else if ("desc".equals(sortType)) { reverseSortType = "na"; } String titleMessage = ""; sb.append("<a href=\"javascript:setOrder('" + field + "','" + reverseSortType + "','" + targets + "');\" title=\"" + titleMessage + "\">"); sb.append(realTitle); sb.append("</a>"); sb.append(image); out.print(sb.toString()); } catch (Exception e) { throw new JspException(e); } return SKIP_BODY; }
From source file:com.redhat.rhn.frontend.taglibs.ColumnTag.java
/** * {@inheritDoc}//from www. j a v a2 s .co m */ 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); } }
From source file:org.springmodules.commons.validator.taglib.JavascriptValidatorTag.java
/** * Render the JavaScript for to perform validations based on the form name. * * @throws JspException if a JSP exception has occurred *///from w ww . ja v a2s .c o m public int doStartTag() throws JspException { StringBuffer results = new StringBuffer(); Locale locale = pageContext.getRequest().getLocale(); ValidatorResources resources = getValidatorResources(); Form form = resources.get(locale, formName); if (form != null) { if ("true".equalsIgnoreCase(dynamicJavascript)) { MessageSource messages = getMessageSource(); List lActions = new ArrayList(); List lActionMethods = new ArrayList(); // Get List of actions for this Form for (Iterator i = form.getFields().iterator(); i.hasNext();) { Field field = (Field) i.next(); for (Iterator x = field.getDependencies().iterator(); x.hasNext();) { Object o = x.next(); if (o != null && !lActionMethods.contains(o)) { lActionMethods.add(o); } } } // Create list of ValidatorActions based on lActionMethods for (Iterator i = lActionMethods.iterator(); i.hasNext();) { String depends = (String) i.next(); ValidatorAction va = resources.getValidatorAction(depends); // throw nicer NPE for easier debugging if (va == null) { throw new NullPointerException( "Depends string \"" + depends + "\" was not found in validator-rules.xml."); } String javascript = va.getJavascript(); if (javascript != null && javascript.length() > 0) { lActions.add(va); } else { i.remove(); } } Collections.sort(lActions, new Comparator() { public int compare(Object o1, Object o2) { ValidatorAction va1 = (ValidatorAction) o1; ValidatorAction va2 = (ValidatorAction) o2; if ((va1.getDepends() == null || va1.getDepends().length() == 0) && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 0; } else if ((va1.getDepends() != null && va1.getDepends().length() > 0) && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 1; } else if ((va1.getDepends() == null || va1.getDepends().length() == 0) && (va2.getDepends() != null && va2.getDepends().length() > 0)) { return -1; } else { return va1.getDependencies().size() - va2.getDependencies().size(); } } }); String methods = null; for (Iterator i = lActions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); if (methods == null) { methods = va.getMethod() + "(form)"; } else { methods += " && " + va.getMethod() + "(form)"; } } results.append(getJavascriptBegin(methods)); for (Iterator i = lActions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); String jscriptVar = null; String functionName = null; if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) { functionName = va.getJsFunctionName(); } else { functionName = va.getName(); } results.append(" function " + functionName + " () { \n"); for (Iterator x = form.getFields().iterator(); x.hasNext();) { Field field = (Field) x.next(); // Skip indexed fields for now until there is a good way to handle // error messages (and the length of the list (could retrieve from scope?)) if (field.isIndexed() || field.getPage() != page || !field.isDependency(va.getName())) { continue; } String message = MessageUtils.getMessage(messages, locale, va, field); message = (message != null) ? message : ""; jscriptVar = this.getNextVar(jscriptVar); results.append(" this." + jscriptVar + " = new Array(\"" + field.getKey() + "\", \"" + message + "\", "); results.append("new Function (\"varName\", \""); Map vars = field.getVars(); // Loop through the field's variables. Iterator varsIterator = vars.keySet().iterator(); while (varsIterator.hasNext()) { String varName = (String) varsIterator.next(); Var var = (Var) vars.get(varName); String varValue = var.getValue(); String jsType = var.getJsType(); // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue if (varName.startsWith("field")) { continue; } if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "; "); } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) { results.append("this." + varName + "=/" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; "); } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) { results.append("this." + varName + "='" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; "); // So everyone using the latest format doesn't need to change their xml files immediately. } else if ("mask".equalsIgnoreCase(varName)) { results.append("this." + varName + "=/" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; "); } else { results.append("this." + varName + "='" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; "); } } results.append(" return this[varName];\"));\n"); } results.append(" } \n\n"); } } else if ("true".equalsIgnoreCase(staticJavascript)) { results.append(this.getStartElement()); if ("true".equalsIgnoreCase(htmlComment)) { results.append(htmlBeginComment); } } } if ("true".equalsIgnoreCase(staticJavascript)) { results.append(getJavascriptStaticMethods(resources)); } if (form != null && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) { results.append(getJavascriptEnd()); } JspWriter writer = pageContext.getOut(); try { writer.print(results.toString()); } catch (IOException e) { throw new JspException(e.getMessage()); } return (SKIP_BODY); }