List of usage examples for javax.servlet.jsp JspException JspException
public JspException(Throwable cause)
JspException
with the specified cause. From source file:org.apache.tiles.jsp.taglib.PutAttributeTag.java
/** {@inheritDoc} */ protected void execute() throws JspException { PutAttributeTagParent parent = (PutAttributeTagParent) TagSupport.findAncestorWithClass(this, PutAttributeTagParent.class); if (parent == null) { String message = "Error: enclosing tag '" + getParent().getClass().getName() + " doesn't accept 'put' tag."; LOG.error(message);/*from ww w. ja va 2 s .c o m*/ throw new JspException(message); } parent.processNestedTag(this); }
From source file:org.apache.webapp.admin.AttributeTag.java
/** * Render the JMX MBean attribute identified by this tag * * @exception JspException if a processing exception occurs *//*from ww w . j a v a 2 s.c o m*/ public int doEndTag() throws JspException { // Retrieve the object name identified by our attributes Object bean = null; if (scope == null) { bean = pageContext.findAttribute(name); } else if ("page".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.PAGE_SCOPE); } else if ("request".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE); } else if ("session".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.SESSION_SCOPE); } else if ("application".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE); } else { throw new JspException("Invalid scope value '" + scope + "'"); } if (bean == null) { throw new JspException("No bean '" + name + "' found"); } if (property != null) { try { bean = PropertyUtils.getProperty(bean, property); } catch (Throwable t) { throw new JspException("Exception retrieving property '" + property + "': " + t); } if (bean == null) { throw new JspException("No property '" + property + "' found"); } } // Convert to an object name as necessary ObjectName oname = null; try { if (bean instanceof ObjectName) { oname = (ObjectName) bean; } else if (bean instanceof String) { oname = new ObjectName((String) bean); } else { oname = new ObjectName(bean.toString()); } } catch (Throwable t) { throw new JspException("Exception creating object name for '" + bean + "': " + t); } // Acquire a reference to our MBeanServer MBeanServer mserver = (MBeanServer) pageContext.getAttribute("org.apache.catalina.MBeanServer", PageContext.APPLICATION_SCOPE); if (mserver == null) throw new JspException("MBeanServer is not available"); // Retrieve the specified attribute from the specified MBean Object value = null; try { value = mserver.getAttribute(oname, attribute); } catch (Throwable t) { throw new JspException("Exception retrieving attribute '" + attribute + "'"); } // Render this value to our current output writer if (value != null) { JspWriter out = pageContext.getOut(); try { out.print(value); } catch (IOException e) { throw new JspException("IOException: " + e); } } // Evaluate the remainder of this page return (EVAL_PAGE); }
From source file:org.araneaframework.jsp.tag.basic.UiKeyboardHandlerBaseTag.java
/** * Checks that either keyCode or key is specified (not both), and initializes the keyCode field. * When overriding don't forget to invoke superimplementation first. *//*w w w . j av a 2s. com*/ protected int before(Writer out) throws Exception { super.before(out); if (!(keyCode == null ^ key == null)) throw new JspException("Either key or keyCode must be specified for a keyboard handler tag."); if (keyCode == null) { int iKeyCode = keyToKeyCode(key); if (iKeyCode == 0) throw new JspException("Invalid key alias specified (" + key + ")"); keyCode = String.valueOf(iKeyCode); } return SKIP_BODY; }
From source file:org.araneaframework.jsp.tag.basic.UiKeyboardHandlerBaseTag.java
/** * Writes "uiRegisterKeypressHandler" javascript, surrounded by <script> tags. * Throws exceptions if parameters are not consistent (e.g. keyCode not specified). * //from w ww. ja v a 2s .co m * @see #setScope * @see #setKeyCode * @see #setHandler */ public static final void writeRegisterKeypressHandlerScript(Writer out, String scope, String keyCode, String handler) throws JspException, IOException { if (StringUtils.isBlank(handler)) throw new JspException("handler may not be empty in the UiKeyboardHandlerTag"); if (StringUtils.isBlank(scope)) scope = ""; UiUtil.writeStartTag(out, "script"); out.write("uiRegisterKeypressHandler('"); out.write(scope); out.write("', "); out.write(keyCode); out.write(", "); UiUtil.writeEscaped(out, handler); out.write(");\n"); UiUtil.writeEndTag_SS(out, "script"); }
From source file:org.araneaframework.jsp.tag.uilib.form.UiFormKeyboardHandlerTag.java
protected final int before(Writer out) throws Exception { super.before(out); if (StringUtils.isBlank(handler)) { // One of elemenId/event must be specified if ((elementId == null && fullElementId == null) || event == null) throw new JspException( "You must specify handler or elementId/event for UiFormKeyboardHandlerTag (elementId=" + elementId + ", fullElementId=" + fullElementId + ", event=" + event + ",subscope=" + subscope); // Only one of elementId/fullElementId must be specified if (!(elementId == null ^ fullElementId == null)) throw new JspException("Either elementId or fullElementId must be specified, not both."); // If elementId was given, translate to fullElementId if (fullElementId == null) fullElementId = elementIdToFullElementId(pageContext, elementId); handler = createHandlerToInvokeJavascriptEvent(fullElementId, event); } else {//from ww w . j ava 2 s. com // None of the elementId/event attributes may be specified if (fullElementId != null || elementId != null || event != null) throw new JspException( "You should specify either handler or event for UiFormKeyboardHandlerTag (handler=" + handler + ")"); } // Scope here means the analogue of "scope" attribute in UiKeyboardHandlerTag // It must be prefixed by componentId when the surrounding systemForm's "scope" is "screen". String scope = (String) pageContext.getAttribute(UiFormTag.FORM_SCOPED_FULL_ID_KEY_REQUEST, PageContext.REQUEST_SCOPE); if (!StringUtils.isBlank(subscope)) { if (StringUtils.isBlank(scope)) scope = subscope; else scope = scope + "." + subscope; } // Write out. UiKeyboardHandlerTag.writeRegisterKeypressHandlerScript(out, scope, keyCode, handler); return SKIP_BODY; }
From source file:org.bibsonomy.webapp.util.tags.JabrefLayoutRendererTag.java
@Override public int doStartTag() throws JspException { try {/*from w w w . j a va 2s .c om*/ pageContext.getOut().print(this.renderPosts()); } catch (final IOException ex) { throw new JspException("Error: IOException while writing to client" + ex.getMessage()); } return super.doStartTag(); }
From source file:org.caofei.taglib.html.JavascriptValidatorTag.java
/** * Returns fully rendered JavaScript./* w ww .j av a 2 s . c om*/ * * @since Struts 1.2 */ protected String renderJavascript() throws JspException { StringBuffer results = new StringBuffer(); /* ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext); */ ValidatorResources resources = null; /* (ValidatorResources) pageContext.getAttribute( ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE); */ if (resources == null) { throw new JspException("ValidatorResources is null"); /* "ValidatorResources not found in application scope under key \"" + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\""); */ } Locale locale = null; /* TagUtils.getInstance().getUserLocale(this.pageContext, null); */ Form form = null; if ("true".equalsIgnoreCase(dynamicJavascript)) { form = resources.getForm(locale, formName); if (form == null) { throw new JspException("No form found under '" + formName + "' in locale '" + locale + "'. A form must be defined in the " + "Commons Validator configuration when " + "dynamicJavascript=\"true\" is set."); } } if (form != null) { if ("true".equalsIgnoreCase(dynamicJavascript)) { results.append(this.createDynamicJavascript(resources, locale, form)); } else if ("true".equalsIgnoreCase(staticJavascript)) { results.append(this.renderStartElement()); if ("true".equalsIgnoreCase(htmlComment)) { results.append(HTML_BEGIN_COMMENT); } } } if ("true".equalsIgnoreCase(staticJavascript)) { results.append(getJavascriptStaticMethods(resources)); } if ((form != null) && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) { results.append(getJavascriptEnd()); } return results.toString(); }
From source file:org.codelabor.system.web.taglib.PaginationTag.java
@Override public void doTag() throws JspException, IOException { logger.debug("doTag"); // if numberOfRow is 0, do nothing if (numberOfRow == 0) { return;/*from w w w .ja v a 2s . c o m*/ } PageContext context = (PageContext) this.getJspContext(); HttpServletRequest request = (HttpServletRequest) context.getRequest(); JspWriter out = context.getOut(); // queryString queryString = request.getQueryString(); // max row per page String maxRowPerPageString = request.getParameter(maxRowPerPageParamName); if (!StringUtils.isBlank(maxRowPerPageString)) { maxRowPerPage = Integer.parseInt(maxRowPerPageString); } // total count int totalPageCount = (int) Math.ceil((double) numberOfRow / (double) maxRowPerPage); // page number int firstPageNo = 1; lastPageNo = totalPageCount; currentPageNo = 1; String pageNoString = request.getParameter(pageNoParamName); if (!StringUtils.isBlank(pageNoString)) { currentPageNo = Integer.parseInt(pageNoString); } // validation if (currentPageNo > lastPageNo) { StringBuilder sb = new StringBuilder(); sb.append(pageNoParamName).append(" is exeeded."); sb.append(" ("); sb.append("requested page number: ").append(currentPageNo).append(", "); sb.append("last page number: ").append(lastPageNo).append(")"); throw new JspException(sb.toString()); } // current index lastPageNoOnCurrentIndex = ((int) Math.ceil((double) currentPageNo / (double) maxIndexPerPage)) * maxIndexPerPage; firstPageNoOnCurrentIndex = (lastPageNoOnCurrentIndex - maxIndexPerPage) + 1; // compensate page number if (lastPageNoOnCurrentIndex > lastPageNo) { lastPageNoOnCurrentIndex = lastPageNo; } // first page number on previous, next index firstPageNoOnPreviousIndex = firstPageNoOnCurrentIndex - maxIndexPerPage; firstPageNoOnNextIndex = lastPageNoOnCurrentIndex + 1; // compensate page number if (firstPageNoOnPreviousIndex < firstPageNo) { firstPageNoOnPreviousIndex = firstPageNo; } if (firstPageNoOnNextIndex > lastPageNo) { firstPageNoOnNextIndex = lastPageNo; } // first page number of first index firstPageNoOnFirstIndex = firstPageNo; // last page number of last index lastPageNoOnLastIndex = ((int) Math.ceil((double) numberOfRow / (double) maxRowPerPage)); // debug logger.debug("queryString: {}", queryString); logger.debug("numberOfRow: {}", numberOfRow); logger.debug("totalPageCount: {}", totalPageCount); logger.debug("firstPageNo: {}", firstPageNo); logger.debug("lastPageNo: {}", lastPageNo); // write html tag StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(); sb.append("<div"); if (!StringUtils.isBlank(cssClass)) { sb.append(" class=\"").append(cssClass).append("\""); } sb.append(" />"); getJspBody().invoke(sw); sb.append(sw.getBuffer()); sb.append("</ div>"); out.print(sb.toString()); }
From source file:org.customer.ContentTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() *//* ww w .j a va 2 s . c o m*/ public int doStartTag() throws JspException { try { Writer out = pageContext.getOut(); // setup http call to content webscript String url = this.getRepoUrl() + "/service/api/node/" + getNodeRef().replace("://", "/") + "/content"; HttpClient client = getHttpClient(); GetMethod getContent = new GetMethod(url); getContent.setDoAuthentication(true); try { // execute the method client.executeMethod(getContent); // render the content returned out.write(getContent.getResponseBodyAsString()); } finally { getContent.releaseConnection(); } } catch (IOException ioe) { throw new JspException(ioe.toString()); } return SKIP_BODY; }
From source file:org.customer.PropertyTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() */// ww w . j ava 2s. c o m public int doStartTag() throws JspException { try { Writer out = pageContext.getOut(); // setup http call to content webscript String url = this.getRepoUrl() + "/service/api/metadata?nodeRef=" + getNodeRef() + "&shortQNames=true"; if (logger.isDebugEnabled()) logger.debug("Getting metadata from: " + url); HttpClient client = getHttpClient(); GetMethod getContent = new GetMethod(url); getContent.setDoAuthentication(true); try { // execute the method client.executeMethod(getContent); // get the JSON response String jsonResponse = getContent.getResponseBodyAsString(); if (logger.isDebugEnabled()) logger.debug(jsonResponse); JSONObject json = new JSONObject(jsonResponse); JSONObject props = json.getJSONObject("properties"); if (props.has(this.property)) { out.write(props.getString(this.property)); } } finally { getContent.releaseConnection(); } } catch (IOException ioe) { throw new JspException(ioe.toString()); } catch (JSONException je) { throw new JspException(je.toString()); } return SKIP_BODY; }