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.parancoe.web.tag.FlashTag.java

@Override
protected final int doStartTagInternal() throws JspException, IOException {
    try {//from  ww w .j ava 2 s  .  c  o m
        Map<String, String> flash = new HashMap<String, String>();
        Map<String, String> flashRequest = (Map<String, String>) pageContext.getRequest().getAttribute("flash");
        if (flashRequest != null) {
            flash.putAll(flashRequest);
        }
        Map<String, String> flashSession = (Map<String, String>) pageContext.getSession().getAttribute("flash");
        if (flashSession != null) {
            flash.putAll(flashSession);
            // And clean the session
            flashSession.remove(type);
        }
        if (flash.get(type) != null) {
            // Resolve the message.
            MessageSource messageSource = getMessageSource();
            if (messageSource == null) {
                throw new JspTagException("No corresponding MessageSource found");
            }
            String msg;
            try {
                Object[] argumentsArray = {};
                msg = messageSource.getMessage(flash.get(type), argumentsArray,
                        getRequestContext().getLocale());
            } catch (Exception ex) {
                // If the message is unresolved, use the key as message
                msg = flash.get(type);
            }

            // Write the message
            writeMessage(msg);

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

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

public int doStartTag() throws JspException {
    try {/*from  w  w  w . j  a v  a2 s.c  om*/

        User user;
        if (!isBlank(userid)) {
            SecurityRealm realm = SecurityRealmFactory.getInstance();
            try {
                user = realm.lookupUser(userid);
            } catch (SystemException e) {
                user = null;
            }
        } else {
            SecuritySession session = SecuritySession
                    .getInstance((HttpServletRequest) pageContext.getRequest());
            user = session.getUser();
        }

        JspWriter out = pageContext.getOut();
        if (user != null) {
            out.write(user.getName());
        } else if (userid != null) {
            out.write(userid);
        }
    } catch (Exception e) {
        log.error("", e);
        throw new JspTagException(e);
    }

    return SKIP_BODY;
}

From source file:au.org.ala.commonui.headertails.BannerTag.java

/**
 * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
 *//*w  ww.  java 2  s  .c o m*/
public int doStartTag() throws JspException {
    try {
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

        //CommonTagBean ctb = new CommonTagBean(pageContext, this.returnUrlPath, this.returnLogoutUrlPath);
        //String html = HeaderAndTailUtil.getBanner(ctb);
        logger.info("populateSearchBox = " + populateSearchBox);
        HeaderAndTailUtil htu = new HeaderAndTailUtil(pageContext, this.returnUrlPath, this.returnLogoutUrlPath,
                this.logoutControllerUrlPath, this.populateSearchBox);
        String html = htu.getBanner();

        pageContext.getOut().print(html);
    } catch (Exception e) {
        logger.error("BannerMenuTag: " + e.getMessage(), e);
        throw new JspTagException("BannerMenuTag: " + e.getMessage());
    }

    return super.doStartTag();
}

From source file:nl.b3p.taglibs.js.QuoteTag.java

@Override
public int doEndTag() throws JspException {
    try {//  ww w  . j  av a 2  s  .c  o  m
        if (output == null) {
            // JSONObject.quote(null) will return ""
            pageContext.getOut().print("null");
        } else {
            pageContext.getOut().print(JSONObject.quote(output));
        }
    } catch (IOException e) {
        throw new JspTagException(e);
    }
    return EVAL_PAGE;
}

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

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

    ancestorTag.setDecorator(this);
    return EVAL_BODY_INCLUDE;
}

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

public int doStartTag() throws JspTagException {
    Object parent = getParent();/*w ww  .  ja va 2s .c o m*/

    if (parent == null || !(parent instanceof ColumnTag)) {
        throw new JspTagException("A BaseDecorator must be used within a ColumnTag.");
    }

    ((ColumnTag) parent).setDecorator(this);

    return SKIP_BODY;
}

From source file:net.jforum.core.tags.ImportFileTag.java

/**
 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
 *///ww w.  j  av a2s  .  co  m
@Override
public void doTag() throws JspException, IOException {
    // check the URL
    if (StringUtils.isEmpty(url))
        throw new NullAttributeException("import", "url");

    String jsp = this.getFile(url);

    ServletRequest request = this.request();
    ServletResponse respose = this.response();
    HttpSession session = ((HttpServletRequest) request).getSession();
    ServletContext servletContext = session.getServletContext();

    String jspPath = servletContext.getRealPath(jsp);
    File jspFile = new File(jspPath);
    if (!jspFile.exists())
        return;

    respose.flushBuffer();
    RequestDispatcher rd = this.pageContext().getRequest().getRequestDispatcher(jsp);
    try {
        // include the resource, using our custom wrapper
        ImportResponseWrapper irw = new ImportResponseWrapper((HttpServletResponse) respose);
        irw.setCharacterEncoding(charEncoding);
        rd.include(request, irw);
        // disallow inappropriate response codes per JSTL spec
        if (irw.getStatus() < 200 || irw.getStatus() > 299) {
            throw new JspTagException(irw.getStatus() + " " + jsp);
        }

        // recover the response String from our wrapper
        pageContext().getOut().print(irw.getString());
    } catch (ServletException e) {
        e.printStackTrace();
    }
}

From source file:org.infoglue.calendar.taglib.AbstractCalendarTag.java

protected void write(String s) throws JspTagException {
    try {// w ww .  ja  v a2  s. co  m
        pageContext.getOut().write(s);
    } catch (IOException e) {
        e.printStackTrace();
        throw new JspTagException("IO error: " + e.getMessage());
    }
}

From source file:info.magnolia.cms.taglibs.util.ConvertNewLineTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*from w w  w.  ja va  2 s  . co m*/
public int doEndTag() throws JspException {
    String bodyText = bodyContent.getString();

    if (StringUtils.isNotEmpty(bodyText)) {
        StringTokenizer bodyTk = new StringTokenizer(bodyText, "\n", false); //$NON-NLS-1$
        JspWriter out = pageContext.getOut();

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

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

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

    if (ancestorTag == null) {
        throw new JspTagException("An QuicknavDecorator must be used within a ColumnTag.");
    }/*  w  w  w.j a v  a  2 s.  co m*/

    ancestorTag.setDecorator(this);

    return SKIP_BODY;
}