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:eu.citadel.liferay.tag.SearchContainerColumnListTag.java

@Override
public int doStartTag() throws JspException {
    @SuppressWarnings("unchecked")
    SearchContainerRowTag<R> searchContainerRowTag = (SearchContainerRowTag<R>) findAncestorWithClass(this,
            SearchContainerRowTag.class);

    if (searchContainerRowTag == null) {
        throw new JspTagException("Requires liferay-ui:search-container-row");
    }/*from w  w w.j  av  a 2 s. co  m*/

    if (!searchContainerRowTag.isHeaderNamesAssigned()) {
        List<String> headerNames = searchContainerRowTag.getHeaderNames();
        if (getHeader() != null) {
            for (Object obj : getHeader()) {
                String key = "";
                if (obj != null)
                    key = obj.toString();
                headerNames.add(key);
            }
        } else {
            for (int i = 0; i < _list.size(); i++) {
                String key = String.valueOf(i);
                headerNames.add(key);
            }
        }
    }

    if (Validator.isNotNull(_property)) {
        return SKIP_BODY;
    } else if (Validator.isNotNull(_buffer)) {
        _sb = new StringBuilder();

        pageContext.setAttribute(_buffer, _sb);

        return EVAL_BODY_INCLUDE;
    } else {
        return SKIP_BODY;
    }
}

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

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

    if (ancestorTag == null) {
        throw new JspTagException("A BooleanDecorator must be used within a ColumnTag.");
    }//from   w ww  .  java  2  s  .  c  o m

    // You have to make a clone, otherwise, if there are more than one
    // boolean decorator in this table, then we'll end up with only one
    // boolean decorator object
    BooleanDecorator clone;
    try {
        clone = (BooleanDecorator) this.clone();
    } catch (CloneNotSupportedException e) {
        // Then just use this
        clone = this;
    }

    ancestorTag.setDecorator(clone);
    return SKIP_BODY;
}

From source file:no.kantega.publishing.api.taglibs.security.GetUserTag.java

public int doStartTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    try {/*from  w ww  . j  a  v  a 2s  .c om*/
        if (webApplicationContext == null) {
            webApplicationContext = WebApplicationContextUtils
                    .getWebApplicationContext(pageContext.getServletContext());
        }
        SecuritySession session = SecuritySession.getInstance(request);
        User user = null;
        if (!isBlank(userid)) {
            try {
                SecurityRealm realm = null;
                Map<String, SecurityRealm> beansOfType = webApplicationContext
                        .getBeansOfType(SecurityRealm.class);
                for (SecurityRealm r : beansOfType.values()) {
                    user = r.lookupUser(userid);
                    if (user != null) {
                        realm = r;
                        break;

                    }
                }

                if (user != null) {
                    if (getRoles || getRoleTopics) {
                        List<Role> roles = realm.lookupRolesForUser(user.getId());
                        for (Role role : roles) {
                            user.addRole(role);
                        }
                        if (getRoleTopics && Aksess.isTopicMapsEnabled()) {
                            // Hent topics for bruker
                            TopicMapService topicService = new TopicMapService(request);

                            if (user.getRoles() != null) {
                                for (Role role : roles) {
                                    List<Topic> tmp = topicService.getTopicsBySID(role);
                                    for (Topic aTmp : tmp) {
                                        user.addTopic(aTmp);
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (SystemException e) {
                user = null;
            }
        } else {
            user = session.getUser();
        }

        if (user != null) {
            request.setAttribute(name, user);
        }
    } catch (Exception e) {
        log.error("Error setting user", e);
        throw new JspTagException(e);
    }

    return SKIP_BODY;
}

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

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

From source file:edu.wustl.common.util.tag.AutoCompleteTag.java

/**
 * A call back function, which gets executed by JSP runtime when opening tag
 * for this custom tag is encountered.//from  ww w  . j a  va2  s . com
 * @exception JspException jsp exception.
 * @return integer value to skip body.
 */
public int doStartTag() throws JspException {

    try {
        JspWriter out = pageContext.getOut();
        String autocompleteHTMLStr = null;
        if (staticField.equalsIgnoreCase(TRUE)) {
            autocompleteHTMLStr = getAutocompleteHTML();
        } else {
            autocompleteHTMLStr = getAutocompleteHTMLForDynamicProperty();
        }

        clearTagVariables();

        out.print(autocompleteHTMLStr);
    } catch (IOException ioe) {
        LOGGER.debug(ioe.getMessage(), ioe);
        throw new JspTagException("Error:IOException while writing to the user");
    }

    return SKIP_BODY;
}

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

/**
 * ^O]Jn?\bh?B/* w ww.  j av a  2s  .co m*/
 *
 * <p>
 *   T?[ubgReLXgR?[hXg??[_?[
 * ??AR?[hXg???AR?[hXgvf?
 * p?B
 * R?[hXg???A0???B
 * </p>
 *
 * @return ???w?B? <code>EVAL_BODY_INCLUDE</code>
 * @throws JspException <code>JSP</code>O
 */
@Override
public int doStartTag() throws JspException {
    if (log.isDebugEnabled()) {
        log.debug("doStartTag() called.");
    }

    JspWriter out = pageContext.getOut();

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

        // pageContext?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[] codeBeanList = loader.getCodeBeans(locale);
        if (codeBeanList == null) {
            // codeBeanListnull??0?o?B
            if (log.isWarnEnabled()) {
                log.warn("Codebean is null. CodeListLoader(bean id:" + id + ")");
            }
            out.print(0);
        } else {
            // ????R?[hXg?o?B
            out.print(codeBeanList.length);
        }

        return EVAL_BODY_INCLUDE;
    } catch (IOException ioe) {
        log.error("IOException caused.");
        throw new JspTagException(ioe.toString());
    }
}

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

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

    ancestorTag.setDecorator(this);
    return SKIP_BODY;
}

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);
                }/*  w  w w  .  ja va  2s .com*/
                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.jahia.taglibs.query.QueryDefinitionTag.java

/**
 * Returns current QOM builder instance.
 *
 * @return an instance of current {@link QOMBuilder}
 * @throws JspTagException//w w  w.j av a  2 s  .co  m
 */
public QOMBuilder getQOMBuilder() throws JspTagException {
    if (qomBuilder == null) {
        try {
            qomBuilder = new QOMBuilder(getJCRSession().getWorkspace().getQueryManager().getQOMFactory(),
                    getJCRSession().getValueFactory());

            QueryObjectModel qom = getInitialQueryObjectModel();
            if (qom != null) {
                qomBuilder.setSource(qom.getSource());
                for (Column column : qom.getColumns()) {
                    qomBuilder.getColumns().add(column);
                }
                qomBuilder.andConstraint(qom.getConstraint());
                for (Ordering ordering : qom.getOrderings()) {
                    qomBuilder.getOrderings().add(ordering);
                }
            }
        } catch (RepositoryException e) {
            throw new JspTagException(e);
        }
    }
    return qomBuilder;
}

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

public String decorate(Object obj) throws Exception {
    try {/*from ww  w. j  ava 2  s  . com*/
        // if the metric value is empty, converting to a Double
        // will give a value of 0.0. this makes it impossible for
        // us to distinguish further down the line whether the
        // metric was actually collected with a value of 0.0 or
        // whether it was not collected at all. therefore, we'll
        // let m be null if the metric was not collected, and
        // we'll check for null later when handling the not-avail
        // case.
        // PR: 7588
        Double m = null;

        if (obj != null) {
            String mval = obj.toString();

            if (mval != null && !mval.equals("")) {
                m = new Double(mval);
            }
        }

        String u = getUnit();
        String dk = getDefaultKey();
        Locale l = TagUtils.getInstance().getUserLocale(context, locale);
        StringBuffer buf = new StringBuffer();

        if ((m == null || Double.isNaN(m.doubleValue()) || Double.isInfinite(m.doubleValue())) && dk != null) {
            buf.append(TagUtils.getInstance().message(context, bundle, l.toString(), dk));
        } else if (u.equals("ms")) {
            // we don't care about scaling and such. we just want
            // to show every metric in seconds with millisecond
            // resolution
            String formatted = UnitsFormat.format(
                    new UnitNumber(m.doubleValue(), UnitsConstants.UNIT_DURATION, UnitsConstants.SCALE_MILLI))
                    .toString();

            buf.append(formatted);
        } else {
            FormattedNumber f = UnitsConvert.convert(m.doubleValue(), u, l);

            buf.append(f.getValue());

            if (f.getTag() != null && f.getTag().length() > 0) {
                buf.append(" ").append(f.getTag());
            }
        }

        return buf.toString();
    } catch (NumberFormatException npe) {
        log.error(npe);

        throw new JspTagException(npe);
    } catch (Exception e) {
        log.error(e);

        throw new JspException(e);
    }
}