Example usage for javax.servlet.jsp JspException JspException

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

Introduction

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

Prototype

public JspException(String message, Throwable cause) 

Source Link

Document

Constructs a new JspException with the specified detail message and cause.

Usage

From source file:com.redhat.rhn.frontend.taglibs.ColumnTag.java

/**
 * {@inheritDoc}/*from  ww w .  j  av  a2 s .c o  m*/
 */
public int doEndTag() throws JspException {
    JspWriter out = null;
    try {
        out = pageContext.getOut();

        if (!showHeader()) {
            if (showUrl()) {
                out.print(href.renderCloseTag());
            }
            out.print(td.renderCloseTag());
        }

        return Tag.EVAL_BODY_INCLUDE;
    } catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
}

From source file:net.jcreate.e3.table.html.tag.TableTag.java

public int doEndTag() throws JspException {
    PageInfo pageInfo = this.getNavInfo();
    if (pageInfo != null) {
        this.table.addParam(
                new HTMLParam(TableConstants.START_PARAM + "_" + id, String.valueOf(pageInfo.getStart())));
        this.table.addParam(new HTMLParam(TableConstants.PAGE_SIZE_PARAM + "_" + id,
                String.valueOf(pageInfo.getPageSize())));
    }//from  w  w w.ja v a2s  . c  o  m

    SortInfo sortInfo = this.getSortInfo();
    if (sortInfo != null && StringUtils.isNotEmpty(sortInfo.getSortProperty())) {
        this.table.addParam(
                new HTMLParam(TableConstants.SORT_PROPERTY_PARAM + "_" + id, sortInfo.getSortProperty()));
        this.table.addParam(new HTMLParam(TableConstants.SORT_DIR_PARAM + "_" + id, sortInfo.getSortDir()));
        HTMLColumn column = (HTMLColumn) this.table.getColumn(sortInfo.getSortProperty());
        this.table.addParam(new HTMLParam(TableConstants.SORT_NAME_PARAM + "_" + id, column.getSortName()));
    } else {
        this.table.addParam(new HTMLParam(TableConstants.SORT_PROPERTY_PARAM + "_" + id, ""));
        this.table.addParam(new HTMLParam(TableConstants.SORT_NAME_PARAM + "_" + id, ""));
        this.table.addParam(new HTMLParam(TableConstants.SORT_DIR_PARAM + "_" + id, ""));
    }
    ThemeFactory themeFactory = getThemeFactory();
    TableDirector director = themeFactory.createDirector();

    //?
    director.setShowTopToolbar(TableConstants.TOP_POSITION.equalsIgnoreCase(this.toolbarPosition)
            || TableConstants.BOTH_POSITION.equalsIgnoreCase(this.toolbarPosition));
    director.setShowBottomToolbar(TableConstants.BOTTOM_POSITION.equalsIgnoreCase(this.toolbarPosition)
            || TableConstants.BOTH_POSITION.equalsIgnoreCase(this.toolbarPosition));

    //
    if (TableConstants.NONE_POLICY.equalsIgnoreCase(this.toolbarShowPolicy)) {
        director.setShowTopToolbar(false);//?
        director.setShowBottomToolbar(false);
    } else if (TableConstants.NEED_POLICY.equalsIgnoreCase(toolbarShowPolicy)) {
        PageInfo pageData = dataModel.getNavInfo();
        boolean isNeedPage = pageData == null ? false : pageData.getTotalPages() > 1;
        if (isNeedPage == false) {//?
            director.setShowTopToolbar(false);
            director.setShowBottomToolbar(false);
        }
    } else {
        ;//do nothing;
    }

    /**
     * todo:?
     */

    java.util.Iterator keys = virtualRows.keySet().iterator();
    int offset = 0;
    while (keys.hasNext()) {
        Object key = keys.next();
        List rowsList = (List) virtualRows.get(key);
        for (int i = 0; i < rowsList.size(); i++) {
            VirtualHTMLRow virtualRow = (VirtualHTMLRow) rowsList.get(i);
            int index = ((Integer) key).intValue();
            table.addRow(index + offset, virtualRow);
            offset++;
        }
    }
    TableBuilder tableBuilder = themeFactory.createBuilder();
    director.build(tableBuilder, table);
    HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
    try {
        Map exportBeanMap = (Map) request.getAttribute(TableConstants.EXPORT_BEAN_PREFIX + this.id);
        boolean isExport = exportBeanMap != null;
        if (isExport == false) {
            /**
             * TODO:?.
             */
            if (tableBuilder instanceof TextTableBuilder) {
                TextTableBuilder textBuilder = (TextTableBuilder) tableBuilder;
                textBuilder.export(this.pageContext.getOut());
            } else if (tableBuilder instanceof BinaryTableBuilder) {
                BinaryTableBuilder binaryBuilder = (BinaryTableBuilder) tableBuilder;
                try {
                    binaryBuilder.export(this.pageContext.getResponse().getOutputStream());
                } catch (IOException e) {
                    throw new JspException(e.getMessage(), e);
                }
            } else {
                throw new JspException("TableBuilder :" + tableBuilder.getClass().getName()
                        + "TextTableBuilderBinaryTableBuilder?.");
            }
        } else {
            //.
            exportBeanMap.put(TableConstants.REPORT_CONTENT_TYPE_KEY, tableBuilder.getMimeType());
            if (tableBuilder instanceof TextTableBuilder) {
                StringWriter writer = new StringWriter();
                TextTableBuilder textBuilder = (TextTableBuilder) tableBuilder;
                textBuilder.export(writer);
                exportBeanMap.put(TableConstants.REPORT_CONTENT_KEY, writer.toString());
            } else if (tableBuilder instanceof BinaryTableBuilder) {
                BinaryTableBuilder binaryBuilder = (BinaryTableBuilder) tableBuilder;
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                binaryBuilder.export(stream);
                exportBeanMap.put(TableConstants.REPORT_CONTENT_KEY, stream.toByteArray());
            } else {
                throw new JspException("TableBuilder :" + tableBuilder.getClass().getName()
                        + "TextTableBuilderBinaryTableBuilder?.");
            }
        }

    } finally {
        cleanUp();
    }
    if (this.enabledStateManager) {
        this.pageContext.getSession().setAttribute(TableConstants.ENABLED_STATE_MANAGER_PREFIX + this.id,
                new Boolean(enabledStateManager));
        this.pageContext.getSession().setAttribute(TableConstants.STATE_PARAM_PREFIX + this.id,
                this.stateParam);
        SessionStateManager stateManager = new SessionStateManager(this.id,
                new JspPageWebContext(this.pageContext));
        StateInfo stateInfo = new DefaultStateInfo(this.id, sortInfo, pageInfo);
        stateManager.saveStateInfo(stateInfo);
    }
    if (this.getBodyContent() != null) {
        this.getBodyContent().clearBody();
    }
    return super.doEndTag();
}

From source file:com.redhat.rhn.frontend.taglibs.ListDisplayTag.java

/** {@inheritDoc} */
@Override//from w ww  .ja v  a  2s. c om
public int doStartTag() throws JspException {
    rowCnt = 0;
    numItemsChecked = 0;
    JspWriter out = null;
    showSetButtons = false;

    try {
        out = pageContext.getOut();

        setupPageList();

        // Now that we have setup the proper tag state we
        // need to return if this is an export render.
        if (isExport()) {
            return SKIP_PAGE;
        }

        String sortedColumn = getSortedColumn();
        if (sortedColumn != null) {
            doSort(sortedColumn);
        }

        out.print("<div class=\"spacewalk-list ");
        out.println(type + "\"");
        if (tableId != null) {
            out.print(" id=\"" + tableId + "\"");
        }
        out.println(">");

        /*
         * If pageList contains an index and pageList.size() (what we are
         * displaying on the page) is less than pageList.getTotalSize() (the
         * total number of items in the data result), render alphabar. This
         * prevents the alphabar from showing up on pages that show all of
         * the entries on a single page and is similar to how the perl code
         * behaves.
         */
        StringWriter alphaBarContent = new StringWriter();
        StringWriter paginationContent = new StringWriter();

        pageContext.pushBody(alphaBarContent);
        if (getPageList().getIndex().size() > 0 && getPageList().size() < getPageList().getTotalSize()) {

            //renderViewAllLink(alphaBarContent);
            renderAlphabar(alphaBarContent);
        }
        pageContext.popBody();

        pageContext.pushBody(paginationContent);
        if (isPaging()) {
            renderPagination(paginationContent, true);
            renderBoundsVariables(paginationContent);
        }
        pageContext.popBody();

        int topAddonsContentLen = alphaBarContent.getBuffer().length() + paginationContent.getBuffer().length();

        if (topAddonsContentLen > 0) {
            out.println("<div class=\"spacewalk-list-top-addons\">");
            out.println("<div class=\"spacewalk-list-alphabar\">");
            out.print(alphaBarContent.getBuffer().toString());
            out.println("</div>");
            out.print(paginationContent.getBuffer().toString());
            out.println("</div>");
        }

        out.print("<div class=\"panel panel-default\">");

        renderPanelHeading(out);

        out.print("<table class=\"table table-striped\">");
        // we render the pagination controls as an additional head
        out.println("<thead>");
        out.println("\n<tr>");

        if (getIterator() != null && getIterator().hasNext()) {
            // Push a new BodyContent writer onto the stack so that
            // we can buffer the body data.
            bodyContent = pageContext.pushBody();
            return EVAL_BODY_INCLUDE;
        }
        return SKIP_BODY;
    } catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
}

From source file:net.ymate.framework.core.taglib.AbstractTagSupport.java

@Override
public int doStartTag() throws JspException {
    // Init/*from  w w w  . j a  v  a2 s. c o  m*/
    __iterator = null;
    __sequence = 0;
    //
    Object _resultObj = doProcessTagData();
    // ?
    if (__iterator != null) {
        if (StringUtils.isBlank(getVar())) {
            throw new NullArgumentException("var");
        }
        if (__iterator.hasNext()) {
            __doProcessIteratorTagDataStatus(__iterator.next(), ++__sequence);
            return EVAL_BODY_AGAIN;
        } else {
            return SKIP_BODY;
        }
    } else {
        // ??
        if (_resultObj != null) {
            if (StringUtils.isNotBlank(getVar())) {
                switch (Scope
                        .valueOf(StringUtils.defaultIfEmpty(getScope(), Scope.PAGE.name()).toUpperCase())) {
                case APPLICATION:
                    pageContext.getServletContext().setAttribute(getVar(), _resultObj);
                    break;
                case REQUEST:
                    pageContext.getRequest().setAttribute(getVar(), _resultObj);
                    break;
                case SESSION:
                    pageContext.getSession().setAttribute(getVar(), _resultObj);
                    break;
                default:
                    pageContext.setAttribute(getVar(), _resultObj);
                }
            } else if (_resultObj instanceof String) {
                try {
                    pageContext.getOut().write(_resultObj.toString());
                } catch (IOException e) {
                    throw new JspException(e.getMessage(), RuntimeUtils.unwrapThrow(e));
                }
            }
            return EVAL_BODY_INCLUDE;
        } else {
            if (isAlways()) {
                return EVAL_BODY_INCLUDE;
            }
            return SKIP_BODY;
        }
    }
}

From source file:net.ymate.framework.core.taglib.TokenTag.java

@Override
public int doStartTag() throws JspException {
    StringBuilder _contentSB = new StringBuilder();
    HttpSession session = pageContext.getSession();
    if (session != null) {
        String _tokenKey = TokenProcessHelper.TRANSACTION_TOKEN_KEY;
        String _token = null;/*from   w  w w  .  ja  v  a  2 s . c o  m*/
        if (create) {
            if (StringUtils.trimToNull(name) != null) {
                _token = TokenProcessHelper.getInstance()
                        .saveToken((HttpServletRequest) pageContext.getRequest(), name);
                _tokenKey += "|" + name;
            } else {
                _token = TokenProcessHelper.getInstance()
                        .saveToken((HttpServletRequest) pageContext.getRequest());
            }
        } else {
            if (StringUtils.trimToNull(name) != null) {
                _tokenKey += "|" + name;
            }
            _token = (String) session.getAttribute(_tokenKey);
        }
        //
        if (_token != null) {
            _contentSB.append("<input type=\"hidden\" name=\"")
                    .append(StringUtils.defaultIfBlank(name, TokenProcessHelper.TOKEN_KEY))
                    .append("\" value=\"").append(_token).append("\">");
        }
    }
    try {
        pageContext.getOut().println(_contentSB.toString());
    } catch (IOException e) {
        throw new JspException(e.getMessage(), RuntimeUtils.unwrapThrow(e));
    }
    return SKIP_BODY;
}

From source file:no.kantega.commons.taglib.util.LabelTag.java

public int doStartTag() throws JspException {
    JspWriter out;/*from   www  .ja  v a2 s . c  om*/
    try {
        out = pageContext.getOut();
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        if (key != null) {
            Locale locale;
            if (isNotBlank(this.locale)) {
                String[] localePair = this.locale.split("_");
                if (localePair.length == 2) {
                    locale = new Locale(localePair[0], localePair[1]);
                } else {
                    locale = new Locale(localePair[0]);
                }
            } else {
                locale = LocaleLabels.getLocaleFromRequestOrDefault(request);
            }

            String textLabel = "";
            // Try site-bundle first, so that the project may overwrite properties from DEFAULT_BUNDLE
            if (bundle.equals(LocaleLabels.DEFAULT_BUNDLE)) {
                textLabel = LocaleLabels.getLabel(key, "site", locale, params);
            }
            if (!bundle.equals(LocaleLabels.DEFAULT_BUNDLE) || textLabel.equals(key)) {
                textLabel = LocaleLabels.getLabel(key, bundle, locale, params);
            }
            if (escapeJavascript) {
                textLabel = JavaScriptUtils.javaScriptEscape(textLabel);
            }
            out.print(textLabel);
        } else {
            out.print("ERROR: LabelTag, missing key " + key);
        }
        params = null;
        escapeJavascript = false;
        key = null;
        bundle = LocaleLabels.DEFAULT_BUNDLE;
        locale = null;
    } catch (IOException e) {
        throw new JspException("ERROR: LabelTag:" + e.getMessage(), e);
    }

    return SKIP_BODY;
}

From source file:org.apache.sling.scripting.jsp.taglib.EncodeTag.java

/**
 * Writes the encoded text to the response.
 * //  w  w w . j  a va2s . com
 * @param encoded
 *            the encoded text to write to the page
 * @throws JspException
 */
private void write(String encoded) throws JspException {
    if (!StringUtils.isEmpty(encoded)) {
        try {
            pageContext.getOut().write(encoded);
        } catch (IOException e) {
            log.error("Exception writing escaped content to page", e);
            throw new JspException("Exception writing escaped content to page", e);
        }
    }
}

From source file:org.apache.struts.tiles.taglib.InsertTag.java

/**
 * Process tag attribute "definition"./*from  w ww  .ja va 2 s.  c om*/
 * First, search definition in the factory, then create handler from this definition.
 * @param name Name of the definition.
 * @return Appropriate TagHandler.
 * @throws JspException- NoSuchDefinitionException No Definition  found for name.
 * @throws JspException- FactoryNotFoundException Can't find Definitions factory.
 * @throws JspException- DefinedComponentFactoryException General error in factory.
 * @throws JspException InstantiationException Can't create requested controller
 */
protected TagHandler processDefinitionName(String name) throws JspException {

    try {
        ComponentDefinition definition = TilesUtil.getDefinition(name,
                (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext());

        if (definition == null) { // is it possible ?
            throw new NoSuchDefinitionException();
        }

        return processDefinition(definition);

    } catch (NoSuchDefinitionException ex) {
        throw new JspException("Error -  Tag Insert : Can't get definition '" + definitionName
                + "'. Check if this name exist in definitions factory.", ex);

    } catch (FactoryNotFoundException ex) {
        throw new JspException(ex.getMessage());

    } catch (DefinitionsFactoryException ex) {
        if (log.isDebugEnabled()) {
            ex.printStackTrace();
        }

        // Save exception to be able to show it later
        pageContext.setAttribute(Globals.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE);
        throw new JspException(ex);
    }
}

From source file:org.apache.struts.tiles.taglib.PutTag.java

/**
 * Extract real value from specified bean.
 * @throws JspException If something goes wrong while getting value from bean.
 */// www  . j  av a 2  s.c  o  m
protected void getRealValueFromBean() throws JspException {
    try {
        Object bean = TagUtils.retrieveBean(beanName, beanScope, pageContext);
        if (bean != null && beanProperty != null) {
            realValue = PropertyUtils.getProperty(bean, beanProperty);
        } else {
            realValue = bean; // value can be null
        }

    } catch (NoSuchMethodException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);

    } catch (InvocationTargetException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);

    } catch (IllegalAccessException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);
    }
}

From source file:org.apache.struts.tiles.taglib.util.TagUtils.java

/**
 * Locate and return the specified property of the specified bean, from
 * an optionally specified scope, in the specified page context.
 *
 * @param pageContext Page context to be searched.
 * @param beanName Name of the bean to be retrieved.
 * @param beanProperty Name of the property to be retrieved, or
 *  <code>null</code> to retrieve the bean itself.
 * @param beanScope Scope to be searched (page, request, session, application)
 *  or <code>null</code> to use <code>findAttribute()</code> instead.
 *
 * @exception JspException Scope name is not recognized as a valid scope
 * @exception JspException if the specified bean is not found
 * @exception JspException if accessing this property causes an
 *  IllegalAccessException, IllegalArgumentException,
 *  InvocationTargetException, or NoSuchMethodException
 *//*from ww w .j a va 2  s .  co m*/
public static Object getRealValueFromBean(String beanName, String beanProperty, String beanScope,
        PageContext pageContext) throws JspException {

    try {
        Object realValue;
        Object bean = retrieveBean(beanName, beanScope, pageContext);
        if (bean != null && beanProperty != null) {
            realValue = PropertyUtils.getProperty(bean, beanProperty);
        } else {
            realValue = bean; // value can be null
        }
        return realValue;

    } catch (NoSuchMethodException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);

    } catch (InvocationTargetException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);

    } catch (IllegalAccessException ex) {
        throw new JspException("Error - component.PutAttributeTag : Error while retrieving value from bean '"
                + beanName + "' with property '" + beanProperty + "' in scope '" + beanScope
                + "'. (exception : " + ex.getMessage(), ex);
    }
}