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.sf.ginp.tags.Translate.java

/**
 *  Called when a Start tag is processed.
 *
 *@return                   Description of the Return Value
 *@exception  JspException  Description of the Exception
 *//* w  w  w. java  2 s  . com*/
public final int doStartTag() throws JspException {
    String message = code;

    try {
        model = ModelUtil.getModel((HttpServletRequest) pageContext.getRequest());
    } catch (Exception e) {
        log.error(e);
        throw new JspException(e);
    }

    try {
        message = model.translate(code);

        // Make sure we return some text.
        if (message == null) {
            message = code;
        }
    } catch (Exception ex) {
        log.error("Error translating Code: " + code, ex);
        message = code;
    }

    // write out to page.
    try {
        pageContext.getOut().write(message);
    } catch (IOException ioe) {
        log.error(ioe);
        throw new JspException(ioe.getMessage());
    }

    return SKIP_BODY;
}

From source file:net.sourceforge.ajaxtags.tags.AjaxTabPanelTag.java

@Override
public int doEndTag() throws JspException {
    // check for tabs presence
    if (pages.isEmpty()) {
        throw new JspException("No tabs added to tab panel.");
    }//from  ww  w.  j  a  va 2s . c o m

    // wrapper
    final HTMLDivElement tabPanel = new HTMLDivElement(getId());
    tabPanel.setClassName(getStyleClass() == null ? "tabPanel" : getStyleClass() + " tabPanel");

    HTMLDivElement tabNavigation = new HTMLDivElement();
    tabNavigation.setClassName("tabNavigation");

    HTMLUListElement ul = new HTMLUListElement();
    ul.setBody(getListItems());

    tabPanel.append(tabNavigation.append(ul));

    tabPanel.append(buildScript());

    out(tabPanel);
    return EVAL_PAGE;
}

From source file:com.redhat.rhn.frontend.configuration.tags.ConfigFileTag.java

/**
 * {@inheritDoc}//from   w  w w. j  av a  2 s. c o m
 */
@Override
public int doEndTag() throws JspException {
    StringBuilder result = new StringBuilder();
    if (nolink || id == null) {
        result.append(writeIcon());
        result.append(StringEscapeUtils.escapeXml(path));
    } else {
        String url;
        if (revisionId != null) {
            url = makeConfigFileRevisionUrl(id, revisionId);
        } else {
            url = makeConfigFileUrl(id);
        }

        result.append("<a href=\"" + url + "\">");
        result.append(writeIcon());
        result.append(StringEscapeUtils.escapeXml(path) + "</a>");
    }
    JspWriter writer = pageContext.getOut();
    try {
        writer.write(result.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }
    return BodyTagSupport.SKIP_BODY;
}

From source file:com.draagon.meta.web.tag.MetaObjectTag.java

public int doStartTag() throws JspException {
    try {//  w  w w  . j av  a  2  s . co  m
        Object o = pageContext.getRequest().getAttribute(getName());
        if (o == null)
            return Tag.SKIP_BODY;

        //log.debug( "(doStartTag) Meta Object found with id [" + mo.getId() + "]" );

        MetaObject mc = MetaDataLoader.findMetaObject(o);

        if (mc == null) {
            log.error("Cannot find MetaClass for object [" + o + "]");
            return Tag.SKIP_BODY;
        }

        MetaField mf = mc.getMetaField(getField());
        if (mf == null) {
            log.error("Cannot find MetaField for MetaClass [" + mc + "] with name [" + getField() + "]");
            return Tag.SKIP_BODY;
        }

        String val = mf.getString(o);

        if (getVar() == null) {
            JspWriter out = pageContext.getOut();
            if (val != null)
                out.print(val);
        } else {
            pageContext.setAttribute(getVar(), val, PageContext.PAGE_SCOPE);
        }
    } catch (Exception e) {
        log.error("Error processing Meta Object Tag [name:" + getName() + ", field:" + getField() + "]", e);
        throw new JspException(
                "Error processing Meta Object Tag [name:" + getName() + ", field:" + getField() + "]: " + e);
    }

    return Tag.SKIP_BODY;
}

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

public int doEndTag() throws JspException {
    try {//from  ww  w  .  j  a v  a  2  s .  c  o  m
        JspWriter out = pageContext.getOut();

        List optList = null;
        ListOrderedMap optGroups = null;

        try {
            optList = (List) getFormObject().getOptionLists().get(name);
            outputOptionsMarkup(optList, out);
        } catch (ClassCastException e) {
            // maybe it's a ListOrderedMap of optgroups
            optGroups = (ListOrderedMap) getFormObject().getOptionLists().get(name);
            OrderedMapIterator ogKey = optGroups.orderedMapIterator();
            while (ogKey.hasNext()) {
                String optGroupName = (String) ogKey.next();
                out.println("<optgroup label=\"" + StringEscapeUtils.escapeHtml(optGroupName) + "\">");
                outputOptionsMarkup((List) optGroups.get(optGroupName), out);
                out.println("</optgroup>");
            }
        } catch (NullPointerException npe) {
            System.out.println("OptionTag could not find option list for " + name);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new JspException(ex.getMessage());
    }
    return SKIP_BODY; // EVAL_PAGE; did colnames only //EVAL_PAGE in connection pooled version;
}

From source file:de.micromata.genome.gwiki.web.tags.GWikiHtmlOptionsCollectionTag.java

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Iterator<?> getIterator(Object collection) throws JspException {
    Class<?> clcls = collection.getClass();
    if (clcls.isArray()) {
        collection = Arrays.asList((Object[]) collection);
    }/*from w w  w .  j  a  v  a2  s  .co  m*/

    if (collection instanceof Collection) {
        return (((Collection<?>) collection).iterator());

    } else if (collection instanceof Iterator) {
        return ((Iterator<?>) collection);

    } else if (collection instanceof Map) {
        return (((Map<?, ?>) collection).entrySet().iterator());

    } else if (collection instanceof Enumeration) {
        return new EnumerationIterator((Enumeration<?>) collection);

    } else {
        throw new JspException("form." + property + " does not return a valid collection");
    }
}

From source file:com.googlecode.psiprobe.jsp.VisualScoreTag.java

public int doAfterBody() throws JspException {
    BodyContent bc = getBodyContent();/*from   w ww  .j a  v a2s  .c o  m*/
    String body = bc.getString().trim();

    StringBuffer buf = calculateSuffix(body);

    try {
        JspWriter out = bc.getEnclosingWriter();
        out.print(buf.toString());
    } catch (IOException ioe) {
        throw new JspException("Error:IOException while writing to client" + ioe.getMessage());
    }

    return SKIP_BODY;
}

From source file:com.lazyloading.tag.handler.LazyHandler.java

/**
 * Default request handler of the Ajax requests made by the Lazy Loading table
 * Change the Enc/Dec secret key in production environment
 * /*from www . j a  va  2 s. c o m*/
 * @param json    Request parameters which keep track of Lazy Loading table
 * @param request HttpServletRequest 
 * @param response HttpServletResponse
 * @return List<?> List of ? Objects
 * @throws Exception
 */
@RequestMapping(value = "/lazyLoading.htm")
public @ResponseBody List<?> lazyLoading(@RequestBody String json, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {

        Gson gson = new GsonBuilder().create();

        Template template = gson.fromJson(json, Template.class);
        if (template.getGetPage() == null)
            throw new JspException("Reuested page no cannot be null");

        Long requestedPage = template.getGetPage();
        Long end = new Long(template.getGetPage()) * new Long(template.getRecordsPerPage());
        Long begin = end - new Long(template.getRecordsPerPage());

        //DECRYPT THE REQUESTED ATTRS. Change the Secret key in production deployment
        String decryptedReqyestAttr = EncDec.decrypt("L!A@Z#Y$L%O^A*D(I)N_G", template.getRequestAttr());

        //CONVERT REUEST ATTRIBUTES IN HASHMAP
        HashMap<String, String> requestMap = new HashMap<String, String>();
        try {
            for (String keyVal : decryptedReqyestAttr.split(",")) {
                String[] split = keyVal.split("=");
                if (split.length > 1) {
                    split[1] = split[1].equals("null") ? null : split[1];

                    requestMap.put(split[0], split[1]);
                } else {
                    requestMap.put(split[0], null);
                }

            }
        } catch (Exception e) {
            throw new JspException("ERROR: lazyLoading 'requestAttrs' should be in attribute=value pair");
        }

        List<?> requestedList = new ArrayList();
        requestedList = LazyLoading.lazyLoadData(begin, end, template.getModelClass(), request, requestMap);

        List<Object> paginatedList = new ArrayList<Object>();

        Long indexCounter = 0L;
        try {

            for (Object obj : requestedList) {

                Method lazyMethod = obj.getClass().getMethod("setLazyPageNo", Long.class);
                lazyMethod.invoke(obj, new Long(template.getGetPage()));

                //Searchable page numbers helps Angular Filter to paginate records
                //records are coupled with commas to differentiate between 1, 11, 2, 22, 23 ... so on
                lazyMethod = obj.getClass().getMethod("setSearchablePageNo", String.class);
                lazyMethod.invoke(obj, "," + template.getGetPage() + ",");

                //CALCLCULATE INDEX
                Long index = (template.getGetPage() - 1) * new Long(template.getRecordsPerPage())
                        + indexCounter;
                indexCounter++;

                lazyMethod = obj.getClass().getMethod("set$index", Long.class);
                lazyMethod.invoke(obj, index);

                paginatedList.add(obj);

            }

        } catch (NullPointerException e) {
            throw new JspException("ERROR: Lazy loading. The load method returned null as a list.");
        }

        return (paginatedList);

    } catch (Exception e) {
        throw new Exception(e);
    }
}

From source file:com.trenako.web.tags.BreadcrumbTags.java

@Override
protected int writeTagContent(JspWriter out, String contextPath) throws JspException {

    if (getCriteria().isEmpty()) {
        return Tag.SKIP_BODY;
    }//  w  ww  . j av  a2  s. co  m

    try {
        List<HtmlTag> items = new ArrayList<HtmlTag>();
        for (Criteria crit : getCriteria().criteria()) {
            addElement(items, contextPath, crit);
        }

        HtmlTag list = ul(tags(items)).cssClass("breadcrumb");
        out.println(list.toString());

    } catch (IOException e) {
        throw new JspException(e);
    }

    return Tag.SKIP_BODY;
}

From source file:net.sf.ginp.tags.Link.java

/**
 *  Called when a Start tag is processed.
 *
 *@return                   Description of the Return Value
 *@exception  JspException  Description of the Exception
 *///from  w w  w.ja va  2s .c o  m
public final int doStartTag() throws JspException {
    try {
        Random rnd = new Random();

        if (url.indexOf("?") == -1) {
            pageContext.getOut().write(url + "?nocache=" + rnd.nextInt(999999999));
        } else {
            pageContext.getOut().write(url + "&nocache=" + rnd.nextInt(999999999));
        }
    } catch (IOException ioe) {
        log.error(ioe);
        throw new JspException(ioe.getMessage());
    }

    return EVAL_BODY_INCLUDE;
}