Search in sources :

Example 6 with JspTagException

use of javax.servlet.jsp.JspTagException in project grails-core by grails.

the class JspInvokeGrailsTagLibTag method doAfterBody.

@Override
public int doAfterBody() throws JspException {
    BodyContent b = getBodyContent();
    if (invocationCount > 0) {
        if (b != null) {
            jspWriter = b.getEnclosingWriter();
            invocationBodyContent.add(b.getString());
            bodyInvokation = true;
            b.clearBody();
        }
    }
    invocationCount--;
    setCurrentArgument();
    if (invocationCount < 1) {
        tagContent = sw.toString();
        int i = 1;
        StringBuilder buf = new StringBuilder();
        for (String body : invocationBodyContent) {
            String replaceFlag = "<jsp-body-gen" + i + ">";
            int j = tagContent.indexOf(replaceFlag);
            if (j > -1) {
                buf.append(tagContent.substring(0, j)).append(body).append(tagContent.substring(j + replaceFlag.length(), tagContent.length()));
                tagContent = buf.toString();
                if (tagContent != null) {
                    try {
                        jspWriter.write(tagContent);
                        out.close();
                    } catch (IOException e) {
                        throw new JspTagException("I/O error writing tag contents [" + tagContent + "] to response out");
                    }
                }
                buf.delete(0, buf.length());
            }
        }
        return SKIP_BODY;
    }
    return EVAL_BODY_BUFFERED;
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) IOException(java.io.IOException) JspTagException(javax.servlet.jsp.JspTagException)

Example 7 with JspTagException

use of javax.servlet.jsp.JspTagException in project libresonic by Libresonic.

the class FormatBytesTag method doEndTag.

public int doEndTag() throws JspException {
    Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest());
    String result = StringUtil.formatBytes(bytes, locale);
    try {
        pageContext.getOut().print(result);
    } catch (IOException x) {
        throw new JspTagException(x);
    }
    return EVAL_PAGE;
}
Also used : Locale(java.util.Locale) IOException(java.io.IOException) JspTagException(javax.servlet.jsp.JspTagException)

Example 8 with JspTagException

use of javax.servlet.jsp.JspTagException in project libresonic by Libresonic.

the class UrlTag method formatUrl.

private String formatUrl() throws JspException {
    String baseUrl = UrlSupport.resolveUrl(value, null, pageContext);
    StringBuffer result = new StringBuffer();
    result.append(baseUrl);
    if (!parameters.isEmpty()) {
        result.append('?');
        for (int i = 0; i < parameters.size(); i++) {
            Parameter parameter = parameters.get(i);
            try {
                result.append(parameter.getName());
                if (isUtf8Hex() && !isAsciiAlphaNumeric(parameter.getValue())) {
                    result.append(ParameterDecodingFilter.PARAM_SUFFIX);
                }
                result.append('=');
                if (parameter.getValue() != null) {
                    result.append(encode(parameter.getValue()));
                }
                if (i < parameters.size() - 1) {
                    result.append("&");
                }
            } catch (UnsupportedEncodingException x) {
                throw new JspTagException(x);
            }
        }
    }
    return result.toString();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) JspTagException(javax.servlet.jsp.JspTagException)

Example 9 with JspTagException

use of javax.servlet.jsp.JspTagException in project sling by apache.

the class AbstractDispatcherTagHandler method doEndTag.

/**
     * Called after the body has been processed.
     *
     * @return whether additional evaluations of the body are desired
     */
public int doEndTag() throws JspException {
    log.debug("AbstractDispatcherTagHandler.doEndTag");
    final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
    // set request dispatcher options according to tag attributes. This
    // depends on the implementation, that using a "null" argument
    // has no effect
    final RequestDispatcherOptions opts = new RequestDispatcherOptions();
    opts.setForceResourceType(resourceType);
    opts.setReplaceSelectors(replaceSelectors);
    opts.setAddSelectors(addSelectors);
    opts.setReplaceSuffix(replaceSuffix);
    // ensure the path (if set) is absolute and normalized
    if (path != null) {
        if (!path.startsWith("/")) {
            path = request.getResource().getPath() + "/" + path;
        }
        path = ResourceUtil.normalize(path);
    }
    // check the resource
    if (resource == null) {
        if (path == null) {
            // neither resource nor path is defined, use current resource
            resource = request.getResource();
        } else {
            // check whether the path (would) resolve, else SyntheticRes.
            Resource tmp = request.getResourceResolver().resolve(path);
            if (tmp == null && resourceType != null) {
                resource = new DispatcherSyntheticResource(request.getResourceResolver(), path, resourceType);
                // remove resource type overwrite as synthetic resource
                // is correctly typed as requested
                opts.remove(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE);
            }
        }
    }
    try {
        // create a dispatcher for the resource or path
        RequestDispatcher dispatcher;
        if (resource != null) {
            dispatcher = request.getRequestDispatcher(resource, opts);
        } else {
            dispatcher = request.getRequestDispatcher(path, opts);
        }
        if (dispatcher != null) {
            SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(pageContext);
            dispatch(dispatcher, request, response);
        } else {
            TagUtil.log(log, pageContext, "No content to include...", null);
        }
    } catch (final JspTagException jte) {
        throw jte;
    } catch (final IOException ioe) {
        throw new JspTagException(ioe);
    } catch (final ServletException ce) {
        throw new JspTagException(TagUtil.getRootCause(ce));
    }
    return EVAL_PAGE;
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) ServletException(javax.servlet.ServletException) JspSlingHttpServletResponseWrapper(org.apache.sling.scripting.jsp.util.JspSlingHttpServletResponseWrapper) RequestDispatcherOptions(org.apache.sling.api.request.RequestDispatcherOptions) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) IOException(java.io.IOException) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) JspTagException(javax.servlet.jsp.JspTagException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 10 with JspTagException

use of javax.servlet.jsp.JspTagException in project spring-framework by spring-projects.

the class BindTag method doStartTagInternal.

@Override
protected final int doStartTagInternal() throws Exception {
    String resolvedPath = getPath();
    if (!isIgnoreNestedPath()) {
        String nestedPath = (String) pageContext.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
        // only prepend if not already an absolute path
        if (nestedPath != null && !resolvedPath.startsWith(nestedPath) && !resolvedPath.equals(nestedPath.substring(0, nestedPath.length() - 1))) {
            resolvedPath = nestedPath + resolvedPath;
        }
    }
    try {
        this.status = new BindStatus(getRequestContext(), resolvedPath, isHtmlEscape());
    } catch (IllegalStateException ex) {
        throw new JspTagException(ex.getMessage());
    }
    // Save previous status values, for re-exposure at the end of this tag.
    this.previousPageStatus = pageContext.getAttribute(STATUS_VARIABLE_NAME, PageContext.PAGE_SCOPE);
    this.previousRequestStatus = pageContext.getAttribute(STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    // Expose this tag's status object as PageContext attribute,
    // making it available for JSP EL.
    pageContext.removeAttribute(STATUS_VARIABLE_NAME, PageContext.PAGE_SCOPE);
    pageContext.setAttribute(STATUS_VARIABLE_NAME, this.status, PageContext.REQUEST_SCOPE);
    return EVAL_BODY_INCLUDE;
}
Also used : BindStatus(org.springframework.web.servlet.support.BindStatus) JspTagException(javax.servlet.jsp.JspTagException)

Aggregations

JspTagException (javax.servlet.jsp.JspTagException)12 IOException (java.io.IOException)8 JspException (javax.servlet.jsp.JspException)2 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Locale (java.util.Locale)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletException (javax.servlet.ServletException)1 JspWriter (javax.servlet.jsp.JspWriter)1 BodyContent (javax.servlet.jsp.tagext.BodyContent)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)1 Resource (org.apache.sling.api.resource.Resource)1 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)1 JspSlingHttpServletResponseWrapper (org.apache.sling.scripting.jsp.util.JspSlingHttpServletResponseWrapper)1 NoSuchMessageException (org.springframework.context.NoSuchMessageException)1 BindStatus (org.springframework.web.servlet.support.BindStatus)1