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:nl.strohalm.cyclos.taglibs.PaginationTag.java

@Override
public int doEndTag() throws JspException {
    final JspWriter out = pageContext.getOut();

    try {//w  ww.  j  a  va 2  s .  co m
        if (!(items instanceof Page<?>)) {
            out.println("<!-- pagination tag: items is not a page -->");
            return EVAL_PAGE;
        }
        out.println("<span style='vertical-align:middle'>");
        final Page<?> page = (Page<?>) items;
        final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

        final int currentPage = page.getCurrentPage() + 1;
        final int pageCount = page.getPageCount();

        if (!page.isEmpty()) {
            final MessageHelper messageHelper = SpringHelper.bean(pageContext.getServletContext(),
                    MessageHelper.class);
            if (pageCount == 1) {
                out.println(messageHelper.message("global.pagination.single.page", page.getTotalCount()));
            } else {
                out.println(messageHelper.message("global.pagination.various.pages", page.getTotalCount()));
                if (currentPage > 1) {
                    out.println(pageLink(currentPage - 1, "<img src=\"" + request.getContextPath()
                            + "/pages/images/previous.gif\" style=\"valign:bottom\" border=\"0\" title=\""
                            + messageHelper.message("global.pagination.tooltip.previous") + "\">"));
                }
                out.println(StringUtils.join(resolvePages(currentPage, pageCount), ' '));
                if (currentPage < pageCount) {
                    out.println(pageLink(currentPage + 1,
                            "<img src=\"" + request.getContextPath()
                                    + "/pages/images/next.gif\" style=\"valign:bottom\" border=\"0\" title=\""
                                    + messageHelper.message("global.pagination.tooltip.next") + "\">"));
                }
            }
        }
        out.println("</span>");
        return EVAL_PAGE;
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }

}

From source file:nl.strohalm.cyclos.taglibs.ProfileTag.java

@Override
public int doEndTag() throws JspException {
    try {//from  www. ja v  a 2s. com
        final JspWriter out = pageContext.getOut();
        try {
            out.write(generateProfileField());
        } catch (final IOException e) {
            throw new JspException(e);
        }
    } finally {
        release();
    }
    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.RichTextAreaTag.java

@Override
public int doEndTag() throws JspException {

    final JspWriter out = pageContext.getOut();
    final String value = this.value;
    final String id = StringUtils.isEmpty(styleId) ? name : styleId;
    try {//from   w  w  w  . j  av a2  s.  com
        final StringBuilder sb = new StringBuilder();
        if (disabled) {
            // When a rich text field is not enabled, render a div and the text inside.
            // Only when enabling it the editor will be rendered
            sb.append("<div style='position:relative;padding-right:6px;'><div id='textOfField_").append(id)
                    .append("' class='fakeFieldDisabled' style='width:479px;height:200px;overflow:auto;'><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td style='padding:0px'>");
            sb.append(StringUtils.isEmpty(value) ? "&nbsp;" : value);
            sb.append("</td></tr></table></div></div>");
            sb.append("<div id='envelopeOfField_").append(id).append("' style='display:none'>");
        }

        final StringBuilder className = new StringBuilder();
        if (StringUtils.isNotEmpty(styleClass)) {
            className.append(styleClass);
        }
        className.append(" full");
        className.append(disabled ? " richEditorDisabled" : " richEditor");
        final String containerId = "container_" + id;
        sb.append("<div class='richTextAreaContainer' id=\"").append(containerId).append("\">");
        sb.append("<textarea rows='6' name='").append(name).append('\'');
        if (StringUtils.isNotEmpty(styleId)) {
            sb.append(" id='" + styleId + '\'');
            sb.append(" fieldId='" + styleId + '\'');
        }
        sb.append(" class='").append(className).append('\'');
        sb.append(' ').append(attributesForTag()).append('>');
        sb.append(value);
        sb.append("</textarea>");
        sb.append("</div>");
        if (disabled) {
            sb.append("</div>");
        } else {
            // Eager init if not disabled
            sb.append("<script>\n");
            sb.append("richEditorsToInitialize.push($('").append(containerId).append("').firstChild);\n");
            sb.append("</script>\n");
        }
        out.print(sb.toString());
        return EVAL_PAGE;
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
}

From source file:nl.strohalm.cyclos.taglibs.ScriptTag.java

@Override
public int doEndTag() throws JspException {
    src = StringUtils.trimToNull(src);/*from w w  w  .  j a  va 2  s.c om*/
    if (src != null) {
        try {
            pageContext.getOut().println(generateScriptTag());
        } catch (final IOException e) {
            throw new JspException(e);
        } finally {
            release();
        }
    }
    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.TruncateTag.java

@Override
public int doEndTag() throws JspException {
    final JspWriter out = pageContext.getOut();
    try {/*from   w  w  w .j a v a 2 s  . c o  m*/
        out.write(truncate(value, length, lines, html));
    } catch (final IOException e) {
        throw new JspException(e);
    }
    return EVAL_PAGE;
}

From source file:no.kantega.publishing.api.taglibs.util.AbbreviateTag.java

/**
 * Rendrer endret body./* w  w  w .  jav  a  2  s .  c om*/
 *
 * @return
 * @throws JspException
 */
public int doEndTag() throws JspException {

    try {
        JspWriter out = pageContext.getOut();
        out.print(text);
    } catch (IOException ioe) {
        throw new JspException(ioe.toString());
    }
    return EVAL_PAGE;

}

From source file:no.kantega.publishing.api.taglibs.util.GetUrlTag.java

public int doStartTag() throws JspException {
    JspWriter out;/*  ww w.j  av a  2s  .  c o m*/
    try {
        out = pageContext.getOut();

        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        if (isNotBlank(url)) {
            initUrlPlaceholderResolverIfNull();
            StringBuilder urlBuilder = new StringBuilder();
            if (isAbsoluteUrl(url)) {
                urlBuilder.append(url);
            } else {
                if (absoluteUrl) {
                    addSchemeServerAndContextPath(urlBuilder, request);
                }
                if (addcontextpath && !absoluteUrl) {
                    urlBuilder.append(request.getContextPath());
                }
                if (url.charAt(0) == '/' || url.charAt(0) == '$') {
                    urlBuilder.append(url);
                } else {
                    urlBuilder.append('/');
                    urlBuilder.append(url);
                }
            }

            addSiteIdIfInAdminMode(urlBuilder, request);

            if (queryParams != null) {
                if ((!queryParams.startsWith("&")) && (!queryParams.startsWith("?"))
                        && (!queryParams.startsWith("#"))) {
                    if (urlBuilder.indexOf("?") == -1) {
                        urlBuilder.append("?");
                    } else {
                        urlBuilder.append("&amp;");
                    }
                }
                urlBuilder.append(queryParams.replaceAll("&", "&amp;"));
            }

            String buildUrl = urlPlaceholderResolver.replaceMacros(urlBuilder.toString(), pageContext);

            if (!escapeurl) {
                out.write(buildUrl.replaceAll("&amp;", "&"));
            } else {
                out.write(buildUrl);
            }

        } else {
            out.write(request.getContextPath());
        }

    } catch (Exception e) {
        log.error("", e);
        throw new JspException(e);
    }

    resetVars();

    return SKIP_BODY;
}

From source file:org.acegisecurity.taglibs.authz.AccessControlListTag.java

public int doStartTag() throws JspException {
    initializeIfRequired();//from   w w  w .  j a v a  2s .c  om

    if ((null == hasPermission) || "".equals(hasPermission)) {
        return Tag.SKIP_BODY;
    }

    final String evaledPermissionsString = ExpressionEvaluationUtils.evaluateString("hasPermission",
            hasPermission, pageContext);

    Permission[] requiredPermissions = null;

    try {
        requiredPermissions = parsePermissionsString(evaledPermissionsString);
    } catch (NumberFormatException nfe) {
        throw new JspException(nfe);
    }

    Object resolvedDomainObject = null;

    if (domainObject instanceof String) {
        resolvedDomainObject = ExpressionEvaluationUtils.evaluate("domainObject", (String) domainObject,
                Object.class, pageContext);
    } else {
        resolvedDomainObject = domainObject;
    }

    if (resolvedDomainObject == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("domainObject resolved to null, so including tag body");
        }

        // Of course they have access to a null object!
        return Tag.EVAL_BODY_INCLUDE;
    }

    if (SecurityContextHolder.getContext().getAuthentication() == null) {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "SecurityContextHolder did not return a non-null Authentication object, so skipping tag body");
        }

        return Tag.SKIP_BODY;
    }

    Sid[] sids = sidRetrievalStrategy.getSids(SecurityContextHolder.getContext().getAuthentication());
    ObjectIdentity oid = objectIdentityRetrievalStrategy.getObjectIdentity(resolvedDomainObject);

    // Obtain aclEntrys applying to the current Authentication object
    try {
        Acl acl = aclService.readAclById(oid, sids);

        if (acl.isGranted(requiredPermissions, sids, false)) {
            return Tag.EVAL_BODY_INCLUDE;
        } else {
            return Tag.SKIP_BODY;
        }
    } catch (NotFoundException nfe) {
        return Tag.SKIP_BODY;
    }
}

From source file:org.acegisecurity.taglibs.authz.AccessControlListTag.java

private void initializeIfRequired() throws JspException {
    if (applicationContext == null) {
        this.applicationContext = getContext(pageContext);

        Map map = applicationContext.getBeansOfType(AclService.class);

        if (map.size() != 1) {
            throw new JspException(
                    "Found incorrect number of AclService instances in application context - you must have only have one!");
        }/*from ww  w  .  j a va2  s  .  co  m*/

        aclService = (AclService) map.values().iterator().next();

        map = applicationContext.getBeansOfType(SidRetrievalStrategy.class);

        if (map.size() == 0) {
            sidRetrievalStrategy = new SidRetrievalStrategyImpl();
        } else if (map.size() == 1) {
            sidRetrievalStrategy = (SidRetrievalStrategy) map.values().iterator().next();
        } else {
            throw new JspException("Found incorrect number of SidRetrievalStrategy instances in application "
                    + "context - you must have only have one!");
        }

        map = applicationContext.getBeansOfType(ObjectIdentityRetrievalStrategy.class);

        if (map.size() == 0) {
            objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl();
        } else if (map.size() == 1) {
            objectIdentityRetrievalStrategy = (ObjectIdentityRetrievalStrategy) map.values().iterator().next();
        } else {
            throw new JspException("Found incorrect number of ObjectIdentityRetrievalStrategy instances in "
                    + "application context - you must have only have one!");
        }
    }
}

From source file:org.acegisecurity.taglibs.authz.AclTag.java

public int doStartTag() throws JspException {
    if ((null == hasPermission) || "".equals(hasPermission)) {
        return Tag.SKIP_BODY;
    }//from   w w w  .  ja v a  2 s. c  o  m

    final String evaledPermissionsString = ExpressionEvaluationUtils.evaluateString("hasPermission",
            hasPermission, pageContext);

    Integer[] requiredIntegers = null;

    try {
        requiredIntegers = parseIntegersString(evaledPermissionsString);
    } catch (NumberFormatException nfe) {
        throw new JspException(nfe);
    }

    Object resolvedDomainObject = null;

    if (domainObject instanceof String) {
        resolvedDomainObject = ExpressionEvaluationUtils.evaluate("domainObject", (String) domainObject,
                Object.class, pageContext);
    } else {
        resolvedDomainObject = domainObject;
    }

    if (resolvedDomainObject == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("domainObject resolved to null, so including tag body");
        }

        // Of course they have access to a null object!
        return Tag.EVAL_BODY_INCLUDE;
    }

    if (SecurityContextHolder.getContext().getAuthentication() == null) {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "SecurityContextHolder did not return a non-null Authentication object, so skipping tag body");
        }

        return Tag.SKIP_BODY;
    }

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    ApplicationContext context = getContext(pageContext);
    String[] beans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, AclManager.class, false,
            false);

    if (beans.length == 0) {
        throw new JspException("No AclManager would found the application context: " + context.toString());
    }

    AclManager aclManager = (AclManager) context.getBean(beans[0]);

    // Obtain aclEntrys applying to the current Authentication object
    AclEntry[] acls = aclManager.getAcls(resolvedDomainObject, auth);

    if (logger.isDebugEnabled()) {
        logger.debug("Authentication: '" + auth + "' has: " + ((acls == null) ? 0 : acls.length)
                + " AclEntrys for domain object: '" + resolvedDomainObject + "' from AclManager: '"
                + aclManager.toString() + "'");
    }

    if ((acls == null) || (acls.length == 0)) {
        return Tag.SKIP_BODY;
    }

    for (int i = 0; i < acls.length; i++) {
        // Locate processable AclEntrys
        if (acls[i] instanceof BasicAclEntry) {
            BasicAclEntry processableAcl = (BasicAclEntry) acls[i];

            // See if principal has any of the required permissions
            for (int y = 0; y < requiredIntegers.length; y++) {
                if (processableAcl.isPermitted(requiredIntegers[y].intValue())) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Including tag body as found permission: " + requiredIntegers[y]
                                + " due to AclEntry: '" + processableAcl + "'");
                    }

                    return Tag.EVAL_BODY_INCLUDE;
                }
            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("No permission, so skipping tag body");
    }

    return Tag.SKIP_BODY;
}