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.rhq.enterprise.gui.legacy.taglib.display.QuicknavDecorator.java

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

    ancestorTag.setDecorator(this);
    return SKIP_BODY;
}

From source file:com.healthcit.cacure.web.tag.AnswerPresenterTag.java

@Override
public int doStartTag() throws JspException {
    try {/* w w w.  ja va  2s  .  c o  m*/

        FormElement fe = formElement;
        if (formElement instanceof LinkElement) {
            ApplicationContext ctx = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(pageContext.getServletContext());
            fe = ctx.getBean(QuestionAnswerManager.class).getFantom(fe.getId());
        }

        String controlHtml = "";

        // TABLE Questions
        if (fe.isTable()) {
            controlHtml = processComplexControls(fe);
        }

        //Non-TABLE Questions
        else {
            Answer.AnswerType[] array = new Answer.AnswerType[] { AnswerType.TEXT, AnswerType.NUMBER,
                    AnswerType.INTEGER, AnswerType.POSITIVE_INTEGER, AnswerType.DATE, AnswerType.YEAR,
                    AnswerType.MONTHYEAR, AnswerType.CHECKBOX, AnswerType.RADIO, AnswerType.DROPDOWN,
                    AnswerType.TEXTAREA };

            if (ArrayUtils.contains(array, fe.getAnswerType())) {
                /*
                 * At this point we will be in this method only if
                 * FormElement is either QuestionElement,
                 * ExternalQuestionElement or LinkElement that is linked to
                 * one of the above
                 */
                List<? extends BaseQuestion> questions = fe.getQuestions();
                if (questions != null && questions.size() > 0) {
                    BaseQuestion question = questions.get(0);
                    controlHtml = processSimpleControls(fe, question.getAnswer());
                }
            } else {
                throw new JspException("Ansert type '" + fe.getAnswerType() + "' is not handled. Please see '"
                        + this.getClass().getSimpleName() + "' to verify");
            }
        }

        pageContext.getOut().print(controlHtml);
    } catch (IOException ioe) {
        throw new JspTagException("Error: IOException while writing to the user");
    }
    return SKIP_BODY;
}

From source file:com.ei.itop.common.tag.MessageTag.java

/**
 * Resolve the specified message into a concrete message String.
 * The returned message String should be unescaped.
 *///from w  ww  . ja  v a 2s .  c om
protected String resolveMessage() throws JspException, NoSuchMessageException {
    MessageSource messageSource = getMessageSource();
    if (messageSource == null) {
        throw new JspTagException("No corresponding MessageSource found");
    }

    // Evaluate the specified MessageSourceResolvable, if any.
    MessageSourceResolvable resolvedMessage = null;
    if (this.message instanceof MessageSourceResolvable) {
        resolvedMessage = (MessageSourceResolvable) this.message;
    } else if (this.message != null) {
        String expr = this.message.toString();
        resolvedMessage = (MessageSourceResolvable) ExpressionEvaluationUtils.evaluate("message", expr,
                MessageSourceResolvable.class, pageContext);
    }

    if (resolvedMessage != null) {
        // We have a given MessageSourceResolvable.
        return messageSource.getMessage(resolvedMessage, getRequestContext().getLocale());
    }

    String resolvedCode = ExpressionEvaluationUtils.evaluateString("code", this.code, pageContext);
    String resolvedText = ExpressionEvaluationUtils.evaluateString("text", this.text, pageContext);

    if (resolvedCode != null || resolvedText != null) {
        // We have a code or default text that we need to resolve.
        Object[] argumentsArray = resolveArguments(this.arguments);
        if (resolvedText != null) {
            return messageSource.getMessage(resolvedCode, argumentsArray, resolvedText, getLocale());
        } else {
            return messageSource.getMessage(resolvedCode, argumentsArray, getLocale());
        }
    }
    // All we have is a specified literal text.
    return resolvedText;
}

From source file:org.kmnet.com.fw.web.message.MessagesPanelTag.java

/**
 * Creates messagesPanel tag/*ww w .ja  v a 2  s  . c o  m*/
 * 
 * @throws JspException
 *             In case when {@link JspException} is generated later in the
 *             chain when tag configured by MessagesPanel could not be
 *             created
 * @see org.springframework.web.servlet.tags.RequestContextAwareTag#doStartTagInternal()
 */
@Override
protected int doStartTagInternal() throws JspException {

    if (!StringUtils.hasText(this.panelElement) && !StringUtils.hasText(this.outerElement)
            && !StringUtils.hasText(this.innerElement)) {
        throw new JspTagException("At least one out of panelElement, outerElement, innerElement should be set");
    }

    TagWriter tagWriter = createTagWriter();

    Object messages = this.pageContext.findAttribute(messagesAttributeName);

    if (messages != null) {

        if (StringUtils.hasText(panelElement)) {
            tagWriter.startTag(panelElement); // <div>

            StringBuilder className = new StringBuilder(panelClassName);
            String type = getType(messages);

            if (panelTypeClassPrefix != null && StringUtils.hasText(type)) {

                if (StringUtils.hasLength(className)) {
                    className.append(" ");
                }
                className.append(panelTypeClassPrefix);
            }
            className.append(type);

            if (StringUtils.hasText(className)) {
                tagWriter.writeAttribute("class", className.toString());
            }
        }

        {
            if (StringUtils.hasText(outerElement)) {
                tagWriter.startTag(outerElement); // <ul>
            }

            writeMessages(tagWriter, messages);

            if (StringUtils.hasText(outerElement)) {
                tagWriter.endTag(); // </ul>
            }
        }

        if (StringUtils.hasText(panelElement)) {
            tagWriter.endTag(); // </div>
        }
    }

    return EVAL_BODY_INCLUDE;
}

From source file:gov.nih.nci.rembrandt.web.taglib.HelpTag.java

public int doStartTag() throws JspException {
    try {/* w  w w  .j  ava2  s.co m*/

        if (help != null) {
            if (label != null) {
                pc.getOut().write("<a href=\"javascript:void(0);\" onmouseover=\"return overlib('" + help
                        + "', CAPTION, 'Help');\" onmouseout=\"return nd();\">" + label + "</a>");
            } else {
                pc.getOut().write("<a href=\"javascript:void(0);\" onmouseover=\"return overlib('" + help
                        + "', CAPTION, 'Help');\" onmouseout=\"return nd();\">[?]</a>");
            }
        } else {
            pc.getOut().write("");
        }

    } catch (IOException e) {
        throw new JspTagException("An IOException occurred.");
    }
    return SKIP_BODY;
}

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

/**
 * ^O]Jn?\bh?B//from  w  w  w .j a  v  a 2s .com
 *
 * <p>
 * T?[ubgReLXg?AApplicationContext?A
 * &quot;codeList&quot; ?w id
 *  CodeListLoader ?AR?[hXg
 * l?A?o?B
 * &quot;key&quot; ?w?AL?[l?A
 * w?A&quot;name&quot; ?wbean
 * L?[p?B
 *
 * R?[hXg???A
 * L?[????A?o?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(codeList) || codeList == null) {
        // codeListw??
        log.error("codeList is required.");
        throw new JspTagException("codeList is required.");
    }

    if (key == null && name == null) {
        // keynamew??
        log.error("key and name is required.");
        throw new JspTagException("key and name is required.");
    }

    String codeKey = null;

    if ((key == null) && (name != null)) {
        if (TagUtil.lookup(pageContext, name, scope) == null) {
            log.error("bean id:" + name + " is not defined.");
            throw new JspTagException("bean id:" + name + " is not defined.");
        }
        Object bean = null;
        try {
            bean = TagUtil.lookup(pageContext, name, property, scope);
        } catch (JspException e) {
            // 
        }
        if (bean == null) {
            log.error("Cannot get property[" + name + "." + property + "].");
            throw new JspTagException("Cannot get property[" + name + "." + property + "].");
        }
        codeKey = bean.toString();
    } else {
        codeKey = key;
    }

    // T?[ubgReLXg?AApplicationContext?B
    ServletContext sc = pageContext.getServletContext();
    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

    CodeListLoader loader = null;

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

    JspWriter out = pageContext.getOut();

    if (loader == null) {
        log.error("CodeListLoader:" + codeList + " is not defined.");
        throw new JspTagException("CodeListLoader:" + codeList + " is not defined.");
    }

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

    CodeBean[] codeBeanArray = loader.getCodeBeans(locale);
    if (codeBeanArray == null) {
        // codeBeanListnull??
        if (log.isWarnEnabled()) {
            log.warn("Codebean is null. CodeListLoader(bean id:" + codeList + ")");
        }
        // 
    } else {
        try {
            // ????R?[hXgl?o?B
            for (int i = 0; i < codeBeanArray.length; i++) {
                if (codeKey.equals(codeBeanArray[i].getId())) {
                    out.print(codeBeanArray[i].getName());
                    break;
                }
            }
            // 
        } catch (IOException ioe) {
            log.error("", ioe);
            throw new JspTagException(ioe);
        }

    }

    return EVAL_BODY_INCLUDE;
}

From source file:gov.nih.nci.cananolab.util.ContextSensitiveHelpTag.java

public int doStartTag() throws JspException {

    try {/* w w  w . ja  v  a  2 s. co m*/
        String theHref = "";
        String wikiSiteBegin = "";
        String theJavascript = "";
        String theText = "";
        String theStyleClass = "";
        try {
            // Get the text
            //            ResourceBundle theBundle = ResourceBundle.getBundle(myBundle);

            // Process optional attributes
            if (myTopic != null) {
                String theTopic = "";
                //               String theJavascript = theBundle.getString(myJavascriptKey);

                Properties wikihelpProperties = new Properties();
                try {

                    String wikihelpPropertiesFileName = null;

                    wikihelpPropertiesFileName = System.getProperty("gov.nih.nci.cananolab.wikihelpProperties");

                    try {

                        FileInputStream in = new FileInputStream(wikihelpPropertiesFileName);
                        wikihelpProperties.load(in);

                    } catch (FileNotFoundException e) {
                        log.error("Caught exception finding file for properties: ", e);
                        e.printStackTrace();
                    } catch (IOException e) {
                        log.error("Caught exception finding file for properties: ", e);
                        e.printStackTrace();
                    }
                    theJavascript = wikihelpProperties.getProperty(myJavascriptKey);
                    theText = wikihelpProperties.getProperty(myKey);
                    theStyleClass = wikihelpProperties.getProperty(myStyleClass);
                    wikiSiteBegin = wikihelpProperties.getProperty(wikiSiteBeginKey);
                    theTopic = wikihelpProperties.getProperty(myTopic);
                }

                // Default to 100 on an exception
                catch (Exception e) {
                    System.err.println("Error loading system.properties file");
                    e.printStackTrace();
                }
                theHref = "href=\"" + theJavascript + wikiSiteBegin + theTopic + "')\"";
            }

            if (myImage != null) {
                myPageContext.getOut()
                        .write("<a " + theHref + " onMouseOver=\"stm(" + theText + "," + theStyleClass
                                + ")\" onMouseOut=\"htm();\"><img alt=\"Help\" src=\"" + myImage
                                + "\" border=\"0\"/>" + "</a>");

            } else {
                myPageContext.getOut()
                        .write("<a class=\"" + getStyleClass() + "\"" + theHref + ">" + myLabelName + "</a>");
            }

        } catch (Exception e) {
            e.printStackTrace();

            System.out.println("Can't get bundle. Ignore tooltip");
            // Can't get bundle. Ignore tooltip
            myPageContext.getOut().write("<a " + theHref + " \">" + myLabelName + "</a>");
        }

    } catch (IOException e) {
        throw new JspTagException("An IOException occurred.");
    } catch (Exception e) {
        throw new JspTagException("An unknown exception occurred.");
    }

    return SKIP_BODY;

}

From source file:org.openmrs.web.taglib.OpenmrsMessageTag.java

/**
 * @see MessageTag#doStartTagInternal()//from  w w w  .jav  a 2 s .c  o  m
 * @should evaluate specified message resolvable
 * @should resolve message by code
 * @should resolve message in locale that different from default
 * @should return code if no message resolved
 * @should use body content as fallback if no message resolved
 * @should use text attribute as fallback if no message resolved
 * @should use body content in prior to text attribute as fallback if no message resolved
 * @should ignore fallbacks if tag locale differs from context locale
 */
@Override
protected int doEndTagInternal() throws JspException, IOException {
    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 = this.var;
        if (resolvedVar != null) {
            pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(this.scope));
        } else {
            writeMessage(msg);
        }

        return EVAL_PAGE;
    } catch (NoSuchMessageException ex) {
        throw new JspTagException(getNoSuchMessageExceptionDescription(ex));
    }
}

From source file:org.openmrs.web.taglib.OpenmrsMessageTag.java

/**
 * Resolve the specified message or code or text or tag body into a concrete message string. The returned message string should
 * be unescaped.//from ww w.j a  va  2s  . c om
 */
protected String resolveMessage() throws JspException {
    MessageSource messageSource = getMessageSource();
    if (messageSource == null) {
        throw new JspTagException("No corresponding MessageSource to resolve message with found");
    }

    // first, evaluate the specified MessageSourceResolvable, if any
    MessageSourceResolvable resolvedMessage = null;
    if (this.message instanceof MessageSourceResolvable) {
        resolvedMessage = (MessageSourceResolvable) this.message;
    } else if (this.message != null) {
        String expr = this.message.toString();
        throw new JspException("Attribute value \"" + expr + "\" is neither a JSP EL expression nor "
                + "assignable to result class [" + MessageSourceResolvable.class.getName() + "]");
    }

    if (resolvedMessage != null) {
        // we have a given MessageSourceResolvable.
        return messageSource.getMessage(resolvedMessage, getRequestContext().getLocale());
    }

    String resolvedCode = this.code;
    String bodyText = null;
    String resolvedText = null;
    // if locale specified with tag attribute is the same as context locale
    if (OpenmrsUtil.nullSafeEquals(this.locale, Context.getLocale().getLanguage())) {
        // we need to evaluate fallback values in this case
        resolvedText = this.text;
        if (getBodyContent() != null) {
            bodyText = getBodyContent().getString();
        }
    }
    // by default message code is used as fallback
    String message = resolvedCode;
    if (resolvedCode != null || resolvedText != null || bodyText != null) {
        // we have either a code or default text or body that we need to resolve.
        Object[] argumentsArray = resolveArguments(this.arguments);
        if (bodyText != null) {
            // we have a fallback body text to consider.
            message = messageSource.getMessage(resolvedCode, argumentsArray, bodyText,
                    getRequestContext().getLocale());
        } else if (resolvedText != null) {
            // we have a fallback value of text attribute to consider.
            message = messageSource.getMessage(resolvedCode, argumentsArray, resolvedText,
                    getRequestContext().getLocale());
        } else {
            // we have no fallback text to consider.
            try {
                message = messageSource.getMessage(resolvedCode, argumentsArray,
                        getRequestContext().getLocale());
            } catch (NoSuchMessageException e) {
                // do nothing, use resolved code as fallback
            }
        }
    }

    // all we have is a specified literal text.
    return message;
}

From source file:org.openmrs.web.taglib.ForEachRecordTag.java

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