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:net.ontopia.topicmaps.webed.taglibs.form.FormTag.java

/**
 * Renders the input form element with it's content.
 *///from   w  w  w  . j  a va 2 s  .  c  om
@Override
public int doAfterBody() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    TagUtils.setCurrentFormTag(request, null);

    VelocityContext vc = TagUtils.getVelocityContext(pageContext);
    // attributes of the form element
    vc.put("name", NAME);
    String id = idattr;
    if (id == null)
        id = requestId;
    // Use requestId by default, to make sure there always is an id.
    vc.put("idattr", id);
    // -- class
    if (klass != null)
        vc.put("class", klass);

    validationRules = getFieldValidationRules();
    if (!validationRules.isEmpty()) {
        vc.put("performFieldValidation", Boolean.TRUE);
        vc.put("validationRules", validationRules);
        vc.put("onsubmit", "return validate('" + id + "');");
    } else
        vc.put("onsubmit", "return true;");

    vc.put("outputSubmitFunc", getOutputSubmitFunc());

    // reset the outputSubmitFunc variable
    setOutputSubmitFunc(false);

    // -- action
    String context_name = request.getContextPath();
    String default_action = context_name + "/" + Constants.PROCESS_SERVLET;
    vc.put("action", (action_uri != null) ? action_uri : default_action);
    ActionRegistryIF registry = TagUtils.getActionRegistry(pageContext);
    // -- target (only in the case of a multi framed web app)
    if (registry == null)
        throw new JspException(
                "No action registry available! Check actions.xml for errors; see log for details.");
    vc.put("target", target);
    // -- enctype
    if (enctype != null)
        vc.put("enctype", enctype);
    // -- nested
    if (nested != null)
        vc.put("nested", nested);

    if (lockVarname != null)
        vc.put(Constants.RP_LOCKVAR, lockVarname);

    NavigatorPageIF contextTag = FrameworkUtils.getContextTag(pageContext);

    // add hidden parameter value pairs to identify the request
    String topicmap_id = request.getParameter(Constants.RP_TOPICMAP_ID);
    if (topicmap_id == null && contextTag != null) {
        // if not set try to retrieve it from the nav context
        NavigatorApplicationIF navApp = contextTag.getNavigatorApplication();
        TopicMapIF tm = contextTag.getTopicMap();
        if (tm != null)
            topicmap_id = navApp.getTopicMapRefId(tm);
    }
    vc.put(Constants.RP_TOPICMAP_ID, topicmap_id);
    vc.put(Constants.RP_TOPIC_ID, request.getParameter(Constants.RP_TOPIC_ID));
    vc.put(Constants.RP_ASSOC_ID, request.getParameter(Constants.RP_ASSOC_ID));
    vc.put(Constants.RP_ACTIONGROUP, actiongroup);
    vc.put(Constants.RP_REQUEST_ID, requestId);

    // FIXME: Do we really need this line? Probably not, since each control
    // should now itself be responisible for determining whether it should be
    // readonly. Hence the individual control can overrule the form setting.
    // vc.put("readonly", TagUtils.isFormReadOnly(request));

    // content inside the form element
    BodyContent body = getBodyContent();
    vc.put("content", body.getString());

    // render JavaScript to set the input focus (if required)
    if (focus != null) {
        String focus_elem = focus;
        StringBuilder focus_ref = new StringBuilder("[");
        if (focus_elem.indexOf('[') > 0) {
            StringTokenizer st = new StringTokenizer(focus_elem, "[");
            if (st.countTokens() == 2) {
                focus_elem = st.nextToken();
                focus_ref.append(st.nextToken());
            }
        }
        vc.put("focus_elem", focus_elem);
        if (focus_ref.length() > 1)
            vc.put("focus_ref", focus_ref.toString());
        else
            vc.put("focus_ref", "");
    }

    // all variables are now set, proceed with outputting
    TagUtils.processWithVelocity(pageContext, TEMPLATE_FILE, getBodyContent().getEnclosingWriter(), vc);

    // clear read-only state
    request.removeAttribute(Constants.OKS_FORM_READONLY);

    return SKIP_BODY;
}

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

/**
 * Locate and return the specified property of the specified bean, from an optionally specified
 * scope, in the specified page context.
 * /*from  w w w  .  j a v a2 s  .c o m*/
 * @param pageContext
 *          Page context to be searched
 * @param name
 *          Name of the bean to be retrieved
 * @param property
 *          Name of the property to be retrieved, or <code>null</code> to retrieve the bean itself
 * @param scope
 *          Scope to be searched (page, request, session, application) or <code>null</code> to use
 *          <code>findAttribute()</code> instead
 * @return property of specified JavaBean
 * @throws JspException
 *           if an invalid scope name is requested
 * @throws JspException
 *           if the specified bean is not found
 * @throws JspException
 *           if accessing this property causes an IllegalAccessException,
 *           IllegalArgumentException, InvocationTargetException, or NoSuchMethodException
 */
public static Object lookup(PageContext pageContext, String name, String property, String scope)
        throws JspException {

    // Look up the requested bean, and return if requested
    Object bean = lookup(pageContext, name, scope);

    if (bean == null) {
        if (scope == null) {
            throw new JspException("Could not find bean '" + name + "' in any scope.");
        } else {
            throw new JspException("Could not find bean '" + name + "' in scope '" + scope + "'.");
        }
    }

    if (property == null) {
        return bean;
    }

    // Locate and return the specified property
    try {
        return PropertyUtils.getProperty(bean, property);
    } catch (IllegalAccessException e) {
        throw new JspException(
                String.format("Invalid access looking up property '%s' of bean %s", property, name), e);
    } catch (IllegalArgumentException e) {
        throw new JspException(
                String.format("Invalid argument looking up property '%s' of bean %s", property, name), e);
    } catch (InvocationTargetException e) {
        throw new JspException(
                String.format("Exception thrown by getter for property '%s' of bean %s", property, name), e);
    } catch (NoSuchMethodException e) {

        throw new JspException(String.format("No getter method for property '%s' of bean %s", property, name),
                e);
    }

}

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

/**
 * Sets the filter used to filter list data
 * @param filterIn name of the filter class to use
 * @throws JspException error occurred creating an instance of the filter
 *//*from   w ww .  j  a  va2  s.com*/
public void setFilter(String filterIn) throws JspException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        Class klass = cl.loadClass(filterIn);
        filter = (ListFilter) klass.newInstance();
        Context threadContext = Context.getCurrentContext();
        filter.prepare(threadContext.getLocale());
    } catch (Exception e) {
        throw new JspException(e.getMessage());
    }
}

From source file:ch.entwine.weblounge.taglib.content.PagePreviewTag.java

/**
 * {@inheritDoc}//from   w w  w.j  a  v  a2s.com
 * 
 * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
 */
@Override
public int doStartTag() throws JspException {

    // Don't do work if not needed (which is the case during precompilation)
    if (RequestUtils.isPrecompileRequest(request))
        return SKIP_BODY;

    Site site = request.getSite();

    if (pageId == null) {
        PageListTag pageListTag = (PageListTag) findAncestorWithClass(this, PageListTag.class);
        if (pageListTag != null) {
            page = pageListTag.getPage();
            pagePreview = pageListTag.getPagePreview();
            pageUrl = pageListTag.getPageUrl();
        } else if (RequestUtils.isMockRequest(request)) {
            // Skip body, if this is a mock-request
            return SKIP_BODY;
        } else {
            throw new JspException("Page preview tag on " + request.getUrl()
                    + " requires either a page id or embedding inside a PageListTag");
        }
    } else {
        ContentRepository contentRepository = null;
        contentRepository = site.getContentRepository();
        if (contentRepository == null) {
            logger.debug("Content repository is offline");
            response.invalidate();
            return SKIP_BODY;
        }

        ResourceURI pageURI = new PageURIImpl(site, null, pageId);

        try {
            page = (Page) contentRepository.get(pageURI);
            if (page == null) {
                logger.error("No data available for page {}", pageURI);
                return EVAL_PAGE;
            }
        } catch (SecurityException e) {
            throw new JspException("Security exception while trying to load " + pageUrl, e);
        } catch (ContentRepositoryException e) {
            throw new JspException("Exception while trying to load " + pageUrl, e);
        }

        pageUrl = new WebUrlImpl(site, page.getURI().getPath());
        response.addTag(CacheTag.Url, pageUrl.getPath());
        response.addTag(CacheTag.Resource, page.getURI().getIdentifier());
    }

    PageTemplate template = site.getTemplate(page.getTemplate());
    if (template == null) {
        logger.error("No page template found for {}", page);
        return EVAL_PAGE;
    }
    template.setEnvironment(request.getEnvironment());

    String stage = template.getStage();
    if (stage == null) {
        logger.error("No stage defined for page template '{}' on {}", template, request.getUrl());
        return EVAL_PAGE;
    }

    // Read pagelets
    List<Pagelet> pagelets = new ArrayList<Pagelet>();
    switch (stopMarker) {
    case None:
        pagelets.addAll(Arrays.asList(page.getPagelets(stage)));
        break;
    case Elements:
        if (previewElements == null || previewElements.size() == 0)
            throw new IllegalStateException("No preview elements set");
        for (Pagelet p : page.getPagelets(stage)) {
            if (previewElements.contains(p.toString())) {
                pagelets.add(p);
            }
        }
        break;
    case Marker:
        if (StringUtils.isBlank(endOfPreviewElement))
            throw new IllegalStateException("No stop marker element set on " + request.getUrl());
        for (Pagelet p : page.getPagelets(stage)) {
            if (p.toString().equals(startOfPreviewElement)) {
                pagelets.clear();
                continue;
            } else if (p.toString().equals(endOfPreviewElement)) {
                break;
            }
            pagelets.add(p);
        }
        break;
    case Pagepreview:
        pagelets.addAll(Arrays.asList(page.getPreview()));
        break;
    default:
        throw new IllegalStateException(
                "Don't know how to handle stop marker '" + stopMarker + "' on " + request.getUrl());
    }

    if (pagelets.size() == 0)
        return SKIP_BODY;

    pagePreview = new ComposerImpl("preview", pagelets);

    // Store old page, composer and pagelet for later reference
    oldPage = request.getAttribute(WebloungeRequest.PAGE);
    oldComposer = request.getAttribute(WebloungeRequest.COMPOSER);
    oldPagelet = request.getAttribute(WebloungeRequest.PAGELET);

    // Define the current values in the page context
    request.setAttribute(PagePreviewTagVariables.URL, pageUrl);
    request.setAttribute(PagePreviewTagVariables.PAGE, page);
    request.setAttribute(PagePreviewTagVariables.PREVIEW, pagePreview);

    stashAttribute(PagePreviewTagVariables.PAGELET);
    stashAndSetAttribute(PagePreviewTagVariables.URL, pageUrl);
    stashAndSetAttribute(PagePreviewTagVariables.PREVIEW, pagePreview);

    // Add included page url to tags
    response.addTag(CacheTag.Url, pageUrl.getLink());

    // Adjust modification date
    response.setModificationDate(page.getLastModified());

    // Handle the first pagelet, we'll do the others
    pageletIndex = 0;
    handlePagelet(pageletIndex);

    return EVAL_BODY_INCLUDE;
}

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

/**
 *
 * @param f the filter to set/*  www  . j  ava 2s . com*/
 */
void setColumnFilter(ListFilter f) throws JspException {
    if (filter != null) {
        String msg = "Cannot set the column filter - [%s], "
                + "since the table has been has already assigned a filter - [%s]";

        throw new JspException(String.format(msg, String.valueOf(f), String.valueOf(filter)));
    }
    filter = f;
    Context threadContext = Context.getCurrentContext();
    filter.prepare(threadContext.getLocale());
    manip.filter(filter, pageContext);
}

From source file:edu.cornell.mannlib.vedit.tags.DynamicFieldsTag.java

public int doEndTag() throws JspException {
    try {//w ww . j  a  va  2 s . c o  m
        parseMarkup();
        JspWriter out = pageContext.getOut();
        HashMap values = null;
        try {
            FormObject foo = getFormObject();
            List<DynamicField> dynfs = foo.getDynamicFields();
            Iterator<DynamicField> dynIt = dynfs.iterator();
            int i = 9899;
            while (dynIt.hasNext()) {
                DynamicField dynf = dynIt.next();
                StringBuffer genTaName = new StringBuffer().append("_").append(dynf.getTable()).append("_");
                genTaName.append("-1").append("_");
                Iterator pparamIt = dynf.getRowTemplate().getParameterMap().keySet().iterator();
                while (pparamIt.hasNext()) {
                    String key = (String) pparamIt.next();
                    String value = (String) dynf.getRowTemplate().getParameterMap().get(key);
                    byte[] valueInBase64 = Base64.encodeBase64(value.getBytes());
                    genTaName.append(key).append(":").append(new String(valueInBase64)).append(";");
                }

                String preWithVars = new String(preMarkup);
                preWithVars = strReplace(preWithVars, type + "NN", Integer.toString(i));
                preWithVars = strReplace(preWithVars, "\\$genTaName", genTaName.toString());
                preWithVars = strReplace(preWithVars, "\\$fieldName", dynf.getName());

                out.print(preWithVars);

                Iterator<DynamicFieldRow> rowIt = dynf.getRowList().iterator();
                while (rowIt.hasNext()) {
                    ++i;
                    DynamicFieldRow row = rowIt.next();
                    if (row.getValue() == null)
                        row.setValue("");
                    if (row.getValue().length() > 0) {
                        StringBuffer taName = new StringBuffer().append("_").append(dynf.getTable())
                                .append("_");
                        taName.append(row.getId()).append("_");
                        Iterator paramIt = row.getParameterMap().keySet().iterator();
                        while (paramIt.hasNext()) {
                            String key = (String) paramIt.next();
                            String value = (String) row.getParameterMap().get(key);
                            byte[] valueInBase64 = Base64.encodeBase64(value.getBytes());
                            taName.append(key).append(":").append(new String(valueInBase64)).append(";");
                        }
                        if (row.getValue().length() > 0) {
                            String templateWithVars = new String(templateMarkup);
                            templateWithVars = strReplace(templateWithVars, type + "NN", Integer.toString(i));
                            templateWithVars = strReplace(templateWithVars, "\\$taName", taName.toString());
                            templateWithVars = strReplace(templateWithVars, "\\$\\$", row.getValue());
                            out.print(templateWithVars);
                        }
                    }
                }

                out.print(postMarkup);
            }
            // output the row template for the javascript to clone

            out.println("<!-- row template inserted by DynamicFieldsTag  -->");
            String hiddenTemplatePreMarkup = new String(preMarkup);
            // bit of a hack to hide the template from the user:
            hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "display\\:none\\;", "");
            hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "display\\:block\\;", "");
            hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "display\\:inline\\;", "");
            hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "style\\=\\\"",
                    "style=\"display:none;");
            out.print(hiddenTemplatePreMarkup);
            String hiddenTemplateTemplateMarkup = new String(templateMarkup);
            hiddenTemplateTemplateMarkup = strReplace(hiddenTemplateTemplateMarkup, "\\$\\$", "");
            out.print(hiddenTemplateTemplateMarkup);
            out.print(postMarkup);

        } catch (Exception e) {
            System.out.println("DynamicFieldsTag could not get the form object");
        }

    } catch (Exception ex) {
        throw new JspException(ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.OptionsTag.java

/**
 * Add an option element to the specified StringBuilder based on the
 * specified parameters./*from w w w  .j av a2 s . c  o  m*/
 * 
 * @param sb
 *            StringBuilder accumulating our results
 * @param value
 *            Value to be returned to the server for this option
 * @param label
 *            Value to be shown to the user for this option
 * @param matched
 *            Should this value be marked as selected?
 */
protected void addOption(StringBuilder sb, String value, String label, boolean matched) throws JspException {

    sb.append("<option value=\"");
    sb.append(value);
    sb.append("\"");
    if (matched) {
        sb.append(" selected=\"selected\"");
    }
    if (style != null) {
        sb.append(" style=\"");
        sb.append(style);
        sb.append("\"");
    }
    if (styleClass != null) {
        sb.append(" class=\"");
        sb.append(styleClass);
        sb.append("\"");
    }
    sb.append(">");

    /* acrescentado por Nanda & Tania */
    // String locale = Action.LOCALE_KEY;
    // String bundle = Action.MESSAGES_KEY;
    String key = label;

    // Retrieve the message string we are looking for
    String message = RequestUtils.message(pageContext, this.bundle, this.localeKey, key, null);

    if (message == null) {
        JspException e = new JspException(messages.getMessage("message.message", key));
        RequestUtils.saveException(pageContext, e);
        throw e;
    }
    label = message;
    /* ate aqui!! */

    sb.append(ResponseUtils.filter(label));
    sb.append("</option>\r\n");

}

From source file:de.laures.cewolf.taglib.tags.ChartMapTag.java

private String generateToolTip(Dataset dataset, ChartEntity ce) throws JspException {
    String tooltip = null;/*from  ww  w.j a  v a  2  s . c o  m*/
    if (useJFreeChartTooltipGenerator) {
        tooltip = ce.getToolTipText();
    } else if (toolTipGenerator instanceof CategoryToolTipGenerator
            || toolTipGenerator instanceof XYToolTipGenerator
            || toolTipGenerator instanceof PieToolTipGenerator) {
        if (toolTipGenerator instanceof CategoryToolTipGenerator) {
            if (ce instanceof CategoryItemEntity) {
                CategoryItemEntity catEnt = (CategoryItemEntity) ce;
                tooltip = ((CategoryToolTipGenerator) toolTipGenerator).generateToolTip(
                        (CategoryDataset) dataset, catEnt.getSeries(), catEnt.getCategoryIndex());
            }
        }

        if (toolTipGenerator instanceof XYToolTipGenerator) {
            if (ce instanceof XYItemEntity) {
                XYItemEntity xyEnt = (XYItemEntity) ce;
                tooltip = ((XYToolTipGenerator) toolTipGenerator).generateToolTip((XYDataset) dataset,
                        xyEnt.getSeriesIndex(), xyEnt.getItem());
            }
        }

        if (toolTipGenerator instanceof PieToolTipGenerator) {
            if (ce instanceof PieSectionEntity) {
                PieSectionEntity pieEnt = (PieSectionEntity) ce;
                PieDataset ds = (PieDataset) dataset;
                final int index = pieEnt.getSectionIndex();
                tooltip = ((PieToolTipGenerator) toolTipGenerator).generateToolTip(ds, ds.getKey(index), index);
            }
        }
    } else {
        // throw because category is unknown
        throw new JspException("TooltipgGenerator of class " + toolTipGenerator.getClass().getName()
                + " does not implement the appropriate TooltipGenerator interface for entity type "
                + ce.getClass().getName());
    }
    return tooltip;
}

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

public String getColumnStyleClass() throws JspException {

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

    ValueListConfigBean config = rootTag.getConfig();

    if (config == null) {
        throw new JspException("No config found on root tag");
    }//  w ww  .j a  v a2s  .com

    return config.getStylePrefix();
}

From source file:com.xhsoft.framework.common.page.MiniPageTag.java

/**
 * <p>Description:?</p>//from   w ww.j  a v  a 2  s .  co  m
 * @param pageNo   
 * @param request 
 * @param totalPages 
 * @return void
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
private void printOutBack(int pageNo, int totalPages, HttpServletRequest request) throws JspException {
    try {
        Integer nextPage = new Integer(pageNo == totalPages ? totalPages : pageNo + 1);
        String next = "";
        String last = "";
        JspWriter out = pageContext.getOut();
        String outString = "";

        if (pageNo == totalPages || totalPages == 0 || totalPages == 1) {
            outString = " "

                    + next + "&nbsp;&nbsp;" + " " + last + "&nbsp;&nbsp;";
        } else {
            outString = " " + "<a href=\"javascript:setPage('" + nextPage + "','" + targets + "');\">" + next
                    + "&nbsp;</a>&nbsp;" + "<a href=\"javascript:setPage('" + totalPages + "','" + targets
                    + "');\">" + last + "&nbsp;</a>&nbsp;";
        }

        out.print(outString);
    } catch (Exception e) {
        throw new JspException(e);
    }
}