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


Java PortletContext类代码示例

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


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

示例1: doRetrieveMatchingPortletContextResources

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Recursively retrieve PortletContextResources that match the given pattern,
 * adding them to the given result set.
 * @param portletContext the PortletContext to work on
 * @param fullPattern the pattern to match against,
 * with preprended root directory path
 * @param dir the current directory
 * @param result the Set of matching Resources to add to
 * @throws IOException if directory contents could not be retrieved
 * @see org.springframework.web.portlet.context.PortletContextResource
 * @see javax.portlet.PortletContext#getResourcePaths
 */
protected void doRetrieveMatchingPortletContextResources(
		PortletContext portletContext, String fullPattern, String dir, Set<Resource> result) throws IOException {

	Set<String> candidates = portletContext.getResourcePaths(dir);
	if (candidates != null) {
		boolean dirDepthNotFixed = fullPattern.contains("**");
		for (Iterator<String> it = candidates.iterator(); it.hasNext();) {
			String currPath = it.next();
			if (currPath.endsWith("/") &&
					(dirDepthNotFixed ||
					StringUtils.countOccurrencesOf(currPath, "/") <= StringUtils.countOccurrencesOf(fullPattern, "/"))) {
				doRetrieveMatchingPortletContextResources(portletContext, fullPattern, currPath, result);
			}
			if (getPathMatcher().match(fullPattern, currPath)) {
				result.add(new PortletContextResource(portletContext, currPath));
			}
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:PortletContextResourcePatternResolver.java

示例2: 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

示例3: registerPortletApplicationScopes

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Register web-specific scopes ("request", "session", "globalSession")
 * with the given BeanFactory, as used by the Portlet ApplicationContext.
 * @param bf the BeanFactory to configure
 * @param pc the PortletContext that we're running within
 */
static void registerPortletApplicationScopes(ConfigurableListableBeanFactory bf, PortletContext pc) {
	bf.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
	bf.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
	bf.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));
	if (pc != null) {
		PortletContextScope appScope = new PortletContextScope(pc);
		bf.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope);
		// Register as PortletContext attribute, for ContextCleanupListener to detect it.
		pc.setAttribute(PortletContextScope.class.getName(), appScope);
	}

	bf.registerResolvableDependency(PortletRequest.class, new RequestObjectFactory());
	bf.registerResolvableDependency(PortletResponse.class, new ResponseObjectFactory());
	bf.registerResolvableDependency(PortletSession.class, new SessionObjectFactory());
	bf.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:PortletApplicationContextUtils.java

示例4: serveResource

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Serve the resource as specified in the given request to the given response,
 * using the PortletContext's request dispatcher.
 * <p>This is roughly equivalent to Portlet 2.0 GenericPortlet.
 * @param request the current resource request
 * @param response the current resource response
 * @param context the current Portlet's PortletContext
 * @throws PortletException propagated from Portlet API's forward method
 * @throws IOException propagated from Portlet API's forward method
 */
public static void serveResource(ResourceRequest request, ResourceResponse response, PortletContext context)
		throws PortletException, IOException {

	String id = request.getResourceID();
	if (id != null) {
		if (!PortletUtils.isProtectedResource(id)) {
			PortletRequestDispatcher rd = context.getRequestDispatcher(id);
			if (rd != null) {
				rd.forward(request, response);
				return;
			}
		}
		response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "404");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:PortletUtils.java

示例5: registerPortletApplicationScopes

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Register web-specific scopes ("request", "session", "globalSession")
 * with the given BeanFactory, as used by the Portlet ApplicationContext.
 * @param beanFactory the BeanFactory to configure
 * @param pc the PortletContext that we're running within
 */
static void registerPortletApplicationScopes(ConfigurableListableBeanFactory beanFactory, PortletContext pc) {
	beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
	beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
	beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));
	if (pc != null) {
		PortletContextScope appScope = new PortletContextScope(pc);
		beanFactory.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope);
		// Register as PortletContext attribute, for ContextCleanupListener to detect it.
		pc.setAttribute(PortletContextScope.class.getName(), appScope);
	}

	beanFactory.registerResolvableDependency(PortletRequest.class, new RequestObjectFactory());
	beanFactory.registerResolvableDependency(PortletSession.class, new SessionObjectFactory());
	beanFactory.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:PortletApplicationContextUtils.java

示例6: testRequiredInitParameterNotSetOtherParameterNotSet

import javax.portlet.PortletContext; //导入依赖的package包/类
public void testRequiredInitParameterNotSetOtherParameterNotSet() throws Exception {
	PortletContext portletContext = new MockPortletContext();
	MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
	String testParam = "testParam";
	String testValue = "testValue";
	portletConfig.addInitParameter(testParam, testValue);
	TestPortletBean portletBean = new TestPortletBean();
	portletBean.addRequiredProperty("anotherParam");
	assertNull(portletBean.getTestParam());
	try {
		portletBean.init(portletConfig);
		fail("should have thrown PortletException");
	}
	catch (PortletException ex) {
		// expected
	}
	assertNull(portletBean.getTestParam());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:GenericPortletBeanTests.java

示例7: testUnknownRequiredInitParameter

import javax.portlet.PortletContext; //导入依赖的package包/类
public void testUnknownRequiredInitParameter() throws Exception {
	PortletContext portletContext = new MockPortletContext();
	MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
	String testParam = "testParam";
	String testValue = "testValue";
	portletConfig.addInitParameter(testParam, testValue);
	TestPortletBean portletBean = new TestPortletBean();
	portletBean.addRequiredProperty("unknownParam");
	assertNull(portletBean.getTestParam());
	try {
		portletBean.init(portletConfig);
		fail("should have thrown PortletException");
	}
	catch (PortletException ex) {
		// expected
	}
	assertNull(portletBean.getTestParam());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:GenericPortletBeanTests.java

示例8: checkGetContextFromSession

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * FIXME: should this test reside in this class?  -- ZHENG Zhong
 */
protected TestResult checkGetContextFromSession(PortletSession session) {
    TestResult result = new TestResult();
    result.setDescription("Ensure that the PortletContext can be retrieved "
    		+ "from the portlet session.");

    PortletContext context = session.getPortletContext();
    if (context != null) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
    	result.setResultMessage("Fail to retrieve PortletContext from "
    			+ "PortletSession: null returned.");
    }
    return result;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:19,代码来源:ContextInitParameterTest.java

示例9: checkAddedSameNameParameter

import javax.portlet.PortletContext; //导入依赖的package包/类
protected TestResult checkAddedSameNameParameter(PortletContext context,
                                                 PortletRequest request,
                                                 PortletResponse response)
throws IOException, PortletException {
	// Dispatch to the companion servlet: call checkAddedSameNameParameter().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_ADDED_SAME_NAME_PARAM)
			.append("&").append(KEY_RENDER).append("=").append(VALUE_ADDED1)
			.append("&").append(KEY_RENDER).append("=").append(VALUE_ADDED2);

	if (LOG.isDebugEnabled()) {
		LOG.debug("Dispatching to: " + buffer.toString());
	}
	PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
			buffer.toString());
	dispatcher.include((RenderRequest) request, (RenderResponse) response);

	// Retrieve test result returned by the companion servlet.
    TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
	request.removeAttribute(RESULT_KEY);
	return result;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:24,代码来源:DispatcherRenderParameterTest.java

示例10: checkEnumerationContainsNames

import javax.portlet.PortletContext; //导入依赖的package包/类
protected TestResult checkEnumerationContainsNames(
		PortletContext context) {
    TestResult result = new TestResult();
    result.setDescription("Ensure that the expected init parameter name "
    		+ "exists in the portlet context's init parameters.");
    result.setSpecPLT("10.3.1");

    boolean found = false;
    for (Enumeration<String> en = context.getInitParameterNames();
    		!found && en.hasMoreElements(); ) {
        String name = en.nextElement();
        if (TEST_PARAM_NAME.equals(name)) {
            found = true;
        }
    }

    if (found) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	result.setReturnCode(TestResult.FAILED);
    	result.setResultMessage("Expected init parameter '"
    			+ TEST_PARAM_NAME + "' not found in portlet context.");
    }
    return result;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:26,代码来源:ContextInitParameterTest.java

示例11: checkParameters

import javax.portlet.PortletContext; //导入依赖的package包/类
protected TestResult checkParameters(PortletContext context,
                                     PortletRequest request,
                                     PortletResponse response)
throws IOException, PortletException {

	// Dispatch to the companion servlet: call checkParameters().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_PARAMS)
			.append("&").append(KEY_A).append("=").append(VALUE_A)
			.append("&").append(KEY_B).append("=").append(VALUE_B);

	if (LOG.isDebugEnabled()) {
		LOG.debug("Dispatching to: " + buffer.toString());
	}
    PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
    		buffer.toString());
    dispatcher.include((RenderRequest) request, (RenderResponse) response);

	// Retrieve test result returned by the companion servlet.
    TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
	request.removeAttribute(RESULT_KEY);
    return result;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:25,代码来源:DispatcherRenderParameterTest.java

示例12: renderTemplate

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Renders the given template
 *
 * @param request The request
 * @param response The response
 * @param ctx The template context
 * @param templatePath The path of the template, relative to the templates path given in the init parameters
 *
 * @throws PortletException Thrown if there is an error during template processing
 * @throws IOException Thrown if there is an error while writing the response
 */
public void renderTemplate(RenderRequest request, RenderResponse response, Map<String, Object> ctx, String templatePath) throws PortletException, IOException {
    PortletContext portletCtx = this.getPortletContext();
    String templateResourcePath = String.format(TEMPLATE_PATH_FORMAT, portletCtx.getPortletContextName(), this.templatesPath, templatePath);

    if(this.templateResourceLoader.hasTemplateResource(templateResourcePath)) {
        try {
            this.writeTemplate(request, response, ctx, templateResourcePath);
        } catch(TemplateException e) {
            throw new PortletException(e);
        }
    } else {
        throw new TemplateNotFoundException(templateResourcePath);
    }
}
 
开发者ID:savoirfairelinux,项目名称:flashlight-search,代码行数:26,代码来源:TemplatedPortlet.java

示例13: _getPortletContextInfo

import javax.portlet.PortletContext; //导入依赖的package包/类
private static final ContextInfo _getPortletContextInfo(final Object context)
{
  assert(context instanceof PortletContext);

  final PortletContext pContext = (PortletContext)context;
  return new ContextInfo(
           new PortletInitParameterMap(pContext),
           new PortletApplicationMap(pContext));
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:10,代码来源:CompositeUploadedFileProcessorImpl.java

示例14: PortletContextAwareProcessor

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Create a new PortletContextAwareProcessor for the given context and config.
 */
public PortletContextAwareProcessor(PortletContext portletContext, PortletConfig portletConfig) {
	this.portletContext = portletContext;
	this.portletConfig = portletConfig;
	if (portletContext == null && portletConfig != null) {
		this.portletContext = portletConfig.getPortletContext();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:PortletContextAwareProcessor.java

示例15: doFindPathMatchingFileResources

import javax.portlet.PortletContext; //导入依赖的package包/类
/**
 * Overridden version which checks for PortletContextResource
 * and uses {@code PortletContext.getResourcePaths} to find
 * matching resources below the web application root directory.
 * In case of other resources, delegates to the superclass version.
 * @see #doRetrieveMatchingPortletContextResources
 * @see PortletContextResource
 * @see javax.portlet.PortletContext#getResourcePaths
 */
@Override
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
	if (rootDirResource instanceof PortletContextResource) {
		PortletContextResource pcResource = (PortletContextResource) rootDirResource;
		PortletContext pc = pcResource.getPortletContext();
		String fullPattern = pcResource.getPath() + subPattern;
		Set<Resource> result = new HashSet<Resource>();
		doRetrieveMatchingPortletContextResources(pc, fullPattern, pcResource.getPath(), result);
		return result;
	}
	return super.doFindPathMatchingFileResources(rootDirResource, subPattern);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:PortletContextResourcePatternResolver.java


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