/** * 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()); }
@Test public void testNativeRequest() { MockRenderRequest portletRequest = new MockRenderRequest(); MockRenderResponse portletResponse = new MockRenderResponse(); PortletWebRequest request = new PortletWebRequest(portletRequest, portletResponse); assertSame(portletRequest, request.getNativeRequest()); assertSame(portletRequest, request.getNativeRequest(PortletRequest.class)); assertSame(portletRequest, request.getNativeRequest(RenderRequest.class)); assertSame(portletRequest, request.getNativeRequest(MockRenderRequest.class)); assertNull(request.getNativeRequest(MultipartRequest.class)); assertSame(portletResponse, request.getNativeResponse()); assertSame(portletResponse, request.getNativeResponse(PortletResponse.class)); assertSame(portletResponse, request.getNativeResponse(RenderResponse.class)); assertSame(portletResponse, request.getNativeResponse(MockRenderResponse.class)); assertNull(request.getNativeResponse(MultipartRequest.class)); }
@Test public void testDecoratedNativeRequest() { MockRenderRequest portletRequest = new MockRenderRequest(); MockRenderResponse portletResponse = new MockRenderResponse(); PortletRequest decoratedRequest = new PortletRequestWrapper(portletRequest); PortletResponse decoratedResponse = new PortletResponseWrapper(portletResponse); PortletWebRequest request = new PortletWebRequest(decoratedRequest, decoratedResponse); assertSame(decoratedRequest, request.getNativeRequest()); assertSame(decoratedRequest, request.getNativeRequest(PortletRequest.class)); assertSame(portletRequest, request.getNativeRequest(RenderRequest.class)); assertSame(portletRequest, request.getNativeRequest(MockRenderRequest.class)); assertNull(request.getNativeRequest(MultipartRequest.class)); assertSame(decoratedResponse, request.getNativeResponse()); assertSame(decoratedResponse, request.getNativeResponse(PortletResponse.class)); assertSame(portletResponse, request.getNativeResponse(RenderResponse.class)); assertSame(portletResponse, request.getNativeResponse(MockRenderResponse.class)); assertNull(request.getNativeResponse(MultipartRequest.class)); }
public boolean especificValidations(UploadRequest uploadRequest,PortletResponse portletResponse) { Object returnObj = null; try { MethodKey especificValidationsMethod = new MethodKey(clp.getClassName(), "especificValidations", UploadRequest.class, PortletResponse.class); returnObj = clp.invoke(new MethodHandler(especificValidationsMethod, uploadRequest, portletResponse)); } catch (Throwable t) { t = ClpSerializer.translateThrowable(t); if (t instanceof RuntimeException) { throw (RuntimeException)t; } else { t.printStackTrace(); throw new RuntimeException(t.getClass().getName() + " is not a valid exception"); } } return ((Boolean)returnObj).booleanValue(); }
@Override public boolean especificValidations(UploadRequest uploadRequest,PortletResponse portletResponse){ Object returnObj = null; try { MethodKey especificValidationsMethod = new MethodKey(clp.getClassName(), "especificValidations", UploadRequest.class, PortletResponse.class); returnObj = clp.invoke(new MethodHandler(especificValidationsMethod, uploadRequest, portletResponse)); } catch (Throwable t) { t = ClpSerializer.translateThrowable(t); if (t instanceof RuntimeException) { throw (RuntimeException)t; } else { t.printStackTrace(); throw new RuntimeException(t.getClass().getName() + " is not a valid exception"); } } return ((Boolean)returnObj).booleanValue(); }
@Override public boolean especificValidations(UploadRequest uploadRequest, PortletResponse portletResponse) { PortletRequest actionRequest = (PortletRequest)uploadRequest.getAttribute( JavaConstants.JAVAX_PORTLET_REQUEST); boolean validate=true; if((Validator.isNotNull(uploadRequest.getParameter("random")))&& ((!Validator.isNumber(uploadRequest.getParameter("random")))|| (Long.parseLong(uploadRequest.getParameter("random"))>100)|| (Long.parseLong(uploadRequest.getParameter("random"))<0))) { SessionErrors.add(actionRequest, "execactivity.editActivity.random.number"); validate=false; } if((Validator.isNotNull(uploadRequest.getParameter("questionsPerPage")))&& ((!Validator.isNumber(uploadRequest.getParameter("questionsPerPage")))|| (Long.parseLong(uploadRequest.getParameter("questionsPerPage"))>100)|| (Long.parseLong(uploadRequest.getParameter("questionsPerPage"))<0))) { SessionErrors.add(actionRequest, "execactivity.editActivity.questionsPerPage.number"); validate=false; } return validate; }
@Override public boolean especificValidations(UploadRequest uploadRequest, PortletResponse portletResponse) { PortletRequest actionRequest = (PortletRequest)uploadRequest.getAttribute( JavaConstants.JAVAX_PORTLET_REQUEST); boolean validate = true; if((Validator.isNotNull(uploadRequest.getParameter("numValidaciones")))&& (!Validator.isNumber(uploadRequest.getParameter("numValidaciones")))) { SessionErrors.add(actionRequest, "p2ptaskactivity.editActivity.numValidaciones.number"); validate=false; } return validate; }
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; }
protected TestResult checkSameNameParameter(PortletContext context, PortletRequest request, PortletResponse response) throws IOException, PortletException { // Dispatch to the companion servlet: call checkSameNameParameter(). StringBuffer buffer = new StringBuffer(); buffer.append(SERVLET_PATH).append("?") .append(KEY_TARGET).append("=").append(TARGET_SAME_NAME_PARAM) .append("&").append(KEY_C).append("=").append(VALUE_C1) .append("&").append(KEY_C).append("=").append(VALUE_C2) .append("&").append(KEY_C).append("=").append(VALUE_C3); 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; }
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; }
protected TestResult checkInvalidParameters(PortletContext context, PortletRequest request, PortletResponse response) throws IOException, PortletException { // Dispatch to the companion servlet: call checkInvalidParameters(). StringBuffer buffer = new StringBuffer(); buffer.append(SERVLET_PATH).append("?") .append(KEY_TARGET).append("=").append(TARGET_INVALID_PARAMS) .append("&").append(KEY_A) .append("&").append(KEY_B).append("=").append(VALUE_B) .append("&").append(KEY_C).append("="); 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; }
public int doStartTag() throws JspException { PortletResponse portletResponse = (PortletResponse) pageContext.getRequest() .getAttribute(Constants.PORTLET_RESPONSE); String namespace = portletResponse.getNamespace(); JspWriter writer = pageContext.getOut(); try { writer.print(namespace); } catch (IOException ioe) { throw new JspException( "Unable to write namespace", ioe ); } return SKIP_BODY; }
private boolean checkEqualProperties(PortletResponse injectedPortletArtifact, PortletResponse portletResponse) { Collection<String> injectedProperties = injectedPortletArtifact .getPropertyNames(); Collection<String> portletResponseProperties = portletResponse .getPropertyNames(); Collection<String> injectedPropertyNames; Collection<String> portletPropertyNames; if (checkEqualCollection(injectedProperties, portletResponseProperties)) { for (String propertyName : injectedProperties) { injectedPropertyNames = injectedPortletArtifact .getPropertyValues(propertyName); portletPropertyNames = injectedPortletArtifact .getPropertyValues(propertyName); if (!checkEqualCollection(injectedPropertyNames, portletPropertyNames)) { return false; } } return true; } else { return false; } }
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request"); PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response"); request.getAttribute("javax.portlet.config"); Thread.currentThread().getId(); portletReq.getAttribute(THREADID_ATTR); PrintWriter writer = ((MimeResponse) portletResp).getWriter(); // Create result objects for the tests PortletURL purl = ((MimeResponse) portletResp).createRenderURL(); TestLink tl = new TestLink(V2DISPATCHERTESTS3S_SPEC2_19_FORWARDSERVLETRESOURCE_DISPATCH4, purl); tl.writeTo(writer); }
/** * Creates a new producer for this thread and stores it in the thread local. * @param req The portlet request * @param resp The portlet response * @param config The portlet config */ public static void setPrecursors(PortletRequest req, PortletResponse resp, PortletConfig config) { PortletArtifactProducer pap = getPAP(); pap.req = req; pap.resp = resp; pap.config = config; if (isTrace) { StringBuilder txt = new StringBuilder(80); txt.append("Set precursors."); txt.append(" ThreadId=").append(Thread.currentThread().getId()); txt.append(", Portlet name: ").append(config == null ? "null" : config.getPortletName()); LOG.trace(txt.toString()); } }
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { Summary summary = createSummary(document, Field.TITLE, Field.CONTENT); return summary; }
@Override public SearchResultsContainer search(PortletRequest request, PortletResponse response, String tabId, int pageOffset, boolean isLoadMore) throws ReadOnlyException, ValidatorException, IOException, SearchException { FlashlightSearchConfiguration config = this.readConfiguration(request.getPreferences()); Map<String, FlashlightSearchConfigurationTab> tabs = config.getTabs(); FacetedSearcher searcher = this.facetedSearcherManager.createFacetedSearcher(); LinkedHashMap<FlashlightSearchConfigurationTab, SearchPage> resultMap = new LinkedHashMap<>(tabs.size()); for(FlashlightSearchConfigurationTab tab : tabs.values()) { int pageSize; int loadMoreSize; if(tab.getId().equals(tabId)) { pageSize = tab.getFullPageSize(); } else { pageSize = tab.getPageSize(); } if(isLoadMore) { loadMoreSize = tab.getLoadMorePageSize(); } else { loadMoreSize = 0; } resultMap.put(tab, this.search(request, response, config, tab, searcher, pageOffset, pageSize, loadMoreSize)); } return new SearchResultsContainer(resultMap); }
/** * Gets the search result's view URL * * @param document The searched document * @param request The request * @param response The response * @param currentLayout The current page * @param tabId The search tab ID * * @return The search result URL */ private String getAssetViewURL(Document document, PortletRequest request, PortletResponse response, Layout currentLayout, String tabId, String keywords) { String className = document.get(Field.ENTRY_CLASS_NAME); long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); String currentUrl = this.portal.getCurrentURL(request); String returnedUrl; if(ASSET_TYPE.equals(className) && classPK > 0) { try { String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID); PortletURL viewInPortletUrlObj = this.portletUrlFactory.create(request, portletId, currentLayout, LIFECYCLE_RENDER); viewInPortletUrlObj.setParameter(PortletRequestParameter.VIEW_MODE.getName(), ViewMode.VIEW_JOURNAL.getParamValue()); viewInPortletUrlObj.setParameter(Field.ENTRY_CLASS_PK, Long.toString(classPK)); viewInPortletUrlObj.setParameter(PortletRequestParameter.TAB_ID.getName(), tabId); viewInPortletUrlObj.setParameter(PortletRequestParameter.KEYWORDS.getName(), keywords); String viewInPortletUrl = viewInPortletUrlObj.toString(); AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className); AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(classPK); returnedUrl = assetRenderer.getURLViewInContext((LiferayPortletRequest) request, (LiferayPortletResponse) response, viewInPortletUrl); } catch(Exception e) { returnedUrl = currentUrl; } } else { returnedUrl = currentUrl; } return returnedUrl; }
@Override public String getSummary(PortletRequest portletRequest, PortletResponse portletResponse) { // TODO return "TODO: contact summary"; // return _contact.getDescription(); }
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { Summary summary = createSummary(document); summary.setMaxContentLength(QueryUtil.ALL_POS); return summary; }