List of usage examples for javax.servlet.jsp JspException JspException
public JspException(Throwable cause)
JspException
with the specified cause. From source file:org.apache.struts.tiles.taglib.InsertTag.java
/** * End of Process tag attribute "definition". * Overload definition with tag attributes "template" and "role". * Then, create appropriate tag handler. * @param definition Definition to process. * @return Appropriate TagHandler.// w w w . ja v a 2 s. co m * @throws JspException InstantiationException Can't create requested controller */ protected TagHandler processDefinition(ComponentDefinition definition) throws JspException { // Declare local variable in order to not change Tag attribute values. String role = this.role; String page = this.page; Controller controller = null; try { controller = definition.getOrCreateController(); // Overload definition with tag's template and role. if (role == null) { role = definition.getRole(); } if (page == null) { page = definition.getTemplate(); } if (controllerName != null) { controller = ComponentDefinition.createController(controllerName, controllerType); } // Can check if page is set return new InsertHandler(definition.getAttributes(), page, role, controller); } catch (InstantiationException ex) { throw new JspException(ex); } }
From source file:org.apache.struts.tiles.taglib.PutTag.java
/** * Find parent tag which must implement AttributeContainer. * @throws JspException If we can't find an appropriate enclosing tag. */// w w w . j a va2 s . c om protected PutTagParent findEnclosingPutTagParent() throws JspException { try { PutTagParent parent = (PutTagParent) findAncestorWithClass(this, PutTagParent.class); if (parent == null) { throw new JspException("Error - tag put : enclosing tag doesn't accept 'put' tag."); } return parent; } catch (ClassCastException ex) { throw new JspException("Error - tag put : enclosing tag doesn't accept 'put' tag.", ex); } }
From source file:org.apache.struts.tiles.taglib.util.TagUtils.java
/** * Converts the scope name into its corresponding PageContext constant value. * @param scopeName Can be "page", "request", "session", or "application" in any * case.// w w w . ja va2 s. c om * @return The constant representing the scope (ie. PageContext.REQUEST_SCOPE). * @throws JspException if the scopeName is not a valid name. */ public static int getScope(String scopeName) throws JspException { Integer scope = (Integer) scopes.get(scopeName.toLowerCase()); if (scope == null) { //throw new JspException(messages.getMessage("lookup.scope", scope)); throw new JspException("Unable to retrieve the scope " + scopeName); } return scope.intValue(); }
From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java
/** * Returns the exception associated with this page * context, if any./* www . ja v a2 s. c o m*/ * <p/> * Added wrapping for Throwables to avoid ClassCastException: * see Bugzilla 31171 for details. * * @return The Exception associated with this page context, if any. */ public Exception getException() { Throwable t = JspRuntimeLibrary.getThrowable(request); // Only wrap if needed if ((t != null) && (!(t instanceof Exception))) { t = new JspException(t); } return (Exception) t; }
From source file:org.apache.struts2.views.jsp.iterator.SubsetIteratorTag.java
public int doStartTag() throws JspException { // source/*from w ww . jav a2s . c om*/ Object source = null; if (sourceAttr == null && sourceAttr.length() <= 0) { source = findValue("top"); } else { source = findValue(sourceAttr); } // count int count = -1; if (countAttr != null && countAttr.length() > 0) { Object countObj = findValue(countAttr); if (countObj instanceof Integer) { count = ((Integer) countObj).intValue(); } else if (countObj instanceof Float) { count = ((Float) countObj).intValue(); } else if (countObj instanceof Long) { count = ((Long) countObj).intValue(); } else if (countObj instanceof Double) { count = ((Long) countObj).intValue(); } else if (countObj instanceof String) { try { count = Integer.parseInt((String) countObj); } catch (NumberFormatException e) { _log.warn("unable to convert count attribute [" + countObj + "] to number, ignore count attribute", e); } } } // start int start = 0; if (startAttr != null && startAttr.length() > 0) { Object startObj = findValue(startAttr); if (startObj instanceof Integer) { start = ((Integer) startObj).intValue(); } else if (startObj instanceof Float) { start = ((Float) startObj).intValue(); } else if (startObj instanceof Long) { start = ((Long) startObj).intValue(); } else if (startObj instanceof Double) { start = ((Long) startObj).intValue(); } else if (startObj instanceof String) { try { start = Integer.parseInt((String) startObj); } catch (NumberFormatException e) { _log.warn("unable to convert count attribute [" + startObj + "] to number, ignore count attribute", e); } } } // decider Decider decider = null; if (deciderAttr != null && deciderAttr.length() > 0) { Object deciderObj = findValue(deciderAttr); if (!(deciderObj instanceof Decider)) { throw new JspException( "decider found from stack [" + deciderObj + "] does not implement " + Decider.class); } decider = (Decider) deciderObj; } subsetIteratorFilter = new SubsetIteratorFilter(); subsetIteratorFilter.setCount(count); subsetIteratorFilter.setDecider(decider); subsetIteratorFilter.setSource(source); subsetIteratorFilter.setStart(start); subsetIteratorFilter.execute(); getStack().push(subsetIteratorFilter); if (getId() != null) { pageContext.setAttribute(getId(), subsetIteratorFilter); } return EVAL_BODY_INCLUDE; }
From source file:org.apache.taglib.tiles.InsertTag.java
/** * Process tag attribute "definition".//w ww. ja v a2 s.c om * First, search definition in the factory, then create handler from this definition. * @param name Name of the definition. * @return Appropriate TagHandler. * @throws JspException- NoSuchDefinitionException No Definition found for name. * @throws JspException- FactoryNotFoundException Can't find Definitions factory. * @throws JspException- DefinedComponentFactoryException General error in factory. * @throws JspException InstantiationException Can't create requested controller */ protected TagHandler processDefinitionName(String name) throws JspException { try { ComponentDefinition definition = TilesUtil.getDefinition(name, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext()); if (definition == null) { // is it possible ? throw new NoSuchDefinitionException(); } return processDefinition(definition); } catch (NoSuchDefinitionException ex) { throw new JspException("Error - Tag Insert : Can't get definition '" + definitionName + "'. Check if this name exist in definitions factory."); } catch (FactoryNotFoundException ex) { log.info("FACTORY NOT FOUND"); String msg = (String) pageContext.getServletContext().getAttribute(Globals.TILES_INIT_EXCEPTION); throw new JspException(msg); } catch (DefinitionsFactoryException ex) { log.info("DEFINITIONS FACTORY EXCEPTION"); if (log.isDebugEnabled()) { ex.printStackTrace(); } // Save exception to be able to show it later pageContext.setAttribute(Globals.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE); throw new JspException(ex.getMessage()); } }
From source file:org.apache.taglib.tiles.PutTag.java
/** * Compute real value according to tag attributes. * @throws JspException If something goes wrong while getting value from bean. *//* w w w . ja v a 2s. c o m*/ protected void computeRealValue() throws JspException { // Compute real value from attributes set. realValue = value; // If realValue is not set, value must come from body if (value == null && beanName == null) { // Test body content in case of empty body. if (bodyContent != null) { realValue = bodyContent.getString(); } else { realValue = ""; } } // Does value comes from a bean ? if (realValue == null && beanName != null) { getRealValueFromBean(); return; } // Is there a type set ? // First check direct attribute, and translate it to a valueType. // Then, evaluate valueType, and create requested typed attribute. // If valueType is not set, use the value "as is". if (valueType == null && direct != null) { if (Boolean.valueOf(direct).booleanValue() == true) { valueType = "string"; } else { valueType = "path"; } } if (realValue != null && valueType != null && !(value instanceof AttributeDefinition)) { String strValue = realValue.toString(); if (valueType.equalsIgnoreCase("string")) { realValue = new DirectStringAttribute(strValue); } else if (valueType.equalsIgnoreCase("page")) { realValue = new PathAttribute(strValue); } else if (valueType.equalsIgnoreCase("template")) { realValue = new PathAttribute(strValue); } else if (valueType.equalsIgnoreCase("instance")) { realValue = new DefinitionNameAttribute(strValue); } else if (valueType.equalsIgnoreCase("definition")) { realValue = new DefinitionNameAttribute(strValue); } else { // bad type throw new JspException("Warning - Tag put : Bad type '" + valueType + "'."); } } }
From source file:org.apache.taglib.tiles.util.TagUtils.java
/** * Converts the scope name into its corresponding PageContext constant value. * @param scopeName Can be "page", "request", "session", or "application" in any * case./*from w w w. j a va 2 s . com*/ * @return The constant representing the scope (ie. PageContext.REQUEST_SCOPE). * @throws JspException if the scopeName is not a valid name. */ public static int getScope(String scopeName) throws JspException { Integer scope = (Integer) scopes.get(scopeName.toLowerCase()); if (scope == null) { throw new JspException(messages.getMessage("lookup.scope", scope)); } return scope.intValue(); }
From source file:org.apache.tapestry.jsp.URLRetriever.java
/** * Invokes the servlet to retrieve the URL. The URL is inserted * into the output (as with/*from w w w .j av a 2 s . co m*/ * {@link RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}). * * **/ public void insertURL(String servletPath) throws JspException { if (LOG.isDebugEnabled()) LOG.debug("Obtaining Tapestry URL for service " + _serviceName + " at " + servletPath); ServletRequest request = _pageContext.getRequest(); RequestDispatcher dispatcher = request.getRequestDispatcher(servletPath); if (dispatcher == null) throw new JspException(Tapestry.format("URLRetriever.unable-to-find-dispatcher", servletPath)); request.setAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE, _serviceName); request.setAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE, _serviceParameters); request.setAttribute(Tapestry.TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE, servletPath); try { _pageContext.getOut().flush(); dispatcher.include(request, _pageContext.getResponse()); } catch (IOException ex) { throw new JspException(Tapestry.format("URLRetriever.io-exception", servletPath, ex.getMessage())); } catch (ServletException ex) { throw new JspException(Tapestry.format("URLRetriever.servlet-exception", servletPath, ex.getMessage())); } finally { request.removeAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE); request.removeAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE); request.removeAttribute(Tapestry.TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE); } }
From source file:org.apache.tiles.jsp.taglib.AddAttributeTag.java
/** {@inheritDoc} */ protected void execute() throws JspException { AddAttributeTagParent parent = (AddAttributeTagParent) TagSupport.findAncestorWithClass(this, AddAttributeTagParent.class); if (parent == null) { String message = "Error: enclosing tag '" + getParent().getClass().getName() + " doesn't accept 'put' tag."; LOG.error(message);/* w w w . j ava 2 s . c om*/ throw new JspException(message); } parent.processNestedTag(this); }