本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}