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:ch.entwine.weblounge.test.site.GreeterTag.java

/**
 * {@inheritDoc}/*from   w ww.  ja va2 s  . co m*/
 * 
 * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
 */
public int doStartTag() throws JspException {
    try {
        Map<String, String> greetings = TestSiteUtils.loadGreetings();
        String greeting = null;
        if (language != null) {
            greeting = greetings.get(language);
            if (greeting == null)
                greeting = "Excuse me?";
        } else {
            String[] languages = greetings.keySet().toArray(new String[greetings.size()]);
            language = languages[(int) Math.random() * languages.length];
            greeting = greetings.get(language);
        }
        String encodedGreeting = StringEscapeUtils.escapeHtml(greeting);
        pageContext.getOut().print("<div id=\"greeting\">");
        pageContext.getOut().print(encodedGreeting);
        pageContext.getOut().println("</div>");
        pageContext.getOut().flush();
    } catch (IOException ioe) {
        throw new JspException("IOException while writing to client" + ioe.getMessage());
    }
    return SKIP_BODY;
}

From source file:eu.europa.ejusticeportal.dss.demo.web.tags.RequestUrlRelativeUrlTagStrategy.java

/**
 * Returns the actual URL to be written in the HTML page.
 *
 * @param tag/*from   ww  w  . ja v  a 2 s. c  o m*/
 *            the URL tag for which the URL is computed
 * @return the actual URL to be written in the HTML page
 * @throws JspException
 *             if no request url is found as a request attribute
 */
@Override
public String resolveURL(UrlTag tag) throws JspException {
    final HttpServletRequest req = (HttpServletRequest) tag.getPageContext().getRequest();
    final String reqUrl = getContextRootRelativeRequestURL(req);
    if (reqUrl == null) {

        throw new JspException(UrlTag.class.getName() + " can only be used if  RequestFilter "
                + "is defined as servlet filter");
    }

    if (!tag.getValue().startsWith("/")) {
        throw new JspException("UrlTag value must be absolute to the context root and start with a /. Was '"
                + tag.getValue() + "'");
    }
    String outputUrl = computeURL(tag);
    outputUrl = addQueryString(outputUrl, tag);
    return outputUrl;
}

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

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

    String value = getExpression();
    if (StringUtils.isBlank(value)) {
        return SKIP_BODY;
    }//from ww w  . jav a 2  s  . co m

    Class<T> clazz = getEnumClass();
    if (clazz == null) {
        return SKIP_BODY;
    }

    try {
        LocalizedEnum<?> val = LocalizedEnum.parseString(value, getMessageSource(), clazz);
        jspWriter.append(val.getLabel());
    } catch (IOException ex) {
        throw new JspException(ex);
    }

    return SKIP_BODY;
}

From source file:com.steeleforge.aem.ironsites.wcm.taglib.SetModeTag.java

@Override
public int doStartTag() throws JspException {
    try {//w  ww  .  j  av a  2  s .c om
        if (StringUtils.isBlank(getMode())) {
            return EVAL_BODY_BUFFERED;
        }
        this.wcmmode = WCMMode.fromRequest(WCMUtil.getSlingRequest(pageContext));
        for (WCMMode candidate : WCMMode.values()) {
            if (StringUtils.equalsIgnoreCase(getMode(), candidate.toString())) {
                candidate.toRequest(WCMUtil.getSlingRequest(pageContext));
                break;
            }
        }
    } catch (RuntimeException re) {
        LOG.debug(re.getMessage());
        throw new JspException(re);
    }
    return EVAL_BODY_BUFFERED;
}

From source file:com.steeleforge.aem.ironsites.xss.taglib.XSSFilterHTMLTag.java

@Override
public int doAfterBody() throws JspException {
    BodyContent bodyContent;//from  w  w w .j av a 2 s.c  o  m
    String body;
    JspWriter out;
    try {
        bodyContent = getBodyContent();
        out = bodyContent.getEnclosingWriter();
        body = XSSUtil.filterHTML(getPolicy(), getContext(), bodyContent.getString(), pageContext);
        if (StringUtils.isNotEmpty(body)) {
            out.print(body);
        }
    } catch (IOException ioe) {
        LOG.debug(ioe.getMessage());
        throw new JspException(ioe);
    } finally {
        bodyContent = null;
        body = null;
        out = null;
    }
    return SKIP_BODY;
}

From source file:ams.fwk.customtag.AmsExcelExportTag.java

/**
 * @return int//from w  w  w  .  ja v  a2s .  co  m
 * @throws JspException
 */
public int doEndTag() throws JspException {
    try {
        JspWriter out = pageContext.getOut();
        out.print(listOpen);
        StringBuffer sb = new StringBuffer();
        sb.append(StringUtils.replace(excelTxTag, "$transactionId$", transactionId));
        sb.append(excelResTag);
        sb.append(StringUtils.replace(exportFileInfoTag, "$exportFileName$", exportFileName));

        out.print(sb.toString());

        out.print(listClose);

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

    }
}

From source file:com.geemvc.taglib.form.LabelTagSupport.java

@Override
protected void appendTagAttributes(JspWriter writer) throws JspException {
    try {//from   w ww  .  j a  v a2 s . co  m
        String forValue = (String) dynamicAttributes.get("for");

        if (forValue == null) {
            String name = getName();
            Object value = getValue();

            if (name != null)
                forValue = toElementId(name, value == null ? null : String.valueOf(value));
        }

        if (!Str.isEmpty(forValue)) {
            // Id attribute.
            writer.write(Char.SPACE);
            writer.write("for");
            writer.write(Char.EQUALS);
            writer.write(Char.DOUBLE_QUOTE);
            writer.write(forValue);
            writer.write(Char.DOUBLE_QUOTE);
        }

        String classValue = (String) dynamicAttributes.get("class");

        if (!Str.isEmpty(classValue)) {
            writer.write(Char.SPACE);
            writer.write("class");
            writer.write(Char.EQUALS);
            writer.write(Char.DOUBLE_QUOTE);
            writer.write(classValue);
            writer.write(Char.DOUBLE_QUOTE);
        }

    } catch (Throwable t) {
        throw new JspException(t);
    }
}

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

/**
 * {@inheritDoc}//from   w w w  .  j ava  2s  .  c o  m
 */
public int doEndTag() throws JspException {
    JspWriter writer = pageContext.getOut();
    try {
        writer.write("</p>");
    } catch (IOException e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}

From source file:net.solarnetwork.node.setup.web.support.MessageTag.java

@Override
public int doEndTag() throws JspException {
    String msg = null;//from w  w w.  jav  a 2 s  .  c om
    if (messageSource != null && key != null) {
        Locale locale = this.pageContext.getRequest().getLocale();
        try {
            msg = this.messageSource.getMessage(this.key, null, locale);
        } catch (NoSuchMessageException e) {
            // ignore
        }
    }
    if (msg == null) {
        if (text != null) {
            msg = text;
        } else {
            msg = "???" + this.key + "???";
        }
    }
    if (msg != null && msg.length() > 0) {
        try {
            pageContext.getOut().write(msg);
        } catch (IOException e) {
            throw new JspException(e);
        }
    }
    return EVAL_PAGE;
}

From source file:com.googlecode.jtiger.modules.ecside.tag.MappingTag.java

public int doStartTag() throws JspException {
    try {/*from   www .jav  a2  s.c o  m*/

        Object propertyValue = getValue();

        if (propertyValue != null) {
            propertyValue = ExpressionEvaluatorManager.evaluate("result", propertyValue.toString(),
                    Object.class, this, pageContext);
        }

        if (mappingItem != null) {
            Object mappingMap = pageContext.findAttribute((String) mappingItem);

            Object outValue = null;
            if (mappingMap instanceof Map) {
                Map itemsMap = (Map) mappingMap;
                outValue = itemsMap.get(propertyValue);
                if (outValue == null && mappingDefaultKey != null) {
                    outValue = itemsMap.get(mappingDefaultKey);
                }
            }
            if (outValue == null) {
                outValue = mappingDefaultValue;
            }
            propertyValue = outValue;
        }

        JspWriter w = pageContext.getOut();
        if (propertyValue == null || (propertyValue != null && propertyValue instanceof String
                && StringUtils.isBlank((String) propertyValue))) {
            w.write("");
        } else {
            w.write((String) propertyValue);
        }

    } catch (Exception e) {
        throw new JspException("MappingTag.doStartTag() Problem: " + ExceptionUtils.formatStackTrace(e));
    }

    return SKIP_BODY;
}