Example usage for javax.servlet.jsp JspException JspException

List of usage examples for javax.servlet.jsp JspException JspException

Introduction

In this page you can find the example usage for javax.servlet.jsp JspException JspException.

Prototype

public JspException(Throwable cause) 

Source Link

Document

Constructs a new JspException with the specified cause.

Usage

From source file:org.apache.struts.taglib.tiles.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. j  av a2  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.getMessage());
    }
}

From source file:org.apache.struts.taglib.tiles.InsertTag.java

/**
 * Process a bean.// ww  w  .  ja v a  2s. com
 * Get bean value, eventually using property and scope. Found value is process by processObjectValue().
 * @param beanName Name of the bean
 * @param beanProperty Property in the bean, or null.
 * @param beanScope bean scope, or null.
 * @return Appropriate TagHandler.
 * @throws JspException - NoSuchDefinitionException No value associated to bean.
 * @throws JspException an error occur while reading bean, or no definition found.
 * @throws JspException - Throws by underlying nested call to processDefinitionName()
 */
protected TagHandler processBean(String beanName, String beanProperty, String beanScope) throws JspException {

    Object beanValue = TagUtils.getRealValueFromBean(beanName, beanProperty, beanScope, pageContext);

    if (beanValue == null) {
        throw new JspException("Error - Tag Insert : No value defined for bean '" + beanName
                + "' with property '" + beanProperty + "' in scope '" + beanScope + "'.");
    }

    return processObjectValue(beanValue);
}

From source file:org.apache.struts.taglib.tiles.InsertTag.java

/**
 * Process tag attribute "attribute".//w  w  w.  j  a v a 2  s. c  o m
 * Get value from component attribute.
 * Found value is process by processObjectValue().
 * @param name Name of the attribute.
 * @return Appropriate TagHandler.
 * @throws JspException - NoSuchDefinitionException No Definition  found for name.
 * @throws JspException - Throws by underlying nested call to processDefinitionName()
 */
public TagHandler processAttribute(String name) throws JspException {
    Object attrValue = getCurrentContext().getAttribute(name);

    if (attrValue == null) {
        throw new JspException("Error - Tag Insert : No value found for attribute '" + name + "'.");
    }

    return processObjectValue(attrValue);
}

From source file:org.apache.struts.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  .  j a va  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 (body != null) {
            realValue = body;
        } 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 = "page";
        }
    }

    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.struts.taglib.tiles.PutTag.java

/**
 * Extract real value from specified bean.
 * @throws JspException If something goes wrong while getting value from bean.
 *///from   w ww  .ja v a  2s. com
protected void getRealValueFromBean() throws JspException {
    try {
        Object bean = TagUtils.retrieveBean(beanName, beanScope, pageContext);
        if (bean != null && beanProperty != null) {
            realValue = PropertyUtils.getProperty(bean, beanProperty);
        } else {
            realValue = bean; // value can be null
        }

    } catch (NoSuchMethodException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());

    } catch (InvocationTargetException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());

    } catch (IllegalAccessException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());
    }
}

From source file:org.apache.struts.taglib.tiles.PutTag.java

/**
 * Find parent tag which must implement AttributeContainer.
 * @throws JspException If we can't find an appropriate enclosing tag.
 *//*from w  w w .j av  a  2 s . com*/
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.");
    }
}

From source file:org.apache.struts.taglib.tiles.util.TagUtils.java

/**
 * Locate and return the specified property of the specified bean, from
 * an optionally specified scope, in the specified page context.
 *
 * @param pageContext Page context to be searched.
 * @param beanName Name of the bean to be retrieved.
 * @param beanProperty Name of the property to be retrieved, or
 *  <code>null</code> to retrieve the bean itself.
 * @param beanScope Scope to be searched (page, request, session, application)
 *  or <code>null</code> to use <code>findAttribute()</code> instead.
 *
 * @exception JspException Scope name is not recognized as a valid scope
 * @exception JspException if the specified bean is not found
 * @exception JspException if accessing this property causes an
 *  IllegalAccessException, IllegalArgumentException,
 *  InvocationTargetException, or NoSuchMethodException
 *//*from ww  w . j a v  a 2s. c o  m*/
public static Object getRealValueFromBean(String beanName, String beanProperty, String beanScope,
        PageContext pageContext) throws JspException {

    try {
        Object realValue;
        Object bean = retrieveBean(beanName, beanScope, pageContext);
        if (bean != null && beanProperty != null) {
            realValue = PropertyUtils.getProperty(bean, beanProperty);
        } else {
            realValue = bean; // value can be null
        }
        return realValue;

    } catch (NoSuchMethodException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());

    } catch (InvocationTargetException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());

    } catch (IllegalAccessException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage());
    }
}

From source file:org.apache.struts.taglib.tiles.util.TagUtils.java

/**
 * Store bean in requested context./*from w w w.  j  ava  2 s. co  m*/
 * If scope is <code>null</code>, save it in REQUEST_SCOPE context.
 *
 * @param pageContext Current pageContext.
 * @param name Name of the bean.
 * @param scope Scope under which bean is saved (page, request, session, application)
 *  or <code>null</code> to store in <code>request()</code> instead.
 * @param value Bean value to store.
 *
 * @exception JspException Scope name is not recognized as a valid scope
 */
public static void setAttribute(PageContext pageContext, String name, Object value, String scope)
        throws JspException {

    if (scope == null)
        pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE);
    else if (scope.equalsIgnoreCase("page"))
        pageContext.setAttribute(name, value, PageContext.PAGE_SCOPE);
    else if (scope.equalsIgnoreCase("request"))
        pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE);
    else if (scope.equalsIgnoreCase("session"))
        pageContext.setAttribute(name, value, PageContext.SESSION_SCOPE);
    else if (scope.equalsIgnoreCase("application"))
        pageContext.setAttribute(name, value, PageContext.APPLICATION_SCOPE);
    else {
        throw new JspException("Error - bad scope name '" + scope + "'");
    }
}

From source file:org.apache.struts.taglib.tiles.util.TagUtils.java

/**
 * Get component definition by its name.
 * @param name Definition name.//from w  w w  . j a v  a 2s. co m
 * @param pageContext The PageContext for the current page.
 * @throws JspException -
 */
public static ComponentDefinition getComponentDefinition(String name, PageContext pageContext)
        throws JspException {

    try {
        return TilesUtil.getDefinition(name, pageContext.getRequest(), pageContext.getServletContext());

    } catch (NoSuchDefinitionException ex) {
        throw new JspException("Error : Can't get component definition for '" + name
                + "'. Check if this name exist in component definitions.");
    } catch (FactoryNotFoundException ex) { // factory not found.
        throw new JspException(ex.getMessage());

    } catch (DefinitionsFactoryException ex) {
        if (debug)
            ex.printStackTrace();
        // Save exception to be able to show it later
        saveException(pageContext, ex);
        throw new JspException(ex.getMessage());
    }
}

From source file:org.apache.struts.tiles.taglib.InsertTag.java

/**
 * Get instantiated Controller.// w  ww . ja v a 2  s. c om
 * Return controller denoted by controllerType, or <code>null</code> if controllerType
 * is null.
 * @throws JspException If controller can't be created.
 */
private Controller getController() throws JspException {
    if (controllerType == null) {
        return null;
    }

    try {
        return ComponentDefinition.createController(controllerName, controllerType);

    } catch (InstantiationException ex) {
        throw new JspException(ex);
    }
}