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:jp.terasoluna.fw.web.struts.taglib.LinkTag.java

/**
 * <p>URLLbVp_ID?B</p>/*from   w ww . j  a  v  a2s .co  m*/
 *
 * <p>zbgX|bg?A<code>Struts 1.2.4</code> 
 * <code>LinkTag.calculate()</code> R?[hRs?[?X?B
 * <code>Struts</code> o?[W?X??
 * Kv??B</p>
 *
 * @return ???w
 * @exception JspException G?[?
 */
@SuppressWarnings("unchecked")
@Override
protected String calculateURL() throws JspException {

    // Identify the parameters we will add to the completed URL
    Map<String, String> params = TagUtils.getInstance().computeParameters(pageContext, paramId, paramName,
            paramProperty, paramScope, name, property, scope, transaction);

    // ========== ?yg??z?==========
    if (params == null) {
        params = new HashMap<String, String>();
    }

    //_ID??????B
    forward = RequestUtil.deleteUrlParam(forward, RANDOM_ID_KEY);
    href = RequestUtil.deleteUrlParam(href, RANDOM_ID_KEY);
    page = RequestUtil.deleteUrlParam(page, RANDOM_ID_KEY);
    action = RequestUtil.deleteUrlParam(action, RANDOM_ID_KEY);

    //p??[^}bv_ID?B
    params.put(RANDOM_ID_KEY, RandomUtil.generateRandomID());

    // if "indexed=true", add "index=x" parameter to query string
    // * @since Struts 1.1
    if (indexed) {

        // look for outer iterate tag
        IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class);
        if (iterateTag == null) {
            // iterateTagbodygp??O
            JspException e = new JspException(messages.getMessage("indexed.noEnclosingIterate"));
            TagUtils.getInstance().saveException(pageContext, e);

            log.error("iterateTag is null.");
            throw e;
        }

        if (indexId != null) {
            params.put(indexId, Integer.toString(iterateTag.getIndex()));
        } else {
            params.put("index", Integer.toString(iterateTag.getIndex()));
        }
    }
    // ========== ?yg??z?==========

    String url = null;
    try {
        url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href, page, action,
                module, params, anchor, false, useLocalEncoding);
    } catch (MalformedURLException e) {
        TagUtils.getInstance().saveException(pageContext, e);

        log.error("Malformed URL has occurred.");
        throw new JspException(messages.getMessage("rewrite.url", e.toString()));
    }
    return (url);

}

From source file:org.jamwiki.taglib.LinkTag.java

/**
 *
 *//*from  w  w  w.j av  a  2  s .  c o m*/
protected void addQueryParam(String key, String value) throws JspException {
    if (StringUtils.isBlank(key)) {
        throw new JspException("linkParam key value cannot be empty");
    }
    this.queryParams = LinkUtil.appendQueryParam(this.queryParams, key, value);
}

From source file:de.laures.cewolf.taglib.tags.ChartImgTag.java

public int doAfterBody() throws JspException {
    try {/*from   w  ww . java2s .  c o  m*/
        // double checking for null as Resin had problems with that
        final BodyContent body = getBodyContent();
        if (body != null) {
            final JspWriter writer = getPreviousOut();
            if (writer != null) {
                body.writeOut(writer);
            }
        }

    } catch (IOException ioex) {
        System.err.println("ChartImgTag.doAfterBody: " + ioex.getMessage());
        throw new JspException(ioex.getMessage());
    }
    return SKIP_BODY;
}

From source file:com.xhsoft.framework.common.page.OrderTag.java

/**
 * <p>Description:</p>//from  ww w.j  ava  2  s  .  co  m
 * @return int
 * @author wenzhi
 * @version 1.0
 * @exception Exception
 */
@Override
public int doStartTag() throws JspException {
    /** ?request*/
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String descMessage = "descMessage";
    String ascMessage = "ascMessage";
    String realTitle = this.getTitle();
    try {
    } catch (NoSuchMessageException e1) {
    }

    String sortType = "";
    String image = "";
    int cnt = 0;

    String order = request.getParameter(ORDER);
    if (StringUtils.isNotEmpty(order)) {
        /** ???*/
        String[] orderItems = order.split(",");
        for (String orderItem : orderItems) {
            cnt++;
            List<String> list = new ArrayList<String>();
            String[] items = orderItem.split(" ");
            for (String item : items) {
                if (item.length() > 0) {
                    list.add(item);
                }
            }

            /**?*/
            if (list.get(0).equalsIgnoreCase(field)) {
                sortType = list.get(1);
                /** ????*/
                image = "<img border='0' src='" + request.getContextPath() + "/images/table/sort_" + sortType
                        + ".gif' align='absmiddle' title='"
                        + ("asc".equals(sortType) ? ascMessage : descMessage) + "'/>"
                        + "<span class='orderCount'>" + cnt + "</span>";
                break;
            }

        }
    }

    try {
        JspWriter out = pageContext.getOut();
        StringBuffer sb = new StringBuffer();
        String reverseSortType = null;
        /** ??*/
        if ("".equals(sortType)) {
            reverseSortType = "asc";
        } else if ("asc".equals(sortType)) {
            reverseSortType = "desc";
        } else if ("desc".equals(sortType)) {
            reverseSortType = "na";
        }
        String titleMessage = "";
        sb.append("<a href=\"javascript:setOrder('" + field + "','" + reverseSortType + "','" + targets
                + "');\" title=\"" + titleMessage + "\">");
        sb.append(realTitle);
        sb.append("</a>");
        sb.append(image);
        out.print(sb.toString());
    } catch (Exception e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}

From source file:ch.entwine.weblounge.taglib.resource.VideoResourceTag.java

/**
 * {@inheritDoc}//from  w  w w .  ja va 2s . c o  m
 * 
 * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
 */
@Override
public int doStartTag() throws JspException {

    // Don't do work if not needed (which is the case during precompilation)
    if (RequestUtils.isPrecompileRequest(request))
        return SKIP_BODY;

    Site site = request.getSite();
    Language language = request.getLanguage();

    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
        logger.debug("Unable to load content repository for site '{}'", site);
        response.invalidate();
        return SKIP_BODY;
    }

    // Create the resource uri, either from the id or the path. If none is
    // specified, and we are not in jsp compilation mode, issue a warning
    ResourceURI uri = null;
    if (StringUtils.isNotBlank(videoId)) {
        uri = new MovieResourceURIImpl(site, null, videoId);
    } else if (StringUtils.isNotBlank(videoResourcePath)) {
        uri = new MovieResourceURIImpl(site, videoResourcePath);
    } else {
        throw new JspException("Neither video id nor video path were specified");
    }

    // Try to load the video resource from the content repository
    try {
        if (!repository.exists(uri)) {
            logger.warn("Non existing video resource {} requested on {}", uri, request.getUrl());
            return SKIP_BODY;
        }
    } catch (ContentRepositoryException e) {
        logger.error("Error trying to look up video resource {} from {}", videoId, repository);
        return SKIP_BODY;
    }

    MovieResource video = null;
    MovieContent videoContent = null;

    // Store the result in the jsp page context
    try {
        video = (MovieResource) repository.get(uri);
        video.switchTo(language);
        videoContent = video.getContent(language);
        if (videoContent == null)
            videoContent = video.getOriginalContent();
    } catch (ContentRepositoryException e) {
        logger.warn("Error trying to load video resource " + uri + ": " + e.getMessage(), e);
        return SKIP_BODY;
    }

    // TODO: Check the permissions

    // Store the resource and the resource content in the request
    stashAndSetAttribute(VideoResourceTagExtraInfo.VIDEO, video);
    stashAndSetAttribute(VideoResourceTagExtraInfo.VIDEO_CONTENT, videoContent);

    // Add cache tags to the response
    response.addTag(CacheTag.Resource, video.getURI().getIdentifier());
    response.addTag(CacheTag.Url, video.getURI().getPath());

    return EVAL_BODY_INCLUDE;
}

From source file:com.adito.input.tags.ToolTipTag.java

public int doStartTag() throws JspException {
    enabled = CoreUtil.getToolTipsEnabled(pageContext.getSession());

    displayText = null;/*from w ww. j a  v a2  s  .c om*/
    if (value == null) {

        if (key == null && name != null) {
            // Look up the requested property value
            Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
            if (value != null && !(value instanceof String)) {
                JspException e = new JspException(messages.getMessage("message.property", key));
                TagUtils.getInstance().saveException(pageContext, e);
                throw e;
            }
            displayText = (String) value;
        }

        // Retrieve the message string we are looking for
        if (displayText == null && key != null) {
            displayText = TagUtils.getInstance().message(pageContext, this.bundle, this.localeKey, key);
            if (displayText == null) {
                log.error("Missing message for key " + key + " bundle = " + bundle);
            }
        }

        // Content location
        if (contentLocation != null) {
            displayText = "";
        }
    } else {
        displayText = value;
    }

    return EVAL_BODY_BUFFERED;
}

From source file:de.micromata.genome.gwiki.page.impl.actionbean.GWikiErrorsTag.java

/**
 * Render the specified error messages if there are any.
 * /*from   ww  w . j a va  2s . co  m*/
 * @exception JspException if a JSP exception has occurred
 */
@Override
public int doStartTag() throws JspException {
    ActionMessages am = (ActionMessages) pageContext.getRequest().getAttribute(ERRORS_TAG_REQUEST_ATTRIBUTE);
    if (am == null || am.isEmpty() == true) {
        return EVAL_BODY_INCLUDE;
    }
    initHeaderFooter();
    StringBuilder sb = new StringBuilder();
    sb.append(this.header);
    Locale loc = Locale.getDefault();
    Matcher<String> m = new EveryMatcher<String>();
    if (StringUtils.isNotBlank(pattern) == true) {
        m = new BooleanListRulesFactory<String>().createMatcher(pattern);
    }
    for (Map.Entry<String, List<ActionMessage>> me : am.entrySet()) {
        if (m.match(me.getKey()) == false) {
            continue;
        }
        for (ActionMessage amm : me.getValue()) {
            if (amm instanceof SimpleActionMessage) {
                sb.append(this.prefix).append(WebUtils.escapeHtml(amm.getMessage(loc))).append(this.suffix);
            } else {
                sb.append(this.prefix).append(WebUtils.escapeHtml(amm.getMessage(loc))).append(this.suffix);
            }
        }
    }
    sb.append(footer);
    try {
        pageContext.getOut().write(sb.toString());
    } catch (IOException ex) {
        throw new JspException(ex);
    }
    return EVAL_BODY_INCLUDE;

}

From source file:org.hdiv.web.servlet.tags.UrlTagHDIV.java

@Override
public int doEndTag() throws JspException {
    String url = createUrl();/* w  ww  .  j  a  va2 s  .  com*/

    if (this.var == null) {
        // print the url to the writer
        try {
            pageContext.getOut().print(url);
        } catch (IOException e) {
            throw new JspException(e);
        }
    } else {
        // store the url as a variable
        pageContext.setAttribute(var, url, scope);
    }
    return EVAL_PAGE;
}

From source file:jp.terasoluna.fw.web.taglib.IfAuthorizedBlockTag.java

/**
 * ^O]Jn?\bh?B/*from  www .ja  v a 2 s.  c  o  m*/
 *
 * @return ???w
 * @throws JspException JSPO
 */
@Override
public int doStartTag() throws JspException {

    if (this.blockId == null) {
        throw new JspException("blockId is required.");
    }

    // {fB]
    return EVAL_BODY_BUFFERED;
}

From source file:jp.terasoluna.fw.web.taglib.TagUtil.java

/**
 * PageContextJspWriter?AweLXg?o?B/* ww  w.j a  v a2  s .  c o m*/
 * ?s?B
 * 
 * @param pageContext y?[WReLXg
 * @param text ?oeLXg
 * @throws JspException
 * I/OG?[???IOExceptionbvO
 */
public static void writeln(PageContext pageContext, String text) throws JspException {
    JspWriter writer = pageContext.getOut();
    try {
        writer.println(text);
    } catch (IOException e) {
        throw new JspException(e);
    }
}