当前位置: 首页>>代码示例>>Java>>正文


Java PortletContext.getAttribute方法代码示例

本文整理汇总了Java中javax.portlet.PortletContext.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java PortletContext.getAttribute方法的具体用法?Java PortletContext.getAttribute怎么用?Java PortletContext.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.portlet.PortletContext的用法示例。


在下文中一共展示了PortletContext.getAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getWebApplicationContext

import javax.portlet.PortletContext; //导入方法依赖的package包/类
/**
 * Find the root {@link WebApplicationContext} for this web app, typically
 * loaded via {@link org.springframework.web.context.ContextLoaderListener}.
 * <p>Will rethrow an exception that happened on root context startup,
 * to differentiate between a failed context startup and no context at all.
 * @param pc PortletContext to find the web application context for
 * @return the root WebApplicationContext for this web app, or {@code null} if none
 * (typed to ApplicationContext to avoid a Servlet API dependency; can usually
 * be casted to WebApplicationContext, but there shouldn't be a need to)
 * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
public static ApplicationContext getWebApplicationContext(PortletContext pc) {
	Assert.notNull(pc, "PortletContext must not be null");
	Object attr = pc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	if (attr == null) {
		return null;
	}
	if (attr instanceof RuntimeException) {
		throw (RuntimeException) attr;
	}
	if (attr instanceof Error) {
		throw (Error) attr;
	}
	if (!(attr instanceof ApplicationContext)) {
		throw new IllegalStateException("Root context attribute is not of type WebApplicationContext: " + attr);
	}
	return (ApplicationContext) attr;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:PortletApplicationContextUtils.java

示例2: getWebApplicationContext

import javax.portlet.PortletContext; //导入方法依赖的package包/类
/**
 * Find the root WebApplicationContext for this portlet application, which is
 * typically loaded via ContextLoaderListener or ContextLoaderServlet.
 * <p>Will rethrow an exception that happened on root context startup,
 * to differentiate between a failed context startup and no context at all.
 * @param pc PortletContext to find the web application context for
 * @return the root WebApplicationContext for this web app, or {@code null} if none
 * (typed to ApplicationContext to avoid a Servlet API dependency; can usually
 * be casted to WebApplicationContext, but there shouldn't be a need to)
 * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
public static ApplicationContext getWebApplicationContext(PortletContext pc) {
	Assert.notNull(pc, "PortletContext must not be null");
	Object attr = pc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	if (attr == null) {
		return null;
	}
	if (attr instanceof RuntimeException) {
		throw (RuntimeException) attr;
	}
	if (attr instanceof Error) {
		throw (Error) attr;
	}
	if (!(attr instanceof ApplicationContext)) {
		throw new IllegalStateException("Root context attribute is not of type WebApplicationContext: " + attr);
	}
	return (ApplicationContext) attr;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:29,代码来源:PortletApplicationContextUtils.java

示例3: checkSetAttribute

import javax.portlet.PortletContext; //导入方法依赖的package包/类
protected TestResult checkSetAttribute(PortletContext context) {
    TestResult res = new TestResult();
    res.setName("Set Attribute Test");
    res.setDescription("Sets and retrieves portlet contextuest attribute.");

    context.setAttribute(KEY, VAL);
    Object val = context.getAttribute(KEY);
    if(!VAL.equals(val)) {
        res.setReturnCode(TestResult.FAILED);
        res.setResultMessage("Retrieved value: '"+val+"' - Expected '"+VAL+"'");
    }
    else {
        res.setReturnCode(TestResult.PASSED);
    }

    context.removeAttribute(KEY);
    return res;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:19,代码来源:SimpleAttributeTest.java

示例4: checkRemoveAttribute

import javax.portlet.PortletContext; //导入方法依赖的package包/类
protected TestResult checkRemoveAttribute(PortletContext context) {
    TestResult res = new TestResult();
    res.setName("Remove Context Attribute Test");
    res.setDescription("Sets, removes and retrieves portlet request attribute.");

    context.setAttribute(KEY, VAL);
    context.removeAttribute(KEY);
    Object val = context.getAttribute(KEY);
    if(val!=null) {
        res.setReturnCode(TestResult.FAILED);
        res.setResultMessage("Retrieved value: '"+val+"' - Expected '"+VAL+"'");
    }
    else {
        res.setReturnCode(TestResult.PASSED);
    }

    return res;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:19,代码来源:SimpleAttributeTest.java

示例5: checkGetNullAttribute

import javax.portlet.PortletContext; //导入方法依赖的package包/类
protected TestResult checkGetNullAttribute(PortletContext context) {
    TestResult res = new TestResult();
    res.setName("Retrieve Missing Context Attribute Test");
    res.setDescription("Retrieves an attribute bound to an invalid key set are retrieved as null");

    Object val = context.getAttribute(KEY);
    if(val != null) {
        res.setReturnCode(TestResult.FAILED);
        res.setResultMessage("Retrieved value: '"+val+"' for attribute '"+KEY+"'");
    }
    else {
        res.setReturnCode(TestResult.PASSED);
    }
    return res;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:16,代码来源:SimpleAttributeTest.java

示例6: getTempDir

import javax.portlet.PortletContext; //导入方法依赖的package包/类
/**
 * Return the temporary directory for the current web application,
 * as provided by the portlet container.
 * @param portletContext the portlet context of the web application
 * @return the File representing the temporary directory
 */
public static File getTempDir(PortletContext portletContext) {
	Assert.notNull(portletContext, "PortletContext must not be null");
	return (File) portletContext.getAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:PortletUtils.java


注:本文中的javax.portlet.PortletContext.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。