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:com.googlecode.jtiger.modules.ecside.tag.TableTag.java

public int doAfterBody() throws JspException {

    Table table = model.getTable();//  w ww .j  a  va2  s  .c  o m
    table.setAttribute(TableConstants.EXTEND_ATTRIBUTES, getExtendAttributesAsString());
    resetExtendAttribute();
    table.afterBody();

    try {

        if (iterator == null) {
            iterator = model.execute().iterator();
        }
        if (iterator != null && iterator.hasNext()) {
            Object bean = iterator.next();
            model.setCurrentRowBean(bean);
            return EVAL_BODY_AGAIN;
        }

    } catch (Exception e) {
        throw new JspException("TableTag.doAfterBody() Problem: " + ExceptionUtils.formatStackTrace(e));
    }

    return SKIP_BODY;
}

From source file:com.seajas.search.utilities.tags.MessageTag.java

/**
 * Put the actual internal processing in here.
 * //  w w  w  .  ja v a2  s  .  c o  m
 * @return
 * @throws JspException
 */
@Override
public int doEndTag() throws JspException {
    try {
        // Resolve the unescaped message.
        String msg = resolveMessage();

        // HTML and/or JavaScript escape, if demanded.
        msg = isHtmlEscape() ? HtmlUtils.htmlEscape(msg) : msg;
        msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg;

        // Expose as variable, if demanded, else write to the page.
        String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, pageContext);
        if (resolvedVar != null) {
            String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, pageContext);
            pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(resolvedScope));
        } else {
            try {
                writeMessage(msg);
            } catch (IOException e) {
                throw new JspException(e);
            }
        }

        return super.doAfterBody();
    } catch (NoSuchMessageException ex) {
        throw new JspTagException(getNoSuchMessageExceptionDescription(ex));
    }
}

From source file:com.tecapro.inventory.common.tag.MSButtonTag.java

@Override
public int doStartTag() throws JspException {

    try {/* w  w w.j  ava 2  s.  c om*/
        String nameSpace = "";
        if (this.nameSpace != null) {
            nameSpace = this.nameSpace;
        }

        MessageUtil msgUtil = (MessageUtil) WebApplicationContextUtils
                .getWebApplicationContext(pageContext.getServletContext()).getBean(BEAN_NAME_MSG_UTIL);
        StringUtil strUtil = (StringUtil) WebApplicationContextUtils
                .getWebApplicationContext(pageContext.getServletContext()).getBean(BEAN_NAME_STR_UTIL);

        TilesInfoValue value = (TilesInfoValue) pageContext
                .getAttribute(nameSpace + TilesInfoValue.class.getSimpleName(), PageContext.REQUEST_SCOPE);
        BaseForm form = (BaseForm) pageContext.getRequest().getAttribute(BaseForm.class.getSimpleName());
        InfoValue info = form.getValue().getInfo();
        value.setInfo(info);
        List<ButtonInfoValue> list = value.getButtonList();
        ButtonInfoValue buttonInfo = list.get(index);

        if (buttonInfo == null || buttonInfo.getButtonName() == null) {
            this.setStyleClass("display_none");
            MSTagUtil.addStyleClass(this, "disabled");
            return super.doStartTag();
        }

        if (buttonInfo.getInvisible() != null) {
            String flag = BeanUtils.getProperty(form, buttonInfo.getInvisible());

            if (Constants.ONE.equals(flag)) {
                this.setStyleClass("display_hidden");
                return super.doStartTag();
            }
        }

        if (buttonInfo.getDisable() != null) {
            String flag = BeanUtils.getProperty(form, buttonInfo.getDisable());

            if (Constants.ONE.equals(flag)) {
                this.setDisabled(true);
                MSTagUtil.addStyleClass(this, "disabled");
            }
        }
        if (this.getDisabled()) {
            MSTagUtil.addStyleClass(this, "disabled");
        }

        StringBuffer onclick = new StringBuffer();

        if (getOnclick() != null && !"".equals(getOnclick())) {
            onclick.append(getOnclick() + ";");
        }

        if (buttonInfo.getMessageId() != null) {
            String[] params = null;
            if (buttonInfo.getMessageParam() != null) {
                StringTokenizer token = new StringTokenizer(buttonInfo.getMessageParam(), ",");
                List<String> tokenList = new ArrayList<String>();
                while (token.hasMoreTokens()) {
                    tokenList.add(token.nextToken());
                }
                params = tokenList.toArray(new String[tokenList.size()]);
            }

            onclick.append("if (!windowConfirm('").append(msgUtil.getMessage(buttonInfo.getMessageId(), params))
                    .append("')){return;};");
        }

        // dirty check msg default
        String msgId = "MSG078C";

        if (buttonInfo.isDirtyCheck() || Constants.BACK.equals(buttonInfo.getButtonName())
                || Constants.MENU_MODORU.equals(buttonInfo.getButtonName())) {
            if (!strUtil.isNull(buttonInfo.getDirtyMsgId()) && !"".equals(buttonInfo.getDirtyMsgId())) {
                msgId = buttonInfo.getDirtyMsgId();
            }
            onclick.append("if (!lossMessage('").append(msgUtil.getMessage(msgId, null))
                    .append("')){return;};");
        }

        if (buttonInfo.getOnClick() != null && !"".equals(buttonInfo.getOnClick())) {
            onclick.append(buttonInfo.getOnClick() + ";");
        }

        if (buttonInfo.getAction() != null && !"".equals(buttonInfo.getAction())) {
            onclick.append("send('").append(buttonInfo.getAction()).append("');");
        }

        if (!"".equals(onclick.toString())) {
            this.setOnclick(onclick.toString());
        }
        this.setValue(buttonInfo.getButtonName());

        return super.doStartTag();
    } catch (Exception e) {
        throw new JspException(e);
    } catch (Throwable e) {
        throw new JspException(e);
    }
}

From source file:ams.fwk.customtag.AmsDownloadTag.java

/**
 * @return int//  w  w w . j  a  v  a  2  s .  c o m
 * @throws JspException
 */
public int doEndTag() throws JspException {
    String context = getContextPath(pageContext);
    try {
        List uploads = getUploads();
        JspWriter out = pageContext.getOut();
        out.print(listOpen);

        for (Iterator all = uploads.iterator(); all.hasNext();) {
            Map each = (Map) all.next();
            if ("IMG".equals(typeId)) {
                String temp = StringUtils.replace(imgTag, "$context$", context);

                temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID"));
                temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo);
                temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID"));

                out.print(temp);

            } else if ("URL".equals(typeId)) {
                String temp = StringUtils.replace(urlTag, "$context$", context);
                temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID"));
                temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo);
                temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID"));

                out.print(temp);
            } else {
                //                   ("N/A".equals(typeId) || typeId.equals(each.get("TYPE_ID"))) {
                String temp = "";
                if ("N".equals(deleteOption)) {
                    temp = StringUtils.replace(listItem, "$deleteImgTag$", "");
                } else {
                    temp = StringUtils.replace(listItem, "$deleteImgTag$", deleteImgTag);
                }
                temp = StringUtils.replace(temp, "$context$", context);
                temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID"));
                temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo);
                temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID"));
                temp = StringUtils.replace(temp, "$filename$", (String) each.get("FILE_NAME"));
                temp = StringUtils.replace(temp, "$filesize$", nexcore.framework.core.util.StringUtils
                        .formatNumber(((BigDecimal) each.get("FILE_SIZE")).toString(), "FINT"));
                out.print(temp);
            }
        }
        out.print(listClose);

        return EVAL_PAGE;
    } catch (IOException e) {
        e.printStackTrace();
        throw new JspException(e);
    } finally {
        typeId = "N/A";
    }
}

From source file:com.gisgraphy.webapp.taglib.ConstantsTag.java

/**
 * Converts the scope name into its corresponding PageContext constant
 * value.//from  ww  w .ja va2s.c o m
 * 
 * @param scopeName
 *                Can be "page", "request", "session", or "application" in
 *                any case.
 * @return The constant representing the scope (ie.
 *         PageContext.REQUEST_SCOPE).
 * @throws JspException
 *                 if the scopeName is not a valid name.
 */
public int getScope(String scopeName) throws JspException {
    Integer scope = SCOPES.get(scopeName.toLowerCase());

    if (scope == null) {
        throw new JspException("Scope '" + scopeName + "' not a valid option");
    }

    return scope;
}

From source file:com.googlecode.jtiger.modules.ecside.tag.TableTag.java

public void doCatch(Throwable e) throws Throwable {
    throw new JspException("TableTag Problem: " + ExceptionUtils.formatStackTrace(e));
}

From source file:net.ontopia.topicmaps.webed.taglibs.form.FormTag.java

@Override
public int doStartTag() throws JspException {
    NavigatorPageIF contextTag = FrameworkUtils.getContextTag(pageContext);
    if (contextTag == null)
        throw new JspTagException("<webed:form> must be nested" + " within a <tolog:context> tag, but no"
                + " <tolog:context> was found.");

    if (TagSupport.findAncestorWithClass(this, FormTag.class) != null)
        throw new JspTagException("<webed:form> cannot be nested");

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    boolean readonly = InteractionELSupport.getBooleanValue(this.readonly, false, pageContext);
    request.setAttribute(Constants.OKS_FORM_READONLY, readonly);

    // put the name of the action group to page scope
    // to allow child tags to access this information
    TagUtils.setActionGroup(pageContext, actiongroup);

    TagUtils.setCurrentFormTag(request, this);

    requestId = TagUtils.createRequestId();

    // -- try to lock variable
    UserIF user = FrameworkUtils.getUser(pageContext);
    if (lockVarname != null) {
        ActionRegistryIF registry = TagUtils.getActionRegistry(pageContext);
        if (registry == null)
            throw new JspException(
                    "No action registry! Check actions.xml for " + "errors; see log for details.");

        Collection lockColl = InteractionELSupport.extendedGetValue(lockVarname, pageContext);

        NamedLockManager lockMan = TagUtils.getNamedLockManager(pageContext.getServletContext());
        LockResult lockResult = lockMan.attemptToLock(user, lockColl, lockVarname, pageContext.getSession());
        lockVarname = lockResult.getName();

        Collection unlockable = lockResult.getUnlockable();
        request.setAttribute(Constants.LOCK_RESULT, lockResult);

        if (!unlockable.isEmpty()) {
            logger.warn("Unable to lock contents of variable '" + lockVarname + "'." + unlockable);
            // forward to error page if variable is locked
            ActionGroupIF ag = registry.getActionGroup(actiongroup);
            ActionForwardPageIF forwardPage = ag.getLockedForwardPage();
            if (forwardPage != null && forwardPage.getURL() != null) {
                String fwd_url = forwardPage.getURL();
                logger.info("Forward to lock error page: " + fwd_url);
                try {
                    ((HttpServletResponse) pageContext.getResponse()).sendRedirect(fwd_url);
                } catch (IOException ioe) {
                    logger.error("Problem occurred while forwarding: " + ioe.getMessage());
                    throw new JspException("I/O-Problem while forwarding to '" + fwd_url + "': " + ioe);
                }/*from   w  w w  . j av  a  2  s . c  om*/
                return SKIP_PAGE;
            } else {
                logger.warn("No forward page found for lock situation. Setting form to be read-only");
                request.setAttribute(Constants.OKS_FORM_READONLY, Boolean.TRUE);
            }
        } else {
            logger.info("Locked contents of variable '" + lockVarname + "'.");
        }
    }

    // register a new action data set
    pageContext.setAttribute(FormTag.REQUEST_ID_ATTRIBUTE_NAME, requestId, PageContext.REQUEST_SCOPE);
    TagUtils.createActionDataSet(pageContext);

    return EVAL_BODY_BUFFERED;
}

From source file:org.hdiv.web.servlet.tags.form.OptionWriterHDIV.java

/**
 * Write the '<code>option</code>' tags for the configured {@link #optionSource} to
 * the supplied {@link TagWriter}./*from   w  w w.j a  v a2 s . c  o  m*/
 */
public void writeOptions(TagWriter tagWriter) throws JspException {

    if (this.optionSource.getClass().isArray()) {
        renderFromArray(tagWriter);
    } else if (this.optionSource instanceof Collection) {
        renderFromCollection(tagWriter);
    } else if (this.optionSource instanceof Map) {
        renderFromMap(tagWriter);
    } else if (this.optionSource instanceof Class && ((Class) this.optionSource).isEnum()) {
        renderFromEnum(tagWriter);
    } else {
        throw new JspException(
                "Type [" + this.optionSource.getClass().getName() + "] is not valid for option items");
    }
}

From source file:org.openmrs.contrib.metadatarepository.webapp.taglib.LabelTag.java

public int doStartTag() throws JspException {

    try {//from  w  ww  .  j  a  v a2 s  .  c o  m
        this.requestContext = new RequestContext((HttpServletRequest) this.pageContext.getRequest());
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        pageContext.getServletContext().log("Exception in custom tag", ex);
    }

    // Look up this key to see if its a field of the current form
    boolean requiredField = false;
    boolean validationError = false;

    ValidatorResources resources = getValidatorResources();

    Locale locale = pageContext.getRequest().getLocale();

    if (locale == null) {
        locale = Locale.getDefault();
    }

    // get the name of the bean from the key
    String formName = key.substring(0, key.indexOf('.'));
    String fieldName = key.substring(formName.length() + 1);

    if (resources != null) {
        Form form = resources.getForm(locale, formName);

        if (form != null) {
            Field field = form.getField(fieldName);

            if (field != null) {
                if (field.isDependency("required") || field.isDependency("validwhen")) {
                    requiredField = true;
                }
            }
        }
    }

    Errors errors = requestContext.getErrors(formName, false);
    List fes = null;
    if (errors != null) {
        fes = errors.getFieldErrors(fieldName);
        //String errorMsg = getErrorMessages(fes);
    }

    if (fes != null && fes.size() > 0) {
        validationError = true;
    }

    // Retrieve the message string we are looking for
    String message = null;
    try {
        message = getMessageSource().getMessage(key, null, locale);
    } catch (NoSuchMessageException nsm) {
        message = "???" + key + "???";
    }

    String cssClass = null;
    if (styleClass != null) {
        cssClass = styleClass;
    } else if (requiredField) {
        cssClass = "required";
    }

    String cssErrorClass = (errorClass != null) ? errorClass : "error";
    StringBuffer label = new StringBuffer();

    if ((message == null) || "".equals(message.trim())) {
        label.append("");
    } else {
        label.append("<label for=\"").append(fieldName).append("\"");

        if (validationError) {
            label.append(" class=\"").append(cssErrorClass).append("\"");
        } else if (cssClass != null) {
            label.append(" class=\"").append(cssClass).append("\"");
        }

        label.append(">").append(message);
        label.append((requiredField) ? " <span class=\"req\">*</span>" : "");
        label.append((colon) ? ":" : "");
        label.append("</label>");

        if (validationError) {
            label.append("<img class=\"validationWarning\" alt=\"");
            label.append(getMessageSource().getMessage("icon.warning", null, locale));
            label.append("\"");

            String context = ((HttpServletRequest) pageContext.getRequest()).getContextPath();

            label.append(" src=\"").append(context);
            label.append(getMessageSource().getMessage("icon.warning.img", null, locale));
            label.append("\" />");
        }
    }

    // Print the retrieved message to our output writer
    try {
        writeMessage(label.toString());
    } catch (IOException io) {
        io.printStackTrace();
        throw new JspException("Error writing label: " + io.getMessage());
    }

    // Continue processing this page
    return (SKIP_BODY);
}

From source file:org.shredzone.cilla.web.tag.LinkTag.java

@Override
public int doEndTag() throws JspException {
    String url = null;//from   www  . ja  va  2 s  .  com
    String useTitle = null;

    lb.view(view);
    lb.author(author);
    lb.category(category);
    lb.page(page);
    lb.section(section);
    lb.picture(picture);
    lb.tag(tag);
    lb.header(header);
    lb.ref(ref);
    lb.qualifier(qualifier);
    lb.commentable(commentable);

    if (title != null) {
        useTitle = title;
    } else if (page != null) {
        useTitle = page.getTitle();
    } else if (category != null) {
        useTitle = category.getTitle();
    } else if (header != null) {
        useTitle = header.getCaption();
    }

    if (anchor != null) {
        lb.anchor(anchor);
    }

    url = lb.toString();

    if (url == null) {
        throw new JspException("Cannot link to view '" + view + "'");
    }

    if (var != null) {
        TagUtils.setScopedAttribute(pageContext, var, url, scope);
        return EVAL_PAGE;
    }

    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

    StringBuilder linktag = new StringBuilder();
    linktag.append("<a href=\"");
    linktag.append(HtmlUtils.htmlEscape(response.encodeURL(url)));
    linktag.append('"');

    if (id != null) {
        linktag.append(" id=\"").append(HtmlUtils.htmlEscape(id)).append('"');
    }

    if (onclick != null) {
        linktag.append(" onclick=\"").append(HtmlUtils.htmlEscape(onclick)).append('"');
    }

    if (styleClass != null) {
        linktag.append(" class=\"").append(HtmlUtils.htmlEscape(styleClass)).append('"');
    }

    if (style != null) {
        linktag.append(" style=\"").append(HtmlUtils.htmlEscape(style)).append('"');
    }

    if (useTitle != null) {
        linktag.append(" title=\"").append(HtmlUtils.htmlEscape(useTitle)).append('"');
    }

    linktag.append('>');

    try {
        pageContext.getOut().print(linktag.toString());

        BodyContent bc = getBodyContent();
        if (bc != null) {
            bc.writeOut(pageContext.getOut());
        }

        pageContext.getOut().print("</a>");
    } catch (IOException ex) {
        throw new JspException(ex);
    }

    return EVAL_PAGE;
}