List of usage examples for javax.servlet.jsp JspException JspException
public JspException(Throwable cause)
JspException
with the specified cause. From source file:org.apache.myfaces.taglib.core.ViewTag.java
public int doEndTag() throws JspException { if (log.isTraceEnabled()) log.trace("entering ViewTag.doEndTag"); FacesContext facesContext = FacesContext.getCurrentInstance(); ResponseWriter responseWriter = facesContext.getResponseWriter(); try {// w w w .jav a 2s . com responseWriter.endDocument(); } catch (IOException e) { log.error("Error writing endDocument", e); throw new JspException(e); } if (log.isTraceEnabled()) log.trace("leaving ViewTag.doEndTag"); return super.doEndTag(); }
From source file:org.apache.myfaces.taglib.core.ViewTag.java
public int doAfterBody() throws JspException { if (log.isTraceEnabled()) log.trace("entering ViewTag.doAfterBody"); try {/* w w w. j av a2 s. com*/ BodyContent bodyContent = getBodyContent(); if (bodyContent != null) { FacesContext facesContext = FacesContext.getCurrentInstance(); StateManager stateManager = facesContext.getApplication().getStateManager(); StateManager.SerializedView serializedView = stateManager.saveSerializedView(facesContext); //until now we have written to a buffer ResponseWriter bufferWriter = facesContext.getResponseWriter(); bufferWriter.flush(); //now we switch to real output ResponseWriter realWriter = bufferWriter.cloneWithWriter(getPreviousOut()); facesContext.setResponseWriter(realWriter); String bodyStr = bodyContent.getString(); /* do this always - even with server-side-state saving if ( stateManager.isSavingStateInClient(facesContext) ) { */ int form_marker = bodyStr.indexOf(JspViewHandlerImpl.FORM_STATE_MARKER); int url_marker = bodyStr.indexOf(HtmlLinkRendererBase.URL_STATE_MARKER); int lastMarkerEnd = 0; while (form_marker != -1 || url_marker != -1) { if (url_marker == -1 || (form_marker != -1 && form_marker < url_marker)) { //replace form_marker realWriter.write(bodyStr, lastMarkerEnd, form_marker - lastMarkerEnd); stateManager.writeState(facesContext, serializedView); lastMarkerEnd = form_marker + JspViewHandlerImpl.FORM_STATE_MARKER_LEN; form_marker = bodyStr.indexOf(JspViewHandlerImpl.FORM_STATE_MARKER, lastMarkerEnd); } else { //replace url_marker realWriter.write(bodyStr, lastMarkerEnd, url_marker - lastMarkerEnd); if (stateManager instanceof MyfacesStateManager) { ((MyfacesStateManager) stateManager).writeStateAsUrlParams(facesContext, serializedView); } else { log.error( "Current StateManager is no MyfacesStateManager and does not support saving state in url parameters."); } lastMarkerEnd = url_marker + HtmlLinkRendererBase.URL_STATE_MARKER_LEN; url_marker = bodyStr.indexOf(HtmlLinkRendererBase.URL_STATE_MARKER, lastMarkerEnd); } } realWriter.write(bodyStr, lastMarkerEnd, bodyStr.length() - lastMarkerEnd); /* change over to do this always - even with server-side state saving } else { realWriter.write( bodyStr ); } */ /* before, this was done when getSerializedView was null } else { bodyContent.writeOut(getPreviousOut()); }*/ } } catch (IOException e) { log.error("Error writing body content", e); throw new JspException(e); } if (log.isTraceEnabled()) log.trace("leaving ViewTag.doAfterBody"); return super.doAfterBody(); }
From source file:org.apache.pluto.driver.tags.PortletModeAnchorTag.java
/** * Method invoked when the start tag is encountered. * @throws JspException if an error occurs. *//*from ww w.j a v a 2 s. c o m*/ public int doStartTag() throws JspException { // Ensure that the modeAnchor tag resides within a portlet tag. PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class); if (parentTag == null) { throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag."); } portletId = parentTag.getPortletId(); // Evaluate portlet ID attribute. evaluatePortletId(); // Retrieve the portlet window config for the evaluated portlet ID. ServletContext servletContext = pageContext.getServletContext(); DriverConfiguration driverConfig = (DriverConfiguration) servletContext .getAttribute(AttributeKeys.DRIVER_CONFIG); if (isPortletModeAllowed(driverConfig, portletMode)) { // Retrieve the portal environment. PortalRequestContext portalEnv = PortalRequestContext .getContext((HttpServletRequest) pageContext.getRequest()); PortalURL portalUrl = portalEnv.createPortalURL(); portalUrl.setPortletMode(evaluatedPortletId, new PortletMode(portletMode)); // Build a string buffer containing the anchor tag StringBuffer tag = new StringBuffer(); // tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">"); // tag.append("<span class=\"" + portletMode + "\"></span>"); // tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">"); // tag.append(ToolTips.forMode(new PortletMode(portletMode))); // tag.append("</span></a>"); tag.append("<a title=\""); tag.append(ToolTips.forMode(new PortletMode(portletMode))); tag.append("\" "); tag.append("href=\"" + portalUrl.toString() + "\">"); tag.append("<span class=\"" + portletMode + "\"></span>"); tag.append("</a>"); // Print the mode anchor tag. try { JspWriter out = pageContext.getOut(); out.print(tag.toString()); } catch (IOException ex) { throw new JspException(ex); } } // Continue to evaluate the tag body. return EVAL_BODY_INCLUDE; }
From source file:org.apache.pluto.driver.tags.PortletModeDropDownTag.java
/** * Method invoked when the start tag is encountered. * @throws JspException if an error occurs. *///www. j a v a 2s . c om public int doStartTag() throws JspException { // Ensure that the modeAnchor tag resides within a portlet tag. PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class); if (parentTag == null) { throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag."); } portletId = parentTag.getPortletId(); // Evaluate portlet ID attribute. evaluatePortletId(); // Retrieve the portlet window config for the evaluated portlet ID. ServletContext servletContext = pageContext.getServletContext(); DriverConfiguration driverConfig = (DriverConfiguration) servletContext .getAttribute(AttributeKeys.DRIVER_CONFIG); // Retrieve the portal environment. PortalRequestContext portalEnv = PortalRequestContext .getContext((HttpServletRequest) pageContext.getRequest()); //find the current mode for use in 'selected' attrib of select option PortalURL requestedPortalUrl = portalEnv.getRequestedPortalURL(); PortletWindowConfig windowConfig = PortletWindowConfig.fromId(evaluatedPortletId); // Retrieve the portlet container from servlet context. PortletContainer container = (PortletContainer) servletContext .getAttribute(AttributeKeys.PORTLET_CONTAINER); // Create the portlet window to render. PortletWindow window = new PortletWindowImpl(container, windowConfig, requestedPortalUrl); PortletMode currentMode = requestedPortalUrl.getPortletMode(window.getId().getStringId()); //start the markup StringBuffer tag = new StringBuffer(); // String strCurrentMode = currentMode.toString(); // tag.append("Current mode: " + currentMode.toString()); tag.append( "<form action=\"\" name=\"modeSelectionForm\" style=\"display:inline\"><select onchange=\"self.location=this.options[this.selectedIndex].value\">"); Set<PortletMode> modeSet = null; try { modeSet = driverConfig.getSupportedPortletModes(evaluatedPortletId); } catch (PortletContainerException e) { throw new JspException(e); } if (modeSet != null) { Iterator<PortletMode> i = modeSet.iterator(); while (i.hasNext()) { PortletMode mode = i.next(); PortalURL portalUrl = portalEnv.createPortalURL(); portalUrl.setPortletMode(evaluatedPortletId, mode); // Build a string buffer containing the anchor tag tag.append("<option value=\"" + portalUrl.toString() + "\""); //Add 'selected' attribute for current mode. if (mode.equals(currentMode)) { tag.append(" selected=\"true\""); } tag.append(">"); if (driverConfig.isPortletManagedMode(evaluatedPortletId, mode.toString())) { tag.append(getCustomModeDecorationName(driverConfig, mode)); } else { tag.append(mode.toString().toUpperCase()); } // tag.append(mode.toString().toUpperCase()); tag.append("</option>"); } } tag.append("</select></form>"); // Print the mode anchor tag. try { JspWriter out = pageContext.getOut(); out.print(tag.toString()); } catch (IOException ex) { throw new JspException(ex); } // Continue to evaluate the tag body. return EVAL_BODY_INCLUDE; }
From source file:org.apache.pluto.driver.tags.PortletWindowStateAnchorTag.java
/** * Method invoked when the start tag is encountered. * @throws JspException if an error occurs. *//*from w w w . j a v a 2 s .c o m*/ public int doStartTag() throws JspException { // Ensure that the modeAnchor tag resides within a portlet tag. PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(this, PortletTag.class); if (parentTag == null) { throw new JspException("Portlet window controls may only reside " + "within a pluto:portlet tag."); } portletId = parentTag.getPortletId(); // Evaluate portlet ID attribute. evaluatePortletId(); // Retrieve the portlet window config for the evaluated portlet ID. ServletContext servletContext = pageContext.getServletContext(); DriverConfiguration driverConfig = (DriverConfiguration) servletContext .getAttribute(AttributeKeys.DRIVER_CONFIG); if (isWindowStateAllowed(driverConfig, state)) { // Retrieve the portal environment. PortalRequestContext portalEnv = PortalRequestContext .getContext((HttpServletRequest) pageContext.getRequest()); PortalURL portalUrl = portalEnv.createPortalURL(); portalUrl.setWindowState(evaluatedPortletId, new WindowState(state)); // Build a string buffer containing the anchor tag StringBuffer tag = new StringBuffer(); // tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">"); // tag.append("<span class=\"" + state + "\"></span>"); // tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">"); // tag.append(ToolTips.forWindowState(new WindowState(state))); // tag.append("</span></a>"); tag.append("<a title=\""); tag.append(ToolTips.forWindowState(new WindowState(state))); tag.append("\" "); tag.append("href=\"" + portalUrl.toString() + "\">"); tag.append("<img border=\"0\" src=\"" + icon + "\" />"); tag.append("</a>"); // Print the mode anchor tag. try { JspWriter out = pageContext.getOut(); out.print(tag.toString()); } catch (IOException ex) { throw new JspException(ex); } } // Continue to evaluate the tag body. return EVAL_BODY_INCLUDE; }
From source file:org.apache.rave.portal.web.tag.RegionWidgetTag.java
/** * Delegates rendering of the RegionWidget to the RenderService * * @return EVAL_BODY_INCLUDE if no exception is thrown * @throws JspException if the regionWidget is not set or is not supported by the renderService. */// w ww . ja va 2s . c om @Override public int doStartTag() throws JspException { if (regionWidget == null) { throw new JspException("RegionWidget not set: " + regionWidget); } if (widget != null && getBean().getSupportedWidgetTypes().contains(widget.getType())) { if (widget.isDisableRendering()) { ScriptManager scriptManager = getBeanFromContext(ScriptManager.class); String widgetScript = String.format(DISABLED_SCRIPT_BLOCK, regionWidget.getRegion().getId(), regionWidget.getId(), StringEscapeUtils.escapeEcmaScript(widget.getDisableRenderingMessage()), regionWidget.isCollapsed(), widget.getId()); String key = REGISTER_DISABLED_WIDGET_KEY + "-" + widget.getId(); scriptManager.registerScriptBlock(key, widgetScript, ScriptLocation.AFTER_RAVE, RenderScope.CURRENT_REQUEST, getContext()); } else { writeString(getBean().render(new RegionWidgetWrapper(widget, regionWidget), getContext())); } } else { throw new JspException("Unsupported regionWidget type: " + regionWidget); } //Certain JSP implementations use tag pools. Setting the regionWidget to null ensures that there is no chance a given tag //will accidentally re-use a region widget if the attribute in the JSP is empty regionWidget = null; widget = null; return EVAL_BODY_INCLUDE; }
From source file:org.apache.struts.faces.taglib.JavascriptValidatorTag.java
/** * Render the JavaScript for to perform validations based on the form name. * * @exception JspException if a JSP exception has occurred *//*w w w . j av a 2 s . c o m*/ public int doStartTag() throws JspException { StringBuffer results = new StringBuffer(); ModuleConfig config = RequestUtils.getModuleConfig(pageContext); ValidatorResources resources = (ValidatorResources) pageContext .getAttribute(ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE); Locale locale = RequestUtils.retrieveUserLocale(this.pageContext, null); Form form = resources.get(locale, formName); if (form != null) { if ("true".equalsIgnoreCase(dynamicJavascript)) { MessageResources messages = (MessageResources) pageContext.getAttribute(bundle + config.getPrefix(), PageContext.APPLICATION_SCOPE); 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(); } if (isStruts11()) { results.append(" function " + functionName + " () { \n"); } else { results.append(" function " + formName + "_" + 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 = Resources.getMessage(messages, locale, va, field); message = (message != null) ? message : ""; jscriptVar = this.getNextVar(jscriptVar); results.append(" this." + jscriptVar + " = new Array(\"" + getFormClientId() + ":" + 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 (EVAL_BODY_TAG); }
From source file:org.apache.struts.taglib.bean.DefineTag.java
/** * Retrieve the required property and expose it as a scripting variable. * * @throws JspException if a JSP exception has occurred *///from w w w . j a v a 2 s .c o m public int doEndTag() throws JspException { // Enforce restriction on ways to declare the new value int n = 0; if (this.body != null) { n++; } if (this.name != null) { n++; } if (this.value != null) { n++; } if (n > 1) { JspException e = new JspException(messages.getMessage("define.value", id)); TagUtils.getInstance().saveException(pageContext, e); throw e; } // Retrieve the required property value Object value = this.value; if ((value == null) && (name != null)) { value = TagUtils.getInstance().lookup(pageContext, name, property, scope); } if ((value == null) && (body != null)) { value = body; } if (value == null) { JspException e = new JspException(messages.getMessage("define.null", id)); TagUtils.getInstance().saveException(pageContext, e); throw e; } // Expose this value as a scripting variable int inScope = PageContext.PAGE_SCOPE; try { if (toScope != null) { inScope = TagUtils.getInstance().getScope(toScope); } } catch (JspException e) { log.warn("toScope was invalid name so we default to PAGE_SCOPE", e); } pageContext.setAttribute(id, value, inScope); // Continue processing this page return (EVAL_PAGE); }
From source file:org.apache.struts.taglib.html.BaseHandlerTag.java
/** * Return the text specified by the literal value or the message resources * key, if any; otherwise return <code>null</code>. * * @param literal Literal text value or <code>null</code> * @param key Message resources key or <code>null</code> * @throws JspException if both arguments are non-null *//*from w w w . ja v a 2 s . c om*/ protected String message(String literal, String key) throws JspException { if (literal != null) { if (key != null) { JspException e = new JspException(messages.getMessage("common.both")); TagUtils.getInstance().saveException(pageContext, e); throw e; } else { return (literal); } } else { if (key != null) { return TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), key); } else { return null; } } }
From source file:org.apache.struts.taglib.html.BaseHandlerTag.java
/** * Returns the index value for tags with 'true' value in 'indexed' * attribute.//from ww w .j a v a 2 s.c o m * * @return the index value. * @throws JspException if 'indexed' tag used outside of iterate tag. */ protected int getIndexValue() throws JspException { // look for outer iterate tag IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class); if (iterateTag != null) { return iterateTag.getIndex(); } // Look for JSTL loops Integer i = getJstlLoopIndex(); if (i != null) { return i.intValue(); } // this tag should be nested in an IterateTag or JSTL loop tag, if it's not, throw exception JspException e = new JspException(messages.getMessage("indexed.noEnclosingIterate")); TagUtils.getInstance().saveException(pageContext, e); throw e; }