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.personalhr.web.taglib.ForEachAlertTag.java

@Override
protected Object next() throws JspTagException {
    if (this.alerts == null) {
        throw new JspTagException("The alert iterator is null");
    }/*from  w  w w . j a v  a  2  s.co m*/
    return this.alerts.next();
}

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

public int doAfterBody() throws JspException {
    try {/*from  w w  w . j av  a2s  . c  o m*/
        JspWriter out = bodyContent.getEnclosingWriter();

        Content content = content(pageContext);

        if (content != null) {

            String userFullName = userFullName(content);

            Date lastUpdated = content.getLastMajorChange();

            String textLabel = textLabel(pageContext, key, bundle, locale, bodyContent.toString());

            String text = String.format(textLabel, userFullName, lastUpdated);

            String html = html(text);

            out.print(html);
        }

    } catch (Exception e) {
        log.error("Failed while generating byline", e);
        throw new JspTagException(e);
    } finally {
        bodyContent.clearBody();
    }

    cssStyle = null;
    cssClass = null;
    key = null;
    bundle = LocaleLabels.DEFAULT_BUNDLE;
    locale = null;

    return SKIP_BODY;
}

From source file:org.infoglue.deliver.taglib.content.DigitalAssetParameterTag.java

/**
 * Adds the digital asset to the ancestor tag.
 * //from  w  ww. java 2s. c  o m
 * @throws JspException if the ancestor tag isn't a content version tag.
 */
protected void addDigitalAsset() throws JspException {
    final ContentVersionParameterInterface parent = (ContentVersionParameterInterface) findAncestorWithClass(
            this, ContentVersionParameterInterface.class);
    if (parent == null) {
        throw new JspTagException(
                "DigitalAssetParameterTag must have a ContentVersionParameterInterface ancestor.");
    }

    if (bytes != null) {
    } else if (file != null) {
        try {
            this.bytes = FileHelper.getFileBytes(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (fileItem != null) {
        try {
            this.bytes = fileItem.get();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        throw new JspException("Must state either bytes, a file or a fileItem");
    }

    RemoteAttachment attachment = new RemoteAttachment(this.assetKey, this.fileName, this.filePath,
            this.contentType, this.bytes);

    ((ContentVersionParameterInterface) parent).addDigitalAsset(attachment);
}

From source file:ch.entwine.weblounge.taglib.content.ElementTag.java

/**
 * Sets the tag variable definitions. This tag supports the following
 * variable://from   w  w  w . j  ava 2s.com
 * <ul>
 * <li><code>element</code> - the element value</li>
 * </ul>
 * 
 * @param value
 *          the variable definitions
 * @throws JspException
 *           if the definition cannot be parsed
 */
public final void setDefine(String value) throws JspException {
    if (definitions == null || !definitions.equals(value)) {
        try {
            variables = TagVariableDefinitionParser.parse(value);
        } catch (ParseException ex) {
            logger.error("Error parsing tag variable definitions: " + value);
            throw new JspTagException(ex.getMessage());
        }
    }
    definitions = value;
}

From source file:org.gvnix.datatables.tags.SpringContextHelper.java

/**
 * Returns the message translation for a code, in the {@link Locale} of the
 * current request.//from  www  .j  av a2s .  c  om
 * 
 * @param pageContext of the current request.
 * @param code to get the message
 * @return the translated message
 * @throws JspException if there is an error getting the message
 */
public String resolveMessage(PageContext pageContext, String code) throws JspException {
    RequestContext requestContext = getRequestContext(pageContext);
    if (requestContext == null) {
        throw new JspTagException("No corresponding RequestContext found");
    }
    MessageSource messageSource = requestContext.getMessageSource();
    if (messageSource == null) {
        throw new JspTagException("No corresponding MessageSource found");
    }

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

    if (resolvedCode != null) {
        // We have no fallback text to consider.
        try {
            return messageSource.getMessage(resolvedCode, null, requestContext.getLocale());
        } catch (NoSuchMessageException e) {
            LOG.warn("Unable to get message with code " + resolvedCode, e);
        }
    }

    return resolvedCode;
}

From source file:info.magnolia.templating.jsp.taglib.ConvertNewLineTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*w  ww.j  a va  2s . c om*/
@Override
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false);
        JspWriter out = pageContext.getOut();

        try {
            if (this.para) {
                // wrap text in p
                while (bodyTk.hasMoreTokens()) {
                    out.write("<p>");
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    out.write("</p>");
                }
            } else {
                // add newlines
                while (bodyTk.hasMoreTokens()) {
                    out.write(StringUtils.replaceChars(bodyTk.nextToken(), (char) 63, '\''));
                    if (bodyTk.hasMoreTokens()) {
                        out.write("<br/>");
                    }
                }
            }
        } catch (IOException e) {
            throw new JspTagException(e.getMessage());
        }
    }
    return EVAL_PAGE;
}

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

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

    if (ancestorTag == null) {
        throw new JspTagException("A LabelDecorator must be used within a ColumnTag.");
    }/*from w w w. j a va2  s . co  m*/

    ancestorTag.setDecorator(this);

    return SKIP_BODY;
}

From source file:org.opencms.jsp.CmsJspTagContentInfo.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 *///from   ww  w  .j  a va  2s.  c  o  m
@Override
public int doStartTag() throws JspException {

    // get a reference to the parent "content container" class
    Tag ancestor = findAncestorWithClass(this, I_CmsResourceContainer.class);
    if (ancestor == null) {
        // build a container
        CmsMessageContainer container = Messages.get().container(Messages.ERR_PARENTLESS_TAG_1, "contentinfo");
        String msg = Messages.getLocalizedMessage(container, pageContext);
        throw new JspTagException(msg);
    }

    I_CmsResourceContainer contentContainer = (I_CmsResourceContainer) ancestor;

    String tagContent = "";

    if (isScopeVarSet()) {
        if (contentContainer instanceof CmsJspTagContentLoad) {
            storeContentInfoBean((CmsJspTagContentLoad) contentContainer);
        } else if (contentContainer instanceof CmsJspTagResourceLoad) {
            storeContentInfoBean((CmsJspTagResourceLoad) contentContainer);
        }
    }

    if (CmsStringUtil.isNotEmpty(m_value)) {
        // value is provided - resolve macros
        tagContent = resolveMacros(m_value);
    }

    try {
        pageContext.getOut().print(tagContent);
    } catch (IOException e) {
        CmsMessageContainer message = Messages.get().container(Messages.ERR_PROCESS_TAG_1, "contentinfo");
        LOG.error(message.key(), e);
        throw new JspException(message.key(pageContext.getRequest().getLocale()));
    }

    return SKIP_BODY;
}

From source file:org.openmrs.module.lancearmstrong.web.taglib.ForEachAlertTag.java

@Override
protected Object next() throws JspTagException {
    if (alerts == null)
        throw new JspTagException("The alert iterator is null");
    return alerts.next();
}

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

public int doStartTag() throws JspTagException {
    ColumnTag ancestorTag = (ColumnTag) TagSupport.findAncestorWithClass(this, ColumnTag.class);
    if (ancestorTag == null) {
        throw new JspTagException("A CheckboxDecorator must be used within a ColumnTag.");
    }//from   w w  w.j av a  2s . c  om

    ancestorTag.setDecorator(this);
    return SKIP_BODY;
}