Example usage for javax.servlet.jsp JspTagException JspTagException

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

Introduction

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

Prototype


public JspTagException(Throwable rootCause) 

Source Link

Document

Constructs a new JSP Tag exception when the JSP Tag needs to throw an exception and include a message about the "root cause" exception that interfered with its normal operation.

Usage

From source file:org.openmrs.module.simplelabentry.web.taglib.PatientProgramTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*from ww w  . ja  v  a 2s.co m*/
public int doEndTag() throws JspException {
    try {
        if (bodyContent != null)
            bodyContent.writeOut(bodyContent.getEnclosingWriter());
    } catch (java.io.IOException e) {
        throw new JspTagException("IO Error: " + e.getMessage());
    }
    return EVAL_PAGE;
}

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

/**
 * ^O]Jn?\bh?B/*from www.  ja v a2 s .co m*/
 *
 * <p>
 * T?[ubgReLXg?AApplicationContext?A
 * &quot;page&quot; ?w id
 *  CodeListLoader ?A
 * R?[hXg pageContext o^?B
 *
 * R?[hXg???AArrayList
 *  pageContext o^?B
 * ?Ao^XR?[v &quot;page&quot; ??B
 * </p>
 *
 * @return ???w?B? EVAL_BODY_INCLUDE
 * @throws JspException JSP O
 */
@Override
public int doStartTag() throws JspException {
    if (log.isDebugEnabled()) {
        log.debug("doStartTag() called.");
    }

    if ("".equals(id)) {
        // id???
        log.error("id is required.");
        throw new JspTagException("id is required.");
    }
    // T?[ubgReLXg?AApplicationContext?B
    ServletContext sc = pageContext.getServletContext();
    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

    CodeListLoader loader = null;

    try {
        loader = (CodeListLoader) context.getBean(id);
    } catch (ClassCastException e) {
        //BeanCodeListLoaderOX??[
        String errorMessage = "bean id:" + id + " is not instance of CodeListLoader.";
        log.error(errorMessage);
        throw new JspTagException(errorMessage, e);
    }

    // ?P?[
    Locale locale = RequestUtils.getUserLocale((HttpServletRequest) pageContext.getRequest(),
            Globals.LOCALE_KEY);

    CodeBean[] codeBeanArray = loader.getCodeBeans(locale);
    if (codeBeanArray == null) {
        // codeBeanListnull??ArrayList??B
        if (log.isWarnEnabled()) {
            log.warn("Codebean is null. CodeListLoader(bean id:" + id + ")");
        }
        pageContext.setAttribute(id, new ArrayList(), PageContext.PAGE_SCOPE);
    } else {
        // R?[hXgo^?B
        pageContext.setAttribute(id, codeBeanArray, PageContext.PAGE_SCOPE);
    }

    return EVAL_BODY_INCLUDE;
}

From source file:org.rhq.enterprise.gui.legacy.taglib.display.CheckBoxDecorator.java

public int doStartTag() throws javax.servlet.jsp.JspException {
    ColumnTag ancestorTag = (ColumnTag) TagSupport.findAncestorWithClass(this, ColumnTag.class);
    if (ancestorTag == null) {
        throw new JspTagException("A CheckboxDecorator must be used within a ColumnTag.");
    }//from   www  .  j a v  a  2 s.com

    ancestorTag.setDecorator(this);
    return SKIP_BODY;
}

From source file:org.hyperic.hq.ui.taglib.display.MetricDecorator.java

public int doStartTag() throws JspTagException {
    ColumnTag ancestorTag = (ColumnTag) TagSupport.findAncestorWithClass(this, ColumnTag.class);

    if (ancestorTag == null) {
        throw new JspTagException("A MetricDecorator must be used within a ColumnTag.");
    }//from  www  .  j  a  v  a 2s  . c o  m

    ancestorTag.setDecorator(this);

    return SKIP_BODY;
}

From source file:org.rhq.enterprise.gui.legacy.taglib.display.MetricDecorator.java

public int doStartTag() throws JspTagException {
    ColumnTag ancestorTag = (ColumnTag) TagSupport.findAncestorWithClass(this, ColumnTag.class);
    if (ancestorTag == null) {
        throw new JspTagException("A MetricDecorator must be used within a ColumnTag.");
    }/*  w w  w.  ja v  a  2 s . co m*/

    ancestorTag.setDecorator(this);
    return SKIP_BODY;
}

From source file:org.hyperic.hq.ui.taglib.display.CheckBoxDecorator.java

public int doStartTag() throws javax.servlet.jsp.JspException {
    ColumnTag ancestorTag = (ColumnTag) TagSupport.findAncestorWithClass(this, ColumnTag.class);

    if (ancestorTag == null) {
        throw new JspTagException("A CheckboxDecorator must be used within a ColumnTag.");
    }// w  w  w.  j  ava2  s.com

    ancestorTag.setDecorator(this);

    return SKIP_BODY;
}

From source file:org.jahia.taglibs.uicomponents.i18n.DisplayLanguageSwitchLinkTag.java

public int doStartTag() {
    try {/*from   w ww .  j ava 2  s . c  om*/
        final StringBuilder buff = new StringBuilder();

        final boolean isCurrentBrowsingLanguage = isCurrentBrowsingLanguage(languageCode);
        final boolean isRedirectToHomePageActivated = InitLangBarAttributes.GO_TO_HOME_PAGE
                .equals(onLanguageSwitch);

        if (!isCurrentBrowsingLanguage) {
            if (isRedirectToHomePageActivated) {
                if (redirectCssClassName == null || redirectCssClassName.length() == 0) {
                    redirectCssClassName = InitLangBarAttributes.REDIRECT_DEFAULT_STYLE;
                }
                buff.append("<div class='");
                buff.append(redirectCssClassName);
                buff.append("'>");
            }
            buff.append("<a href='");
            final String link;
            if (onLanguageSwitch == null || onLanguageSwitch.length() == 0
                    || InitLangBarAttributes.STAY_ON_CURRENT_PAGE.equals(onLanguageSwitch)) {
                link = generateCurrentNodeLangSwitchLink(languageCode) + "##requestParameters##";

            } else if (isRedirectToHomePageActivated) {
                link = generateNodeLangSwitchLink(rootPage, languageCode) + "##requestParameters##";

            } else {
                throw new JspTagException("Unknown onLanguageSwitch attribute value " + onLanguageSwitch);
            }

            buff.append(StringEscapeUtils.escapeXml(link));
            if (urlVar != null && urlVar.length() > 0) {
                pageContext.setAttribute(urlVar, link);
            }
            buff.append("' ");
            buff.append("title='");
            if (isRedirectToHomePageActivated) {
                titleKey += "." + onLanguageSwitch;
            }
            buff.append(getMessage(titleKey, title));
            buff.append("'>");
        } else {
            buff.append("<span>");
            if (urlVar != null)
                pageContext.removeAttribute(urlVar, PageContext.PAGE_SCOPE);
        }

        String attributeValue = null;
        if (linkKind == null || linkKind.length() == 0 || LANGUAGE_CODE.equals(linkKind)
                || linkKind.startsWith(FLAG)) {
            attributeValue = languageCode;
            buff.append(languageCode);

        } else if (NAME_CURRENT_LOCALE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(getRenderContext().getMainResource().getLocale());
            attributeValue = value;
            buff.append(value);

        } else if (NAME_IN_LOCALE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale);
            attributeValue = value;
            buff.append(value);

        } else if (LETTER.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale).substring(0, 1).toUpperCase();
            attributeValue = value;
            buff.append(value);

        } else if (DOUBLE_LETTER.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            final String value = locale.getDisplayName(locale).substring(0, 2).toUpperCase();
            attributeValue = value;
            buff.append(value);

        } else if (ISOLOCALECOUNTRY_CODE.equals(linkKind)) {
            final Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
            StringBuilder value = new StringBuilder(locale.getLanguage().toUpperCase());
            if (locale.getCountry() != null && locale.getCountry().length() != 0) {
                value.append("(").append(locale.getCountry()).append(")");
            }
            attributeValue = value.toString();
            buff.append(value);

        } else {
            throw new JspTagException("Unknown linkKind value '" + linkKind + "'");
        }

        if (getVar() != null) {
            pageContext.setAttribute(getVar(), attributeValue);
        }

        if (!isCurrentBrowsingLanguage) {
            buff.append("</a>");
            if (isRedirectToHomePageActivated)
                buff.append("</div>");
        } else {
            buff.append("</span>");
        }

        if (display) {
            pageContext.getOut().print(buff.toString());
        }

    } catch (final Exception e) {
        logger.error("Error while getting language switch URL", e);
    }
    return SKIP_BODY;
}

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

/**
 * Put the actual internal processing in here.
 * /*from w w w  . ja v  a 2s.com*/
 * @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:jp.terasoluna.fw.web.struts.taglib.ChangeStyleClassTag.java

/**
 * ^O]Jn?\bh?B/* ww  w  .j a v a 2  s. co  m*/
 * G?[L?oX^CV?[gNX?X?B
 *
 * @return ???w
 * @throws JspException JSPO
 */
@Override
public int doStartTag() throws JspException {
    HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
    if (req == null) {
        return SKIP_BODY;
    }
    String result = chooseClass(req, this.name, this.defaultValue, this.errorValue);
    try {
        JspWriter out = pageContext.getOut();
        out.print(result);
    } catch (IOException e) {
        log.error("Output failed.");
        throw new JspTagException(e.toString());
    }
    return EVAL_BODY_INCLUDE;
}

From source file:com.rainbow.fw.web.taglib.CodeListTag.java

/**
 * ??/*from   w w  w  .j a  va2s. c om*/
 * 
 * <p>
 * ??ApplicationContext??? &quot;page&quot; ??? id ?
 * CodeListLoader ???????  pageContext ??
 * 
 * ?????????ArrayList pageContext ?? ?????
 * &quot;page&quot; ??
 * </p>
 * 
 * @return ?? EVAL_BODY_INCLUDE
 * @throws JspException
 *             JSP 
 */
@Override
public int doStartTag() throws JspException {
    if (log.isDebugEnabled()) {
        log.debug("doStartTag() called.");
    }

    if ("".equals(id)) {
        // id?????
        log.error("id is required.");
        throw new JspTagException("id is required.");
    }

    // ?ApplicationContext??
    ServletContext sc = pageContext.getServletContext();

    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

    CodeListLoader loader = null;

    if (null == codeDefineList) {
        try {
            loader = ContextProvider.getBean(CodeListLoader.class);

        } catch (ClassCastException e) {
            // ???Bean?CodeListLoader??????
            String errorMessage = "bean id:" + id + " is not instance of CodeListLoader.";
            log.error(errorMessage);
            throw new JspTagException(errorMessage, e);
        }
        codeDefineList = loader.getCodeBeans(id);
    }
    // List<CodeDefine> codeDefineList = loader.getCodeBeans(id);

    Map<String, String> cardType = new LinkedHashMap<String, String>();

    for (CodeDefine codeDefine : codeDefineList) {
        cardType.put(codeDefine.getCodeValue(), codeDefine.getCodeKey());
    }

    cardType = Collections.unmodifiableMap(cardType);

    if (cardType == null) {
        // codeBeanList?null???ArrayList?
        if (log.isWarnEnabled()) {
            log.warn("Codebean is null. CodeListLoader(bean id:" + id + ")");
        }
        pageContext.setAttribute(id, new ArrayList(), PageContext.PAGE_SCOPE);
    } else {
        // ?
        pageContext.setAttribute(id, cardType, PageContext.PAGE_SCOPE);
    }

    return EVAL_BODY_INCLUDE;
}