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:de.iteratec.iteraplan.presentation.tags.TagUtils.java

/**
 * Write the specified text as the response to the writer associated with this page.
 * //w ww.  j av  a 2s .  co  m
 * @param pageContext
 *          The PageContext object for this page
 * @param text
 *          The text to be written
 * @throws JspException
 *           if an input/output error occurs
 */
public static void write(PageContext pageContext, String text) throws JspException {
    JspWriter writer = pageContext.getOut();

    try {
        writer.print(text);
    } catch (IOException e) {
        throw new JspException("An I/O error ocurred: ", e);
    }
}

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

/**
 * {@inheritDoc}// w  w  w. ja  v a 2  s.c  o  m
 */
public int doStartTag() throws JspException {
    td = new HtmlTag("td");
    href = new HtmlTag("a");

    try {
        JspWriter out = pageContext.getOut();

        if (usesRefactoredList) {
            UnpagedListDisplayTag parent = findUnpagedListDisplay();
            if (showHeader()) {
                parent.incrNumberOfColumns();
                renderHeader(out, header, arg0);
                return SKIP_BODY;
            }
            renderData(out, parent);
        } else {
            ListDisplayTag parent = findListDisplay();
            if (showHeader()) {
                parent.incrNumberOfColumns();
                renderHeader(out, header, arg0);
                return SKIP_BODY;
            }
            renderData(out, parent);
        }

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

From source file:com.redhat.rhn.frontend.taglibs.list.ListTag.java

private ListDecorator getDecorator(String decName) throws JspException {
    if (decName != null) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {//from   w  w w .ja v  a2  s. c om
            if (decName.indexOf('.') == -1) {
                decName = "com.redhat.rhn.frontend.taglibs.list.decorators." + decName;
            }
            ListDecorator dec = (ListDecorator) cl.loadClass(decName).newInstance();
            ListSetTag parent = (ListSetTag) BodyTagSupport.findAncestorWithClass(this, ListSetTag.class);
            dec.setEnvironment(pageContext, parent, getUniqueName());
            return dec;
        } catch (Exception e) {
            String msg = "Exception while adding Decorator [" + decName + "]";
            throw new JspException(msg, e);
        }
    }
    return null;

}

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

/** {@inheritDoc}
 * @throws JspException/*from  w  ww. ja va 2s .  co m*/
 */
public int doStartTag() throws JspException {

    JspWriter out = null;
    try {
        out = pageContext.getOut();
        LocalizationService ls = LocalizationService.getInstance();

        StringBuilder result = new StringBuilder();
        StringBuilder key = new StringBuilder("address type ");
        key.append(type);
        result.append("<strong>");
        result.append(ls.getMessage(key.toString()));
        result.append("</strong>");
        if (user == null) {
            throw new IllegalArgumentException("User is null");
        }

        // If this Address is new
        if (address != null && StringUtils.isNotBlank(address.getCity())
                && StringUtils.isNotBlank(address.getZip())) {
            result.append("<address>");
            // Address 1 and 2
            result.append(address.getAddress1());
            result.append("<br />");
            if (StringUtils.isNotBlank(address.getAddress2())) {
                result.append(address.getAddress2());
                result.append("<br />");
            }

            // City
            result.append(address.getCity());
            if (StringUtils.isNotBlank(address.getState())) {
                result.append(", ");
                result.append(address.getState());
            }

            result.append(" ");
            result.append(address.getZip());
            result.append("<br />");

            // Phones
            result.append(ls.getMessage("phone"));
            result.append(": ");
            result.append(address.getPhone());
            result.append("<br />");
            if (StringUtils.isNotBlank(address.getFax())) {
                result.append(ls.getMessage("fax"));
                result.append(": ");
                result.append(address.getFax());
                result.append("<br />");
            }

            result.append("</address>");

            result.append("<p>");
            result.append("<a ").append("class=\"btn btn-primary\"").append(" href=\"").append(getActionUrl())
                    .append("/EditAddress.do?type=").append(type).append("&amp;uid=")
                    .append(String.valueOf(user.getId())).append("\">")
                    .append(ls.getMessage("Edit this address")).append("</a>");
            result.append("</p>");
        } else {
            result.append("<div class=\"alert alert-info\">");
            result.append(ls.getMessage("address not filled in"));
            result.append("</div>");
            result.append("<p>");
            result.append("<a ").append("class=\"btn btn-primary\"").append(" href=\"").append(getActionUrl())
                    .append("/EditAddress.do?type=").append(type).append("&amp;uid=")
                    .append(String.valueOf(user.getId())).append("\">")
                    .append(ls.getMessage("Fill in this address")).append("</a>");
            result.append("</p>");
        }

        out.print(result);
    } catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }

    return (SKIP_BODY);
}

From source file:net.mlw.vlh.web.tag.DefaultColumnTag.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *///from w w w . j  a v  a  2  s. co m
public int doEndTag() throws JspException {

    ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class);

    DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class);

    ValueListConfigBean config = rootTag.getConfig();

    appendClassCellAttribute(rowTag.getRowStyleClass());

    if (locale == null) {
        //         locale = config.getLocaleResolver().resolveLocale((HttpServletRequest) pageContext.getRequest());
        locale = Locales.getSupportedLocale((HttpServletRequest) pageContext.getRequest());
    }

    if (rowTag.getCurrentRowNumber() == 0) // if this is the 1st row == the one with cell headers
    {

        String titleKey = getTitleKey();
        String label = (titleKey == null) ? getTitle()
                : config.getMessageSource().getMessage(titleKey, null, titleKey, locale);

        ColumnInfo columnInfo = new ColumnInfo(config.getDisplayHelper().help(pageContext, label),
                getAdapterProperty(), defaultSort, getAttributes());

        // Process toolTip if any
        // toolTip or toolTipKey is set => get the string and put it into the ColumnInfo
        String toolTipKey = getToolTipKey();
        columnInfo.setToolTip((toolTipKey == null) ? getToolTip()
                : config.getMessageSource().getMessage(toolTipKey, null, toolTipKey, locale));

        columnInfo.setNestedList(this.nestedColumnInfoList);

        rowTag.addColumnInfo(columnInfo);
    }

    DisplayProvider displayProvider = rowTag.getDisplayProvider();

    StringBuffer sb = new StringBuffer(displayProvider.getCellPreProcess(getCellAttributes()));

    boolean hasBodyContent = false;

    if (displayProvider.doesIncludeBodyContent() && bodyContent != null && bodyContent.getString() != null
            && bodyContent.getString().trim().length() > 0) {
        sb.append(bodyContent.getString().trim());
        bodyContent.clearBody();
        hasBodyContent = true;
    }

    {
        if (property != null && rowTag.getBeanName() != null) {
            try {
                Object bean = pageContext.getAttribute(rowTag.getBeanName());
                if (bean != null) {
                    Object value = null;
                    try {
                        value = PropertyUtils.getProperty(bean, property);
                    } catch (Exception e) {
                        //Do nothing, if you want to handle this exception, then
                        // use a try catch in the body content.
                        //                     LOGGER.error("<vlh:column> Error getting property='" + property + "' from the iterated JavaBean name='"
                        //                           + rowTag.getBeanName() + "'\n The row's JavaBean was >>>" + bean
                        //                           + "<<<\n Check the syntax or the spelling of the column's property!");
                    }

                    if (value != null) {
                        if (sum != null && value instanceof Number) {
                            double doubleValue = ((Number) value).doubleValue();
                            Double sumValue = (Double) pageContext.getAttribute(sum);
                            if (sumValue == null) {
                                sumValue = new Double(doubleValue);
                            } else {
                                sumValue = new Double(sumValue.doubleValue() + doubleValue);
                            }
                            pageContext.setAttribute(sum, sumValue);
                        }

                        if (!hasBodyContent) {
                            String formattedValue = JspUtils.format(value, format, locale);

                            if (groupKey == null
                                    || (config.getCellInterceptor() == null || !config.getCellInterceptor()
                                            .isHidden(pageContext, groupKey, property, formattedValue))) {
                                sb.append(displayProvider.emphase(formattedValue, getEmphasisPattern(),
                                        getColumnStyleClass()));
                            }
                        }

                    } else if (!hasBodyContent) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("The property '" + property + "' of the iterated JavaBean '" + bean
                                    + "' is null!");
                        }

                        Object nullValue = (defaultValue == null) ? config.getNullToken() : defaultValue;

                        if (groupKey == null || (config.getCellInterceptor() == null || !config
                                .getCellInterceptor().isHidden(pageContext, groupKey, property, nullValue))) {
                            sb.append(nullValue);
                        }
                    }
                }
            } catch (Exception e) {
                final String message = "DefaultColumnTag.doEndTag() - <vlh:column> error getting property: "
                        + property + " from bean.";
                LOGGER.error(message, e);
                throw new JspException(message, e);
            }
        }
    }

    sb.append(displayProvider.getCellPostProcess());
    JspUtils.write(pageContext, sb.toString());

    release();

    return EVAL_PAGE;
}

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

/** {@inheritDoc} */
public int doStartTag() throws JspException {
    rowCnt = 0;/*from  ww  w .j a v  a  2s. co  m*/
    JspWriter out = null;

    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.print("<div class=\"panel panel-default\">");

        renderPanelHeading(out);

        /* If the type is list, we must set the width explicitly. Otherwise,
         * it shouldn't matter
         */
        if (getType().equals("list")) {
            out.print("<table class=\"table table-striped\"");
        } else if (getType().equals("treeview")) {
            out.print("<table class=\"table table-striped\" id=\"channel-list\"");
        } else {
            out.print("<table class=\"" + getType() + "\"");
        }

        /*if (isTransparent()) {
        out.print(" style=\"border-bottom: 1px solid #ffffff;\" ");
        }*/

        out.println(">");
        out.println("<thead>");
        out.println("<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:com.redhat.rhn.frontend.taglibs.IconTag.java

/** {@inheritDoc}
 * @throws JspException//from  w  ww .j  a v a2  s. c  o  m
 */
public int doStartTag() throws JspException {
    if (!icons.containsKey(type)) {
        throw new IllegalArgumentException("Unknown icon type: \"" + type + "\".");
    }

    JspWriter out = null;
    try {
        out = pageContext.getOut();
        String result = renderStartTag();
        out.print(result);
    } catch (IOException ioe) {
        throw new JspException("IO error writing to JSP file:", ioe);
    }
    return SKIP_BODY;
}

From source file:javax.faces.webapp.UIComponentTag.java

/**
 * Invoked by the standard jsp processing mechanism when the opening
 * tag of a JSF component element is found.
 * <p>// w  w w. j  a va  2  s. co m
 * The UIComponent associated with this tag is created (if the view
 * doesn't exist) or located if the view is being re-rendered. If
 * the component is not "suppressed" then its encodeBegin method is
 * called (see method isSuppressed). Note also that method
 * encodeBegin is <i>not</i> called for components for which
 * getRendersChildren returns true; that occurs only in doEndTag.
 */
public int doStartTag() throws JspException {
    setupResponseWriter();
    FacesContext facesContext = getFacesContext();
    UIComponent component = findComponent(facesContext);
    if (!component.getRendersChildren() && !isSuppressed()) {
        try {
            encodeBegin();
            _writer.flush();
        } catch (IOException e) {
            throw new JspException(e.getMessage(), e);
        }
    }
    pushTag();
    return getDoStartValue();
}

From source file:de.iteratec.iteraplan.presentation.tags.IteratecWriteTag.java

/**
 * Format value according to specified format string (as tag attribute or as string from message
 * resources) or to current user locale.
 * /*from w ww. j  a  v  a 2s.  co m*/
 * @param valueToFormat
 *          value to process and convert to String
 * @exception JspException
 *              if a JSP exception has occurred
 */
protected String formatValue(Object valueToFormat) throws JspException {
    Format format = null;
    Object value = valueToFormat;
    Locale locale = UserContext.getCurrentLocale();
    boolean formatStrFromResources = false;
    String formatString = null;

    // Return String object as is.
    if (value instanceof String) {
        return (String) value;
    } else {

        // Prepare format object for numeric values.
        if (value instanceof Number) {

            if ((value instanceof Byte) || (value instanceof Short) || (value instanceof Integer)
                    || (value instanceof Long) || (value instanceof BigInteger)) {
                formatString = MessageAccess.getStringOrNull(INT_FORMAT_KEY, locale);
            } else if ((value instanceof Float) || (value instanceof Double) || (value instanceof BigDecimal)) {
                formatString = MessageAccess.getStringOrNull(FLOAT_FORMAT_KEY, locale);
            }

            if (formatString != null) {
                formatStrFromResources = true;

                try {
                    format = NumberFormat.getNumberInstance(locale);
                    if (formatStrFromResources) {
                        ((DecimalFormat) format).applyLocalizedPattern(formatString);
                    } else {
                        ((DecimalFormat) format).applyPattern(formatString);
                    }
                } catch (IllegalArgumentException _e) {
                    JspException e = new JspException("Wrong format string: " + formatString, _e);
                    throw e;
                }
            }

        } else if (value instanceof Date) {

            formatString = MessageAccess.getStringOrNull(DATE_FORMAT_KEY, locale);

            if (formatString != null) {
                formatStrFromResources = true;

                if (formatStrFromResources) {
                    format = new SimpleDateFormat(formatString, locale);
                } else {
                    format = new SimpleDateFormat(formatString); // NOPMD this is the last fallback, so
                                                                 // locale-less is intended
                }
            }

        }
    }

    if (format != null) {
        return format.format(value);
    } else {
        return value.toString();
    }
}

From source file:javax.faces.webapp.UIComponentTag.java

/**
 * Invoked by the standard jsp processing mechanism when the closing
 * tag of a JSF component element is found.
 * <p>/*ww  w .  jav  a2 s.  c om*/
 * When the view is being re-rendered, any former children of this tag's
 * corresponding component which do not have corresponding tags
 * as children of this tag are removed from the view. This isn't likely
 * to be a common occurrence: wrapping JSF tags in JSTL tag "c:if" is
 * one possible cause. Programmatically created components are not affected
 * by this.
 * <p>
 * If the corresponding component returns true from getRendersChildren
 * then its encodeBegin and encodeChildren methods are called here.
 * <p>
 * The component's encodeEnd method is called provided the component
 * is not "suppressed".
 */
public int doEndTag() throws JspException {
    popTag();
    UIComponent component = getComponentInstance();
    removeFormerChildren(component);
    removeFormerFacets(component);

    try {
        if (!isSuppressed()) {
            if (component.getRendersChildren()) {
                encodeBegin();
                encodeChildren();
            }
            encodeEnd();
        }
    } catch (IOException e) {
        throw new JspException(e.getMessage(), e);
    }

    int retValue = getDoEndValue();
    internalRelease();
    return retValue;
}