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

Source Link

Document

Construct a JspException.

Usage

From source file:jp.terasoluna.fw.web.taglib.TagUtil.java

/**
 * ?XR?[vvXR?[v?p?B//from  w  w  w.j ava  2 s  . c  om
 * vXR?[v???O??B
 * 
 * @param scopeName ?XR?[v
 * @return XR?[v?
 * @throws JspException vXR?[v???
 */
public static int getScope(String scopeName) throws JspException {

    if (scopeName == null) {
        throw new JspException();
    }

    Integer scope = SCOPES.get(scopeName.toLowerCase());

    if (scope == null) {
        throw new JspException();
    }

    return scope.intValue();
}

From source file:jp.terasoluna.fw.web.taglib.TagUtil.java

/**
 * wBean?ABean?/*from  w w w. ja va2  s  . c  o  m*/
 * wv?peBl?B
 * ?v?peBNull??Beanp?B
 * Bean???AO??B
 *  
 * @param pageContext y?[WReLXg
 * @param name Bean
 * @param property Beanv?peB
 * @param scopeName BeanXR?[v
 * @return Bean
 * @throws JspException vXR?[v???,
 * wBean???
 */
public static Object lookup(PageContext pageContext, String name, String property, String scopeName)
        throws JspException {

    //wBean?B
    Object bean = lookup(pageContext, name, scopeName);

    //BeanNull??O?B
    if (bean == null) {
        throw new JspException();
    }

    //v?peBw???ABeanp?B
    if (property == null) {
        return bean;
    }

    //Beanwv?peBl?B
    //OJspExceptionbv?B
    try {
        return PropertyUtils.getProperty(bean, property);

    } catch (IllegalAccessException e) {
        throw new JspException(e);
    } catch (IllegalArgumentException e) {
        throw new JspException(e);
    } catch (InvocationTargetException e) {
        throw new JspException(e);
    } catch (NoSuchMethodException e) {
        throw new JspException(e);
    }

}

From source file:egovframework.rte.ptl.mvc.tags.ui.PaginationTag.java

public int doEndTag() throws JspException {

    try {/*  w  w w .j ava 2s.co m*/

        JspWriter out = pageContext.getOut();

        PaginationManager paginationManager;

        // WebApplicationContext? id 'paginationManager' ??  Manager .
        WebApplicationContext ctx = RequestContextUtils.getWebApplicationContext(pageContext.getRequest(),
                pageContext.getServletContext());

        if (ctx.containsBean("paginationManager")) {
            paginationManager = (PaginationManager) ctx.getBean("paginationManager");
        } else {
            //bean ?  DefaultPaginationManager . ?   ?? ? ??  .
            paginationManager = new DefaultPaginationManager();
        }

        PaginationRenderer paginationRenderer = paginationManager.getRendererType(type);

        String contents = paginationRenderer.renderPagination(paginationInfo, jsFunction);

        out.println(contents);

        return EVAL_PAGE;

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

From source file:ch.entwine.weblounge.taglib.resource.ResourceTag.java

/**
 * {@inheritDoc}/*from   w  w w.j  av  a  2 s.  c  om*/
 * 
 * @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();

    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
        logger.debug("Unable to load content repository for site '{}'", site);
        response.invalidate();
        throw new JspException();
    }

    // Create the resource uri, either from the id or the path. If none is
    // specified, and we are not in jsp compilation mode, issue a warning
    ResourceURI uri = null;
    if (StringUtils.isNotBlank(resourceId)) {
        uri = new GeneralResourceURIImpl(site, null, resourceId);
    } else if (StringUtils.isNotBlank(resourcePath)) {
        uri = new GeneralResourceURIImpl(site, resourcePath);
    } else {
        logger.warn("Neither uuid nor path were specified for resource on {}", request.getUrl());
        return SKIP_BODY;
    }

    // Try to load the resource from the content repository
    try {
        if (!repository.exists(uri)) {
            logger.warn("Non existing resource {} requested on {}", uri, request.getUrl());
            return SKIP_BODY;
        }
    } catch (ContentRepositoryException e) {
        logger.error("Error trying to look up resource {} from {}", resourceId, repository);
        return SKIP_BODY;
    }

    Resource<?> resource = null;
    ResourceContent resourceContent = null;

    // Try to determine the language
    Language language = request.getLanguage();

    // Store the result in the jsp page context
    try {
        resource = repository.get(uri);
        resource.switchTo(language);

        Language contentLanguage = null;
        contentLanguage = LanguageUtils.getPreferredContentLanguage(resource, request, site);
        if (contentLanguage == null) {
            logger.warn("Resource {} does not have suitable content", resource);
            return SKIP_BODY;
        }

        resourceContent = resource.getContent(contentLanguage);
        if (resourceContent == null)
            resourceContent = resource.getOriginalContent();
    } catch (ContentRepositoryException e) {
        logger.warn("Error trying to load resource {}: {}", uri, e.getMessage());
        return SKIP_BODY;
    }

    // TODO: Check the permissions

    // Store the resource and the resource content in the request
    stashAndSetAttribute(ResourceTagExtraInfo.RESOURCE, resource);
    stashAndSetAttribute(ResourceTagExtraInfo.RESOURCE_CONTENT, resourceContent);

    // Add cache tags to the response
    response.addTag(CacheTag.Resource, resource.getURI().getIdentifier());
    response.addTag(CacheTag.Url, resource.getURI().getPath());

    return EVAL_BODY_INCLUDE;
}

From source file:org.terasoluna.gfw.web.token.transaction.TransactionTokenTagTest.java

/**
 * JspException occurs/*w ww  .j av a2s . com*/
 */
@Test
public void testWriteTagContentTagWriter03() {

    // setup arguments
    TransactionTokenTag tag = new TransactionTokenTag();
    PageContext pageContext = mock(PageContext.class);
    tag.setPageContext(pageContext);
    HttpServletRequest request = mock(HttpServletRequest.class);
    TransactionToken token = new TransactionToken("tokenName", "tokenkey", "tokenValue");
    TagWriter tagWriter = mock(TagWriter.class);

    // mock behavior
    when((HttpServletRequest) pageContext.getRequest()).thenReturn(request);
    when((TransactionToken) request.getAttribute(TransactionTokenInterceptor.NEXT_TOKEN_REQUEST_ATTRIBUTE_NAME))
            .thenReturn(token);

    // run
    int result = 1;
    try {
        doThrow(new JspException()).when(tagWriter).startTag(anyString());
        result = tag.writeTagContent(tagWriter);
    } catch (JspException e) {
        e.printStackTrace();
    }
    assertThat(result, is(1));
}

From source file:ch.entwine.weblounge.taglib.resource.ImageResourceTag.java

/**
 * {@inheritDoc}// w w  w .j a  va 2 s . 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();

    ContentRepository repository = site.getContentRepository();
    if (repository == null) {
        logger.debug("Unable to load content repository for site '{}'", site);
        response.invalidate();
        throw new JspException();
    }

    // Create the image uri, either from the id or the path. If none is
    // specified, and we are not in jsp compilation mode, issue a warning
    ResourceURI uri = null;
    if (StringUtils.isNotBlank(imageId))
        uri = new ImageResourceURIImpl(site, null, imageId);
    if (uri == null && StringUtils.isNotBlank(imagePath))
        uri = new ImageResourceURIImpl(site, imagePath, null);
    if (uri == null && imageSubjects != null && imageSubjects.size() > 0) {
        SearchQuery query = new SearchQueryImpl(site);
        query.withVersion(Resource.LIVE);
        query.withTypes(ImageResource.TYPE);
        query.withSubjects(SearchQuery.Quantifier.All, imageSubjects.toArray(new String[imageSubjects.size()]));
        SearchResult result;
        try {
            result = repository.find(query);
        } catch (ContentRepositoryException e) {
            logger.warn("Error searching for image with given subjects ({}): {}",
                    StringUtils.join(imageSubjects, ", "), e.getMessage());
            return SKIP_BODY;
        }
        if (result.getHitCount() > 1)
            logger.warn("Search returned {} images for subjects '{}' on {}", new Object[] {
                    result.getHitCount(), StringUtils.join(imageSubjects, ", "), request.getUrl() });
        if (result.getHitCount() > 0)
            uri = new ImageResourceURIImpl(site, null, result.getItems()[0].getId());
    }
    if (uri == null && StringUtils.isNotBlank(altImageId))
        uri = new ImageResourceURIImpl(site, null, altImageId);
    if (uri == null && StringUtils.isNotBlank(altImagePath))
        uri = new ImageResourceURIImpl(site, altImagePath, null);
    if (uri == null) {
        logger.debug("None of the several possibilities returned a valid image on {}", request.getUrl());
        return SKIP_BODY;
    }

    // Try to load the image from the content repository
    try {
        if (!repository.exists(uri)) {
            logger.warn("Non existing image {} requested on {}", uri, request.getUrl());
            return SKIP_BODY;
        }
    } catch (ContentRepositoryException e) {
        logger.error("Error trying to look up image {} from {}", imageId, repository);
        return SKIP_BODY;
    }

    ImageResource image = null;
    ImageContent imageContent = null;
    ImageStyle style = null;
    String linkToImage = null;
    int imageWidth = 0;
    int imageHeight = 0;

    // Try to determine the language
    Language language = request.getLanguage();

    // Load the content
    try {
        image = (ImageResource) repository.get(uri);
        if (image == null) {
            logger.warn("Non existing image {} requested on {}", uri, request.getUrl());
            return SKIP_BODY;
        }
        image.switchTo(language);

        Language contentLanguage = null;
        contentLanguage = LanguageUtils.getPreferredContentLanguage(image, request, site);
        if (contentLanguage == null) {
            logger.warn("Image {} does not have suitable content", image);
            return SKIP_BODY;
        }

        imageContent = image.getContent(contentLanguage);
        if (imageContent == null)
            imageContent = image.getOriginalContent();
        imageWidth = imageContent.getWidth();
        imageHeight = imageContent.getHeight();
        // TODO: Make this a reference rather than a hard coded string
        linkToImage = UrlUtils.concat("/weblounge-images", image.getIdentifier(), language.getIdentifier());
    } catch (ContentRepositoryException e) {
        logger.warn("Error trying to load image " + uri + " on " + request.getUrl() + ": " + e.getMessage(), e);
        return SKIP_BODY;
    }

    // Find the image style
    if (StringUtils.isNotBlank(imageStyle)) {
        style = ImageStyleUtils.findStyle(imageStyle, site);
        if (style != null) {
            linkToImage += "?style=" + style.getIdentifier();
            imageWidth = ImageStyleUtils.getStyledWidth(imageContent, style);
            imageHeight = ImageStyleUtils.getStyledHeight(imageContent, style);
            stashAndSetAttribute(ImageResourceTagExtraInfo.STYLE, style);
        } else {
            logger.warn("Image style '{}' not found to render on {}", imageStyle, request.getUrl());
        }
    }

    // TODO: Check the permissions

    // Store the image and the image content in the request
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE, image);
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE_CONTENT, imageContent);
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE_WIDTH, imageWidth);
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE_HEIGHT, imageHeight);
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE_SRC, linkToImage);
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE_TITLE, image.getTitle(language));
    stashAndSetAttribute(ImageResourceTagExtraInfo.IMAGE_DESC, image.getDescription(language));

    // Add the cache tags to the response
    response.addTag(CacheTag.Resource, image.getURI().getIdentifier());
    response.addTag(CacheTag.Url, image.getURI().getPath());

    return EVAL_BODY_INCLUDE;
}