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(Throwable cause) 

Source Link

Document

Constructs a new JspException with the specified cause.

Usage

From source file:nl.b3p.commons.taglib.LinkBeanTag.java

/**
 * Render the end of the hyperlink./*from  www  . j  av a2s  . co m*/
 *
 * @exception JspException if a JSP exception has occurred
 */
public int doEndTag() throws JspException {

    // Calculate message from bean, if present and no body content
    if (blink != null && bmessage != null && text == null) {
        // Retrieve the required property
        String key = null;
        try {
            Object bean = pageContext.findAttribute(blink);
            key = (String) PropertyUtils.getProperty(bean, bmessage);
        } catch (IllegalAccessException e) {
            throw new JspException("No access: " + e.getMessage());
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            throw new JspException("No result: " + e.getMessage());
        } catch (NoSuchMethodException e) {
            throw new JspException("No method: " + e.getMessage());
        } catch (Exception e) {
        }

        // Retrieve the message string we are looking for
        String message = TagUtils.getInstance().message(pageContext, this.bundle, this.localeKey, key);
        if (message != null && message.length() > 0) {
            text = message;
        } else if (key != null) {
            text = key;
        } else {
            text = "";
        }
    }

    return super.doEndTag();
}

From source file:nl.strohalm.cyclos.taglibs.AbstractEscapeTag.java

@Override
public int doEndTag() throws JspException {

    // Retrieve the string form the attribute 'value' or from the body
    String out;/*from www.  j  a  v  a 2  s  .c o  m*/
    if (value != null) {
        out = value;
    } else if (body != null) {
        out = body;
    } else {
        out = "";
    }

    // Escape the string as JavaScript
    final String js = escape(out);

    // If var is defined, export the variable instead of writing the result
    if (var != null) {
        pageContext.setAttribute(var, js, scope);
    } else {
        try {
            pageContext.getOut().print(js);
        } catch (final IOException e) {
            throw new JspException(e);
        }
    }

    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.CustomFieldTag.java

@Override
public int doEndTag() throws JspException {
    try {//w  w w  .j  a v a 2 s  .c  o  m
        if (field == null) {
            throw new JspException("Field is null on CustomFieldTag");
        }

        // Get the field value from collection if needed
        if (value == null && collection != null) {
            for (final CustomFieldValue customValue : collection) {
                if (field.equals(customValue.getField())) {
                    value = customValue;
                    break;
                }
            }
        }

        final StringBuilder sb = new StringBuilder();

        // There is a hidden that will store the field id
        if (StringUtils.isNotEmpty(fieldName)) {
            sb.append("<input type=\"hidden\" name=\"").append(fieldName).append("\" value=\"")
                    .append(field.getId()).append("\">");
        }

        final CustomField.Control control = field.getControl();

        if (editable && !textOnly) {
            if (field.getType() == CustomField.Type.BOOLEAN) {
                if (search) {
                    // When a boolean is on search, we use a select with true and false values
                    renderSelect(sb);
                } else {
                    // Boolean is always a check box. As it is not submitted when is not checked, we must use a hidden that will be submitted
                    renderCheckBox(sb);
                }
            } else if (field.getType() == Type.MEMBER) {
                renderMemberSelect(sb);
            } else if (field.getType() == CustomField.Type.ENUMERATED) {
                final Collection<CustomFieldPossibleValue> possibleValues = field.getPossibleValues(false);
                if (CollectionUtils.isEmpty(possibleValues)) {
                    // If there are no possible values, render a hidden, so it is ensured that a value will be submitted
                    sb.append("<input type=\"hidden\" name=\"").append(valueName).append("\">");
                } else {
                    if (control == CustomField.Control.RADIO && !search) {
                        // Render a radio group
                        renderRadioGroup(sb);
                    } else {
                        // Render a select box
                        renderSelect(sb);
                    }
                }
            } else if (!search && field.getControl() == CustomField.Control.TEXTAREA) {
                renderTextarea(sb);
            } else if (!search && field.getControl() == CustomField.Control.RICH_EDITOR) {
                renderRichEditor(sb);
            } else {
                renderText(sb);
            }
        } else {
            renderDisplay(sb);
        }
        pageContext.getOut().write(sb.toString());
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.CustomizedFilePathTag.java

@Override
public int doEndTag() throws JspException {
    final String path = resolvePath();
    try {// w w w.j  a va  2  s.  c  o m
        if (var == null) {
            pageContext.getOut().write(path);
        } else {
            pageContext.setAttribute(var, path, scope);
        }
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.FormatTag.java

@Override
public int doEndTag() throws JspException {
    String out = "";
    final LocalSettings localSettings = getLocalSettings();
    if (number != null) {
        if (number instanceof Double || number instanceof BigDecimal || number instanceof Float) {
            final BigDecimal theNumber = CoercionHelper.coerce(BigDecimal.class, number);
            NumberConverter<BigDecimal> numberConverter;
            if (StringUtils.isNotEmpty(unitsPattern)) {
                numberConverter = localSettings.getUnitsConverter(unitsPattern);
            } else if (precision == null) {
                numberConverter = localSettings.getNumberConverter();
            } else {
                numberConverter = localSettings.getNumberConverterForPrecision(precision);
            }/*from   w  w w  .j  ava 2 s.  c om*/
            out = numberConverter.toString(theNumber);
            if (forceSignal && theNumber.compareTo(BigDecimal.ZERO) > 0) {
                out = "+" + out;
            }
        } else if (number instanceof StatisticalNumber) {
            out = convertStatisticalNumber((StatisticalNumber) number);
        } else if (number instanceof BigInteger && cardNumberPattern != null) {
            out = new CardNumberConverter(cardNumberPattern).toString((BigInteger) number);
        } else {
            final NumberConverter<Long> longConverter = localSettings.getLongConverter();
            final Long theNumber = CoercionHelper.coerce(Long.class, number);
            out = longConverter.toString(theNumber);
        }
    } else if (amount != null) {
        Converter<Amount> converter;
        if (StringUtils.isEmpty(unitsPattern)) {
            converter = localSettings.getAmountConverter();
        } else {
            converter = localSettings.getAmountConverter(unitsPattern);
        }
        out = converter.toString(amount);
    } else if (rawDate != null) {
        out = localSettings.getRawDateConverter().toString(rawDate);
    } else if (date != null) {
        out = localSettings.getDateConverter().toString(date);
    } else if (dateTime != null) {
        out = localSettings.getDateTimeConverter().toString(dateTime);
    } else if (time != null) {
        out = localSettings.getTimeConverter().toString(time);
    } else if (bytes != null) {
        out = FileUtils.byteCountToDisplaySize(bytes);
    } else {
        out = defaultValue == null ? null : defaultValue.toString();
    }
    try {
        if (StringUtils.isNotEmpty(out)) {
            pageContext.getOut().print(out);
        }
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.ImagesTag.java

@Override
public int doStartTag() throws JspException {

    final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    final StringBuilder sb = new StringBuilder();
    if (images == null) {
        images = Collections.emptyList();
    }/*from ww w.j a v  a  2s.  c  o  m*/

    final LocalSettings localSettings = getLocalSettings();

    // Get the nature and owner id of the images
    Image.Nature nature = null;
    Long ownerId = null;
    if (!images.isEmpty()) {
        final OwneredImage image = images.iterator().next();
        nature = image.getNature();
        ownerId = image.getOwner().getId();
    }

    final int adjust = imageOnly ? 0 : 8;
    final int width = localSettings.getMaxThumbnailWidth() + adjust;
    final String rnd = System.currentTimeMillis() + "_" + RandomStringUtils.random(4, true, false);
    final String id = "img_" + rnd;
    sb.append("<div id='").append(id).append("' style='width:").append(width).append("px;")
            .append(style == null ? "" : style).append("' class='imageContainerDiv ")
            .append(imageOnly ? "" : "imageContainer").append("'>");
    if (!imageOnly) {
        sb.append(
                "<div class='thumbnailContainer'><table style='width:100%;border:none;padding:0px;margin:0px;'><tr><td style='text-align:center;vertical-align:middle;border:none;padding:0px;margin:0px;'>\n");
    }
    sb.append("<img class='thumbnail' id='thumbnail_").append(rnd).append("' src='")
            .append(request.getContextPath()).append("/systemImage?image=noPicture&thumbnail=true'/>");
    if (!imageOnly) {
        sb.append("</td></tr></table></div>");
        if (images.size() > 1) {
            sb.append("<div class='imageControls' id='imageControls_").append(rnd)
                    .append("'><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr>");
            sb.append("<td style='padding:0px' class='imageControlPrevious' id='previous_").append(rnd).append(
                    "' onclick='this.container.previousImage()' align='center' width='10'><img style='cursor:pointer;cursor:hand;' src=\""
                            + request.getContextPath() + "/pages/images/previous.gif\" border=\"0\"></td>");
            sb.append("<td style='padding:0px' class='imageIndex' id='index_").append(rnd)
                    .append("' nowrap='nowrap' align='center'>1 / ").append(images.size()).append("</td>");
            sb.append("<td style='padding:0px' class='imageControlNext' id='next_").append(rnd).append(
                    "' onclick='this.container.nextImage()' align='center' width=\'10\'><img style='cursor:pointer;cursor:hand;' src=\""
                            + request.getContextPath() + "/pages/images/next.gif\" border=\"0\"></td>");
            sb.append("</tr></table></div>\n");
        }
        if (editable && !images.isEmpty()) {
            final MessageHelper messageHelper = SpringHelper.bean(pageContext.getServletContext(),
                    MessageHelper.class);
            sb.append("<div class='imageDetails' id='imageDetails_").append(rnd)
                    .append("' style='cursor:pointer;cursor:hand' onclick='this.container.details()'><a>");
            sb.append(messageHelper.message("image.details"));
            sb.append("</a></div>\n");
            sb.append("<div class='imageRemove' id='imageRemove_").append(rnd)
                    .append("' style='cursor:pointer;cursor:hand' onclick='this.container.removeImage()'><a>");
            sb.append(messageHelper.message("image.remove"));
            sb.append("</a></div>\n");
        }
    }
    sb.append("</div>\n");
    sb.append("<script>\n");
    final String varName = StringUtils.isEmpty(this.varName) ? id : this.varName;
    sb.append(
            String.format("var %s = new ImageContainer($('%s'), '%s', '%s');\n", varName, id, nature, ownerId));

    // Add the image descriptors
    for (final OwneredImage image : images) {
        final String caption = StringEscapeUtils.escapeHtml(StringUtils.trimToEmpty(image.getCaption()));
        final String url = StringEscapeUtils
                .escapeHtml(request.getContextPath() + "/thumbnail?id=" + image.getId());
        sb.append(varName)
                .append(String.format(".imageDescriptors.push(new ImageDescriptor('%s', '%s', '%s'));\n",
                        image.getId(), StringEscapeUtils.escapeJavaScript(caption),
                        StringEscapeUtils.escapeJavaScript(url)));
    }

    // Set the references to other elements
    sb.append(varName).append(".appendElement('index', 'index_").append(rnd).append("');\n");
    sb.append(varName).append(".appendElement('thumbnail', 'thumbnail_").append(rnd).append("');\n");
    sb.append(varName).append(".appendElement('controls', 'imageControls_").append(rnd).append("');\n");
    sb.append(varName).append(".appendElement('previous', 'previous_").append(rnd).append("');\n");
    sb.append(varName).append(".appendElement('next', 'next_").append(rnd).append("');\n");
    sb.append(varName).append(".appendElement('imageRemove', 'imageRemove_").append(rnd).append("');\n");
    sb.append(varName).append(".appendElement('imageDetails', 'imageDetails_").append(rnd).append("');\n");

    sb.append(varName).append(".currentImage = 0;\n");
    sb.append(varName).append(".updateImage();\n");

    sb.append("</script>\n");
    try {
        pageContext.getOut().print(sb.toString());
    } catch (final IOException e) {
        throw new JspException(e);
    }
    return EVAL_PAGE;
}

From source file:nl.strohalm.cyclos.taglibs.MenuTag.java

@Override
public int doEndTag() throws JspException {
    try {/*from  w w w  .  j a  v  a 2 s  . co m*/
        // Rendering is done by the topmost tag. If this is nested, do nothing
        // Also, render something only if there is some content
        if (menu == null || menu.isNested() || !menu.hasContent()) {
            return EVAL_PAGE;
        }
        final JspWriter out = pageContext.getOut();

        // Render this parent menu
        final int index = index();
        final String divId = divId(menu, index);
        renderDiv(menu, index, divId);

        // Render each submenu
        final List<Menu> subMenus = menu.getChildren();
        if (CollectionUtils.isNotEmpty(subMenus)) {
            out.print("<ul id='subMenuContainer" + index + "' class='subMenuContainer' style='display:none'>");
            final int subMenuCount = subMenus.size();
            for (int i = 0; i < subMenuCount; i++) {
                final Menu subMenu = subMenus.get(i);
                final String subMenuId = divId(subMenu, i);
                renderDiv(subMenu, i, subMenuId);
                if (i == 0) {
                    out.println("<script>$('" + subMenuId + "').addClassName('firstSubMenu');</script>");
                } else if (i == subMenuCount - 1) {
                    out.println("<script>$('" + subMenuId + "').addClassName('lastSubMenu');</script>");
                }
            }
            out.println("</ul></li>");
        }
        out.println();
        out.println("<script>allMenus.push($('" + divId + "'));</script>");

        return EVAL_PAGE;
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
}

From source file:nl.strohalm.cyclos.taglibs.MultiDropDownTag.java

@Override
public int doEndTag() throws JspException {
    try {//from   w w  w . j  a  v  a 2s. co  m
        // Build the options object
        final StringBuilder options = new StringBuilder();
        options.append('{');
        options.append("'singleField':").append(singleField).append(',');
        options.append("'open':").append(open).append(',');
        options.append("'disabled':").append(disabled);
        if (size != null) {
            options.append(",'size':").append(size);
        }
        if (minWidth != null) {
            options.append(",'minWidth':").append(minWidth);
        }
        if (maxWidth != null) {
            options.append(",'maxWidth':").append(maxWidth);
        }
        if (emptyLabelKey != null) {
            emptyLabel = messageHelper.message(emptyLabelKey);
        }
        if (emptyLabel != null) {
            options.append(",'emptyLabel':\"").append(StringEscapeUtils.escapeJavaScript(emptyLabel))
                    .append('"');
        }
        if (onchange != null) {
            options.append(",'onchange':\"").append(StringEscapeUtils.escapeJavaScript(onchange)).append('"');
        }
        options.append('}');

        // Write the rest of the script
        final JspWriter out = pageContext.getOut();
        if (StringUtils.isNotEmpty(varName)) {
            out.print(varName + "=");
        }
        out.println("new MultiDropDown(" + divId + ", '" + name + "', " + divId + ".values, " + options + ")");
        out.println("</script>");
        return EVAL_PAGE;
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
}

From source file:nl.strohalm.cyclos.taglibs.MultiDropDownTag.java

@Override
@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {
    divId = "_container_" + System.currentTimeMillis() + "_" + new Random().nextInt(Integer.MAX_VALUE);

    if (selectedValues == null) {
        try {/*w  w w. j a va2 s  .  co  m*/
            final Object form = pageContext.findAttribute(Constants.BEAN_KEY);
            selectedValues = CoercionHelper.coerce(List.class, PropertyHelper.get(form, name));
            for (int i = 0; i < selectedValues.size(); i++) {
                selectedValues.set(i, CoercionHelper.coerce(String.class, selectedValues.get(i)));
            }
        } catch (final Exception e) {
            // Leave selected values empty
        }
    }

    try {
        final JspWriter out = pageContext.getOut();
        out.print("<div");
        if (maxWidth != null) {
            out.print(" style='width:" + maxWidth + "px'");
        }
        out.println(" id='" + divId + "'></div>");
        // Write the start of the script
        out.println("<script>");
        out.println("var mddNoItemsMessage = \""
                + StringEscapeUtils.escapeJavaScript(messageHelper.message("multiDropDown.noItemsMessage"))
                + "\";");
        out.println("var mddSingleItemsMessage = \""
                + StringEscapeUtils.escapeJavaScript(messageHelper.message("multiDropDown.singleItemMessage"))
                + "\";");
        out.println("var mddMultiItemsMessage = \""
                + StringEscapeUtils.escapeJavaScript(messageHelper.message("multiDropDown.multiItemsMessage"))
                + "\";");

        out.println("var " + divId + " = $('" + divId + "');");
        out.println(divId + ".values = [];");
    } catch (final IOException e) {
        throw new JspException(e);
    }

    return EVAL_BODY_INCLUDE;
}

From source file:nl.strohalm.cyclos.taglibs.OptionTag.java

@Override
public int doEndTag() throws JspException {
    try {//from   www .  j a v a2 s.c o  m
        final MultiDropDownTag mdd = (MultiDropDownTag) findAncestorWithClass(this, MultiDropDownTag.class);
        if (mdd == null) {
            throw new IllegalStateException("cyclos:option tag must be nested in a cyclos:muldiDropDown tag");
        }
        final JspWriter out = pageContext.getOut();
        final String text = StringEscapeUtils.escapeJavaScript(StringUtils.trimToEmpty(this.text));
        final String value = StringEscapeUtils.escapeJavaScript(StringUtils.trimToEmpty(this.value));
        boolean selected;
        if (this.selected == null) {
            final List<String> selectedValues = mdd.getSelectedValues();
            selected = selectedValues != null && selectedValues.contains(value);
        } else {
            selected = this.selected;
        }
        out.println(mdd.getDivId() + ".values.push({text:'" + text + "', value:'" + value + "', selected:"
                + selected + "})");
        return EVAL_PAGE;
    } catch (final IOException e) {
        throw new JspException(e);
    } finally {
        release();
    }
}