Search in sources :

Example 1 with JspException

use of javax.servlet.jsp.JspException in project tomcat by apache.

the class TagHandlerPool method get.

/**
     * Gets the next available tag handler from this tag handler pool,
     * instantiating one if this tag handler pool is empty.
     *
     * @param handlerClass
     *            Tag handler class
     * @return Reused or newly instantiated tag handler
     * @throws JspException
     *             if a tag handler cannot be instantiated
     */
public Tag get(Class<? extends Tag> handlerClass) throws JspException {
    Tag handler;
    synchronized (this) {
        if (current >= 0) {
            handler = handlers[current--];
            return handler;
        }
    }
    // wait for us to construct a tag for this thread.
    try {
        if (Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
            return (Tag) instanceManager.newInstance(handlerClass.getName(), handlerClass.getClassLoader());
        } else {
            Tag instance = handlerClass.newInstance();
            instanceManager.newInstance(instance);
            return instance;
        }
    } catch (Exception e) {
        Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
        ExceptionUtils.handleThrowable(t);
        throw new JspException(e.getMessage(), t);
    }
}
Also used : JspException(javax.servlet.jsp.JspException) Tag(javax.servlet.jsp.tagext.Tag) JspException(javax.servlet.jsp.JspException)

Example 2 with JspException

use of javax.servlet.jsp.JspException in project jetty.project by eclipse.

the class DateTag method doAfterBody.

public int doAfterBody() throws JspException {
    try {
        SimpleDateFormat format = new SimpleDateFormat(body.getString());
        format.setTimeZone(TimeZone.getTimeZone(tz));
        body.getEnclosingWriter().write(format.format(new Date()));
        return SKIP_BODY;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new JspTagException(ex.toString());
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) JspTagException(javax.servlet.jsp.JspTagException) Date(java.util.Date) JspException(javax.servlet.jsp.JspException) JspTagException(javax.servlet.jsp.JspTagException)

Example 3 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class TagUtils method retrieveMessageResources.

/**
     * Returns the appropriate MessageResources object for the current module
     * and the given bundle.
     *
     * @param pageContext    Search the context's scopes for the resources.
     * @param bundle         The bundle name to look for.  If this is
     *                       <code>null</code>, the default bundle name is
     *                       used.
     * @param checkPageScope Whether to check page scope
     * @return MessageResources The bundle's resources stored in some scope.
     * @throws JspException if the MessageResources object could not be
     *                      found.
     */
public MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope) throws JspException {
    MessageResources resources = null;
    if (bundle == null) {
        bundle = Globals.MESSAGES_KEY;
    }
    if (checkPageScope) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.PAGE_SCOPE);
    }
    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.REQUEST_SCOPE);
    }
    if (resources == null) {
        ModuleConfig moduleConfig = getModuleConfig(pageContext);
        resources = (MessageResources) pageContext.getAttribute(bundle + moduleConfig.getPrefix(), PageContext.APPLICATION_SCOPE);
    }
    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE);
    }
    if (resources == null) {
        JspException e = new JspException(messages.getMessage("message.bundle", bundle));
        saveException(pageContext, e);
        throw e;
    }
    return resources;
}
Also used : JspException(javax.servlet.jsp.JspException) MessageResources(org.apache.struts.util.MessageResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 4 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class TagUtils method lookup.

/**
     * Locate and return the specified property of the specified bean, from an
     * optionally specified scope, in the specified page context.  If an
     * exception is thrown, it will have already been saved via a call to
     * <code>saveException()</code>.
     *
     * @param pageContext Page context to be searched
     * @param name        Name of the bean to be retrieved
     * @param property    Name of the property to be retrieved, or
     *                    <code>null</code> to retrieve the bean itself
     * @param scope       Scope to be searched (page, request, session,
     *                    application) or <code>null</code> to use
     *                    <code>findAttribute()</code> instead
     * @return property of specified JavaBean
     * @throws JspException if an invalid scope name is requested
     * @throws JspException if the specified bean is not found
     * @throws JspException if accessing this property causes an
     *                      IllegalAccessException, IllegalArgumentException,
     *                      InvocationTargetException, or NoSuchMethodException
     */
public Object lookup(PageContext pageContext, String name, String property, String scope) throws JspException {
    // Look up the requested bean, and return if requested
    Object bean = lookup(pageContext, name, scope);
    if (bean == null) {
        JspException e = null;
        if (scope == null) {
            e = new JspException(messages.getMessage("lookup.bean.any", name));
        } else {
            e = new JspException(messages.getMessage("lookup.bean", name, scope));
        }
        saveException(pageContext, e);
        throw e;
    }
    if (property == null) {
        return bean;
    }
    // Locate and return the specified property
    try {
        return PropertyUtils.getProperty(bean, property);
    } catch (IllegalAccessException e) {
        saveException(pageContext, e);
        throw new JspException(messages.getMessage("lookup.access", property, name));
    } catch (IllegalArgumentException e) {
        saveException(pageContext, e);
        throw new JspException(messages.getMessage("lookup.argument", property, name));
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t == null) {
            t = e;
        }
        saveException(pageContext, t);
        throw new JspException(messages.getMessage("lookup.target", property, name));
    } catch (NoSuchMethodException e) {
        saveException(pageContext, e);
        String beanName = name;
        // its class name for the exception message.
        if (Constants.BEAN_KEY.equals(name)) {
            Object obj = pageContext.findAttribute(Constants.BEAN_KEY);
            if (obj != null) {
                beanName = obj.getClass().getName();
            }
        }
        throw new JspException(messages.getMessage("lookup.method", property, beanName));
    }
}
Also used : JspException(javax.servlet.jsp.JspException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class TagUtils method computeParameters.

/**
     * Compute a set of query parameters that will be dynamically added to a
     * generated URL.  The returned Map is keyed by parameter name, and the
     * values are either null (no value specified), a String (single value
     * specified), or a String[] array (multiple values specified).  Parameter
     * names correspond to the corresponding attributes of the
     * <code>&lt;html:link&gt;</code> tag.  If no query parameters are
     * identified, return <code>null</code>.
     *
     * @param pageContext   PageContext we are operating in
     * @param paramId       Single-value request parameter name (if any)
     * @param paramName     Bean containing single-value parameter value
     * @param paramProperty Property (of bean named by <code>paramName</code>
     *                      containing single-value parameter value
     * @param paramScope    Scope containing bean named by <code>paramName</code>
     * @param name          Bean containing multi-value parameters Map (if
     *                      any)
     * @param property      Property (of bean named by <code>name</code>
     *                      containing multi-value parameters Map
     * @param scope         Scope containing bean named by <code>name</code>
     * @param transaction   Should we add our transaction control token?
     * @return Map of query parameters
     * @throws JspException if we cannot look up the required beans
     * @throws JspException if a class cast exception occurs on a looked-up
     *                      bean or property
     */
public Map computeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction) throws JspException {
    // Short circuit if no parameters are specified
    if ((paramId == null) && (name == null) && !transaction) {
        return (null);
    }
    // Locate the Map containing our multi-value parameters map
    Map map = null;
    try {
        if (name != null) {
            map = (Map) getInstance().lookup(pageContext, name, property, scope);
        }
    // @TODO - remove this - it is never thrown
    //        } catch (ClassCastException e) {
    //            saveException(pageContext, e);
    //            throw new JspException(
    //                    messages.getMessage("parameters.multi", name, property, scope));
    } catch (JspException e) {
        saveException(pageContext, e);
        throw e;
    }
    // Create a Map to contain our results from the multi-value parameters
    Map results = null;
    if (map != null) {
        results = new HashMap(map);
    } else {
        results = new HashMap();
    }
    // Add the single-value parameter (if any)
    if ((paramId != null) && (paramName != null)) {
        Object paramValue = null;
        try {
            paramValue = TagUtils.getInstance().lookup(pageContext, paramName, paramProperty, paramScope);
        } catch (JspException e) {
            saveException(pageContext, e);
            throw e;
        }
        if (paramValue != null) {
            String paramString = null;
            if (paramValue instanceof String) {
                paramString = (String) paramValue;
            } else {
                paramString = paramValue.toString();
            }
            Object mapValue = results.get(paramId);
            if (mapValue == null) {
                results.put(paramId, paramString);
            } else if (mapValue instanceof String[]) {
                String[] oldValues = (String[]) mapValue;
                String[] newValues = new String[oldValues.length + 1];
                System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
                newValues[oldValues.length] = paramString;
                results.put(paramId, newValues);
            } else {
                String[] newValues = new String[2];
                newValues[0] = mapValue.toString();
                newValues[1] = paramString;
                results.put(paramId, newValues);
            }
        }
    }
    // Add our transaction control token (if requested)
    if (transaction) {
        HttpSession session = pageContext.getSession();
        String token = null;
        if (session != null) {
            token = (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
        }
        if (token != null) {
            results.put(Constants.TOKEN_KEY, token);
        }
    }
    // Return the completed Map
    return (results);
}
Also used : JspException(javax.servlet.jsp.JspException) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JspException (javax.servlet.jsp.JspException)151 IOException (java.io.IOException)34 Map (java.util.Map)30 HashMap (java.util.HashMap)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)21 Iterator (java.util.Iterator)20 JspWriter (javax.servlet.jsp.JspWriter)20 ActionMessages (org.apache.struts.action.ActionMessages)15 MockFormBean (org.apache.struts.mock.MockFormBean)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 ActionMessage (org.apache.struts.action.ActionMessage)11 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 List (java.util.List)7 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 MalformedURLException (java.net.MalformedURLException)5 Locale (java.util.Locale)5 ModuleConfig (org.apache.struts.config.ModuleConfig)5 UserContext (org.mifos.security.util.UserContext)5 JspTag (javax.servlet.jsp.tagext.JspTag)4